Makefile自动生成目标

时间:2016-01-05 02:47:10

标签: macos bash makefile

我有以下目录树

moving_files/
        Makefile
        source/
                a
                b
                c
        target/

使用我的Makefile,我想cpsource/中的每个文件target/。 问题:我希望以后能够将其他文件移动到source/,而无需编辑Makefile。为此我写了这个:

FILES = $(filter-out Makefile, $(wildcard source/*) ) 
all: $(subst source,target,$(FILES))
$(subst source,target,$(FILES)): $(FILES)
    cat $< >| $@

它工作正常。

但是,当我之后再次执行touch source/dmake时,除了dabc之外cat也是。{我需要做些什么才能改变这种行为。

1 个答案:

答案 0 :(得分:1)

$(subst source,target,$(FILES)): $(FILES)

扩展为

target/a target/b target/c: source/a source/b source/c

这意味着每个目标都取决于source中的所有文件,可能不是您想要的。 static或隐式规则可以解决此问题,静态规则通常更好,因为它们更具体:

$(subst source,target,$(FILES)): target/%: source/%