Makefile 4.1 KB

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