-
Notifications
You must be signed in to change notification settings - Fork 36
/
build-gcc.sh
executable file
·116 lines (104 loc) · 3.09 KB
/
build-gcc.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
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0
# Author: Vaisakh Murali
set -e
echo "*****************************************"
echo "* Building Bare-Metal Bleeding Edge GCC *"
echo "*****************************************"
# Declare the number of jobs to run simultaneously
JOBS=$(nproc --all)
# TODO: Add more dynamic option handling
while getopts a: flag; do
case "${flag}" in
a) arch=${OPTARG} ;;
*) echo "Invalid argument passed" && exit 1 ;;
esac
done
# TODO: Better target handling
case "${arch}" in
"arm") TARGET="arm-eabi" ;;
"arm64") TARGET="aarch64-elf" ;;
"arm64gnu") TARGET="aarch64-linux-gnu" ;;
"x86") TARGET="x86_64-elf" ;;
esac
export WORK_DIR="$PWD"
export PREFIX="$WORK_DIR/gcc-${arch}"
export PATH="$PREFIX/bin:/usr/bin/core_perl:$PATH"
export OPT_FLAGS="-flto -flto-compression-level=10 -O3 -pipe -ffunction-sections -fdata-sections"
echo "Cleaning up previously cloned repos..."
rm -rf "$WORK_DIR"/{binutils,build-binutils,build-gcc,gcc}
echo "|| ||"
echo "|| Building Bare Metal Toolchain for ${arch} with ${TARGET} as target ||"
echo "|| ||"
download_resources() {
echo "Downloading Pre-requisites"
echo "Cloning binutils"
git clone git://sourceware.org/git/binutils-gdb.git -b master binutils --depth=1
sed -i '/^development=/s/true/false/' binutils/bfd/development.sh
echo "Cloned binutils!"
echo "Cloning GCC"
git clone git://gcc.gnu.org/git/gcc.git -b master gcc --depth=1
cd "${WORK_DIR}"
echo "Downloaded prerequisites!"
}
build_binutils() {
cd "${WORK_DIR}"
echo "Building Binutils"
mkdir build-binutils
cd build-binutils
env CFLAGS="$OPT_FLAGS" CXXFLAGS="$OPT_FLAGS" \
../binutils/configure --target="$TARGET" \
--disable-docs \
--disable-gdb \
--disable-nls \
--disable-werror \
--enable-gold \
--prefix="$PREFIX" \
--with-pkgversion="Eva Binutils" \
--with-sysroot
make -j"$JOBS"
make install -j"$JOBS"
cd ../
echo "Built Binutils, proceeding to next step...."
}
build_gcc() {
cd "${WORK_DIR}"
echo "Building GCC"
cd gcc
./contrib/download_prerequisites
echo "Bleeding Edge" > gcc/DEV-PHASE
cd ../
mkdir build-gcc
cd build-gcc
env CFLAGS="$OPT_FLAGS" CXXFLAGS="$OPT_FLAGS" \
../gcc/configure --target="$TARGET" \
--disable-decimal-float \
--disable-docs \
--disable-gcov \
--disable-libffi \
--disable-libgomp \
--disable-libmudflap \
--disable-libquadmath \
--disable-libstdcxx-pch \
--disable-nls \
--disable-shared \
--enable-default-ssp \
--enable-languages=c,c++,fortran \
--enable-threads=posix \
--prefix="$PREFIX" \
--with-gnu-as \
--with-gnu-ld \
--with-headers="/usr/include" \
--with-linker-hash-style=gnu \
--with-newlib \
--with-pkgversion="Eva GCC" \
--with-sysroot
make all-gcc -j"$JOBS"
make all-target-libgcc -j"$JOBS"
make install-gcc -j"$JOBS"
make install-target-libgcc -j"$JOBS"
echo "Built GCC!"
}
download_resources
build_binutils
build_gcc