make笔记

2 篇文章 0 订阅

make 工具的官网文档, TDM-GCC 工具链的 mingw32-make 命令帮助信息如下:

> mingw32-make -h
Usage: mingw32-make [options] [target] ...
Options:
  -b, -m                      Ignored for compatibility.
  -B, --always-make           Unconditionally make all targets.
  -C DIRECTORY, --directory=DIRECTORY
                              Change to DIRECTORY before doing anything.
  -d                          Print lots of debugging information.
  --debug[=FLAGS]             Print various types of debugging information.
  -e, --environment-overrides
                              Environment variables override makefiles.
  --eval=STRING               Evaluate STRING as a makefile statement.
  -f FILE, --file=FILE, --makefile=FILE
                              Read FILE as a makefile.
  -h, --help                  Print this message and exit.
  -i, --ignore-errors         Ignore errors from recipes.
  -I DIRECTORY, --include-dir=DIRECTORY
                              Search DIRECTORY for included makefiles.
  -j [N], --jobs[=N]          Allow N jobs at once; infinite jobs with no arg.
  -k, --keep-going            Keep going when some targets can't be made.
  -l [N], --load-average[=N], --max-load[=N]
                              Don't start multiple jobs unless load is below N.
  -L, --check-symlink-times   Use the latest mtime between symlinks and target.
  -n, --just-print, --dry-run, --recon
                              Don't actually run any recipe; just print them.
  -o FILE, --old-file=FILE, --assume-old=FILE
                              Consider FILE to be very old and don't remake it.
  -p, --print-data-base       Print make's internal database.
  -q, --question              Run no recipe; exit status says if up to date.
  -r, --no-builtin-rules      Disable the built-in implicit rules.
  -R, --no-builtin-variables  Disable the built-in variable settings.
  -s, --silent, --quiet       Don't echo recipes.
  -S, --no-keep-going, --stop
                              Turns off -k.
  -t, --touch                 Touch targets instead of remaking them.
  --trace                     Print tracing information.
  -v, --version               Print the version number of make and exit.
  -w, --print-directory       Print the current directory.
  --no-print-directory        Turn off -w, even if it was turned on implicitly.
  -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE
                              Consider FILE to be infinitely new.
  --warn-undefined-variables  Warn when an undefined variable is referenced.

This program built for i686-pc-mingw32
Report bugs to <bug-make@gnu.org>

规则文件

当执行 mingw32-make 命令时,如果没有使用 -f 参数指定文件的话它会从当前目录依次寻找 GNUmakefilemakefileMakefile
若未找到 3 个文件中的任意 1 个就会报错。
官方建议用 Makkefile 作为规则文件名。
当规则文件名不为默认名称时,必须使用 -f <makefile_name>--file=<makefile_name> 来指定规则文件名称。

make 如何处理规则文件中的规则

mingw32-make 在找到 Makefie 后会执行文件中的第1条规则,如果 Makefile 内容如下:

# Makefile 文件内容
first: 
	echo $@
second: 
	@echo $@
third: 
	@echo $@

当在该目录下执行 mingw32-make 命令时会得到如下结果:

> mingw32-make
echo first
first

从结题可以看出 make 执行了规则文件中的第1第条规则,
所以规则文件中的第1条规则通常是我们需要执行的规则。修改上面的 Makefile 文件:

# Makefile 文件内容
all: third second

first: 
	echo $@
second: 
	@echo $@
third: 
	@echo $@

再次执行 mingw32-make 命令时会得到如下结果:

> mingw32-make
third
second

1. 通过特殊变量指定默认规则

在 MakeFile 文件中可能指定 特殊变量中的 .DEFAULT_GOAL 变量值来设置默认的规则,示例如下:

# Makefile 文件内容
all: third second
.DEFAULT_GOAL = second

first: 
	echo $@
second: 
	@echo $@
third: 
	@echo $@

再次执行 mingw32-make 命令得到如下结果:

> mingw32-make
second

2. 通过命令参数指默认规则

在执行 mingw32-make 命令时指定需要执行的规则

> mingw32-make third first
third
echo first
first

从执行结果可以看出参数指定的规则优先于.DEFAULT_GOAL变量

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值