Here is a part from a Makefile that I use regularly (in this example, it's trying to build a program named foo).
If you run it like $ make BUILD=debug
or $ make debug
then the Debug CFLAGS will be used. These turn off optimization (-O0
) and includes debugging symbols (-g
).
If you omit these flags (by running $ make
without any additional parameters), you'll build the Release CFLAGS version where optimization is turned on (-O2
), debugging symbols stripped (-s
) and assertions disabled (-DNDEBUG
).
As others have suggested, you can experiment with different -O*
settings dependig on your specific needs.
ifeq ($(BUILD),debug)
# "Debug" build - no optimization, and debugging symbols
CFLAGS += -O0 -g
else
# "Release" build - optimization, and no debug symbols
CFLAGS += -O2 -s -DNDEBUG
endif
all: foo
debug:
make "BUILD=debug"
foo: foo.o
# The rest of the makefile comes here...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…