GNU make recursive dry run runs commands

284 Views Asked by At

I have a makefile that includes several other makefiles and uses recursive make in numerous places.

I'm trying to have make print its database of targets (-p) without running them. This should simply be achievable with make -pn, however it isn't working. The recipes are being run despite -n being passed.

  • I've checked many times and every invocation of make inside every file is via $(MAKE), so I would expect this to work.

  • Removing -p makes no difference, make --dry-run still executes commands.

  • The issue appears to affect all makes, not just sub-makes.

Is there anything I'm missing? I'm on GNU Make 4.3 on Alpine.

I'm using these special variables/targets which may affect the outcome:

.ONESHELL:
.SILENT:
SHELL = /bin/bash
.SHELLFLAGS = -o pipefail -exc

export MAKELEVEL
1

There are 1 best solutions below

1
On

Here's a quick example to prove that it works as expected:

$ cat Makefile
all: ; $(MAKE) recurse

recurse: ; @echo hi

Now run without -n:

$ make
make recurse
hi

We can see the recipe was run and the shell echos hi. Now run with -n:

$ make -n
make recurse
echo hi

Here it prints the command to run, but doesn't actually run it.

No need to add -$(MAKEFLAGS) to the sub-make invocation.