summaryrefslogtreecommitdiffstats
path: root/build/cc.sh
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-08-28 17:13:54 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-08-28 17:33:19 -0400
commit8ca167ee93d4a79f1f24bd959de8b85183577064 (patch)
tree1a9299832a004eff16bbdedcab6b00e45061f7af /build/cc.sh
parentbfbe6851afd2eb5b40b23dcb7ce6a9422b0f17fa (diff)
downloadbfs-8ca167ee93d4a79f1f24bd959de8b85183577064.tar.xz
build: Move per-file flag support into cc.sh
Diffstat (limited to 'build/cc.sh')
-rwxr-xr-xbuild/cc.sh24
1 files changed, 21 insertions, 3 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