How can I configure my makefile for debug and release builds?

后端 未结 7 618
借酒劲吻你
借酒劲吻你 2020-12-12 08:41

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 plac

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 09:31

    You can use Target-specific Variable Values. Example:

    CXXFLAGS = -g3 -gdwarf2
    CCFLAGS = -g3 -gdwarf2
    
    all: executable
    
    debug: CXXFLAGS += -DDEBUG -g
    debug: CCFLAGS += -DDEBUG -g
    debug: executable
    
    executable: CommandParser.tab.o CommandParser.yy.o Command.o
        $(CXX) -o output CommandParser.yy.o CommandParser.tab.o Command.o -lfl
    
    CommandParser.yy.o: CommandParser.l 
        flex -o CommandParser.yy.c CommandParser.l
        $(CC) -c CommandParser.yy.c
    

    Remember to use $(CXX) or $(CC) in all your compile commands.

    Then, 'make debug' will have extra flags like -DDEBUG and -g where as 'make' will not.

    On a side note, you can make your Makefile a lot more concise like other posts had suggested.

提交回复
热议问题