help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Append value on the command line to a predefined macro in the make file


From: Guan Wang
Subject: Append value on the command line to a predefined macro in the make file
Date: Thu, 28 Jan 2010 10:12:19 -0500

Hi,

I have a c file foo.c:

 

int main(void)

{

#ifdef FOO

printf("FOO!\n");

#endif

#ifdef BAR

printf("BAR!\n");

#endif

return 0;

 

}

 

and a Makefile may be like this:

CPPFLAGS=-DFOO

a.out:foo.o

        gcc -o $@ $^

%.o:%.c

        gcc -c $< ${CPPFLAGS}

 

if I make it and run a.out (I am on a GNU Make 3.81), the output is

FOO!. If I want to print out BAR! or FOO!BAR!, I could always append -

DBAR onto CPPFLAGS.

 

So, my question is: what if I want to append -DBAR on the command

line?

 

I tried: make CPPFLAGS+=-DBAR

But it will completely replace the defined CPPFLAGS in the Makefile.

Obviously, the one defined on the command line has the precedence.

 

Is this doable through command line arguments to make?

 

Many thanks!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]