aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-07-15 17:20:56 +0100
committerTomasz Kramkowski <tk@the-tk.com>2021-07-15 17:20:56 +0100
commit945563f4e4e4cf4e4aa570ad64acd41702e8f9e6 (patch)
tree3971802d9f6133c2e16dd25578c98ea75e2bfb47
parent18e1756dfb07d0adbd4f045534a18194839fe86c (diff)
downloadpack-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.
-rwxr-xr-x.compile.do4
-rw-r--r--.gitignore3
-rwxr-xr-x.link-executable.do4
-rwxr-xr-x.link-library.do4
-rwxr-xr-x.vars.rc.do68
-rwxr-xr-xall.do2
-rwxr-xr-xclean2
-rwxr-xr-xcompile_flags.txt.do4
-rwxr-xr-xconfigure71
9 files changed, 103 insertions, 59 deletions
diff --git a/.compile.do b/.compile.do
index 2a8d932..a249c44 100755
--- a/.compile.do
+++ b/.compile.do
@@ -1,6 +1,6 @@
#!/bin/bash -e
-redo-ifchange .config.rc
-. ./.config.rc
+redo-ifchange .vars.rc
+. ./.vars.rc
exec >"$3"
echo "# generated by $0"
declare -p CC CFLAGS CPPFLAGS
diff --git a/.gitignore b/.gitignore
index 0fd3620..187e67e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,11 +3,12 @@
*.o
*.so
.compile
-.config.rc
.link-executable
.link-library
.redo/
+.vars.rc
all
compile_flags.txt
+config.rc
test
test_gen
diff --git a/.link-executable.do b/.link-executable.do
index bb3dea6..6b2ef81 100755
--- a/.link-executable.do
+++ b/.link-executable.do
@@ -1,6 +1,6 @@
#!/bin/bash -e
-redo-ifchange .config.rc
-. ./.config.rc
+redo-ifchange .vars.rc
+. ./.vars.rc
exec >"$3"
echo "# generated by $0"
declare -p CC LDFLAGS LDLIBS
diff --git a/.link-library.do b/.link-library.do
index 7a7aad2..67ea23d 100755
--- a/.link-library.do
+++ b/.link-library.do
@@ -1,6 +1,6 @@
#!/bin/bash -e
-redo-ifchange .config.rc
-. ./.config.rc
+redo-ifchange .vars.rc
+. ./.vars.rc
exec >"$3"
echo "# generated by $0"
declare -p CC LDFLAGS LDLIBS
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
diff --git a/all.do b/all.do
index 749f446..321cf2c 100755
--- a/all.do
+++ b/all.do
@@ -1,2 +1,2 @@
#!/bin/sh
-redo-ifchange libpack.so test
+redo-ifchange libpack.so test compile_flags.txt
diff --git a/clean b/clean
index 246aa82..2cb5f16 100755
--- a/clean
+++ b/clean
@@ -1,3 +1,3 @@
#!/bin/sh
find . -type f \( -name '*.d' -o -name '*.o' -o -name '*.inc' \) -exec rm -f {} +
-rm -f .compile .link-library .link-executable test_gen test libpack.so all
+rm -f .compile .link-executable .link-library .vars.rc all compile_flags.txt libpack.so test test_gen
diff --git a/compile_flags.txt.do b/compile_flags.txt.do
new file mode 100755
index 0000000..4d14f78
--- /dev/null
+++ b/compile_flags.txt.do
@@ -0,0 +1,4 @@
+#!/bin/bash
+redo-ifchange .vars.rc
+. ./.vars.rc
+printf '%s\n' "${CFLAGS[@]}" "${CPPFLAGS[@]}" >"$3"
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}"