Calling Windows commands (such as del) from the make file of GNU files

It is not possible to invoke Windows system commands (e.g. del, move, etc.) using GNU Make. I am trying to create a make file that does not rely on a user who has additional tools installed (e.g. rm.exe from Cygwin).

When the following rule is executed, the del: command not found error is reported:

 clean: del *.o 

This is apparently because there is no such execuatable as "del". I also tried running it as an option for cmd , but with this it just seems like a new prompt opens:

 clean: cmd /C del *.o 

I am using Windows XP (5.1.2600) with GNU Make 3.79.1, which is included with MSys.

+7
windows makefile
source share
7 answers

It seems that the /C switch should be escaped because / interpreted as a path in GNU Make. The following works as expected:

 clean: cmd //C del *.o 
+9
source share

Do you use cygwin? Why not call rm ?

+3
source share

del is the built-in cmd.exe command (as well as previously command.com ). Your cmd /C del *.o command should work if it launches a new command prompt, I suspect cmd might be a shell. Have you tried calling cmd with the full path (e.g. c: /WINDOWS/system32/cmd.exe)?

+3
source share

Since DOS-based systems have two different commands for deleting files and directories, I believe that using two different definitions works best:

 ifeq ($(OS),Windows_NT) RM = cmd //C del //Q //F RRM = cmd //C rmdir //Q //S else RM = rm -f RRM = rm -f -r endif clean: $(RM) $(TARGET).elf $(TARGET).map $(RRM) $(BUILD_DIR) 
+1
source share

Tom Longrig's answer was close to the truth for me, but the escape had to be done using the backslash before the slash on a Windows Vista Business machine, for which I need it:

 RM=cmd \/C del 
0
source share

Another solution is to create a del.bat file containing:

 @echo off del %* 

then makefile might just contain

 clean: del *.o 

this clears the makefile, but may interfere with your build directory a bit.

0
source share

It happened to me. At the top of your makefile, add:

 SHELL=cmd 

Since you are compiling on Windows, select "cmd" as the default shell. This is important because GNU make will look for a path for the linux / unix shell, and if it finds it, it will use it instead. This is the case when cygwin is installed. A side effect of this behavior is that commands such as "del" and "echo" are not found. If we tell GNU make to use "cmd" as our shell, then "del", etc. Will be available.

0
source share

All Articles