alain
alain

Reputation: 175

How to assign a variable to a variable without evaluation?

it is much easier to explain my problem by showing you some code.

Here it is:

FILES = $(F1)
A.FILES = $(FILES)

FILES = $(F2)
B.FILES = $(FILES)

F1 := file1
F2 := file2

all: a b

a: $(A.FILES)
    echo $^

b: $(B.FILES)
    echo $^

$(F1) $(F2):
    echo $@

The problem is calling make a prints file2, instead of file1. How could I maintain specifying A.FILES with a variable named FILES? I know, := would do the job, but I may have F1 defined later. I would like to have something which permits to have the following:

FILES = $(F1)
A.FILES <- FILES (assignation) such that A.FILES = $(F1)

Thanks!

Upvotes: 0

Views: 99

Answers (1)

MadScientist
MadScientist

Reputation: 100946

There is no straightforward way to do this. You can do some tricky things to get it to work, like this:

F = $(F1)
A := $(value F)

F= $(F2)
B := $(value F)

F1 = foo
F2 = bar

$(eval A := $(A))
$(eval B := $(B))

all: ; @echo 'A=$(A) B=$(B)'

but there's no other way to do it.

ETA

Actually alain gives an even better solution:

F = $(F1)
$(eval A = $(value F))

F= $(F2)
$(eval B = $(value F))

F1 = foo
F2 = bar

all: ; @echo 'A=$(A) B=$(B)'

Upvotes: 1

Related Questions