I'm aware that the behavior of MAKEFLAGS wrt -j is a little unusual, however I was still surprised by the result of the following simulation of a recursive make with -j and haven't found anything in the manual to support it:
% cat Makefile
level ?= 0
$(info At level $(level) MAKEFLAGS=$(MAKEFLAGS) (info))
all:
@echo "At level $(level) MAKEFLAGS=$(MAKEFLAGS) (recipe)"
ifneq ($(level),2)
@$(MAKE) --no-print level=$(shell expr $(level) + 1)
endif
% make-4.2.1 -j12
At level 0 MAKEFLAGS= (info)
At level 0 MAKEFLAGS= -j12 --jobserver-auth=3,4 (recipe)
At level 1 MAKEFLAGS= --no-print-directory (info)
At level 1 MAKEFLAGS= -j12 --jobserver-auth=3,4 --no-print-directory -- level=1 (recipe)
At level 2 MAKEFLAGS= --no-print-directory (info)
At level 2 MAKEFLAGS= -j12 --jobserver-auth=3,4 --no-print-directory -- level=2 (recipe)
There are two separate issues here: first, that MAKEFLAGS isn't visible at all in the top level. This I seem to recall reading about before and wasn't surprised. Second, that -j is hidden, except in recipes, all the way down. This seems unfortunate and I can't think of why it would be a feature, though it probably is.
Section 5.7.3 "Communicating Options to a Sub-make" says that -j is a special case but says nothing about this recipe-vs-internal difference. Similarly 7.3 "Conditionals that Test Flags" uses MAKEFLAGS as its example but doesn't say "don't try this with -j". I think both these sections could use a little verbiage on the topic but I don't want to contribute anything without understanding the background.
Thanks,
David