]> granicus.if.org Git - esp-idf/commitdiff
build system: add menuconfig choice for optimization level, reorganize C*FLAGS
authorIvan Grokhotkov <ivan@espressif.com>
Mon, 17 Oct 2016 04:38:17 +0000 (12:38 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Mon, 17 Oct 2016 04:38:17 +0000 (12:38 +0800)
This change adds two options (Debug/Release) for optimization level.
Debug enables -O0, release enables -Os and adds -DNDEBUG (which removes all assert() statements).
Debugging symbols are kept in both cases, although we may add an option to strip output file if necessary.
Also we used to define all common compiler flags in CPPFLAGS, and then appended them to CFLAGS/CXXFLAGS.
It makes it impossible to add preprocessor macros to CPPFLAGS at component level (one has to use CFLAGS/CXXFLAGS instead).
Some third party libraries are not compatible with this approach. Changed to the more common way of using these variables.

Kconfig
components/log/log.c
make/component_common.mk
make/project.mk

diff --git a/Kconfig b/Kconfig
index 11ea099de2c469af97d80aef68f0b251b38d9a32..936181a9cb3a3400f72fc4a7f039bedcaaa24649 100644 (file)
--- a/Kconfig
+++ b/Kconfig
@@ -23,6 +23,17 @@ endmenu
 
 source "$COMPONENT_KCONFIGS_PROJBUILD"
 
+choice OPTIMIZATION_LEVEL
+    prompt "Optimization level"
+    default OPTIMIZATION_LEVEL_DEBUG
+    help
+        This option sets compiler optimization level.
+config OPTIMIZATION_LEVEL_DEBUG
+    bool "Debug"
+config OPTIMIZATION_LEVEL_RELEASE
+    bool "Release"
+endchoice
+
 menu "Component config"
 source "$COMPONENT_KCONFIGS"
 endmenu
index aae12a773579c45eae775470bfb59f10b1dad658..a2b41d7e62feb6e37ac6539220ef90ed27afc9e7 100644 (file)
@@ -284,7 +284,7 @@ static inline void heap_swap(int i, int j)
 }
 #endif //BOOTLOADER_BUILD
 
-inline IRAM_ATTR uint32_t esp_log_early_timestamp()
+IRAM_ATTR uint32_t esp_log_early_timestamp()
 {
     return xthal_get_ccount() / (CPU_CLK_FREQ_ROM / 1000);
 }
index ebad525a76036957d410f3d07ae339c60459054d..bf2eace0198c64a8072529513e28e8f05b8dab08 100644 (file)
@@ -91,15 +91,15 @@ define GenerateCompileTargets
 # $(1) - directory containing source files, relative to $(COMPONENT_PATH)
 $(1)/%.o: $$(COMPONENT_PATH)/$(1)/%.c | $(1)
        $$(summary) CC $$@
-       $$(Q) $$(CC) $$(CFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
+       $$(Q) $$(CC) $$(CFLAGS) $(CPPFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
 
 $(1)/%.o: $$(COMPONENT_PATH)/$(1)/%.cpp | $(1)
-       $$(summary) CC $$@
-       $$(Q) $$(CXX) $$(CXXFLAGS) $$(addprefix -I,$$(COMPONENT_INCLUDES)) $$(addprefix -I,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
+       $$(summary) CXX $$@
+       $$(Q) $$(CXX) $$(CXXFLAGS) $(CPPFLAGS) $$(addprefix -I,$$(COMPONENT_INCLUDES)) $$(addprefix -I,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
 
 $(1)/%.o: $$(COMPONENT_PATH)/$(1)/%.S | $(1)
-       $$(summary) CC $$@
-       $$(Q) $$(CC) $$(CFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
+       $$(summary) AS $$@
+       $$(Q) $$(CC) $$(CFLAGS) $(CPPFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I$(1) -c $$< -o $$@
 
 # CWD is build dir, create the build subdirectory if it doesn't exist
 $(1):
index d91165cfd751d16d6449904d891df15aef2e0e4c..49c349946781720d94520c403c8029bce661ca90 100644 (file)
@@ -157,15 +157,36 @@ LDFLAGS ?= -nostdlib \
 # If you need your component to add CFLAGS/etc globally for all source
 # files, set CFLAGS += in your component's Makefile.projbuild
 
-# CPPFLAGS used by an compile pass that uses the C preprocessor
-CPPFLAGS = -DESP_PLATFORM -Og -g3 -Wpointer-arith -Werror -Wno-error=unused-function -Wno-error=unused-but-set-variable \
-               -Wno-error=unused-variable -Wall -ffunction-sections -fdata-sections -mlongcalls -nostdlib -MMD -MP
+# CPPFLAGS used by C preprocessor
+CPPFLAGS = -DESP_PLATFORM
+
+# Warnings-related flags relevant both for C and C++
+COMMON_WARNING_FLAGS = -Wall -Werror \
+       -Wno-error=unused-function \
+       -Wno-error=unused-but-set-variable \
+       -Wno-error=unused-variable 
+
+# Flags which control code generation and dependency generation, both for C and C++
+COMMON_FLAGS = \
+       -ffunction-sections -fdata-sections \
+       -fstrict-volatile-bitfields \
+       -mlongcalls \
+       -nostdlib \
+       -MMD -MP
+
+# Optimization flags are set based on menuconfig choice
+ifneq ("$(CONFIG_OPTIMIZATION_LEVEL_RELEASE)","")
+OPTMIZATION_FLAGS = -Os
+CPPFLAGS += -DNDEBUG
+else
+OPTMIZATION_FLAGS = -O0
+endif
 
-# C flags use by C only
-CFLAGS = $(CPPFLAGS) -std=gnu99 -g3 -fstrict-volatile-bitfields
+# List of flags to pass to C compiler
+CFLAGS = -ggdb -std=gnu99 $(strip $(OPTMIZATION_FLAGS) $(COMMON_FLAGS) $(COMMON_WARNING_FLAGS))
 
-# CXXFLAGS uses by C++ only
-CXXFLAGS = $(CPPFLAGS) -Og -std=gnu++11 -g3 -fno-exceptions -fstrict-volatile-bitfields -fno-rtti
+# List of flags to pass to C++ compiler
+CXXFLAGS = -ggdb -std=gnu++11 -fno-exceptions -fno-rtti $(strip $(OPTMIZATION_FLAGS) $(COMMON_FLAGS) $(COMMON_WARNING_FLAGS))
 
 export CFLAGS CPPFLAGS CXXFLAGS