diff options
Diffstat (limited to 'scripts/build.sh')
| -rwxr-xr-x | scripts/build.sh | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..d155974 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,149 @@ +#!/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++ \ + --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 |
