如何捕获命令错误并在 makefile 中继续编译?

How can I catch a command error and continue the compilation in a makefile?

比如在编译时会出现L6220E错误(由于我使用的是ARM编译器,这个错误标志表示内部闪存不足)。我想做的是即使产生了错误也继续编译。有什么办法可以捕获命令错误和 运行 其他命令?喜欢,

normal_target:
             gcc -o main main.c    (this will generate error)

ifeq($(error),L6220E):
             gcc -o ...

有什么办法吗?

您可以在任何命令前加上 - 以向 make 表明此命令可以失败:

normal_target:
         -gcc -o main main.c
         next command here

另一种方法是简单地测试命令中的失败:

normal_target:
         if gcc -o main main.c; then \
            echo succeeded; \
         else \
            echo compilation failed; \
            gcc -o ...; \
         fi