【问题标题】:mark Make target as not directly callable将目标标记为不可直接调用
【发布时间】:2016-02-03 21:28:20
【问题描述】:

如何将 Make 目标标记为“不可调用”或“不直接调用此目标”?

例如,

common:
    touch $(VAR)  # VAR is expected to be set

foo: VAR = this
foo: common

bar: VAR = that
bar: common

我不希望用户执行以下操作:

make common


是否有 Make 成语将common 标记为不可调用?

【问题讨论】:

标签: makefile gnu-make


【解决方案1】:

您可以对“私有目标”使用特定模式并检查此模式

以“_”开头的目标似乎也没有在自动完成中列出

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"

【讨论】:

    【解决方案2】:

    以下方法可行

    ifeq ($(MAKECMDGOALS),common)
    $(error do not call common directly)
    endif
    

    然而,写ifeq ($(MAKECMDGOALS), ...) 对像这样的目标来说很困难

    %-$(VERSION).tar:
         # create the final .tar file
    

    【讨论】:

    • 我希望有更简洁的东西。可以应用于目标的.PHONY 标签之类的东西。例如,可以使用 .INDIRECT 之类的东西将目标标记为只能间接调用(或不可直接调用)。
    【解决方案3】:

    没有什么类似于.PHONY 可以阻止通过命令行构建目标。你可以这样做:

    common:
            $(if $(VAR),,$(error You must run 'make foo' or 'make bar'))
            touch $(VAR)
    

    【讨论】:

      猜你喜欢
      • 2013-05-03
      • 2010-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-28
      • 2017-12-05
      • 2019-02-06
      • 2018-03-05
      相关资源
      最近更新 更多