views:

161

answers:

3

It does not appear to be possible to call Windows system commands (e.g. del, move, etc) using GNU Make. I'm trying to create a makefile that doesn't rely on the user having extra tools (e.g. rm.exe from Cygwin) installed.

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

clean:
   del *.o

This is presumably because there is no such execuatable as "del". I've also tried running it as an option to cmd but with this only seems to open a new prompt:

clean:
    cmd /C del *.o

I'm using Windows XP (5.1.2600) with GNU Make 3.79.1 that is bundled as part of MSys.

+2  A: 

Are you using Cygwin? Why not call rm?

Tom
I'm writing a makefile to go on other users' machines who may not have Cygwin/rm.
TomLongridge
+2  A: 

del is a builtin command of cmd.exe (as well as previously command.com). Your command cmd /C del *.o should work, if it starts a new command prompt I suspect that cmd maybe might be a wrapper. Have you tried to call cmd with its full path (e.g. c:/WINDOWS/system32/cmd.exe)?

hlovdal
It doesn't start a new command prompt window, it prints the MS copyright banner and then stops. Using the full path doesn't have any effect.
TomLongridge
Try quoting the command (i.e. cmd /C "del *.o") - if it doesn't work, try cmd /K to see what the error is (/K will keep the cmd window around till you close it)
Paul Betts
Interestingly it does work with `cmd /K del *.o` however it leaves you in the new session and will only carry on with the makefile when you type `exit`. Quoting doesn't seem to make any difference.
TomLongridge
A: 

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

clean:
    cmd //C del *.o
TomLongridge