diff mbox series

[RFC,06/11] kbuild: set $dry_run when running in --dry-run mode

Message ID 20240819160309.2218114-7-vegard.nossum@oracle.com (mailing list archive)
State New
Headers show
Series output a valid shell script when running 'make -n' | expand

Commit Message

Vegard Nossum Aug. 19, 2024, 4:03 p.m. UTC
Add a convenience variable that allows us to use 'ifdef dry_run...endif'
in Makefiles or '[ -v dry_run ]' in shell scripts to test whether make
was invoked with '-n'.

See [1] for an explanation of this particular construction.

[1]: https://www.gnu.org/software/make/manual/make.html#Testing-Flags

Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
---
 Makefile | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 58f3843ccfac6..953951157ec92 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,11 @@  $(if $(filter __%, $(MAKECMDGOALS)), \
 PHONY := __all
 __all:
 
+# Was make invoked with --dry-run/-n? Record this in a convenience variable.
+ifeq (n,$(findstring n,$(firstword -$(MAKEFLAGS))))
+export dry_run := 1
+endif
+
 # We are using a recursive build, so we need to do a little thinking
 # to get the ordering right.
 #