forked from mvaisakh/gcc-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-gcc.sh
executable file
·146 lines (133 loc) · 4.13 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
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
#!/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" ;;
"x86") TARGET="x86_64-linux-gnu" ;;
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" --build="$TARGET" --host="$TARGET" \
--program-prefix= \
--disable-docs \
--disable-gdb \
--disable-nls \
--disable-werror \
--enable-ld \
--enable-gold \
--enable-deterministic-archives=no \
--enable-lto \
--enable-compressed-debug-sections=none \
--enable-generate-build-notes=no \
--enable-threads=yes \
--enable-relro=yes \
--enable-plugins \
--prefix="$PREFIX" \
--with-bugurl=https://github.com/indiff/gcc-build \
--with-sysroot=/ \
--with-pkgversion="Indiff binutils"
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 "Indiff Build" > gcc/DEV-PHASE
cd ../
mkdir build-gcc
cd build-gcc
rm -rf ../gcc/testsuite
# --target="$TARGET" --build="$TARGET" --host="$TARGET"
env CFLAGS="$OPT_FLAGS" CXXFLAGS="$OPT_FLAGS" \
../gcc/configure --target="$TARGET" --build="$TARGET" --host="$TARGET" \
--with-bugurl=https://github.com/indiff/gcc-build \
--program-prefix="" \
--program-suffix="" \
--disable-decimal-float \
--disable-docs \
--disable-gcov \
--disable-libffi \
--disable-libgomp \
--disable-libmudflap \
--disable-libquadmath \
--disable-libstdcxx-pch \
--disable-nls \
--disable-shared \
--disable-libunwind-exceptions \
--enable-__cxa_atexit \
--enable-bootstrap \
--enable-multilib \
--enable-gnu-unique-object \
--enable-plugin \
--enable-gnu-indirect-function \
--enable-initfini-array \
--enable-default-ssp \
--enable-languages=c,c++,fortran,lto \
--enable-threads=posix \
--enable-libstdcxx-backtrace \
--enable-offload-targets=nvptx-none \
--without-cuda-driver --enable-offload-defaulted \
--with-tune=generic \
--with-gcc-major-version-only \
--with-arch_32=x86-64 \
--prefix="$PREFIX" \
--with-gnu-as \
--with-gnu-ld \
--with-linker-hash-style=gnu \
--with-pkgversion="Indiff GCC"
make all-gcc -j"$JOBS"
make all-target-libgcc -j"$JOBS"
make all-target-libstdc++-v3 -j"$JOBS"
make install-gcc -j"$JOBS"
make install-target-libgcc -j"$JOBS"
make install-target-libstdc++-v3 -j"$JOBS"
echo "Built GCC!"
}
download_resources
build_binutils
build_gcc