-
Notifications
You must be signed in to change notification settings - Fork 34
/
Makefile
140 lines (104 loc) · 4.14 KB
/
Makefile
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
# -*- make -*-
PROJ = $(notdir $(PWD))
SOURCES = $(wildcard *.ino *.cpp *.h)
FSDIR = data
FILES = $(wildcard $(FSDIR)/*)
# Don't use -DATOMIC_FS_UPDATE
CFLAGS_DEFAULT = -DNO_GLOBAL_HTTPUPDATE
CFLAGS = $(CFLAGS_DEFAULT)
CLI := arduino-cli
PLATFORM := esp8266:esp8266
CFGFILE := $(PWD)/arduino/arduino-cli.yaml
# Add CLICFG command to add config file location to CLI command
CLICFG := $(CLI) --config-file $(CFGFILE)
# bug in http stream, fallback to 2.7.4
# ESP8266URL := https://github.com/esp8266/Arduino/releases/download/3.0.2/package_esp8266com_index.json
ESP8266URL := https://github.com/esp8266/Arduino/releases/download/2.7.4/package_esp8266com_index.json
LIBRARIES := libraries/WiFiManager libraries/ArduinoJson libraries/PubSubClient libraries/TelnetStream libraries/AceTime libraries/OneWire libraries/DallasTemperature
BOARDS := arduino/package_esp8266com_index.json
# PORT can be overridden by the environment or on the command line. E.g.:
# export PORT=/dev/ttyUSB2; make upload, or: make upload PORT=/dev/ttyUSB2
PORT ?= /dev/ttyUSB0
BAUD ?= 460800
INO = $(PROJ).ino
MKFS = $(wildcard arduino/packages/esp8266/tools/mklittlefs/*/mklittlefs)
TOOLS = $(wildcard arduino/packages/esp8266/hardware/esp8266/*/tools)
ESPTOOL = python3 $(TOOLS)/esptool/esptool.py
BOARD = $(PLATFORM):d1_mini
FQBN = $(BOARD):eesz=4M2M,xtal=160
IMAGE = build/$(INO).bin
FILESYS = build/$(INO).littlefs.bin
export PYTHONPATH = $(TOOLS)/pyserial
binaries: $(IMAGE)
publish: $(PROJ)-fs.bin $(PROJ)-fw.bin
platform: $(BOARDS)
clean:
find $(FSDIR) -name '*~' -exec rm {} +
distclean: clean
rm -f *~
rm -rf arduino build libraries staging arduino-cli.yaml
$(CFGFILE):
$(CLI) config init --dest-file $(CFGFILE)
$(CLICFG) config set directories.data $(PWD)/arduino
$(CLICFG) config set board_manager.additional_urls $(ESP8266URL)
$(CLICFG) config set directories.downloads $(PWD)/staging
$(CLICFG) config set directories.user $(PWD)
$(CLICFG) config set sketch.always_export_binaries true
$(CLICFG) config set library.enable_unsafe_install true
##
# Make sure CFG is updated before libraries are called.
##
$(LIBRARIES): | $(CFGFILE)
$(BOARDS): | $(CFGFILE)
$(CLICFG) core update-index
$(CLICFG) core install $(PLATFORM)
refresh: | $(CFGFILE)
$(CLICFG) lib update-index
flush: | $(CFGFILE)
$(CLICFG) cache clean
libraries/WiFiManager: | $(BOARDS)
$(CLICFG) lib install [email protected]
libraries/ArduinoJson:
$(CLICFG) lib install [email protected]
libraries/PubSubClient:
$(CLICFG) lib install [email protected]
libraries/TelnetStream:
$(CLICFG) lib install [email protected]
libraries/AceTime:
$(CLICFG) lib install [email protected]
# libraries/Time:
# $(CLI) lib install --git-url https://github.com/PaulStoffregen/Time
# # https://github.com/PaulStoffregen/Time/archive/refs/tags/v1.6.1.zip
libraries/OneWire:
$(CLICFG) lib install [email protected]
libraries/DallasTemperature: | libraries/OneWire
$(CLICFG) lib install [email protected]
$(IMAGE): $(BOARDS) $(LIBRARIES) $(SOURCES)
$(info Build code)
$(CLICFG) compile --fqbn=$(FQBN) --warnings default --verbose --build-property compiler.cpp.extra_flags="$(CFLAGS)"
filesystem: $(FILESYS)
$(FILESYS): $(FILES) $(CONF) | $(BOARDS) clean
$(MKFS) -p 256 -b 8192 -s 1024000 -c $(FSDIR) $@
$(PROJ)-fs.bin: $(FILES) $(CONF) | $(BOARDS) clean
$(MKFS) -p 256 -b 8192 -s 1024000 -c $(FSDIR) $@
$(PROJ)-fw.bin: $(IMAGE)
cp $(IMAGE) $@
$(PROJ).zip: $(PROJ)-fw.bin $(PROJ)-fs.bin
rm -f $@
zip $@ $^
# Build the image with debugging output
debug: CFLAGS = $(CFLAGS_DEFAULT) -DDEBUG
debug: $(IMAGE)
# Load only the sketch into the device
upload: $(IMAGE)
$(ESPTOOL) --port $(PORT) -b $(BAUD) write_flash 0x0 $(IMAGE)
# Load only the file system into the device
upload-fs: $(FILESYS)
$(ESPTOOL) --port $(PORT) -b $(BAUD) write_flash 0x200000 $(FILESYS)
# Load both the sketch and the file system into the device
install: $(IMAGE) $(FILESYS)
$(ESPTOOL) --port $(PORT) -b $(BAUD) write_flash 0x0 $(IMAGE) 0x200000 $(FILESYS)
.PHONY: binaries platform publish clean upload upload-fs install debug filesystem
### Allow customization through a local Makefile: Makefile-local.mk
# Include the local make file, if it exists
-include Makefile-local.mk