-
Notifications
You must be signed in to change notification settings - Fork 6
/
build-cross-compiler.sh
executable file
·98 lines (82 loc) · 2.93 KB
/
build-cross-compiler.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
#!/bin/bash
GCCVER=11.1.0
BINUTILSVER=2.31.1
GDBVER=8.2.1
function error() {
echo -e "\033[1;31m$@\\033[0m";
}
function highlight() {
echo -e "\033[1;32m$@\\033[0m";
}
function progress() {
echo -n "$1... ";
shift;
TEMPFILE=`mktemp`;
eval $@ >$TEMPFILE 2>&1;
if [ $? -ne 0 ]; then
echo -e "\033[1;5;31merror\033[0m";
cat $TEMPFILE;
rm $TEMPFILE;
exit 1;
fi
rm $TEMPFILE;
echo "done";
}
if [ $# -ne 2 ]; then
echo "[i] Usage: $0 installation_prefix target";
echo "[i] ie: $0 /home/lj/Apps/cross-compiler/x86_64-elf x86_64-elf";
exit 1;
fi
PREFIX=$1;
TARGET=$2;
highlight "[i] Installation parameters:";
echo "[i] Installation prefix: ${PREFIX}";
echo "[i] Installation target: ${TARGET}";
echo;
highlight "[i] For the build to succeed you need to have the following packages installed:";
echo "[i] ]==> sudo apt-get install build-essential libgmp-dev libmpc-dev libmpfr-dev texinfo";
echo;
read -p "[?] Do you want to continue? (y/n) " -n 1 -r;
echo;
echo;
if [ x"$REPLY" != xy ]; then
echo "[i] Bye.";
exit 0;
fi
TEMPDIR=`mktemp -d`;
(
echo "[i] Working in ${TEMPDIR}";
cd ${TEMPDIR};
progress "[i] Donwloading binutils" wget http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVER}.tar.bz2;
progress "[i] Downloading gcc" wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-${GCCVER}/gcc-${GCCVER}.tar.xz;
progress "[i] Downloading gdb" wget https://ftp.gnu.org/gnu/gdb/gdb-${GDBVER}.tar.xz;
progress "[i] Unpacking binutils" tar jxf binutils-${BINUTILSVER}.tar.bz2;
mkdir binutils-build;
cd binutils-build;
progress "[i] Configuring binutils" ../binutils-${BINUTILSVER}/configure --target=${TARGET} --prefix=${PREFIX} \
--with-sysroot --disable-nls --disable-werror;
progress "[i] Building binutils" make -j 4;
progress "[i] Installing binutils" make install;
cd ..;
progress "[i] Unpacking gcc" tar xf gcc-${GCCVER}.tar.xz;
mkdir gcc-build;
cd gcc-build;
export PATH=${PREFIX}/bin:$PATH;
progress "[i] Configuring gcc" ../gcc-${GCCVER}/configure --target=${TARGET} --prefix=${PREFIX} \
--disable-nls --enable-languages=c,c++ --without-headers;
progress "[i] Building gcc" make -j4 all-gcc;
progress "[i] Building libgcc" make -j4 all-target-libgcc;
progress "[i] Installing gcc" make install-gcc;
progress "[i] Installing libgcc" make install-target-libgcc;
progress "[i] Installing unwind-pe.h" cp ../gcc-${GCCVER}/libgcc/unwind-pe.h ${PREFIX}/lib/gcc/${TARGET}/${GCCVER}/include
cd ..;
progress "[i] Unpacking gdb" tar xf gdb-${GDBVER}.tar.xz;
mkdir gdb-build;
cd gdb-build;
progress "[i] Configuring gdb" ../gdb-${GDBVER}/configure --target=${TARGET} --prefix=${PREFIX}
progress "[i] Building gdb" make -j 4;
progress "[i] Installing gdb" make install;
echo;
highlight "[i] Installation successfull. Add the following to your shell profile:";
echo "[i] export PATH=${PREFIX}/bin:\$PATH";
)