-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbuild-gcc.sh
More file actions
executable file
·143 lines (127 loc) · 3.97 KB
/
Copy pathbuild-gcc.sh
File metadata and controls
executable file
·143 lines (127 loc) · 3.97 KB
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
#!/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:p: flag; do
case "${flag}" in
a) arch=${OPTARG} ;;
p) PHASE=${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
# PGO Setup
export PGO_DIR="${PWD}/pgo-profiles-${arch}"
if [ "$PHASE" == "instrument" ]; then
mkdir -p "$PGO_DIR"
export PGO_FLAGS="-fprofile-generate=${PGO_DIR}"
echo ">>> Running in INSTRUMENT phase. PGO data will go to: $PGO_DIR"
elif [ "$PHASE" == "optimize" ]; then
export PGO_FLAGS="-fprofile-use=${PGO_DIR} -fprofile-correction -Wno-error"
echo ">>> Running in OPTIMIZE phase. Using PGO data from: $PGO_DIR"
else
export PGO_FLAGS=""
echo ">>> Running in NORMAL phase (No PGO)."
fi
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 $PGO_FLAGS"
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
if [ "$PHASE" == "instrument" ]; then
echo "Building GCC (Instrumented phase - skipping target libs)"
make all-gcc -j"$JOBS"
make install-gcc -j"$JOBS"
echo "Built GCC for profiling"
else
# If we are in the optimize or normal phase, build EVERYTHING!
echo "Building GCC (Final phase - including target libs)"
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!"
fi
}
download_resources
build_binutils
build_gcc