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