Makefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #
  2. # This is a project Makefile. It is assumed the directory this Makefile resides in is a
  3. # project subdirectory.
  4. #
  5. PROJECT_NAME := unit-test-app
  6. include $(IDF_PATH)/make/project.mk
  7. print_flash_cmd:
  8. echo $(ESPTOOL_WRITE_FLASH_OPTIONS) $(ESPTOOL_ALL_FLASH_ARGS) | sed -e 's:'$(PWD)/build/'::g'
  9. # List of unit-test-app configurations.
  10. # Each file in configs/ directory defines a configuration. The format is the
  11. # same as sdkconfig file. Configuration is applied on top of sdkconfig.defaults
  12. # file from the project directory
  13. CONFIG_NAMES := $(notdir $(wildcard configs/*))
  14. # Per-config targets
  15. CONFIG_BUILD_TARGETS := $(addprefix ut-build-,$(CONFIG_NAMES))
  16. CONFIG_CLEAN_TARGETS := $(addprefix ut-clean-,$(CONFIG_NAMES))
  17. CONFIG_APPLY_TARGETS := $(addprefix ut-apply-config-,$(CONFIG_NAMES))
  18. # Build (intermediate) and output (artifact) directories
  19. BUILDS_DIR := $(PROJECT_PATH)/builds
  20. BINARIES_DIR := $(PROJECT_PATH)/output
  21. # This generates per-config targets (clean, build, apply-config).
  22. define GenerateConfigTargets
  23. # $(1) - configuration name
  24. ut-clean-$(1):
  25. rm -rf $$(BUILDS_DIR)/$(1) $$(BINARIES_DIR)/$(1)
  26. ut-build-$(1): $$(BINARIES_DIR)/$(1)/$$(PROJECT_NAME).bin
  27. ut-apply-config-$(1):
  28. cat sdkconfig.defaults > sdkconfig
  29. echo "" >> sdkconfig
  30. cat configs/$(1) >> sdkconfig
  31. $(call RunConf,conf --olddefconfig)
  32. endef
  33. $(foreach config_name,$(CONFIG_NAMES), $(eval $(call GenerateConfigTargets,$(config_name))))
  34. ut-build-all-configs: $(CONFIG_BUILD_TARGETS)
  35. ut-clean-all-configs: $(CONFIG_CLEAN_TARGETS)
  36. # This target builds the configuration. It does not currently track dependencies,
  37. # but is good enough for CI builds if used together with clean-all-configs.
  38. # For local builds, use 'apply-config-NAME' target and then use normal 'all'
  39. # and 'flash' targets.
  40. $(BINARIES_DIR)/%/bootloader.bin \
  41. $(BINARIES_DIR)/%/$(PROJECT_NAME).elf \
  42. $(BINARIES_DIR)/%/$(PROJECT_NAME).map \
  43. $(BINARIES_DIR)/%/$(PROJECT_NAME).bin: configs/%
  44. # Create build and output directories
  45. mkdir -p $(BINARIES_DIR)/$*/bootloader
  46. mkdir -p $(BUILDS_DIR)/$*
  47. # Prepare configuration: top-level sdkconfig.defaults file plus the current configuration (configs/$*)
  48. $(summary) CONFIG $(BUILDS_DIR)/$*/sdkconfig
  49. rm -f $(BUILDS_DIR)/$*/sdkconfig
  50. cat sdkconfig.defaults > $(BUILDS_DIR)/$*/sdkconfig.defaults
  51. echo "" >> $(BUILDS_DIR)/$*/sdkconfig.defaults # in case there is no trailing newline in sdkconfig.defaults
  52. cat configs/$* >> $(BUILDS_DIR)/$*/sdkconfig.defaults
  53. # Build, tweaking paths to sdkconfig and sdkconfig.defaults
  54. $(summary) BUILD_CONFIG $(BUILDS_DIR)/$*
  55. $(MAKE) defconfig all \
  56. BUILD_DIR_BASE=$(BUILDS_DIR)/$* \
  57. SDKCONFIG=$(BUILDS_DIR)/$*/sdkconfig \
  58. SDKCONFIG_DEFAULTS=$(BUILDS_DIR)/$*/sdkconfig.defaults
  59. $(MAKE) print_flash_cmd \
  60. BUILD_DIR_BASE=$(BUILDS_DIR)/$* \
  61. SDKCONFIG=$(BUILDS_DIR)/$*/sdkconfig \
  62. | sed -e 's:'$(BUILDS_DIR)/$*/'::g' \
  63. | tail -n 1 > $(BINARIES_DIR)/$*/download.config
  64. # Copy files of interest to the output directory
  65. cp $(BUILDS_DIR)/$*/bootloader/bootloader.bin $(BINARIES_DIR)/$*/bootloader/
  66. cp $(BUILDS_DIR)/$*/$(PROJECT_NAME).elf $(BINARIES_DIR)/$*/
  67. cp $(BUILDS_DIR)/$*/$(PROJECT_NAME).bin $(BINARIES_DIR)/$*/
  68. cp $(BUILDS_DIR)/$*/$(PROJECT_NAME).map $(BINARIES_DIR)/$*/
  69. cp $(BUILDS_DIR)/$*/partition_table*.bin $(BINARIES_DIR)/$*/
  70. cp $(BUILDS_DIR)/$*/sdkconfig $(BINARIES_DIR)/$*/
  71. ut-help:
  72. @echo "Additional unit-test-app specific targets:"
  73. @echo ""
  74. @echo "make ut-build-NAME - Build unit-test-app with configuration provided in configs/NAME."
  75. @echo " Build directory will be builds/NAME/, output binaries will be"
  76. @echo " under output/NAME/"
  77. @echo "make ut-clean-NAME - Remove build and output directories for configuration NAME."
  78. @echo ""
  79. @echo "make ut-build-all-configs - Build all configurations defined in configs/ directory."
  80. @echo ""
  81. @echo "make ut-apply-config-NAME - Generates configuration based on configs/NAME in sdkconfig"
  82. @echo " file. After this, normal all/flash targets can be used."
  83. @echo " Useful for development/debugging."
  84. @echo ""
  85. help: ut-help
  86. .PHONY: ut-build-all-configs ut-clean-all-configs \
  87. $(CONFIG_BUILD_TARGETS) $(CONFIG_CLEAN_TARGETS) $(CONFIG_APPLY_TARGETS) \
  88. ut-help