-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmktoolchain.bash
More file actions
executable file
·190 lines (159 loc) · 4.6 KB
/
mktoolchain.bash
File metadata and controls
executable file
·190 lines (159 loc) · 4.6 KB
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
#!/usr/bin/env bash
set -e
BINUTILS=https://ftp.gnu.org/gnu/binutils/binutils-2.42.tar.bz2
# GCC
GMP=https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.bz2
MPFR=https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.bz2
MPC=https://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz
GCC=https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
# LLVM
CMAKE=https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2.tar.gz
LLVM=https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.4/llvm-project-18.1.4.src.tar.xz
source "$(dirname "$0")/env.bash"
function get() {
local name
rm -rf "$(dir "$1")"
name="$(basename "$1")"
if [ ! -f "$name" ]; then
echo "Downloading $name..."
curl --progress-bar --location --output "$name" "$1"
fi
echo "Extracting $name..."
tar xf "$name"
}
function dir() {
basename "$1" | sed 's/\.tar\..*$//'
}
BUILD_GCC=0
BUILD_CLANG=0
SKIP_CLEANUP=0
for arg in "$@"; do
case $arg in
--gcc)
BUILD_GCC=1
;;
--clang)
BUILD_CLANG=1
;;
--skip-cleanup)
SKIP_CLEANUP=1
;;
*)
echo "Unknown argument: $arg"
exit 1
;;
esac
done
if [ "$BUILD_GCC" -eq 0 ] && [ "$BUILD_CLANG" -eq 0 ]; then
GCC=1
fi
if [ "$BUILD_GCC" -eq 1 ] && [ "$(uname)" = "Darwin" ]; then
echo "Error: GCC 13 doesn't build with Xcode 15. This should be fixed in GCC 14."
echo "See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111632 for more info."
exit 1
fi
mkdir -p "$PREFIX/tmp"
cd "$PREFIX/tmp"
# We always install binutils because lld has the following issues with some of our linker
# scripts. Specifically:
#
# - It doesn't support adding the boot signature in boot.ld.
# - It doesn't support discarding .shstrtab even when output format is binary.
# It would be nicer to extract binutils once and build it out of tree in build-x86_64
# and build-aarch64 directories, but building binutils out of tree seems to require
# textinfo, which we'd like to avoid.
if [ ! -x "$PREFIX/bin/x86_64-elf-ld" ]; then
get "$BINUTILS"
cd "$(dir $BINUTILS)"
./configure --prefix="$PREFIX" --target=x86_64-elf --disable-werror
make
make install
cd ..
fi
if [ ! -x "$PREFIX/bin/aarch64-elf-ld" ]; then
# Won't re-download but will re-extract.
get "$BINUTILS"
cd "$(dir $BINUTILS)"
./configure --prefix="$PREFIX" --target=aarch64-elf --disable-werror
make
make install
cd ..
fi
if [ "$BUILD_CLANG" -eq 1 ]; then
if ! type cmake >/dev/null 2>&1 || [ "$(cmake -P "$PREFIX/../llvm_cmake_version.cmake")" != 1 ]; then
get "$CMAKE"
cd "$(dir $CMAKE)"
./bootstrap --prefix="$PREFIX" --parallel="$NCORES"
make
make install
cd ..
fi
if [[ ! -x $PREFIX/bin/clang ]]; then
get "$LLVM"
mkdir -p "$(dir $LLVM)/build"
cd "$(dir $LLVM)/build"
cmake -DCMAKE_INSTALL_PREFIX="$PREFIX" -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm
make
make install
cd ../..
fi
fi
if [ "$BUILD_GCC" -eq 1 ]; then
if [ ! -f "$PREFIX/lib/libgmp.a" ]; then
get "$GMP"
cd "$(dir $GMP)"
./configure --prefix="$PREFIX"
make
make install
cd ..
fi
if [ ! -f "$PREFIX/lib/libmpfr.a" ]; then
get "$MPFR"
cd "$(dir $MPFR)"
./configure --prefix="$PREFIX" --with-gmp="$PREFIX"
make
make install
cd ..
fi
if [ ! -f "$PREFIX/lib/libmpc.a" ]; then
get "$MPC"
cd "$(dir $MPC)"
./configure --prefix="$PREFIX" --with-gmp="$PREFIX"
make
make install
cd ..
fi
if [ ! -x "$PREFIX/bin/x86_64-elf-gcc" ] || [ ! -x "$PREFIX/bin/aarch64-elf-gcc" ]; then
get "$GCC"
cd "$(dir $GCC)"
if [ ! -x "$PREFIX/bin/x86_64-elf-gcc" ]; then
mkdir build-x86_64
cd build-x86_64
../configure --prefix="$PREFIX" --target=x86_64-elf --disable-werror \
--disable-libssp --disable-libmudflap --with-newlib --without-headers \
--enable-languages=c,c++,objc,lto --enable-lto --with-gmp="$PREFIX"
make all-gcc
make install-gcc
make all-target-libgcc
make install-target-libgcc
cd ..
fi
if [ ! -x "$PREFIX/bin/aarch64-elf-gcc" ]; then
mkdir build-aarch64
cd build-aarch64
../configure --prefix="$PREFIX" --target=aarch64-elf --disable-werror \
--disable-libssp --disable-libmudflap --with-newlib --without-headers \
--enable-languages=c,c++,objc,lto --enable-lto --with-gmp="$PREFIX"
make all-gcc
make install-gcc
make all-target-libgcc
make install-target-libgcc
cd ..
fi
cd ..
fi
fi
if [ "$SKIP_CLEANUP" -eq 0 ]; then
find "$PREFIX/tmp" -mindepth 1 -maxdepth 1 -exec rm -rf {} \;
fi
echo "Toolchain installed in $PREFIX"