Makefile fails when CygWin in Path

0

I'm trying to figure out why a simple Windows command in makefile fails only when the CygWin binary folder is included in the PATH variable.

To take most variables out of the equation I'm using the barebone makefile below:

clean:
    del /F /Q file.txt

I'm running GNU make 3.81 from a directory that contains only make.exe and makefile.

C:\temp\test>dir /b
make.exe
makefile

C:\temp\test>make -v
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for Windows32

When PATH includes the Cygwin binary folder, I get a ProcessCreate() error.

C:\temp\test>path=c:\tools\cygwin\bin

C:\temp\test>make clean
del /F /Q file.txt
process_begin: CreateProcess(NULL, del /F /Q file.txt, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [clean] Error 2

It works as expected, otherwise.

C:\temp\test>set path=

C:\temp\test>make clean
del /F /Q file.txt
Could Not Find C:\temp\test\file.txt

This makes no sense to me.
Any idea what could be happening here?

user4233

Posted 2017-01-09T20:12:08.947

Reputation:

2I think I know what the problem is here. I'm not giving you an answer (because this is not the right site for this question, and I don't want to encourage more questions on the wrong site) but I will suggest that you look up what PATH does, then have a look through the cygwin/bin directory. – wizzwizz4 – 2017-01-09T20:48:43.633

Answers

1

I've made some progress after more experiments and reading. I think I understand the logic now.

It appears that all recipe commands in the makefile are exclusively shell commands once sh.exe in in the PATH. They cannot be windows commands.

After removing sh.exe from cygwin/bin, the original makefile worked as I expected. 'cmd' can also be explicitly specified instead of the default 'sh' in the makefile as follows:

clean:
    cmd /c 'del /F /Q file.txt'

If this is correct, this is a bit disappointing. By having cygwin/bin in the 'PATH', I was assuming either type of commands could be used in the makefile, just like on the windows commands or in batch file.

What still does not make great sense to me is that windows commands work when sh.exe is not in reach. Still missing part of the logic.

(sorry for posting on the wrong site, thought I was on stackoverflow. If moderator can move or delete this post, please do.

Hector Psih

Posted 2017-01-09T20:12:08.947

Reputation: 11

I moved this to Super User because it belongs here, not [so] (it's not specifically a programming question). If you are the same user who posted this question, please make sure you're logged in before posting in future. – wizzwizz4 – 2017-01-10T08:11:55.573