5

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.

1
  • 3
    It should, and it does, that's what "Error 1 (ignored)" means. – lcd047 Jun 28 '15 at 16:47
8

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.

1
  • Thanks. I was confused by the recipe for target 'distclean' failed message. I was expecting a silent behaviour. As you say, successive recipes are executed. – Eleno Jun 28 '15 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.