开发者

Conditional statements depending on successful compilation within a Makefile

开发者 https://www.devze.com 2023-04-02 15:41 出处:网络
For a makefile, I am trying to make it run a block of code in case of successful compilation, or an else block otherwise.

For a makefile, I am trying to make it run a block of code in case of successful compilation, or an else block otherwise.

I have tried something like this

default:
ifeq ($(gcc -obuild main.c), 0)
    echo "successful"
else
    echo "you fail lol"
endif

But I cannot get the compilation command to be evaluat开发者_如何学Pythoned as my code suggests that I want. I thought that it could work like Bash but it seems that not, or I am missing something I dont know.

How can I accomplish this task?


Do it with the shell, not with Make:

default:
    if gcc -obuild main.c  ; then \                                        
echo "sucessful" ; \
else echo "you fail" ; fi

Note that only the first line of the commands (if...) starts with a tab.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号