blob: 9ed3fb445640b1265956a65d2ef99de2cb6daac5 (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#!/usr/bin/env bash
usage () { echo "Usage: $0 [-h|options...]"; }
help () {
cat <<EOF
Options:
-B ldlib Append ldlib to LDLIBS
-C cflag Append cflag to CFLAGS
-L ldflag Append ldflag to LDFLAGS
-P cppflag Append cppflag to CPPFLAGS
-W profile Enable compiler specific warnings (clang|gcc) (overrides -w)
-c when Enable compiler colours (always|auto|off) [default: auto]
-d Enable debugging flags
-e Enable -Werror
-f Generate compile_commands.json database (needs jq)
-h Show this help
-o Enable optimisation flags
-v Print results of configuration
-w Enable warning flags (overrides -W)
Environment:
CC C compiler
EOF
}
exec 3>config.rc
conf() { echo "$1" >&3; }
colour=auto
while getopts B:C:L:P:W:c:defhovw opt; do
qopt=${OPTARG@Q}
case $opt in
B) conf "LDLIBS+=($qopt)";;
C) conf "CFLAGS+=($qopt)";;
L) conf "LDFLAGS+=($qopt)";;
P) conf "CPPFLAGS+=($qopt)";;
W) warn="$OPTARG";;
c) colour="$OPTARG";;
d) conf "debug=1" >&3;;
e) conf "werror=1" >&3;;
f) conf "extra_targets+=(compile_commands.json)" ;;
h) usage; help; exit;;
o) conf "optimise=1" >&3;;
v) conf "verbose=1" >&3;;
w) warn=1;;
?) usage >&2; exit 1;;
esac
done
case "$colour" in
auto) [[ -t 1 ]] && conf "colour=1" || conf "colour=0";;
always) conf "colour=1";;
off) conf "colour=0";;
*) usage >&2; exit 1;;
esac
case "$warn" in
1|clang|gcc) conf "warn=$warn";;
?*) usage >&2; exit 1;;
esac
if [[ $CC ]]; then conf "CC=${CC@Q}"; fi
|