在makefile中计算文件路径

在makefile中计算文件路径,makefile,gnu-make,Makefile,Gnu Make,我需要根据一些子系统名称计算文件路径。见下文MWE。请问有没有更简单的方法达到同样的效果?请参阅下面我的aa、ab、ac和join方法 我不喜欢重复使用$(子系统),因为它依赖于make以相同的顺序执行。我尝试使用$(patsubst),但它只替换了%的第一个实例。有什么提示吗 # ## Given some subsystem names subsystem := pi_sub_chris \ pi_sub_rob \ pi_sub_greg

我需要根据一些子系统名称计算文件路径。见下文MWE。请问有没有更简单的方法达到同样的效果?请参阅下面我的aa、ab、ac和join方法

我不喜欢重复使用$(子系统),因为它依赖于make以相同的顺序执行。我尝试使用$(patsubst),但它只替换了%的第一个实例。有什么提示吗

#
## Given some subsystem names
subsystem := pi_sub_chris \
             pi_sub_rob \
             pi_sub_greg

#
## And an output directory
dir_export := ../pi_sw/export

#
## Calculate a file path in export directory to be made
## Is there a better way to do this!?
aa := $(addprefix $(dir_export)/,$(subsystem))
ab := $(addsuffix /a2l/, $(aa))
ac := $(addsuffix .a2l, $(subsystem))
files_to_be_made := $(join $(ab), $(ac))

.PHONY :
go : $(files_to_be_made)
    @echo Done!

%.a2l :
    @echo A perl script is run here to generate file $@
正确输出:

A perl script is run here to generate file ../pi_sw/export/pi_sub_chris/a2l/pi_sub_chris.a2l
A perl script is run here to generate file ../pi_sw/export/pi_sub_rob/a2l/pi_sub_rob.a2l
A perl script is run here to generate file ../pi_sw/export/pi_sub_greg/a2l/pi_sub_greg.a2l
Done!

依赖于这些变量展开的顺序没有问题;这一定是真的,否则几乎每个makefile都会崩溃。这是绝对有保证的

但是,如果您不喜欢,可以使用以下内容:

files_to_be_made := $(foreach S,$(subsystem),$(dir_export)/$S/a21/$S.a21)

依赖于这些变量展开的顺序没有问题;这一定是真的,否则几乎每个makefile都会崩溃。这是绝对有保证的

但是,如果您不喜欢,可以使用以下内容:

files_to_be_made := $(foreach S,$(subsystem),$(dir_export)/$S/a21/$S.a21)

谢谢你的回答。正是我想要的。谢谢你的回答。正是我想要的。