blob: 2fa53e693ef496904577c5f55a172a505c91b417 (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#!/bin/bash
libs=(luajit sdl2 pangoft2)
CFLAGS+=(-std=c11 -fPIC)
LDFLAGS+=(-shared)
usage () {
echo "Usage: $0 [-h|options...]"
}
help () {
echo "Options:"
echo " -B ldlib Append ldlib to LDLIBS"
echo " -C cflag Append cflag to CFLAGS"
echo " -L ldflag Append ldflag to LDFLAGS"
echo " -P cppflag Append cppflag to CPPFLAGS"
echo " -c when Enable compiler colours (always|auto|off) [default: auto]"
echo " -d Enable debugging flags"
echo " -e Enable -Werror"
echo " -h Show this help"
echo " -o Enable optimisation flags"
echo " -v Print results of configuration"
echo " -w Enable warning flags"
echo "Environment:"
echo " CC C compiler"
echo " PKG_CONFIG pkg-config"
}
exists() {
command -v "$1" >/dev/null 2>&1
}
check() {
what=$1
shift
for p do
if exists "$p"; then
echo "$p"
return
fi
done
echo "$what not set or found" >&2
return 1
}
CC=$(check '$CC, cc, gcc or clang' "$CC" cc gcc clang) || exit
pc=$(check '$PKG_CONFIG, pkg-config or pkg-conf' "$PKG_CONFIG" pkg-config pkg-conf) || exit
for l in "${libs[@]}"; do
"$pc" --print-errors --exists "$l" || exit
done
CFLAGS+=($("$pc" --cflags-only-other "${libs[@]}"))
CPPFLAGS+=($("$pc" --cflags-only-I "${libs[@]}"))
LDFLAGS+=($("$pc" --libs-only-L --libs-only-other "${libs[@]}"))
LDLIBS+=($("$pc" --libs-only-l "${libs[@]}"))
colour=auto
while getopts B:C:L:P:c:dehovw opt; do
case $opt in
B) LDLIBS+=("$OPTARG");;
C) CFLAGS+=("$OPTARG");;
L) LDFLAGS+=("$OPTARG");;
P) CPPFLAGS+=("$OPTARG");;
c) colour="$OPTARG";;
d)
CFLAGS+=(-Og -g)
LDFLAGS+=(-Og -g)
;;
e) CFLAGS+=(-Werror);;
h) usage; help; exit;;
o)
CFLAGS+=(-O2 -flto)
LDFLAGS+=(-O2 -flto)
;;
v) verbose=1;;
w) CFLAGS+=(-Wall -Wextra);;
?) usage >&2; exit 1;;
esac
done
if [[ $colour == auto ]] && exists tput && (( $(tput colors) >= 8 )); then
colour=always
fi
if [[ $colour == always ]]; then
CFLAGS+=(-fdiagnostics-color)
fi
{
echo "# generated using $0 $@"
echo "CC=$CC"
echo "CFLAGS=(${CFLAGS[@]@Q})"
echo "CPPFLAGS=(${CPPFLAGS[@]@Q})"
echo "LDFLAGS=(${LDFLAGS[@]@Q})"
echo "LDLIBS=(${LDLIBS[@]@Q})"
} >.config.rc
[[ $verbose ]] && cat .config.rc
|