my c++ source file look for a specific variable passed from the makefile. when making a different target, this variable definition is different.
How can I define a variable in Makefile based on target.
Thanks
Just add -Dxxx=yy on the command line ( xxx the name of the macro and yy the replacement, or just -Dxxx if there is no value).
To get the value of a variable, enclose the variable name in $( ) . As a special case, single-letter variable names can omit the parentheses and simply use $ letter .
Macros are defined in a Makefile as = pairs. For example: MACROS= -me PSROFF= groff -Tps DITROFF= groff -Tdvi CFLAGS= -O -systype bsd43 LIBS = "-lncurses -lm -lsdl" MYFACE = ":*)" Special Macros.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With