On Wed, 2010-07-28 at 20:46 +0530, Sandeep K S wrote:
> I have two targets A and B. For Target A, I need to set a variable
> FLAG as '-DFLAG_A', and for target B, I need to set the variable FLAG
> as '-DFLAG_B'. This FLAG variable is used in the compilation which
> declares two macros (FLAG_A and FLAG_B) for the C file to use.

Look up "target-specific variables" in the GNU make manual.

> I tried the following two options, but was not able to successfully
> set the FLAG variable depending on the target.
> ifeq ($@, "A")   
> FLAG=-DFLAG_A
> else
> FLAG=-DFLAG_B
> endif

This will not work because ifeq, etc. are parsed when the makefile is
read in, but $@ is only set in the context of a rule, when make is
actually invoking it.  So here, $@ evaluates to the empty string.  See
"How make Reads a Makefile" in the GNU make manual.

> A: x.o y.o z.o $FLAG
> B: x.o y.o g.o $FLAG

These are both wrong: first you mean $(FLAG), not $FLAG, and second this
would add a prerequisite file named "-DFLAG_B" to your target A, which
is obviously not what you want.

> A: x.o y.o z.o $FLAG
>     FLAG=-DFLAG_A
> 
> B: x.o y.o g.o $FLAG
>     FLAG=-DFLAG_B

No.  Too many things wrong to get into here :-)

See the manual.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <[email protected]>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist


_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to