Makefile 将maketarget标记为不可直接调用
如何将Make目标标记为“不可调用”或“不直接调用此目标” 比如说,Makefile 将maketarget标记为不可直接调用,makefile,gnu-make,Makefile,Gnu Make,如何将Make目标标记为“不可调用”或“不直接调用此目标” 比如说, common: touch $(VAR) # VAR is expected to be set foo: VAR = this foo: common bar: VAR = that bar: common 我不希望用户执行以下操作: make common 是否有一个Make习语将common标记为不可调用?以下方法可行 ifeq ($(MAKECMDGOALS),common) $(error do
common:
touch $(VAR) # VAR is expected to be set
foo: VAR = this
foo: common
bar: VAR = that
bar: common
我不希望用户执行以下操作:
make common
是否有一个Make习语将
common
标记为不可调用?以下方法可行
ifeq ($(MAKECMDGOALS),common)
$(error do not call common directly)
endif
但是,编写ifeq($(MAKECMDGOALS),…)
对于像
%-$(VERSION).tar:
# create the final .tar file
没有任何类似于
.PHONY
的东西可以阻止通过命令行生成目标。您可以这样做:
common:
$(if $(VAR),,$(error You must run 'make foo' or 'make bar'))
touch $(VAR)
您可以为“私有目标”使用特定模式,并检查此模式 此外,以“\u1”开头的目标似乎未在自动完成中列出
ifeq ($(findstring _,$(MAKECMDGOALS)),_)
$(error target $(MAKECMDGOALS) is private)
endif
.PHONY: public-target
public-target: _private-target
public-target:
echo "public target"
.PHONY: _private-target
_private-target:
echo "private target"
我希望有更简洁的东西。类似于可应用于目标的
.PHONY
标签。例如,可以使用类似于.INDIRECT
的方式将目标标记为仅可间接调用(或不可直接调用)。的可能重复项