Search code examples
windows-10mingwgnu-make

Why does make.exe try to run /usr/bin/sh on Windows?


I have recently moved from Window 7 to Windows 10 and I cannot get my makefiles to work anymore.

I have been using the GNU Make for Windows

The first thing that I noticed was that it had started treating Windows folder dividers (backslash characters '\') as line continuation characters, so I modified the 'clean' section as shown below to use forward slash '/' characters instead:

clean:
    del $(ObjDir)/*.o

When I call make -ftest.mak clean I get the following error which suggests it is now trying to run in a MinGw/Cygwin environment:

c:\Test\Source>make -ftest.mak clean
del obj/*.o
/usr/bin/sh: del: command not found
make: *** [clean] Error 127

I do have MinGw folder on my PC (which I have renamed to stop make looking for it) and I can't see any 'MingGw' related environment variables in my Cmd.exe environment or PATH

How can I get make working so it doesn't try executing sh under Windows?

Is there some configuration parameter somewhere that makes it call sh instead of cmd.exe?

Update: Just tried running make -d which logs debug output. It looks as though it is using my Git folder as some sort of root folder:

Must remake target `clean'.
del obj/*.o
CreateProcess(NULL,C:/Program Files/Git/usr/bin/sh.exe -c "del obj/*.o",...)
Putting child 0x006e7fc0 (clean) PID 7234712 on the chain.

Solution

  • The cleanest way is to specify SHELL on command line.

    make -ftest.mak clean SHELL=cmd
    

    will do the job. ndk-build will do that for you, see your ndk-build.cmd. Don't try to run ndk-build bash script on Windows. The scripts in NDK may go amoc when you run them on Windows in bash.