aboutsummaryrefslogtreecommitdiffstats
path: root/default.tool.do
blob: 5a99afae7da154f814b1440de6c4ac79eb8e8e99 (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
#!/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
printf '#generated by %s %s\ncmd=(%s)\n' "${0##*/}" "$tool" "$cmd" >"$3"
if command -v redo-stamp &>/dev/null; then redo-stamp <"$3"; fi