aboutsummaryrefslogtreecommitdiffstats
path: root/configure
diff options
context:
space:
mode:
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure71
1 files changed, 21 insertions, 50 deletions
diff --git a/configure b/configure
index 431dc4a..2085a38 100755
--- a/configure
+++ b/configure
@@ -1,17 +1,5 @@
#!/bin/bash
-CFLAGS=(-std=c11 -fPIC)
-CPPFLAGS=()
-LDLIBS=()
-LDFLAGS=()
-
-warnings=(
- -Wall -Wcast-align -Wcast-qual -Wextra -Wpedantic -Wformat=2
- -Winit-self -Wmissing-prototypes -Wpointer-arith -Wshadow
- -Wstrict-prototypes -Wsuggest-attribute=format
- -Wsuggest-attribute=noreturn
-)
-
usage () { echo "Usage: $0 [-h|options...]"; }
help () {
@@ -24,7 +12,6 @@ Options:
-c when Enable compiler colours (always|auto|off) [default: auto]
-d Enable debugging flags
-e Enable -Werror
- -f Generate a compile_flags.txt
-h Show this help
-o Enable optimisation flags
-v Print results of configuration
@@ -34,49 +21,33 @@ Environment:
EOF
}
-check() {
- what=$1
- shift
- for p do
- if command -v "$p" >/dev/null 2>&1; 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
+exec 3>config.rc
+conf() { echo "$1" >&3; }
colour=auto
-while getopts B:C:L:P:c:defhovw opt; do
+while getopts B:C:L:P:c:dehovw opt; do
+ qopt=${OPTARG@Q}
case $opt in
- B) LDLIBS+=("$OPTARG");;
- C) CFLAGS+=("$OPTARG");;
- L) LDFLAGS+=("$OPTARG");;
- P) CPPFLAGS+=("$OPTARG");;
+ B) conf "LDLIBS+=($qopt)";;
+ C) conf "CFLAGS+=($qopt)";;
+ L) conf "LDFLAGS+=($qopt)";;
+ P) conf "CPPFLAGS+=($qopt)";;
c) colour="$OPTARG";;
- d) CFLAGS+=(-Og -g); LDFLAGS+=(-Og -g);;
- e) CFLAGS+=(-Werror);;
- f) gen_flags=1;;
+ d) conf "debug=1" >&3;;
+ e) conf "werror=1" >&3;;
h) usage; help; exit;;
- o) CFLAGS+=(-O2 -flto); LDFLAGS+=(-O2 -flto);;
- v) verbose=1;;
- w) CFLAGS+=("${warnings[@]}");;
+ o) conf "optimise=1" >&3;;
+ v) conf "verbose=1" >&3;;
+ w) conf "warn=1" >&3;;
?) usage >&2; exit 1;;
esac
done
-if [[ $colour == auto && -t 1 ]]; then
- colour=always
-fi
-if [[ $colour == always ]]; then
- CFLAGS+=(-fdiagnostics-color)
-fi
-{
- echo "# generated using $0 $@"
- declare -p CC CFLAGS CPPFLAGS LDFLAGS LDLIBS
-} >.config.rc
-[[ $verbose ]] && cat .config.rc
-[[ $gen_flags ]] && printf '%s\n' "${CFLAGS[@]}" "${CPPFLAGS[@]}" >compile_flags.txt
+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}"