Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Windows commands (e.g. del) from a GNU makefile

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.

like image 591
TomLongridge Avatar asked Mar 17 '10 14:03

TomLongridge


2 Answers

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
like image 182
TomLongridge Avatar answered Nov 15 '22 18:11

TomLongridge


Because DOS-based systems have two different commands for removing files and directories, I find that having two different defines works the 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)
like image 45
jpsecher Avatar answered Nov 15 '22 20:11

jpsecher