Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

For instance, an error L6220E would be generated during the compilation (since I am using the ARM compiler, this error flag means out of internal flash memory). What I want to do is to continue the compilation even though the error was generated. Is there any way I can catch the command error and run other commands? Like,

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

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

Is there any way to do so?

like image 385
Qiyang Li Avatar asked Jun 02 '17 21:06

Qiyang Li


1 Answers

You can prefix any command with a - to indicate to make that this command is okay to fail:

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

Another way would be to simply test for failure in the commands:

normal_target:
         if gcc -o main main.c; then \
            echo succeeded; \
         else \
            echo compilation failed; \
            gcc -o ...; \
         fi
like image 200
Jens Avatar answered Oct 11 '22 13:10

Jens