I have written a rule where a directory should be removed if it exists:
.PHONY: distclean
distclean:
-rmdir release
make distclean
prints:
rmdir release
rmdir: failed to remove ‘release’: No such file or directory
test.mak:3: recipe for target 'distclean' failed
make: [distclean] Error 1 (ignored)
Shouldn't the -
sign make GNU Make ignore the error?
I am using GNU Make 4.0.
Best Answer
Make is ignoring the error:
It still prints the error messages, but if you add another rule in the
distclean
target it should be processed in spite of thermdir
failure.In more detail:
This is
make
printing the command it's about to run.This is
rmdir
printing an error message becauserelease
doesn't exist. To remove that, you'd add2> /dev/null
to the command (or>& /dev/null
to silencermdir
completely).rmdir
exits with a non-zero exit code, somake
prints an error message. To remove that, you'd add|| true
to the command (so that it exits with a zero exit code in all cases).Finally, since the command was prefixed with
-
, the error is ignored andmake
continues.