summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbuild/cc.sh24
-rwxr-xr-xbuild/flags-if.sh10
-rwxr-xr-xbuild/pkgconf.sh10
3 files changed, 33 insertions, 11 deletions
diff --git a/build/cc.sh b/build/cc.sh
index fd58393..e1d2b0b 100755
--- a/build/cc.sh
+++ b/build/cc.sh
@@ -3,14 +3,32 @@
# Copyright © Tavian Barnes <tavianator@tavianator.com>
# SPDX-License-Identifier: 0BSD
-# Run the compiler and check if it succeeded
+# Run the compiler and check if it succeeded. Usage:
+#
+# $ build/cc.sh [-q] path/to/file.c [-flags -Warnings ...]
set -eu
+QUIET=
if [ "$1" = "-q" ]; then
+ QUIET=y
shift
-else
+fi
+
+# Source files can specify their own flags with lines like
+#
+# /// _CFLAGS += -Wmissing-variable-declarations
+#
+# which will be added to the makefile on success, or lines like
+#
+# /// -Werror
+#
+# which are just used for the current file.
+EXTRA_FLAGS=$(sed -n '\|^///|{s|^/// ||; s|[^=]*= ||; p;}' "$1")
+
+# Without -q, print the executed command for config.log
+if [ -z "$QUIET" ]; then
set -x
fi
-$XCC $XCPPFLAGS $XCFLAGS $XLDFLAGS "$@" $XLDLIBS
+$XCC $XCPPFLAGS $XCFLAGS $XLDFLAGS "$@" $EXTRA_FLAGS $XLDLIBS
diff --git a/build/flags-if.sh b/build/flags-if.sh
index 76e1c34..81eb345 100755
--- a/build/flags-if.sh
+++ b/build/flags-if.sh
@@ -7,11 +7,15 @@
set -eu
+build/cc.sh "$@" || exit 1
+
+# If the build succeeded, print any lines like
+#
+# /// _CFLAGS += -foo
+#
+# (unless they're already set)
OLD_FLAGS="$XCC $XCPPFLAGS $XCFLAGS $XLDFLAGS $XLDLIBS"
-NEW_FLAGS=$(sed -n '\|^///|{s|^/// ||; s|[^=]*= ||; p;}' "$1")
-build/cc.sh "$@" $NEW_FLAGS || exit 1
-# De-duplicate against the existing flags
while IFS="" read -r line; do
case "$line" in
///*=*)
diff --git a/build/pkgconf.sh b/build/pkgconf.sh
index a8a3341..decf706 100755
--- a/build/pkgconf.sh
+++ b/build/pkgconf.sh
@@ -34,10 +34,10 @@ if [ -z "$MODE" ]; then
n|0) exit 1 ;;
esac
- CFLAGS=$("$0" --cflags "$LIB") || exit 1
- LDFLAGS=$("$0" --ldflags "$LIB") || exit 1
- LDLIBS=$("$0" --ldlibs "$LIB") || exit 1
- build/cc.sh $CFLAGS $LDFLAGS "build/with/$LIB.c" $LDLIBS -o "gen/with/.$LIB.out" || exit 1
+ XCFLAGS="$XCFLAGS $("$0" --cflags "$LIB")" || exit 1
+ XLDFLAGS="$XLDFLAGS $("$0" --ldflags "$LIB")" || exit 1
+ XLDLIBS="$("$0" --ldlibs "$LIB") $XLDLIBS" || exit 1
+ build/cc.sh "build/with/$LIB.c" -o "gen/with/.$LIB.out" || exit 1
done
fi
@@ -92,5 +92,5 @@ done
case "$MODE" in
--ldlibs)
printf '%s\n' "$LDLIBS"
- ;;
+ ;;
esac