假设有一份makefile, 我的目的只是需要在debug版中加入 -g 的编译选项,那么可以这么做:
原makefile
$(CC) = g++ -g3 -gdwarf2
$(cc) = gcc -g3 -gdwarf2
all: executable
executable:
g++ -g -o output -lfl
:
flex -o
gcc -g -c
:
bison -d
g++ -g -c
:
g++ -g -c
clean:
rm -f .* .* output *.o
加入-g编译选项的makefile
CXXFLAGS = -g3 -gdwarf2
CCFLAGS = -g3 -gdwarf2
all: executable
debug: CXXFLAGS += -DDEBUG -g
debug: CCFLAGS += -DDEBUG -g
debug: executable
executable:
$(CXX) -o output -lfl
:
flex -o
$(CC) -c
参考文章:
How can I configure my makefile for debug and release builds?