forked from OpenSprinkler/OpenSprinkler-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.esp8266
184 lines (150 loc) · 7.19 KB
/
Makefile.esp8266
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#====================================================================================
# makeESPArduino
#
# A makefile for ESP8286 Arduino projects.
# Edit the contents of this file to suit your project
# or just include it and override the applicable macros.
#
# License: GPL 2.1
# General and full license information is available at:
# https://github.com/plerup/makeEspArduino
#
# Copyright (c) 2016 Peter Lerup. All rights reserved.
#
#====================================================================================
#====================================================================================
# User editable area
#====================================================================================
#=== Project specific definitions: sketch and list of needed libraries
SKETCH ?= ./examples/mainArduino/mainArduino.ino
LIBS ?= $(ESP_LIBS)/Wire \
$(ESP_LIBS)/ESP8266WiFi \
$(ESP_LIBS)/ESP8266WebServer \
$(ESP_LIBS)/ESP8266mDNS \
$(ESP_LIBS)/SSD1306 \
.
# Esp8266 Arduino git location. Change ESP_ROOT to match your path
ESP_ROOT ?= $(HOME)/esp8266/
# Output directory
BUILD_ROOT ?= /tmp/$(MAIN_NAME)
# Board definitions. Assumes 4M flash, 1M SPIFF
FLASH_SIZE ?= 4M
FLASH_MODE ?= dio
FLASH_SPEED ?= 40
FLASH_LAYOUT ?= eagle.flash.4m.ld
# Upload parameters. Change UPLOAD_PORT to match your port name
UPLOAD_SPEED ?= 230400
UPLOAD_PORT ?= /dev/ttyUSB0
UPLOAD_VERB ?= -v
UPLOAD_RESET ?= ck
#====================================================================================
# The area below should normally not need to be edited
#====================================================================================
MKESPARD_VERSION = 1.0.0
START_TIME := $(shell perl -e "print time();")
# Main output definitions
MAIN_NAME = $(basename $(notdir $(SKETCH)))
MAIN_EXE = $(BUILD_ROOT)/$(MAIN_NAME).bin
MAIN_ELF = $(OBJ_DIR)/$(MAIN_NAME).elf
SRC_GIT_VERSION = $(call git_description,$(dir $(SKETCH)))
# esp8266 arduino directories
ESP_GIT_VERSION = $(call git_description,$(ESP_ROOT))
ESP_LIBS = $(ESP_ROOT)/libraries
TOOLS_ROOT = $(ESP_ROOT)/tools
TOOLS_BIN = $(TOOLS_ROOT)/xtensa-lx106-elf/bin
SDK_ROOT = $(ESP_ROOT)/tools/sdk
# Directory for intermedite build files
OBJ_DIR = $(BUILD_ROOT)/obj
OBJ_EXT = .o
DEP_EXT = .d
# Compiler definitions
CC = $(TOOLS_BIN)/xtensa-lx106-elf-gcc
CPP = $(TOOLS_BIN)/xtensa-lx106-elf-g++
LD = $(CC)
AR = $(TOOLS_BIN)/xtensa-lx106-elf-ar
ESP_TOOL = $(TOOLS_ROOT)/esptool/esptool
OTA_TOOL = $(TOOLS_ROOT)/espota.py
INCLUDE_DIRS += $(SDK_ROOT)/include $(SDK_ROOT)/lwip/include $(CORE_DIR) $(ESP_ROOT)/variants/generic $(OBJ_DIR)
C_DEFINES = -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -DF_CPU=80000000L -DARDUINO=10605 -DARDUINO_ESP8266_ESP01 -DARDUINO_ARCH_ESP8266 -DESP8266
C_INCLUDES = $(foreach dir,$(INCLUDE_DIRS) $(USER_DIRS),-I$(dir))
C_FLAGS ?= -c -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections
CPP_FLAGS ?= -c -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections
S_FLAGS ?= -c -g -x assembler-with-cpp -MMD
LD_FLAGS ?= -g -w -Os -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -L$(SDK_ROOT)/lib -L$(SDK_ROOT)/ld -T$(FLASH_LAYOUT) -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,register_chipv6_phy
LD_STD_LIBS ?= -lm -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig -lwps -lcrypto -laxtls
# Core source files
CORE_DIR = $(ESP_ROOT)/cores/esp8266
CORE_SRC = $(shell find $(CORE_DIR) -name "*.S" -o -name "*.c" -o -name "*.cpp")
CORE_OBJ = $(patsubst %,$(OBJ_DIR)/%$(OBJ_EXT),$(notdir $(CORE_SRC)))
CORE_LIB = $(OBJ_DIR)/core.ar
# User defined compilation units
USER_SRC = $(SKETCH) $(shell find $(LIBS) -name "*.S" -o -name "*.c" -o -name "*.cpp")
# Object file suffix seems to be significant for the linker...
USER_OBJ = $(subst .ino,.cpp,$(patsubst %,$(OBJ_DIR)/%$(OBJ_EXT),$(notdir $(USER_SRC))))
USER_DIRS = $(sort $(dir $(USER_SRC)))
VPATH += $(shell find $(CORE_DIR) -type d) $(USER_DIRS)
# Automatically generated build information data
# Makes the build date and git descriptions at the actual build
# event available as string constants in the program
BUILD_INFO_H = $(OBJ_DIR)/buildinfo.h
BUILD_INFO_CPP = $(OBJ_DIR)/buildinfo.cpp
BUILD_INFO_OBJ = $(BUILD_INFO_CPP)$(OBJ_EXT)
$(BUILD_INFO_H): | $(OBJ_DIR)
echo "typedef struct { const char *date, *time, *src_version, *env_version;} _tBuildInfo; extern _tBuildInfo _BuildInfo;" >$@
# Utility functions
git_description = $(shell git -C $(1) describe --tags --always --dirty 2>/dev/null)
time_string = $(shell perl -e 'use POSIX qw(strftime); print strftime($(1), localtime());')
MEM_USAGE = \
'while (<>) { \
$$r += $$1 if /^\.(?:data|rodata|bss)\s+(\d+)/;\
$$f += $$1 if /^\.(?:irom0\.text|text|data|rodata)\s+(\d+)/;\
}\
print "\nMemory usage\n";\
print sprintf(" %-6s %6d bytes\n" x 2 ."\n", "Ram:", $$r, "Flash:", $$f);'
# Build rules
$(OBJ_DIR)/%.cpp$(OBJ_EXT): %.cpp $(BUILD_INFO_H)
echo $(<F)
$(CPP) $(C_DEFINES) $(C_INCLUDES) $(CPP_FLAGS) $< -o $@
$(OBJ_DIR)/%.cpp$(OBJ_EXT): %.ino $(BUILD_INFO_H)
echo $(<F)
$(CPP) -x c++ -include $(CORE_DIR)/Arduino.h $(C_DEFINES) $(C_INCLUDES) $(CPP_FLAGS) $< -o $@
$(OBJ_DIR)/%.c$(OBJ_EXT): %.c
echo $(<F)
$(CC) $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) $< -o $@
$(OBJ_DIR)/%.S$(OBJ_EXT): %.S
echo $(<F)
$(CC) $(C_DEFINES) $(C_INCLUDES) $(S_FLAGS) $< -o $@
$(CORE_LIB): $(CORE_OBJ)
echo Creating core archive
rm -f $@
$(AR) cru $@ $^
BUILD_DATE = $(call time_string,"%Y-%m-%d")
BUILD_TIME = $(call time_string,"%H:%M:%S")
$(MAIN_EXE): $(CORE_LIB) $(USER_OBJ)
echo Linking $(MAIN_EXE)
echo " Versions: $(SRC_GIT_VERSION), $(ESP_GIT_VERSION)"
echo '#include <buildinfo.h>' >$(BUILD_INFO_CPP)
echo '_tBuildInfo _BuildInfo = {"$(BUILD_DATE)","$(BUILD_TIME)","$(SRC_GIT_VERSION)","$(ESP_GIT_VERSION)"};' >>$(BUILD_INFO_CPP)
$(CPP) $(C_DEFINES) $(C_INCLUDES) $(CPP_FLAGS) $(BUILD_INFO_CPP) -o $(BUILD_INFO_OBJ)
$(LD) $(LD_FLAGS) -Wl,--start-group $^ $(BUILD_INFO_OBJ) $(LD_STD_LIBS) -Wl,--end-group -L$(OBJ_DIR) -o $(MAIN_ELF)
$(ESP_TOOL) -eo $(ESP_ROOT)/bootloaders/eboot/eboot.elf -bo $@ -bm $(FLASH_MODE) -bf $(FLASH_SPEED) -bz $(FLASH_SIZE) -bs .text -bp 4096 -ec -eo $(MAIN_ELF) -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
$(TOOLS_BIN)/xtensa-lx106-elf-size -A $(MAIN_ELF) | perl -e $(MEM_USAGE)
perl -e 'print "Build complete. Elapsed time: ", time()-$(START_TIME), " seconds\n\n"'
upload: all
$(ESP_TOOL) $(UPLOAD_VERB) -cd $(UPLOAD_RESET) -cb $(UPLOAD_SPEED) -cp $(UPLOAD_PORT) -ca 0x00000 -cf $(MAIN_EXE)
ota: all
$(OTA_TOOL) -i $(ESP_ADDR) -p $(ESP_PORT) -a $(ESP_PWD) -f $(MAIN_EXE)
clean:
echo Removing all intermediate build files...
rm -f $(OBJ_DIR)/*
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
.PHONY: all
all: $(OBJ_DIR) $(BUILD_INFO_H) $(MAIN_EXE)
# Include all available dependencies
-include $(wildcard $(OBJ_DIR)/*$(DEP_EXT))
.DEFAULT_GOAL = all
ifndef VERBOSE
# Set silent mode as default
MAKEFLAGS += --silent
endif