Browse Source

Parametrize expand_variables

Add flexiblility for more specialized targets
Alois Mahdal 9 years ago
parent
commit
78ed991707
1 changed files with 13 additions and 10 deletions
  1. 13
    10
      src/include/build.sh

+ 13
- 10
src/include/build.sh View File

@@ -24,8 +24,8 @@ build1() {
24 24
     dstpath=$2
25 25
     test -n "$dstpath" || dstpath=${srcpath%.skel}
26 26
     case $dstpath in
27
-        *.md) <"$srcpath" expand_includes | expand_variables >"$dstpath" ;;
28
-        *)    <"$srcpath"                   expand_variables >"$dstpath" ;;
27
+        *.md) <"$srcpath" expand_includes | expand_variables "vars" >"$dstpath" ;;
28
+        *)    <"$srcpath"                   expand_variables "vars" >"$dstpath" ;;
29 29
     esac
30 30
     mkdir -p "$MKIT_LOCAL"
31 31
     echo "$dstpath" >> "$MKIT_LOCAL/built.lst"
@@ -118,16 +118,19 @@ expand_includes() {
118 118
 
119 119
 expand_variables() {
120 120
     #
121
-    # Expand variable values
121
+    # Expand variables from sections $@
122 122
     #
123 123
     local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
124
-    local varname varvalue
125
-    ini lskeys "vars" \
126
-      | while read varname;
127
-        do
128
-            varvalue="$(ini 1value "vars:$varname" | sed -e 's/\$/\\$/' )"
129
-            echo "s|$varname|$varvalue|;" >> "$script"
130
-        done
124
+    local section varname varvalue
125
+    for section in "$@";
126
+    do
127
+        ini lskeys "$section" \
128
+          | while read varname;
129
+            do
130
+                varvalue="$(ini 1value "$section:$varname" | sed -e 's/\$/\\$/' )"
131
+                echo "s|$varname|$varvalue|;" >> "$script"
132
+            done
133
+    done
131 134
     echo "s|__CODENAME__|$CODENAME|;"     >> "$script"
132 135
     echo "s|__VERSION__|$(get_version)|;" >> "$script"
133 136
     perl -wp "$script" || die "expand_variables failed"