blob: e6edfd8cf7e23bdf9745aa8355c6ba2d9be40924 (
plain)
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
#!/bin/bash
BINUTILS=2.46.0
GCC_VERSION=16.1.0
GLIBC_VERSION=2.43
DISTRO_SPEC="x221e"
DESTDIR_STAGE0="${HOME}/opt/cross"
SYSROOT_LOC="${HOME}/opt/cross/"
HEADERS_LOC="${HOME}/opt/cross/usr/include"
BINUTILS_CONF_DIR="binutils-conf"
GLIBC_CONF_DIR="glibc-conf"
GCC_CONF_DIR="gcc-conf"
LIBSTDCXX_CONF_DIR="libstdc++-conf"
function binutils_configure {
CURRDIR=$(pwd)
compiler=$1
conf_flags=("${@:2}")
if [[ $compiler == "distro" ]]
then
compiler=x86_64-${DISTRO_SPEC}-linux-gnu-gcc
elif [[ $compiler == "default" ]]
then
compiler=x86_64-linux-gnu-gcc
fi
mkdir "${BINUTILS_CONF_DIR}"
cd "${BINUTILS_CONF_DIR}"
CC=${compiler} ../binutils-${BINUTILS}/configure --prefix=/usr\
--disable-nls\
--disable-multilib\
--target=x86_64-${DISTRO_SPEC}-linux-gnu\
--with-sysroot=${SYSROOT_LOC}\
--disable-werror \
"${conf_flags[@]}"
if [ $? -eq 0 ]
then
echo "Succesfully configured binutils!"
else
echo "Configuration of binutils failed!!! With error code: " $?
exit 1
fi
cd ${CURRDIR}
}
function binutils_make {
echo "Building binutils"
arg=$1
CURRDIR=$(pwd)
if [[ ! -e "${BINUTILS_CONF_DIR}" || ! -d "${BINUTILS_CONF_DIR}" ]]
then
echo "Could not find the binutils-conf directory!"
exit 1
fi
cd "${BINUTILS_CONF_DIR}"
make ${arg} -j$(nproc)
if [ $? -ne 0 ]
then
echo "Could not '${arg}' binutils!!! With error code: " $?
exit 1
fi
echo "Succesfully completed '${arg}' in binutils!"
cd "${CURRDIR}"
}
function gcc_configure {
gcc_flags=("$@")
currdir=$(pwd)
mkdir "${GCC_CONF_DIR}"
cd "${GCC_CONF_DIR}"
echo -e "building gcc with flags: ${gcc_flags}"
../gcc-${GCC_VERSION}/configure\
--disable-multilib\
--disable-nls\
--target=x86_64-${DISTRO_SPEC}-linux-gnu\
--disable-werror\
"${gcc_flags[@]}"
if [ $? -eq 0 ]
then
echo -e "Succesfully configured gcc!"
else
echo -e "Configuration of binutils failed!!! With error code: " $?
exit 1
fi
cd "${currdir}"
}
function gcc_make {
arg=$1
currdir=$(pwd)
if [[ ! -e "${GCC_CONF_DIR}" || ! -d "${GCC_CONF_DIR}" ]]
then
echo -e "Could not find the binutils-conf directory!"
exit 1
fi
cd "${GCC_CONF_DIR}"
make ${arg} -j$(nproc)
if [ $? -eq 0 ]
then
echo -e "Succesfully built all-gcc!"
else
echo -e "make '${arg}' failed!!! With error code: " $?
exit 1
fi
cd "${currdir}"
}
function libstdc++_configure {
gcc_flags=("$@")
currdir=$(pwd)
mkdir "${LIBSTDCXX_CONF_DIR}"
cd "${LIBSTDCXX_CONF_DIR}"
echo -e "building libstdc++ with flags: ${gcc_flags}"
../gcc-${GCC_VERSION}/libstdc++-v3/configure\
--disable-multilib\
--disable-nls\
--target=x86_64-${DISTRO_SPEC}-linux-gnu\
--disable-werror\
--disable-libstdcxx-pch\
--with-gxx-include-dir=${DESTDIR_STAGE0}/usr/x86_64-${DISTRO_SPEC}-linux-gnu/include/${GCC-VERSION}/
"${gcc_flags[@]}"
if [ $? -eq 0 ]
then
echo -e "Succesfully configured libstdcxx!"
else
echo -e "Configuration of binutils failed!!! With error code: " $?
exit 1
fi
cd "${currdir}"
}
function libstdc++_make {
arg=$1
currdir=$(pwd)
if [[ ! -e "${LIBSTDCXX_CONF_DIR}" || ! -d "${LIBSTDCXX_CONF_DIR}" ]]
then
echo -e "Could not find the ${LIBSTDCXX_CONF_DIR} directory!"
exit 1
fi
cd "${GCC_CONF_DIR}"
make ${arg} -j$(nproc)
if [ $? -eq 0 ]
then
echo -e "Succesfully built '${arg}'!"
else
echo -e "make '${arg}' failed!!! With error code: " $?
exit 1
fi
cd "${currdir}"
}
function glibc_configure {
compiler="$1"
conf_flags=("${@:2}")
if [[ $compiler == "distro" ]]
then
compiler=x86_64-${DISTRO_SPEC}-linux-gnu-gcc
fi
currdir=$(pwd)
mkdir ${GLIBC_CONF_DIR}
cd ${GLIBC_CONF_DIR}
echo "rootsbindir=/usr/sbin" > configparms
CC=${compiler} ../glibc-${GLIBC_VERSION}/configure\
--host=x86_64-${DISTRO_SPEC}-linux-gnu\
--build=x86_64-linux-gnu\
--with-headers="${HEADERS_LOC}"\
--disable-werror\
--disable-ncsd\
libc_cv_slibdir=/usr/lib\
"${conf_flags[@]}"
cd "${currdir}"
}
function glibc_make {
arg=$1
currdir=$(pwd)
if [[ ! -e "${GLIBC_CONF_DIR}" || ! -d "${GLIBC_CONF_DIR}" ]]
then
echo -e "Could not find the '${GLIBC_CONF_DIR} directory!"
exit 1
fi
cd ${GLIBC_CONF_DIR}
make ${arg} -j$(nproc)
if [ $? -eq 0 ]
then
echo -e "Succesful '${arg}'!"
else
echo -e "make '${arg}' failed!!! With error code: " $?
exit 1
fi
cd "${currdir}"
}
function stage0_binutils {
rm -rf "${BINUTILS_CONF_DIR}"
conf_flags=(
--prefix=/usr
)
binutils_configure "default" "${conf_flags[@]}"
binutils_make
binutils_make "DESTDIR=${DESTDIR_STAGE0} install"
echo "Stage 0 binutils completed."
}
function stage0_gcc {
rm -rf "${GCC_CONF_DIR}"
conf_flags=(
--prefix=/tools
--with-sysroot="${SYSROOT_LOC}"
--with-glibc-version=2.43
--with-newlib
--without-headers
--enable-languages=c,c++
--disable-shared
--disable-threads
--disable-gcov
--disable-libgcov
--disable-libatomic
--disable-libgomp
--disable-libssp
--disable-libvtv
--disable-libstdcxx
--disable-libquadmath
--disable-libssp
)
gcc_configure "${conf_flags[@]}"
gcc_make all-gcc
gcc_make all-target-libgcc
gcc_make "DESTDIR=${DESTDIR_STAGE0} install-gcc"
gcc_make "DESTDIR=${DESTDIR_STAGE0} install-target-libgcc"
echo "Stage 0 gcc completed."
}
function stage0_glibc {
rm -rf "${GLIBC_CONF_DIR}"
conf_flags=(
--prefix=/usr
)
glibc_configure "distro" "${conf_flags[@]}"
glibc_make
glibc_make "DESTDIR=${DESTDIR_STAGE0} install"
}
function stage0 {
stage0_binutils
stage0_gcc
stage0_glibc
echo -e "Stage 0 completed."
}
function stage1_binutils {
rm -rf "${BINUTILS_CONF_DIR}"
conf_flags=(
--prefix=/usr
)
binutils_configure "distro" "${conf_flags[@]}"
binutils_make
binutils_make "DESTDIR=${DESTDIR_STAGE0} install"
}
function stage1_gcc {
rm -rf "${GCC_CONF_DIR}"
conf_flags=(
--prefix=/usr
--enable-languages=c,c++
--enable-threads=posix
--enable-default-pie
--enable-default-ssp
--enable-shared
--with-sysroot="${SYSROOT_LOC}"
--with-build-sysroot="${SYSROOT_LOC}"
--disable-libvtv
--disable-libssp
--disable-libgomp
--disable-quadmath
)
gcc_configure "${conf_flags[@]}"
gcc_make
gcc_make "DESTDIR=${DESTDIR_STAGE0} install"
}
function stage1_glibc {
rm -rf "${GLIBC_CONF_DIR}"
conf_flags=(
--prefix=/usr
)
glibc_configure "distro" "${conf_flags[@]}"
glibc_make
glibc_make "DESTDIR=${DESTDIR_STAGE0} install"
}
function stage1_libstdc++ {
libstdc++_configure "distro"
libstdc++_make
libstdc++_make "DESTDIR=${DESTDIR_STAGE0} install"
echo -e "Libstdc++-3 is installed!"
}
function stage1 {
stage1_gcc
stage1_glibc
stage1_libstdc++
echo -e "Cross compiler installed!"
}
case "$1" in
"stage0") stage0 ;;
"stage0-gcc") stage0_gcc ;;
"stage0-binutils") stage0_binutils ;;
"stage0-glibc") stage0_glibc ;;
"stage1") stage1 ;;
"stage1-gcc") stage1_gcc ;;
"stage1-binutils") stage1_binutils ;;
"stage1-glibc") stage1_glibc ;;
"stage1-libstdc++") stage1_libstdc++ ;;
"install") stage0 && stage1 ;;
*) echo -e "you must supply an argument!" && exit 1 ;;
esac
|