Execute commands if compiling fails with Make
With GNU Make and one of the compilers in gcc: Is it possible to execute commands if (and only if) the c开发者_JAVA技巧ompiling fails?
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; \
}
精彩评论