Commit 0418fa9c

0418fa9c2d50Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Fix '-j forced in makefile' jobserver warning on recursive make

The default-parallelism logic (MAKEFLAGS += -j) re-fired in every sub-make, and re-forcing -j while the parent's jobserver is active makes GNU Make warn and reset the jobserver. The old --jobserver-auth guard didn't help: that flag isn't present in MAKEFLAGS at a sub-make's parse time. Gate the default on MAKELEVEL==0 so only the top-level invocation sets -j; sub-makes inherit the jobserver cleanly (still parallel, no warning). A command-line -jN still wins by precedence.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
0418fa9c2d50
Parent
cd6106b9b2cf

common.mkmodifiedView file

@@ -69,13 +69,20 @@
6969 TIMEOUT10 := $(if $(TIMEOUT_BIN),$(TIMEOUT_BIN) 10,)
7070 TIMEOUT60 := $(if $(TIMEOUT_BIN),$(TIMEOUT_BIN) 60,)
7171
72-# Default -j to logical CPU count when MAKEFLAGS doesn't already carry a
73-# -j flag (covers `-j N` / `-jN`, the short-flag-cluster form, and Make
74-# 4.x's `--jobserver-auth=…`). GNU Make 3.81 reports MAKEFLAGS empty at
75-# parse time, so the guard always fires there.
76-ifeq (,$(filter -j%,$(MAKEFLAGS))$(findstring j,$(firstword -$(MAKEFLAGS)))$(filter --jobserver%,$(MAKEFLAGS)))
72+# Default to a parallel build at the logical CPU count, unless the
73+# invocation already asked for a job count. Applied ONLY at the top level
74+# (MAKELEVEL 0): a sub-make inherits the parent's jobserver, and forcing
75+# -j again in a sub-make's MAKEFLAGS triggers GNU Make's "-j forced in
76+# makefile: resetting jobserver mode" warning (the --jobserver-auth flag
77+# isn't visible in MAKEFLAGS at sub-make parse time, so a plain -j guard
78+# can't see it — MAKELEVEL is the reliable discriminator). A command-line
79+# -jN still wins by precedence; the env form `MAKEFLAGS=-jN` is honored
80+# by the inner guard.
81+ifeq ($(MAKELEVEL),0)
82+ifeq (,$(filter -j%,$(MAKEFLAGS))$(findstring j,$(firstword -$(MAKEFLAGS))))
7783 MAKEFLAGS += -j$(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)
7884 endif
85+endif
7986
8087 # Reference Ruby for test/bench output comparison. Override on the command
8188 # line to use a freshly-built interpreter, e.g. `REF_RUBY=miniruby make test`.