Skip to content

treewide: reduce usage of shell in Makefiles - #22669

Open
basilfx wants to merge 7 commits into
RIOT-OS:masterfrom
basilfx:feature/remove_makefile_shell
Open

treewide: reduce usage of shell in Makefiles#22669
basilfx wants to merge 7 commits into
RIOT-OS:masterfrom
basilfx:feature/remove_makefile_shell

Conversation

@basilfx

@basilfx basilfx commented Sep 6, 2026

Copy link
Copy Markdown
Member

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_underscore can be used instead of tr a-z- A-Z_
  • Use memoization for flags re-evaluated multiple times

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):

App / board base head saving execve base → head
hello-world / nucleo-f767zi 2.30 s 0.66 s −71% 651 → 207 (−68%)
gnrc networking / nucleo-f767zi 3.23 s 1.10 s −66% 807 → 311 (−61%)
hello-world / samr21-xpro 1.19 s 0.65 s −46% 314 → 209 (−33%)
hello-world / native 0.54 s 0.41 s −23% 197 → 174 (−12%)

For make -j8 (rebuild, so warm cache):

App / board base head saving
hello-world / nucleo-f767zi 2.50 s 1.72 s −31%
gnrc networking / nucleo-f767zi 4.83 s 3.68 s −24%
hello-world / samr21-xpro 1.52 s 1.26 s −17%
hello-world / native 0.52 s 0.56 s ~0 (noise)

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 of execve in the output file.

Issues/PRs references

None

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • Claude Code Opus 5 for coming up with alternatives (especially 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.

@basilfx basilfx added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 6, 2026
@github-actions github-actions Bot added Platform: native Platform: This PR/issue effects the native platform Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: tests Area: tests and testing framework Area: build system Area: Build system Area: pkg Area: External package ports Area: cpu Area: CPU/MCU ports Area: toolchain Area: toolchains; everything related to compilation, libc, linking, … labels Sep 6, 2026
@basilfx basilfx added the AI: Co-Authored PR/Issue relies on AI. Documentation / Code was partly generated by AI. label Sep 6, 2026
@riot-ci

riot-ci commented Sep 6, 2026

Copy link
Copy Markdown

Murdock results

✔️ PASSED

ccc1ea2 tests/build_system/utils: add tests

Success Failures Total Runtime
11285 0 11286 15m:38s

Artifacts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Co-Authored PR/Issue relies on AI. Documentation / Code was partly generated by AI. Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Area: pkg Area: External package ports Area: tests Area: tests and testing framework Area: toolchain Area: toolchains; everything related to compilation, libc, linking, … CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Platform: native Platform: This PR/issue effects the native platform Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants