Make Make构建可变数量的子目录

时间:2018-01-31 08:49:52

标签: makefile

在我的项目中,我有一个名为samples的子文件夹,其中有许多目录,每个样本一个。

我想通过规则制作和制作所有样本,而不维护它们的列表。

到目前为止,我有这个:

test-samples: $(wildcard samples/**/Cargo.toml)

samples/%/Cargo.toml : samples/%/context.toml flowc
    @echo ""
    @echo "------- Compiling and Generating code from flow: $< ----"
    ./target/debug/flowc $<

samples/%/target : samples/%/Cargo.toml
    @echo "------- Compiling and Running generated code: $< ----"
    @cargo run --quiet --manifest-path $<

如果Cargo.toml文件和target目录已经存在 - 则依赖项可以正常工作并重新生成。

但如果Cargo.toml文件尚不存在(第一次),或target目录尚不存在,我无法运行规则。

1 个答案:

答案 0 :(得分:0)

我认为这可能是使用路径替换的解决方案。

让我知道你的想法:

sample_flows := $(patsubst samples/%,samples/%/target,$(wildcard samples/*))

test-samples: $(sample_flows)

samples/%/Cargo.toml : samples/%/context.toml ./target/debug/flowc
    @echo ""
    @echo "------- Compiling and Generating code from flow: $< ----"
    ./target/debug/flowc $<

samples/%/target : samples/%/Cargo.toml
    @echo "------- Compiling and Running generated code: $< ----"
    @cargo run --quiet --manifest-path $<
相关问题