Преглед на файлове

Update mk.sh from fastfoo

Alois Mahdal преди 10 години
родител
ревизия
4d9045eabb
променени са 1 файла, в които са добавени 46 реда и са изтрити 19 реда
  1. 46
    19
      setup/mk.sh

+ 46
- 19
setup/mk.sh Целия файл

38
     local srcpath dstpath
38
     local srcpath dstpath
39
     srcpath=$1
39
     srcpath=$1
40
     dstpath=${srcpath%.skel}
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
     echo $dstpath >> built.list
50
     echo $dstpath >> built.list
46
 }
51
 }
47
 
52
 
79
     rm -rf $dirname
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
 install() {
121
 install() {
83
     mkdir -vp $bindir
122
     mkdir -vp $bindir
84
     list_of_bins | xargs cp -vrt $bindir
123
     list_of_bins | xargs cp -vrt $bindir
91
     local stage=$STAGE
130
     local stage=$STAGE
92
     if git rev-parse HEAD >&/dev/null;
131
     if git rev-parse HEAD >&/dev/null;
93
     then    # we are in git repo... so we can get smart
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
         if ! git describe --tags --exact-match HEAD >&/dev/null;
134
         if ! git describe --tags --exact-match HEAD >&/dev/null;
96
         then    # we are not at later commit than the last tag
135
         then    # we are not at later commit than the last tag
97
             local sha=g$(git describe --always HEAD)
136
             local sha=g$(git describe --always HEAD)
101
             local dirty=dirty
140
             local dirty=dirty
102
         fi
141
         fi
103
         version=${lasttag:1}
142
         version=${lasttag:1}
143
+        local suffix=""
104
         case $stage:$sha:$dirty in
144
         case $stage:$sha:$dirty in
105
             ::)         suffix=""                    ;;
145
             ::)         suffix=""                    ;;
106
             ::dirty)    suffix="+$dirty"             ;;
146
             ::dirty)    suffix="+$dirty"             ;;
116
     echo $version
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
 uninstall() {
159
 uninstall() {
130
     list_of_installed_bins | xargs rm -vf
160
     list_of_installed_bins | xargs rm -vf
131
 }
161
 }
134
     build|clean|dist|install|install_manpages|manpages|uninstall)
164
     build|clean|dist|install|install_manpages|manpages|uninstall)
135
         $1
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
 esac
169
 esac