我有一个大致如下的Makefile:
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
,但创建图形的数据文件的名称如下所示:
Ax_1x_Cx.out
Ax_2x_Cx.out
Ax_3x_Cx.out
因此,对于每个图,我需要一个动态创建的依赖列表,其中包含多个文件名。换句话说,我上面例子的所需输出是:
#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);
不幸的是,subst
命令似乎被忽略了,因为输出如下所示:
#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);
我查看了this possible duplicate,但认为答案无法帮助我,因为我使用%
而不是$@
,这在先决条件中应该没问题。
显然我在这里弄错了。非常感谢任何帮助。
答案 0 :(得分:3)
要进行花哨的先决条件操作,至少需要make-3.82支持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)