Makefile 5.6 KB

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