diff mbox series

[RFC,07/11] kbuild: define 'make' as a no-op in --dry-run mode

Message ID 20240819160309.2218114-8-vegard.nossum@oracle.com (mailing list archive)
State Handled Elsewhere
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
Output 'make() { :; }' at the start of the script in order to make
all 'make' invocations in the resulting build script no-ops (GNU Make
will actually execute -- and print -- all recipe lines that include
$(MAKE), even when invoked with -n).

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

Comments

Nicolas Schier Nov. 14, 2024, 10:47 a.m. UTC | #1
On Mon, Aug 19, 2024 at 06:03:04PM +0200, Vegard Nossum wrote:
> Output 'make() { :; }' at the start of the script in order to make
> all 'make' invocations in the resulting build script no-ops (GNU Make
> will actually execute -- and print -- all recipe lines that include
> $(MAKE), even when invoked with -n).
> 
> Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
> ---
>  Makefile | 6 ++++++
>  1 file changed, 6 insertions(+)

Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 953951157ec92..d08ade5791c2e 100644
--- a/Makefile
+++ b/Makefile
@@ -226,6 +226,12 @@  $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
 
 # Invoke a second make in the output directory, passing relevant variables
 __sub-make:
+ifdef dry_run
+	# define 'make' as a no-op alias so that those commands are not
+	# actually run
+	@make() { :; }
+	@export -f make
+endif
 	$(Q)$(MAKE) $(no-print-directory) -C $(abs_objtree) \
 	-f $(abs_srctree)/Makefile $(MAKECMDGOALS)