aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-08-08 03:01:43 +0100
committerTomasz Kramkowski <tk@the-tk.com>2021-08-08 03:01:43 +0100
commitbd0969cb8af8b1e34931e06489de0343bbfa9a69 (patch)
tree30cde5d750c91b53f5c52ff6691effd22ed9c174
parent4a0fa28d61dc097b962fd96e5eded47385663716 (diff)
downloadpack-bd0969cb8af8b1e34931e06489de0343bbfa9a69.tar.gz
pack-bd0969cb8af8b1e34931e06489de0343bbfa9a69.tar.xz
pack-bd0969cb8af8b1e34931e06489de0343bbfa9a69.zip
default.tool.do: make things cleaner hopefully
-rwxr-xr-xdefault.tool.do38
1 files changed, 19 insertions, 19 deletions
diff --git a/default.tool.do b/default.tool.do
index d9845fa..5a99afa 100755
--- a/default.tool.do
+++ b/default.tool.do
@@ -2,25 +2,25 @@
set -e
tool=${1##*/}
if [[ $tool = *-host.tool ]]; then prefix=H; else prefix=T; fi
-case "$tool" in
-compile*.tool)
- vars=(CC CFLAGS CPPFLAGS)
- cmd='"$CC" -MMD -MF - "${CFLAGS[@]}" "${CPPFLAGS[@]}" -c -o "$3" "${1%.o}.c"'
- ;;
-link-*.tool)
- vars=(CC LDFLAGS LDLIBS)
- if [[ $1 = *-library* ]]; then shared='-shared '; else shared=''; fi
- cmd='"$CC" "${LDFLAGS[@]}" '"$shared"'"${objects[@]}" "${LDLIBS[@]}" -o "$3"'
- ;;
-*)
- echo "Invalid tool name $1" >&2
- exit 1 ;;
-esac
-for v in "${vars[@]}"; do cmd=${cmd//$v/$prefix$v}; done
redo-ifchange .vars.rc
. ./.vars.rc
-exec >"$3"
-echo "#generated by $0 $1"
-declare -p "${vars[@]/#/$prefix}"
-echo "cmd=($cmd)"
+# Assign expanded and quoted versions of the prefixed variables
+eval "CC=\${${prefix}CC@Q}"
+for v in CFLAGS CPPFLAGS LDFLAGS LDLIBS; do
+ eval "$v=\${$prefix$v[*]@Q}"
+done
+out='"$3"'
+src='"${1%.o}.c"'
+objects='"${objects[@]}"'
+case $tool in
+compile*)
+ cmd="$CC -MMD -MF - $CFLAGS $CPPFLAGS -c -o $out $src" ;;
+link-library*)
+ shared='-shared' ;& # fallthrough
+link-*)
+ cmd="$CC $LDFLAGS $shared $objects $LDLIBS -o $out" ;;
+*)
+ echo "Invalid tool name $1" >&2; exit 1 ;;
+esac
+printf '#generated by %s %s\ncmd=(%s)\n' "${0##*/}" "$tool" "$cmd" >"$3"
if command -v redo-stamp &>/dev/null; then redo-stamp <"$3"; fi