Skip to content

Fix make shell detection - #6146

Merged
raysan5 merged 2 commits into
raysan5:masterfrom
Peter0x44:fix-make-shell-detection
Sep 12, 2026
Merged

Fix make shell detection#6146
raysan5 merged 2 commits into
raysan5:masterfrom
Peter0x44:fix-make-shell-detection

Conversation

@Peter0x44

Copy link
Copy Markdown
Contributor

Fixes #6135.

The Makefiles assume Windows means cmd, but GNU Make can select sh
instead. This causes make clean to use the wrong shell commands.

Detect the recipe shell using echo "test": cmd preserves the quotes,
while sh removes them. Apply this to the library, examples and tools,
and remove the forced cmd shell from library cleanup. Explicit
PLATFORM_SHELL overrides remain supported.

Also fix Win32 clean recipe indentation and,
pass rlparser's recursive make variables as command-line arguments
so those calls work under both cmd and sh.

GNU Make on Windows may use sh even when invoked from cmd. Probe how
echo handles quotes instead of choosing shell syntax from the target OS.

Apply this to the library, examples and tools, preserving explicit
PLATFORM_SHELL overrides. Stop forcing cmd for library cleanup and fix
Win32 recipe indentation.
The form FORMAT=JSON EXTENSION=json $(MAKE) parse uses sh environment
assignments. Under cmd, FORMAT=JSON is treated as a command and fails.

Use $(MAKE) parse FORMAT=JSON EXTENSION=json instead. This passes the
variables directly to make and works under both shells.
@emecdelam

Copy link
Copy Markdown

For curiosity, are there any reasons to use echo "test" instead of just finding the executable? something like

ifeq ($(OS),Windows_NT)
    ifeq ($(findstring sh.exe,$(SHELL)),sh.exe)
        DETECTED_SHELL := sh
    else
        DETECTED_SHELL := cmd
    endif
else
    DETECTED_SHELL := sh
endif

@Peter0x44

Peter0x44 commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Actually, my blogpost is a little wrong on this point. Make DOES report sh.exe in SHELL (it's not unset), but it's not consistent.

This is maybe a GNU make bug, but if you run make without an sh.exe on your PATH it will still report that it using sh (despite that it is NOT). Probably could be patched, but these buggy makes are of course going to be very widespread.

I still think it's the correct approach for this PR.

@Peter0x44

Copy link
Copy Markdown
Contributor Author
   Configuration         $(SHELL)       $(shell echo "test")
  ━━━━━━━━━━━━━━━━━━━━  ━━━━━━━━━━━━━  ━━━━━━━━━━━━━━━━━━━━━━
   sh on PATH            C:/…/sh.exe    test
  ────────────────────  ─────────────  ──────────────────────
   No sh on PATH         sh.exe         "test"
  ────────────────────  ─────────────  ──────────────────────
   Explicit SHELL=sh     sh             test
  ────────────────────  ─────────────  ──────────────────────
   Explicit SHELL=cmd    cmd            "test"

@raysan5
raysan5 merged commit a414da3 into raysan5:master Sep 12, 2026
17 checks passed
@raysan5

raysan5 commented Sep 12, 2026

Copy link
Copy Markdown
Owner

@Peter0x44 thanks for the review and the explanation!

@Peter0x44
Peter0x44 deleted the fix-make-shell-detection branch September 12, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[build][Make] make clean not working correctly for me when running from mingw64 shell

3 participants