summaryrefslogtreecommitdiff
path: root/Toolchain/BuildIt.sh
blob: a97f3c44e914b4d01c677a3b0ff97650d001eccc (plain)
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
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

echo $DIR

TARGET=i686-pc-serenity
PREFIX="$DIR/Local"
SYSROOT="$DIR/../Root"

echo PREFIX is $PREFIX
echo SYSROOT is $SYSROOT

mkdir -p "$DIR/Tarballs"

source "$DIR/UseIt.sh"

pushd "$DIR/Tarballs"
    md5="$(md5sum binutils-2.32.tar.gz | cut -f1 -d' ')"
    echo "bu md5='$md5'"
    if [ ! -e "binutils-2.32.tar.gz" ] || [ "$md5" != "d1119c93fc0ed3007be4a84dd186af55" ] ; then
        rm -f binutils-2.32.tar.gz
        wget "http://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.gz"
    else
        echo "Skipped downloading binutils"
    fi

    md5="$(md5sum gcc-8.3.0.tar.gz | cut -f1 -d' ')"
    echo "gc md5='$md5'"
    if [ ! -e "gcc-8.3.0.tar.gz" ] || [ "$md5" != "9972f8c24c02ebcb5a342c1b30de69ff" ] ; then
        rm -f gcc-8.3.0.tar.gz
        wget "http://ftp.gnu.org/gnu/gcc/gcc-8.3.0/gcc-8.3.0.tar.gz"
    else
        echo "Skipped downloading gcc"
    fi

    if [ ! -d "binutils-2.32" ]; then
        echo "Extracting binutils..."
        tar -xf "binutils-2.32.tar.gz"

        pushd "binutils-2.32"
            patch -p1 < $DIR/Patches/binutils.patch > /dev/null
        popd
    else
        echo "Skipped extracting binutils"
    fi

    if [ ! -d "gcc-8.3.0" ]; then
        echo "Extracting gcc..."
        tar -xf "gcc-8.3.0.tar.gz"

        pushd "gcc-8.3.0"
            patch -p1 < $DIR/Patches/gcc.patch > /dev/null
        popd
    else
        echo "Skipped extracting gcc"
    fi
popd

mkdir -p $PREFIX

mkdir -p "$DIR/Build/binutils"
mkdir -p "$DIR/Build/gcc"

pushd "$DIR/Build/"
    unset PKG_CONFIG_LIBDIR # Just in case

    pushd binutils
        $DIR/Tarballs/binutils-2.32/configure --prefix=$PREFIX \
                                              --target=$TARGET \
                                              --with-sysroot=$SYSROOT \
                                              --disable-nls || exit 1
        make -j $(nproc) || exit 1
        make install || exit 1
    popd

    pushd gcc
        $DIR/Tarballs/gcc-8.3.0/configure --prefix=$PREFIX \
                                          --target=$TARGET \
                                          --with-sysroot=$SYSROOT \
                                          --disable-nls \
                                          --with-newlib \
                                          --enable-languages=c,c++ || exit 1

        echo "XXX build gcc and libgcc"
        make -j $(nproc) all-gcc all-target-libgcc || exit 1
        echo "XXX install gcc and libgcc"
        make install-gcc install-target-libgcc || exit 1

        echo "XXX serenity libc and libm"
        make -C "$DIR/../LibC/" install
        make -C "$DIR/../LibM/" install

        echo "XXX build libstdc++"
        make all-target-libstdc++-v3 || exit 1 
        echo "XXX install libstdc++"
        make install-target-libstdc++-v3 || exit 1
    popd
popd