home | list info | list archive | date index | thread index

[OCLUG-Tech] gnu make: the superfluous use of "||:"

  digging through the build system for the hyperledger fabric
distributed ledger technology, and noticed something in the Makefile
i'd never seen before that took me a couple seconds to recognize:

  .PHONY: clean
  clean: docker-clean unit-test-clean release-clean
        -@rm -rf build ||:

  .PHONY: clean-all
  clean-all: clean gotools-clean dist-clean
        -@rm -rf /var/hyperledger/* ||:


i thought, what's with that "||:" at the end of those rm commands,
then it dawned on me that it just means if the command fails, continue
and run the "true" command; in other words, if the rm command fails,
keep going.

  but what is the value of that, given the leading "-" for the
command, which i understood to mean the same thing? isn't that
overkill? this question at SO:

https://stackoverflow.com/questions/7772393/gnu-make-run-a-target-after-all-others-regardless-of-failures

has an answer that pretty clearly suggests "||:" is a bit silly when a
leading "-" does the same thing and more obviously?

  thoughts?

rday

p.s. in those two cases, even the "-" is superfluous since "rm -rf"
can't fail, even if the file or directory doesn't exist.