update readme introduction part, add demo screen-shot
[lunaix-os.git] / slides / c0-workspace / gcc-build.sh
1 #! /usr/bin/bash
2 sudo apt update &&\
3      sudo apt install -y \
4                 build-essential \
5                 bison\
6                 flex\
7                 libgmp3-dev\
8                 libmpc-dev\
9                 libmpfr-dev\
10                 texinfo
11
12 BINUTIL_VERSION=2.37
13 BINUTIL_URL=https://ftp.gnu.org/gnu/binutils/binutils-2.37.tar.xz
14
15 GCC_VERSION=11.2.0
16 GCC_URL=https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz
17
18 GCC_SRC="gcc-${GCC_VERSION}"
19 BINUTIL_SRC="binutils-${BINUTIL_VERSION}"
20
21 # download gcc & binutil src code
22
23 export PREFIX="$HOME/cross-compiler"
24 export TARGET=i686-elf
25 export PATH="$PREFIX/bin:$PATH"
26
27 mkdir -p "${PREFIX}"
28 mkdir -p "${HOME}/toolchain/binutils-build"
29 mkdir -p "${HOME}/toolchain/gcc-build"
30
31 cd "${HOME}/toolchain"
32
33 if [ ! -d "${HOME}/toolchain/${GCC_SRC}" ]
34 then
35         (wget -O "${GCC_SRC}.tar" ${GCC_URL} \
36                 && tar -xf "${GCC_SRC}.tar") || exit
37         rm -f "${GCC_SRC}.tar"
38 else
39         echo "skip downloading gcc"
40 fi
41
42 if [ ! -d "${HOME}/toolchain/${BINUTIL_SRC}" ]
43 then
44         (wget -O "${BINUTIL_SRC}.tar" ${BINUTIL_URL} \
45                 && tar -xf "${BINUTIL_SRC}.tar") || exit
46         rm -f "${BINUTIL_SRC}.tar"
47 else
48         echo "skip downloading binutils"
49 fi
50
51 echo "Building binutils"
52
53 cd "${HOME}/toolchain/binutils-build"
54
55 ("${HOME}/toolchain/${BINUTIL_SRC}/configure" --target=$TARGET --prefix="$PREFIX" \
56         --with-sysroot --disable-nls --disable-werror) || exit
57
58 (make && make install) || exit
59
60 echo "Binutils build successfully!"
61
62 echo "Building GCC"
63
64 cd "${HOME}/toolchain/gcc-build"
65
66 which -- "$TARGET-as" || echo "$TARGET-as is not in the PATH"
67
68 ("${HOME}/toolchain/${GCC_SRC}/configure" --target=$TARGET --prefix="$PREFIX" \
69         --disable-nls --enable-languages=c,c++ --without-headers) || exit
70
71 (make all-gcc &&\
72  make all-target-libgcc &&\
73  make install-gcc &&\
74  make install-target-libgcc) || exit
75
76 echo "done"