help-make
[Top][All Lists]
Advanced

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

Re: setting variable value


From: Maxim Yegorushkin
Subject: Re: setting variable value
Date: Wed, 23 Aug 2006 13:20:44 +0100
User-agent: Thunderbird 1.5.0.5 (X11/20060808)

Aditya Kher wrote:
GNU Make 3.79

Lets say I have a Makefile like this

FOO:=<some_dir>

all: target_1 target_2

target_1:
  cd ${FOO}
  ls

targe_2:
  cd ${FOO}
  ls

Now  I want to ensure that for FOO is set to different directory for
target_1 and target_2
so I added following to this Makefile

ifeq(${MAKECMDGOALS}, target_1)
FOO = dir_1
endif

ifeq (${MAKECMDGOALS}, target_2)
FOO = dir_2
endif

but if I execute gmake all then I want FOO to be changed to dir_1
while it is making target_1 and dir_2 while it is making target_2
That doesnt happen with above code.
Ideas?

Use target specific variables:

$ cat Makefile
FOO := whatever
.PHONY : all
all : target_1 target_2 target_3
target_1 : FOO := foo # override FOO for this target
target_2 : FOO := bar # override FOO for this target
target_% : ; @echo "cd ${FOO} && ls"

$ make
cd foo && ls
cd bar && ls
cd whatever && ls

Note that you have to put cd and ls on the same line, because each rule line is executed by another invocation of shell, so the effect of cd in the previous line is lost.





reply via email to

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