blob: 21c9b12f17735f3bf2f9b76974eb703c98ab7692 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#!/usr/bin/env bash
set -e
tool=${1##*/}
if [[ $tool = *-host.tool ]]; then prefix=H; else prefix=T; fi
redo-ifchange .vars.rc
. ./.vars.rc
# 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
cat <<EOF >"$3"
#generated by ${0##*/} $tool
cmd=($cmd)
redo-ifchange "\${cmd[0]}"
EOF
if command -v redo-stamp &>/dev/null; then redo-stamp <"$3"; fi
# vim:ft=bash
|