project.mk 21 KB

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