gpt4 book ai didi

Makefile:依赖项列表中的 $subst

转载 作者:行者123 更新时间:2023-12-02 19:23:46 25 4
gpt4 key购买 nike

我有一个 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但我认为答案无法帮助我,因为我使用的是 % 而不是 $@,这在先决条件中应该没问题。

显然我在这里遇到了问题。非常感谢任何帮助。

最佳答案

要进行奇特的先决条件操作,您至少需要 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)

关于Makefile:依赖项列表中的 $subst,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14731869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com