summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Containerfile44
-rw-r--r--Dockerfile26
-rw-r--r--Makefile21
-rw-r--r--downloads/.gitkeep0
-rw-r--r--patches/gcc-14.2.0-x86_64-pc-elf/0001-no-red-zone.patch (renamed from patches/gcc-14.2.0-x86_64-elf.patch)7
l---------patches/gcc-14.3.0-x86_64-pc-elf/0001-no-red-zone.patch1
-rwxr-xr-xscripts/0000-prepare-os.sh15
-rwxr-xr-xscripts/0100-download.sh10
-rwxr-xr-xscripts/0200-build-target-binutils.sh20
-rwxr-xr-xscripts/0300-build-bootstrap-gcc.sh31
-rwxr-xr-xscripts/0400-build-target-newlib.sh23
-rwxr-xr-xscripts/0500-build-target-gcc.sh27
-rwxr-xr-xscripts/0600-build-target-gdb.sh18
-rwxr-xr-xscripts/build.sh150
15 files changed, 217 insertions, 177 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..08a5b84
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/downloads \ No newline at end of file
diff --git a/Containerfile b/Containerfile
new file mode 100644
index 0000000..d988874
--- /dev/null
+++ b/Containerfile
@@ -0,0 +1,44 @@
+FROM docker.io/archlinux:latest AS build
+
+ARG BINUTILS_VERSION
+ARG GCC_VERSION
+ARG GDB_VERSION
+ARG NEWLIB_VERSION
+ARG TARGET
+
+RUN /scripts/0000-prepare-os.sh
+RUN /scripts/0100-download.sh
+RUN /scripts/0200-build-target-binutils.sh
+RUN /scripts/0300-build-bootstrap-gcc.sh
+RUN /scripts/0400-build-target-newlib.sh
+RUN /scripts/0500-build-target-gcc.sh
+RUN /scripts/0600-build-target-gdb.sh
+
+FROM docker.io/archlinux:latest
+
+ARG EMULATOR=x86
+
+RUN pacman --noconfirm -Syu && \
+ pacman --noconfirm --needed -S \
+ cmake \
+ flex \
+ git \
+ gmp \
+ grub \
+ guile \
+ libelf \
+ libisl \
+ libisoburn \
+ libmpc \
+ mpfr \
+ mtools \
+ ninja \
+ openssh \
+ qemu-system-$EMULATOR \
+ qemu-ui-curses \
+ xxhash \
+ zlib
+
+COPY --from=build /opt/toolchain /opt/toolchain
+
+ENV PATH=/opt/toolchain/bin:$PATH
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 36114b4..0000000
--- a/Dockerfile
+++ /dev/null
@@ -1,26 +0,0 @@
-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 \
- openssh \
- python-sphinx \
- qemu-system-x86 \
- qemu-ui-curses
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..7140cda
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,21 @@
+mkfile_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
+
+BINUTILS_VERSION ?= 2.44
+GCC_VERSION ?= 14.2.0
+GDB_VERSION ?= 16.2
+NEWLIB_VERSION ?= 4.5.0.20241231
+TARGET ?= x86_64-pc-elf
+
+all:
+ podman pull docker.io/archlinux:latest
+ podman build \
+ --volume $(mkfile_dir)downloads:/downloads \
+ --volume $(mkfile_dir)scripts:/scripts \
+ --volume $(mkfile_dir)patches:/patches \
+ --build-arg BINUTILS_VERSION=$(BINUTILS_VERSION) \
+ --build-arg GCC_VERSION=$(GCC_VERSION) \
+ --build-arg GDB_VERSION=$(GDB_VERSION) \
+ --build-arg NEWLIB_VERSION=$(NEWLIB_VERSION) \
+ --build-arg TARGET=$(TARGET) \
+ --tag registry.gitlab.ost.ch:45023/teachos/devcontainers:$(GCC_VERSION) \
+ . \ No newline at end of file
diff --git a/downloads/.gitkeep b/downloads/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/downloads/.gitkeep
diff --git a/patches/gcc-14.2.0-x86_64-elf.patch b/patches/gcc-14.2.0-x86_64-pc-elf/0001-no-red-zone.patch
index 2a8d0a5..e488a6e 100644
--- a/patches/gcc-14.2.0-x86_64-elf.patch
+++ b/patches/gcc-14.2.0-x86_64-pc-elf/0001-no-red-zone.patch
@@ -1,10 +1,15 @@
+--- /dev/null
++++ gcc/config/i386/t-x86_64-pc-elf
+@@ -0,0 +1,2 @@
++MULTILIB_OPTIONS += mno-red-zone
++MULTILIB_DIRNAMES += no-red-zone
--- 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"
++ tmake_file="${tmake_file} i386/t-x86_64-pc-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/patches/gcc-14.3.0-x86_64-pc-elf/0001-no-red-zone.patch b/patches/gcc-14.3.0-x86_64-pc-elf/0001-no-red-zone.patch
new file mode 120000
index 0000000..e0b243d
--- /dev/null
+++ b/patches/gcc-14.3.0-x86_64-pc-elf/0001-no-red-zone.patch
@@ -0,0 +1 @@
+../gcc-14.2.0-x86_64-pc-elf/0001-no-red-zone.patch \ No newline at end of file
diff --git a/scripts/0000-prepare-os.sh b/scripts/0000-prepare-os.sh
new file mode 100755
index 0000000..33b0deb
--- /dev/null
+++ b/scripts/0000-prepare-os.sh
@@ -0,0 +1,15 @@
+#!/bin/env bash
+
+set -e
+
+pacman --noconfirm -Syu
+
+pacman --noconfirm --needed -S \
+ base-devel \
+ libelf \
+ libmpc \
+ zlib
+
+pacman --noconfirm --needed --asdeps -S \
+ gmp \
+ mpfr
diff --git a/scripts/0100-download.sh b/scripts/0100-download.sh
new file mode 100755
index 0000000..03bd544
--- /dev/null
+++ b/scripts/0100-download.sh
@@ -0,0 +1,10 @@
+#!/bin/env bash
+
+set -e
+
+mkdir -p /downloads && cd /downloads
+
+curl -LO -C - ftp://sourceware.org/pub/newlib/newlib-$NEWLIB_VERSION.tar.gz
+curl -LO -C - http://ftp.gwdg.de/pub/linux/sources.redhat.com/binutils/releases/binutils-$BINUTILS_VERSION.tar.xz
+curl -LO -C - http://ftp.gwdg.de/pub/linux/sources.redhat.com/gcc/releases/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz
+curl -LO -C - http://ftp.gwdg.de/pub/linux/sources.redhat.com/gdb/releases/gdb-$GDB_VERSION.tar.xz
diff --git a/scripts/0200-build-target-binutils.sh b/scripts/0200-build-target-binutils.sh
new file mode 100755
index 0000000..a739e9d
--- /dev/null
+++ b/scripts/0200-build-target-binutils.sh
@@ -0,0 +1,20 @@
+#!/bin/env bash
+
+set -e
+
+mkdir -p /toolchain/binutils/.build && cd /toolchain/binutils
+
+tar xf /downloads/binutils-$BINUTILS_VERSION.tar.xz
+
+cd .build
+
+../binutils-$BINUTILS_VERSION/configure \
+ --disable-nls \
+ --disable-werror \
+ --enable-colored-disassembly \
+ --prefix=/opt/toolchain \
+ --target=$TARGET
+
+make -j$(nproc)
+
+make install-strip
diff --git a/scripts/0300-build-bootstrap-gcc.sh b/scripts/0300-build-bootstrap-gcc.sh
new file mode 100755
index 0000000..0e54b3b
--- /dev/null
+++ b/scripts/0300-build-bootstrap-gcc.sh
@@ -0,0 +1,31 @@
+#!/bin/env bash
+
+set -e
+
+mkdir -p /toolchain/gcc/.bootstrap-build && cd /toolchain/gcc
+
+tar xf /downloads/gcc-$GCC_VERSION.tar.xz
+
+cd gcc-$GCC_VERSION
+
+for PATCH in $(ls /patches/gcc-$GCC_VERSION-$TARGET/*.patch); do
+ patch -p0 -i $PATCH
+done
+
+cd /toolchain/gcc/.bootstrap-build
+
+CFLAGS=${CFLAGS/-Werror=format-security/}
+CXXFLAGS=${CXXFLAGS/-Werror=format-security/}
+PATH=/opt/bootstrap/bin:/opt/toolchain/bin:$PATH
+
+../gcc-$GCC_VERSION/configure \
+ --enable-languages=c,c++ \
+ --prefix=/opt/bootstrap \
+ --target=$TARGET \
+ --without-headers
+
+make -j$(nproc) all-gcc
+make install-gcc
+
+make -j$(nproc) all-target-libgcc
+make install-target-libgcc
diff --git a/scripts/0400-build-target-newlib.sh b/scripts/0400-build-target-newlib.sh
new file mode 100755
index 0000000..0560f3b
--- /dev/null
+++ b/scripts/0400-build-target-newlib.sh
@@ -0,0 +1,23 @@
+#!/bin/env bash
+
+set -e
+
+PATH=/opt/bootstrap/bin:/opt/toolchain/bin:$PATH
+
+mkdir -p /toolchain/newlib/.build && cd /toolchain/newlib
+
+tar xf /downloads/newlib-$NEWLIB_VERSION.tar.gz
+
+cd .build
+
+LDFLAGS=-mno-red-zone ../newlib-$NEWLIB_VERSION/configure \
+ --disable-newlib-fseek-optimization \
+ --disable-newlib-io-float \
+ --disable-newlib-supplied-syscalls \
+ --disable-nls \
+ --disable-werror \
+ --prefix=/opt/toolchain \
+ --target=$TARGET
+
+make -j$(nproc)
+make install
diff --git a/scripts/0500-build-target-gcc.sh b/scripts/0500-build-target-gcc.sh
new file mode 100755
index 0000000..3ef2f5e
--- /dev/null
+++ b/scripts/0500-build-target-gcc.sh
@@ -0,0 +1,27 @@
+#!/bin/env bash
+
+set -e
+
+mkdir -p /toolchain/gcc/.target-build && cd /toolchain/gcc/.target-build
+
+CFLAGS=${CFLAGS/-Werror=format-security/}
+CXXFLAGS=${CXXFLAGS/-Werror=format-security/}
+PATH=/opt/bootstrap/bin:/opt/toolchain/bin:$PATH
+
+../gcc-$GCC_VERSION/configure \
+ --disable-hosted-libstdcxx \
+ --disable-nls \
+ --disable-wchar_t \
+ --enable-cxx-flags=-fno-exceptions \
+ --enable-languages=c,c++ \
+ --prefix=/opt/toolchain \
+ --target=$TARGET \
+ --with-newlib
+
+make -j$(nproc) all-gcc
+make install-strip-gcc
+
+for COMPONENT in target-libgcc target-libstdc++-v3; do
+ make -j$(nproc) all-$COMPONENT
+ make install-$COMPONENT
+done
diff --git a/scripts/0600-build-target-gdb.sh b/scripts/0600-build-target-gdb.sh
new file mode 100755
index 0000000..85184de
--- /dev/null
+++ b/scripts/0600-build-target-gdb.sh
@@ -0,0 +1,18 @@
+#!/bin/env bash
+
+set -e
+
+PATH=/opt/bootstrap/bin:/opt/toolchain/bin:$PATH
+
+mkdir -p /toolchain/gdb/.build && cd /toolchain/gdb
+
+tar xf /downloads/gdb-$GDB_VERSION.tar.xz
+
+cd .build
+
+../gdb-$GDB_VERSION/configure \
+ --prefix=/opt/toolchain \
+ --target=$TARGET
+
+make -j$(nproc) all-gdb
+make install-strip-gdb
diff --git a/scripts/build.sh b/scripts/build.sh
deleted file mode 100755
index 1ac8f47..0000000
--- a/scripts/build.sh
+++ /dev/null
@@ -1,150 +0,0 @@
-#!/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