-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_tools.sh
executable file
·133 lines (101 loc) · 2.75 KB
/
build_tools.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
#! /bin/bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )"
export PREFIX="$SCRIPT_DIR/tools"
export TARGET=x86_64-elf
export BINUTILS_VERSION=2.29.1
export GCC_VERSION=7.2.0
export GRUB_VERSION=2.02
export PATH="$PREFIX/bin:$PATH"
silent() {
while read line; do
printf '.'
done
printf '\n'
}
run() {
if [ "$CI" == "true" ]; then
"$@" | silent
else
"$@"
fi
}
download_tar() {
if [ ! -f $1 ]; then
echo "::: Downloading source"
wget -c $2
fi
echo "::: Extracting source"
tar -xf $1
}
download_git() {
if [ ! -d $1 ]; then
echo "::: Cloning source"
git clone $2 $1
fi
}
install_binutils() {
echo "===== Binutils ====="
download_tar binutils-$BINUTILS_VERSION.tar.gz ftp://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.gz
mkdir -p build-binutils; pushd build-binutils
echo "::: Configuring"
run ../binutils-$BINUTILS_VERSION/configure --target=$TARGET --prefix="$PREFIX" \
--disable-nls --disable-werror \
--disable-gdb --disable-libdecnumber --disable-readline --disable-sim
echo "::: Building"
run make
run make install
popd
echo "::: Done!"
}
install_gcc() {
echo "===== GCC ====="
download_tar gcc-$GCC_VERSION.tar.gz ftp://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz
echo "::: Downloading prerequisites"
pushd gcc-$GCC_VERSION
run ./contrib/download_prerequisites
popd
mkdir -p build-gcc; pushd build-gcc
echo "::: Configuring"
run ../gcc-$GCC_VERSION/configure --target=$TARGET --prefix="$PREFIX" \
--disable-nls --enable-languages=c,c++
echo "::: Building"
run make all-gcc
run make all-target-libgcc
run make install-gcc
run make install-target-libgcc
popd
echo "::: Done!"
}
install_grub() {
echo "===== GRUB ====="
download_tar grub-$GRUB_VERSION.tar.xz ftp://ftp.gnu.org/gnu/grub/grub-$GRUB_VERSION.tar.xz
pushd grub-$GRUB_VERSION
echo "::: Configuring GRUB"
run ./autogen.sh
run ./configure --disable-werror TARGET_CC=$TARGET-gcc TARGET_OBJCOPY=$TARGET-objcopy \
TARGET_STRIP=$TARGET-strip TARGET_NM=$TARGET-nm TARGET_RANLIB=$TARGET-ranlib \
--target=$TARGET --prefix="$PREFIX"
echo "::: Building GRUB"
run make
run make install
popd
echo "::: Done!"
}
install() {
if [ ! -f $PREFIX/bin/$TARGET-ld ]; then
install_binutils
fi
if [ ! -f $PREFIX/bin/$TARGET-gcc ]; then
install_gcc
fi
if [ ! -f $PREFIX/bin/grub-mkrescue ]; then
install_grub
fi
}
mkdir -p $PREFIX/src; cd $PREFIX/src
install
if [ "$CI" = true ]; then
echo "===== Cleanup ====="
rm -rf "$PREFIX/src"
fi