mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
110 lines
4.3 KiB
Makefile
110 lines
4.3 KiB
Makefile
# Extra make rules for components containing ULP coprocessor code.
|
|
#
|
|
# ULP program(s) gets built and linked into the application.
|
|
# Steps taken here are explained in docs/ulp.rst
|
|
|
|
# Define names for files generated at different stages
|
|
ULP_ELF := $(ULP_APP_NAME).elf
|
|
ULP_MAP := $(ULP_ELF:.elf=.map)
|
|
ULP_SYM := $(ULP_ELF:.elf=.sym)
|
|
ULP_BIN := $(ULP_ELF:.elf=.bin)
|
|
ULP_EXPORTS_LD := $(ULP_ELF:.elf=.ld)
|
|
ULP_EXPORTS_HEADER := $(ULP_ELF:.elf=.h)
|
|
ULP_LD_SCRIPT := $(ULP_ELF:.elf=.common.ld)
|
|
|
|
ULP_OBJECTS := $(notdir $(ULP_S_SOURCES:.S=.ulp.o))
|
|
ULP_DEP := $(notdir $(ULP_S_SOURCES:.S=.ulp.d)) $(ULP_LD_SCRIPT:.ld=.d)
|
|
ULP_PREPROCESSED := $(notdir $(ULP_S_SOURCES:.S=.ulp.pS))
|
|
ULP_LISTINGS := $(notdir $(ULP_S_SOURCES:.S=.ulp.lst))
|
|
|
|
ULP_PREPROCESSOR_ARGS := \
|
|
$(addprefix -I ,$(COMPONENT_INCLUDES)) \
|
|
$(addprefix -I ,$(COMPONENT_EXTRA_INCLUDES)) \
|
|
-I$(COMPONENT_PATH) -D__ASSEMBLER__
|
|
|
|
-include $(ULP_DEP)
|
|
|
|
# Check the assembler version
|
|
include $(IDF_PATH)/components/ulp/toolchain_ulp_version.mk
|
|
ULP_AS_VER := $(shell $(ULP_AS) --version | sed -E -n 's|GNU assembler \(GNU Binutils\) ([a-z0-9\.-]+)|\1|gp')
|
|
|
|
$(info Building ULP app $(ULP_APP_NAME))
|
|
$(info ULP assembler version: $(ULP_AS_VER))
|
|
|
|
ifeq (,$(findstring $(ULP_AS_VER), $(SUPPORTED_ULP_ASSEMBLER_VERSION)))
|
|
$(info WARNING: ULP assembler version $(ULP_AS_VER) is not supported.)
|
|
$(info Expected to see version: $(SUPPORTED_ULP_ASSEMBLER_VERSION))
|
|
$(info Please check ESP-IDF ULP setup instructions and update the toolchain, or proceed at your own risk.)
|
|
endif
|
|
|
|
# Preprocess LD script used to link ULP program
|
|
$(ULP_LD_SCRIPT): $(ULP_LD_TEMPLATE)
|
|
$(summary) CPP $(patsubst $(PWD)/%,%,$(CURDIR))/$@
|
|
$(CC) $(CPPFLAGS) -MT $(ULP_LD_SCRIPT) -E -P -xc -o $@ $(ULP_PREPROCESSOR_ARGS) $<
|
|
|
|
# Generate preprocessed assembly files.
|
|
# To inspect these preprocessed files, add a ".PRECIOUS: %.ulp.pS" rule.
|
|
%.ulp.pS: $(COMPONENT_PATH)/ulp/%.S
|
|
$(summary) CPP $(patsubst $(PWD)/%,%,$<)
|
|
$(CC) $(CPPFLAGS) -MT $(patsubst %.ulp.pS,%.ulp.o,$@) -E -P -xc -o $@ $(ULP_PREPROCESSOR_ARGS) $<
|
|
|
|
# Compiled preprocessed files into object files.
|
|
%.ulp.o: %.ulp.pS
|
|
$(summary) ULP_AS $(patsubst $(PWD)/%,%,$(CURDIR))/$@
|
|
$(ULP_AS) -al=$(patsubst %.ulp.o,%.ulp.lst,$@) -o $@ $<
|
|
|
|
# Link object files and generate map file
|
|
$(ULP_ELF): $(ULP_OBJECTS) $(ULP_LD_SCRIPT)
|
|
$(summary) ULP_LD $(patsubst $(PWD)/%,%,$(CURDIR))/$@
|
|
$(ULP_LD) -o $@ -A elf32-esp32ulp -Map=$(ULP_MAP) -T $(ULP_LD_SCRIPT) $(ULP_OBJECTS)
|
|
|
|
# Dump the list of global symbols in a convenient format.
|
|
$(ULP_SYM): $(ULP_ELF)
|
|
$(ULP_NM) -g -f posix $< > $@
|
|
|
|
# Dump the binary for inclusion into the project
|
|
$(COMPONENT_BUILD_DIR)/$(ULP_BIN): $(ULP_ELF)
|
|
$(summary) ULP_BIN $(patsubst $(PWD)/%,%,$@)
|
|
$(ULP_OBJCOPY) -O binary $< $@
|
|
|
|
# Left and right side of the rule are the same, but the right side
|
|
# is given as an absolute path.
|
|
# (Make can not resolve such things automatically)
|
|
$(ULP_EXPORTS_HEADER): $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER)
|
|
|
|
# Artificial intermediate target to trigger generation of .h and .ld files.
|
|
.INTERMEDIATE: $(COMPONENT_NAME)_ulp_mapgen_intermediate
|
|
|
|
$(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER)\
|
|
$(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD): $(COMPONENT_NAME)_ulp_mapgen_intermediate
|
|
|
|
# Convert the symbols list into a header file and linker export script.
|
|
$(COMPONENT_NAME)_ulp_mapgen_intermediate: $(ULP_SYM)
|
|
$(summary) ULP_MAPGEN $(patsubst $(PWD)/%,%,$(CURDIR))/$<
|
|
$(ULP_MAP_GEN) -s $(ULP_SYM) -o $(ULP_EXPORTS_LD:.ld=)
|
|
|
|
# Building the component separately from the project should result in
|
|
# ULP files being built.
|
|
build: $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER) \
|
|
$(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD) \
|
|
$(COMPONENT_BUILD_DIR)/$(ULP_BIN)
|
|
|
|
# Objects listed as being dependent on $(ULP_EXPORTS_HEADER) must also
|
|
# depend on $(ULP_SYM), to order build steps correctly.
|
|
$(ULP_EXP_DEP_OBJECTS) : $(ULP_EXPORTS_HEADER) $(ULP_SYM)
|
|
|
|
# Finally, set all the variables processed by the build system.
|
|
COMPONENT_EXTRA_CLEAN += $(ULP_OBJECTS) \
|
|
$(ULP_LD_SCRIPT) \
|
|
$(ULP_PREPROCESSED) \
|
|
$(ULP_ELF) $(ULP_BIN) \
|
|
$(ULP_MAP) $(ULP_SYM) \
|
|
$(ULP_EXPORTS_LD) \
|
|
$(ULP_EXPORTS_HEADER) \
|
|
$(ULP_DEP) \
|
|
$(ULP_LISTINGS)
|
|
|
|
COMPONENT_EMBED_FILES += $(COMPONENT_BUILD_DIR)/$(ULP_BIN)
|
|
COMPONENT_ADD_LDFLAGS += -l$(COMPONENT_NAME) -T $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD)
|
|
COMPONENT_EXTRA_INCLUDES += $(COMPONENT_BUILD_DIR)
|