summaryrefslogtreecommitdiffstats
path: root/build/cc.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build/cc.sh')
-rwxr-xr-xbuild/cc.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/build/cc.sh b/build/cc.sh
new file mode 100755
index 0000000..e1d2b0b
--- /dev/null
+++ b/build/cc.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# Copyright © Tavian Barnes <tavianator@tavianator.com>
+# SPDX-License-Identifier: 0BSD
+
+# 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
+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 "$@" $EXTRA_FLAGS $XLDLIBS