Reproducible toolchain build inside docker container

This commit is contained in:
Thomas Oltmann 2026-01-21 21:38:54 +01:00
parent 91dd381715
commit 3cfa7eaa19
7 changed files with 59 additions and 11 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/final
/x86_64-karlos-toolchain.tar.xz

8
Dockerfile Normal file
View file

@ -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" ]

32
Readme.md Normal file
View file

@ -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

View file

@ -7,4 +7,4 @@ cd binutils-2.37-build
--disable-nls --disable-werror \
--with-sysroot="$SYSROOT"
make
#make install
make install DESTDIR="/final"

View file

@ -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"

7
make-toolchain.sh Executable file
View file

@ -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

View file

@ -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"