Mig*_*zao 7 dependencies makefile
试图找到一种优雅的方法来解决一些复杂的依赖关系.我的Makefile中有以下内容:
.PHONY: FOO
FOO: foo
foo:
build foo
.PHONY: BAR
BAR: bar
bar: FOO
build bar
Run Code Online (Sandbox Code Playgroud)
这里的想法是我想用虚假目标(FOO BAR)抽象真实文件(foo,bar).当然,在我真正的Makefile中,它更复杂,这就是为什么抽象很重要.但是,这里的问题是让假目标FOO成为bar的依赖,然后Make总是尝试重建bar,即使foo和bar都是最新的.这显然是因为它总是将FOO视为过时.但这种行为并不正确.
所以看起来我只有3个选项:1)让bar直接依赖于foo.在我真正的Makefile中,它更复杂,并且尝试将实际文件指定为依赖项是非常不受欢迎的.2)除了所有的声音之外还使用变量.这使得整个Makefile更加复杂.3)从bar中删除foo/Foo作为依赖项,并在bar中添加FOO的递归make作为规则的一部分.这是非常糟糕的形式.
是否有一些我不知道的更优雅的解决方案?
谢谢.
正如您所建议的,变量是您所需要的,并且实际上可以帮助提高可读性。它们允许我们使 bar 文件正确依赖于 foo 文件,而不是用户友好的 .PHONY 目标:
foo.file = horrendously/long/path/to/the/real/foo.file
bar.file = horrendously/long/path/to/the/real/bar.file
.PHONY: FOO
FOO: $(foo.file)
$(foo.file):
touch $@
.PHONY: BAR
BAR: $(bar.file)
$(bar.file): $(foo.file)
touch $@
Run Code Online (Sandbox Code Playgroud)
现在我们开始:
$ make BAR
touch horrendously/long/path/to/the/real/foo.file
touch horrendously/long/path/to/the/real/bar.file
$ make BAR
make: Nothing to be done for `BAR'.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1475 次 |
| 最近记录: |