From f6dac334cf41c618f20e043f6ddd0faa21043d4f Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Fri, 7 Feb 2020 15:12:48 -0800 Subject: [PATCH] [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 --- Scripts/Makefile.configs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Scripts/Makefile.configs b/Scripts/Makefile.configs index 1263e9d2..13e11f74 100644 --- a/Scripts/Makefile.configs +++ b/Scripts/Makefile.configs @@ -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)