1

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
Jonny
  • 842
  • 5
  • 14
  • 1
    You're not showing any relevant code, but `$(MAKE) -$(MAKEFLAGS)` will inherit flags like `-s` and `-n` (and not propagating `MAKEFLAGS` will not). – tripleee May 19 '22 at 10:15
  • Turn that into an answer and I'll mark solved - that was it. Everyone said to use `$(MAKE)` but never mentioned `MAKEFLAGS`! – Jonny May 19 '22 at 11:53
  • Adding `MAKEFLAGS` to the sub-make invocation is not correct and you should not do it. If you need this, then something else is wrong with your makefiles. Since you haven't provided us any reproducible test case or shown us rules that are run when they shouldn't be, there's not much else we can say. – MadScientist May 19 '22 at 13:37
  • It's a fairly extensive codebase on private repos, so I cannot directly share – Jonny May 19 '22 at 15:35
  • I wasn't suggesting you share the entire thing, just relevant parts (we won't have the energy to go through a complex setup anyway). But if you can't reproduce it with a simple setup then clearly there's something deeper wrong that's not described here so we can't help. – MadScientist May 19 '22 at 19:10

1 Answers1

1

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.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Adding `-$(MAKEFLAGS)` fixes it in my case. I have run your example and it indeed behaves as you say, even with `.ONESHELL`, `.SHELLFLAGS` and the rest. Each invocation to make is as `$(MAKE) `, usually after some conditional check. I'll continue to try to produce a minimal example that shows the failure but struggling to see what would cause it so far – Jonny May 19 '22 at 15:34