0

I want make to continue even if a dependency's build fails. I usually use -i to accomplish this. A colleague of mine said he uses -k. Indeed, this stack overflow question has an answer for each:

Make: how to continue after a command fails?

Is there a difference between these two options?

Here's what the make man page says for these two options:

   -i, --ignore-errors
        Ignore all errors in commands executed to remake files.

   -k, --keep-going
        Continue as much as possible after an error.  While the 
        target that failed, and those that depend on it, cannot be 
        remade, the  other  dependencies of these targets can be 
        processed all the same.

What -k describes is what I think -i does. I'm sure I'm missing something: can someone help me understand the difference?

firebush
  • 5,180
  • 4
  • 34
  • 45

1 Answers1

6

Consider this makefile:

all: fail success

all success:
        @echo $@

fail:
        exit 1
        @echo $@

Now run with the two flags:

$ make -i
exit 1
make: [Makefile:7: fail] Error 1 (ignored)
fail
success
all

This flag caused make to pretend that a specific recipe command succeeded, even though it failed. Thus the all target is still run, because make believes that the fail target actually succeeded. It's equivalent to adding a - at the beginning of every recipe line.

As opposed to:

$ make -k
exit 1
make: *** [Makek:7: fail] Error 1
success
make: Target 'all' not remade because of errors.

Here, make knows the fail target was not built. success is run because of -k: it doesn't depend on fail. However, all is not built because it does depend on fail.

I've never really needed -i; it seems dangerous to me.

On the other hand, I use -k almost by default.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • 3
    The manual also says in [5.5 Errors in Recipes](https://www.gnu.org/software/make/manual/make.html#Errors) that the `-i` or`--ignore-errors` flags or the special target `.IGNORE` are obsolete (although `make` does not complain about it in any way). – Reinier Torenbeek Dec 21 '18 at 21:18
  • Great example. This demonstrates the two options well. Thank you. – firebush Dec 22 '18 at 14:10
  • `make -i check` is useful when running multiple tests without stopping – matzeri Dec 23 '18 at 19:41