Reputation: 4440
With GNU Make and one of the compilers in gcc: Is it possible to execute commands if (and only if) the compiling fails?
Upvotes: 0
Views: 336
Reputation: 107879
If you prefix a command with -
, make keeps going even if the command returns a nonzero error code. But there's no way to access the error code from the first command in the second command.
You can write arbitrarily complex shell scripts in a single make command. For example, here is how to call two recovery commands if the C compiler fails, running the second one only if the first one fails, and then stopping the build process if the C compiler failed.
$(CC) $(CFLAGS) -o $@ -c $< || { \
recovery_command_1 && \
recovery_command_2; \
false; \
}
Upvotes: 2