Makefile 4.1 KB

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