如何将宏定义作为make的参数传递? [英] How can a macro definition be passed as an argument to 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.
背景:我想指令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屋!