3

我有一个大致如下所示的 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 中)文件创建的。虽然每个图形的文件名都有 format 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);

我查看了这个可能的重复项,但认为答案对我没有帮助,因为我正在使用%and not $@,这在先决条件中应该没问题。

显然我在这里遇到了问题。任何帮助是极大的赞赏。

4

1 回答 1

3

要进行花哨的先决条件操作,您至少需要支持二级扩展功能的 make-3.82 :

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)
于 2013-02-06T15:22:04.553 回答