How to add release target to Makefile?

风格不统一 提交于 2019-11-29 12:28:38

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!