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

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

    If by configure release/build, you mean you only need one config per makefile, then it is simply a matter and decoupling CC and CFLAGS:

    CFLAGS=-DDEBUG
    #CFLAGS=-O2 -DNDEBUG
    CC=g++ -g3 -gdwarf2 $(CFLAGS)
    

    Depending on whether you can use gnu makefile, you can use conditional to make this a bit fancier, and control it from the command line:

    DEBUG ?= 1
    ifeq ($(DEBUG), 1)
        CFLAGS =-DDEBUG
    else
        CFLAGS=-DNDEBUG
    endif
    
    .o: .c
        $(CC) -c $< -o $@ $(CFLAGS)
    

    and then use:

    make DEBUG=0
    make DEBUG=1
    

    If you need to control both configurations at the same time, I think it is better to have build directories, and one build directory / config.

提交回复
热议问题