project.mk 22 KB

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