This repository has been archived by the owner on Mar 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-aarch64-toolchain.sh
executable file
·240 lines (212 loc) · 5.56 KB
/
make-aarch64-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
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
#!/bin/bash
set -e
BUILD_TOP=`pwd`
NCPUS=`getconf _NPROCESSORS_ONLN`
die() {
echo $@ >&2
exit 1
}
edo() {
echo $@
"$@" || die "$@ failed"
}
get_src() {
# Get all the component sources
edo wget --quiet http://ftpmirror.gnu.org/binutils/binutils-2.24.tar.gz
edo wget --quiet http://ftpmirror.gnu.org/gcc/gcc-5.3.0/gcc-5.3.0.tar.gz
edo wget --quiet http://ftpmirror.gnu.org/glibc/glibc-2.17.tar.xz
edo wget --quiet --no-check-certificate https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.7.10.tar.xz
edo wget --quiet http://ftpmirror.gnu.org/mpfr/mpfr-3.1.1.tar.xz
edo wget --quiet http://ftpmirror.gnu.org/gmp/gmp-5.0.5.tar.xz
edo wget --quiet http://ftpmirror.gnu.org/mpc/mpc-1.0.1.tar.gz
# for f in *.tar*; do edo tar xf $f; done
for f in *.tar*; do
echo $f | sed 's/\.tar\..*//g'
fbase=$(echo $f | sed 's/\.tar\..*//g')
echo $fbase
if [[ ! -d "$fbase" ]]; then
edo tar xf $f;
fi
done
}
apply_patches() {
# Apply patches and set up support libraries
edo pushd binutils-2.24
for f in $BUILD_TOP/patches/binutils-2.24/*; do edo patch -p1 < $f; done
edo popd
edo pushd gcc-5.3.0
edo ln -s $BUILD_TOP/gmp-5.0.5 gmp
edo ln -s $BUILD_TOP/mpfr-3.1.1 mpfr
edo ln -s $BUILD_TOP/mpc-1.0.1 mpc
for f in $BUILD_TOP/patches/gcc-5.3.0/*; do edo patch -p1 < $f; done
edo popd
}
set_env() {
# Set up envrionment variables
INSTALL_PATH=$BUILD_TOP/install
TRIPLET=aarch64-linux-gnu
SYSROOT=$INSTALL_PATH/$TRIPLET/sysroot
PATH=$INSTALL_PATH/bin:$PATH
}
build_binutils() {
# Build binutils
edo mkdir build-binutils
edo pushd build-binutils/
edo $BUILD_TOP/binutils-2.24/configure \
--prefix=$INSTALL_PATH \
--target=$TRIPLET \
--with-sysroot=$SYSROOT \
--enable-plugins \
--enable-gold \
--enable-lto \
--enable-shared \
--disable-multilib \
--disable-werror
edo make -j${NCPUS}
edo make install
edo popd
}
install_linux_headers() {
# Set up Linux headers
edo pushd linux-3.7.10
edo make ARCH=arm64 INSTALL_HDR_PATH=$SYSROOT/usr headers_install
edo popd
}
build_gcc_stage1() {
# Build 1st stage gcc
edo mkdir build-gcc1
edo pushd build-gcc1
$BUILD_TOP/gcc-5.3.0/configure \
LDFLAGS=-static \
--prefix=$INSTALL_PATH \
--target=$TRIPLET \
--enable-languages=c,c++,fortran \
--enable-theads=posix \
--enable-shared \
--enable-lto \
--enable-gold \
--disable-libsanitizer \
--disable-gnu-indirect-function \
--disable-gnu-unique-object \
--disable-multilib \
--with-sysroot=$SYSROOT
edo make -j${NCPUS} all-gcc LIMITS_H_TEST=true
edo make install-gcc
edo popd
}
build_glibc_stage1() {
# Build 1st stage glibc
edo mkdir build-glibc1
edo pushd build-glibc1
edo mkdir -p $SYSROOT/usr/lib
$BUILD_TOP/glibc-2.17/configure \
--prefix=$SYSROOT/usr \
--with-headers=$SYSROOT/usr/include \
--build=$MACHTYPE \
--host=$TRIPLET \
--target=$TRIPLET \
--enable-add-ons=nptl,$BUILD_TOP/glibc-2.17/ports \
--with-tls \
--disable-nscd \
--disable-stackguard-randomization \
CC=$TRIPLET-gcc \
libc_cv_forced_unwind=yes
edo make install-bootstrap-headers=yes install-headers
edo make -j${NCPUS} csu/subdir_lib
edo install csu/crt1.o csu/crti.o csu/crtn.o $SYSROOT/usr/lib
edo $TRIPLET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $SYSROOT/usr/lib/libc.so
edo touch $SYSROOT/usr/include/gnu/stubs.h
edo popd
}
build_gcc_support_lib() {
# Build compiler support library
edo mkdir build-gcc2
edo pushd build-gcc2
$BUILD_TOP/gcc-5.3.0/configure \
LDFLAGS=-static \
--prefix=$INSTALL_PATH \
--target=$TRIPLET \
--enable-languages=c,c++,fortran \
--enable-theads=posix \
--enable-shared \
--disable-libsanitizer \
--disable-gnu-indirect-function \
--disable-gnu-unique-object \
--disable-multilib \
--with-sysroot=$SYSROOT
edo make -j${NCPUS} all-target-libgcc
edo make install-target-libgcc
edo popd
}
build_final_glibc() {
# Finish glibc
edo mkdir build-glibc2
edo pushd build-glibc2
$BUILD_TOP/glibc-2.17/configure \
--prefix=/usr \
--with-headers=$SYSROOT/usr/include \
--build=$MACHTYPE \
--host=$TRIPLET \
--target=$TRIPLET \
--enable-add-ons=nptl,$BUILD_TOP/glibc-2.17/ports \
--with-tls \
--disable-nscd \
--disable-stackguard-randomization \
CC=$TRIPLET-gcc
edo make -j${NCPUS}
edo make install install_root=$SYSROOT
edo popd
}
build_final_gcc() {
# Build libstdc++
edo mkdir build-gcc3
edo pushd build-gcc3
$BUILD_TOP/gcc-5.3.0/configure \
LDFLAGS=-static \
--prefix=$INSTALL_PATH \
--target=$TRIPLET \
--enable-languages=c,c++,fortran \
--enable-theads=posix \
--enable-shared \
--enable-lto \
--enable-gold \
--disable-libsanitizer \
--disable-gnu-indirect-function \
--disable-gnu-unique-object \
--disable-multilib \
--with-sysroot=$SYSROOT
edo make -j${NCPUS}
edo make install
edo popd
}
echo "Downloading sources"
edo get_src > get_src.log 2>&1
echo "Done"
echo "Applying patches"
edo apply_patches > apply_patches.log 2>&1
echo "Done"
echo "Set environment"
edo set_env
echo "Done"
echo "Build binutils"
edo build_binutils > build_binutils.log 2>&1
echo "Done"
echo "Install Linux headers"
edo install_linux_headers > install_linux_headers.log 2>&1
echo "Done"
echo "Build GCC stage1"
edo build_gcc_stage1 > build_gcc_stage1.log 2>&1
echo "Done"
echo "Build Glibc stage1"
edo build_glibc_stage1 > build_glibc_stage1.log 2>&1
echo "Done"
echo "Build GCC support lib"
edo build_gcc_support_lib > build_gcc_support_lib.log 2>&1
echo "Done"
echo "Build final Glibc"
edo build_final_glibc > build_final_glibc.log 2>&1
echo "Done"
echo "Build final GCC"
edo build_final_gcc > build_final_gcc.log 2>&1
echo "Done"
echo "Success!"