forked from toitlang/toit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
345 lines (278 loc) · 10.4 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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# Copyright (C) 2021 Toitware ApS.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; version
# 2.1 only.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# The license can be found in the file `LICENSE` in the top level
# directory of this repository.
.ONESHELL: # Run all lines of targets in one shell
.SHELLFLAGS += -e
SHELL=bash
# General options.
BUILD ?= build
HOST ?= host
BUILD_TYPE ?= Release
TARGET ?= $(HOST)
TOOLCHAIN ?= $(TARGET)
prefix ?= /opt/toit-sdk
# Use 'make flash ESP32_ENTRY=examples/mandelbrot.toit' to flash
# a firmware version with an embedded application.
ESP32_CHIP=esp32
ESP32_PORT=
# The system process is started from its own entry point.
ESP32_SYSTEM_ENTRY=system/extensions/esp32/boot.toit
ifeq ($(ESP32_CHIP),esp32s3-spiram-octo)
IDF_TARGET=esp32s3
else ifeq ($(ESP32_CHIP),esp32-eth-clk-out17)
IDF_TARGET=esp32
else
IDF_TARGET=$(ESP32_CHIP)
endif
export IDF_TARGET
# Use Toitware ESP-IDF fork by default.
export IDF_PATH ?= $(CURDIR)/third_party/esp-idf
ifeq ($(OS),Windows_NT)
EXE_SUFFIX=.exe
DETECTED_OS=$(OS)
else
EXE_SUFFIX=
DETECTED_OS=$(shell uname)
endif
.PHONY: all
all: sdk
.PHONY: debug
debug:
LOCAL_CXXFLAGS="-O0" $(MAKE) BUILD_TYPE=Debug
.PHONY: sdk
sdk: tools toit-tools version-file
# Rebuilds the SDK using only Ninja, without rebuilding the
# Ninja files with Cmake.
.PHONY: sdk-no-cmake
sdk-no-cmake: tools-no-cmake toit-tools-no-cmake
check-env:
ifndef IGNORE_SUBMODULE
@ if git submodule status | grep '^[-+]' ; then \
echo "Submodules not updated or initialized. Did you 'git submodule update --init --recursive'?"; \
exit 1; \
fi
endif
ifndef IGNORE_GIT_TAGS
@ if [ -z "$$(git rev-list --tags --max-count=1)" ]; then \
echo "No tags in repository. Checkout is probably shallow. Run 'git fetch --tags --recurse-submodules=no'"; \
exit 1; \
fi
endif
ifeq ('$(wildcard $(IDF_PATH)/components/mbedtls/mbedtls/LICENSE)',"")
ifeq ('$(IDF_PATH)', '$(CURDIR)/third_party/esp-idf')
$(error mbedtls sources are missing. Did you `git submodule update --init --recursive`?)
else
$(error Invalid IDF_PATH. Missing mbedtls sources.)
endif
endif
ifneq ('$(realpath $(IDF_PATH))', '$(realpath $(CURDIR)/third_party/esp-idf)')
$(info -- Not using Toitware ESP-IDF fork.)
endif
ifeq ("$(wildcard ./toolchains/$(TOOLCHAIN).cmake)","")
$(error invalid compilation target '$(TOOLCHAIN)')
endif
# We mark this phony because adding and removing .cc files means that
# cmake needs to be rerun, but we don't detect that, so it might not
# get run enough. It takes <1s on Linux to run cmake, so it's
# usually best to run it eagerly.
.PHONY: $(BUILD)/$(TARGET)/CMakeCache.txt
$(BUILD)/$(TARGET)/CMakeCache.txt:
$(MAKE) rebuild-cmake
ifneq ($(TARGET),$(HOST))
# Support for cross-compilation.
.PHONY: $(BUILD)/$(HOST)/CMakeCache.txt
$(BUILD)/$(HOST)/CMakeCache.txt:
$(MAKE) TARGET=$(HOST) rebuild-cmake
.PHONY: sysroot
sysroot: check-env
$(MAKE) $(BUILD)/$(TARGET)/sysroot/usr
endif
BIN_DIR = $(abspath $(BUILD)/$(HOST)/sdk/bin)
TOITPKG_BIN = $(BIN_DIR)/toit.pkg$(EXE_SUFFIX)
TOITC_BIN = $(BIN_DIR)/toit.compile$(EXE_SUFFIX)
FIRMWARE_BIN = $(TOIT_TOOLS_DIR)/firmware$(EXE_SUFFIX)
.PHONY: download-packages
download-packages: check-env $(BUILD)/$(HOST)/CMakeCache.txt tools
(cd $(BUILD)/$(HOST) && ninja download_packages)
.PHONY: rebuild-cmake
rebuild-cmake:
mkdir -p $(BUILD)/$(TARGET)
(cd $(BUILD)/$(TARGET) && cmake $(CURDIR) -G Ninja -DTOITC=$(TOITC_BIN) -DTOITPKG=$(TOITPKG_BIN) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/toolchains/$(TOOLCHAIN).cmake --no-warn-unused-cli)
.PHONY: sync
sync: sync-packages
git submodule update --init --recursive
.PHONY: sync-packages
sync-packages: check-env $(BUILD)/$(HOST)/CMakeCache.txt
(cd $(BUILD)/$(HOST) && ninja sync_packages)
.PHONY: disable-auto-sync
disable-auto-sync:
$(MAKE) rebuild-cmake
cmake -DTOIT_PKG_AUTO_SYNC=OFF $(BUILD)/$(HOST)
.PHONY: host-tools
host-tools: check-env $(BUILD)/$(HOST)/CMakeCache.txt
(cd $(BUILD)/$(HOST) && ninja build_tools)
.PHONY: tools
# This rule contains a reference to host-tools.
# This means that on host we will try to build host twice, but
# the second attempt will be a no-op.
tools: host-tools check-env $(BUILD)/$(TARGET)/CMakeCache.txt tools-no-cmake
(cd $(BUILD)/$(TARGET) && ninja build_tools)
.PHONY: tools-no-cmake
tools-no-cmake:
(cd $(BUILD)/$(TARGET) && ninja build_tools)
.PHONY: toit-tools
toit-tools: tools download-packages
(cd $(BUILD)/$(TARGET) && ninja build_toit_tools)
.PHONY: toit-tools-no-cmake
toit-tools-no-cmake:
(cd $(BUILD)/$(TARGET) && ninja build_toit_tools)
.PHONY: vessels
vessels: check-env $(BUILD)/$(TARGET)/CMakeCache.txt
(cd $(BUILD)/$(TARGET) && ninja build_vessels)
.PHONY: version-file
version-file: $(BUILD)/$(TARGET)/CMakeCache.txt
(cd $(BUILD)/$(TARGET) && ninja build_version_file)
.PHONY: pi
pi: raspbian
TOITLANG_SYSROOTS := armv7 aarch64 riscv64 raspbian arm-linux-gnueabi
ifneq (,$(filter $(TARGET),$(TOITLANG_SYSROOTS)))
SYSROOT_URL=https://github.com/toitlang/sysroots/releases/download/v1.3.0/sysroot-$(TARGET).tar.gz
rebuild-cmake: sysroot
$(BUILD)/$(TARGET)/sysroot/sysroot.tar.xz:
if [[ "$(SYSROOT_URL)" == "" ]]; then \
echo "No sysroot URL for $(TARGET)"; \
exit 1; \
fi
mkdir -p $(BUILD)/$(TARGET)/sysroot
curl --location --output $(BUILD)/$(TARGET)/sysroot/sysroot.tar.xz $(SYSROOT_URL)
$(BUILD)/$(TARGET)/sysroot/usr: $(BUILD)/$(TARGET)/sysroot/sysroot.tar.xz
tar x -f $(BUILD)/$(TARGET)/sysroot/sysroot.tar.xz -C $(BUILD)/$(TARGET)/sysroot
touch $@
endif
# Create convenience rules for armv7, aarch64 and riscv64.
define CROSS_RULE
.PHONY: $(1)
$(1):
$(MAKE) TARGET=$(1) sdk
endef
$(foreach arch,$(TOITLANG_SYSROOTS),$(eval $(call CROSS_RULE,$(arch))))
# ESP32 VARIANTS
.PHONY: check-esp32-env
check-esp32-env:
ifeq ("", "$(shell command -v xtensa-esp32-elf-g++)")
$(error xtensa-esp32-elf-g++ not in path. Did you `source third_party/esp-idf/export.sh`?)
endif
IDF_PY := "$(IDF_PATH)/tools/idf.py"
.PHONY: esp32
esp32:
if [ "$(shell command -v xtensa-esp32-elf-g++)" = "" ]; then source '$(IDF_PATH)/export.sh'; fi; \
$(MAKE) esp32-no-env
.PHONY: esp32-no-env
esp32-no-env: check-env check-esp32-env sdk
cmake -E env IDF_TARGET=$(IDF_TARGET) IDF_CCACHE_ENABLE=1 python$(EXE_SUFFIX) $(IDF_PY) -C toolchains/$(ESP32_CHIP) -B $(BUILD)/$(ESP32_CHIP) -p "$(ESP32_PORT)" build
# ESP32 MENU CONFIG
.PHONY: menuconfig
menuconfig:
if [ "$(shell command -v xtensa-esp32-elf-g++)" = "" ]; then source '$(IDF_PATH)/export.sh'; fi; \
$(MAKE) menuconfig-no-env
.PHONY: menuconfig-no-env
menuconfig-no-env: check-env check-esp32-env
cmake -E env IDF_TARGET=$(IDF_TARGET) python$(EXE_SUFFIX) $(IDF_PY) -C toolchains/$(ESP32_CHIP) -B $(BUILD)/$(ESP32_CHIP) menuconfig
cmake -E env IDF_TARGET=$(IDF_TARGET) python$(EXE_SUFFIX) $(IDF_PY) -C toolchains/$(ESP32_CHIP) -B $(BUILD)/$(ESP32_CHIP) save-defconfig
# ESP32 MENU CONFIG
.PHONY: size-components
size-components:
if [ "$(shell command -v xtensa-esp32-elf-g++)" = "" ]; then source '$(IDF_PATH)/export.sh'; fi; \
$(MAKE) size-components-no-env
.PHONY: size-components-no-env
size-components-no-env: check-env check-esp32-env
cmake -E env IDF_TARGET=$(IDF_TARGET) python$(EXE_SUFFIX) $(IDF_PY) -C toolchains/$(ESP32_CHIP) -B build/$(ESP32_CHIP) -p "$(ESP32_PORT)" size-components
.PHONY: flash
flash:
if [ "$(shell command -v xtensa-esp32-elf-g++)" = "" ]; then source '$(IDF_PATH)/export.sh'; fi; \
$(MAKE) flash-no-env
.PHONY: flash-no-env
flash-no-env: esp32-no-env
cmake -E env IDF_TARGET=$(IDF_TARGET) python$(EXE_SUFFIX) $(IDF_PY) -C toolchains/$(ESP32_CHIP) -B $(BUILD)/$(ESP32_CHIP) -p "$(ESP32_PORT)" flash monitor
# UTILITY
.PHONY: clean
clean:
rm -rf $(BUILD)/
INSTALL_SRC_ARCH := $(TARGET)
.PHONY: install-sdk install
install-sdk:
install -D --target-directory="$(DESTDIR)$(prefix)"/bin "$(BUILD)"/$(INSTALL_SRC_ARCH)/sdk/bin/*
install -D --target-directory="$(DESTDIR)$(prefix)"/tools "$(BUILD)"/$(INSTALL_SRC_ARCH)/sdk/tools/*
install -D --target-directory="$(DESTDIR)$(prefix)"/vessels "$(BUILD)"/$(INSTALL_SRC_ARCH)/sdk/vessels/*
mkdir -p "$(DESTDIR)$(prefix)"/lib
cp -R "$(CURDIR)"/lib/* "$(DESTDIR)$(prefix)"/lib
find "$(DESTDIR)$(prefix)"/lib -type f -exec chmod 644 {} \;
install: install-sdk
# TESTS (host)
.PHONY: test
test:
(cd $(BUILD)/$(HOST) && ninja check_slow check_fuzzer_lib)
.PHONY: test-flaky
test-flaky:
(cd $(BUILD)/$(HOST) && ninja check_flaky)
.PHONY: test-fast
test-fast:
(cd $(BUILD)/$(HOST) && ninja check)
.PHONY: update-gold
update-gold:
$(MAKE) rebuild-cmake
(cd $(BUILD)/$(HOST) && ninja update_gold)
(cd $(BUILD)/$(HOST) && ninja update_minus_s_gold)
(cd $(BUILD)/$(HOST) && ninja update_type_gold)
.PHONY: test-health
test-health: download-packages
$(MAKE) rebuild-cmake
(cd $(BUILD)/$(HOST) && ninja check_health)
.PHONY: update-health-gold
update-health-gold: download-packages
$(MAKE) rebuild-cmake
(cd $(BUILD)/$(HOST) && ninja clear_health_gold)
(cd $(BUILD)/$(HOST) && ninja update_health_gold)
.PHONY: enable-external
enable-external:
$(MAKE) rebuild-cmake # Ensure the cmake-directory was created.
cmake -DTOIT_TEST_EXTERNAL=ON $(BUILD)/$(HOST)
$(MAKE) download-external
$(MAKE) rebuild-cmake
$(MAKE) download-packages
.PHONY: check-external-enabled
check-external-enabled:
@ if ! cmake -LA -N $(BUILD)/$(HOST) | grep 'TOIT_TEST_EXTERNAL:BOOL=ON'; then \
echo "external projects are not enabled. Run 'make enable-external' first."; \
exit 1; \
fi
.PHONY: disable-external
disable-external: check-external-enabled
$(MAKE) rebuild-cmake # Ensure the cmake-directory was created.
cmake -DTOIT_TEST_EXTERNAL=OFF $(BUILD)/$(HOST)
.PHONY: download-external
download-external: check-external-enabled
# Download with higher parallelism.
(cd $(BUILD)/$(HOST) && ninja -j 16 download_external)
.PHONY: test-external
test-external: check-external-enabled
(cd $(BUILD)/$(HOST) && ninja check_external)
.PHONY: test-external-health
test-external-health: check-external-enabled
(cd $(BUILD)/$(HOST) && ninja check_external_health)
.PHONY: update-external-health-gold
update-external-health-gold: download-packages check-external-enabled
$(MAKE) rebuild-cmake
(cd $(BUILD)/$(HOST) && ninja clear_external_health_gold)
(cd $(BUILD)/$(HOST) && ninja update_external_health_gold)