如何将宏定义作为make的参数传递? [英] How can a macro definition be passed as an argument to make?

查看:660
本文介绍了如何将宏定义作为make的参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望通过将C宏作为参数传递给make来定义C宏,该宏从命令行调用.

I wish to define a C macro by passing it as an argument to make, which is called from the command-line.

背景:我想指令要包括在我的C源代码被选择特定构建选项时.因此,我希望通过make命令行完成此操作,而不是修改源代码 makefile.

Background: I want the directive #define ENABLE_OPT 1 to be included in my C source code when a certain build option is chosen. Thus, I want this to be done via the make command-line instead of modifying the source code or the makefile.

如何实现?我发现make -DENABLE_OPT=1 -f Makefile会抛出错误,指出"E","N"等是要使之无效的参数.

How can this be achieved? I find that make -DENABLE_OPT=1 -f Makefile throws errors that 'E', 'N' etc. are invalid arguments to make.

推荐答案

您可以使用--eval,它将把字符串作为makefile语句求值:

You can use --eval, which will evaluate the string as a makefile statement:

make --eval="FLAGS+= -D ENABLE_OPT=1"

然后,将make变量FLAGS用作编译器参数来编译代码.

The make variable FLAGS is then used as a compiler argument to compile the code.

这篇关于如何将宏定义作为make的参数传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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