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.
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
}
#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);
}
# $(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):
# 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