stage1

Details
Source
FROM scratch AS base
ARG LIVE_BOOTSTRAP_SOURCE
ARG LIVE_BOOTSTRAP_VERSION
ARG M2LIBC_SOURCE
ARG M2LIBC_VERSION
COPY --from=stagex/bootstrap-stage0 /bin /usr/bin

FROM base AS sources
ADD fetch/${M2LIBC_SOURCE} .
ADD fetch/${LIVE_BOOTSTRAP_SOURCE} .

FROM base AS build
COPY --from=fetch . /external/distfiles/
COPY --from=sources M2libc-${M2LIBC_VERSION} /M2libc
COPY --from=sources live-bootstrap-${LIVE_BOOTSTRAP_VERSION}/steps steps
ENV ARCH=x86
ENV ARCH_DIR=x86
ENV FORCE_TIMESTAMPS=False
ENV CHROOT=True
ENV UPDATE_CHECKSUMS=True
ENV JOBS=2
ENV SWAP_SIZE=0
ENV INTERNAL_CI=False
ENV INTERACTIVE=False
ENV BARE_METAL=False
ENV DISK=sda1
ENV KERNEL_BOOTSTRAP=False
ENV BUILD_KERNELS=False
ENV CONFIGURATOR=False
ENV DISTFILES=/external/distfiles
ENV PREFIX=/usr
ENV BINDIR=${PREFIX}/bin
ENV LIBDIR=${PREFIX}/lib/mes
ENV INCDIR=${PREFIX}/include/mes
ENV SRCDIR=/steps
ENV TMPDIR=/tmp
ENV PATH=${BINDIR}:${PREFIX}/bin
ENV M2LIBC_PATH=/M2libc
ENV NYACC_PKG=nyacc-1.00.2
ENV MES_PKG=mes-0.27
ENV MES_PREFIX=${SRCDIR}/${MES_PKG}/build/${MES_PKG}
ENV GUILE_LOAD_PATH=${MES_PREFIX}/mes/module:${MES_PREFIX}/module:${SRCDIR}/${MES_PKG}/build/${NYACC_PKG}/module

WORKDIR ${TMPDIR}
WORKDIR ${BINDIR}
WORKDIR ${LIBDIR}
WORKDIR ${INCDIR}

SHELL ["/usr/bin/kaem","--verbose","--file"]

ENV pkg=checksum-transcriber-1.0
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=simple-patch-1.0
WORKDIR /steps/${pkg}
RUN pass1.kaem

# This step currently loads mescc over and over for every libc file
# Concatinating all libc files into one so mescc can be called only
# one time should dramatically speed up this step, as was done in
# tcc-0.9.26
ENV pkg=mes-0.27
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=tcc-0.9.26
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV GUILE_LOAD_PATH=

ENV pkg=tcc-0.9.27
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=make-3.82
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=patch-2.5.9
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=gzip-1.2.4
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=tar-1.12
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=sed-4.0.9
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=bzip2-1.0.8
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=coreutils-5.0
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=byacc-20240109
WORKDIR /steps/${pkg}
RUN pass1.kaem

ENV pkg=bash-2.05b
WORKDIR /steps/${pkg}
RUN pass1.kaem

WORKDIR /steps

ENV SHELL=/usr/bin/bash
ENV HOME=/tmp
ENV SOURCE_DATE_EPOCH=0
ENV KBUILD_BUILD_TIMESTAMP='@0'
ENV DESTDIR=/tmp/destdir
ENV LIBDIR=""
COPY --chmod=644 <<-EOF /etc/passwd
	root:x:0:0:root:/root:/bin/sh
EOF
COPY --chmod=644 <<-EOF /etc/group
	root:x:0:
EOF
SHELL ["/usr/bin/bash","-c"]
RUN <<-'EOF'
	set -eux
	mkdir -p /external/repo
	tar -cf - \
		--exclude='/external/repo/*' \
		--exclude='/external/repo-preseeded/*' \
		--exclude='/external/distfiles/*' \
		--exclude='/dev/*' \
		--exclude='/proc/*' \
		--exclude='/sys/*' \
		--exclude='/tmp/*' \
		/ \
	| bzip2 --best \
	> /external/repo/base.tar.bz2
	ln -s bin /usr/sbin
	for d in bin lib sbin; do
		ln -s "usr/${d}" "/${d}" || true;
	done
EOF
COPY --chmod=755 <<-'EOF' /shell.sh
	#!/usr/bin/bash
	set -ex
	JOBS=$(ls -1 /sys/bus/cpu/devices | wc -l | sed 's/^[ \t]*//')
	MAKEJOBS=-j${JOBS}
	. /steps/helpers.sh
	$@
EOF
SHELL ["/shell.sh"]

RUN build tcc-0.9.27 pass2.sh
ENV LIBDIR=${PREFIX}/lib/i386-unknown-linux-musl
RUN build musl-1.1.24 pass1.sh
RUN build tcc-0.9.27 pass3.sh
RUN build musl-1.1.24 pass2.sh
RUN build tcc-0.9.27 pass4.sh
RUN build sed-4.0.9 pass2.sh
RUN build bzip2-1.0.8 pass2.sh
RUN build m4-1.4.7 pass1.sh
RUN build heirloom-devtools-070527 pass1.sh
RUN build flex-2.5.11 pass1.sh
RUN build flex-2.6.4 pass1.sh
RUN uninstall heirloom-devtools-070527
RUN build bison-3.4.1 pass1.sh
RUN build bison-3.4.1 pass2.sh
RUN build bison-3.4.1 pass3.sh
RUN build grep-2.4 pass1.sh
RUN build diffutils-2.7 pass1.sh
RUN build coreutils-5.0 pass2.sh
RUN build coreutils-6.10 pass1.sh
RUN build gawk-3.0.4 pass1.sh
RUN build perl-5.000 pass1.sh
RUN build perl-5.003 pass1.sh
RUN build perl5.004-05 pass1.sh
RUN build perl5.005-03 pass1.sh
RUN build perl-5.6.2 pass1.sh
RUN uninstall perl-5.000 perl-5.003 perl5.004-05 perl5.005-03
RUN build autoconf-2.52 pass1.sh
RUN build automake-1.6.3 pass1.sh
RUN build automake-1.6.3 pass2.sh
RUN build autoconf-2.53 pass1.sh
RUN build automake-1.7 pass1.sh
RUN build autoconf-2.54 pass1.sh
RUN build autoconf-2.55 pass1.sh
RUN build automake-1.7.8 pass1.sh
RUN build autoconf-2.57 pass1.sh
RUN build autoconf-2.59 pass1.sh
RUN build automake-1.8.5 pass1.sh
RUN build help2man-1.36.4 pass1.sh
RUN build autoconf-2.61 pass1.sh
RUN build automake-1.9.6 pass1.sh
RUN build automake-1.10.3 pass1.sh
RUN build autoconf-2.64 pass1.sh
RUN build automake-1.11.2 pass1.sh
RUN build autoconf-2.69 pass1.sh
RUN build libtool-2.2.4 pass1.sh
RUN build automake-1.15.1 pass1.sh
RUN build binutils-2.30 pass1.sh
RUN build musl-1.1.24 pass3.sh
RUN build tcc-0.9.27 pass5.sh

# Fix to make copying Go toolchain files work
COPY copy-escape.patch /steps/
RUN ["bash", "-c", "patch -p1 < copy-escape.patch"]

COPY --chmod=644 <<-EOF go-1.4/pass1.sh
	src_compile() {
		cd src
		CC=tcc \\
		GOHOSTARCH=386 \\
		GOROOT="${PREFIX}/lib/go" \\
		GOROOT_FINAL="${PREFIX}/lib/go" \\
		GOBIN="${PREFIX}/lib/go/bin" \\
		bash -- make.bash -v=1 -d
		cd ..
	}

	src_install() {
		mkdir -p ${DESTDIR}${PREFIX}/lib/go

		rm -rf src/testdata

		cp -a bin lib pkg src ${DESTDIR}${PREFIX}/lib/go
	}
EOF
COPY --chmod=644 <<-EOF go-1.4/sources
	go1.4.src.tar.gz f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52
EOF
RUN build go-1.4 pass1.sh

COPY --chmod=644 <<-EOF go-1.19/pass1.sh
	src_compile() {
		cd src
		CGO_ENABLED=0 \\
		GOHOSTARCH=386 \\
		GOROOT_BOOTSTRAP=${PREFIX}/lib/go \\
		GOROOT_FINAL=${PREFIX}/lib/go \\
		bash -- make.bash -v=1 -d
		cd ..
	}

	src_install() {
		# Remove previous Go version, removing from / also required
		rm -rf ${PREFIX}/lib/go
		rm -rf ${DESTDIR}${PREFIX}/lib/go
		rm -rf ${DESTDIR}/tmp
		mkdir -p ${DESTDIR}${PREFIX}/lib/go

		# Remove paths that contain special files
		# that fail to copy
		rm -rf src/testdata
		rm -rf src/cmd/go/testdata

		cp -a bin lib pkg src ${DESTDIR}${PREFIX}/lib/go
	}
EOF
COPY --chmod=644 <<-EOF go-1.19/sources
	go1.19.11.src.tar.gz e25c9ab72d811142b7f41ff6da5165fec2d1be5feec3ef2c66bc0bdecb431489
EOF
RUN build go-1.19 pass1.sh

COPY --chmod=644 <<-EOF go-1.20/pass1.sh
	src_compile() {
		cd src
		CGO_ENABLED=0 \\
		GOHOSTARCH=386 \\
		GOROOT_BOOTSTRAP=${PREFIX}/lib/go \\
		GOROOT_FINAL=${PREFIX}/lib/go \\
		bash -- make.bash -v=1 -d
		rm -rf /tmp/.cache /tmp/.config
		cd ..
	}

	src_install() {
		# Remove previous Go version, removing from / also required
		rm -rf ${PREFIX}/lib/go
		rm -rf ${DESTDIR}${PREFIX}/lib/go
		rm -rf ${DESTDIR}/tmp
		mkdir -p ${DESTDIR}${PREFIX}/lib/go

		# Remove paths that contain special files
		# that fail to copy
		rm -rf src/testdata
		rm -rf src/cmd/go/testdata

		cp -a bin lib pkg src ${DESTDIR}${PREFIX}/lib/go
	}
EOF
COPY --chmod=644 <<-EOF go-1.20/sources
	go1.20.6.src.tar.gz 62ee5bc6fb55b8bae8f705e0cb8df86d6453626b4ecf93279e2867092e0b7f70
EOF
RUN build go-1.20 pass1.sh

COPY --chmod=644 <<-EOF go/pass1.sh
	src_compile() {
		cd src
		GOHOSTARCH=386 \\
		GOROOT_BOOTSTRAP=${PREFIX}/lib/go \\
		GOROOT_FINAL=${PREFIX}/lib/go \\
		bash -- make.bash -v=1 -d
		rm -rf /tmp/.cache /tmp/.config
		cd ..
	}

	src_install() {
		# Remove previous Go version, removing from / also required
		rm -rf ${PREFIX}/lib/go
		rm -rf ${DESTDIR}${PREFIX}/lib/go
		rm -rf ${DESTDIR}/tmp
		mkdir -p ${DESTDIR}${PREFIX}/lib/go

		# Remove paths that contain special files
		# that fail to copy
		rm -rf src/testdata
		rm -rf src/cmd/go/testdata

		cp -a bin lib pkg src ${DESTDIR}${PREFIX}/lib/go
	}
EOF
COPY --chmod=644 <<-EOF go/sources
	go1.23.5.src.tar.gz a6f3f4bbd3e6bdd626f79b668f212fbb5649daf75084fb79b678a0ae4d97423b
EOF
RUN build go pass1.sh

RUN build gcc-4.0.4 pass1.sh
RUN build findutils-4.2.33 pass1.sh
RUN build musl-1.2.4 pass1.sh
RUN build linux-headers-4.14.341-openela pass1.sh
RUN build gcc-4.0.4 pass2.sh
RUN build kbd-1.15 pass1.sh
RUN build make-3.82 pass2.sh
RUN ["/usr/bin/bash","-c","/usr/bin/bash","/steps/improve/clean_sources.sh"]
RUN build musl-1.2.4 pass2.sh
RUN build bash-5.2.15 pass1.sh
RUN build xz-5.4.1 pass1.sh
RUN build file-5.44 pass1.sh
RUN build libtool-2.4.7 pass1.sh
RUN build tar-1.34 pass1.sh
RUN build coreutils-9.4 pass1.sh
RUN build pkg-config-0.29.2 pass1.sh
RUN build make-4.2.1 pass1.sh
RUN build gmp-6.2.1 pass1.sh
RUN build autoconf-archive-2021.02.19 pass1.sh
RUN build mpfr-4.1.0 pass1.sh
RUN build mpc-1.2.1 pass1.sh
RUN build flex-2.5.33 pass1.sh
RUN build bison-2.3 pass1.sh
RUN build bison-3.4.2 pass1.sh
RUN build perl-5.10.1 pass1.sh
RUN build dist-3.5-236 pass1.sh
RUN build perl-5.32.1 pass1.sh
RUN uninstall perl-5.6.2 perl-5.10.1
RUN build libarchive-3.5.2 pass1.sh
RUN build zlib-1.2.13 pass1.sh
RUN build automake-1.16.3 pass1.sh
RUN build autoconf-2.71 pass1.sh
RUN build patch-2.7.6 pass1.sh
RUN build gettext-0.21 pass1.sh
RUN build texinfo-6.7 pass1.sh
RUN build gcc-4.7.4 pass1.sh
RUN build binutils-2.41 pass1.sh
RUN build gperf-3.1 pass1.sh
RUN build libunistring-0.9.10 pass1.sh
RUN build libffi-3.3 pass1.sh
RUN build libatomic_ops-7.6.10 pass1.sh
RUN build gc-8.0.4 pass1.sh
RUN build guile-3.0.9 pass1.sh
RUN build which-2.21 pass1.sh
RUN build grep-3.7 pass1.sh
RUN build sed-4.8 pass1.sh
RUN build autogen-5.18.16 pass1.sh
RUN build musl-1.2.4 pass3.sh
RUN build gcc-10.4.0 pass1.sh
RUN build binutils-2.41 pass2.sh
RUN build gcc-13.1.0 pass1.sh

FROM build AS install
WORKDIR /rootfs
SHELL ["/usr/bin/bash","-c"]
RUN <<-EOF
	set -ex
	mkdir -p tmp
	cp -R /lib /usr /bin /etc .
	rm etc/hosts etc/resolv.conf
EOF

FROM scratch AS package
COPY --from=install /rootfs /