Browse Source

Update mk.sh from fastfoo

Alois Mahdal 10 years ago
parent
commit
4d9045eabb
1 changed files with 46 additions and 19 deletions
  1. 46
    19
      setup/mk.sh

+ 46
- 19
setup/mk.sh View File

@@ -38,10 +38,15 @@ build1() {
38 38
     local srcpath dstpath
39 39
     srcpath=$1
40 40
     dstpath=${srcpath%.skel}
41
-    perl -pe "
42
-        s|__SATURNIN_INI_PATH__|$SATURNIN_INI_PATH_GLOBAL:\\\$HOME/$SATURNIN_INI_PATH_USER|;
43
-        s|__VERSION__|$(get_version)|;
44
-    " < $srcpath > $dstpath
41
+    case $dstpath in
42
+        *.md)   cat $srcpath \
43
+                  | expand_includes \
44
+                  | expand_variables \
45
+                > $dstpath ;;
46
+        *)      cat $srcpath \
47
+                  | expand_variables \
48
+                > $dstpath ;;
49
+    esac
45 50
     echo $dstpath >> built.list
46 51
 }
47 52
 
@@ -79,6 +84,40 @@ dist() {
79 84
     rm -rf $dirname
80 85
 }
81 86
 
87
+expand_includes() {
88
+    #
89
+    # Expand include directives
90
+    #
91
+    # Expand e.g. `<!-- include4: foo.sh -->` to include code of foo.sh
92
+    #
93
+    perl -we '
94
+        use strict;
95
+        my $text;
96
+        while (<>) {
97
+            chomp;
98
+            if (m/<!-- include4: (\S+) -->/) {
99
+                open my $fh, $1 or warn "cannot find: $1";
100
+                my $text = do { local($/); <$fh> };
101
+                close $fh;
102
+                $text =~ s/^(.)/    $1/gm;
103
+                chomp $text;
104
+                print "$text\n";
105
+            } else {
106
+                print "$_\n";
107
+            }
108
+        }
109
+    '
110
+}
111
+
112
+expand_variables() {
113
+    #
114
+    # Expand variable values
115
+    #
116
+    perl -pe "
117
+        s|__SATURNIN_INI_PATH__|$SATURNIN_INI_PATH_GLOBAL:\\\$HOME/$SATURNIN_INI_PATH_USER|;
118
+        s|__VERSION__|$(get_version)|;
119
+    "
120
+}
82 121
 install() {
83 122
     mkdir -vp $bindir
84 123
     list_of_bins | xargs cp -vrt $bindir
@@ -91,7 +130,7 @@ get_version() {
91 130
     local stage=$STAGE
92 131
     if git rev-parse HEAD >&/dev/null;
93 132
     then    # we are in git repo... so we can get smart
94
-        local lasttag=$(git tag | grep ^v | tail -n1)
133
+        local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
95 134
         if ! git describe --tags --exact-match HEAD >&/dev/null;
96 135
         then    # we are not at later commit than the last tag
97 136
             local sha=g$(git describe --always HEAD)
@@ -101,6 +140,7 @@ get_version() {
101 140
             local dirty=dirty
102 141
         fi
103 142
         version=${lasttag:1}
143
+        local suffix=""
104 144
         case $stage:$sha:$dirty in
105 145
             ::)         suffix=""                    ;;
106 146
             ::dirty)    suffix="+$dirty"             ;;
@@ -116,16 +156,6 @@ get_version() {
116 156
     echo $version
117 157
 }
118 158
 
119
-run_test() {
120
-    pushd test
121
-    find -maxdepth 1 -type f \! -name '*.skel' | while read test;
122
-    do
123
-        chmod 0755 $test
124
-        $test || exit $?
125
-    done
126
-    popd
127
-}
128
-
129 159
 uninstall() {
130 160
     list_of_installed_bins | xargs rm -vf
131 161
 }
@@ -134,9 +164,6 @@ case $1 in
134 164
     build|clean|dist|install|install_manpages|manpages|uninstall)
135 165
         $1
136 166
         ;;
137
-    test)
138
-        run_test
139
-        ;;
140 167
     *)
141
-        echo "usage: $(basename $0) build|clean|dist|install|test|uninstall" >&2
168
+        echo "usage: $(basename $0) build|clean|dist|install|uninstall" >&2
142 169
 esac