Makefile 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. EXTRA_COMPONENT_DIRS += ${IDF_PATH}/examples/peripherals/rmt/ir_protocols/components
  7. ifeq ($(MAKELEVEL),0)
  8. # Set default target
  9. all:
  10. # Define helper targets only when not recursing
  11. # List of unit-test-app configurations.
  12. # Each file in configs/ directory defines a configuration. The format is the
  13. # same as sdkconfig file. Configuration is applied on top of sdkconfig.defaults
  14. # file from the project directory
  15. CONFIG_NAMES := $(shell ${IDF_PATH}/tools/unit-test-app/tools/get_available_configs.sh esp32)
  16. # Per-config targets
  17. CONFIG_BUILD_TARGETS := $(addprefix ut-build-,$(CONFIG_NAMES))
  18. CONFIG_CLEAN_TARGETS := $(addprefix ut-clean-,$(CONFIG_NAMES))
  19. CONFIG_APPLY_TARGETS := $(addprefix ut-apply-config-,$(CONFIG_NAMES))
  20. # Build (intermediate) and output (artifact) directories
  21. PROJECT_DIR := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
  22. BUILDS_DIR := $(PROJECT_DIR)/builds
  23. BINARIES_DIR := $(PROJECT_DIR)/output
  24. # This generates per-config targets (clean, build, apply-config).
  25. define GenerateConfigTargets
  26. # $(1) - configuration name
  27. ut-clean-$(1):
  28. rm -rf $$(BUILDS_DIR)/$(1) $$(BINARIES_DIR)/$(1)
  29. ut-build-$(1): $$(BINARIES_DIR)/$(1)/$$(PROJECT_NAME).bin
  30. ut-apply-config-$(1):
  31. cat sdkconfig.defaults > sdkconfig
  32. echo "" >> sdkconfig
  33. cat configs/$(1) >> sdkconfig
  34. $(call RunConf,conf --olddefconfig)
  35. endef
  36. $(foreach config_name,$(CONFIG_NAMES), $(eval $(call GenerateConfigTargets,$(config_name))))
  37. ut-build-all-configs: $(CONFIG_BUILD_TARGETS)
  38. ut-clean-all-configs: $(CONFIG_CLEAN_TARGETS)
  39. # This target builds the configuration. It does not currently track dependencies,
  40. # but is good enough for CI builds if used together with clean-all-configs.
  41. # For local builds, use 'apply-config-NAME' target and then use normal 'all'
  42. # and 'flash' targets.
  43. $(BINARIES_DIR)/%/bootloader.bin \
  44. $(BINARIES_DIR)/%/$(PROJECT_NAME).elf \
  45. $(BINARIES_DIR)/%/$(PROJECT_NAME).map \
  46. $(BINARIES_DIR)/%/$(PROJECT_NAME).bin: configs/%
  47. # Create build and output directories
  48. mkdir -p $(BINARIES_DIR)/$*/bootloader
  49. mkdir -p $(BUILDS_DIR)/$*
  50. # Prepare configuration: top-level sdkconfig.defaults file plus the current configuration (configs/$*)
  51. echo CONFIG $(BUILDS_DIR)/$*/sdkconfig
  52. rm -f $(BUILDS_DIR)/$*/sdkconfig
  53. cat sdkconfig.defaults > $(BUILDS_DIR)/$*/sdkconfig.defaults
  54. echo "" >> $(BUILDS_DIR)/$*/sdkconfig.defaults # in case there is no trailing newline in sdkconfig.defaults
  55. cat sdkconfig.defaults.esp32 >> $(BUILDS_DIR)/$*/sdkconfig.defaults
  56. echo "" >> $(BUILDS_DIR)/$*/sdkconfig.defaults
  57. cat configs/$* >> $(BUILDS_DIR)/$*/sdkconfig.defaults
  58. # Build, tweaking paths to sdkconfig and sdkconfig.defaults
  59. echo BUILD_CONFIG $(BUILDS_DIR)/$*
  60. # 'TEST_COMPONENTS=names' option can be added to configs/$* to limit the set
  61. # of tests to build for given configuration.
  62. # Build all tests if this option is not present.
  63. test_components=`sed -n 's/^TEST_COMPONENTS=\(.*\)/\1/p' configs/$*`; \
  64. test_exclude_components=`sed -n 's/^TEST_EXCLUDE_COMPONENTS=\(.*\)/\1/p' configs/$*`; \
  65. tests_all=`test -n "$${test_components}"; echo $${?}`; \
  66. exclude_components=`sed -n 's/^EXCLUDE_COMPONENTS=\(.*\)/\1/p' configs/$*`; \
  67. $(MAKE) defconfig list-components all \
  68. BUILD_DIR_BASE=$(BUILDS_DIR)/$* \
  69. SDKCONFIG=$(BUILDS_DIR)/$*/sdkconfig \
  70. SDKCONFIG_DEFAULTS=$(BUILDS_DIR)/$*/sdkconfig.defaults \
  71. TEST_COMPONENTS="$${test_components}" \
  72. TEST_EXCLUDE_COMPONENTS="$${test_exclude_components}" \
  73. TESTS_ALL=$${tests_all} \
  74. EXCLUDE_COMPONENTS="$${exclude_components}"
  75. $(MAKE) --silent print_flash_cmd \
  76. BUILD_DIR_BASE=$(BUILDS_DIR)/$* \
  77. SDKCONFIG=$(BUILDS_DIR)/$*/sdkconfig \
  78. | sed -e 's:'$(BUILDS_DIR)/$*/'::g' \
  79. | tail -n 1 > $(BINARIES_DIR)/$*/download.config
  80. # Copy files of interest to the output directory
  81. cp $(BUILDS_DIR)/$*/bootloader/bootloader.bin $(BINARIES_DIR)/$*/bootloader/
  82. cp $(BUILDS_DIR)/$*/$(PROJECT_NAME).elf $(BINARIES_DIR)/$*/
  83. cp $(BUILDS_DIR)/$*/$(PROJECT_NAME).bin $(BINARIES_DIR)/$*/
  84. cp $(BUILDS_DIR)/$*/$(PROJECT_NAME).map $(BINARIES_DIR)/$*/
  85. cp $(BUILDS_DIR)/$*/*.bin $(BINARIES_DIR)/$*/
  86. cp $(BUILDS_DIR)/$*/sdkconfig $(BINARIES_DIR)/$*/
  87. ut-help:
  88. @echo "Additional unit-test-app specific targets:"
  89. @echo ""
  90. @echo "make ut-build-NAME - Build unit-test-app with configuration provided in configs/NAME."
  91. @echo " Build directory will be builds/NAME/, output binaries will be"
  92. @echo " under output/NAME/"
  93. @echo ""
  94. @echo "make ut-build-all-configs - Build all configurations defined in configs/ directory."
  95. @echo ""
  96. @echo "Above targets determine list of components to be built from configs/NAME files."
  97. @echo "To build custom subset of components use 'make ut-apply-config-NAME' and then 'make all'."
  98. @echo ""
  99. @echo "make ut-apply-config-NAME - Generates configuration based on configs/NAME in sdkconfig"
  100. @echo " file. After this, normal all/flash targets can be used."
  101. @echo " Useful for development/debugging."
  102. @echo ""
  103. @echo "make ut-clean-NAME - Remove build and output directories for configuration NAME."
  104. @echo ""
  105. help: ut-help
  106. LOCAL_TARGETS := ut-build-all-configs ut-clean-all-configs \
  107. $(CONFIG_BUILD_TARGETS) $(CONFIG_CLEAN_TARGETS) \
  108. ut-help
  109. .PHONY: $(LOCAL_TARGETS)
  110. NON_INTERACTIVE_TARGET += ut-apply-config-% ut-clean-% ut-build-% \
  111. ut-build-all-configs ut-clean-all-configs
  112. endif # MAKELEVEL == 0
  113. # When targets defined in this makefile are built, don't need to include the main project makefile.
  114. # This prevents some variables which depend on build directory from being set erroneously.
  115. ifeq ($(filter $(LOCAL_TARGETS),$(MAKECMDGOALS)),)
  116. include $(IDF_PATH)/make/project.mk
  117. endif
  118. # If recursing, print the actual list of tests being built
  119. ifneq ($(MAKELEVEL),0)
  120. $(info TESTS $(foreach comp,$(TEST_COMPONENT_NAMES),$(patsubst %_test,%,$(comp))))
  121. endif # MAKELEVEL != 0