传递字符串
Makefile
CXX_VALUE = "name"
ifdef CXX_VALUE
$(warning $(CXX_VALUE))
#要使用转移字符 \ 来标明真实的 "" 字符
CXXFLAGS+= -DAAA=\"$(CXX_VALUE)\"
endif
main: main.cpp
@echo "Compiling " $@
$(CXX) $^ $(CXXFLAGS) $(LDLIBS) -o $@
c++
int main()
{
#ifdef CXX_VALUE
printf("CXX_VALUE: %s\n", CXX_VALUE);
#endif
return 1;
}
output
CXX_VALUE: name
传递bool值
Makefile
CXX_VALUE = 1
ifeq ($(CXX_VALUE), 1)
$(warning $(CXX_VALUE))
CXXFLAGS+= -DCXX_VALUE
endif
main: main.cpp
@echo "Compiling " $@
$(CXX) $^ $(CXXFLAGS) $(LDLIBS) -o $@
c++
int main()
{
#ifdef CXX_VALUE
printf("CXX_VALUE: %s\n", CXX_VALUE);
#endif
return 1;
}
output
CXX_VALUE: 1