GNU Make does not ignore failed command

gnu-make

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:

make: [distclean] Error 1 (ignored)

It still prints the error messages, but if you add another rule in the distclean target it should be processed in spite of the rmdir failure.

In more detail:

rmdir release

This is make printing the command it's about to run.

rmdir: failed to remove ‘release’: No such file or directory

This is rmdir printing an error message because release doesn't exist. To remove that, you'd add 2> /dev/null to the command (or >& /dev/null to silence rmdir completely).

test.mak:3: recipe for target 'distclean' failed

rmdir exits with a non-zero exit code, so make 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).

make: [distclean] Error 1 (ignored)

Finally, since the command was prefixed with -, the error is ignored and make continues.

Related Question