aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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