[Makefile] handle DEBUG more cleanly

Handle DEBUG more cleanly.
- DEBUG undefined: -O2 (same as before)
- DEBUG=0: same as undefined DEBUG (newly supported)
- DEBUG=1: enable debug symbol + -DDEBUG with -O2 enabled
- DEBUG=2: debug symbol + -DDEBUG + turn off -O2 (newly supported)
- other:   explicit error
This commit is contained in:
Isaku Yamahata
2020-02-07 15:15:00 -08:00
parent 32c1965fdd
commit f6dac334cf
+24 -9
View File
@@ -23,22 +23,37 @@ OBJCOPY ?= objcopy
SYS ?= $(shell $(CC) -dumpmachine)
export SYS
DEBUG ?=
export DEBUG
CFLAGS += -Wall -std=c11
CXXFLAGS += -Wall -std=c++14
ifeq ($(DEBUG),1)
DEBUG ?=
export DEBUG
# make DEBUG=0 synonym for undefined DEBUG
ifeq ($(DEBUG),0)
override DEBUG =
endif
ifeq ($(DEBUG),)
# -O2: yes -DDEBUG: no
CFLAGS += -O2
CXXFLAGS += -O2
else ifeq ($(DEBUG),1)
# -O2: yes -DDEBUG: yes
CFLAGS += -O2 -gdwarf-2 -g3
CXXFLAGS += -O2 -gdwarf-2 -g3
CFLAGS += -DDEBUG
ASFLAGS += -DDEBUG
else ifeq ($(DEBUG),2)
# -O2: no -DDEBUG: yes
CFLAGS += -gdwarf-2 -g3
CXXFLAGS += -gdwarf-2 -g3
CFLAGS += -DDEBUG
ASFLAGS += -DDEBUG
endif
ifeq ($(DEBUG),)
CFLAGS += -O2
CXXFLAGS += -O2
# other makefiles assumes only DEBUG=1 for debug
override DEBUG = 1
else
$(error unknown DEBUG value "$(DEBUG)")
endif
ifeq ($(WERROR),1)