如何为调试和发布版本配置我的makefile? [英] How can I configure my makefile for debug and release builds?
问题描述
我的项目有以下makefile,我想对其进行配置以进行发布和调试.在我的代码中,我有很多#ifdef DEBUG
宏,因此只需设置此宏并将-g3 -gdwarf2
标志添加到编译器即可.我该怎么办?
I have the following makefile for my project, and I'd like to configure it for release and debug builds. In my code, I have lots of #ifdef DEBUG
macros in place, so it's simply a matter of setting this macro and adding the -g3 -gdwarf2
flags to the compilers. How can I do this?
$(CC) = g++ -g3 -gdwarf2
$(cc) = gcc -g3 -gdwarf2
all: executable
executable: CommandParser.tab.o CommandParser.yy.o Command.o
g++ -g -o output CommandParser.yy.o CommandParser.tab.o Command.o -lfl
CommandParser.yy.o: CommandParser.l
flex -o CommandParser.yy.c CommandParser.l
gcc -g -c CommandParser.yy.c
CommandParser.tab.o: CommandParser.y
bison -d CommandParser.y
g++ -g -c CommandParser.tab.c
Command.o: Command.cpp
g++ -g -c Command.cpp
clean:
rm -f CommandParser.tab.* CommandParser.yy.* output *.o
为了澄清,当我说发布/调试版本时,我希望能够只键入make
并获得发布版本或make debug
并获得调试版本,而无需手动注释makefile中的内容.
Just to clarify, when I say release/debug builds, I want to be able to just type make
and get a release build or make debug
and get a debug build, without manually commenting out things in the makefile.
推荐答案
您可以使用请记住在所有编译命令中都使用$(CXX)或$(CC).
Remember to use $(CXX) or $(CC) in all your compile commands.
然后,"make debug"将具有-DDEBUG和-g之类的额外标志,而"make"则不会.
Then, 'make debug' will have extra flags like -DDEBUG and -g where as 'make' will not.
顺便提一句,您可以像其他帖子所建议的那样使Makefile更加简洁.
On a side note, you can make your Makefile a lot more concise like other posts had suggested.
这篇关于如何为调试和发布版本配置我的makefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!