summaryrefslogtreecommitdiffstats
path: root/build/flags-if.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build/flags-if.sh')
-rwxr-xr-xbuild/flags-if.sh16
1 files changed, 16 insertions, 0 deletions
diff --git a/build/flags-if.sh b/build/flags-if.sh
new file mode 100755
index 0000000..098b2d3
--- /dev/null
+++ b/build/flags-if.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# Copyright © Tavian Barnes <tavianator@tavianator.com>
+# SPDX-License-Identifier: 0BSD
+
+# Add flags to a makefile if a build succeeds
+
+set -eu
+
+FLAGS=$(sed -n '\|^///|{s|^/// ||; s|[^=]*= ||; p}' "$1")
+
+if build/cc.sh "$@" $FLAGS; then
+ sed -n 's|^/// \(.*=.*\)|\1|p' "$1"
+else
+ exit 1
+fi