project.mk 24 KB

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