Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define compilation variables based on target for

Tags:

makefile

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

like image 918
user635646 Avatar asked Feb 26 '11 16:02

user635646


People also ask

How do I set #define in Makefile?

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).

Which command can display the value of a variable defined using make command?

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 .

What are macros in Makefile?

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.


1 Answers

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
like image 183
Maxim Egorushkin Avatar answered Nov 05 '22 03:11

Maxim Egorushkin