summaryrefslogtreecommitdiff
path: root/scripts/build.sh
blob: 1ac8f477c41283c12c65ef5f2bfa261765172518 (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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/env bash

pacman --noconfirm -Syu

mkdir toolchain && cd toolchain

# Install runtime dependencies

pacman --noconfirm --needed -S \
  base-devel \
  libelf \
  libmpc \
  zlib

# Install build dependencies

pacman --noconfirm --needed --asdeps -S \
  gmp \
  mpfr

# Download sources

curl -LO https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.xz
curl -LO https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz
curl -LO ftp://sourceware.org/pub/newlib/newlib-$NEWLIB_VERSION.tar.gz

# Build binutils

mkdir binutils && cd binutils && mkdir .build

tar xf ../binutils-$BINUTILS_VERSION.tar.xz

cd .build

../binutils-$BINUTILS_VERSION/configure \
  --target=$TARGET \
  --prefix=/usr/lib/$TARGET \
  --bindir=/usr/bin \
  --libdir=/usr/lib/$TARGET \
  --disable-nls \
  --disable-werror

make -j$(nproc)

make install

cd /toolchain

# Build first iteration of GCC (for newlib boostrapping)

mkdir gcc-bootstrap && cd gcc-bootstrap && mkdir .build

tar xf ../gcc-$GCC_VERSION.tar.xz

cd gcc-$GCC_VERSION

cat <<EOF > gcc/config/i386/t-x86_64-elf
MULTILIB_OPTIONS += mno-red-zone
MULTILIB_DIRNAMES += no-red-zone
EOF

patch -p0 -i /patches/gcc-$GCC_VERSION-$TARGET.patch

cd ../.build

CFLAGS=${CFLAGS/-Werror=format-security/}
CXXFLAGS=${CXXFLAGS/-Werror=format-security/}

../gcc-$GCC_VERSION/configure \
  --target=$TARGET \
  --prefix=/usr \
  --disable-nls \
  --disable-plugin \
  --libexecdir=/usr/lib \
  --enable-languages=c,c++ \
  --without-headers

make -j$(nproc) all-gcc
make -j$(nproc) all-target-libgcc
make install-gcc
make install-target-libgcc

cd /toolchain

# Build newlib

mkdir newlib && cd newlib && mkdir .build

tar xf ../newlib-$NEWLIB_VERSION.tar.gz

cd .build

LDFLAGS=-mno-red-zone ../newlib-$NEWLIB_VERSION/configure \
  --target=$TARGET \
  --prefix=/usr \
  --disable-newlib-supplied-syscalls \
  --disable-newlib-fseek-optimization \
  --disable-newlib-io-float \
  --disable-nls \
  --disable-werror

make -j$(nproc)
make install

cd /toolchain

# Build final gcc

mkdir gcc-final && cd gcc-final && mkdir .build

tar xf ../gcc-$GCC_VERSION.tar.xz

cd gcc-$GCC_VERSION

cat <<EOF > gcc/config/i386/t-x86_64-elf
MULTILIB_OPTIONS += mno-red-zone
MULTILIB_DIRNAMES += no-red-zone
EOF

patch -p0 -i /patches/gcc-$GCC_VERSION-$TARGET.patch

cd ../.build

CFLAGS=${CFLAGS/-Werror=format-security/}
CXXFLAGS=${CXXFLAGS/-Werror=format-security/}


../gcc-$GCC_VERSION/configure \
  CFLAGS_FOR_TARGET='-mcmodel=large' \
  --target=$TARGET \
  --prefix=/usr \
  --disable-nls \
  --disable-plugin \
  --libexecdir=/usr/lib \
  --enable-languages=c,c++ \
  --enable-cxx-flags=-fno-exceptions \
  --disable-hosted-libstdcxx \
  --disable-wchar_t \
  --with-newlib

make -j$(nproc) all-gcc
make -j$(nproc) all-target-libgcc
make -j$(nproc) all-target-libstdc++-v3
make install-gcc
make install-target-libgcc
make install-target-libstdc++-v3

cd /

rm -rf toolchain