GNU make:根据特定目录内容创建目标(1:1 目标目录映射)

GNU make: create targets baed on specific directory contents (1:1 target-directory mapping)

我有一系列这样组织的目录:

foo/
    foo.file1 foo.file2
bar/
    bar.file1 bar.file2
baz/
    baz.file1 baz.file2

现在我正在使用一个脚本来处理这些文件,该脚本会检查文件是否存在等,但我想也许我可以为它使用一个 Makefile(因为所说的脚本非常脆弱),以避免重新处理文件那没有改变。

问题是每个目录都是独立的,我需要这样做,例如:

foo.file1.processed: foo.file1
      run_random_program foo.file1 -o foo.file1.processed

对于该路径中总共 71 个目录中的每一个。这看起来非常乏味,我想知道是否有什么东西可以阻止我手写所有这些内容。

这样的事情可能吗?

编辑:一些例子展示了我的想法,如果每个目录都有一个 Makefile:

file1.cds.callable: file1.callable
    long_script_name -i $< -o $@

file1.rds: file1.cds.callable
    another_long_script_name $< additional_file_in_folder $@

file1.csv: file1.rds
    yet_another_script $< $@

看来 pattern rules 正是您所需要的:

# These are the original source files (based on the example)
CALLABLE := $(wildcard */*.callable)

# These are the final targets
TARGETS := $(CALLABLE:%.callable=%.csv)

all: $(TARGETS)

%.csv : %.rds
        yet_another_script $< $@
%.rds: %.cds.callable
        another_long_script_name $< additional_file_in_folder $@
%.cds.callable: %.callable
        long_script_name -i $< -o $@