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.
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make