Operating System - HP-UX
1753770 Members
4754 Online
108799 Solutions
New Discussion

Set make file variable depending on Target

 
Debd001
New Member

Set make file variable depending on Target

Hoe to update Variable in target of a makefile:

 

CC=aCC

 

all:

<Builds source>

 

update_cc: 

<Here I want CC="cadvice +wall aCC">

 

Change_CC: update_cc all

 

---------------------------------------

In above make, if I call >> make Change_CC, It shuold build with "cadvice +wall aCC". Otherwise alll should be same

2 REPLIES 2
Dennis Handly
Acclaimed Contributor

Re: Set makefile variable depending on target

>How to update variable in target of a makefile

 

I don't think you can, those lines are passed to the shell.

 

>I want CC="cadvise +wall aCC"

 

The simplest way to do this is set the variable on the command line:

make CC="cadvise +wall aCC"

Steven Schweda
Honored Contributor

Re: Set make file variable depending on Target

   Are you talking about using what the GNU "make" folks call a
'sub-"make"'?  For example (tested on a Mac, using "GNU Make 3.81", but
I don't think that there's anything exotic or GNU-specific here):

mba$ cat Makefile
def:
        $(CC) $(CFLAGS) -o test test.c

alt:
        @$(MAKE) CFLAGS='-O0 -g'

mba$ rm test
mba$ make
cc  -o test test.c

mba$ rm test
mba$ make alt
cc -O0 -g -o test test.c

   Remove the "@" on the "alt" action line to see what's happening.

 

   I set CFLAGS, but setting CC should work, too.