Makefile:依赖项列表中的$ subst [英] Makefile: $subst in dependency list
问题描述
我有一个看起来像这样的Makefile:
I have a Makefile which looks roughly 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 :
重点是我的图形的文件名包含某些信息(A,B,C),并且每个图形都是由my_program从几个(在示例3中)文件中创建的.
虽然每个图形的文件名的格式为Ax_Bx_Cx.eps
,但是用于创建图形的数据文件的名称如下所示:
The point is that the file names of my figures contain certain information (A, B, C) and that each figure is created by my_program from several (in the example 3) files.
While the filename of each figure has the format Ax_Bx_Cx.eps
, the names of the data files to create the figures from look like this:
Ax_1x_Cx.out
Ax_2x_Cx.out
Ax_3x_Cx.out
因此,对于每个图,我需要一个带有几个文件名的动态创建的依赖项列表.换句话说,我在上面的示例中期望的输出将是:
So for each figure, I need a dynamically created dependency list with several file names. In other words, my desired output for the example above would be:
#my_program(A1_11_C1.out A1_21_C1.out A1_31_C1.out,A1_B1_C1.eps);
# 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(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);
# my_program(A3_13_C3.out A3_23_C3.out A3_33_C3.out, A3_B2_C3.eps);
不幸的是,subst
命令似乎被忽略了,因为输出看起来像这样:
Unfortunately, the subst
command seems to be ignored, for 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(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(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);
# my_program(A3_B3_C3.out A3_B3_C3.out A3_B3_C3.out, A3_B3_C3.eps);
我查看了这种可能的重复,但发现答案无济于事,因为我使用的是%
而不是$@
,在先决条件中应该没问题.
I had a look at this possible duplicate but figured that the answer cannot help me, since I am using %
and not $@
, which should be ok in the prerequisites.
很明显,我在这里出了点问题.任何帮助,我们将不胜感激.
Clearly I am getting something wrong here. Any help is greatly appreciated.
推荐答案
要进行精美的先决条件操作,您至少需要make-3.82,它支持
To do fancy prerequisite manipulations you need at least make-3.82 which supports Secondary Expansion 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 $@
输出:
$ 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)
这篇关于Makefile:依赖项列表中的$ subst的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!