jameh jameh - 1 year ago 142
Linux Question

How to avoid "No such file or directory" Error for `make clean` Makefile target

I have a Makefile that defines a .PHONY clean target for cleaning up .o files and executables, that target looks like:

.PHONY : 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,
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
command to "remove these files if they exist, and don't complain if they don't"? I looked up the manpage for
, and found no such flag.

Edit: I actually didn't notice the description of the
flag in the manpage, this is the solution.

Answer Source

Use rm -f instead of rm in your cleanrule.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download