GNU make manual 翻译( 一百七十五)

本文深入探讨了Makefile中`.DEFAULT_GOAL`变量的用途,包括如何设置、查询和重置缺省目标,以及设置多个目标时的注意事项。通过示例展示了`.DEFAULT_GOAL`在不同场景下的应用,帮助开发者更好地理解和利用这一特性。

继续翻译

`.DEFAULT_GOAL'
     Sets the default goal to be used if no targets were specified on
     the command line (*note Arguments to Specify the Goals: Goals.).
     The `.DEFAULT_GOAL' variable allows you to discover the current
     default goal, restart the default goal selection algorithm by
     clearing its value, or to explicitly set the default goal.  The
     following example illustrates these cases:

          # Query the default goal.
          ifeq ($(.DEFAULT_GOAL),)
            $(warning no default goal is set)
          endif

          .PHONY: foo
          foo: ; @echo $@

          $(warning default goal is $(.DEFAULT_GOAL))

          # Reset the default goal.
          .DEFAULT_GOAL :=

          .PHONY: bar
          bar: ; @echo $@

          $(warning default goal is $(.DEFAULT_GOAL))

          # Set our own.
          .DEFAULT_GOAL := foo

     This makefile prints:

          no default goal is set
          default goal is foo
          default goal is bar
          foo

     Note that assigning more than one target name to `.DEFAULT_GOAL' is
     illegal and will result in an error.

`.DEFAULT_GOAL'

设置如果在命令行中没有制定目的场合,缺省的终点(*note Arguments to Specify the Goals :Goals)。

.DEFAULT_GOAL 变量允许你发现当前的缺省的终点,通过清除它的值来重新设置缺省的终点。下面的例子给出了如何操作:

# Query the default goal.
ifeq ($(.DEFAULT_GOAL),)
  $(warning no default goal is set)
endif

.PHONY: foo
foo: ; @echo $@

$(warning default goal is $(.DEFAULT_GOAL))

# Reset the default goal.
.DEFAULT_GOAL :=

.PHONY: bar
bar: ; @echo $@

$(warning default goal is $(.DEFAULT_GOAL))

# Set our own.
.DEFAULT_GOAL := foo

这个 makefile 输出:

no default goal is set
default goal is foo
default goal is bar
foo

请注意设置多余一个的目的名给`.DEFAULT_GOAL' 是无效的,会造成错误。

后文待续

转载于:https://www.cnblogs.com/gaojian/archive/2012/10/05/2712160.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值