component_ulp_common.mk 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Extra make rules for components containing ULP coprocessor code.
  2. #
  3. # ULP program(s) gets built and linked into the application.
  4. # Steps taken here are explained in docs/ulp.rst
  5. # Define names for files generated at different stages
  6. ULP_ELF := $(ULP_APP_NAME).elf
  7. ULP_MAP := $(ULP_ELF:.elf=.map)
  8. ULP_SYM := $(ULP_ELF:.elf=.sym)
  9. ULP_BIN := $(ULP_ELF:.elf=.bin)
  10. ULP_EXPORTS_LD := $(ULP_ELF:.elf=.ld)
  11. ULP_EXPORTS_HEADER := $(ULP_ELF:.elf=.h)
  12. ULP_LD_SCRIPT := $(ULP_ELF:.elf=.common.ld)
  13. ULP_OBJECTS := $(notdir $(ULP_S_SOURCES:.S=.ulp.o))
  14. ULP_DEP := $(notdir $(ULP_S_SOURCES:.S=.ulp.d)) $(ULP_LD_SCRIPT:.ld=.d)
  15. ULP_PREPROCESSED := $(notdir $(ULP_S_SOURCES:.S=.ulp.pS))
  16. ULP_LISTINGS := $(notdir $(ULP_S_SOURCES:.S=.ulp.lst))
  17. ULP_PREPROCESSOR_ARGS := \
  18. $(addprefix -I ,$(COMPONENT_INCLUDES)) \
  19. $(addprefix -I ,$(COMPONENT_EXTRA_INCLUDES)) \
  20. -I$(COMPONENT_PATH) -D__ASSEMBLER__
  21. -include $(ULP_DEP)
  22. # Preprocess LD script used to link ULP program
  23. $(ULP_LD_SCRIPT): $(ULP_LD_TEMPLATE)
  24. $(summary) CPP $(patsubst $(PWD)/%,%,$(CURDIR))/$@
  25. $(CC) $(CPPFLAGS) -MT $(ULP_LD_SCRIPT) -E -P -xc -o $@ $(ULP_PREPROCESSOR_ARGS) $<
  26. # Generate preprocessed assembly files.
  27. # To inspect these preprocessed files, add a ".PRECIOUS: %.ulp.pS" rule.
  28. %.ulp.pS: $(COMPONENT_PATH)/ulp/%.S
  29. $(summary) CPP $(patsubst $(PWD)/%,%,$<)
  30. $(CC) $(CPPFLAGS) -MT $(patsubst %.ulp.pS,%.ulp.o,$@) -E -P -xc -o $@ $(ULP_PREPROCESSOR_ARGS) $<
  31. # Compiled preprocessed files into object files.
  32. %.ulp.o: %.ulp.pS
  33. $(summary) ULP_AS $(patsubst $(PWD)/%,%,$(CURDIR))/$@
  34. $(ULP_AS) -al=$(patsubst %.ulp.o,%.ulp.lst,$@) -o $@ $<
  35. # Link object files and generate map file
  36. $(ULP_ELF): $(ULP_OBJECTS) $(ULP_LD_SCRIPT)
  37. $(summary) ULP_LD $(patsubst $(PWD)/%,%,$(CURDIR))/$@
  38. $(ULP_LD) -o $@ -A elf32-esp32ulp -Map=$(ULP_MAP) -T $(ULP_LD_SCRIPT) $(ULP_OBJECTS)
  39. # Dump the list of global symbols in a convenient format.
  40. $(ULP_SYM): $(ULP_ELF)
  41. $(ULP_NM) -g -f posix $< > $@
  42. # Dump the binary for inclusion into the project
  43. $(COMPONENT_BUILD_DIR)/$(ULP_BIN): $(ULP_ELF)
  44. $(summary) ULP_BIN $(patsubst $(PWD)/%,%,$@)
  45. $(ULP_OBJCOPY) -O binary $< $@
  46. # Left and right side of the rule are the same, but the right side
  47. # is given as an absolute path.
  48. # (Make can not resolve such things automatically)
  49. $(ULP_EXPORTS_HEADER): $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER)
  50. # Artificial intermediate target to trigger generation of .h and .ld files.
  51. .INTERMEDIATE: $(COMPONENT_NAME)_ulp_mapgen_intermediate
  52. $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER)\
  53. $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD): $(COMPONENT_NAME)_ulp_mapgen_intermediate
  54. # Convert the symbols list into a header file and linker export script.
  55. $(COMPONENT_NAME)_ulp_mapgen_intermediate: $(ULP_SYM)
  56. $(summary) ULP_MAPGEN $(patsubst $(PWD)/%,%,$(CURDIR))/$<
  57. $(ULP_MAP_GEN) -s $(ULP_SYM) -o $(ULP_EXPORTS_LD:.ld=)
  58. # Building the component separately from the project should result in
  59. # ULP files being built.
  60. build: $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_HEADER) \
  61. $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD) \
  62. $(COMPONENT_BUILD_DIR)/$(ULP_BIN)
  63. # Objects listed as being dependent on $(ULP_EXPORTS_HEADER) must also
  64. # depend on $(ULP_SYM), to order build steps correctly.
  65. $(ULP_EXP_DEP_OBJECTS) : $(ULP_EXPORTS_HEADER) $(ULP_SYM)
  66. # Finally, set all the variables processed by the build system.
  67. COMPONENT_EXTRA_CLEAN := $(ULP_OBJECTS) \
  68. $(ULP_LD_SCRIPT) \
  69. $(ULP_PREPROCESSED) \
  70. $(ULP_ELF) $(ULP_BIN) \
  71. $(ULP_MAP) $(ULP_SYM) \
  72. $(ULP_EXPORTS_LD) \
  73. $(ULP_EXPORTS_HEADER) \
  74. $(ULP_DEP) \
  75. $(ULP_LISTINGS)
  76. COMPONENT_EMBED_FILES := $(COMPONENT_BUILD_DIR)/$(ULP_BIN)
  77. COMPONENT_ADD_LDFLAGS := -l$(COMPONENT_NAME) -T $(COMPONENT_BUILD_DIR)/$(ULP_EXPORTS_LD)
  78. COMPONENT_EXTRA_INCLUDES := $(COMPONENT_BUILD_DIR)