summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-10-24 14:50:52 +0200
committerFelix Morgner <felix.morgner@ost.ch>2025-10-24 14:50:52 +0200
commit552a0482af54cd856f14c8fa138fff63d4e0b926 (patch)
tree98a8961e8a765bff86d9798d80aa574189859fef
parent94d007b7bda07f0aa97ed5ae5e1b64bb8d6576f0 (diff)
downloadteachos-toolchain-552a0482af54cd856f14c8fa138fff63d4e0b926.tar.xz
teachos-toolchain-552a0482af54cd856f14c8fa138fff63d4e0b926.zip
toolchain: switch to semi-static toolchain
-rw-r--r--Containerfile62
-rw-r--r--Makefile20
-rwxr-xr-xscripts/0000-prepare-os.sh25
-rwxr-xr-xscripts/0100-download.sh8
-rwxr-xr-xscripts/0150-build-static-deps.sh55
-rwxr-xr-xscripts/0200-build-target-binutils.sh5
-rwxr-xr-xscripts/0300-build-bootstrap-gcc.sh8
-rwxr-xr-xscripts/0500-build-target-gcc.sh6
-rwxr-xr-xscripts/0600-build-target-gdb.sh15
9 files changed, 151 insertions, 53 deletions
diff --git a/Containerfile b/Containerfile
index e840311..8add7ce 100644
--- a/Containerfile
+++ b/Containerfile
@@ -1,4 +1,4 @@
-FROM docker.io/archlinux:latest AS build
+FROM ubuntu:latest AS builder
ARG BINUTILS_VERSION
ARG GCC_VERSION
@@ -6,48 +6,40 @@ ARG GDB_VERSION
ARG NEWLIB_VERSION
ARG TARGET
+ARG ZLIB_VERSION
+ARG NCURSES_VERSION
+ARG EXPAT_VERSION
+ARG READLINE_VERSION
+ARG GMP_VERSION
+ARG MPFR_VERSION
+ARG MPC_VERSION
+
+ENV STATIC_DEPS_PREFIX=/opt/static-deps
+
ADD ./patches /patches
ADD ./scripts /scripts
RUN /scripts/0000-prepare-os.sh
RUN /scripts/0100-download.sh
+RUN /scripts/0150-build-static-deps.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 useradd -m dev
-
-COPY --from=build /opt/toolchain /opt/toolchain
-
-ENV PATH=/opt/toolchain/bin:$PATH
-
-RUN pacman --noconfirm -Syu && \
- pacman --noconfirm --needed -S \
- cmake \
- doxygen \
- flex \
- git \
- gmp \
- grub \
- guile \
- libelf \
- libisl \
- libisoburn \
- libmpc \
- mpfr \
- mtools \
- ninja \
- openssh \
- qemu-system-$EMULATOR \
- qemu-ui-curses \
- which \
- xxhash \
- zlib
-
-RUN rm -rf /var/cache/pacman
+FROM ubuntu:latest
+
+LABEL org.opencontainers.image.title="TeachOS Toolchain"
+LABEL org.opencontainers.image.description="A semi-statically linked cross-compiler toolchain for TeachOS development."
+
+RUN apt-get update && \
+ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
+ libstdc++6 && \
+ rm -rf /var/lib/apt/lists/*
+
+COPY --from=builder /opt/toolchain /opt/toolchain
+
+ENV PATH="/opt/toolchain/bin:${PATH}"
+
+CMD [ "/bin/bash" ]
diff --git a/Makefile b/Makefile
index 7531848..5ca38cf 100644
--- a/Makefile
+++ b/Makefile
@@ -4,13 +4,22 @@ BINUTILS_VERSION ?= 2.44
GCC_VERSION ?= 15.1.0
GDB_VERSION ?= 16.3
NEWLIB_VERSION ?= 4.5.0.20241231
+
+ZLIB_VERSION ?= 1.3.1
+NCURSES_VERSION ?= 6.4
+EXPAT_VERSION ?= 2.6.2
+READLINE_VERSION ?= 8.2
+GMP_VERSION ?= 6.2.1
+MPFR_VERSION ?= 4.1.0
+MPC_VERSION ?= 1.2.1
+
TARGET ?= x86_64-pc-elf
PLATFORM ?= x86-64
-IMAGE_BUILD ?= 4
+IMAGE_BUILD ?= 5
all:
- podman pull docker.io/archlinux:latest
+ podman pull docker.io/ubuntu:latest
podman build \
--volume $(mkfile_dir)downloads:/downloads \
--build-arg BINUTILS_VERSION=$(BINUTILS_VERSION) \
@@ -18,5 +27,12 @@ all:
--build-arg GDB_VERSION=$(GDB_VERSION) \
--build-arg NEWLIB_VERSION=$(NEWLIB_VERSION) \
--build-arg TARGET=$(TARGET) \
+ --build-arg ZLIB_VERSION=$(ZLIB_VERSION) \
+ --build-arg NCURSES_VERSION=$(NCURSES_VERSION) \
+ --build-arg EXPAT_VERSION=$(EXPAT_VERSION) \
+ --build-arg READLINE_VERSION=$(READLINE_VERSION) \
+ --build-arg GMP_VERSION=$(GMP_VERSION) \
+ --build-arg MPFR_VERSION=$(MPFR_VERSION) \
+ --build-arg MPC_VERSION=$(MPC_VERSION) \
--tag registry.gitlab.ost.ch:45023/teachos/devcontainers/$(PLATFORM):$(GCC_VERSION)-$(IMAGE_BUILD) \
.
diff --git a/scripts/0000-prepare-os.sh b/scripts/0000-prepare-os.sh
index 33b0deb..a2039ad 100755
--- a/scripts/0000-prepare-os.sh
+++ b/scripts/0000-prepare-os.sh
@@ -2,14 +2,21 @@
set -e
-pacman --noconfirm -Syu
+export DEBIAN_FRONTEND=noninteractive
-pacman --noconfirm --needed -S \
- base-devel \
- libelf \
- libmpc \
- zlib
+apt-get update
-pacman --noconfirm --needed --asdeps -S \
- gmp \
- mpfr
+apt-get install -y --no-install-recommends \
+ build-essential \
+ bison \
+ curl \
+ ca-certificates \
+ flex \
+ gawk \
+ libtool \
+ patch \
+ texinfo \
+ wget \
+ xz-utils
+
+rm -rf /var/lib/apt/lists/*
diff --git a/scripts/0100-download.sh b/scripts/0100-download.sh
index 03bd544..761fbf0 100755
--- a/scripts/0100-download.sh
+++ b/scripts/0100-download.sh
@@ -8,3 +8,11 @@ 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
+
+curl -LO -C - https://zlib.net/zlib-$ZLIB_VERSION.tar.gz
+curl -LO -C - https://ftp.gnu.org/gnu/ncurses/ncurses-$NCURSES_VERSION.tar.gz
+curl -LO -C - https://github.com/libexpat/libexpat/releases/download/R_${EXPAT_VERSION//./_}/expat-$EXPAT_VERSION.tar.gz
+curl -LO -C - https://ftp.gnu.org/gnu/readline/readline-$READLINE_VERSION.tar.gz
+curl -LO -C - https://ftp.gnu.org/gnu/gmp/gmp-$GMP_VERSION.tar.xz
+curl -LO -C - https://www.mpfr.org/mpfr-$MPFR_VERSION/mpfr-$MPFR_VERSION.tar.xz
+curl -LO -C - https://ftp.gnu.org/gnu/mpc/mpc-$MPC_VERSION.tar.gz
diff --git a/scripts/0150-build-static-deps.sh b/scripts/0150-build-static-deps.sh
new file mode 100755
index 0000000..d0a460f
--- /dev/null
+++ b/scripts/0150-build-static-deps.sh
@@ -0,0 +1,55 @@
+#!/bin/env bash
+
+set -e
+
+mkdir -p $STATIC_DEPS_PREFIX/include $STATIC_DEPS_PREFIX/lib
+mkdir -p /static-deps && cd /static-deps
+
+echo "Building static zlib..."
+tar xf /downloads/zlib-$ZLIB_VERSION.tar.gz
+cd zlib-$ZLIB_VERSION
+./configure --prefix=$STATIC_DEPS_PREFIX --static
+make -j$(nproc) && make install
+cd ..
+
+echo "Building static ncurses..."
+tar xf /downloads/ncurses-$NCURSES_VERSION.tar.gz
+cd ncurses-$NCURSES_VERSION
+./configure --prefix=$STATIC_DEPS_PREFIX --disable-shared --enable-static --with-termlib
+make -j$(nproc) && make install
+cd ..
+
+echo "Building static expat..."
+tar xf /downloads/expat-$EXPAT_VERSION.tar.gz
+cd expat-$EXPAT_VERSION
+./configure --prefix=$STATIC_DEPS_PREFIX --disable-shared --enable-static
+make -j$(nproc) && make install
+cd ..
+
+echo "Building static readline..."
+tar xf /downloads/readline-$READLINE_VERSION.tar.gz
+cd readline-$READLINE_VERSION
+./configure --prefix=$STATIC_DEPS_PREFIX --disable-shared --enable-static
+make -j$(nproc) && make install
+cd ..
+
+echo "Building static gmp..."
+tar xf /downloads/gmp-$GMP_VERSION.tar.xz
+cd gmp-$GMP_VERSION
+./configure --prefix=$STATIC_DEPS_PREFIX --disable-shared --enable-static
+make -j$(nproc) && make install
+cd ..
+
+echo "Building static mpfr..."
+tar xf /downloads/mpfr-$MPFR_VERSION.tar.xz
+cd mpfr-$MPFR_VERSION
+./configure --prefix=$STATIC_DEPS_PREFIX --with-gmp=$STATIC_DEPS_PREFIX --disable-shared --enable-static
+make -j$(nproc) && make install
+cd ..
+
+echo "Building static mpc..."
+tar xf /downloads/mpc-$MPC_VERSION.tar.gz
+cd mpc-$MPC_VERSION
+./configure --prefix=$STATIC_DEPS_PREFIX --with-gmp=$STATIC_DEPS_PREFIX --with-mpfr=$STATIC_DEPS_PREFIX --disable-shared --enable-static
+make -j$(nproc) && make install
+cd ..
diff --git a/scripts/0200-build-target-binutils.sh b/scripts/0200-build-target-binutils.sh
index 6afcc43..78974ec 100755
--- a/scripts/0200-build-target-binutils.sh
+++ b/scripts/0200-build-target-binutils.sh
@@ -14,7 +14,10 @@ cd .build
--enable-colored-disassembly \
--prefix=/opt/toolchain \
--target=$TARGET \
- --with-pic
+ --with-pic \
+ --with-zlib=yes \
+ CPPFLAGS="-I$STATIC_DEPS_PREFIX/include" \
+ LDFLAGS="-L$STATIC_DEPS_PREFIX/lib"
make -j$(nproc)
diff --git a/scripts/0300-build-bootstrap-gcc.sh b/scripts/0300-build-bootstrap-gcc.sh
index f5c28e7..e5ee70b 100755
--- a/scripts/0300-build-bootstrap-gcc.sh
+++ b/scripts/0300-build-bootstrap-gcc.sh
@@ -8,6 +8,8 @@ tar xf /downloads/gcc-$GCC_VERSION.tar.xz
cd gcc-$GCC_VERSION
+./contrib/download_prerequisites
+
for PATCH in $(ls /patches/gcc-$GCC_VERSION-$TARGET/*.patch); do
patch -p0 -i $PATCH
done
@@ -23,7 +25,11 @@ PATH=/opt/bootstrap/bin:/opt/toolchain/bin:$PATH
--enable-languages=c,c++ \
--prefix=/opt/bootstrap \
--target=$TARGET \
- --without-headers
+ --with-as=/opt/toolchain/bin/${TARGET}-as \
+ --with-ld=/opt/toolchain/bin/${TARGET}-ld \
+ --without-headers \
+ CPPFLAGS="-I$STATIC_DEPS_PREFIX/include" \
+ LDFLAGS="-L$STATIC_DEPS_PREFIX/lib"
make -j$(nproc) all-gcc
make install-gcc
diff --git a/scripts/0500-build-target-gcc.sh b/scripts/0500-build-target-gcc.sh
index e3053f8..47249f9 100755
--- a/scripts/0500-build-target-gcc.sh
+++ b/scripts/0500-build-target-gcc.sh
@@ -8,7 +8,7 @@ CFLAGS=${CFLAGS/-Werror=format-security/}
CXXFLAGS=${CXXFLAGS/-Werror=format-security/}
PATH=/opt/bootstrap/bin:/opt/toolchain/bin:$PATH
-../gcc-$GCC_VERSION/configure \
+../gcc-$GCC_VERSION/configure \
--disable-hosted-libstdcxx \
--disable-nls \
--disable-tm-clone-registry \
@@ -21,7 +21,9 @@ PATH=/opt/bootstrap/bin:/opt/toolchain/bin:$PATH
--prefix=/opt/toolchain \
--target=$TARGET \
--with-mcmodel=kernel \
- --with-newlib
+ --with-newlib \
+ CPPFLAGS="-I$STATIC_DEPS_PREFIX/include" \
+ LDFLAGS="-L$STATIC_DEPS_PREFIX/lib"
make -j$(nproc) all-gcc
make install-strip-gcc
diff --git a/scripts/0600-build-target-gdb.sh b/scripts/0600-build-target-gdb.sh
index 85184de..8e984d8 100755
--- a/scripts/0600-build-target-gdb.sh
+++ b/scripts/0600-build-target-gdb.sh
@@ -10,9 +10,18 @@ tar xf /downloads/gdb-$GDB_VERSION.tar.xz
cd .build
-../gdb-$GDB_VERSION/configure \
- --prefix=/opt/toolchain \
- --target=$TARGET
+../gdb-$GDB_VERSION/configure \
+ --prefix=/opt/toolchain \
+ --target=$TARGET \
+ --disable-nls \
+ --disable-werror \
+ --with-gmp=$STATIC_DEPS_PREFIX \
+ --with-mpfr=$STATIC_DEPS_PREFIX \
+ --with-python=no \
+ --with-expat=yes \
+ --with-zlib=yes \
+ CPPFLAGS="-I$STATIC_DEPS_PREFIX/include -I$STATIC_DEPS_PREFIX/include/ncursesw" \
+ LDFLAGS="-L$STATIC_DEPS_PREFIX/lib"
make -j$(nproc) all-gdb
make install-strip-gdb