Merge branch 'feature/release_build' into 'master'

Add menuconfig setting for optimization level

This change adds two options (Debug/Release) for optimization level.
- Debug (default) enables -O0
- Release enables -Os and adds `-DNDEBUG`, which removes all assert() statements

These options may be overriden at project level by adding necessary flags to CFLAGS/CXXFLAGS.

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 prepended them to CFLAGS/CXXFLAGS.
It made it impossible to add preprocessor macros to CPPFLAGS at component level (one had 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.

CI will build both debug (default) and release.


See merge request !138
This commit is contained in:
Ivan Grokhotkov 2016-10-21 10:56:03 +08:00
commit 4f704ac2fe
9 changed files with 87 additions and 22 deletions

View file

@ -37,6 +37,12 @@ build_template_app:
# branch
- git checkout ${CI_BUILD_REF_NAME} || echo "Using esp-idf-template default branch..."
- make defconfig
# Test debug build (default)
- make all V=1
# Now test release build
- make clean
- sed -i.bak -e's/CONFIG_OPTIMIZATION_LEVEL_DEBUG\=y/CONFIG_OPTIMIZATION_LEVEL_RELEASE=y/' sdkconfig
- make defconfig
- make all V=1

20
Kconfig
View file

@ -23,6 +23,26 @@ endmenu
source "$COMPONENT_KCONFIGS_PROJBUILD"
choice OPTIMIZATION_LEVEL
prompt "Optimization level"
default OPTIMIZATION_LEVEL_DEBUG
help
This option sets optimization level.
- for "Release" setting, -Os flag is added to CFLAGS,
and -DNDEBUG flag is added to CPPFLAGS.
- for "Debug" setting, -Og flag is added to CFLAGS.
To override any of these settings, set CFLAGS and/or CPPFLAGS
in project makefile, before including $(IDF_PATH)/make/project.mk.
config OPTIMIZATION_LEVEL_DEBUG
bool "Debug"
config OPTIMIZATION_LEVEL_RELEASE
bool "Release"
endchoice
menu "Component config"
source "$COMPONENT_KCONFIGS"
endmenu

View 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);
}

View file

@ -7177,7 +7177,7 @@ uint32_t nghttp2_session_get_remote_settings(nghttp2_session *session,
return session->remote_settings.max_header_list_size;
}
assert(0);
abort();
}
static int nghttp2_session_upgrade_internal(nghttp2_session *session,

View file

@ -769,7 +769,7 @@ void Page::invalidateCache()
void Page::debugDump() const
{
printf("state=%x addr=%x seq=%d\nfirstUsed=%d nextFree=%d used=%d erased=%d\n", mState, mBaseAddress, mSeqNumber, static_cast<int>(mFirstUsedEntry), static_cast<int>(mNextFreeEntry), mUsedEntryCount, mErasedEntryCount);
printf("state=%x addr=%x seq=%d\nfirstUsed=%d nextFree=%d used=%d erased=%d\n", (int) mState, mBaseAddress, mSeqNumber, static_cast<int>(mFirstUsedEntry), static_cast<int>(mNextFreeEntry), mUsedEntryCount, mErasedEntryCount);
size_t skip = 0;
for (size_t i = 0; i < ENTRY_COUNT; ++i) {
printf("%3d: ", static_cast<int>(i));

View file

@ -49,7 +49,7 @@ esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount)
return activatePage();
} else {
uint32_t lastSeqNo;
assert(mPageList.back().getSeqNumber(lastSeqNo) == ESP_OK);
ESP_ERROR_CHECK( mPageList.back().getSeqNumber(lastSeqNo) );
mSeqNumber = lastSeqNo + 1;
}
@ -142,7 +142,9 @@ esp_err_t PageManager::requestNewPage()
Page* newPage = &mPageList.back();
Page* erasedPage = maxErasedItemsPageIt;
#ifndef NDEBUG
size_t usedEntries = erasedPage->getUsedEntryCount();
#endif
err = erasedPage->markFreeing();
if (err != ESP_OK) {
return err;

View file

@ -123,8 +123,7 @@ esp_err_t Storage::writeItem(uint8_t nsIndex, ItemType datatype, const char* key
if (findPage) {
if (findPage->state() == Page::PageState::UNINITIALIZED ||
findPage->state() == Page::PageState::INVALID) {
auto err = findItem(nsIndex, datatype, key, findPage, item);
assert(err == ESP_OK);
ESP_ERROR_CHECK( findItem(nsIndex, datatype, key, findPage, item) );
}
err = findPage->eraseItem(nsIndex, datatype, key);
if (err == ESP_ERR_FLASH_OP_FAIL) {

View 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):

View file

@ -151,23 +151,61 @@ LDFLAGS ?= -nostdlib \
-Wl,-EL
# Set default CPPFLAGS, CFLAGS, CXXFLAGS
#
# These are exported so that components can use them when compiling.
#
# If you need your component to add CFLAGS/etc for it's own source compilation only, set CFLAGS += in your component's Makefile.
#
# If you need your component to add CFLAGS/etc globally for all source
# files, set CFLAGS += in your component's Makefile.projbuild
# files, set CFLAGS += in your component's Makefile.projbuild
# If you need to set CFLAGS/CPPFLAGS/CXXFLAGS at project level, set them in application Makefile
# before including project.mk. Default flags will be added before the ones provided in application Makefile.
# 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
# If any flags are defined in application Makefile, add them at the end.
CPPFLAGS := -DESP_PLATFORM $(CPPFLAGS)
# C flags use by C only
CFLAGS = $(CPPFLAGS) -std=gnu99 -g3 -fstrict-volatile-bitfields
# 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
# CXXFLAGS uses by C++ only
CXXFLAGS = $(CPPFLAGS) -Og -std=gnu++11 -g3 -fno-exceptions -fstrict-volatile-bitfields -fno-rtti
# 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)","")
OPTIMIZATION_FLAGS = -Os
CPPFLAGS += -DNDEBUG
else
OPTIMIZATION_FLAGS = -Og
endif
# Enable generation of debugging symbols
OPTIMIZATION_FLAGS += -ggdb
# List of flags to pass to C compiler
# If any flags are defined in application Makefile, add them at the end.
CFLAGS := $(strip \
-std=gnu99 \
$(OPTIMIZATION_FLAGS) \
$(COMMON_FLAGS) \
$(COMMON_WARNING_FLAGS) \
$(CFLAGS))
# List of flags to pass to C++ compiler
# If any flags are defined in application Makefile, add them at the end.
CXXFLAGS := $(strip \
-std=gnu++11 \
-fno-exceptions \
-fno-rtti \
$(OPTIMIZATION_FLAGS) \
$(COMMON_FLAGS) \
$(COMMON_WARNING_FLAGS) \
$(CXXFLAGS))
export CFLAGS CPPFLAGS CXXFLAGS