How to add release target to Makefile?

后端 未结 1 654
长情又很酷
长情又很酷 2020-12-20 06:25

I have following Makefile, and I would like to configure it to produce debug build by default and release build by specifying corresponding target.

The problem I am

相关标签:
1条回答
  • 2020-12-20 06:59

    Debug and release targets get build with different macros (e.g. NDEBUG) and different optimization levels. You normally do not want to mix debug and release object files, hence they need to be compiled into different directories.

    I often use a different top-level build directory for different build modes this way:

    BUILD := debug
    BUILD_DIR := build/${BUILD}
    

    And compiler flags this way:

    cppflags.debug :=
    cppflags.release := -DNDEBUG
    cppflags := ${cppflags.${BUILD}} ${CPPFLAGS}
    
    cxxflags.debug := -Og
    cxxflags.release := -O3 -march=native
    cxxflags := -g -pthread ${cxxflags.${BUILD}} ${CXXFLAGS}
    

    And then build your objects into BUILD_DIR.

    When you invoke it as make BUILD=release that overrides BUILD := debug assignment made in the makefile.

    0 讨论(0)
提交回复
热议问题