aboutsummaryrefslogtreecommitdiffstats
path: root/configure
blob: 2085a382fc64d68148c1306c13da204b7dda90d4 (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
#!/bin/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
  -c when     Enable compiler colours (always|auto|off) [default: auto]
  -d          Enable debugging flags
  -e          Enable -Werror
  -h          Show this help
  -o          Enable optimisation flags
  -v          Print results of configuration
  -w          Enable warning flags
Environment:
  CC          C compiler
EOF
}

exec 3>config.rc
conf() { echo "$1" >&3; }

colour=auto
while getopts B:C:L:P:c:dehovw opt; do
	qopt=${OPTARG@Q}
	case $opt in
	B) conf "LDLIBS+=($qopt)";;
	C) conf "CFLAGS+=($qopt)";;
	L) conf "LDFLAGS+=($qopt)";;
	P) conf "CPPFLAGS+=($qopt)";;
	c) colour="$OPTARG";;
	d) conf "debug=1" >&3;;
	e) conf "werror=1" >&3;;
	h) usage; help; exit;;
	o) conf "optimise=1" >&3;;
	v) conf "verbose=1" >&3;;
	w) conf "warn=1" >&3;;
	?) 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

[[ $CC ]] && conf "CC=${CC@Q}"