第一
我参考gnu make manual 3.81,因为我的版本是3.81(make --v)
第7.2节
conditional-directive
text-if-one-is-true
else conditional-directive
text-if-true
else
text-if-false
endif
Run Code Online (Sandbox Code Playgroud)
所以我的makefile
version=ag101p
ifeq ($(version),ag101p)
ag101p:ag101p.o zigbee.o
cc -o $@ $(CFLAGS) $^
else ifeq($(version),test)
@echo "test"
else
CFLAGS += -DM2C
m2c:m2c.o zigbee.o
cc -o $@ $(CFLAGS) $^
endif
.PHONY:clean
clean:CLL
rm -rf *.o ag101p m2c
CLL:
Run Code Online (Sandbox Code Playgroud)
但控制台显示
Makefile:7:'else'指令后的无关文本
小智 5
通过在“else ifeq”和“(”之间添加一个空格在linux平台上有效。但在windows上它不起作用。我通过添加花药endif使“if else”嵌套在windows上修复了这个问题。
ifeq ($(version),ag101p)
ag101p:ag101p.o zigbee.o
cc -o $@ $(CFLAGS) $^
else
ifeq ($(version),test)
@echo "test"
else
CFLAGS += -DM2C
m2c:m2c.o zigbee.o
cc -o $@ $(CFLAGS) $^
endif
endif
.PHONY:clean
clean:CLL
rm -rf *.o ag101p m2c
CLL:
Run Code Online (Sandbox Code Playgroud)