From 3cfa7eaa1962b6853ca33d0ddd00621c9cad9686 Mon Sep 17 00:00:00 2001 From: Thomas Oltmann Date: Wed, 21 Jan 2026 21:38:54 +0100 Subject: [PATCH] Reproducible toolchain build inside docker container --- .gitignore | 2 ++ Dockerfile | 8 ++++++++ Readme.md | 32 ++++++++++++++++++++++++++++++++ build-binutils.sh | 2 +- build-gcc.sh | 11 +++++------ make-toolchain.sh | 7 +++++++ vars.sh | 8 ++++---- 7 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Readme.md create mode 100755 make-toolchain.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b0dba6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/final +/x86_64-karlos-toolchain.tar.xz diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a2819f0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM debian:oldoldstable-slim +WORKDIR /build +COPY . . +RUN apt-get update +RUN apt-get install -y patch gcc g++ binutils make libgmp-dev libmpfr-dev libmpc-dev +ADD https://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-11.2.0/gcc-11.2.0.tar.gz gcc-11.2.0.tar.gz +ADD https://ftp.fu-berlin.de/unix/gnu/binutils/binutils-2.37.tar.gz binutils-2.37.tar.gz +CMD [ "sh", "-c", "./make-toolchain.sh" ] diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..d1419e5 --- /dev/null +++ b/Readme.md @@ -0,0 +1,32 @@ +KarlOS Toolchain +================ + +We have a customized version of GCC and GNU binutils that support KarlOS as a compilation target platform. +Additionally, everybody working on KarlOS needs a couple of other development tools such as mkbootimg. + +This repository contains the sources for a Docker container that can build a (somewhat) portable release of +our development tools. + +To compile our toolchain from source, you first need to create the container image like this: +```sh +docker buildx build -t build-karlos-toolchain:latest . +``` + +Then, you can run the container like this: +```sh +docker container run --rm -it -v $(pwd)/final:/final build-karlos-toolchain +``` + +You can then bundle the toolchain into a tarball like this: +```sh +tar cJ -C final -f x86_64-karlos-toolchain.tar.xz . +``` + +ToDos +----- + +- Verify signatures of downloaded tarballs (keep signatures in git repo) +- Use shell variables to make it easier to change GCC/binutils versions +- Add mkbootimg to the toolchain so members don't have to install it manually +- Document the toolchain process more +- Port patches to latest versions of GCC & binutils diff --git a/build-binutils.sh b/build-binutils.sh index 9e8c781..2fd9036 100755 --- a/build-binutils.sh +++ b/build-binutils.sh @@ -7,4 +7,4 @@ cd binutils-2.37-build --disable-nls --disable-werror \ --with-sysroot="$SYSROOT" make -#make install +make install DESTDIR="/final" diff --git a/build-gcc.sh b/build-gcc.sh index 6564aac..25a5674 100755 --- a/build-gcc.sh +++ b/build-gcc.sh @@ -5,10 +5,9 @@ cd gcc-11.2.0-build ../gcc-11.2.0/configure \ --target="$TARGET" --prefix="$PREFIX" \ --disable-nls \ + --disable-libssp \ + --disable-libquadmath \ --enable-languages=c \ - --disable-gcov \ - --with-sysroot="$SYSROOT" -make "$MAKEFLAGS" all-gcc -make "$MAKEFLAGS" all-target-libgcc -#make install-gcc -#make install-target-libgcc + --disable-gcov +make $MAKEFLAGS +make install DESTDIR="/final" diff --git a/make-toolchain.sh b/make-toolchain.sh new file mode 100755 index 0000000..5583f6a --- /dev/null +++ b/make-toolchain.sh @@ -0,0 +1,7 @@ +#!/bin/sh +tar xf binutils-2.37.tar.gz +tar xf gcc-11.2.0.tar.gz +patch -p0 < binutils-karlos-target-2.37.diff +patch -p0 < gcc-karlos-target-11.2.0.diff +./build-binutils.sh +./build-gcc.sh diff --git a/vars.sh b/vars.sh index 1d00fe4..826365d 100644 --- a/vars.sh +++ b/vars.sh @@ -1,13 +1,13 @@ # Modify these definitions to fit your host system # PREFIX: Path on your host system where the toolchain shall be installed -export PREFIX="/opt/karlos-toolchain" +export PREFIX="/usr/local/x86_64-karlos-toolchain" # SYSROOT: Path to the 'sysroot' folder in your local copy of the karlos repository -export SYSROOT="$HOME/karlos/karlos/sysroot" +#export SYSROOT="/usr/local/share/karlos/sysroot" -export MAKEFLAGS="-j 10" +export MAKEFLAGS="-j $(getconf _NPROCESSORS_ONLN)" # Do not modify the following lines # TARGET: The target triplet export TARGET="x86_64-karlos" # Temporarily add PREFIX to PATH so the toolchain can find itself during compilation -export PATH="$PREFIX/bin:$PATH" +export PATH="/final/$PREFIX/bin:$PATH"