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

后端 未结 7 593
借酒劲吻你
借酒劲吻你 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:34

    Completing the answers from earlier... You need to reference the variables you define info in your commands...

    DEBUG ?= 1
    ifeq (DEBUG, 1)
        CFLAGS =-g3 -gdwarf2 -DDEBUG
    else
        CFLAGS=-DNDEBUG
    endif
    
    CXX = g++ $(CFLAGS)
    CC = gcc $(CFLAGS)
    
    all: 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
    
    CommandParser.tab.o: CommandParser.y
        bison -d CommandParser.y
        $(CXX) -c CommandParser.tab.c
    
    Command.o: Command.cpp
        $(CXX) -c Command.cpp
    
    clean:
        rm -f CommandParser.tab.* CommandParser.yy.* output *.o
    

提交回复
热议问题