hn.today

Recursive `Make` and `-J`

quuxplusone.github.io25 points12 comments
Screenshot of Recursive `Make` and `-J`

This examines what happens when a Makefile recipe invokes make in a subdirectory (recursive make) while the top-level make is run with -j. Tests with small example Makefiles show that child makes often do not inherit the parent's jobserver tokens, so a parallel build like make -j4 may issue warnings and run subjobs serially or with a different parallelism than expected. The author ran the same tests across GNU Make 3.81, 4.0, 4.2.1 and 4.3 and recorded how many recipes ran concurrently for several recipe forms (plain make, +make, $(MAKE), and variants that force -j in the submake). Some recipe idioms are flagged as non-portable because their behavior changes between versions.

The findings show concrete version differences: older Make (3.81) often behaved as expected, while 4.0 introduced warnings such as "jobserver unavailable: using -j1" and "-jN forced in submake: disabling jobserver mode." 4.2.1/4.3 adjusted those messages and behavior further, sometimes restoring unlimited parallelism for particular patterns. Prefixing a recipe with + or invoking $(MAKE) will forward the jobserver and avoid the first warning, but they do not eliminate warnings about "resetting jobserver mode." There is no single portable configuration that achieves the ideal of inheriting the parent's processor count in all versions, so using $(MAKE) and avoiding fragile recursive idioms is the practical recommendation.

Read on quuxplusone.github.io12 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.