制作:没有在Mac上翻拍

时间:2018-01-20 14:48:13

标签: makefile gnu-make

我有某种make依赖问题。触摸all_2后,a1.src不会重建,all_1会触发$ cat Makefile DIR = ${HOME}/tmp outputs = $(DIR)/dir1/a1.out $(DIR)/dir2/a2.out all_1 : dir1/a1.out dir2/a2.out all_2 : $(outputs) ls -l $(outputs) # debug print */%.out : $(notdir %.src) @touch $@ @echo 'Build $@ from $(notdir $*.src)' 。为什么?我不能使用绝对路径吗?

$ ls -R
Makefile    a1.src      a2.src      dir1        dir2

./dir1:
a1.out

./dir2:
a2.out

这是我的目录结构:

all_1

$ touch a1.src $ make all_1 Build dir1/a1.out from a1.src $ make all_1 make: Nothing to be done for `all_1'. 效果很好:

all_2

但是a1.out不重建$ touch a1.src $ make all_2 ls -l /Users/eternity/tmp/dir1/a1.out /Users/eternity/tmp/dir2/a2.out # debug print -rw-r--r-- 1 eternity staff 0 Jan 20 15:25 /Users/eternity/tmp/dir1/a1.out -rw-r--r-- 1 eternity staff 0 Jan 20 14:46 /Users/eternity/tmp/dir2/a2.out $ (虽然存在out文件,所以我猜目标还可以):

[mat-dialog-close]="true"

1 个答案:

答案 0 :(得分:1)

首先,*不是目标方面的“通配符”。您需要一个模式规则,其中%.out为目标:

%.out: ...

这将与具有尾随.out的目标名称匹配。

与模式规则匹配的词干(即:目标中的%部分)将存储在自动变量$*中:

%.out: $(notdir $*.src)

但是,仅此一项不会:您还需要启用辅助扩展 以将变量$*用作规则的一部分定义,因为在第一次扩展期间其值为空。为了实现二次扩展,只需定义目标.SECONDEXPANSION,即:

.SECONDEXPANSION:

启用后,要在规则定义中延迟变量或函数的扩展,您需要将$替换为$$

%.out: $$(notdir $$*.src)

所以,考虑到所有这些,你的最后一条规则应该是:

.SECONDEXPANSION:
%.out: $$(notdir $$*.src)
    @touch $@
    @echo 'Build $@ from $(notdir $*.src)'