I have a Makefile that defines a .PHONY clean target for cleaning up .o files and executables, that target looks like:
...
.PHONY : clean
clean:
rm $(addprefix $(vq_DIR),$(vq_OBJS)) \
$(addprefix $(vq_DIR),vq) \
$(addprefix $(covq_DIR),$(covq_OBJS)) \
$(addprefix $(covq_DIR),covq) \
$(addprefix $(covq_2_DIR),$(covq_2_OBJS)) \
$(addprefix $(covq_2_DIR),covq_2) \
$(addprefix $(covq_2_DIR),$(test_OBJS)) \
$(addprefix $(covq_2_DIR),test)
Everything works as it should, but when some of these files do not exist, rm
raises an Error (No such file or directory), and the output says that the Makefile target failed, when it clearly did what I wanted.
Is there a good way to basically tell the rm
command to "remove these files if they exist, and don't complain if they don't"? I looked up the manpage for rm
, and found no such flag.
Edit: I actually didn't notice the description of the -f
flag in the manpage, this is the solution.
Use
rm -f
(or even better$(RM)
, provided by built-inmake
rules, which can be found out usingmake -p
) instead ofrm
in yourclean
rule.will FORCE and not output any error
I've given up with rm. The following command will remove files and dirs.
To remove only files or only dirs, there is the -type option:
Actually, I've create a little script (based on that snippet) named bomb that removes files without complaining: https://github.com/lingtalfi/bomb
~ http://www.cprogramming.com/tutorial/makefiles.html
Late to the party, but here's another solution that worked with our quirky build environment:
Not output free, but reduced and exits cleanly:
I tried a lot of alternatives that all had issues before settling on this one.