mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
build system: Project ELF should depend on linker scripts, binary libraries
TW#7816
This commit is contained in:
parent
9a378bca0e
commit
bbe1bceda8
@ -5,5 +5,8 @@
|
|||||||
# we pull in bootloader-specific linker arguments.
|
# we pull in bootloader-specific linker arguments.
|
||||||
#
|
#
|
||||||
|
|
||||||
COMPONENT_ADD_LDFLAGS := -L $(COMPONENT_PATH) -lmain -T esp32.bootloader.ld -T $(IDF_PATH)/components/esp32/ld/esp32.rom.ld
|
LINKER_SCRIPTS := esp32.bootloader.ld $(IDF_PATH)/components/esp32/ld/esp32.rom.ld
|
||||||
|
|
||||||
|
COMPONENT_ADD_LDFLAGS := -L $(COMPONENT_PATH) -lmain $(addprefix -T ,$(LINKER_SCRIPTS))
|
||||||
|
|
||||||
|
COMPONENT_ADD_LINKER_DEPS := $(LINKER_SCRIPTS)
|
||||||
|
@ -33,8 +33,10 @@ COMPONENT_ADD_INCLUDEDIRS := bluedroid/bta/include \
|
|||||||
LIBS := btdm_app
|
LIBS := btdm_app
|
||||||
|
|
||||||
COMPONENT_ADD_LDFLAGS := -lbt -L $(COMPONENT_PATH)/lib \
|
COMPONENT_ADD_LDFLAGS := -lbt -L $(COMPONENT_PATH)/lib \
|
||||||
$(addprefix -l,$(LIBS)) \
|
$(addprefix -l,$(LIBS))
|
||||||
$(LINKER_SCRIPTS)
|
|
||||||
|
# re-link program if BT binary libs change
|
||||||
|
COMPONENT_ADD_LINKER_DEPS := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
|
||||||
|
|
||||||
COMPONENT_SRCDIRS := bluedroid/bta/dm \
|
COMPONENT_SRCDIRS := bluedroid/bta/dm \
|
||||||
bluedroid/bta/gatt \
|
bluedroid/bta/gatt \
|
||||||
@ -68,7 +70,4 @@ COMPONENT_SRCDIRS := bluedroid/bta/dm \
|
|||||||
bluedroid \
|
bluedroid \
|
||||||
.
|
.
|
||||||
|
|
||||||
ALL_LIB_FILES := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
|
|
||||||
$(COMPONENT_LIBRARY): $(ALL_LIB_FILES)
|
|
||||||
|
|
||||||
COMPONENT_SUBMODULES += lib
|
COMPONENT_SUBMODULES += lib
|
||||||
|
@ -6,31 +6,27 @@ COMPONENT_SRCDIRS := . hwcrypto
|
|||||||
|
|
||||||
LIBS := core net80211 phy rtc pp wpa smartconfig coexist wps wpa2
|
LIBS := core net80211 phy rtc pp wpa smartconfig coexist wps wpa2
|
||||||
|
|
||||||
LINKER_SCRIPTS += -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld
|
LINKER_SCRIPTS += esp32.common.ld esp32.rom.ld esp32.peripherals.ld
|
||||||
|
|
||||||
ifeq ("$(CONFIG_NEWLIB_NANO_FORMAT)","y")
|
ifeq ("$(CONFIG_NEWLIB_NANO_FORMAT)","y")
|
||||||
LINKER_SCRIPTS += -T esp32.rom.nanofmt.ld
|
LINKER_SCRIPTS += esp32.rom.nanofmt.ld
|
||||||
endif
|
endif
|
||||||
|
|
||||||
COMPONENT_ADD_LDFLAGS := -lesp32 \
|
COMPONENT_ADD_LDFLAGS := -lesp32 \
|
||||||
$(COMPONENT_PATH)/libhal.a \
|
$(COMPONENT_PATH)/libhal.a \
|
||||||
-L$(COMPONENT_PATH)/lib \
|
-L$(COMPONENT_PATH)/lib \
|
||||||
$(addprefix -l,$(LIBS)) \
|
$(addprefix -l,$(LIBS)) \
|
||||||
-L $(COMPONENT_PATH)/ld \
|
-L $(COMPONENT_PATH)/ld \
|
||||||
$(LINKER_SCRIPTS)
|
-T esp32_out.ld \
|
||||||
|
$(addprefix -T ,$(LINKER_SCRIPTS))
|
||||||
|
|
||||||
ALL_LIB_FILES := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
|
ALL_LIB_FILES := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
|
||||||
|
|
||||||
COMPONENT_SUBMODULES += lib
|
COMPONENT_SUBMODULES += lib
|
||||||
|
|
||||||
# this is a hack to make sure the app is re-linked if the binary
|
# final linking of project ELF depends on all binary libraries, and
|
||||||
# libraries change or are updated. If they change, the main esp32
|
# all linker scripts (except esp32_out.ld, as this is code generated here.)
|
||||||
# library will be rebuild by AR andthis will trigger a re-linking of
|
COMPONENT_ADD_LINKER_DEPS := $(ALL_LIB_FILES) $(addprefix ld/,$(LINKER_SCRIPTS))
|
||||||
# the entire app.
|
|
||||||
#
|
|
||||||
# It would be better for components to be able to expose any of these
|
|
||||||
# non-standard dependencies via get_variable, but this will do for now.
|
|
||||||
$(COMPONENT_LIBRARY): $(ALL_LIB_FILES)
|
|
||||||
|
|
||||||
# Preprocess esp32.ld linker script into esp32_out.ld
|
# Preprocess esp32.ld linker script into esp32_out.ld
|
||||||
#
|
#
|
||||||
|
@ -5,6 +5,10 @@ else
|
|||||||
LIBC_PATH := $(COMPONENT_PATH)/lib/libc.a
|
LIBC_PATH := $(COMPONENT_PATH)/lib/libc.a
|
||||||
endif
|
endif
|
||||||
|
|
||||||
COMPONENT_ADD_LDFLAGS := $(LIBC_PATH) $(COMPONENT_PATH)/lib/libm.a -lnewlib
|
LIBM_PATH := $(COMPONENT_PATH)/lib/libm.a
|
||||||
|
|
||||||
|
COMPONENT_ADD_LDFLAGS := $(LIBC_PATH) $(LIBM_PATH) -lnewlib
|
||||||
|
|
||||||
|
COMPONENT_ADD_LINKER_DEPS := $(LIBC_PATH) $(LIBM_PATH)
|
||||||
|
|
||||||
COMPONENT_ADD_INCLUDEDIRS := include platform_include
|
COMPONENT_ADD_INCLUDEDIRS := include platform_include
|
||||||
|
@ -188,6 +188,10 @@ The following variables can be set inside ``component.mk`` to control build sett
|
|||||||
are available at all times. It is necessary if one component
|
are available at all times. It is necessary if one component
|
||||||
generates an include file which you then want to include in another
|
generates an include file which you then want to include in another
|
||||||
component. Most components do not need to set this variable.
|
component. Most components do not need to set this variable.
|
||||||
|
- ``COMPONENT_ADD_LINKER_DEPS``: Optional list of component-relative paths
|
||||||
|
to files which should trigger a re-link of the ELF file if they change.
|
||||||
|
Typically used for linker script files and binary libraries. Most components do
|
||||||
|
not need to set this variable.
|
||||||
|
|
||||||
The following variable only works for components that are part of esp-idf itself:
|
The following variable only works for components that are part of esp-idf itself:
|
||||||
|
|
||||||
|
@ -52,5 +52,5 @@ endef
|
|||||||
#
|
#
|
||||||
# example $(call resolvepath,$(CONFIG_PATH),$(CONFIG_DIR))
|
# example $(call resolvepath,$(CONFIG_PATH),$(CONFIG_DIR))
|
||||||
define resolvepath
|
define resolvepath
|
||||||
$(if $(filter /%,$(1)),$(1),$(subst //,/,$(2)/$(1)))
|
$(foreach dir,$(1),$(if $(filter /%,$(dir)),$(dir),$(subst //,/,$(2)/$(dir))))
|
||||||
endef
|
endef
|
||||||
|
@ -95,7 +95,7 @@ COMPONENT_INCLUDES := $(OWN_INCLUDES) $(filter-out $(OWN_INCLUDES),$(COMPONENT_I
|
|||||||
#
|
#
|
||||||
# This means if directories move (breaking absolute paths), don't need to 'make clean'
|
# This means if directories move (breaking absolute paths), don't need to 'make clean'
|
||||||
define MakeVariablePath
|
define MakeVariablePath
|
||||||
$(subst $(IDF_PATH),$$(IDF_PATH),$(subst $(PROJECT_PATH),$$(PROJECT_PATH),$(subst $(BUILD_DIR_BASE),\$$(BUILD_DIR_BASE),$(1))))
|
$(subst $(IDF_PATH),$$(IDF_PATH),$(subst $(PROJECT_PATH),$$(PROJECT_PATH),$(subst $(BUILD_DIR_BASE),$$(BUILD_DIR_BASE),$(1))))
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# component_project_vars.mk target for the component. This is used to
|
# component_project_vars.mk target for the component. This is used to
|
||||||
@ -116,6 +116,7 @@ component_project_vars.mk::
|
|||||||
@echo '# Automatically generated build file. Do not edit.' > $@
|
@echo '# Automatically generated build file. Do not edit.' > $@
|
||||||
@echo 'COMPONENT_INCLUDES += $(call MakeVariablePath,$(addprefix $(COMPONENT_PATH)/,$(COMPONENT_ADD_INCLUDEDIRS)))' >> $@
|
@echo 'COMPONENT_INCLUDES += $(call MakeVariablePath,$(addprefix $(COMPONENT_PATH)/,$(COMPONENT_ADD_INCLUDEDIRS)))' >> $@
|
||||||
@echo 'COMPONENT_LDFLAGS += $(call MakeVariablePath,$(COMPONENT_ADD_LDFLAGS))' >> $@
|
@echo 'COMPONENT_LDFLAGS += $(call MakeVariablePath,$(COMPONENT_ADD_LDFLAGS))' >> $@
|
||||||
|
@echo 'COMPONENT_LINKER_DEPS += $(call MakeVariablePath,$(call resolvepath,$(COMPONENT_ADD_LINKER_DEPS),$(COMPONENT_PATH)))' >> $@
|
||||||
@echo 'COMPONENT_SUBMODULES += $(call MakeVariablePath,$(addprefix $(COMPONENT_PATH)/,$(COMPONENT_SUBMODULES)))' >> $@
|
@echo 'COMPONENT_SUBMODULES += $(call MakeVariablePath,$(addprefix $(COMPONENT_PATH)/,$(COMPONENT_SUBMODULES)))' >> $@
|
||||||
@echo '$(COMPONENT_NAME)-build: $(addsuffix -build,$(COMPONENT_DEPENDS))' >> $@
|
@echo '$(COMPONENT_NAME)-build: $(addsuffix -build,$(COMPONENT_DEPENDS))' >> $@
|
||||||
|
|
||||||
|
@ -150,8 +150,6 @@ endif
|
|||||||
# Set default LDFLAGS
|
# Set default LDFLAGS
|
||||||
|
|
||||||
LDFLAGS ?= -nostdlib \
|
LDFLAGS ?= -nostdlib \
|
||||||
-L$(IDF_PATH)/lib \
|
|
||||||
-L$(IDF_PATH)/ld \
|
|
||||||
$(addprefix -L$(BUILD_DIR_BASE)/,$(COMPONENTS) $(TEST_COMPONENT_NAMES) $(SRCDIRS) ) \
|
$(addprefix -L$(BUILD_DIR_BASE)/,$(COMPONENTS) $(TEST_COMPONENT_NAMES) $(SRCDIRS) ) \
|
||||||
-u call_user_start_cpu0 \
|
-u call_user_start_cpu0 \
|
||||||
$(EXTRA_LDFLAGS) \
|
$(EXTRA_LDFLAGS) \
|
||||||
@ -273,7 +271,10 @@ COMPONENT_LIBRARIES = $(filter $(notdir $(COMPONENT_PATHS_BUILDABLE)) $(TEST_COM
|
|||||||
|
|
||||||
# ELF depends on the library archive files for COMPONENT_LIBRARIES
|
# ELF depends on the library archive files for COMPONENT_LIBRARIES
|
||||||
# the rules to build these are emitted as part of GenerateComponentTarget below
|
# the rules to build these are emitted as part of GenerateComponentTarget below
|
||||||
$(APP_ELF): $(foreach libcomp,$(COMPONENT_LIBRARIES),$(BUILD_DIR_BASE)/$(libcomp)/lib$(libcomp).a)
|
#
|
||||||
|
# also depends on additional dependencies (linker scripts & binary libraries)
|
||||||
|
# stored in COMPONENT_LINKER_DEPS, built via component.mk files' COMPONENT_ADD_LINKER_DEPS variable
|
||||||
|
$(APP_ELF): $(foreach libcomp,$(COMPONENT_LIBRARIES),$(BUILD_DIR_BASE)/$(libcomp)/lib$(libcomp).a) $(COMPONENT_LINKER_DEPS)
|
||||||
$(summary) LD $(notdir $@)
|
$(summary) LD $(notdir $@)
|
||||||
$(CC) $(LDFLAGS) -o $@ -Wl,-Map=$(APP_MAP)
|
$(CC) $(LDFLAGS) -o $@ -Wl,-Map=$(APP_MAP)
|
||||||
|
|
||||||
|
@ -141,6 +141,19 @@ function run_tests()
|
|||||||
assert_built ${APP_BINS} ${BOOTLOADER_BINS} partitions_singleapp.bin
|
assert_built ${APP_BINS} ${BOOTLOADER_BINS} partitions_singleapp.bin
|
||||||
[ -f ${BUILD}/partition*.bin ] || failure "A partition table should have been built in CRLF mode"
|
[ -f ${BUILD}/partition*.bin ] || failure "A partition table should have been built in CRLF mode"
|
||||||
|
|
||||||
|
print_status "Touching rom ld file should re-link app and bootloader"
|
||||||
|
make
|
||||||
|
take_build_snapshot
|
||||||
|
touch ${IDF_PATH}/components/esp32/ld/esp32.rom.ld
|
||||||
|
make
|
||||||
|
assert_rebuilt ${APP_BINS} ${BOOTLOADER_BINS}
|
||||||
|
|
||||||
|
print_status "Touching peripherals ld file should only re-link app"
|
||||||
|
take_build_snapshot
|
||||||
|
touch ${IDF_PATH}/components/esp32/ld/esp32.peripherals.ld
|
||||||
|
make
|
||||||
|
assert_rebuilt ${APP_BINS}
|
||||||
|
assert_not_rebuilt ${BOOTLOADER_BINS}
|
||||||
|
|
||||||
print_status "All tests completed"
|
print_status "All tests completed"
|
||||||
if [ -n "${FAILURES}" ]; then
|
if [ -n "${FAILURES}" ]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user