2015-05-07 05:24:35 +00:00
|
|
|
# esp-open-rtos common Makefile
|
|
|
|
#
|
2015-06-02 05:06:40 +00:00
|
|
|
# ******************************************************************
|
|
|
|
# Run 'make help' in any example subdirectory to see a usage summary
|
2015-06-02 23:15:56 +00:00
|
|
|
# (or skip to the bottom of this file!)
|
|
|
|
#
|
|
|
|
# For example, from the top level run:
|
|
|
|
# make help -C examples/http_get
|
2015-06-02 05:06:40 +00:00
|
|
|
# ******************************************************************
|
2015-05-07 05:24:35 +00:00
|
|
|
#
|
2015-06-02 23:15:56 +00:00
|
|
|
# In-depth documentation is at https://github.com/SuperHouse/esp-open-rtos/wiki/Build-Process
|
2015-06-02 05:06:40 +00:00
|
|
|
#
|
|
|
|
# Most sections Copyright 2015 Superhouse Automation Pty Ltd
|
|
|
|
# BSD Licensed as described in the file LICENSE at top level.
|
2015-05-07 05:24:35 +00:00
|
|
|
#
|
|
|
|
# This makefile is adapted from the esp-mqtt makefile by @tuanpmt
|
2015-07-21 05:02:09 +00:00
|
|
|
# https://github.com/tuanpmt/esp_mqtt, but it has changed very significantly
|
2015-05-07 05:24:35 +00:00
|
|
|
# since then.
|
2015-07-21 05:02:09 +00:00
|
|
|
|
2015-06-02 23:14:50 +00:00
|
|
|
# assume the 'root' directory (ie top of the tree) is the directory common.mk is in
|
|
|
|
ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
|
|
|
|
|
2015-06-12 00:26:02 +00:00
|
|
|
# include optional local overrides at the root level, then in program directory
|
2015-07-21 05:02:09 +00:00
|
|
|
#
|
|
|
|
# Create either of these files for local system overrides if possible,
|
|
|
|
# instead of editing this makefile directly.
|
2015-06-02 23:14:50 +00:00
|
|
|
-include $(ROOT)local.mk
|
2015-05-07 05:24:35 +00:00
|
|
|
-include local.mk
|
|
|
|
|
2015-07-21 05:02:09 +00:00
|
|
|
# Flash size in megabits
|
2015-08-04 08:28:27 +00:00
|
|
|
# Valid values are same as for esptool.py - 2,4,8,16,32
|
2015-07-21 05:02:09 +00:00
|
|
|
FLASH_SIZE ?= 16
|
2015-06-02 05:06:40 +00:00
|
|
|
|
2015-08-04 08:28:27 +00:00
|
|
|
# Flash mode, valid values are same as for esptool.py - qio,qout,dio.dout
|
|
|
|
FLASH_MODE ?= qio
|
|
|
|
|
|
|
|
# Flash speed in MHz, valid values are same as for esptool.py - 80, 40, 26, 20
|
|
|
|
FLASH_SPEED ?= 40
|
|
|
|
|
2015-06-12 00:26:02 +00:00
|
|
|
# Output directories to store intermediate compiled files
|
|
|
|
# relative to the program directory
|
|
|
|
BUILD_DIR ?= $(PROGRAM_DIR)build/
|
|
|
|
FW_BASE ?= $(PROGRAM_DIR)firmware/
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-07-21 05:02:09 +00:00
|
|
|
# esptool.py from https://github.com/themadinventor/esptool
|
|
|
|
ESPTOOL ?= esptool.py
|
|
|
|
# serial port settings for esptool.py
|
|
|
|
ESPPORT ?= /dev/ttyUSB0
|
|
|
|
ESPBAUD ?= 115200
|
|
|
|
|
|
|
|
# Set OTA to 1 to build an image that supports rBoot OTA bootloader
|
|
|
|
#
|
|
|
|
# Currently only works with 16mbit or more flash sizes, with 8mbit
|
|
|
|
# images for each "slot"
|
|
|
|
OTA ?= 0
|
|
|
|
|
|
|
|
ifeq ($(OTA),1)
|
|
|
|
# for OTA, we build a "SDK v1.2 bootloader" compatible image where everything is in
|
|
|
|
# one file (should work with the v1.2 binary bootloader, and the FOSS rBoot bootloader).
|
|
|
|
IMGTOOL ?= esptool2
|
|
|
|
|
|
|
|
# Tell C preprocessor that we're building for OTA
|
|
|
|
CPPFLAGS = -DOTA
|
|
|
|
endif
|
2015-05-07 05:24:35 +00:00
|
|
|
|
|
|
|
FLAVOR ?= release # or debug
|
|
|
|
|
|
|
|
# Compiler names, etc. assume gdb
|
|
|
|
CROSS ?= xtensa-lx106-elf-
|
|
|
|
|
|
|
|
AR = $(CROSS)ar
|
|
|
|
CC = $(CROSS)gcc
|
2015-07-16 06:24:33 +00:00
|
|
|
CPP = $(CROSS)cpp
|
2015-05-07 05:24:35 +00:00
|
|
|
LD = $(CROSS)gcc
|
|
|
|
NM = $(CROSS)nm
|
2015-07-16 06:24:33 +00:00
|
|
|
C++ = $(CROSS)g++
|
2015-05-13 06:41:16 +00:00
|
|
|
SIZE = $(CROSS)size
|
2015-05-07 05:24:35 +00:00
|
|
|
OBJCOPY = $(CROSS)objcopy
|
2015-06-02 07:57:33 +00:00
|
|
|
OBJDUMP = $(CROSS)objdump
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-05-12 00:08:39 +00:00
|
|
|
# Source components to compile and link. Each of these are subdirectories
|
|
|
|
# of the root, with a 'component.mk' file.
|
2015-09-28 03:00:56 +00:00
|
|
|
COMPONENTS ?= $(EXTRA_COMPONENTS) FreeRTOS lwip core
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-05-30 09:11:04 +00:00
|
|
|
# binary esp-iot-rtos SDK libraries to link. These are pre-processed prior to linking.
|
|
|
|
SDK_LIBS ?= main net80211 phy pp wpa
|
|
|
|
|
|
|
|
# open source libraries linked in
|
2015-07-09 03:48:47 +00:00
|
|
|
LIBS ?= hal gcc c
|
2015-05-30 09:11:04 +00:00
|
|
|
|
2015-07-15 05:09:55 +00:00
|
|
|
# set to 0 if you want to use the toolchain libc instead of esp-open-rtos newlib
|
|
|
|
OWN_LIBC ?= 1
|
2015-05-30 09:11:04 +00:00
|
|
|
|
2015-07-21 05:02:09 +00:00
|
|
|
# Note: you will need a recent esp
|
|
|
|
ENTRY_SYMBOL ?= call_user_start
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-08-27 06:47:38 +00:00
|
|
|
# Set this to zero if you don't want individual function & data sections
|
|
|
|
# (some code may be slightly slower, linking will be slighty slower,
|
|
|
|
# but compiled code size will come down a small amount.)
|
|
|
|
SPLIT_SECTIONS ?= 1
|
|
|
|
|
2015-07-30 17:34:13 +00:00
|
|
|
# Common flags for both C & C++_
|
|
|
|
C_CXX_FLAGS = -Wall -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals $(CPPFLAGS)
|
|
|
|
# Flags for C only
|
|
|
|
CFLAGS = $(C_CXX_FLAGS) -std=gnu99
|
|
|
|
# Flags for C++ only
|
2015-08-19 06:38:15 +00:00
|
|
|
CXXFLAGS = $(C_CXX_FLAGS) -fno-exceptions -fno-rtti
|
2015-08-27 06:47:38 +00:00
|
|
|
|
2015-07-28 01:20:18 +00:00
|
|
|
LDFLAGS = -nostdlib -Wl,--no-check-sections -Wl,-L$(BUILD_DIR)sdklib -Wl,-L$(ROOT)lib -u $(ENTRY_SYMBOL) -Wl,-static -Wl,-Map=build/${PROGRAM}.map $(EXTRA_LDFLAGS)
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-08-27 06:47:38 +00:00
|
|
|
ifeq ($(SPLIT_SECTIONS),1)
|
|
|
|
C_CXX_FLAGS += -ffunction-sections -fdata-sections
|
|
|
|
LDFLAGS += -Wl,-gc-sections
|
|
|
|
endif
|
|
|
|
|
2015-05-07 05:24:35 +00:00
|
|
|
ifeq ($(FLAVOR),debug)
|
2015-07-30 17:34:13 +00:00
|
|
|
C_CXX_FLAGS += -g -O0
|
2015-05-07 05:24:35 +00:00
|
|
|
LDFLAGS += -g -O0
|
2015-08-26 00:21:51 +00:00
|
|
|
else ifeq ($(FLAVOR),sdklike)
|
|
|
|
# These are flags intended to produce object code as similar as possible to
|
|
|
|
# the output of the compiler used to build the SDK libs (for comparison of
|
|
|
|
# disassemblies when coding replacement routines). It is not normally
|
|
|
|
# intended to be used otherwise.
|
|
|
|
CFLAGS += -O2 -Os -fno-inline -fno-ipa-cp -fno-toplevel-reorder
|
|
|
|
LDFLAGS += -O2
|
2015-05-07 05:24:35 +00:00
|
|
|
else
|
2015-07-30 17:34:13 +00:00
|
|
|
C_CXX_FLAGS += -g -O2
|
2015-05-07 05:24:35 +00:00
|
|
|
LDFLAGS += -g -O2
|
|
|
|
endif
|
|
|
|
|
2015-06-02 05:06:00 +00:00
|
|
|
GITSHORTREV=\"$(shell cd $(ROOT); git rev-parse --short -q HEAD)\"
|
2015-07-21 05:02:09 +00:00
|
|
|
CPPFLAGS += -DGITSHORTREV=$(GITSHORTREV) -DFLASH_SIZE=$(FLASH_SIZE)
|
2015-06-02 05:06:00 +00:00
|
|
|
|
2015-11-13 01:11:37 +00:00
|
|
|
ifeq ($(OTA),0)
|
|
|
|
LINKER_SCRIPTS = $(ROOT)ld/nonota.ld
|
|
|
|
else
|
|
|
|
LINKER_SCRIPTS = $(ROOT)ld/ota.ld
|
|
|
|
endif
|
|
|
|
LINKER_SCRIPTS += $(ROOT)ld/common.ld $(ROOT)ld/rom.ld
|
2015-05-12 00:08:39 +00:00
|
|
|
|
2015-05-07 05:24:35 +00:00
|
|
|
####
|
|
|
|
#### no user configurable options below here
|
|
|
|
####
|
|
|
|
|
2015-07-21 05:02:09 +00:00
|
|
|
ifndef PROGRAM
|
|
|
|
$(error "Set the PROGRAM environment variable in your Makefile before including common.mk"
|
|
|
|
endif
|
|
|
|
|
2015-05-12 00:08:39 +00:00
|
|
|
# hacky way to get a single space value
|
|
|
|
empty :=
|
|
|
|
space := $(empty) $(empty)
|
|
|
|
|
2015-06-11 22:12:47 +00:00
|
|
|
# GNU Make lowercase function, bit of a horrorshow but works (courtesy http://stackoverflow.com/a/665045)
|
|
|
|
lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
|
|
|
|
|
2015-06-12 00:26:02 +00:00
|
|
|
# assume the program dir is the directory the top-level makefile was run in
|
|
|
|
PROGRAM_DIR := $(dir $(firstword $(MAKEFILE_LIST)))
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-05-12 00:08:39 +00:00
|
|
|
# derive various parts of compiler/linker arguments
|
2015-07-30 17:34:13 +00:00
|
|
|
SDK_LIB_ARGS = $(addprefix -l,$(SDK_LIBS))
|
|
|
|
LIB_ARGS = $(addprefix -l,$(LIBS))
|
2015-06-12 00:26:02 +00:00
|
|
|
PROGRAM_OUT = $(BUILD_DIR)$(PROGRAM).out
|
2015-11-13 01:11:37 +00:00
|
|
|
LDFLAGS += $(addprefix -T,$(LINKER_SCRIPTS))
|
2015-07-21 05:02:09 +00:00
|
|
|
|
|
|
|
ifeq ($(OTA),0)
|
|
|
|
# for non-OTA, we create two different files for uploading into the flash
|
|
|
|
# these are the names and options to generate them
|
|
|
|
FW_ADDR_1 = 0x00000
|
2015-09-18 03:45:44 +00:00
|
|
|
FW_ADDR_2 = 0x20000
|
2015-07-21 05:02:09 +00:00
|
|
|
FW_FILE_1 = $(addprefix $(FW_BASE),$(FW_ADDR_1).bin)
|
|
|
|
FW_FILE_2 = $(addprefix $(FW_BASE),$(FW_ADDR_2).bin)
|
|
|
|
else
|
|
|
|
# for OTA, it's a single monolithic image
|
2015-07-23 05:19:30 +00:00
|
|
|
FW_FILE = $(addprefix $(FW_BASE),$(PROGRAM).bin)
|
2015-07-21 05:02:09 +00:00
|
|
|
endif
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-08-06 01:34:26 +00:00
|
|
|
# firmware tool arguments
|
|
|
|
ESPTOOL_ARGS=-fs $(FLASH_SIZE)m -fm $(FLASH_MODE) -ff $(FLASH_SPEED)m
|
|
|
|
|
|
|
|
IMGTOOL_FLASH_SIZE_2=256
|
|
|
|
IMGTOOL_FLASH_SIZE_4=512
|
|
|
|
IMGTOOL_FLASH_SIZE_8=1024
|
|
|
|
IMGTOOL_FLASH_SIZE_16=2048
|
|
|
|
IMGTOOL_FLASH_SIZE_32=4096
|
|
|
|
IMGTOOL_FLASH_SIZE=$(value IMGTOOL_FLASH_SIZE_$(FLASH_SIZE))
|
|
|
|
IMGTOOL_ARGS=-$(IMGTOOL_FLASH_SIZE) -$(FLASH_MODE) -$(FLASH_SPEED)
|
|
|
|
|
2015-05-12 00:08:39 +00:00
|
|
|
# Common include directories, shared across all "components"
|
|
|
|
# components will add their include directories to this argument
|
|
|
|
#
|
2015-06-12 00:26:02 +00:00
|
|
|
# Placing $(PROGRAM_DIR) and $(PROGRAM_DIR)include first allows
|
|
|
|
# programs to have their own copies of header config files for components
|
2015-05-12 00:08:39 +00:00
|
|
|
# , which is useful for overriding things.
|
2015-08-21 06:30:52 +00:00
|
|
|
INC_DIRS = $(PROGRAM_DIR) $(PROGRAM_DIR)include $(ROOT)include
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-07-15 05:09:55 +00:00
|
|
|
ifeq ($(OWN_LIBC),1)
|
|
|
|
INC_DIRS += $(ROOT)libc/xtensa-lx106-elf/include
|
|
|
|
LDFLAGS += -L$(ROOT)libc/xtensa-lx106-elf/lib
|
|
|
|
endif
|
|
|
|
|
2015-05-07 05:24:35 +00:00
|
|
|
ifeq ("$(V)","1")
|
|
|
|
Q :=
|
|
|
|
vecho := @true
|
|
|
|
else
|
|
|
|
Q := @
|
|
|
|
vecho := @echo
|
|
|
|
endif
|
|
|
|
|
2015-05-12 00:08:39 +00:00
|
|
|
.PHONY: all clean debug_print
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-07-21 05:02:09 +00:00
|
|
|
all: $(PROGRAM_OUT) $(FW_FILE_1) $(FW_FILE_2) $(FW_FILE)
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-05-12 00:08:39 +00:00
|
|
|
# component_compile_rules: Produces compilation rules for a given
|
|
|
|
# component
|
|
|
|
#
|
2015-09-08 00:36:03 +00:00
|
|
|
# For user-facing documentation, see:
|
|
|
|
# https://github.com/SuperHouse/esp-open-rtos/wiki/Build-Process#adding-a-new-component
|
|
|
|
#
|
2015-05-12 00:08:39 +00:00
|
|
|
# Call arguments are:
|
|
|
|
# $(1) - component name
|
|
|
|
#
|
|
|
|
# Expects that the following component-specific variables are defined:
|
|
|
|
#
|
|
|
|
# $(1)_ROOT = Top-level dir containing component. Can be in-tree or out-of-tree.
|
2015-09-07 23:59:59 +00:00
|
|
|
# (if this variable isn't defined, directory containing component.mk is used)
|
2015-05-12 00:08:39 +00:00
|
|
|
# $(1)_SRC_DIR = List of source directories for the component. All must be under $(1)_ROOT
|
|
|
|
# $(1)_INC_DIR = List of include directories specific for the component
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Each call appends to COMPONENT_ARS which is a list of archive files for compiled components
|
|
|
|
COMPONENT_ARS =
|
|
|
|
define component_compile_rules
|
2015-09-07 23:59:59 +00:00
|
|
|
$(1)_DEFAULT_ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
|
|
|
|
$(1)_ROOT ?= $$($(1)_DEFAULT_ROOT)
|
2015-06-11 22:12:47 +00:00
|
|
|
$(1)_OBJ_DIR = $(call lc,$(BUILD_DIR)$(1)/)
|
2015-05-12 00:08:39 +00:00
|
|
|
### determine source files and object files ###
|
2015-08-10 05:51:57 +00:00
|
|
|
$(1)_SRC_FILES ?= $$(foreach sdir,$$($(1)_SRC_DIR), \
|
|
|
|
$$(wildcard $$(sdir)/*.c) $$(wildcard $$(sdir)/*.S) \
|
|
|
|
$$(wildcard $$(sdir)/*.cpp)) \
|
2015-07-28 01:27:35 +00:00
|
|
|
$$($(1)_EXTRA_SRC_FILES)
|
2015-06-12 00:27:14 +00:00
|
|
|
$(1)_REAL_SRC_FILES = $$(foreach sfile,$$($(1)_SRC_FILES),$$(realpath $$(sfile)))
|
2015-05-12 00:08:39 +00:00
|
|
|
$(1)_REAL_ROOT = $$(realpath $$($(1)_ROOT))
|
2015-06-12 00:27:14 +00:00
|
|
|
# patsubst here substitutes real component root path for the relative OBJ_DIR path, making things short again
|
2015-08-10 05:51:57 +00:00
|
|
|
$(1)_OBJ_FILES_CXX = $$(patsubst $$($(1)_REAL_ROOT)%.cpp,$$($(1)_OBJ_DIR)%.o,$$($(1)_REAL_SRC_FILES))
|
|
|
|
$(1)_OBJ_FILES_C = $$(patsubst $$($(1)_REAL_ROOT)%.c,$$($(1)_OBJ_DIR)%.o,$$($(1)_OBJ_FILES_CXX))
|
2015-07-30 00:10:37 +00:00
|
|
|
$(1)_OBJ_FILES = $$(patsubst $$($(1)_REAL_ROOT)%.S,$$($(1)_OBJ_DIR)%.o,$$($(1)_OBJ_FILES_C))
|
2015-06-11 23:51:25 +00:00
|
|
|
# the last included makefile is our component's component.mk makefile (rebuild the component if it changes)
|
|
|
|
$(1)_MAKEFILE ?= $(lastword $(MAKEFILE_LIST))
|
2015-05-12 00:08:39 +00:00
|
|
|
|
|
|
|
### determine compiler arguments ###
|
|
|
|
$(1)_CFLAGS ?= $(CFLAGS)
|
2015-07-30 17:34:13 +00:00
|
|
|
$(1)_CXXFLAGS ?= $(CXXFLAGS)
|
2015-06-05 01:47:19 +00:00
|
|
|
$(1)_CC_ARGS = $(Q) $(CC) $$(addprefix -I,$$(INC_DIRS)) $$(addprefix -I,$$($(1)_INC_DIR)) $$($(1)_CFLAGS)
|
2015-07-30 17:34:13 +00:00
|
|
|
$(1)_CXX_ARGS = $(Q) $(C++) $$(addprefix -I,$$(INC_DIRS)) $$(addprefix -I,$$($(1)_INC_DIR)) $$($(1)_CXXFLAGS)
|
2015-06-11 22:12:47 +00:00
|
|
|
$(1)_AR = $(call lc,$(BUILD_DIR)$(1).a)
|
2015-05-12 00:08:39 +00:00
|
|
|
|
2015-06-11 23:51:25 +00:00
|
|
|
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.c $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
2015-05-12 00:08:39 +00:00
|
|
|
$(vecho) "CC $$<"
|
|
|
|
$(Q) mkdir -p $$(dir $$@)
|
|
|
|
$$($(1)_CC_ARGS) -c $$< -o $$@
|
|
|
|
$$($(1)_CC_ARGS) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
|
|
|
|
2015-08-10 05:51:57 +00:00
|
|
|
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.cpp $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
|
|
|
$(vecho) "C++ $$<"
|
|
|
|
$(Q) mkdir -p $$(dir $$@)
|
|
|
|
$$($(1)_CXX_ARGS) -c $$< -o $$@
|
|
|
|
$$($(1)_CXX_ARGS) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
|
|
|
|
2015-07-30 00:10:37 +00:00
|
|
|
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.S $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
2015-07-28 01:27:35 +00:00
|
|
|
$(vecho) "AS $$<"
|
|
|
|
$(Q) mkdir -p $$(dir $$@)
|
2015-07-30 00:10:37 +00:00
|
|
|
$$($(1)_CC_ARGS) -c $$< -o $$@
|
2015-09-15 01:22:59 +00:00
|
|
|
$$($(1)_CC_ARGS) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
2015-07-28 01:27:35 +00:00
|
|
|
|
2015-06-12 00:27:14 +00:00
|
|
|
# the component is shown to depend on both obj and source files so we get a meaningful error message
|
|
|
|
# for missing explicitly named source files
|
|
|
|
$$($(1)_AR): $$($(1)_OBJ_FILES) $$($(1)_SRC_FILES)
|
2015-05-12 00:08:39 +00:00
|
|
|
$(vecho) "AR $$@"
|
2015-07-29 00:40:53 +00:00
|
|
|
$(Q) mkdir -p $$(dir $$@)
|
2015-05-12 00:08:39 +00:00
|
|
|
$(Q) $(AR) cru $$@ $$^
|
|
|
|
|
|
|
|
COMPONENT_ARS += $$($(1)_AR)
|
|
|
|
|
|
|
|
-include $$($(1)_OBJ_FILES:.o=.d)
|
|
|
|
endef
|
|
|
|
|
2015-05-30 09:11:04 +00:00
|
|
|
## Linking rules for SDK libraries
|
|
|
|
## SDK libraries are preprocessed to:
|
2015-06-16 00:02:36 +00:00
|
|
|
# - remove object files named in <libname>.remove
|
2015-05-30 09:11:04 +00:00
|
|
|
# - prefix all defined symbols with 'sdk_'
|
|
|
|
# - weaken all global symbols so they can be overriden from the open SDK side
|
2015-06-16 00:02:36 +00:00
|
|
|
#
|
|
|
|
# SDK binary libraries are preprocessed into build/sdklib
|
2015-05-30 09:11:04 +00:00
|
|
|
SDK_PROCESSED_LIBS = $(addsuffix .a,$(addprefix $(BUILD_DIR)sdklib/lib,$(SDK_LIBS)))
|
|
|
|
|
2015-06-16 00:02:36 +00:00
|
|
|
# Make rules for preprocessing each SDK library
|
2015-05-30 09:11:04 +00:00
|
|
|
|
2015-06-16 00:02:36 +00:00
|
|
|
# hacky, but prevents confusing error messages if one of these files disappears
|
|
|
|
$(ROOT)lib/%.remove:
|
|
|
|
touch $@
|
2015-05-30 09:11:04 +00:00
|
|
|
|
2015-06-16 00:02:36 +00:00
|
|
|
# Remove comment lines from <libname>.remove files
|
|
|
|
$(BUILD_DIR)sdklib/%.remove: $(ROOT)lib/%.remove | $(BUILD_DIR)sdklib
|
|
|
|
$(Q) grep -v "^#" $< | cat > $@
|
2015-05-30 09:11:04 +00:00
|
|
|
|
2015-06-16 00:02:36 +00:00
|
|
|
# Stage 1: remove unwanted object files listed in <libname>.remove alongside each library
|
|
|
|
$(BUILD_DIR)sdklib/%_stage1.a: $(ROOT)lib/%.a $(BUILD_DIR)sdklib/%.remove | $(BUILD_DIR)sdklib
|
|
|
|
@echo "SDK processing stage 1: Removing unwanted objects from $<"
|
|
|
|
$(Q) cat $< > $@
|
|
|
|
$(Q) $(AR) d $@ @$(word 2,$^)
|
2015-05-30 09:11:04 +00:00
|
|
|
|
2015-08-25 16:31:02 +00:00
|
|
|
# Stage 2: Redefine all SDK symbols as sdk_, weaken all symbols.
|
|
|
|
$(BUILD_DIR)sdklib/%.a: $(BUILD_DIR)sdklib/%_stage1.a $(ROOT)lib/allsymbols.rename
|
|
|
|
@echo "SDK processing stage 2: Renaming symbols in SDK library $< -> $@"
|
2015-06-16 00:02:36 +00:00
|
|
|
$(Q) $(OBJCOPY) --redefine-syms $(word 2,$^) --weaken $< $@
|
|
|
|
|
2015-06-12 00:26:02 +00:00
|
|
|
# include "dummy component" for the 'program' object files, defined in the Makefile
|
|
|
|
PROGRAM_SRC_DIR ?= $(PROGRAM_DIR)
|
|
|
|
PROGRAM_ROOT ?= $(PROGRAM_DIR)
|
|
|
|
PROGRAM_MAKEFILE = $(firstword $(MAKEFILE_LIST))
|
|
|
|
$(eval $(call component_compile_rules,PROGRAM))
|
2015-05-12 00:08:39 +00:00
|
|
|
|
2015-06-05 01:47:19 +00:00
|
|
|
## Include other components (this is where the actual compiler sections are generated)
|
2015-09-08 00:36:19 +00:00
|
|
|
##
|
|
|
|
## if component directory exists relative to $(ROOT), use that.
|
|
|
|
## otherwise try to resolve it as an absolute path
|
|
|
|
$(foreach component,$(COMPONENTS), \
|
|
|
|
$(if $(wildcard $(ROOT)$(component)), \
|
|
|
|
$(eval include $(ROOT)$(component)/component.mk), \
|
|
|
|
$(eval include $(component)/component.mk) \
|
|
|
|
) \
|
|
|
|
)
|
2015-07-16 06:24:33 +00:00
|
|
|
|
2015-05-12 00:08:39 +00:00
|
|
|
# final linking step to produce .elf
|
2015-11-13 01:11:37 +00:00
|
|
|
$(PROGRAM_OUT): $(COMPONENT_ARS) $(SDK_PROCESSED_LIBS) $(LINKER_SCRIPTS)
|
2015-05-07 05:24:35 +00:00
|
|
|
$(vecho) "LD $@"
|
2015-08-31 06:56:16 +00:00
|
|
|
$(Q) $(LD) $(LDFLAGS) -Wl,--start-group $(COMPONENT_ARS) $(LIB_ARGS) $(SDK_LIB_ARGS) -Wl,--end-group -o $@
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-11-13 01:11:37 +00:00
|
|
|
$(BUILD_DIR) $(FW_BASE) $(BUILD_DIR)sdklib:
|
2015-05-07 05:24:35 +00:00
|
|
|
$(Q) mkdir -p $@
|
|
|
|
|
2015-06-12 00:26:02 +00:00
|
|
|
$(FW_FILE_1) $(FW_FILE_2): $(PROGRAM_OUT) $(FW_BASE)
|
2015-05-12 00:08:39 +00:00
|
|
|
$(vecho) "FW $@"
|
2015-08-06 01:34:26 +00:00
|
|
|
$(Q) $(ESPTOOL) elf2image $(ESPTOOL_ARGS) $< -o $(FW_BASE)
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-07-21 05:02:09 +00:00
|
|
|
$(FW_FILE): $(PROGRAM_OUT) $(FW_BASE)
|
2015-08-06 01:34:26 +00:00
|
|
|
$(Q) $(IMGTOOL) $(IMGTOOL_ARGS) -bin -boot2 $(PROGRAM_OUT) $(FW_FILE) .text .data .rodata
|
2015-07-21 05:02:09 +00:00
|
|
|
|
|
|
|
ifeq ($(OTA),0)
|
2015-05-07 05:24:35 +00:00
|
|
|
flash: $(FW_FILE_1) $(FW_FILE_2)
|
2015-08-06 01:34:26 +00:00
|
|
|
$(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) write_flash $(ESPTOOL_ARGS) $(FW_ADDR_2) $(FW_FILE_2) $(FW_ADDR_1) $(FW_FILE_1)
|
2015-07-21 05:02:09 +00:00
|
|
|
else
|
|
|
|
flash: $(FW_FILE)
|
|
|
|
$(vecho) "Flashing OTA image slot 0 (bootloader not updated)"
|
2015-08-06 01:34:26 +00:00
|
|
|
$(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) write_flash $(ESPTOOL_ARGS) 0x2000 $(FW_FILE)
|
2015-07-21 05:02:09 +00:00
|
|
|
endif
|
2015-05-07 05:24:35 +00:00
|
|
|
|
2015-06-12 00:26:02 +00:00
|
|
|
size: $(PROGRAM_OUT)
|
|
|
|
$(Q) $(CROSS)size --format=sysv $(PROGRAM_OUT)
|
2015-05-13 06:41:16 +00:00
|
|
|
|
2015-05-07 05:24:35 +00:00
|
|
|
test: flash
|
|
|
|
screen $(ESPPORT) 115200
|
|
|
|
|
2015-05-12 00:20:09 +00:00
|
|
|
# the rebuild target is written like this so it can be run in a parallel build
|
|
|
|
# environment without causing weird side effects
|
|
|
|
rebuild:
|
|
|
|
$(MAKE) clean
|
|
|
|
$(MAKE) all
|
2015-05-07 05:24:35 +00:00
|
|
|
|
|
|
|
clean:
|
|
|
|
$(Q) rm -rf $(BUILD_DIR)
|
|
|
|
$(Q) rm -rf $(FW_BASE)
|
2015-05-30 09:11:04 +00:00
|
|
|
|
|
|
|
# prevent "intermediate" files from being deleted
|
|
|
|
.SECONDARY:
|
|
|
|
|
2015-06-02 05:06:40 +00:00
|
|
|
# print some useful help stuff
|
|
|
|
help:
|
|
|
|
@echo "esp-open-rtos make"
|
|
|
|
@echo ""
|
|
|
|
@echo "Other targets:"
|
|
|
|
@echo ""
|
|
|
|
@echo "all"
|
|
|
|
@echo "Default target. Will build firmware including any changed source files."
|
|
|
|
@echo
|
|
|
|
@echo "clean"
|
|
|
|
@echo "Delete all build output."
|
|
|
|
@echo ""
|
|
|
|
@echo "rebuild"
|
|
|
|
@echo "Build everything fresh from scratch."
|
|
|
|
@echo ""
|
|
|
|
@echo "flash"
|
|
|
|
@echo "Build then upload firmware to MCU. Set ESPPORT & ESPBAUD to override port/baud rate."
|
|
|
|
@echo ""
|
|
|
|
@echo "test"
|
|
|
|
@echo "'flash', then start a GNU Screen session on the same serial port to see serial output."
|
|
|
|
@echo ""
|
|
|
|
@echo "size"
|
|
|
|
@echo "Build, then print a summary of built firmware size."
|
|
|
|
@echo ""
|
|
|
|
@echo "TIPS:"
|
|
|
|
@echo "* You can use -jN for parallel builds. Much faster! Use 'make rebuild' instead of 'make clean all' for parallel builds."
|
|
|
|
@echo "* You can create a local.mk file to create local overrides of variables like ESPPORT & ESPBAUD."
|
|
|
|
@echo ""
|
|
|
|
@echo "SAMPLE COMMAND LINE:"
|
|
|
|
@echo "make -j2 test ESPPORT=/dev/ttyUSB0"
|
|
|
|
@echo ""
|
|
|
|
|
|
|
|
|