且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Makefile中使用条件规则

更新时间:2021-12-05 21:38:18

问题是echo属于外壳程序; Make可以在命令中将其传递给Shell,但是Make无法执行它.使用info代替:

The problem is that echo belongs to the shell; Make can pass it to the shell in a command, but Make cannot execute it. Use info instead:

ifdef CATEGORY
$(info CATEGORY defined)
else
$(info CATEGORY undefined)
endif

如果您希望规则是有条件的:

If you want the rules to be conditional:

ifdef CATEGORY
ifdef TEST
$(CATEGORY):
    whatever
else
$(info TEST not defined)
else
$(info CATEGORY not defined)
endif