使用makefile目标设置构建选项 [英] using makefile targets to set build options

查看:110
本文介绍了使用makefile目标设置构建选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是微不足道的,或者与应如何使用make的原理背道而驰,但是我希望有一个命令行显示为"make debug"而不是"make DEBUG = 1".我尝试创建一个称为debug的伪造目标,除了设置DEBUG变量外什么也没做,但是"make debug build"和"make build debug"之间是有区别的–也就是说,在一种情况下,变量是在build之后设置的发生了.

This is either trivial or runs counter to the philosophy of how make should be used, but I'd like to have a command line that reads as "make debug" rather than "make DEBUG=1". I tried creating a phony target called debug that did nothing except set the DEBUG variable, but then there was a difference between "make debug build" and "make build debug"--namely that in one case, the variable got set after the build happened.

是否可以赋予某些目标优先级?

Is there a way to give certain targets precedence?

感谢您的帮助.

推荐答案

您也可以通过查看MAKECMDGOALS变量来做到这一点

You can also do it by looking at the MAKECMDGOALS variable

ifneq "$(findstring debug, $(MAKECMDGOALS))" ""
DEBUG = 1
endif

build:
    @echo build and DEBUG is [$(DEBUG)]

debug:

当您调用它时会发生以下情况:

This is what happens when you call it:

$ make build
build and DEBUG is []
$ make build debug
build and DEBUG is [1]
make: Nothing to be done for `debug'.
$ make debug build
make: Nothing to be done for `debug'.
build and DEBUG is [1]

这篇关于使用makefile目标设置构建选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆