-
Notifications
You must be signed in to change notification settings - Fork 372
/
vars.sh
executable file
·54 lines (44 loc) · 955 Bytes
/
vars.sh
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env sh
set -eu
from=
var=
print_usage() {
echo 'Query Makefile variables from scripts. Use like so:'
echo
echo " $0 go_version"
echo " $0 FROM=docs python_version"
}
fail() {
echo "$@" >&2
print_usage >&2
exit 1
}
[ $# -gt 0 ] || { print_usage && exit; }
while [ $# -gt 0 ]; do
case "$1" in
*=*)
name="${1%%=*}" && val="${1#*=}"
[ "$name" = FROM ] || fail Unsupported variable "$name"
[ -z "$from" ] || fail FROM already given
[ -n "$val" ] || fail FROM may not be empty
from="$val"
;;
*)
[ -z "$var" ] || fail Makefile variable already given
var="$1"
;;
esac
shift 1
done
[ -n "$var" ] || fail Makefile variable not given
[ -n "$from" ] || from=embedded-bins
exec make --no-print-directory -r -s -f - <<EOF
include $from/Makefile.variables
.PHONY: print
print:
ifeq (\$(origin $var),file)
\$(info \$($var))
else
\$(error Makefile variable $var doesn't exist)
endif
EOF