summaryrefslogtreecommitdiffstats
path: root/build/msg.sh
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-04-30 15:07:06 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-04-30 15:07:06 -0400
commit1f06941a7cc586c78152ca67dec0551106977b08 (patch)
tree4ebedfe5ed59fafae32e337eff73758828ff82f7 /build/msg.sh
parent37caa3d71fd8bb4d0d9204e4a2f5cac234fa25fd (diff)
downloadbfs-1f06941a7cc586c78152ca67dec0551106977b08.tar.xz
build: Listen to make -s
Diffstat (limited to 'build/msg.sh')
-rwxr-xr-xbuild/msg.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/build/msg.sh b/build/msg.sh
new file mode 100755
index 0000000..8b4714e
--- /dev/null
+++ b/build/msg.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Copyright © Tavian Barnes <tavianator@tavianator.com>
+# SPDX-License-Identifier: 0BSD
+
+# Print a message from a makefile:
+#
+# $ make -s
+# $ make
+# [ CC ] src/main.c
+# $ make V=1
+# cc -Isrc -Igen -D...
+
+set -eu
+
+# Get the $MAKEFLAGS from the top-level make invocation
+MFLAGS="${XMAKEFLAGS-${MAKEFLAGS-}}"
+
+# Check if make should be quiet (make -s)
+is_quiet() {
+ # GNU make puts single-letter flags in the first word of $MAKEFLAGS,
+ # without a leading dash
+ case "${MFLAGS%% *}" in
+ -*) : ;;
+ *s*) return 0 ;;
+ esac
+
+ # BSD make puts each flag separately like -r -s -j 48
+ for flag in $MFLAGS; do
+ case "$flag" in
+ # Ignore things like --jobserver-auth
+ --*) continue ;;
+ -*s*) return 0 ;;
+ esac
+ done
+
+ return 1
+}
+
+# Check if make should be loud (make V=1)
+is_loud() {
+ test "$XV"
+}
+
+MSG="$1"
+shift
+
+if ! is_quiet && ! is_loud; then
+ printf '%s\n' "$MSG"
+fi
+
+if [ $# -eq 0 ]; then
+ exit
+fi
+
+if is_loud; then
+ printf '%s\n' "$*"
+fi
+
+"$@"