--- /dev/null
+FROM docker.io/debian:bookworm
+
+#
+# Create the container: podman build -t . gcc-4.8
+# Build the cross compilers:
+# mkdir -p ~/gcc-4.8
+# for i in aarch64-linux-gnu arm-linux-gnueabihf i686-linux-gnu powerpc64le-linux-gnu powerpc-linux-gnu riscv64-linux-gnu s390x-linux-gnu ; do podman run --rm -e "TARGET=$i" -v ~/gcc-4.8:/output localhost/gcc-4.8 ; done
+# tar -czf ~/gcc-4.8.tgz -C ~/gcc-4.8 ./
+
+RUN echo 'deb-src http://deb.debian.org/debian bookworm main contrib' >> /etc/apt/sources.list
+RUN apt-get update
+
+RUN apt-get -y --force-yes build-dep gcc-12
+RUN apt-get -y --force-yes install wget
+#RUN apt-get -y --force-yes install -t jessie cross-gcc-dev
+RUN mkdir -p /src/build /src/patches /output
+WORKDIR /src
+RUN wget -q -O - https://github.com/gcc-mirror/gcc/archive/refs/tags/releases/gcc-4.8.5.tar.gz | tar -xzf -
+WORKDIR /src/patches
+
+# This patch fixes builds with more recent versions of texinfo
+RUN wget -q https://aur.archlinux.org/cgit/aur.git/plain/gcc.texi.49.patch?h=gcc48 -O 01-texi.patch.0
+
+# This patch updates the program search directions and installation directories
+# to match those used by the Debian packages, so we can piggy-back on the modern
+# toolchain binaries (eg. binutils--arch64-linux-gnu)
+RUN wget -q https://salsa.debian.org/toolchain-team/gcc/-/raw/gcc-4.8-debian/debian/patches/cross-install-location.diff -O 02-cross_install_dir.patch.2
+
+WORKDIR /src/build
+COPY script.sh /usr/bin/build-gcc.sh
+CMD /usr/bin/build-gcc.sh
+
+# @TODO: missing crtbegin.o eg., libgcc-4.8-dev-arm64-cross
+# This can be "worked around" by copying the system libc-cross
+# eg.
+# cp -r /usr/lib/gcc-cross/aarch64-linux-gnu/12/ /usr/lib/gcc-cross/aarch64-linux-gnu/4.8.5
+# make
+#
--- /dev/null
+#!/bin/bash -x
+
+SRC_DIR="${SRC_DIR:-/src/gcc-releases-gcc-4.8.5}"
+PATCH_DIR="${PATCH_DIR:-/src/patches}"
+TARGET="${TARGET:-aarch64-linux-gnu}"
+HOST="${HOST:-x86_64-linux-gnu}"
+CONFIGURE_ARGS="${CONFIGURE_ARGS:-}"
+MAKE_ARGS="${MAKE_ARGS:-}"
+MAKE_INSTALL_ARGS="${MAKE_INSTALL_ARGS:-}"
+
+OWD="$(pwd)"
+cd "${SRC_DIR}" || exit 1
+while read -r line ; do
+ EXT=$(echo "$line" | rev | cut -d. -f1 | rev)
+ PATCH_LEVEL=1
+ if [[ "${EXT}" =~ [0-9]+ ]] ; then
+ PATCH_LEVEL="${EXT}"
+ fi
+ patch -p"${PATCH_LEVEL}" < "${line}"
+done < <(find "${PATCH_DIR}" -type f)
+cd "${OWD}"
+
+TARGET_ARGS=()
+case "${TARGET}" in
+ aarch64-linux-gnu)
+ TARGET_ARGS+=(
+ --enable-fix-cortex-a64-84319
+ )
+ ;;
+ arm-linux-gnueabihf)
+ TARGET_ARGS+=(
+ --with-arch=armv7-a
+ --with-float=hard
+ --with-fpu=vfpv3-d16
+ --with-mode=thumb
+ )
+ ;;
+ i686-linux-gnu)
+ TARGET_ARGS+=(
+ --with-arch-i686
+ --with-tune=generic
+ )
+ ;;
+ powerpc64le-linux-gnu)
+ TARGET_ARGS+=(
+ --enable-secureplt
+ --enable-targets=powerpcle-linux
+ --with-cpu=power8
+ --with-long-double-128
+ )
+ ;;
+ powerpc-linux-gnu)
+ TARGET_ARGS+=(
+ --disable-softfloat
+ --enable-secureplt
+ --enable-targets=powerpc-linux,powerpc64-linux
+ --with-cpu=default32
+ --with-long-double-128
+ )
+ ;;
+ riscv64-linux-gnu)
+ echo "Not supported in gcc-4.8"
+ exit 0
+ ;;
+ s390x-linux-gnu)
+ TARGET_ARGS+=(
+ --with-arch=zEC12
+ --with-long-double-128
+ )
+ ;;
+ *)
+ echo "Unrecognized target: ${TARGET}"
+ exit 0
+ ;;
+esac
+
+"${SRC_DIR}/configure" --build="${HOST}" --host="${HOST}" --enable-languages=c,c++ \
+ --program-prefix="${TARGET}-" --target="${TARGET}" --program-suffix=-4.8 \
+ --prefix=/usr/ --with-system-zlib \
+ --libexecdir=/usr/lib/ --libdir=/usr/lib/ \
+ --disable-nls --disable-shared --enable-host-shared \
+ --disable-bootstrap --enable-threads=posix --enable-default-pie \
+ --with-sysroot=/ --includedir=/usr/"${TARGET}"/include \
+ --without-target-system-zlib --enable-multiarch
+ ${TARGET_ARGS[@]} ${CONFIGURE_ARGS} \
+ CFLAGS='-std=gnu99' CXXFLAGS='-std=gnu++98'
+
+make -j"${NPROC:-$(nproc)}" ${MAKE_ARGS} \
+ CFLAGS='-std=gnu99' CXXFLAGS='-std=gnu++98'
+
+make install ${MAKE_INSTALL_ARGS}
+mkdir -p /output/usr/lib/ /output/usr/bin/
+cp -r /usr/lib/gcc-cross /output/usr/lib/
+cp /usr/bin/*-4.8 /output/usr/bin/
- name: Ensure cross-compilers packages are installed.
apt: "name={{ cross_compilers_packages }} state=present"
+
+- name: Install legacy cross compilers
+ when: ansible_distribution == 'Debian' and ansible_architecture == 'x86_64'
+ block:
+ # This step needs to happen after the cross compiler packages are installed
+ # so the libgcc cross libraries can be copied
+ - name: Copy gcc-cross libs
+ ansible.builtin.command:
+ argv: ['cp', '-r', "/usr/lib/gcc-cross/{{item}}/12/", "/usr/lib/gcc-cross/{{item}}/4.8.5"]
+ creates: "/usr/lib/gcc-cross/{{item}}/4.8.5"
+ with_items:
+ - aarch64-linux-gnu
+ - arm-linux-gnueabihf
+ - i686-linux-gnu
+ - powerpc64le-linux-gnu
+ - powerpc-linux-gnu
+ - riscv64-linux-gnu
+ - s390x-linux-gnu
+ - name: Download legacy compiler binaries
+ # These binaries built from files/Containerfile
+ ansible.builtin.get_url:
+ url: https://obj.internal.efficios.com/jenkins/gcc-4.8-x86_64-linux-gnu-cross.tgz
+ dest: /root/gcc-4.8-x86_64-linux-gnu-cross.tgz
+ register: cross_download
+ - name: Extract legacy compiler binaries
+ when: cross_download.changed
+ ansible.builtin.command:
+ argv: ['tar', '-C', '/', '-xzf', '/root/gcc-4.8-x86_64-linux-gnu-cross.tgz']