summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile24
-rw-r--r--patches/gcc-14.2.0-x86_64-elf.patch10
-rwxr-xr-xscripts/build.sh149
3 files changed, 183 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..56d11a0
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,24 @@
+FROM archlinux:latest
+
+ARG BINUTILS_VERSION=2.43
+ARG GCC_VERSION=14.2.0
+ARG NEWLIB_VERSION=4.4.0.20231231
+ARG TARGET=x86_64-elf
+
+ADD scripts/build.sh build.sh
+ADD patches patches
+
+RUN ./build.sh
+
+RUN pacman --noconfirm -S \
+ cmake \
+ doxygen \
+ gdb \
+ git \
+ graphviz \
+ grub \
+ libisoburn \
+ mtools \
+ ninja \
+ python-sphinx \
+ qemu-system-x86
diff --git a/patches/gcc-14.2.0-x86_64-elf.patch b/patches/gcc-14.2.0-x86_64-elf.patch
new file mode 100644
index 0000000..2a8d0a5
--- /dev/null
+++ b/patches/gcc-14.2.0-x86_64-elf.patch
@@ -0,0 +1,10 @@
+--- gcc/config.gcc 2024-08-01 10:17:14.000000000 +0200
++++ gcc/config.gcc 2024-09-16 14:03:02.049140896 +0200
+@@ -1933,6 +1933,7 @@
+ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h newlib-stdint.h i386/i386elf.h"
+ ;;
+ x86_64-*-elf*)
++ tmake_file="${tmake_file} i386/t-x86_64-elf"
+ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h"
+ ;;
+ x86_64-*-rtems*)
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