summaryrefslogtreecommitdiffstats
path: root/build
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
parent37caa3d71fd8bb4d0d9204e4a2f5cac234fa25fd (diff)
downloadbfs-1f06941a7cc586c78152ca67dec0551106977b08.tar.xz
build: Listen to make -s
Diffstat (limited to 'build')
-rw-r--r--build/config.mk8
-rw-r--r--build/deps.mk8
-rw-r--r--build/flags.mk8
-rw-r--r--build/header.mk21
-rwxr-xr-xbuild/msg-if.sh21
-rwxr-xr-xbuild/msg.sh60
-rw-r--r--build/pkgs.mk13
-rw-r--r--build/prelude.mk21
8 files changed, 112 insertions, 48 deletions
diff --git a/build/config.mk b/build/config.mk
index 153838d..24873ec 100644
--- a/build/config.mk
+++ b/build/config.mk
@@ -43,20 +43,20 @@ gen/vars.mk::
# Sets the build flags. This depends on vars.mk and uses a recursive make so
# that the default flags can depend on variables like ${OS}.
gen/flags.mk: gen/vars.mk
- @+${MAKE} -sf build/flags.mk $@
+ @+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/flags.mk $@
.PHONY: gen/flags.mk
# Check for dependency generation support
gen/deps.mk: gen/flags.mk
- @+${MAKE} -sf build/deps.mk $@
+ @+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/deps.mk $@
.PHONY: gen/deps.mk
# Auto-detect dependencies and their build flags
gen/pkgs.mk: gen/flags.mk
- @+${MAKE} -sf build/pkgs.mk $@
+ @+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/pkgs.mk $@
.PHONY: gen/pkgs.mk
# Compile-time feature detection
gen/config.h: gen/config.mk
- @+${MAKE} -sf build/header.mk $@
+ @+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/header.mk $@
.PHONY: gen/config.h
diff --git a/build/deps.mk b/build/deps.mk
index e8dd9fb..3db62b6 100644
--- a/build/deps.mk
+++ b/build/deps.mk
@@ -10,9 +10,9 @@ include build/exports.mk
gen/deps.mk::
${MSG} "[ GEN] $@"
- printf '# %s\n' "$@" >$@
- if build/cc.sh -MD -MP -MF /dev/null build/empty.c; then \
- printf 'DEPFLAGS := -MD -MP\n'; \
+ @printf '# %s\n' "$@" >$@
+ @if build/cc.sh -MD -MP -MF /dev/null build/empty.c; then \
+ printf 'CPPFLAGS += -MD -MP\n'; \
fi >>$@ 2>$@.log
${VCAT} $@
- printf -- '-include %s\n' ${OBJS:.o=.d} >>$@
+ @printf -- '-include %s\n' ${OBJS:.o=.d} >>$@
diff --git a/build/flags.mk b/build/flags.mk
index 0a44e94..c911b22 100644
--- a/build/flags.mk
+++ b/build/flags.mk
@@ -101,14 +101,14 @@ export RELEASE_CPPFLAGS=${RELEASE_CPPFLAGS,${_RELEASE}}
export RELEASE_CFLAGS=${RELEASE_CFLAGS,${_RELEASE}}
# Set a variable
-SETVAR = printf '%s := %s\n' >>$@
+SETVAR = @printf '%s := %s\n' >>$@
# Append to a variable, if non-empty
-APPEND = append() { test -z "$$2" || printf '%s += %s\n' "$$1" "$$2" >>$@; }; append
+APPEND = @append() { test -z "$$2" || printf '%s += %s\n' "$$1" "$$2" >>$@; }; append
gen/flags.mk::
${MSG} "[ GEN] $@"
- printf '# %s\n' "$@" >$@
+ @printf '# %s\n' "$@" >$@
${SETVAR} CPPFLAGS "$$BFS_CPPFLAGS"
${APPEND} CPPFLAGS "$$TSAN_CPPFLAGS"
${APPEND} CPPFLAGS "$$LINT_CPPFLAGS"
@@ -132,5 +132,5 @@ gen/flags.mk::
${APPEND} LDLIBS "$$EXTRA_LDLIBS"
${APPEND} LDLIBS "$$BFS_LDLIBS"
${SETVAR} NOLIBS "$$XNOLIBS"
- test "${OS}-${SAN}" != FreeBSD-y || printf 'POSTLINK = elfctl -e +noaslr $$@\n' >>$@
+ @test "${OS}-${SAN}" != FreeBSD-y || printf 'POSTLINK = elfctl -e +noaslr $$@\n' >>$@
${VCAT} $@
diff --git a/build/header.mk b/build/header.mk
index 3f77ca5..951f09b 100644
--- a/build/header.mk
+++ b/build/header.mk
@@ -48,12 +48,12 @@ PKG_HEADERS := ${ALL_PKGS:%=gen/use/%.h}
gen/config.h: ${PKG_HEADERS} ${HEADERS}
${MSG} "[ GEN] $@"
- printf '// %s\n' "$@" >$@
- printf '#ifndef BFS_CONFIG_H\n' >>$@
- printf '#define BFS_CONFIG_H\n' >>$@
- cat ${.ALLSRC} >>$@
- printf '#endif // BFS_CONFIG_H\n' >>$@
- cat ${.ALLSRC:%=%.log} >$@.log
+ @printf '// %s\n' "$@" >$@
+ @printf '#ifndef BFS_CONFIG_H\n' >>$@
+ @printf '#define BFS_CONFIG_H\n' >>$@
+ @cat ${.ALLSRC} >>$@
+ @printf '#endif // BFS_CONFIG_H\n' >>$@
+ @cat ${.ALLSRC:%=%.log} >$@.log
${VCAT} $@
.PHONY: gen/config.h
@@ -61,9 +61,6 @@ gen/config.h: ${PKG_HEADERS} ${HEADERS}
SLUG = ${@:gen/%.h=%}
${HEADERS}::
- ${MKDIR} ${@D}
- if build/define-if.sh ${SLUG} build/cc.sh build/${SLUG}.c >$@ 2>$@.log; then \
- test "${IS_V}" || printf '[ CC ] %-${MSG_WIDTH}s ✔\n' ${SLUG}.c; \
- else \
- test "${IS_V}" || printf '[ CC ] %-${MSG_WIDTH}s ✘\n' ${SLUG}.c; \
- fi
+ @${MKDIR} ${@D}
+ @build/define-if.sh ${SLUG} build/cc.sh build/${SLUG}.c >$@ 2>$@.log; \
+ build/msg-if.sh "[ CC ] ${SLUG}.c" test $$? -eq 0
diff --git a/build/msg-if.sh b/build/msg-if.sh
new file mode 100755
index 0000000..8112aea
--- /dev/null
+++ b/build/msg-if.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# Copyright © Tavian Barnes <tavianator@tavianator.com>
+# SPDX-License-Identifier: 0BSD
+
+# Print a success/failure indicator from a makefile:
+#
+# $ ./configure
+# [ CC ] use/liburing.c ✘
+# [ CC ] use/oniguruma.c ✔
+
+set -eu
+
+MSG="$1"
+shift
+
+if "$@"; then
+ build/msg.sh "$(printf '%-37s ✔' "$MSG")"
+else
+ build/msg.sh "$(printf '%-37s ✘' "$MSG")"
+fi
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
+
+"$@"
diff --git a/build/pkgs.mk b/build/pkgs.mk
index 51ca664..39b550d 100644
--- a/build/pkgs.mk
+++ b/build/pkgs.mk
@@ -12,8 +12,8 @@ HEADERS := ${ALL_PKGS:%=gen/use/%.h}
gen/pkgs.mk: ${HEADERS}
${MSG} "[ GEN] $@"
- printf '# %s\n' "$@" >$@
- gen() { \
+ @printf '# %s\n' "$@" >$@
+ @gen() { \
printf 'PKGS := %s\n' "$$*"; \
printf 'CFLAGS += %s\n' "$$(build/pkgconf.sh --cflags "$$@")"; \
printf 'LDFLAGS += %s\n' "$$(build/pkgconf.sh --ldflags "$$@")"; \
@@ -28,9 +28,6 @@ gen/pkgs.mk: ${HEADERS}
PKG = ${@:gen/use/%.h=%}
${HEADERS}::
- ${MKDIR} ${@D}
- if build/define-if.sh use/${PKG} build/pkgconf.sh ${PKG} >$@ 2>$@.log; then \
- test "${IS_V}" || printf '[ CC ] %-${MSG_WIDTH}s ✔\n' use/${PKG}.c; \
- else \
- test "${IS_V}" || printf '[ CC ] %-${MSG_WIDTH}s ✘\n' use/${PKG}.c; \
- fi
+ @${MKDIR} ${@D}
+ @build/define-if.sh use/${PKG} build/pkgconf.sh ${PKG} >$@ 2>$@.log; \
+ build/msg-if.sh "[ CC ] use/${PKG}.c" test $$? -eq 0;
diff --git a/build/prelude.mk b/build/prelude.mk
index b235fa9..5be26cb 100644
--- a/build/prelude.mk
+++ b/build/prelude.mk
@@ -44,33 +44,22 @@ TRUTHY,y := y
TRUTHY,1 := y
# Boolean operators are also implemented with nested expansion
-NOT, := y
+NOT, := y
# Normalize ${V} to either "y" or ""
-IS_V := ${TRUTHY,${V}}
+export XV=${TRUTHY,${V}}
# Suppress output unless V=1
Q, := @
-Q := ${Q,${IS_V}}
+Q := ${Q,${XV}}
# Show full commands with `make V=1`, otherwise short summaries
-MSG = @msg() { \
- MSG="$$1"; \
- shift; \
- test "${IS_V}" || printf '%s\n' "$$MSG"; \
- test "$${1:-}" || return 0; \
- test "${IS_V}" && printf '%s\n' "$$*"; \
- "$$@"; \
- }; \
- msg
-
-# Maximum width of a short message, to align the ✔/✘
-MSG_WIDTH := 30
+MSG = @build/msg.sh
# cat a file if V=1
VCAT,y := @cat
VCAT, := @:
-VCAT := ${VCAT,${IS_V}}
+VCAT := ${VCAT,${XV}}
# All external dependencies
ALL_PKGS := \