diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-07-15 17:20:56 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-07-15 17:20:56 +0100 |
commit | 945563f4e4e4cf4e4aa570ad64acd41702e8f9e6 (patch) | |
tree | 3971802d9f6133c2e16dd25578c98ea75e2bfb47 /.vars.rc.do | |
parent | 18e1756dfb07d0adbd4f045534a18194839fe86c (diff) | |
download | pack-945563f4e4e4cf4e4aa570ad64acd41702e8f9e6.tar.gz pack-945563f4e4e4cf4e4aa570ad64acd41702e8f9e6.tar.xz pack-945563f4e4e4cf4e4aa570ad64acd41702e8f9e6.zip |
Generate .config.rc (now .vars.rc) with redo
This avoids relying on configure generating anything, this should also
make it easier to ensure that git-bisect builds don't need any
reconfiguring or cleans.
Diffstat (limited to '.vars.rc.do')
-rwxr-xr-x | .vars.rc.do | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/.vars.rc.do b/.vars.rc.do new file mode 100755 index 0000000..2494f3f --- /dev/null +++ b/.vars.rc.do @@ -0,0 +1,68 @@ +#!/bin/bash -e + +# Ensure variables from the config aren't set before the config is read to +# avoid capturing transient state +unset CC CFLAGS CPPFLAGS LDFLAGS LDLIBS colour debug optimise verbose warn werror + +CFLAGS=(-std=c11 -fPIC) + +wflags=( + -Wall -Wcast-align -Wcast-qual -Wextra -Wpedantic -Wformat=2 + -Winit-self -Wmissing-prototypes -Wpointer-arith -Wshadow + -Wstrict-prototypes -Wsuggest-attribute=format + -Wsuggest-attribute=noreturn +) + +declare -a CFLAGS CPPFLAGS LDFLAGS LDLIBS + +if [ -e config.rc ]; then + redo-ifchange config.rc + . ./config.rc +else + redo-ifcreate config.rc +fi + +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 + +if [[ $colour ]]; then + if [[ $colour != 1 ]]; then no=no-; fi + CFLAGS+=("-f${no}diagnostics-colour") + LDFLAGS+=("-f${no}diagnostics-colour") +fi +if [[ $debug ]]; then + CFLAGS+=(-Og -g) + LDFLAGS+=(-Og -g) +fi +if [[ $optimise ]]; then + CFLAGS+=(-O2 -flto) + LDFLAGS+=(-O2 -flto) +fi +if [[ $warn ]]; then + CFLAGS+=("${warnings[@]}") +fi +if [[ $werror ]]; then + CFLAGS+=(-Werror) +fi + +{ + echo "# generated by $0" + declare -p CC CFLAGS CPPFLAGS LDFLAGS LDLIBS +} >"$3" + +if [[ $verbose ]]; then + echo "# Configuration regenerated:" >&2 + cat "$3" >&2 +fi |