基于当前目标的Makefile依赖目标

时间:2014-07-14 17:23:06

标签: makefile dependencies gnu target

我的Makefile中有以下代码:

Target0: Deps0 Common Rule to build Target Target1: Deps1 Common Rule to build Target ...

我的问题是,由于所有目标都有一个共同的规则,有没有办法将目标组合成一个目标并指定目标特定的依赖关系?

1 个答案:

答案 0 :(得分:2)

请参阅Multiple Targets in a Rule

中的Multiple Rules for One TargetGNU Make Manual
$ cat Makefile.common
all: Target0 Target1

Target0: Deps0
Target1: Deps1

Deps%:
        @echo 'Making $@'

Target0 Target1:
        @echo 'Making $@ from $^'

$ make -f Makefile.common
Making Deps0
Making Target0 from Deps0
Making Deps1
Making Target1 from Deps1