使用ifdef条件来设置Make标志



我有一个简单的gnu makefile:

ifdef $(DEBUGGING)
  CFLAGS = -g -O0 -Wall
else
  CFLAGS = -O3 -Wall
endif
test:
    @echo DEBUGGING is $(DEBUGGING)
    @echo $(CFLAGS)

当我像这样调用它时,我看到DEBUGGING被设置为true,但是ifdef $DEBUGGING似乎是false:

$ DEBUGGING=true make test
DEBUGGING is true
-O3 -Wall

我希望CFLAGS设置为"-g - 0 -Wall"。我错过了什么?

您在ifdef中使用NAME变量:

ifdef DEBUGGING

ifdef的值首先展开,结果作为变量名

最新更新