views:

43

answers:

1

I would like to perform expansion on a variable that might contain references to other variables. I'll illustrate with an example:

a = 1
b = 2
c = 3
X = foo bar baz $(foreach x, a b c, $$(value $(x))) qux
$(info $(X))

If you run this makefile, it prints:
foo bar baz $(value a) $(value b) $(value c) qux

I'd like to know how to expand it so that I get:
foo bar baz 1 2 3 qux

I can do the following:
$(eval X = $(X))

To get close to what I want, however this requires me to reassign the variable again. Also, I'm "eval"ing whatever was in the whole variable which may not be what I want. I'd like to be able to do something like $(expand X) and have the resulting text.

+1  A: 
X = $(foreach x, a b c, $($(x)))
Beta
I'm sorry, I didn't quite make my example right, I end up with a variable containing something like "foo bar baz $(somevar) $(some-other-var)".I'd like to expand $(somevar) and $(some-other-var).I am/was aware of how to indirectly expand a variable reference when that is all a variable contains.
BitShifter
@BitShifter: I've given this a lot of thought, and I just can't see how to do it. My best guess is to use SECONDEXPANSION (which my version of gmake doesn't have) and take `$(X)` as the prerequisite of a dummy rule. If that doesn't work there may still exist some horrible hack that will do it, but I have no idea what it might be.
Beta