Search code examples
makefilevxworksbuildingrm

removing *.o in makefile is not cleaning files


In makefile's clean i have written like rm -rf *.o. But its not cleaning files. If i have given rm -rf libdummy.o then its cleaning it properly. So if I use *, its not working as expected.

clean:
    rm -rf *.o
    rm -rf dummy.a

and the output is


    [exec] rm -rf *.o
    [exec] rm -rf dummy.a

If the folder is having a.o, b.o and dummy.a. After make clean, a.o and b.o presents in that folder itsefl, dummy.a got deleted.

Note : I am executing this make in windows, building for vxworks using tornado 2.2 package. All the commands like make, cd, cp, rm from my makefile is executed from tornado package. There is no file name called clean. More over I have declared clean as PHONY tag also.

Below discussion is different from my problem.

Makefile clean not removing *.o files?


Solution

  • In a Unix enviroment, the expansion of wildcards like *.o is handled by the shell before invoking other programs like rm. If I recall correctly, Tornado does not include a Unix-style shell. I suspect that its make instead uses cmd.exe to invoke commands. cmd.exe doesn't do wildcard expansion like a Unix shell. It would simply pass the *.o to rm, which would silently ignore it, due to the -f option.

    If that is the cause of the problem, you could either use the Windows del command, which does its own wildcard expansion, or you could let make do the wildcard expansion for you by writing rm -rf $(wildcard *.o).