makefile default target

本文深入探讨了在Make工具中如何确定默认构建目标的过程。当没有指定目标时,Make会处理第一个不以特殊字符开头的目标,这通常被视为默认目标。文章还介绍了如何通过.DEFAULT_GOAL特殊目标来覆盖这一行为,并提供了示例说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How does “make” app know default target to build if no target is specified?

$ make

which target to build?

By default, it begins by processing the first target that does not begin with a . aka the default goal; to do that, it may have to process other targets - specifically, ones the first target depends on.

The GNU Make Manual covers all this stuff, and is a surprisingly easy and informative read.

If you like to override this behavior, there is the .DEFAULT_GOAL: special target. An example from GNU make manual.

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

About .DEFAULT, have not understand it. there is a blog for it.

all:gao
    @echo "final"
.DEFAULT:
  @echo "In default"

由于 gao 是一个前提条件,但是 makefile中没有一个名字为 gao的目的。

所以符合 .DEFAULT 目的的执行条件。

故执行结果为:

In default

final

完毕

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值