2016-08-17 11:08:22 -04:00
|
|
|
#
|
|
|
|
# Main Project Makefile
|
2016-08-31 19:19:06 -04:00
|
|
|
# This Makefile is included directly from the user project Makefile in order to call the component.mk
|
|
|
|
# makefiles of all components (in a separate make process) to build all the libraries, then links them
|
|
|
|
# together into the final file. If so, PWD is the project dir (we assume).
|
2016-08-17 11:08:22 -04:00
|
|
|
#
|
|
|
|
|
|
|
|
#
|
2016-08-31 19:19:06 -04:00
|
|
|
# This makefile requires the environment variable IDF_PATH to be set to the top-level esp-idf directory
|
|
|
|
# where this file is located.
|
2016-08-17 11:08:22 -04:00
|
|
|
#
|
|
|
|
|
2017-06-14 22:18:48 -04:00
|
|
|
.PHONY: build-components menuconfig defconfig all build clean all_binaries check-submodules size size-components size-files
|
2016-10-31 19:50:16 -04:00
|
|
|
all: all_binaries
|
|
|
|
# see below for recipe of 'all' target
|
|
|
|
#
|
|
|
|
# # other components will add dependencies to 'all_binaries'. The
|
|
|
|
# reason all_binaries is used instead of 'all' is so that the flash
|
|
|
|
# target can build everything without triggering the per-component "to
|
|
|
|
# flash..." output targets.)
|
2016-08-18 05:11:27 -04:00
|
|
|
|
|
|
|
help:
|
|
|
|
@echo "Welcome to Espressif IDF build system. Some useful make targets:"
|
|
|
|
@echo ""
|
|
|
|
@echo "make menuconfig - Configure IDF project"
|
2016-08-23 04:18:36 -04:00
|
|
|
@echo "make defconfig - Set defaults for all new configuration options"
|
2016-08-18 05:11:27 -04:00
|
|
|
@echo ""
|
|
|
|
@echo "make all - Build app, bootloader, partition table"
|
2016-12-19 18:00:04 -05:00
|
|
|
@echo "make flash - Flash app, bootloader, partition table to a chip"
|
2016-08-18 05:11:27 -04:00
|
|
|
@echo "make clean - Remove all build output"
|
2017-06-14 22:18:48 -04:00
|
|
|
@echo "make size - Display the static memory footprint of the app"
|
|
|
|
@echo "make size-components, size-files - Finer-grained memory footprints"
|
2016-12-19 18:00:04 -05:00
|
|
|
@echo "make erase_flash - Erase entire flash contents"
|
2017-03-07 17:15:19 -05:00
|
|
|
@echo "make monitor - Run idf_monitor tool to monitor serial output from app"
|
|
|
|
@echo "make simple_monitor - Monitor serial output on terminal console"
|
2016-08-18 05:11:27 -04:00
|
|
|
@echo ""
|
|
|
|
@echo "make app - Build just the app"
|
|
|
|
@echo "make app-flash - Flash just the app"
|
|
|
|
@echo "make app-clean - Clean just the app"
|
|
|
|
@echo ""
|
|
|
|
@echo "See also 'make bootloader', 'make bootloader-flash', 'make bootloader-clean', "
|
|
|
|
@echo "'make partition_table', etc, etc."
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-11-13 18:51:53 -05:00
|
|
|
# dependency checks
|
|
|
|
ifndef MAKE_RESTARTS
|
|
|
|
ifeq ("$(filter 4.% 3.81 3.82,$(MAKE_VERSION))","")
|
|
|
|
$(warning "esp-idf build system only supports GNU Make versions 3.81 or newer. You may see unexpected results with other Makes.")
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2016-12-21 18:31:20 -05:00
|
|
|
# make IDF_PATH a "real" absolute path
|
|
|
|
# * works around the case where a shell character is embedded in the environment variable value.
|
|
|
|
# * changes Windows-style C:/blah/ paths to MSYS/Cygwin style /c/blah
|
2017-01-03 20:36:59 -05:00
|
|
|
ifeq ("$(OS)","Windows_NT")
|
|
|
|
# On Windows MSYS2, make wildcard function returns empty string for paths of form /xyz
|
|
|
|
# where /xyz is a directory inside the MSYS root - so we don't use it.
|
|
|
|
SANITISED_IDF_PATH:=$(realpath $(IDF_PATH))
|
|
|
|
else
|
|
|
|
SANITISED_IDF_PATH:=$(realpath $(wildcard $(IDF_PATH)))
|
|
|
|
endif
|
|
|
|
|
|
|
|
export IDF_PATH := $(SANITISED_IDF_PATH)
|
2016-12-15 19:30:37 -05:00
|
|
|
|
|
|
|
ifndef IDF_PATH
|
|
|
|
$(error IDF_PATH variable is not set to a valid directory.)
|
|
|
|
endif
|
|
|
|
|
2017-01-03 20:36:59 -05:00
|
|
|
ifneq ("$(IDF_PATH)","$(SANITISED_IDF_PATH)")
|
|
|
|
# implies IDF_PATH was overriden on make command line.
|
|
|
|
# Due to the way make manages variables, this is hard to account for
|
2016-12-15 19:30:37 -05:00
|
|
|
#
|
|
|
|
# if you see this error, do the shell expansion in the shell ie
|
|
|
|
# make IDF_PATH=~/blah not make IDF_PATH="~/blah"
|
|
|
|
$(error If IDF_PATH is overriden on command line, it must be an absolute path with no embedded shell special characters)
|
|
|
|
endif
|
|
|
|
|
2016-12-21 18:31:20 -05:00
|
|
|
ifneq ("$(IDF_PATH)","$(subst :,,$(IDF_PATH))")
|
|
|
|
$(error IDF_PATH cannot contain colons. If overriding IDF_PATH on Windows, use Cygwin-style /c/dir instead of C:/dir)
|
|
|
|
endif
|
|
|
|
|
2016-08-17 11:08:22 -04:00
|
|
|
# disable built-in make rules, makes debugging saner
|
2016-10-06 03:29:34 -04:00
|
|
|
MAKEFLAGS_OLD := $(MAKEFLAGS)
|
2016-08-17 11:08:22 -04:00
|
|
|
MAKEFLAGS +=-rR
|
|
|
|
|
2016-11-10 00:19:59 -05:00
|
|
|
# Default path to the project: we assume the Makefile including this file
|
|
|
|
# is in the project directory
|
|
|
|
ifndef PROJECT_PATH
|
2016-08-17 11:08:22 -04:00
|
|
|
PROJECT_PATH := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
|
|
|
|
export PROJECT_PATH
|
2016-08-18 00:36:15 -04:00
|
|
|
endif
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# A list of the "common" makefiles, to use as a target dependency
|
|
|
|
COMMON_MAKEFILES := $(abspath $(IDF_PATH)/make/project.mk $(IDF_PATH)/make/common.mk $(IDF_PATH)/make/component_wrapper.mk)
|
2016-11-08 20:51:55 -05:00
|
|
|
export COMMON_MAKEFILES
|
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# The directory where we put all objects/libraries/binaries. The project Makefile can
|
|
|
|
# configure this if needed.
|
2016-08-17 11:08:22 -04:00
|
|
|
BUILD_DIR_BASE ?= $(PROJECT_PATH)/build
|
2016-10-04 00:03:48 -04:00
|
|
|
export BUILD_DIR_BASE
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# Component directories. These directories are searched for components.
|
|
|
|
# The project Makefile can override these component dirs, or define extra component directories.
|
2016-08-19 02:32:35 -04:00
|
|
|
COMPONENT_DIRS ?= $(PROJECT_PATH)/components $(EXTRA_COMPONENT_DIRS) $(IDF_PATH)/components
|
2016-08-17 11:08:22 -04:00
|
|
|
export COMPONENT_DIRS
|
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# Source directories of the project itself (a special, project-specific component.) Defaults to only "main".
|
|
|
|
SRCDIRS ?= main
|
|
|
|
|
|
|
|
# The project Makefile can define a list of components, but if it does not do this we just take
|
|
|
|
# all available components in the component dirs.
|
2016-11-10 00:19:59 -05:00
|
|
|
ifndef COMPONENTS
|
2016-11-09 21:20:55 -05:00
|
|
|
# Find all component names. The component names are the same as the
|
|
|
|
# directories they're in, so /bla/components/mycomponent/ -> mycomponent. We then use
|
|
|
|
# COMPONENT_DIRS to build COMPONENT_PATHS with the full path to each component.
|
2016-08-17 11:08:22 -04:00
|
|
|
COMPONENTS := $(foreach dir,$(COMPONENT_DIRS),$(wildcard $(dir)/*))
|
|
|
|
COMPONENTS := $(sort $(foreach comp,$(COMPONENTS),$(lastword $(subst /, ,$(comp)))))
|
|
|
|
endif
|
|
|
|
export COMPONENTS
|
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# Resolve all of COMPONENTS into absolute paths in COMPONENT_PATHS.
|
|
|
|
#
|
|
|
|
# If a component name exists in multiple COMPONENT_DIRS, we take the first match.
|
|
|
|
#
|
|
|
|
# NOTE: These paths must be generated WITHOUT a trailing / so we
|
|
|
|
# can use $(notdir x) to get the component name.
|
2016-08-17 11:08:22 -04:00
|
|
|
COMPONENT_PATHS := $(foreach comp,$(COMPONENTS),$(firstword $(foreach dir,$(COMPONENT_DIRS),$(wildcard $(dir)/$(comp)))))
|
|
|
|
COMPONENT_PATHS += $(abspath $(SRCDIRS))
|
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# A component is buildable if it has a component.mk makefile in it
|
2016-08-31 19:19:06 -04:00
|
|
|
COMPONENT_PATHS_BUILDABLE := $(foreach cp,$(COMPONENT_PATHS),$(if $(wildcard $(cp)/component.mk),$(cp)))
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2017-03-09 06:42:46 -05:00
|
|
|
# If TESTS_ALL set to 1, set TEST_COMPONENTS_LIST to all components
|
2016-11-22 22:42:12 -05:00
|
|
|
ifeq ($(TESTS_ALL),1)
|
2017-03-09 06:42:46 -05:00
|
|
|
TEST_COMPONENTS_LIST := $(COMPONENTS)
|
|
|
|
else
|
|
|
|
# otherwise, use TEST_COMPONENTS
|
|
|
|
TEST_COMPONENTS_LIST := $(TEST_COMPONENTS)
|
2016-11-22 22:42:12 -05:00
|
|
|
endif
|
2017-03-09 06:42:46 -05:00
|
|
|
TEST_COMPONENT_PATHS := $(foreach comp,$(TEST_COMPONENTS_LIST),$(firstword $(foreach dir,$(COMPONENT_DIRS),$(wildcard $(dir)/$(comp)/test))))
|
|
|
|
TEST_COMPONENT_NAMES := $(foreach comp,$(TEST_COMPONENT_PATHS),$(lastword $(subst /, ,$(dir $(comp))))_test)
|
2016-11-22 22:42:12 -05:00
|
|
|
|
2016-11-17 03:36:10 -05:00
|
|
|
|
2016-11-15 19:12:48 -05:00
|
|
|
# Initialise project-wide variables which can be added to by
|
|
|
|
# each component.
|
2016-11-09 21:20:55 -05:00
|
|
|
#
|
|
|
|
# These variables are built up via the component_project_vars.mk
|
|
|
|
# generated makefiles (one per component).
|
2016-11-15 19:12:48 -05:00
|
|
|
#
|
|
|
|
# See docs/build-system.rst for more details.
|
2016-08-18 00:36:15 -04:00
|
|
|
COMPONENT_INCLUDES :=
|
|
|
|
COMPONENT_LDFLAGS :=
|
2016-11-15 19:12:48 -05:00
|
|
|
COMPONENT_SUBMODULES :=
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# COMPONENT_PROJECT_VARS is the list of component_project_vars.mk generated makefiles
|
|
|
|
# for each component.
|
|
|
|
#
|
|
|
|
# Including $(COMPONENT_PROJECT_VARS) builds the COMPONENT_INCLUDES,
|
|
|
|
# COMPONENT_LDFLAGS variables and also targets for any inter-component
|
|
|
|
# dependencies.
|
2016-08-17 11:08:22 -04:00
|
|
|
#
|
2016-11-09 21:20:55 -05:00
|
|
|
# See the component_project_vars.mk target in component_wrapper.mk
|
2016-11-17 03:36:10 -05:00
|
|
|
COMPONENT_PROJECT_VARS := $(addsuffix /component_project_vars.mk,$(notdir $(COMPONENT_PATHS_BUILDABLE) ) $(TEST_COMPONENT_NAMES))
|
2016-11-08 20:51:55 -05:00
|
|
|
COMPONENT_PROJECT_VARS := $(addprefix $(BUILD_DIR_BASE)/,$(COMPONENT_PROJECT_VARS))
|
2016-11-13 18:51:53 -05:00
|
|
|
# this line is -include instead of include to prevent a spurious error message on make 3.81
|
|
|
|
-include $(COMPONENT_PROJECT_VARS)
|
2016-11-08 20:51:55 -05:00
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# Also add top-level project include path, for top-level includes
|
2016-10-06 03:05:51 -04:00
|
|
|
COMPONENT_INCLUDES += $(abspath $(BUILD_DIR_BASE)/include/)
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-11-08 20:51:55 -05:00
|
|
|
export COMPONENT_INCLUDES
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# Set variables common to both project & component
|
|
|
|
include $(IDF_PATH)/make/common.mk
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-10-31 19:50:16 -04:00
|
|
|
all:
|
2016-11-24 22:09:26 -05:00
|
|
|
ifdef CONFIG_SECURE_BOOT_ENABLED
|
2016-10-31 19:50:16 -04:00
|
|
|
@echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
|
2016-12-18 21:06:21 -05:00
|
|
|
ifndef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
|
|
|
|
@echo "App built but not signed. Sign app & partition data before flashing, via espsecure.py:"
|
|
|
|
@echo "espsecure.py sign_data --keyfile KEYFILE $(APP_BIN)"
|
|
|
|
@echo "espsecure.py sign_data --keyfile KEYFILE $(PARTITION_TABLE_BIN)"
|
|
|
|
endif
|
2016-10-31 19:50:16 -04:00
|
|
|
@echo "To flash app & partition table, run 'make flash' or:"
|
|
|
|
else
|
|
|
|
@echo "To flash all build output, run 'make flash' or:"
|
|
|
|
endif
|
|
|
|
@echo $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS)
|
|
|
|
|
2017-01-10 11:24:50 -05:00
|
|
|
|
2017-04-11 06:04:18 -04:00
|
|
|
IDF_VER := $(shell cd ${IDF_PATH} && git describe --always --tags --dirty)
|
2017-01-10 11:24:50 -05:00
|
|
|
|
2016-09-08 20:14:38 -04:00
|
|
|
# Set default LDFLAGS
|
2017-04-08 18:18:16 -04:00
|
|
|
SRCDIRS_COMPONENT_NAMES := $(sort $(foreach comp,$(SRCDIRS),$(lastword $(subst /, ,$(comp)))))
|
2016-09-08 20:14:38 -04:00
|
|
|
LDFLAGS ?= -nostdlib \
|
2017-04-08 18:18:16 -04:00
|
|
|
$(addprefix -L$(BUILD_DIR_BASE)/,$(COMPONENTS) $(TEST_COMPONENT_NAMES) $(SRCDIRS_COMPONENT_NAMES) ) \
|
2016-09-08 20:14:38 -04:00
|
|
|
-u call_user_start_cpu0 \
|
2016-11-03 02:33:30 -04:00
|
|
|
$(EXTRA_LDFLAGS) \
|
2016-09-08 20:14:38 -04:00
|
|
|
-Wl,--gc-sections \
|
|
|
|
-Wl,-static \
|
|
|
|
-Wl,--start-group \
|
|
|
|
$(COMPONENT_LDFLAGS) \
|
|
|
|
-lgcc \
|
2017-01-04 11:27:59 -05:00
|
|
|
-lstdc++ \
|
2016-09-08 20:14:38 -04:00
|
|
|
-Wl,--end-group \
|
|
|
|
-Wl,-EL
|
|
|
|
|
|
|
|
# Set default CPPFLAGS, CFLAGS, CXXFLAGS
|
|
|
|
# These are exported so that components can use them when compiling.
|
|
|
|
# If you need your component to add CFLAGS/etc for it's own source compilation only, set CFLAGS += in your component's Makefile.
|
|
|
|
# If you need your component to add CFLAGS/etc globally for all source
|
2016-10-20 05:17:54 -04:00
|
|
|
# files, set CFLAGS += in your component's Makefile.projbuild
|
|
|
|
# If you need to set CFLAGS/CPPFLAGS/CXXFLAGS at project level, set them in application Makefile
|
|
|
|
# before including project.mk. Default flags will be added before the ones provided in application Makefile.
|
2016-09-08 20:14:38 -04:00
|
|
|
|
2016-10-17 00:38:17 -04:00
|
|
|
# CPPFLAGS used by C preprocessor
|
2016-10-20 05:17:54 -04:00
|
|
|
# If any flags are defined in application Makefile, add them at the end.
|
2017-01-10 11:24:50 -05:00
|
|
|
CPPFLAGS := -DESP_PLATFORM -D IDF_VER=\"$(IDF_VER)\" -MMD -MP $(CPPFLAGS) $(EXTRA_CPPFLAGS)
|
2016-10-17 00:38:17 -04:00
|
|
|
|
|
|
|
# Warnings-related flags relevant both for C and C++
|
2016-11-15 23:42:38 -05:00
|
|
|
COMMON_WARNING_FLAGS = -Wall -Werror=all \
|
2016-10-17 00:38:17 -04:00
|
|
|
-Wno-error=unused-function \
|
|
|
|
-Wno-error=unused-but-set-variable \
|
2016-11-08 04:34:46 -05:00
|
|
|
-Wno-error=unused-variable \
|
2016-11-15 23:42:38 -05:00
|
|
|
-Wno-error=deprecated-declarations \
|
|
|
|
-Wextra \
|
|
|
|
-Wno-unused-parameter -Wno-sign-compare
|
2016-10-17 00:38:17 -04:00
|
|
|
|
|
|
|
# Flags which control code generation and dependency generation, both for C and C++
|
|
|
|
COMMON_FLAGS = \
|
|
|
|
-ffunction-sections -fdata-sections \
|
|
|
|
-fstrict-volatile-bitfields \
|
|
|
|
-mlongcalls \
|
2016-12-11 18:02:41 -05:00
|
|
|
-nostdlib
|
2016-10-17 00:38:17 -04:00
|
|
|
|
|
|
|
# Optimization flags are set based on menuconfig choice
|
|
|
|
ifneq ("$(CONFIG_OPTIMIZATION_LEVEL_RELEASE)","")
|
2016-10-17 01:47:13 -04:00
|
|
|
OPTIMIZATION_FLAGS = -Os
|
2016-10-17 00:38:17 -04:00
|
|
|
else
|
2016-10-20 04:10:51 -04:00
|
|
|
OPTIMIZATION_FLAGS = -Og
|
2016-10-17 00:38:17 -04:00
|
|
|
endif
|
2016-09-08 20:14:38 -04:00
|
|
|
|
2017-06-18 21:25:45 -04:00
|
|
|
ifeq ("$(CONFIG_OPTIMIZATION_ASSERTIONS)", "")
|
|
|
|
CPPFLAGS += -DNDEBUG
|
|
|
|
endif
|
|
|
|
|
2016-10-17 01:47:13 -04:00
|
|
|
# Enable generation of debugging symbols
|
2017-03-21 04:46:48 -04:00
|
|
|
# (we generate even in Release mode, as this has no impact on final binary size.)
|
|
|
|
DEBUG_FLAGS ?= -ggdb
|
2016-10-17 01:47:13 -04:00
|
|
|
|
2016-10-17 00:38:17 -04:00
|
|
|
# List of flags to pass to C compiler
|
2016-10-20 05:17:54 -04:00
|
|
|
# If any flags are defined in application Makefile, add them at the end.
|
|
|
|
CFLAGS := $(strip \
|
|
|
|
-std=gnu99 \
|
2017-03-21 04:46:48 -04:00
|
|
|
$(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \
|
2016-10-20 05:17:54 -04:00
|
|
|
$(COMMON_FLAGS) \
|
2016-11-15 23:42:38 -05:00
|
|
|
$(COMMON_WARNING_FLAGS) -Wno-old-style-declaration \
|
|
|
|
$(CFLAGS) \
|
|
|
|
$(EXTRA_CFLAGS))
|
2016-09-08 20:14:38 -04:00
|
|
|
|
2016-10-17 00:38:17 -04:00
|
|
|
# List of flags to pass to C++ compiler
|
2016-10-20 05:17:54 -04:00
|
|
|
# If any flags are defined in application Makefile, add them at the end.
|
|
|
|
CXXFLAGS := $(strip \
|
|
|
|
-std=gnu++11 \
|
|
|
|
-fno-exceptions \
|
|
|
|
-fno-rtti \
|
2017-03-21 04:46:48 -04:00
|
|
|
$(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \
|
2016-10-20 05:17:54 -04:00
|
|
|
$(COMMON_FLAGS) \
|
|
|
|
$(COMMON_WARNING_FLAGS) \
|
2016-11-15 23:42:38 -05:00
|
|
|
$(CXXFLAGS) \
|
|
|
|
$(EXTRA_CXXFLAGS))
|
2016-09-08 20:14:38 -04:00
|
|
|
|
|
|
|
export CFLAGS CPPFLAGS CXXFLAGS
|
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# Set host compiler and binutils
|
2016-08-17 11:08:22 -04:00
|
|
|
HOSTCC := $(CC)
|
|
|
|
HOSTLD := $(LD)
|
|
|
|
HOSTAR := $(AR)
|
|
|
|
HOSTOBJCOPY := $(OBJCOPY)
|
2016-12-09 11:07:44 -05:00
|
|
|
HOSTSIZE := $(SIZE)
|
|
|
|
export HOSTCC HOSTLD HOSTAR HOSTOBJCOPY SIZE
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# Set target compiler. Defaults to whatever the user has
|
|
|
|
# configured as prefix + ye olde gcc commands
|
2016-08-17 11:08:22 -04:00
|
|
|
CC := $(call dequote,$(CONFIG_TOOLPREFIX))gcc
|
|
|
|
CXX := $(call dequote,$(CONFIG_TOOLPREFIX))c++
|
|
|
|
LD := $(call dequote,$(CONFIG_TOOLPREFIX))ld
|
|
|
|
AR := $(call dequote,$(CONFIG_TOOLPREFIX))ar
|
|
|
|
OBJCOPY := $(call dequote,$(CONFIG_TOOLPREFIX))objcopy
|
2016-12-09 11:07:44 -05:00
|
|
|
SIZE := $(call dequote,$(CONFIG_TOOLPREFIX))size
|
|
|
|
export CC CXX LD AR OBJCOPY SIZE
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
|
|
PYTHON=$(call dequote,$(CONFIG_PYTHON))
|
|
|
|
|
2016-08-18 05:11:27 -04:00
|
|
|
# the app is the main executable built by the project
|
|
|
|
APP_ELF:=$(BUILD_DIR_BASE)/$(PROJECT_NAME).elf
|
|
|
|
APP_MAP:=$(APP_ELF:.elf=.map)
|
|
|
|
APP_BIN:=$(APP_ELF:.elf=.bin)
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
|
|
# Include any Makefile.projbuild file letting components add
|
|
|
|
# configuration at the project level
|
|
|
|
define includeProjBuildMakefile
|
2016-09-08 20:49:35 -04:00
|
|
|
$(if $(V),$(if $(wildcard $(1)/Makefile.projbuild),$(info including $(1)/Makefile.projbuild...)))
|
2016-08-17 11:08:22 -04:00
|
|
|
COMPONENT_PATH := $(1)
|
|
|
|
-include $(1)/Makefile.projbuild
|
|
|
|
endef
|
|
|
|
$(foreach componentpath,$(COMPONENT_PATHS),$(eval $(call includeProjBuildMakefile,$(componentpath))))
|
|
|
|
|
2016-11-08 20:51:55 -05:00
|
|
|
# once we know component paths, we can include the config generation targets
|
2016-11-08 22:26:50 -05:00
|
|
|
#
|
|
|
|
# (bootloader build doesn't need this, config is exported from top-level)
|
2016-11-09 21:20:55 -05:00
|
|
|
ifndef IS_BOOTLOADER_BUILD
|
2016-08-19 02:32:35 -04:00
|
|
|
include $(IDF_PATH)/make/project_config.mk
|
2016-11-08 22:26:50 -05:00
|
|
|
endif
|
2016-08-18 00:36:15 -04:00
|
|
|
|
2016-08-24 01:02:51 -04:00
|
|
|
# A "component" library is any library in the LDFLAGS where
|
|
|
|
# the name of the library is also a name of the component
|
|
|
|
APP_LIBRARIES = $(patsubst -l%,%,$(filter -l%,$(LDFLAGS)))
|
2016-11-17 03:36:10 -05:00
|
|
|
COMPONENT_LIBRARIES = $(filter $(notdir $(COMPONENT_PATHS_BUILDABLE)) $(TEST_COMPONENT_NAMES),$(APP_LIBRARIES))
|
2016-08-24 01:02:51 -04:00
|
|
|
|
|
|
|
# ELF depends on the library archive files for COMPONENT_LIBRARIES
|
|
|
|
# the rules to build these are emitted as part of GenerateComponentTarget below
|
2016-12-11 23:54:30 -05:00
|
|
|
#
|
|
|
|
# also depends on additional dependencies (linker scripts & binary libraries)
|
|
|
|
# stored in COMPONENT_LINKER_DEPS, built via component.mk files' COMPONENT_ADD_LINKER_DEPS variable
|
|
|
|
$(APP_ELF): $(foreach libcomp,$(COMPONENT_LIBRARIES),$(BUILD_DIR_BASE)/$(libcomp)/lib$(libcomp).a) $(COMPONENT_LINKER_DEPS)
|
2016-08-24 01:02:51 -04:00
|
|
|
$(summary) LD $(notdir $@)
|
2016-11-10 20:29:38 -05:00
|
|
|
$(CC) $(LDFLAGS) -o $@ -Wl,-Map=$(APP_MAP)
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-08-18 05:11:27 -04:00
|
|
|
# Generation of $(APP_BIN) from $(APP_ELF) is added by the esptool
|
2016-08-17 11:08:22 -04:00
|
|
|
# component's Makefile.projbuild
|
2016-08-18 05:11:27 -04:00
|
|
|
app: $(APP_BIN)
|
2016-12-18 21:06:21 -05:00
|
|
|
ifeq ("$(CONFIG_SECURE_BOOT_ENABLED)$(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)","y") # secure boot enabled, but remote sign app image
|
|
|
|
@echo "App built but not signed. Signing step via espsecure.py:"
|
|
|
|
@echo "espsecure.py sign_data --keyfile KEYFILE $(APP_BIN)"
|
|
|
|
@echo "Then flash app command is:"
|
|
|
|
@echo $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_APP_OFFSET) $(APP_BIN)
|
|
|
|
else
|
2016-08-17 11:08:22 -04:00
|
|
|
@echo "App built. Default flash app command is:"
|
2016-08-22 06:43:47 -04:00
|
|
|
@echo $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_APP_OFFSET) $(APP_BIN)
|
2016-12-18 21:06:21 -05:00
|
|
|
endif
|
2016-08-18 05:11:27 -04:00
|
|
|
|
|
|
|
all_binaries: $(APP_BIN)
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
|
|
$(BUILD_DIR_BASE):
|
|
|
|
mkdir -p $(BUILD_DIR_BASE)
|
|
|
|
|
2016-11-09 01:25:57 -05:00
|
|
|
# Macro for the recursive sub-make for each component
|
|
|
|
# $(1) - component directory
|
|
|
|
# $(2) - component name only
|
|
|
|
#
|
|
|
|
# Is recursively expanded by the GenerateComponentTargets macro
|
|
|
|
define ComponentMake
|
2016-11-17 03:36:10 -05:00
|
|
|
+$(MAKE) -C $(BUILD_DIR_BASE)/$(2) -f $(IDF_PATH)/make/component_wrapper.mk COMPONENT_MAKEFILE=$(1)/component.mk COMPONENT_NAME=$(2)
|
2016-08-17 11:08:22 -04:00
|
|
|
endef
|
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# Generate top-level component-specific targets for each component
|
2016-08-17 11:08:22 -04:00
|
|
|
# $(1) - path to component dir
|
2016-11-08 20:51:55 -05:00
|
|
|
# $(2) - name of component
|
2016-11-09 21:20:55 -05:00
|
|
|
#
|
|
|
|
define GenerateComponentTargets
|
2016-11-09 01:25:57 -05:00
|
|
|
.PHONY: $(2)-build $(2)-clean
|
|
|
|
|
2016-11-15 19:12:48 -05:00
|
|
|
$(2)-build: check-submodules
|
2016-11-09 01:25:57 -05:00
|
|
|
$(call ComponentMake,$(1),$(2)) build
|
|
|
|
|
|
|
|
$(2)-clean:
|
|
|
|
$(call ComponentMake,$(1),$(2)) clean
|
|
|
|
|
2016-11-08 20:51:55 -05:00
|
|
|
$(BUILD_DIR_BASE)/$(2):
|
|
|
|
@mkdir -p $(BUILD_DIR_BASE)/$(2)
|
2016-08-24 01:02:51 -04:00
|
|
|
|
2016-11-09 01:25:57 -05:00
|
|
|
# tell make it can build any component's library by invoking the -build target
|
2016-08-24 01:02:51 -04:00
|
|
|
# (this target exists for all components even ones which don't build libraries, but it's
|
|
|
|
# only invoked for the targets whose libraries appear in COMPONENT_LIBRARIES and hence the
|
|
|
|
# APP_ELF dependencies.)
|
2016-11-08 20:51:55 -05:00
|
|
|
$(BUILD_DIR_BASE)/$(2)/lib$(2).a: $(2)-build
|
2016-08-31 19:19:06 -04:00
|
|
|
$(details) "Target '$$^' responsible for '$$@'" # echo which build target built this file
|
2016-11-09 01:25:57 -05:00
|
|
|
|
2016-11-09 21:20:55 -05:00
|
|
|
# add a target to generate the component_project_vars.mk files that
|
|
|
|
# are used to inject variables into project make pass (see matching
|
|
|
|
# component_project_vars.mk target in component_wrapper.mk).
|
|
|
|
#
|
|
|
|
# If any component_project_vars.mk file is out of date, the make
|
|
|
|
# process will call this target to rebuild it and then restart.
|
|
|
|
#
|
2017-02-03 00:02:22 -05:00
|
|
|
$(BUILD_DIR_BASE)/$(2)/component_project_vars.mk: $(1)/component.mk $(COMMON_MAKEFILES) $(SDKCONFIG_MAKEFILE) | $(BUILD_DIR_BASE)/$(2)
|
2016-11-09 01:25:57 -05:00
|
|
|
$(call ComponentMake,$(1),$(2)) component_project_vars.mk
|
2016-08-17 11:08:22 -04:00
|
|
|
endef
|
|
|
|
|
2016-11-08 20:51:55 -05:00
|
|
|
$(foreach component,$(COMPONENT_PATHS_BUILDABLE),$(eval $(call GenerateComponentTargets,$(component),$(notdir $(component)))))
|
2016-11-17 03:36:10 -05:00
|
|
|
$(foreach component,$(TEST_COMPONENT_PATHS),$(eval $(call GenerateComponentTargets,$(component),$(lastword $(subst /, ,$(dir $(component))))_test)))
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-08-18 05:11:27 -04:00
|
|
|
app-clean: $(addsuffix -clean,$(notdir $(COMPONENT_PATHS_BUILDABLE)))
|
2016-08-24 01:02:24 -04:00
|
|
|
$(summary) RM $(APP_ELF)
|
2016-11-10 20:29:38 -05:00
|
|
|
rm -f $(APP_ELF) $(APP_BIN) $(APP_MAP)
|
2016-12-15 19:30:37 -05:00
|
|
|
|
2016-12-09 11:07:44 -05:00
|
|
|
size: $(APP_ELF)
|
2017-06-14 22:18:48 -04:00
|
|
|
$(PYTHON) $(IDF_PATH)/tools/idf_size.py $(APP_MAP)
|
|
|
|
|
|
|
|
size-files: $(APP_ELF)
|
|
|
|
$(PYTHON) $(IDF_PATH)/tools/idf_size.py --files $(APP_MAP)
|
|
|
|
|
|
|
|
size-components: $(APP_ELF)
|
|
|
|
$(PYTHON) $(IDF_PATH)/tools/idf_size.py --archives $(APP_MAP)
|
2016-08-18 05:11:27 -04:00
|
|
|
|
2016-11-04 01:05:00 -04:00
|
|
|
# NB: this ordering is deliberate (app-clean before config-clean),
|
|
|
|
# so config remains valid during all component clean targets
|
|
|
|
config-clean: app-clean
|
|
|
|
clean: config-clean
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-11-15 19:12:48 -05:00
|
|
|
# phony target to check if any git submodule listed in COMPONENT_SUBMODULES are missing
|
|
|
|
# or out of date, and exit if so. Components can add paths to this variable.
|
|
|
|
#
|
|
|
|
# This only works for components inside IDF_PATH
|
|
|
|
check-submodules:
|
|
|
|
|
2017-03-14 06:55:12 -04:00
|
|
|
# Dump the git status for the whole working copy once, then grep it for each submodule. This saves a lot of time on Windows.
|
2017-03-28 02:22:27 -04:00
|
|
|
GIT_STATUS := $(shell cd ${IDF_PATH} && git status --porcelain --ignore-submodules=dirty)
|
2017-03-14 06:55:12 -04:00
|
|
|
|
2016-11-15 19:12:48 -05:00
|
|
|
# Generate a target to check this submodule
|
|
|
|
# $(1) - submodule directory, relative to IDF_PATH
|
|
|
|
define GenerateSubmoduleCheckTarget
|
|
|
|
check-submodules: $(IDF_PATH)/$(1)/.git
|
|
|
|
$(IDF_PATH)/$(1)/.git:
|
|
|
|
@echo "WARNING: Missing submodule $(1)..."
|
2017-03-20 02:11:13 -04:00
|
|
|
[ -e ${IDF_PATH}/.git ] || ( echo "ERROR: esp-idf must be cloned from git to work."; exit 1)
|
2016-11-15 19:12:48 -05:00
|
|
|
[ -x $(which git) ] || ( echo "ERROR: Need to run 'git submodule init $(1)' in esp-idf root directory."; exit 1)
|
|
|
|
@echo "Attempting 'git submodule update --init $(1)' in esp-idf root directory..."
|
|
|
|
cd ${IDF_PATH} && git submodule update --init $(1)
|
|
|
|
|
2017-03-14 06:55:12 -04:00
|
|
|
# Parse 'git status' output to check if the submodule commit is different to expected
|
|
|
|
ifneq ("$(filter $(1),$(GIT_STATUS))","")
|
2016-12-11 23:08:57 -05:00
|
|
|
$$(info WARNING: esp-idf git submodule $(1) may be out of date. Run 'git submodule update' in IDF_PATH dir to update.)
|
2016-11-15 19:12:48 -05:00
|
|
|
endif
|
|
|
|
endef
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-11-15 19:12:48 -05:00
|
|
|
# filter/subst in expression ensures all submodule paths begin with $(IDF_PATH), and then strips that prefix
|
|
|
|
# so the argument is suitable for use with 'git submodule' commands
|
|
|
|
$(foreach submodule,$(subst $(IDF_PATH)/,,$(filter $(IDF_PATH)/%,$(COMPONENT_SUBMODULES))),$(eval $(call GenerateSubmoduleCheckTarget,$(submodule))))
|
2016-12-04 02:02:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
# Check toolchain version using the output of xtensa-esp32-elf-gcc --version command.
|
|
|
|
# The output normally looks as follows
|
|
|
|
# xtensa-esp32-elf-gcc (crosstool-NG crosstool-ng-1.22.0-59-ga194053) 4.8.5
|
|
|
|
# The part in brackets is extracted into TOOLCHAIN_COMMIT_DESC variable,
|
|
|
|
# the part after the brackets is extracted into TOOLCHAIN_GCC_VER.
|
2017-01-12 22:09:01 -05:00
|
|
|
ifdef CONFIG_TOOLPREFIX
|
2016-12-04 02:02:02 -05:00
|
|
|
ifndef MAKE_RESTARTS
|
2017-01-15 23:01:25 -05:00
|
|
|
TOOLCHAIN_COMMIT_DESC := $(shell $(CC) --version | sed -E -n 's|xtensa-esp32-elf-gcc.*\ \(([^)]*).*|\1|gp')
|
|
|
|
TOOLCHAIN_GCC_VER := $(shell $(CC) --version | sed -E -n 's|xtensa-esp32-elf-gcc.*\ \(.*\)\ (.*)|\1|gp')
|
2016-12-04 02:02:02 -05:00
|
|
|
|
|
|
|
# Officially supported version(s)
|
|
|
|
SUPPORTED_TOOLCHAIN_COMMIT_DESC := crosstool-NG crosstool-ng-1.22.0-61-gab8375a
|
|
|
|
SUPPORTED_TOOLCHAIN_GCC_VERSIONS := 5.2.0
|
|
|
|
|
2017-01-12 21:48:33 -05:00
|
|
|
ifdef TOOLCHAIN_COMMIT_DESC
|
2016-12-04 02:02:02 -05:00
|
|
|
ifneq ($(TOOLCHAIN_COMMIT_DESC), $(SUPPORTED_TOOLCHAIN_COMMIT_DESC))
|
|
|
|
$(info WARNING: Toolchain version is not supported: $(TOOLCHAIN_COMMIT_DESC))
|
|
|
|
$(info Expected to see version: $(SUPPORTED_TOOLCHAIN_COMMIT_DESC))
|
|
|
|
$(info Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.)
|
|
|
|
endif
|
|
|
|
ifeq (,$(findstring $(TOOLCHAIN_GCC_VER), $(SUPPORTED_TOOLCHAIN_GCC_VERSIONS)))
|
2017-01-12 21:48:33 -05:00
|
|
|
$(info WARNING: Compiler version is not supported: $(TOOLCHAIN_GCC_VER))
|
2016-12-04 02:02:02 -05:00
|
|
|
$(info Expected to see version(s): $(SUPPORTED_TOOLCHAIN_GCC_VERSIONS))
|
|
|
|
$(info Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.)
|
|
|
|
endif
|
2017-01-12 21:48:33 -05:00
|
|
|
else
|
|
|
|
$(info WARNING: Failed to find Xtensa toolchain, may need to alter PATH or set one in the configuration menu)
|
|
|
|
endif # TOOLCHAIN_COMMIT_DESC
|
2016-12-04 02:02:02 -05:00
|
|
|
|
2017-01-12 22:09:01 -05:00
|
|
|
endif #MAKE_RESTARTS
|
|
|
|
endif #CONFIG_TOOLPREFIX
|