问题:
是否可以为目标对象分配另一个名称或别名,以便可以使用原始目标名称或别名来调用它。
例如,类似于以下内容:
/very/long/path/my_binary: dep_a dep_b dep_c
# Compile
# Desired command
ALIAS my_binary = /very/long/path/my_binary
# NOTE: Notice the use of 'my_binary' in the dependencies
data1: my_binary datafile
# Build data file using compiled my_binary
尝试1:.PHONY
我尝试使用.PHONY
目标:
.PHONY: my_binary
my_binary: /very/long/path/my_binary
当从命令行调用时,这个功能非常好用:
# Runs rule 'my_binary' and then *only* runs rule '/very/long/path/my_binary'
# if the rule '/very/long/path/my_binary' needs updating.
make my_binary
然而,当别名my_binary
被列为依赖项时,这种方法并不奏效:
# *Always* thinks that rule 'data1' needs updating, because it always thinks that
# the .PHONY target 'my_binary' "needs updating". As a result, 'data1' is
# rebuilt every time.
make /very/long/path/my_binary
可能的黑客攻击?
一种可能的黑客攻击方法是使用空目标,如这个问题的答案中建议的那样,但这将需要引入具有与别名对应的虚假文件名称:
my_binary: /very/long/path/my_binary
touch my_binary
这样会在主目录中创建很多文件!把虚假文件放在子目录中会失去意义,因为别名必须被称为”directory/my_binary”。
$(platform): platform.json $(os)
而不是$(platform): platform.json os
)。 - Vladimir Panteleev.PHONY
目标想象成仅供最终用户使用的接口,即仅在从shell调用make <target>
时使用.PHONY
目标。在makefile中描述依赖树时,请始终使用“真实”目标。=> 对最终用户来说很舒适;对编写makefile的开发人员来说有点繁琐。结果:正确的依赖计算;良好的用户体验。 如果您有类似于binary: my-phony-target
的东西,则每次调用都会重新构建二进制文件,因为虚拟目标总是过时的,并且可传递性适用。 - frncmx:=
(简单扩展变量)而不是=
(递归变量)$(platform): platform.json $(os)
其中os
是该变量。 - frncmx