Makefile: $ subst in dependency list
I have a Makefile that looks something like this:
FIGURES = A1_B1_C1.eps A2_B2_C2.eps A3_B3_C3.eps
NUMBERS = 1 2 3
all : $(FIGURES)
%.eps : $(foreach num, $(NUMBERS), $(subst B, $(num), %).out)
# my_program($+, $@);
%.out :
The point is that the file names of my drawings contain certain information (A, B, C) and that each shape is created by my_program from several (in example 3) files. Although the file name of each shape is in a format Ax_Bx_Cx.eps
, the data file names for creating shapes are as follows:
Ax_1x_Cx.out
Ax_2x_Cx.out
Ax_3x_Cx.out
So, for each shape, I need a dynamically generated list of dependencies with multiple filenames. In other words, my desired output for the example above:
# my_program (A1_11_C1.out A1_21_C1.out A1_31_C1.out, A1_B1_C1.eps);
# my_program (A2_12_C2.out A2_22_C2.out A2_32_C2.out, A2_B2_C2.eps);
# my_program (A3_13_C3.out A3_23_C3.out A3_33_C3.out, A3_B2_C3.eps);
Unfortunately the command subst
seems to be ignored as the output looks like this:
# my_program (A1_B1_C1.out A1_B1_C1.out A1_B1_C1.out, A1_B1_C1.eps);
# my_program (A2_B2_C2.out A2_B2_C2.out A2_B2_C2.out, A2_B2_C2.eps);
# my_program (A3_B3_C3.out A3_B3_C3.out A3_B3_C3.out, A3_B3_C3.eps);
I looked at this possible duplicate but figured the answer would not help me since I am using %
, not $@
which should be ok in the preconditions.
It is clear that I have something wrong here. Any help is appreciated.
source to share
To do the necessary pre-manipulation, you need at least make-3.82, which supports the secondary extension feature :
FIGURES = A1_B1_C1.eps A2_B2_C2.eps A3_B3_C3.eps
NUMBERS = 1 2 3
all : $(FIGURES)
.SECONDEXPANSION:
$(FIGURES) : %.eps : $$(foreach num,$$(NUMBERS),$$(subst B,$$(num),$$*).out)
@echo "my_program($+, $@)"
%.out :
touch $@
Output:
$ make
touch A1_11_C1.out
touch A1_21_C1.out
touch A1_31_C1.out
my_program(A1_11_C1.out A1_21_C1.out A1_31_C1.out, A1_B1_C1.eps)
touch A2_12_C2.out
touch A2_22_C2.out
touch A2_32_C2.out
my_program(A2_12_C2.out A2_22_C2.out A2_32_C2.out, A2_B2_C2.eps)
touch A3_13_C3.out
touch A3_23_C3.out
touch A3_33_C3.out
my_program(A3_13_C3.out A3_23_C3.out A3_33_C3.out, A3_B3_C3.eps)
source to share