This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
i686-elf-gcc-build.sh
executable file
·111 lines (73 loc) · 2.44 KB
/
i686-elf-gcc-build.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
#!/bin/bash
#
# Script to build the i686-elf GCC cross compiler
#
# ref: https://wiki.osdev.org/GCC_Cross-Compiler
# The cross compiler will be located here: `~/opt/cross`
# The InstructionOS src/Makefile depends on this location
# when compiling the kernel
# Exit immediately if a command exits with a non-zero status.
set -e
echo "This script will build the i686-elf GCC cross compiler"
echo "Continue?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) exit;;
esac
done
echo "#"
echo "# Build GCC and binutils from source"
echo "#"
echo "--- Installing packages ---";
sudo apt install build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo
mkdir -p ~/Source && pushd ~/Source
echo "--- Downloading sources ---";
wget https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
wget https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.xz
echo "--- Extracting sources ---";
tar -xf gcc-13.2.0.tar.gz
tar -xf binutils-2.41.tar.xz
echo "--- Compiling binutils ---";
export PREFIX="$HOME/opt/gcc-13.2.0"
mkdir -p build-binutils && pushd build-binutils
../binutils-2.41/configure --prefix="$PREFIX" --disable-nls --disable-werror
make -j$(nproc)
make install
popd
echo "--- Downloading GCC prerequisites ---";
pushd gcc-13.2.0
./contrib/download_prerequisites
popd
echo "--- Compiling GCC ---";
mkdir -p build-gcc && pushd build-gcc
../gcc-13.2.0/configure --prefix="$PREFIX" --disable-nls --enable-languages=c,c++
make -j$(nproc)
make install
popd
echo "#"
echo "# Build the i686-elf GCC cross compiler"
echo "#"
# nb. assumes we are following on from above
export TARGET=i686-elf
export PREFIX="$HOME/opt/cross"
export PATH="$PREFIX/bin:$PATH"
echo "--- Compiling binutils ---";
rm -fdr build-binutils && mkdir -p build-binutils && pushd build-binutils
../binutils-2.41/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make -j$(nproc)
make install
popd
# The $PREFIX/bin directory _must_ be in the PATH
which -- $TARGET-as
echo "--- Compiling GCC ---";
rm -fdr build-gcc && mkdir -p build-gcc && pushd build-gcc
../gcc-13.2.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make -j$(nproc) all-gcc
make -j$(nproc) all-target-libgcc
make install-gcc
make install-target-libgcc
popd
echo "--- Confirm installation of the compiler ---";
$HOME/opt/cross/bin/$TARGET-gcc --version
$HOME/opt/cross/bin/$TARGET-ld --version