forked from hermit-os/hermit-gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toolchain.sh
executable file
·206 lines (179 loc) · 4.39 KB
/
toolchain.sh
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
#!/bin/bash
# script to build Hermit's toolchain
#
# $1 = specifies the target architecture
# exit when any command fails
set -e
SUPPORTED_TARGETS="x86_64-hermit aarch64-hermit riscv64-hermit"
TARGET=$1
if [ -z "$TARGET" ]; then
echo "Usage: $0 <target>"
exit 1
fi
if ! echo "$SUPPORTED_TARGETS" | grep -q "$TARGET"; then
echo "Unsupported target: $TARGET"
echo "Supported targets: $SUPPORTED_TARGETS"
exit 1
fi
ARCH=
case "$TARGET" in
x86_64-*)
ARCH=x86_64
;;
aarch64-*)
ARCH=aarch64
;;
riscv64-*)
ARCH=riscv64
;;
default)
echo "Unable to parse a supported architecture from $TARGET"
exit 1
;;
esac
NJOBS=-j"$(nproc)"
SCRIPTDIR="$(dirname "$0")"
HERE="$(cd "$SCRIPTDIR" && pwd)"
PREFIX="$HERE/prefix"
BUILDDIR="$HERE/build"
PATH=$PATH:$PREFIX/bin
export CFLAGS="-w"
export CXXFLAGS="-w"
# -O3 to enable optimizations
# -fPIC to enable position-independent code
# -fpermissive to downgrade the implicit declaration errors to warnings (occurs when compiling newlib with GCC 14)
# -ggdb to enable debugging information
export CFLAGS_FOR_TARGET="-ggdb -O3 -fPIC -fpermissive"
export CXXFLAGS_FOR_TARGET="-ggdb -O3 -fPIC -fpermissive"
case "$TARGET" in
x86_64-*)
export CFLAGS_FOR_TARGET+=" -m64"
export CXXFLAGS_FOR_TARGET+=" -m64"
;;
esac
echo "Build Hermit toolchain (target: $TARGET, arch: $ARCH, jobs: $NJOBS, prefix: $PREFIX)."
mkdir -p "$BUILDDIR"
echo
echo "*********************"
echo "* Building binutils *"
echo "*********************"
echo
if [ ! -d "$BUILDDIR/binutils" ]; then
mkdir -p "$BUILDDIR/binutils"
pushd "$BUILDDIR/binutils"
"$HERE/binutils/configure" \
--target="$TARGET" \
--prefix="$PREFIX" \
--with-sysroot \
--disable-werror \
--disable-multilib \
--disable-nls \
--disable-sim \
--enable-tls \
--enable-lto \
--enable-plugin
make "$NJOBS" -O
make install
popd
fi
echo
echo "************************"
echo "* Building stage 1 GCC *"
echo "************************"
echo
if [ ! -d "$BUILDDIR/gcc-1" ]; then
mkdir -p "$BUILDDIR/gcc-1"
pushd "$BUILDDIR/gcc-1"
"$HERE/gcc/configure" \
--target="$TARGET" \
--prefix="$PREFIX" \
--without-headers \
--disable-multilib \
--with-isl \
--enable-languages=c,c++,lto \
--disable-nls \
--disable-libssp \
--disable-libgomp \
--enable-threads=posix \
--enable-tls \
--enable-lto \
--disable-symvers
make "$NJOBS" -O all-gcc
make install-gcc
popd
fi
echo
echo "**************************"
echo "* Building Hermit kernel *"
echo "**************************"
echo
mkdir -p "$BUILDDIR/hermit"
pushd "$HERE/hermit"
HERMIT_LOG_LEVEL_FILTER=Debug cargo run --package=xtask build --arch "$ARCH" --no-default-features --features pci,smp,acpi,newlib,tcp,dhcpv4 --target-dir "$BUILDDIR/hermit"
popd
mkdir -p "$PREFIX/$TARGET/lib"
cp "$BUILDDIR/hermit/$ARCH/debug/libhermit.a" "$PREFIX/$TARGET/lib/libhermit.a"
echo
echo "*****************************"
echo "* Building Newlib C library *"
echo "*****************************"
echo
if [ ! -d "$BUILDDIR/newlib" ]; then
mkdir -p "$BUILDDIR/newlib"
pushd "$BUILDDIR/newlib"
"$HERE/newlib/configure" \
--target="$TARGET" \
--prefix="$PREFIX" \
--disable-multilib \
--enable-lto \
--enable-newlib-io-c99-formats \
--enable-newlib-multithread
make -O "$NJOBS"
make install
# Newlib overwrites crt0.o with the one from libgloss,
# so we need to restore it manually
mv -f "$BUILDDIR/newlib/$TARGET/newlib/crt0.o" "$PREFIX/$TARGET/lib/crt0.o"
popd
fi
echo
echo "***************************************"
echo "* Building pthread-embedded C library *"
echo "***************************************"
echo
if [ ! -d "$BUILDDIR/pte" ]; then
cp -r "$HERE/pte" "$BUILDDIR"
pushd "$BUILDDIR/pte"
"$BUILDDIR/pte/configure" \
--target="$TARGET" \
--prefix="$PREFIX"
make -O "$NJOBS"
make install
popd
fi
echo
echo "************************"
echo "* Building stage 2 GCC *"
echo "************************"
echo
if [ ! -d "$BUILDDIR/gcc-2" ]; then
mkdir -p "$BUILDDIR/gcc-2"
pushd "$BUILDDIR/gcc-2"
"$HERE/gcc/configure" \
--target="$TARGET" \
--prefix="$PREFIX" \
--with-newlib \
--with-isl \
--disable-multilib \
--without-libatomic \
--enable-languages=c,c++,lto \
--disable-nls \
--enable-libssp \
--enable-threads=posix \
--enable-libgomp \
--enable-tls \
--enable-lto \
--disable-symver
make -O "$NJOBS"
make install
popd
fi