forked from google/tock-on-titan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
119 lines (103 loc) · 4.79 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
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Note that `all` does _not_ depend on `build-signed`. Many consumers
# of this project (especially new ones) won't be happy if they have to
# struggle with signing from day one.
.PHONY: all
all: build
# Subdirectories containing Build.mk files.
BUILD_SUBDIRS := kernel runner third_party tools userspace
# Both cargo and Tock's build system like connecting to the internet and
# installing things during builds. We don't like that. This is a sandbox we can
# run commands in that denies network access as well as write access outside the
# build/ directory.
#
# The mount order of /tmp and CURDIR is important. It is reasonable for someone
# to check this repository out under /tmp and try to build it. If this only has
# `--ro-bind / / --tmpfs /tmp` without `--ro-bind "$(CURDIR)" "$(CURDIR)"`,
# the sandbox will not contain any source code and the build will fail. Mounting
# in this order leaves the source code available and /tmp writable.
BWRAP := bwrap \
--ro-bind / / \
--tmpfs /tmp \
--ro-bind "$(CURDIR)" "$(CURDIR)" \
--bind "$(CURDIR)/build" "$(CURDIR)/build" \
--bind "$(CURDIR)/kernel/Cargo.lock" "$(CURDIR)/kernel/Cargo.lock" \
--bind "$(CURDIR)/runner/Cargo.lock" "$(CURDIR)/runner/Cargo.lock" \
--bind "$(CURDIR)/third_party/libtock-rs/Cargo.lock" \
"$(CURDIR)/third_party/libtock-rs/Cargo.lock" \
--bind "$(CURDIR)/third_party/rustc-demangle/Cargo.lock" \
"$(CURDIR)/third_party/rustc-demangle/Cargo.lock" \
--bind "$(CURDIR)/tools/Cargo.lock" "$(CURDIR)/tools/Cargo.lock" \
--bind "$(CURDIR)/userspace/Cargo.lock" \
"$(CURDIR)/userspace/Cargo.lock" \
--dev /dev \
--unshare-all
# A target that sets up directories the bwrap sandbox needs.
.PHONY: sandbox_setup
sandbox_setup:
mkdir -p build
>kernel/Cargo.lock
>runner/Cargo.lock
>third_party/libtock-rs/Cargo.lock
>third_party/rustc-demangle/Cargo.lock
>tools/Cargo.lock
>userspace/Cargo.lock
.PHONY: build
build: $(addsuffix /build,$(BUILD_SUBDIRS))
.PHONY: build-signed
build-signed: $(addsuffix /build-signed,$(BUILD_SUBDIRS))
.PHONY: check
check: $(addsuffix /check,$(BUILD_SUBDIRS))
# No need to recurse into most directories, as rm does that for us.
.PHONY: clean
clean: kernel/clean runner/clean third_party/clean tools/clean userspace/clean
rm -rf build/
.PHONY: devicetests
devicetests: $(addsuffix /devicetests,$(BUILD_SUBDIRS))
.PHONY: doc
doc: $(addsuffix /doc,$(BUILD_SUBDIRS))
.PHONY: localtests
localtests: $(addsuffix /localtests,$(BUILD_SUBDIRS))
.PHONY: prtest
prtest: build check devicetests localtests
@echo '------------------------------------------------------'
@echo 'prtest successful. When you open a PR, paste the below'
@echo 'block (not the output above) into the PR description:'
@echo '------------------------------------------------------'
@echo '```'
@echo '----------------------'
@echo '`make prtest` summary:'
@echo '----------------------'
git rev-parse HEAD
git status
@echo '```'
# Installs the necessary Rust toolchains
.PHONY: setup
setup:
cd userspace && rustup target add thumbv7m-none-eabi
cd kernel && rustup target add thumbv7m-none-eabi
# A target that prints an error message and fails the build if the cargo version
# is not sufficiently up-to-date.
.PHONY: cargo_version_check
cargo_version_check:
min_version="1.37.0" ; \
cargo_version="$$(cargo -V | awk '{ print $$2 }')" ; \
if [ "$$(third_party/tock/tools/semver.sh $${cargo_version} \< $${min_version})" != "false" ] ; \
then echo "#######################################################################"; \
echo "# Please update your stable toolchain. Minimum version: $${min_version}"; \
echo "#######################################################################"; \
exit 1; \
fi
include $(addsuffix /Build.mk,$(BUILD_SUBDIRS))