-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
339 lines (292 loc) · 12.8 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
# ----------------------------------------------------------------------
#
# File: Makefile
#
# Created: 30.06.2023
#
# Copyright (C) 2023, ETH Zurich and University of Bologna.
#
# Author: Moritz Scherer, ETH Zurich
#
# ----------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
#
# 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
#
# 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.
SHELL = /usr/bin/env bash
ROOT_DIR := $(patsubst %/,%, $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
INSTALL_PREFIX ?= install
DEEPLOY_INSTALL_DIR ?= ${ROOT_DIR}/${INSTALL_PREFIX}
TOOLCHAIN_DIR := ${ROOT_DIR}/toolchain
LLVM_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/llvm
LLVM_CLANG_RT_ARM ?= ${LLVM_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/libclang_rt.builtins-armv7m.a
LLVM_CLANG_RT_RISCV_RV32IMC ?= ${LLVM_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32imc/libclang_rt.builtins-riscv32.a
LLVM_CLANG_RT_RISCV_RV32IM ?= ${LLVM_INSTALL_DIR}/lib/clang/15.0.0/lib/baremetal/rv32im/libclang_rt.builtins-riscv32.a
PICOLIBC_ARM_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/arm
PICOLIBC_RISCV_INSTALL_DIR ?= ${LLVM_INSTALL_DIR}/picolibc/riscv
PULP_SDK_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/pulp-sdk
QEMU_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/qemu
BANSHEE_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/banshee
MEMPOOL_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/mempool
SNITCH_INSTALL_DIR ?= ${DEEPLOY_INSTALL_DIR}/snitch_cluster
CMAKE ?= cmake
LLVM_COMMIT_HASH ?= 99902b1
PICOLIBC_COMMIT_HASH ?= 31ff1b3601b379e4cab63837f253f59729ce1fef
PULP_SDK_COMMIT_HASH ?= c216298881cee767afc30928e055982b9e40e568
BANSHEE_COMMIT_HASH ?= 0e105921e77796e83d01c2aa4f4cadfa2005b4d9
MEMPOOL_COMMIT_HASH ?= affd45d94e05e375a6966af6a762deeb182a7bd6
SNITCH_COMMIT_HASH ?= e02cc9e3f24b92d4607455d5345caba3eb6273b2
RUSTUP_CARGO ?= $$(rustup which cargo)
all: toolchain emulators docs echo-bash
echo-bash:
@echo "Please export the following symbols:"
@echo "PULP_SDK_HOME=${PULP_SDK_INSTALL_DIR}"
@echo "SNITCH_HOME=${SNITCH_INSTALL_DIR}"
@echo "LLVM_INSTALL_DIR=${LLVM_INSTALL_DIR}"
@echo "CMAKE=$$(which cmake)"
@echo "Please add the following paths to your PATH variable:"
@echo "${QEMU_INSTALL_DIR}/bin"
@echo "${BANSHEE_INSTALL_DIR}"
@echo "For PULP to work, please source the following file:"
@echo "${PULP_SDK_INSTALL_DIR}/configs/siracusa.sh"
@echo ""
@echo "TL/DR: add these lines to run ~/.bashrc"
@echo "export PULP_SDK_HOME=${PULP_SDK_INSTALL_DIR}"
@echo "export SNITCH_HOME=${SNITCH_INSTALL_DIR}"
@echo "export LLVM_INSTALL_DIR=${LLVM_INSTALL_DIR}"
@echo "export PULP_RISCV_GCC_TOOLCHAIN=/PULP_SDK_IS_A_MESS"
@echo "export MEMPOOL_HOME=${MEMPOOL_INSTALL_DIR}"
@echo "export CMAKE=$$(which cmake)"
@echo "export PATH=${QEMU_INSTALL_DIR}/bin:${BANSHEE_INSTALL_DIR}:\$$PATH"
@echo "export PATH=~/.cargo/bin:\$$PATH"
@echo "source ${PULP_SDK_INSTALL_DIR}/configs/siracusa.sh"
toolchain: llvm llvm-compiler-rt-riscv llvm-compiler-rt-arm picolibc-arm picolibc-riscv
emulators: snitch_runtime pulp-sdk qemu banshee mempool
${TOOLCHAIN_DIR}/llvm-project:
cd ${TOOLCHAIN_DIR} && \
git clone https://github.com/pulp-platform/llvm-project.git \
-b main && \
cd ${TOOLCHAIN_DIR}/llvm-project && git checkout ${LLVM_COMMIT_HASH} && \
git submodule update --init --recursive && \
git apply ${TOOLCHAIN_DIR}/llvm.patch
${LLVM_INSTALL_DIR}: ${TOOLCHAIN_DIR}/llvm-project
cd ${TOOLCHAIN_DIR}/llvm-project && \
mkdir -p build && cd build && \
${CMAKE} -G Ninja \
-DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR} \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_TARGETS_TO_BUILD="ARM;RISCV;host" \
-DLLVM_BUILD_DOCS="0" \
-DLLVM_ENABLE_BINDINGS="0" \
-DLLVM_ENABLE_TERMINFO="0" \
-DLLVM_OPTIMIZED_TABLEGEN=ON \
-DLLVM_PARALLEL_LINK_JOBS=2 \
-DCMAKE_BUILD_TYPE=Release \
../llvm && \
${CMAKE} --build . -j && \
${CMAKE} --install .
llvm: ${LLVM_INSTALL_DIR}
${LLVM_CLANG_RT_RISCV_RV32IMC}: ${TOOLCHAIN_DIR}/llvm-project
cd ${TOOLCHAIN_DIR}/llvm-project && mkdir -p build-compiler-rt-riscv-rv32imc \
&& cd build-compiler-rt-riscv-rv32imc; \
${CMAKE} ../compiler-rt \
-DCMAKE_C_COMPILER_WORKS=1 \
-DCMAKE_CXX_COMPILER_WORKS=1 \
-DCMAKE_AR=${LLVM_INSTALL_DIR}/bin/llvm-ar \
-DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR}/lib/clang/15.0.0 \
-DCMAKE_ASM_COMPILER_TARGET="riscv32-unknown-elf" \
-DCMAKE_C_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \
-DCMAKE_ASM_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \
-DCMAKE_C_FLAGS="-mno-relax -march=rv32imc" \
-DCMAKE_SYSTEM_NAME=baremetal \
-DCMAKE_HOST_SYSTEM_NAME=baremetal \
-DCMAKE_C_COMPILER_TARGET="riscv32-unknown-elf" \
-DCMAKE_CXX_COMPILER_TARGET="riscv32-unknown-elf" \
-DCMAKE_SIZEOF_VOID_P=4 \
-DCMAKE_NM=${LLVM_INSTALL_DIR}/bin/llvm-nm \
-DCMAKE_RANLIB=${LLVM_INSTALL_DIR}/bin/llvm-ranlib \
-DCOMPILER_RT_BUILD_BUILTINS=ON \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DCOMPILER_RT_BUILD_MEMPROF=OFF \
-DCOMPILER_RT_BUILD_PROFILE=OFF \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DCOMPILER_RT_BAREMETAL_BUILD=ON \
-DCOMPILER_RT_OS_DIR="baremetal/rv32imc" \
-DLLVM_CONFIG_PATH=${LLVM_INSTALL_DIR}/bin/llvm-config && \
${CMAKE} --build . -j && \
${CMAKE} --install .
${LLVM_CLANG_RT_RISCV_RV32IM}: ${TOOLCHAIN_DIR}/llvm-project
cd ${TOOLCHAIN_DIR}/llvm-project && mkdir -p build-compiler-rt-riscv-rv32im \
&& cd build-compiler-rt-riscv-rv32im; \
${CMAKE} ../compiler-rt \
-DCMAKE_C_COMPILER_WORKS=1 \
-DCMAKE_CXX_COMPILER_WORKS=1 \
-DCMAKE_AR=${LLVM_INSTALL_DIR}/bin/llvm-ar \
-DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR}/lib/clang/15.0.0 \
-DCMAKE_ASM_COMPILER_TARGET="riscv32-unknown-elf" \
-DCMAKE_C_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \
-DCMAKE_ASM_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \
-DCMAKE_C_FLAGS="-mno-relax -march=rv32im" \
-DCMAKE_SYSTEM_NAME=baremetal \
-DCMAKE_HOST_SYSTEM_NAME=baremetal \
-DCMAKE_C_COMPILER_TARGET="riscv32-unknown-elf" \
-DCMAKE_CXX_COMPILER_TARGET="riscv32-unknown-elf" \
-DCMAKE_SIZEOF_VOID_P=4 \
-DCMAKE_NM=${LLVM_INSTALL_DIR}/bin/llvm-nm \
-DCMAKE_RANLIB=${LLVM_INSTALL_DIR}/bin/llvm-ranlib \
-DCOMPILER_RT_BUILD_BUILTINS=ON \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DCOMPILER_RT_BUILD_MEMPROF=OFF \
-DCOMPILER_RT_BUILD_PROFILE=OFF \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DCOMPILER_RT_BAREMETAL_BUILD=ON \
-DCOMPILER_RT_OS_DIR="baremetal/rv32im" \
-DLLVM_CONFIG_PATH=${LLVM_INSTALL_DIR}/bin/llvm-config && \
${CMAKE} --build . -j && \
${CMAKE} --install .
llvm-compiler-rt-riscv: ${LLVM_CLANG_RT_RISCV_RV32IM} ${LLVM_CLANG_RT_RISCV_RV32IMC}
${LLVM_CLANG_RT_ARM}: ${TOOLCHAIN_DIR}/llvm-project
cd ${TOOLCHAIN_DIR}/llvm-project && mkdir -p build-compiler-rt-arm \
&& cd build-compiler-rt-arm; \
${CMAKE} ../compiler-rt \
-DCMAKE_C_COMPILER_WORKS=1 \
-DCMAKE_CXX_COMPILER_WORKS=1 \
-DCMAKE_AR=${LLVM_INSTALL_DIR}/bin/llvm-ar \
-DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR}/lib/clang/15.0.0 \
-DCMAKE_ASM_COMPILER_TARGET="armv7m-none-eabi" \
-DCMAKE_C_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \
-DCMAKE_ASM_COMPILER=${LLVM_INSTALL_DIR}/bin/clang \
-DCMAKE_C_FLAGS="-mcpu=cortex-m4 "\
-DCMAKE_SYSTEM_NAME=baremetal \
-DCMAKE_HOST_SYSTEM_NAME=baremetal \
-DCMAKE_C_COMPILER_TARGET="armv7m-none-eabi" \
-DCMAKE_CXX_COMPILER_TARGET="armv7m-none-eabi" \
-DCMAKE_SIZEOF_VOID_P=4 \
-DCMAKE_NM=${LLVM_INSTALL_DIR}/bin/llvm-nm \
-DCMAKE_RANLIB=${LLVM_INSTALL_DIR}/bin/llvm-ranlib \
-DCOMPILER_RT_BUILD_BUILTINS=ON \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DCOMPILER_RT_BUILD_MEMPROF=OFF \
-DCOMPILER_RT_BUILD_PROFILE=OFF \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DCOMPILER_RT_BAREMETAL_BUILD=ON \
-DCOMPILER_RT_OS_DIR="baremetal" \
-DLLVM_CONFIG_PATH=${LLVM_INSTALL_DIR}/bin/llvm-config && \
${CMAKE} --build . -j && \
${CMAKE} --install .
llvm-compiler-rt-arm: ${LLVM_CLANG_RT_ARM}
${TOOLCHAIN_DIR}/picolibc:
cd ${TOOLCHAIN_DIR} && \
git clone https://github.com/picolibc/picolibc.git && \
cd ${TOOLCHAIN_DIR}/picolibc && git checkout ${PICOLIBC_COMMIT_HASH} && \
git submodule update --init --recursive
${PICOLIBC_ARM_INSTALL_DIR}: ${TOOLCHAIN_DIR}/picolibc
cd ${TOOLCHAIN_DIR}/picolibc && mkdir -p build-arm && cd build-arm && \
cp ${TOOLCHAIN_DIR}/meson-build-script-arm.txt ../scripts && \
PATH=${LLVM_INSTALL_DIR}/bin:${PATH} meson setup --reconfigure -Dincludedir=include \
-Dlibdir=lib \
-Dspecsdir=none \
-Dmultilib=false \
--prefix ${PICOLIBC_ARM_INSTALL_DIR} \
--cross-file ../scripts/meson-build-script-arm.txt && \
PATH=${LLVM_INSTALL_DIR}/bin:${PATH} meson install
picolibc-arm: ${PICOLIBC_ARM_INSTALL_DIR}
${PICOLIBC_RISCV_INSTALL_DIR}: ${TOOLCHAIN_DIR}/picolibc
cd ${TOOLCHAIN_DIR}/picolibc && mkdir -p build-riscv && cd build-riscv && \
cp ${TOOLCHAIN_DIR}/meson-build-script-riscv.txt ../scripts && \
PATH=${LLVM_INSTALL_DIR}/bin:${PATH} meson setup --reconfigure -Dincludedir=include \
-Dlibdir=lib \
-Dspecsdir=none \
-Dmultilib=false \
--prefix ${PICOLIBC_RISCV_INSTALL_DIR} \
--cross-file ../scripts/meson-build-script-riscv.txt && \
PATH=${LLVM_INSTALL_DIR}/bin:${PATH} meson install
picolibc-riscv: ${PICOLIBC_RISCV_INSTALL_DIR}
${TOOLCHAIN_DIR}/pulp-sdk:
cd ${TOOLCHAIN_DIR} && \
git clone https://github.com/Scheremo/pulp-sdk.git -b scheremo && \
cd ${TOOLCHAIN_DIR}/pulp-sdk && git checkout ${PULP_SDK_COMMIT_HASH} && \
git submodule update --init --recursive
${PULP_SDK_INSTALL_DIR}: ${TOOLCHAIN_DIR}/pulp-sdk
mkdir -p ${PULP_SDK_INSTALL_DIR}
cp -r ${TOOLCHAIN_DIR}/pulp-sdk/ ${PULP_SDK_INSTALL_DIR}/../
cd ${PULP_SDK_INSTALL_DIR} && \
source configs/siracusa.sh && \
make build
pulp-sdk: ${PULP_SDK_INSTALL_DIR}
${TOOLCHAIN_DIR}/snitch_cluster:
cd ${TOOLCHAIN_DIR} && \
git clone https://github.com/pulp-platform/snitch_cluster.git && \
cd ${TOOLCHAIN_DIR}/snitch_cluster && git submodule update --init --recursive && \
git checkout ${SNITCH_COMMIT_HASH} && git apply ${TOOLCHAIN_DIR}/snitch_cluster.patch
${SNITCH_INSTALL_DIR}: ${TOOLCHAIN_DIR}/snitch_cluster
mkdir -p ${SNITCH_INSTALL_DIR}
cp -r ${TOOLCHAIN_DIR}/snitch_cluster/ ${SNITCH_INSTALL_DIR}/../
cd ${SNITCH_INSTALL_DIR} && \
[ -d /usr/pack/riscv-1.0-kgf/pulp-llvm-0.12.0/bin ] && export LLVM_BINROOT=/usr/pack/riscv-1.0-kgf/pulp-llvm-0.12.0/bin || \
export LLVM_BINROOT=$(dir $(shell which clang) ) && \
mkdir tmp && \
TMPDIR=tmp pip install -r python-requirements.txt && rm -rf tmp && \
bender vendor init && \
cd ${SNITCH_INSTALL_DIR}/target/snitch_cluster && \
make sw/runtime/banshee sw/math
snitch_runtime: ${SNITCH_INSTALL_DIR}
${TOOLCHAIN_DIR}/qemu:
cd ${TOOLCHAIN_DIR} && \
git clone https://github.com/qemu/qemu.git --depth 1 -b stable-6.1 && \
cd ${TOOLCHAIN_DIR}/qemu && \
git submodule update --init --recursive
${QEMU_INSTALL_DIR}: ${TOOLCHAIN_DIR}/qemu
cd ${TOOLCHAIN_DIR}/qemu/ && \
mkdir -p build && cd build && \
../configure --target-list=arm-softmmu,arm-linux-user,riscv32-softmmu,riscv32-linux-user \
--prefix=${QEMU_INSTALL_DIR} && \
make -j && \
make install
qemu: ${QEMU_INSTALL_DIR}
${TOOLCHAIN_DIR}/banshee:
cd ${TOOLCHAIN_DIR} && \
git clone https://github.com/pulp-platform/banshee.git && \
cd ${TOOLCHAIN_DIR}/banshee && git checkout ${BANSHEE_COMMIT_HASH} && \
git submodule update --init --recursive && \
git apply ${TOOLCHAIN_DIR}/banshee.patch
${BANSHEE_INSTALL_DIR}: ${TOOLCHAIN_DIR}/banshee
export LLVM_SYS_150_PREFIX=${LLVM_INSTALL_DIR} && \
cd ${TOOLCHAIN_DIR}/banshee/ && \
${RUSTUP_CARGO} clean && \
${RUSTUP_CARGO} install --path . -f
banshee: ${BANSHEE_INSTALL_DIR}
mempool: ${MEMPOOL_INSTALL_DIR}
${TOOLCHAIN_DIR}/mempool:
cd ${TOOLCHAIN_DIR} && \
git clone https://github.com/Xeratec/mempool.git && \
cd ${TOOLCHAIN_DIR}/mempool && git checkout ${MEMPOOL_COMMIT_HASH}
${MEMPOOL_INSTALL_DIR}: ${TOOLCHAIN_DIR}/mempool
mkdir -p ${MEMPOOL_INSTALL_DIR}/software && \
cd ${TOOLCHAIN_DIR}/mempool && \
cp -r ${TOOLCHAIN_DIR}/mempool/software/runtime ${MEMPOOL_INSTALL_DIR}/software
.PHONY: docs clean-docs format
format:
python scripts/run_clang_format.py -e "*/third_party/*" -e "*/install/*" -e "*/toolchain/*" -ir ./ scripts --clang-format-executable=${LLVM_INSTALL_DIR}/bin/clang-format
autoflake -i -r --remove-all-unused-imports --ignore-init-module-imports --exclude "*/third_party/**" ./
yapf -ipr -e "third_party/" -e "install/" -e "toolchain/" .
isort --sg "**/third_party/*" --sg "install/*" --sg "toolchain/*" ./
docs:
make -C docs html
clean-docs:
rm -rf docs/_autosummary docs/_build