根据目标定义编译变量

根据目标定义编译变量

问题描述:

我的c ++源文件查找从makefile传递的特定变量.当创建不同的目标时,此变量定义是不同的.

my c++ source file look for a specific variable passed from the makefile. when making a different target, this variable definition is different.

如何根据目标在Makefile中定义变量.

How can I define a variable in Makefile based on target.

谢谢

您可以使用

You can use target-specific variable values, they propagate to target's prerequisites:

all : foo bar
foo : CXXFLAGS += -DFOO
bar : CXXFLAGS += -DBAR

foo bar :
    @echo target=$@ CXXFLAGS=${CXXFLAGS}

.PHONY : all