64 GNU make
x = variable1
variable2 := Hello
y = $(subst 1,2,$(x))
z = y
a := $($($(z)))
eventually defines a as ‘Hello’. It is doubtful that anyone would ever want to write a nested
reference as convoluted as this one, but it works: ‘$($($(z)))’ expands to ‘$($(y))’ which
becomes ‘$($(subst 1,2,$(x)))’. This gets the value ‘variable1’ from x and changes it
by substitution to ‘variable2’, so that the entire string becomes ‘$(variable2)’, a simple
variable reference whose value is ‘Hello’.
A computed variable name need not consist entirely of a single variable reference. It can
contain several variable references, as well as some invariant text. For example,
a_dirs := dira dirb
1_dirs := dir1 dir2
a_files := filea fileb
1_files := file1 file2
ifeq "$(use_a)" "yes"
a1 := a
else
a1 := 1
endif
ifeq "$(use_dirs)" "yes"
df := dirs
else
df := files
endif
dirs := $($(a1)_$(df))
will give dirs the same value as a_dirs, 1_dirs, a_files or 1_files depending on the
settings of use_a and use_dirs.
Computed variable names can also be used in substitution references:
a_objects := a.o b.o c.o
1_objects := 1.o 2.o 3.o
sources := $($(a1)_objects:.o=.c)
defines sources as either ‘a.c b.c c.c’ or ‘1.c 2.c 3.c’, depending on the value of a1.
The only restriction on this sort of use of nested variable references is that they cannot
specify part of the name of a function to be called. This is because the test for a recognized
function name is done before the expansion of nested references. For example,
Comentarios a estos manuales