treewide: reduce usage of shell in Makefiles - #22669
Open
basilfx wants to merge 7 commits into
Open
Conversation
With their intended use, both produce the same result, but notdir does not spawn a subprocess.
basilfx
requested review from
MichelRottleuthner,
aabadie,
benpicco,
dylad,
keestux,
leandrolanzieri,
nandojve and
vincent-d
as code owners
September 6, 2026 22:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
Using
$(shell ..)in Makefiles spawns a subprocess, which is less performant than built-in alternatives. Recalling #13174 from before, I let Claude analyze where this may improve on current master.An overview:
$(shell basename $(CURDIR))works the same as$(notdir $(CURDIR))(unless$(CURDIR)equals/)uppercase_and_underscorecan be used instead oftr a-z- A-Z_The impact will be unnoticeable for a single build and will probably be in the noise when actual compilation takes the overhand. But (hopefully) it will be more noticeable for CI builds with warmer caches. I don't expect miracles, and it started as an experiment.
To give an idea of the improvement (I let Claude do the benchmarking) on my server (i5 14600K with 64 GiB of memory):
For
make -j1(rebuild, so warm cache):For
make -j8(rebuild, so warm cache):Testing procedure
This should not impact the builds. The end result should be the same.
To count subprocessed, one can use for example
strace -f -qq -e trace=execve -o trace.txt make BOARD=nucleo-f767zi all. Then count the number ofexecvein the output file.Issues/PRs references
None
Declaration of AI-Tools / LLMs usage:
AI-Tools / LLMs that were used are:
strings.mk) and performing benchmarks. I have read an understand every line changed, but I am not a Makefile export, and it can probably be better.