]> granicus.if.org Git - esp-idf/blob - make/project.mk
build: Add TEST_EXCLUDE_COMPONENTS
[esp-idf] / make / project.mk
1 #
2 # Main Project Makefile
3 # This Makefile is included directly from the user project Makefile in order to call the component.mk
4 # makefiles of all components (in a separate make process) to build all the libraries, then links them
5 # together into the final file. If so, PWD is the project dir (we assume).
6 #
7
8 #
9 # This makefile requires the environment variable IDF_PATH to be set to the top-level esp-idf directory
10 # where this file is located.
11 #
12
13 .PHONY: build-components menuconfig defconfig all build clean all_binaries check-submodules size size-components size-files size-symbols list-components
14
15 MAKECMDGOALS ?= all
16 all: all_binaries
17 # see below for recipe of 'all' target
18 #
19 # # other components will add dependencies to 'all_binaries'. The
20 # reason all_binaries is used instead of 'all' is so that the flash
21 # target can build everything without triggering the per-component "to
22 # flash..." output targets.)
23
24 help:
25         @echo "Welcome to Espressif IDF build system. Some useful make targets:"
26         @echo ""
27         @echo "make menuconfig - Configure IDF project"
28         @echo "make defconfig - Set defaults for all new configuration options"
29         @echo ""
30         @echo "make all - Build app, bootloader, partition table"
31         @echo "make flash - Flash app, bootloader, partition table to a chip"
32         @echo "make clean - Remove all build output"
33         @echo "make size - Display the static memory footprint of the app"
34         @echo "make size-components, size-files - Finer-grained memory footprints"
35         @echo "make size-symbols - Per symbol memory footprint. Requires COMPONENT=<component>"
36         @echo "make erase_flash - Erase entire flash contents"
37         @echo "make monitor - Run idf_monitor tool to monitor serial output from app"
38         @echo "make simple_monitor - Monitor serial output on terminal console"
39         @echo "make list-components - List all components in the project"
40         @echo ""
41         @echo "make app - Build just the app"
42         @echo "make app-flash - Flash just the app"
43         @echo "make app-clean - Clean just the app"
44         @echo "make print_flash_cmd - Print the arguments for esptool when flash"
45         @echo ""
46         @echo "See also 'make bootloader', 'make bootloader-flash', 'make bootloader-clean', "
47         @echo "'make partition_table', etc, etc."
48
49 # Non-interactive targets. Mostly, those for which you do not need to build a binary
50 NON_INTERACTIVE_TARGET += defconfig clean% %clean help list-components print_flash_cmd
51
52 # dependency checks
53 ifndef MAKE_RESTARTS
54 ifeq ("$(filter 4.% 3.81 3.82,$(MAKE_VERSION))","")
55 $(warning esp-idf build system only supports GNU Make versions 3.81 or newer. You may see unexpected results with other Makes.)
56 endif
57
58 ifdef MSYSTEM
59 ifneq ("$(MSYSTEM)","MINGW32")
60 $(warning esp-idf build system only supports MSYS2 in "MINGW32" mode. Consult the ESP-IDF documentation for details.)
61 endif
62 endif  # MSYSTEM
63
64 endif  # MAKE_RESTARTS
65
66 # can't run 'clean' along with any non-clean targets
67 ifneq ("$(filter clean% %clean,$(MAKECMDGOALS))" ,"")
68 ifneq ("$(filter-out clean% %clean,$(MAKECMDGOALS))", "")
69 $(error esp-idf build system doesn't support running 'clean' targets along with any others. Run 'make clean' and then run other targets separately.)
70 endif
71 endif
72
73 OS ?=
74
75 # make IDF_PATH a "real" absolute path
76 # * works around the case where a shell character is embedded in the environment variable value.
77 # * changes Windows-style C:/blah/ paths to MSYS style /c/blah
78 ifeq ("$(OS)","Windows_NT")
79 # On Windows MSYS2, make wildcard function returns empty string for paths of form /xyz
80 # where /xyz is a directory inside the MSYS root - so we don't use it.
81 SANITISED_IDF_PATH:=$(realpath $(IDF_PATH))
82 else
83 SANITISED_IDF_PATH:=$(realpath $(wildcard $(IDF_PATH)))
84 endif
85
86 export IDF_PATH := $(SANITISED_IDF_PATH)
87
88 ifndef IDF_PATH
89 $(error IDF_PATH variable is not set to a valid directory.)
90 endif
91
92 ifneq ("$(IDF_PATH)","$(SANITISED_IDF_PATH)")
93 # implies IDF_PATH was overriden on make command line.
94 # Due to the way make manages variables, this is hard to account for
95 #
96 # if you see this error, do the shell expansion in the shell ie
97 # make IDF_PATH=~/blah not make IDF_PATH="~/blah"
98 $(error If IDF_PATH is overriden on command line, it must be an absolute path with no embedded shell special characters)
99 endif
100
101 ifneq ("$(IDF_PATH)","$(subst :,,$(IDF_PATH))")
102 $(error IDF_PATH cannot contain colons. If overriding IDF_PATH on Windows, use MSYS Unix-style /c/dir instead of C:/dir)
103 endif
104
105 # disable built-in make rules, makes debugging saner
106 MAKEFLAGS_OLD := $(MAKEFLAGS)
107 MAKEFLAGS +=-rR
108
109 # Default path to the project: we assume the Makefile including this file
110 # is in the project directory
111 ifndef PROJECT_PATH
112 PROJECT_PATH := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
113 export PROJECT_PATH
114 endif
115
116 # A list of the "common" makefiles, to use as a target dependency
117 COMMON_MAKEFILES := $(abspath $(IDF_PATH)/make/project.mk $(IDF_PATH)/make/common.mk $(IDF_PATH)/make/component_wrapper.mk $(firstword $(MAKEFILE_LIST)))
118 export COMMON_MAKEFILES
119
120 # The directory where we put all objects/libraries/binaries. The project Makefile can
121 # configure this if needed.
122 ifndef BUILD_DIR_BASE
123 BUILD_DIR_BASE := $(PROJECT_PATH)/build
124 endif
125 export BUILD_DIR_BASE
126
127 # Component directories. These directories are searched for components (either the directory is a component,
128 # or the directory contains subdirectories which are components.)
129 # The project Makefile can override these component dirs, or add extras via EXTRA_COMPONENT_DIRS
130 ifndef COMPONENT_DIRS
131 EXTRA_COMPONENT_DIRS ?=
132 COMPONENT_DIRS := $(PROJECT_PATH)/components $(EXTRA_COMPONENT_DIRS) $(IDF_PATH)/components $(PROJECT_PATH)/main
133 endif
134 export COMPONENT_DIRS
135
136 ifdef SRCDIRS
137 $(warning SRCDIRS variable is deprecated. These paths can be added to EXTRA_COMPONENT_DIRS or COMPONENT_DIRS instead.)
138 COMPONENT_DIRS += $(abspath $(SRCDIRS))
139 endif
140
141 # The project Makefile can define a list of components, but if it does not do this we just take all available components
142 # in the component dirs. A component is COMPONENT_DIRS directory, or immediate subdirectory,
143 # which contains a component.mk file.
144 #
145 # Use the "make list-components" target to debug this step.
146 ifndef COMPONENTS
147 # Find all component names. The component names are the same as the
148 # directories they're in, so /bla/components/mycomponent/component.mk -> mycomponent.
149 COMPONENTS := $(dir $(foreach cd,$(COMPONENT_DIRS),                           \
150                                         $(wildcard $(cd)/*/component.mk) $(wildcard $(cd)/component.mk) \
151                                 ))
152 COMPONENTS := $(sort $(foreach comp,$(COMPONENTS),$(lastword $(subst /, ,$(comp)))))
153 endif
154 # After a full manifest of component names is determined, subtract the ones explicitly omitted by the project Makefile.
155 ifdef EXCLUDE_COMPONENTS
156 COMPONENTS := $(filter-out $(subst ",,$(EXCLUDE_COMPONENTS)), $(COMPONENTS)) 
157 # to keep syntax highlighters happy: "))
158 endif
159 export COMPONENTS
160
161 # Resolve all of COMPONENTS into absolute paths in COMPONENT_PATHS.
162 #
163 # If a component name exists in multiple COMPONENT_DIRS, we take the first match.
164 #
165 # NOTE: These paths must be generated WITHOUT a trailing / so we
166 # can use $(notdir x) to get the component name.
167 COMPONENT_PATHS := $(foreach comp,$(COMPONENTS),$(firstword $(foreach cd,$(COMPONENT_DIRS),$(wildcard $(dir $(cd))$(comp) $(cd)/$(comp)))))
168 export COMPONENT_PATHS
169
170 TEST_COMPONENTS ?=
171 TEST_EXCLUDE_COMPONENTS ?=
172 TESTS_ALL ?=
173
174 # If TESTS_ALL set to 1, set TEST_COMPONENTS_LIST to all components.
175 # Otherwise, use the list supplied in TEST_COMPONENTS.
176 ifeq ($(TESTS_ALL),1)
177 TEST_COMPONENTS_LIST := $(filter-out $(TEST_EXCLUDE_COMPONENTS), $(COMPONENTS))
178 else
179 TEST_COMPONENTS_LIST := $(TEST_COMPONENTS)
180 endif
181
182 TEST_COMPONENT_PATHS := $(foreach comp,$(TEST_COMPONENTS_LIST),$(firstword $(foreach dir,$(COMPONENT_DIRS),$(wildcard $(dir)/$(comp)/test))))
183 TEST_COMPONENT_NAMES := $(foreach comp,$(TEST_COMPONENT_PATHS),$(lastword $(subst /, ,$(dir $(comp))))_test)
184
185 # Initialise project-wide variables which can be added to by
186 # each component.
187 #
188 # These variables are built up via the component_project_vars.mk
189 # generated makefiles (one per component).
190 #
191 # See docs/build-system.rst for more details.
192 COMPONENT_INCLUDES :=
193 COMPONENT_LDFLAGS :=
194 COMPONENT_SUBMODULES :=
195 COMPONENT_LIBRARIES :=
196
197 # COMPONENT_PROJECT_VARS is the list of component_project_vars.mk generated makefiles
198 # for each component.
199 #
200 # Including $(COMPONENT_PROJECT_VARS) builds the COMPONENT_INCLUDES,
201 # COMPONENT_LDFLAGS variables and also targets for any inter-component
202 # dependencies.
203 #
204 # See the component_project_vars.mk target in component_wrapper.mk
205 COMPONENT_PROJECT_VARS := $(addsuffix /component_project_vars.mk,$(notdir $(COMPONENT_PATHS) ) $(TEST_COMPONENT_NAMES))
206 COMPONENT_PROJECT_VARS := $(addprefix $(BUILD_DIR_BASE)/,$(COMPONENT_PROJECT_VARS))
207 # this line is -include instead of include to prevent a spurious error message on make 3.81
208 -include $(COMPONENT_PROJECT_VARS)
209
210 # Also add top-level project include path, for top-level includes
211 COMPONENT_INCLUDES += $(abspath $(BUILD_DIR_BASE)/include/)
212
213 export COMPONENT_INCLUDES
214
215 # Set variables common to both project & component
216 include $(IDF_PATH)/make/common.mk
217
218 all:
219 ifdef CONFIG_SECURE_BOOT_ENABLED
220         @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
221 ifndef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
222         @echo "App built but not signed. Sign app & partition data before flashing, via espsecure.py:"
223         @echo "espsecure.py sign_data --keyfile KEYFILE $(APP_BIN)"
224         @echo "espsecure.py sign_data --keyfile KEYFILE $(PARTITION_TABLE_BIN)"
225 endif
226         @echo "To flash app & partition table, run 'make flash' or:"
227 else
228         @echo "To flash all build output, run 'make flash' or:"
229 endif
230         @echo $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS)
231
232
233 # If we have `version.txt` then prefer that for extracting IDF version
234 ifeq ("$(wildcard ${IDF_PATH}/version.txt)","")
235 IDF_VER := $(shell cd ${IDF_PATH} && git describe --always --tags --dirty)
236 else
237 IDF_VER := `cat ${IDF_PATH}/version.txt`
238 endif
239
240 # Set default LDFLAGS
241 EXTRA_LDFLAGS ?=
242 LDFLAGS ?= -nostdlib \
243         -u call_user_start_cpu0 \
244         $(EXTRA_LDFLAGS) \
245         -Wl,--gc-sections       \
246         -Wl,-static     \
247         -Wl,--start-group       \
248         $(COMPONENT_LDFLAGS) \
249         -lgcc \
250         -lstdc++ \
251         -lgcov \
252         -Wl,--end-group \
253         -Wl,-EL
254
255 # Set default CPPFLAGS, CFLAGS, CXXFLAGS
256 # These are exported so that components can use them when compiling.
257 # If you need your component to add CFLAGS/etc for it's own source compilation only, set CFLAGS += in your component's Makefile.
258 # If you need your component to add CFLAGS/etc globally for all source
259 #  files, set CFLAGS += in your component's Makefile.projbuild
260 # If you need to set CFLAGS/CPPFLAGS/CXXFLAGS at project level, set them in application Makefile
261 #  before including project.mk. Default flags will be added before the ones provided in application Makefile.
262
263 # CPPFLAGS used by C preprocessor
264 # If any flags are defined in application Makefile, add them at the end. 
265 CPPFLAGS ?=
266 EXTRA_CPPFLAGS ?=
267 CPPFLAGS := -DESP_PLATFORM -D IDF_VER=\"$(IDF_VER)\" -MMD -MP $(CPPFLAGS) $(EXTRA_CPPFLAGS)
268
269 # Warnings-related flags relevant both for C and C++
270 COMMON_WARNING_FLAGS = -Wall -Werror=all \
271         -Wno-error=unused-function \
272         -Wno-error=unused-but-set-variable \
273         -Wno-error=unused-variable \
274         -Wno-error=deprecated-declarations \
275         -Wextra \
276         -Wno-unused-parameter -Wno-sign-compare
277
278 ifdef CONFIG_WARN_WRITE_STRINGS
279 COMMON_WARNING_FLAGS += -Wwrite-strings
280 endif #CONFIG_WARN_WRITE_STRINGS
281
282 # Flags which control code generation and dependency generation, both for C and C++
283 COMMON_FLAGS = \
284         -ffunction-sections -fdata-sections \
285         -fstrict-volatile-bitfields \
286         -mlongcalls \
287         -nostdlib
288
289 ifndef IS_BOOTLOADER_BUILD
290 # stack protection (only one option can be selected in menuconfig)
291 ifdef CONFIG_STACK_CHECK_NORM
292 COMMON_FLAGS += -fstack-protector
293 endif
294 ifdef CONFIG_STACK_CHECK_STRONG
295 COMMON_FLAGS += -fstack-protector-strong
296 endif
297 ifdef CONFIG_STACK_CHECK_ALL
298 COMMON_FLAGS += -fstack-protector-all
299 endif
300 endif
301
302 # Optimization flags are set based on menuconfig choice
303 ifdef CONFIG_OPTIMIZATION_LEVEL_RELEASE
304 OPTIMIZATION_FLAGS = -Os
305 else
306 OPTIMIZATION_FLAGS = -Og
307 endif
308
309 ifdef CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED
310 CPPFLAGS += -DNDEBUG
311 endif
312
313 # Enable generation of debugging symbols
314 # (we generate even in Release mode, as this has no impact on final binary size.)
315 DEBUG_FLAGS ?= -ggdb
316
317 # List of flags to pass to C compiler
318 # If any flags are defined in application Makefile, add them at the end.
319 CFLAGS ?=
320 EXTRA_CFLAGS ?=
321 CFLAGS := $(strip \
322         -std=gnu99 \
323         $(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \
324         $(COMMON_FLAGS) \
325         $(COMMON_WARNING_FLAGS) -Wno-old-style-declaration \
326         $(CFLAGS) \
327         $(EXTRA_CFLAGS))
328
329 # List of flags to pass to C++ compiler
330 # If any flags are defined in application Makefile, add them at the end.
331 CXXFLAGS ?=
332 EXTRA_CXXFLAGS ?=
333 CXXFLAGS := $(strip \
334         -std=gnu++11 \
335         -fno-rtti \
336         $(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \
337         $(COMMON_FLAGS) \
338         $(COMMON_WARNING_FLAGS) \
339         $(CXXFLAGS) \
340         $(EXTRA_CXXFLAGS))
341
342 ifdef CONFIG_CXX_EXCEPTIONS
343 CXXFLAGS += -fexceptions
344 else
345 CXXFLAGS += -fno-exceptions
346 endif
347
348 export CFLAGS CPPFLAGS CXXFLAGS
349
350 # Set default values that were not previously defined
351 CC ?= gcc
352 LD ?= ld
353 AR ?= ar
354 OBJCOPY ?= objcopy
355 SIZE ?= size
356
357 # Set host compiler and binutils
358 HOSTCC := $(CC)
359 HOSTLD := $(LD)
360 HOSTAR := $(AR)
361 HOSTOBJCOPY := $(OBJCOPY)
362 HOSTSIZE := $(SIZE)
363 export HOSTCC HOSTLD HOSTAR HOSTOBJCOPY SIZE
364
365 # Set target compiler. Defaults to whatever the user has
366 # configured as prefix + ye olde gcc commands
367 CC := $(call dequote,$(CONFIG_TOOLPREFIX))gcc
368 CXX := $(call dequote,$(CONFIG_TOOLPREFIX))c++
369 LD := $(call dequote,$(CONFIG_TOOLPREFIX))ld
370 AR := $(call dequote,$(CONFIG_TOOLPREFIX))ar
371 OBJCOPY := $(call dequote,$(CONFIG_TOOLPREFIX))objcopy
372 SIZE := $(call dequote,$(CONFIG_TOOLPREFIX))size
373 export CC CXX LD AR OBJCOPY SIZE
374
375 PYTHON=$(call dequote,$(CONFIG_PYTHON))
376
377 # the app is the main executable built by the project
378 APP_ELF:=$(BUILD_DIR_BASE)/$(PROJECT_NAME).elf
379 APP_MAP:=$(APP_ELF:.elf=.map)
380 APP_BIN:=$(APP_ELF:.elf=.bin)
381
382 # Include any Makefile.projbuild file letting components add
383 # configuration at the project level
384 define includeProjBuildMakefile
385 $(if $(V),$$(info including $(1)/Makefile.projbuild...))
386 COMPONENT_PATH := $(1)
387 include $(1)/Makefile.projbuild
388 endef
389 $(foreach componentpath,$(COMPONENT_PATHS), \
390         $(if $(wildcard $(componentpath)/Makefile.projbuild), \
391                 $(eval $(call includeProjBuildMakefile,$(componentpath)))))
392
393 # once we know component paths, we can include the config generation targets
394 #
395 # (bootloader build doesn't need this, config is exported from top-level)
396 ifndef IS_BOOTLOADER_BUILD
397 include $(IDF_PATH)/make/project_config.mk
398 endif
399
400 # ELF depends on the library archive files for COMPONENT_LIBRARIES
401 # the rules to build these are emitted as part of GenerateComponentTarget below
402 #
403 # also depends on additional dependencies (linker scripts & binary libraries)
404 # stored in COMPONENT_LINKER_DEPS, built via component.mk files' COMPONENT_ADD_LINKER_DEPS variable
405 COMPONENT_LINKER_DEPS ?=
406 $(APP_ELF): $(foreach libcomp,$(COMPONENT_LIBRARIES),$(BUILD_DIR_BASE)/$(libcomp)/lib$(libcomp).a) $(COMPONENT_LINKER_DEPS) $(COMPONENT_PROJECT_VARS)
407         $(summary) LD $(patsubst $(PWD)/%,%,$@)
408         $(CC) $(LDFLAGS) -o $@ -Wl,-Map=$(APP_MAP)
409
410 app: $(APP_BIN) partition_table_get_info
411 ifeq ("$(CONFIG_SECURE_BOOT_ENABLED)$(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)","y") # secure boot enabled, but remote sign app image
412         @echo "App built but not signed. Signing step via espsecure.py:"
413         @echo "espsecure.py sign_data --keyfile KEYFILE $(APP_BIN)"
414         @echo "Then flash app command is:"
415         @echo $(ESPTOOLPY_WRITE_FLASH) $(APP_OFFSET) $(APP_BIN)
416 else
417         @echo "App built. Default flash app command is:"
418         @echo $(ESPTOOLPY_WRITE_FLASH) $(APP_OFFSET) $(APP_BIN)
419 endif
420
421 all_binaries: $(APP_BIN)
422
423 $(BUILD_DIR_BASE):
424         mkdir -p $(BUILD_DIR_BASE)
425
426 # Macro for the recursive sub-make for each component
427 # $(1) - component directory
428 # $(2) - component name only
429 #
430 # Is recursively expanded by the GenerateComponentTargets macro
431 define ComponentMake
432 +$(MAKE) -C $(BUILD_DIR_BASE)/$(2) -f $(IDF_PATH)/make/component_wrapper.mk COMPONENT_MAKEFILE=$(1)/component.mk COMPONENT_NAME=$(2)
433 endef
434
435 # Generate top-level component-specific targets for each component
436 # $(1) - path to component dir
437 # $(2) - name of component
438 #
439 define GenerateComponentTargets
440 .PHONY: component-$(2)-build component-$(2)-clean
441
442 component-$(2)-build: check-submodules $(call prereq_if_explicit, component-$(2)-clean) | $(BUILD_DIR_BASE)/$(2)
443         $(call ComponentMake,$(1),$(2)) build
444
445 component-$(2)-clean: | $(BUILD_DIR_BASE)/$(2) $(BUILD_DIR_BASE)/$(2)/component_project_vars.mk
446         $(call ComponentMake,$(1),$(2)) clean
447
448 $(BUILD_DIR_BASE)/$(2):
449         @mkdir -p $(BUILD_DIR_BASE)/$(2)
450
451 # tell make it can build any component's library by invoking the -build target
452 # (this target exists for all components even ones which don't build libraries, but it's
453 # only invoked for the targets whose libraries appear in COMPONENT_LIBRARIES and hence the
454 # APP_ELF dependencies.)
455 $(BUILD_DIR_BASE)/$(2)/lib$(2).a: component-$(2)-build
456         $(details) "Target '$$^' responsible for '$$@'" # echo which build target built this file
457
458 # add a target to generate the component_project_vars.mk files that
459 # are used to inject variables into project make pass (see matching
460 # component_project_vars.mk target in component_wrapper.mk).
461 #
462 # If any component_project_vars.mk file is out of date, the make
463 # process will call this target to rebuild it and then restart.
464 #
465 $(BUILD_DIR_BASE)/$(2)/component_project_vars.mk: $(1)/component.mk $(COMMON_MAKEFILES) $(SDKCONFIG_MAKEFILE) | $(BUILD_DIR_BASE)/$(2)
466         $(call ComponentMake,$(1),$(2)) component_project_vars.mk
467 endef
468
469 $(foreach component,$(COMPONENT_PATHS),$(eval $(call GenerateComponentTargets,$(component),$(notdir $(component)))))
470 $(foreach component,$(TEST_COMPONENT_PATHS),$(eval $(call GenerateComponentTargets,$(component),$(lastword $(subst /, ,$(dir $(component))))_test)))
471
472 app-clean: $(addprefix component-,$(addsuffix -clean,$(notdir $(COMPONENT_PATHS))))
473         $(summary) RM $(APP_ELF)
474         rm -f $(APP_ELF) $(APP_BIN) $(APP_MAP)
475
476 size: $(APP_ELF)
477         $(PYTHON) $(IDF_PATH)/tools/idf_size.py $(APP_MAP)
478
479 size-files: $(APP_ELF)
480         $(PYTHON) $(IDF_PATH)/tools/idf_size.py --files $(APP_MAP)
481
482 size-components: $(APP_ELF)
483         $(PYTHON) $(IDF_PATH)/tools/idf_size.py --archives $(APP_MAP)
484
485 size-symbols: $(APP_ELF)
486 ifndef COMPONENT
487         $(error "ERROR: Please enter the component to look symbols for, e.g. COMPONENT=heap")
488 else
489         $(PYTHON) $(IDF_PATH)/tools/idf_size.py --archive_details lib$(COMPONENT).a $(APP_MAP)
490 endif
491
492 # NB: this ordering is deliberate (app-clean & bootloader-clean before
493 # _config-clean), so config remains valid during all component clean
494 # targets
495 config-clean: app-clean bootloader-clean
496 clean: app-clean bootloader-clean config-clean
497
498 # phony target to check if any git submodule listed in COMPONENT_SUBMODULES are missing
499 # or out of date, and exit if so. Components can add paths to this variable.
500 #
501 # This only works for components inside IDF_PATH
502 check-submodules:
503 # Check if .gitmodules exists, otherwise skip submodule check, assuming flattened structure
504 ifneq ("$(wildcard ${IDF_PATH}/.gitmodules)","")
505
506 # Dump the git status for the whole working copy once, then grep it for each submodule. This saves a lot of time on Windows.
507 GIT_STATUS := $(shell cd ${IDF_PATH} && git status --porcelain --ignore-submodules=dirty)
508
509 # Generate a target to check this submodule
510 # $(1) - submodule directory, relative to IDF_PATH
511 define GenerateSubmoduleCheckTarget
512 check-submodules: $(IDF_PATH)/$(1)/.git
513 $(IDF_PATH)/$(1)/.git:
514         @echo "WARNING: Missing submodule $(1)..."
515         [ -e ${IDF_PATH}/.git ] || ( echo "ERROR: esp-idf must be cloned from git to work."; exit 1)
516         [ -x "$(shell which git)" ] || ( echo "ERROR: Need to run 'git submodule init $(1)' in esp-idf root directory."; exit 1)
517         @echo "Attempting 'git submodule update --init $(1)' in esp-idf root directory..."
518         cd ${IDF_PATH} && git submodule update --init $(1)
519
520 # Parse 'git status' output to check if the submodule commit is different to expected
521 ifneq ("$(filter $(1),$(GIT_STATUS))","")
522 $$(info WARNING: esp-idf git submodule $(1) may be out of date. Run 'git submodule update' in IDF_PATH dir to update.)
523 endif
524 endef
525
526 # filter/subst in expression ensures all submodule paths begin with $(IDF_PATH), and then strips that prefix
527 # so the argument is suitable for use with 'git submodule' commands
528 $(foreach submodule,$(subst $(IDF_PATH)/,,$(filter $(IDF_PATH)/%,$(COMPONENT_SUBMODULES))),$(eval $(call GenerateSubmoduleCheckTarget,$(submodule))))
529 endif # End check for .gitmodules existence
530
531
532 # PHONY target to list components in the build and their paths
533 list-components:
534         $(info $(call dequote,$(SEPARATOR)))
535         $(info COMPONENT_DIRS (components searched for here))
536         $(foreach cd,$(COMPONENT_DIRS),$(info $(cd)))
537         $(info $(call dequote,$(SEPARATOR)))
538         $(info TEST_COMPONENTS (list of test component names))
539         $(info $(TEST_COMPONENTS_LIST))
540         $(info $(call dequote,$(SEPARATOR)))
541         $(info TEST_EXCLUDE_COMPONENTS (list of test excluded names))
542         $(info $(if $(EXCLUDE_COMPONENTS) || $(TEST_EXCLUDE_COMPONENTS),$(EXCLUDE_COMPONENTS) $(TEST_EXCLUDE_COMPONENTS),(none provided)))      
543         $(info $(call dequote,$(SEPARATOR)))
544         $(info COMPONENT_PATHS (paths to all components):)
545         $(foreach cp,$(COMPONENT_PATHS),$(info $(cp)))
546
547 # print flash command, so users can dump this to config files and download somewhere without idf
548 print_flash_cmd: partition_table_get_info
549         echo $(ESPTOOL_WRITE_FLASH_OPTIONS) $(ESPTOOL_ALL_FLASH_ARGS) | sed -e 's:'$(PWD)/build/'::g'
550
551 # Check toolchain version using the output of xtensa-esp32-elf-gcc --version command.
552 # The output normally looks as follows
553 #     xtensa-esp32-elf-gcc (crosstool-NG crosstool-ng-1.22.0-59-ga194053) 4.8.5
554 # The part in brackets is extracted into TOOLCHAIN_COMMIT_DESC variable,
555 # the part after the brackets is extracted into TOOLCHAIN_GCC_VER.
556 ifdef CONFIG_TOOLPREFIX
557 ifndef MAKE_RESTARTS
558 TOOLCHAIN_COMMIT_DESC := $(shell $(CC) --version | sed -E -n 's|.*crosstool-ng-([0-9]+).([0-9]+).([0-9]+)-([0-9]+)-g([0-9a-f]{7}).*|\1.\2.\3-\4-g\5|gp')
559 TOOLCHAIN_GCC_VER := $(shell $(CC) --version | sed -E -n 's|xtensa-esp32-elf-gcc.*\ \(.*\)\ (.*)|\1|gp')
560
561 # Officially supported version(s)
562 SUPPORTED_TOOLCHAIN_COMMIT_DESC := 1.22.0-80-g6c4433a
563 SUPPORTED_TOOLCHAIN_GCC_VERSIONS := 5.2.0
564
565 ifdef TOOLCHAIN_COMMIT_DESC
566 ifneq ($(TOOLCHAIN_COMMIT_DESC), $(SUPPORTED_TOOLCHAIN_COMMIT_DESC))
567 $(info WARNING: Toolchain version is not supported: $(TOOLCHAIN_COMMIT_DESC))
568 $(info Expected to see version: $(SUPPORTED_TOOLCHAIN_COMMIT_DESC))
569 $(info Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.)
570 endif
571 ifeq (,$(findstring $(TOOLCHAIN_GCC_VER), $(SUPPORTED_TOOLCHAIN_GCC_VERSIONS)))
572 $(info WARNING: Compiler version is not supported: $(TOOLCHAIN_GCC_VER))
573 $(info Expected to see version(s): $(SUPPORTED_TOOLCHAIN_GCC_VERSIONS))
574 $(info Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.)
575 endif
576 else
577 $(info WARNING: Failed to find Xtensa toolchain, may need to alter PATH or set one in the configuration menu)
578 endif # TOOLCHAIN_COMMIT_DESC
579
580 endif #MAKE_RESTARTS
581 endif #CONFIG_TOOLPREFIX