This repository has been archived by the owner on May 12, 2021. It is now read-only.
forked from USBhost/build-tools-gcc
-
Notifications
You must be signed in to change notification settings - Fork 33
/
build
executable file
·653 lines (552 loc) · 20.4 KB
/
build
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
#!/usr/bin/env bash
# shellcheck disable=SC1117
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Copyright (C) 2016-2018 USBhost
# Copyright (C) 2016-2017 Joe Maples
# Copyright (C) 2017-2018 Nathan Chancellor
#
# GCC cross compiler compilation script
###########
# SOURCES #
###########
# http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/ # credits for almost everything
# http://www.mpfr.org/
# https://gmplib.org/
# http://www.multiprecision.org/
# http://isl.gforge.inria.fr/
# https://www.gnu.org/software/binutils/
# https://www.gnu.org/software/libc/
# https://www.kernel.org/
# https://git.linaro.org/toolchain/gcc.git # linaro and gnu
#############
# FUNCTIONS #
#############
# Easy alias for escape codes
function echo() {
command echo -e "${@}"
}
# Help menu function
function help_menu() {
echo
echo "${BOLD}OVERVIEW:${RST} Build a gcc toolchain"
echo
echo "${BOLD}USAGE:${RST} ${0} <options>"
echo
echo "${BOLD}EXAMPLE:${RST} ${0} -a arm64 -s linaro -v 7"
echo
echo "${BOLD}REQUIRED PARAMETERS:${RST}"
echo " -a | --arch: Possible values: arm, arm64, i686, or x86_64. This is the toolchain's target architecture."
echo " -s | --source: Possible values: gnu or linaro. This is the GCC source (GNU official vs. Linaro fork)."
echo " -v | --version: Possible values: (4, 5, 6, 7, 8*, and 9* [*GNU only]). This is the GCC version to build."
echo
echo "${BOLD}OPTIONAL PARAMETERS:${RST}"
echo " -f | --full-src: Download full git repos instead of shallow clones"
echo " -nt | --no-tmpfs: Do not use tmpfs for building (useful if you don't have much RAM)."
echo " -nu | --no-update: Do not update the downloaded components before building (useful if you have slow internet)."
echo " -p | --package: Possible values: gz or xz. Compresses toolchain after build."
echo " -t | --tarballs: Use tarballs for binutils, ISL, and, GCC"
echo " -V | --verbose: Make script print all output, not just errors and the ending information"
echo
}
# Prints a formatted header to let the user know what's being done
function header() {
[[ "${*}" =~ "--no-first-echo" ]] || echo
# shellcheck disable=SC2034
echo "${RED}====$(for i in $(seq ${#1}); do echo "=\c"; done)===="
echo "== ${1} =="
# shellcheck disable=SC2034
echo "====$(for i in $(seq ${#1}); do echo "=\c"; done)====${RST}"
[[ "${*}" =~ "--no-second-echo" ]] || echo
}
# Prints an error in bold red
function die() {
[[ -z ${VERBOSE} ]] && exec 1>&5 2>&6
echo ""
echo "${RED}${1}${RST}"
[[ "${*}" =~ "-n" ]] && echo
[[ "${*}" =~ "-h" ]] && help_menu
exit
}
# Prints a warning in bold yellow
function warn() {
echo ""
echo "${YLW}${1}${RST}"
[[ "${*}" =~ "-n" ]] && echo
}
# Formats the time for the end
function format_time() {
MINS=$(((${2} - ${1}) / 60))
SECS=$(((${2} - ${1}) % 60))
if [[ ${MINS} -ge 60 ]]; then
HOURS=$((MINS / 60))
MINS=$((MINS % 60))
fi
if [[ ${HOURS} -eq 1 ]]; then
TIME_STRING+="1 HOUR, "
elif [[ ${HOURS} -ge 2 ]]; then
TIME_STRING+="${HOURS} HOURS, "
fi
if [[ ${MINS} -eq 1 ]]; then
TIME_STRING+="1 MINUTE"
else
TIME_STRING+="${MINS} MINUTES"
fi
if [[ ${SECS} -eq 1 && -n ${HOURS} ]]; then
TIME_STRING+=", AND 1 SECOND"
elif [[ ${SECS} -eq 1 && -z ${HOURS} ]]; then
TIME_STRING+=" AND 1 SECOND"
elif [[ ${SECS} -ne 1 && -n ${HOURS} ]]; then
TIME_STRING+=", AND ${SECS} SECONDS"
elif [[ ${SECS} -ne 1 && -z ${HOURS} ]]; then
TIME_STRING+=" AND ${SECS} SECONDS"
fi
echo "${TIME_STRING}"
}
# Check if user needs to enter sudo password or not
function check_sudo() {
echo
echo "Checking if sudo is available, please enter your password if a prompt appears!"
if ! sudo -v 2>/dev/null; then
warn "Sudo is not available! Disabling the option for tmpfs..." -n
NO_TMPFS=true
fi
}
# Unmount tmpfs
function unmount_tmpfs() {
if [[ -z ${NO_TMPFS} ]]; then
sudo umount -f build-glibc 2>/dev/null
sudo umount -f build-gcc 2>/dev/null
sudo umount -f build-binutils 2>/dev/null
fi
}
# git clone wrapper
function git_clone() {
git clone ${DEPTH_FLAG:+"--depth=1"} "${@}"
}
# git fetch wrapper
function git_fetch() {
git fetch ${DEPTH_FLAG:+"--depth=1"} "${@}"
}
# Initial setup
function setup_variables() {
# Colors
BOLD="\033[1m"
RED="\033[01;31m"
RST="\033[0m"
YLW="\033[01;33m"
# Configuration variables
CONFIGURATION=( "--disable-multilib" "--disable-werror" )
JOBS="-j$(($(nproc --all) + 1))"
# Binary versions
BINUTILS_git="binutils-2_31-branch"
BINUTILS_tar="2.31"
GMP="gmp-6.1.2"
MPFR="mpfr-4.0.1"
MPC="mpc-1.1.0"
ISL="isl-0.20"
GLIBC="glibc-2.28"
LINUX="4.18"
# Start of script
START=$(date +%s)
}
# Parse parameters
function parse_parameters() {
while [[ ${#} -ge 1 ]]; do
case "${1}" in
# REQUIRED FLAGS
"-a"|"--arch") shift && ARCH=${1} ;;
"-s"|"--source") shift && SOURCE=${1} ;;
"-v"|"--version") shift && VERSION=${1} ;;
# OPTIONAL FLAGS
"-f"|"--full-src") FULL_SOURCE=true ;;
"-nt"|"--no-tmpfs") NO_TMPFS=true ;;
"-nu"|"--no-update") NO_UPDATE=true ;;
"-p"|"--package") shift && COMPRESSION=${1} ;;
"-t"|"--tarballs") TARBALLS=true ;;
"-V"|"--verbose") VERBOSE=true ;;
# HELP!
"-h"|"--help") help_menu; exit ;;
esac
shift
done
[[ -z ${NO_TMPFS} ]] && check_sudo
[[ -z ${VERBOSE} ]] && exec 6>&2 5>&1 &>/dev/null
[[ -z ${FULL_SOURCE} ]] && DEPTH_FLAG=true
# Default values
case "${ARCH}" in
"arm") TARGET="arm-linux-gnueabi" ;;
"arm64") TARGET="aarch64-linux-gnu" ;;
"i686") TARGET="i686-linux-gnu" ;;
"x86_64") TARGET="x86_64-linux-gnu" ;;
*) die "Absent or invalid arch specified!" -h ;;
esac
if [[ -z ${TARBALLS} ]]; then
# Set GCC branch based on version and Linaro or not
case "${SOURCE}:${VERSION}" in
"gnu:4") die "Will not build, Use Linaro instead" ;;
"gnu:5") GCC=gcc-5-branch
ISL="isl-0.17.1" ;;
"gnu:6") GCC=gcc-6-branch ;;
"gnu:7") GCC=gcc-7-branch ;;
"gnu:8") GCC=gcc-8-branch ;;
"gnu:9") GCC=master ;;
"linaro:4") GCC=linaro-local/releases/linaro-4.9-2017.01
ISL="isl-0.17.1" ;;
"linaro:5") GCC=linaro-local/gcc-5-integration-branch
ISL="isl-0.17.1" ;;
"linaro:6") GCC=linaro-local/gcc-6-integration-branch ;;
"linaro:7") GCC=linaro-local/gcc-7-integration-branch ;;
"linaro:8") die "There's no such thing as Linaro 8.x Clannad..." -h ;;
"linaro:9") die "There's no such thing as Linaro 9.x Clannad..." -h ;;
*) die "Absent or invalid GCC version or source specified!" -h ;;
esac
else
# Set GCC branch based on version and Linaro or not
case "${SOURCE}:${VERSION}" in
"gnu:4") die "Will not build, Use Linaro instead" ;;
"gnu:5") GCC=gcc-5.5.0
ISL="isl-0.17.1" ;;
"gnu:6") GCC=gcc-6.4.0 ;;
"gnu:7") GCC=gcc-7.3.0 ;;
"gnu:8") GCC=gcc-8.2.0 ;;
"gnu:9") die "GCC 9.0 is currently a WIP so there is no tarball to download! Either use the git repo or choose a new version..." ;;
"linaro:4") GCC=linaro-4.9-2017.01
ISL="isl-0.17.1" ;;
"linaro:5") GCC=linaro-5.5-2017.10
ISL="isl-0.17.1" ;;
"linaro:6") GCC=linaro-snapshot-6.4-2018.06 ;;
"linaro:7") GCC=linaro-snapshot-7.3-2018.06 ;;
"linaro:8") die "There's no such thing as Linaro 8.x Clannad..." -h ;;
"linaro:9") die "There's no such thing as Linaro 9.x Clannad..." -h ;;
*) die "Absent or invalid GCC version or source specified!" -h ;;
esac
fi
}
# Clean up from a previous compilation
function clean_up() { #FIXME: we dont need to remove everything everytime.
header "CLEANING UP"
unmount_tmpfs
git clean -fxdq -e sources -e prebuilts
find . -maxdepth 1 -type l -exec rm -rf {} \; #FIXME
if [[ -d binutils ]] ||
[[ -d build-binutils ]] ||
[[ -d build-gcc ]] ||
[[ -d build-glibc ]] ||
[[ -d gcc ]] ||
[[ -d linux ]] ||
[[ -f ${TARGET} ]] ||
[[ $(for FILE in *.tar.*; do if [[ -f "${FILE}" ]]; then echo "true"; break; else echo "false"; fi done) = "true" ]]; then
die "Clean up failed! Aborting. Try checking that you have proper permissions to delete files."
else
echo "Clean up successful!"
fi
}
function build_binaries() {
ROOT=${PWD}
PREBUILTS_BIN=${ROOT}/prebuilts/bin
mkdir -p sources
if [[ ! -f ${PREBUILTS_BIN}/axel ]]; then
AXEL=${ROOT}/sources/axel
[[ ! -d ${AXEL} ]] && git -C "$(dirname "${AXEL}")" clone --depth=1 https://github.com/axel-download-accelerator/axel
git -C "${AXEL}" clean -fxdq
git -C "${AXEL}" pull
(
cd "${AXEL}" || die "Issue with cloning axel source!"
./autogen.sh
./configure --prefix="$(dirname "${PREBUILTS_BIN}")"
make ${JOBS} || die "Error building axel!"
make ${JOBS} install || die "Error installing axel!"
)
fi
if [[ ! -f ${PREBUILTS_BIN}/pigz ]]; then
PIGZ=${ROOT}/sources/pigz
[[ ! -d ${PIGZ} ]] && git -C "$(dirname "${PIGZ}")" clone --depth=1 https://github.com/madler/pigz
git -C "${PIGZ}" clean -fxdq
git -C "${PIGZ}" pull
make -C "${PIGZ}" ${JOBS} pigz || die "Error building pigz!"
mv "${PIGZ}"/pigz "${PREBUILTS_BIN}"
fi
if [[ ! -f ${PREBUILTS_BIN}/pxz ]]; then
PXZ=${ROOT}/sources/pxz
[[ ! -d ${PXZ} ]] && git -C "$(dirname "${PXZ}")" clone --depth=1 https://github.com/jnovy/pxz
git -C "${PXZ}" clean -fxdq
git -C "${PXZ}" pull
make -C "${PXZ}" ${JOBS} pxz || die "Error building pxz!"
mv "${PXZ}"/pxz "${PREBUILTS_BIN}"
fi
export PATH=${PREBUILTS_BIN}:${PATH}
}
function download_sources() {
cd sources || die "Failed to create sources directory!"
if [[ ! -f ${MPFR}.tar.xz ]]; then
header "DOWNLOADING MPR"
axel https://www.mpfr.org/mpfr-current/${MPFR}.tar.xz
fi
if [[ ! -f ${GMP}.tar.xz ]]; then
header "DOWNLOADING GMP"
axel https://ftp.gnu.org/gnu/gmp/${GMP}.tar.xz
fi
if [[ ! -f ${MPC}.tar.gz ]]; then
header "DOWNLOADING MPC"
axel https://ftp.gnu.org/gnu/mpc/${MPC}.tar.gz
fi
if [[ ! -f ${GLIBC}.tar.xz ]]; then
header "DOWNLOADING GLIBC"
axel https://ftp.gnu.org/gnu/glibc/${GLIBC}.tar.xz
fi
if [[ ! -f linux-${LINUX}.tar.xz ]]; then
header "DOWNLOADING LINUX KERNEL"
axel https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-${LINUX}.tar.xz
fi
if [[ -z ${TARBALLS} ]]; then
if [[ ! -d binutils ]]; then
header "DOWNLOADING BINUTILS"
git_clone https://git.linaro.org/toolchain/binutils-gdb.git binutils -b ${BINUTILS_git}
fi
if [[ ! -d isl ]]; then
header "DOWNLOADING ISL"
git_clone git://repo.or.cz/isl.git -b ${ISL}
fi
if [[ ! -d gcc ]]; then
header "DOWNLOADING GCC"
git_clone https://git.linaro.org/toolchain/gcc.git -b ${GCC}
fi
else
if [[ ! -f binutils-${BINUTILS_tar}.tar.xz ]]; then
header "DOWNLOADING BINUTILS"
axel https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_tar}.tar.xz
fi
if [[ ! -f ${ISL}.tar.xz ]]; then
header "DOWNLOADING ISL ${ISL} FOR GCC ${VERSION}"
axel http://isl.gforge.inria.fr/${ISL}.tar.xz
fi
if [[ ${SOURCE} == "gnu" ]]; then
if [[ ! -f ${GCC}.tar.${EXT:-xz} ]]; then
header "DOWNLOADING GCC"
axel https://mirrors.kernel.org/gnu/gcc/${GCC}/${GCC}.tar."${EXT:-gz}"
fi
GCC_TAR=${GCC}.tar.${EXT:-gz}
else
if [[ ! -f gcc-${GCC}.tar.gz ]]; then
header "DOWNLOADING GCC"
axel https://git.linaro.org/toolchain/gcc.git/snapshot/gcc-${GCC}.tar.gz
fi
GCC_TAR=gcc-${GCC}.tar.gz
fi
fi
}
function extract() {
case "${1}" in
*.gz) UNPACK=pigz ;;
*.xz) UNPACK=pxz ;;
esac
mkdir -p "${2}"
${UNPACK} -d < "${1}" | tar -xC "${2}" --strip-components=1
}
# Extract tarballs to their proper locations
function extract_sources() {
header "EXTRACTING DOWNLOADED TARBALLS"
extract ${MPFR}.tar.xz ../${MPFR}
extract ${GMP}.tar.xz ../${GMP}
extract ${MPC}.tar.gz ../${MPC}
extract ${GLIBC}.tar.xz ../${GLIBC}
extract linux-${LINUX}.tar.xz ../linux
if [[ -n ${TARBALLS} ]]; then
extract binutils-${BINUTILS_tar}.tar.xz ../binutils
extract ${ISL}.tar.xz ../${ISL}
extract ${GCC_TAR} ../gcc
fi
}
# Update git repos
function update_repos() {
if [[ -z ${NO_UPDATE} && -z ${TARBALLS} ]]; then
header "UPDATING SOURCES"
(
cd isl || die "ISL did not get cloned properly!"
git remote update
git checkout ${ISL}
git reset --hard HEAD
./autogen.sh
)
(
cd binutils || die "binutils did not get cloned properly!"
[[ -n ${FULL_SOURCE} ]] && BRANCH=origin/${BINUTILS_git} || BRANCH=FETCH_HEAD
git_fetch origin ${BINUTILS_git}
git checkout ${BINUTILS_git} || git checkout -b ${BINUTILS_git} ${BRANCH}
git reset --hard ${BRANCH}
)
(
cd gcc || die "GCC did not get cloned properly!"
[[ -n ${FULL_SOURCE} ]] && BRANCH=origin/${GCC} || BRANCH=FETCH_HEAD
git_fetch origin ${GCC}
git checkout ${GCC} || git checkout -b ${GCC} ${BRANCH}
git reset --hard ${BRANCH}
)
else
if [[ -d isl ]]; then
(
cd isl || die "ISL did not get downloaded properly!"
./autogen.sh
)
fi
fi
cd ..
[[ ! -d linux ]] && ln -s sources/linux linux
[[ ! -d binutils ]] && ln -s sources/binutils binutils
[[ ! -d gcc ]] && ln -s sources/gcc gcc
}
# Setup source folders and build folders
function setup_env() {
INSTALL=${ROOT}/${TARGET}
export PATH=${INSTALL}/bin:${PATH}
[[ ! -d gcc ]] && die "GCC source is missing! Please check your connection and rerun the script!" -h
mkdir build-glibc
mkdir build-gcc
mkdir build-binutils
if [[ -z ${NO_TMPFS} ]]; then
sudo mount -t tmpfs -o rw none build-glibc
sudo mount -t tmpfs -o rw none build-gcc
sudo mount -t tmpfs -o rw none build-binutils
fi
cd gcc || die "GCC folder does not exit!"
ln -s -f "${ROOT}/${MPFR}" mpfr
ln -s -f "${ROOT}/${GMP}" gmp
ln -s -f "${ROOT}/${MPC}" mpc
if [[ -n ${TARBALLS} ]]; then
ln -s -f "${ROOT}/${ISL}" isl
else
ln -s -f "${ROOT}/isl" isl
fi
cd ..
if [[ -z ${VERBOSE} ]]; then
exec 1>&5 2>&6
header "BUILDING TOOLCHAIN"
exec 6>&2 5>&1 &>/dev/null
fi
}
# Build binutils
function build_binutils() {
header "BUILDING BINUTILS"
cd build-binutils || die "binutils build folder does not exist!"
../binutils/configure "${CONFIGURATION[@]}" \
--target=${TARGET} \
--prefix="${INSTALL}" \
--disable-gdb
make ${JOBS} || die "Error while building binutils!" -n
make install ${JOBS} || die "Error while installing binutils!" -n
}
# Make Linux kernel headers
function build_headers() {
header "MAKING LINUX HEADERS"
cd ../linux || die "Linux kernel folder does not exist!"
make ARCH="${ARCH}" \
INSTALL_HDR_PATH="${INSTALL}/${TARGET}" \
headers_install ${JOBS} || die "Error while building/installing Linux headers!" -n
}
# Build GCC
function build_gcc() {
header "MAKING GCC"
cd ../build-gcc || die "GCC build folder does not exist!"
../gcc/configure "${CONFIGURATION[@]}" \
--enable-languages=c \
--target=${TARGET} \
--prefix="${INSTALL}"
make all-gcc ${JOBS} || die "Error while building gcc!" -n
make install-gcc ${JOBS} || die "Error while installing gcc!" -n
if [[ ${ARCH} = "x86_64" ]]; then
make all-target-libgcc ${JOBS} || die "Error while installing libgcc for host!" -n
make install-target-libgcc ${JOBS} || die "Error while installing libgcc for target!" -n
fi
}
# Build glibc
function build_glibc() {
header "MAKING GLIBC"
cd ../build-glibc || die "glibc build folder does not exist!"
../${GLIBC}/configure --prefix="${INSTALL}/${TARGET}" \
--build="${MACHTYPE}" \
--host=${TARGET} \
--target=${TARGET} \
--with-headers="${INSTALL}/${TARGET}/include" \
"${CONFIGURATION[@]}" libc_cv_forced_unwind=yes
make install-bootstrap-headers=yes install-headers ${JOBS} || die "Error installing headers for glibc!" -n
make csu/subdir_lib ${JOBS} || die "Error while making subdir_lib for glibc!" -n
install csu/crt1.o csu/crti.o csu/crtn.o "${INSTALL}/${TARGET}/lib"
${TARGET}-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o "${INSTALL}/${TARGET}/lib/libc.so"
touch "${INSTALL}/${TARGET}/include/gnu/stubs.h"
if [[ ${ARCH} = "x86_64" || ${ARCH} = "i686" ]]; then
make ${JOBS} || die "Error while building glibc for the host!" -n
make install ${JOBS} || die "Error while installing glibc for the host!" -n
else
cd ../build-gcc || die "GCC build folder does not exist!"
make all-target-libgcc ${JOBS} || die "Error while building libgcc for target!" -n
make install-target-libgcc ${JOBS} || die "Error while installing libgcc for target!" -n
cd ../build-glibc || die "glibc build folder does not exist!"
make ${JOBS} || die "Error while building glibc for target" -n
make install ${JOBS} || die "Error while installing glibc for target" -n
fi
}
# Install GCC
function install_gcc() {
header "INSTALLING GCC"
cd ../build-gcc || die "GCC build folder does not exist!"
make all ${JOBS} || die "Error while compiling final toolchain!" -n
make install ${JOBS} || die "Error while installing final toolchain!" -n
cd ..
}
# Package toolchain
function package_tc() {
if [[ -n ${COMPRESSION} ]]; then
PACKAGE=${TARGET}-${VERSION}.x-${SOURCE}-$(TZ=UTC date +%Y%m%d).tar.${COMPRESSION}
header "PACKAGING TOOLCHAIN"
echo "Target file: ${PACKAGE}"
case "${COMPRESSION}" in
"gz")
echo "Packaging with GZIP..."
GZ_OPT=-9 tar -c --use-compress-program=pigz -f "${PACKAGE}" ${TARGET} ;;
"xz")
echo "Packaging with XZ..."
XZ_OPT=-9 tar -c --use-compress-program=pxz -f "${PACKAGE}" ${TARGET} ;;
*)
die "Invalid compression specified... skipping" ;;
esac
fi
}
# Ending information
function ending_info() {
END=$(date +%s)
[[ -z ${VERBOSE} ]] && exec 1>&5 2>&6
if [[ -e ${TARGET}/bin/${TARGET}-gcc ]]; then
header "BUILD SUCCESSFUL" ${VERBOSE:-"--no-first-echo"}
echo "${BOLD}Script duration:${RST} $(format_time "${START}" "${END}")"
echo "${BOLD}GCC version:${RST} $(${TARGET}/bin/${TARGET}-gcc --version | head -n 1)"
if [[ -n ${COMPRESSION} ]] && [[ -e ${PACKAGE} ]]; then
echo "${BOLD}File location:${RST} $(pwd)/${PACKAGE}"
echo "${BOLD}File size:${RST} $(du -h "${PACKAGE}" | awk '{print $1}')"
else
echo "${BOLD}Toolchain location:${RST} $(pwd)/${TARGET}"
fi
else
header "BUILD FAILED"
fi
# Alert to script end
echo "\a"
}
setup_variables
parse_parameters "${@}"
trap 'unmount_tmpfs; die "Manually aborted!" -n' SIGINT SIGTERM
trap 'unmount_tmpfs' EXIT
clean_up
build_binaries
download_sources
extract_sources
update_repos
setup_env
build_binutils
build_headers
build_gcc
build_glibc
install_gcc
package_tc
ending_info