How does GNU make decide if it runs a line from a rule directly or via a batch file? I'm using GNU Make v3.80 on Windows Server 2008 platform, so my shell is cmd.exe.
Switching on debugging (-d) and noticed that some lines from within a rule are not run via a sub-shell (batch in my case as using cmd.exe) but appear to be called directly by make.
See example below. See how the xcopy command is run directly:
CreateProcess(C:\Windows\system32\xcopy.exe,xcopy /?,...)
But the echo command is run via a batch file:
Creating temporary batch file C:\Users\fbloggs\AppData\Local\Temp\95\make732002.bat
Example makefile:
stackoverflow :
xcopy /?
@echo Done
Full dDebug output:
GNU Make 3.80 Tool Version v1.3 build for Linux on 20060503
Copyright (C) 2002 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.
find_and_set_shell path search set default_shell = C:/Windows/System32/cmd.exe
Reading makefiles...
Reading makefile `..\..\..\pi_scripts\make\make_shell.mak'...
Updating makefiles....
Considering target file `..\..\..\pi_scripts\make\make_shell.mak'.
Looking for an implicit rule for `..\..\..\pi_scripts\make\make_shell.mak'.
No implicit rule found for `..\..\..\pi_scripts\make\make_shell.mak'.
Finished prerequisites of target file `..\..\..\pi_scripts\make\make_shell.mak'.
No need to remake target `..\..\..\pi_scripts\make\make_shell.mak'.
Updating goal targets....
Considering target file `stackoverflow'.
File `stackoverflow' does not exist.
Finished prerequisites of target file `stackoverflow'.
Must remake target `stackoverflow'.
xcopy /?
CreateProcess(C:\Windows\system32\xcopy.exe,xcopy /?,...)
Putting child 0x025dc670 (stackoverflow) PID 39739552 on the chain.
Live child 0x025dc670 (stackoverflow) PID 39739552
Copies files and directory trees.
NOTE: Xcopy is now deprecated, please use Robocopy.
XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
[/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/B]
[/EXCLUDE:file1[+file2][+file3]...]
source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
<snip>
Reaping winning child 0x025dc670 PID 39739552
Creating temporary batch file C:\Users\fbloggs\AppData\Local\Temp\95\make732002.bat
CreateProcess(C:\Users\fbloggs\AppData\Local\Temp\95\make732002.bat,C:\Users\fbloggs\AppData\Local\Temp\95\make732002.bat,...)
Live child 0x025dc670 (stackoverflow) PID 39739552
Done
Reaping winning child 0x025dc670 PID 39739552
Cleaning up temp batch file C:\Users\fbloggs\AppData\Local\Temp\95\make732002.bat
Removing child 0x025dc670 PID 39739552 from chain.
Successfully remade target file `stackoverflow'.
echo
, does it? – keltarecho
withoutcmd
, because there is no such program. But anyway, - makefile recipes uses shell syntax; if make is completely sure it can avoid using shell here, it is free to do so. – keltar