我的项目有以下makefile,我想为发布和调试版本配置它.在我的代码中,我有很多#ifdef DEBUG宏,所以这只是设置这个宏并将-g3 -gdwarf2标志添加到编译器的问题.我怎样才能做到这一点?
$(CC) = g++ -g3 -gdwarf2
$(cc) = gcc -g3 -gdwarf2
all: executable
executable: CommandParser.tab.o CommandParser.yy.o Command.o
g++ -g -o output CommandParser.yy.o CommandParser.tab.o Command.o -lfl
CommandParser.yy.o: CommandParser.l
flex -o CommandParser.yy.c CommandParser.l
gcc -g -c CommandParser.yy.c
CommandParser.tab.o: CommandParser.y
bison -d CommandParser.y
g++ -g -c CommandParser.tab.c
Command.o: Command.cpp
g++ -g -c Command.cpp
clean:
rm -f CommandParser.tab.* CommandParser.yy.* output *.o
Run Code Online (Sandbox Code Playgroud)
只是为了澄清,当我说发布/调试版本时,我希望能够只键入make并获得发布版本或make debug获得调试版本,而无需手动注释掉makefile中的内容.
我有一个makefile,变量$DEBUG决定是否构建部署或调试.有一个主要的Makefile,以及包含的多个特定于平台的makefile.我希望在构建目标时自动将变量$DEBUG设置为.1test
主要的makefile:
DEBUG := 0
test : override DEBUG := 1
DIST_DIR := dist/
ifeq ($(DEBUG), 1)
BUILD_DIR := build/debug
else
BUILD_DIR := build/deploy
endif
# detect operating system
ifeq ($(OS), Windows_NT)
UNAME := Windows
else
UNAME := $(shell uname -s)
endif
# include platform-specific Makefile
export
ifeq ($(UNAME), Darwin)
include Makefile.darwin
endif
ifeq ($(UNAME), Linux)
include Makefile.linux
endif
Run Code Online (Sandbox Code Playgroud)
并且特定于平台Makefile.linux:
...
CXX := clang++-3.8
CXXFLAGS := -std=c++14 -fPIC -I./external/include -fcolor-diagnostics
LDFLAGS := …Run Code Online (Sandbox Code Playgroud)