bootstrap: linux headers and various cleanup & path fixes

This commit is contained in:
Lance Vick 2024-01-23 09:50:50 -08:00
parent b6d50d7124
commit 355322796f
Signed by: lrvick
GPG Key ID: 8E47A1EC35A1551D
2 changed files with 207 additions and 42 deletions

View File

@ -2,11 +2,14 @@ ARG REGISTRY=local
FROM ${REGISTRY}/stage1:latest as stage1
FROM stage1 as base
ENV TARGET=x86_64-linux-musl
ENV ARCH=x86_64
ENV TARGET=${ARCH}-linux-musl
ENV SYSROOT_DIR ${HOME}/build-sysroot
ENV GCC_VERSION 13.1.0
ENV GCC_FILE gcc-$GCC_VERSION.tar.xz
ENV GCC_SITE https://mirrors.kernel.org/gnu/gcc/gcc-${GCC_VERSION}
ENV GCC_HASH 61d684f0aa5e76ac6585ad8898a2427aade8979ed5e7f85492286c4dfc13ee86
ENV GCC_DIR ${HOME}/build-gcc
ENV GCC_DEP_SITE https://gcc.gnu.org/pub/gcc/infrastructure/
ENV GMP_FILE gmp-6.2.1.tar.bz2
ENV GMP_HASH eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c
@ -20,18 +23,23 @@ ENV MUSL_VERSION 1.2.4
ENV MUSL_SITE http://musl.libc.org
ENV MUSL_FILE musl-${MUSL_VERSION}.tar.gz
ENV MUSL_HASH 7a35eae33d5372a7c0da1188de798726f68825513b7ae3ebe97aaaa52114f039
ENV MUSL_DIR ${HOME}/build-musl
ENV LINUX_SITE https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/
ENV LINUX_VERSION 6.6
ENV LINUX_HASH d926a06c63dd8ac7df3f86ee1ffc2ce2a3b81a2d168484e76b5b389aba8e56d0
ENV LINUX_FILE linux-${LINUX_VERSION}.tar.xz
ENV LINUX_DIR ${HOME}/build-linux
ENV BINUTILS_VERSION 2.41
ENV BINUTILS_SITE https://ftp.gnu.org/gnu/binutils
ENV BINUTILS_FILE binutils-${BINUTILS_VERSION}.tar.xz
ENV BINUTILS_HASH ae9a5789e23459e59606e6714723f2d3ffc31c03174191ef0d015bdf06007450
ENV BINUTILS_DIR ${HOME}/build-binutils
ENV GCC_DIR ${HOME}/build-gcc
ENV MUSL_DIR ${HOME}/build-musl
ENV SYSROOT_DIR ${HOME}/build-sysroot
FROM base as fetch
WORKDIR ${HOME}
RUN set -eux; \
curl -OJ ${LINUX_SITE}/${LINUX_FILE}; \
echo "${LINUX_HASH} ${LINUX_FILE}" | sha256sum -c; \
curl -OJ ${GCC_SITE}/${GCC_FILE}; \
echo "${GCC_HASH} ${GCC_FILE}" | sha256sum -c; \
curl -OJ ${GCC_DEP_SITE}/${GMP_FILE}; \
@ -49,6 +57,7 @@ RUN set -eux; \
FROM fetch as extract
RUN set -eux; \
tar -xf ${LINUX_FILE}; \
tar -xzf ${MUSL_FILE}; \
tar -xf ${BINUTILS_FILE}; \
tar -xf ${GCC_FILE}; \
@ -144,6 +153,15 @@ RUN set -eux; \
WORKDIR ${GCC_DIR}
RUN make all
# Phase 7: Generate linux headers
WORKDIR ${HOME}/linux-${LINUX_VERSION}
RUN set -eux; \
make ARCH=${ARCH} headers; \
find usr/include -name '.*' -delete; \
rm usr/include/Makefile; \
rm usr/include/headers_check.pl; \
cp -rv usr/include ${LINUX_DIR}
FROM build as install
WORKDIR ${HOME}
USER 0:0
@ -153,9 +171,10 @@ RUN set -eux; \
env -C build-musl make DESTDIR=/rootfs/${TARGET} install; \
env -C build-gcc make DESTDIR=/rootfs/ install; \
env -C build-binutils make DESTDIR=/rootfs/ install; \
cp -Rv ${LINUX_DIR}/* /rootfs/${TARGET}/include; \
ln -s /usr/lib/ld-musl-i386.so.1 /rootfs/lib/libc.so; \
ln -s /usr/lib/ld-musl-i386.so.1 /rootfs/lib/ld-musl-i386.so.1; \
ln -s /${TARGET}/lib/ld-musl-x86_64.so.1 /rootfs/lib/ld-musl-x86_64.so.1; \
ln -s /${TARGET}/lib/ld-musl-${ARCH}.so.1 /rootfs/lib/ld-musl-${ARCH}.so.1; \
find /rootfs -exec touch -hcd "@0" "{}" +
FROM scratch as package

View File

@ -2,89 +2,235 @@ ARG REGISTRY=local
FROM ${REGISTRY}/stage2 as stage2
FROM stage2 as base
ENV TARGET=x86_64-linux-musl
ENV ARCH=x86_64
ENV TARGET=${ARCH}-linux-musl
ENV BUILD=i386-unknown-linux-musl
ENV KCONFIG_NOTIMESTAMP=1
ENV MUSL_VERSION 1.2.4
ENV MUSL_SITE http://musl.libc.org/releases
ENV MUSL_FILE musl-${MUSL_VERSION}.tar.gz
ENV MUSL_HASH 7a35eae33d5372a7c0da1188de798726f68825513b7ae3ebe97aaaa52114f039
ENV MUSL_DIR=${HOME}/build-musl
ENV BASH_SITE=https://ftp.gnu.org/gnu/bash
ENV BASH_VERSION_=5.2.21
ENV BASH_HASH c8e31bdc59b69aaffc5b36509905ba3e5cbb12747091d27b4b977f078560d5b8
ENV BASH_FILE bash-${BASH_VERSION_}.tar.gz
ENV BASH_DIR=${HOME}/build-bash
ENV COREUTILS_SITE=https://ftp.gnu.org/gnu/coreutils
ENV COREUTILS_VERSION=9.4
ENV COREUTILS_HASH 5f600d9093973b0afe25393d9bc18c44f2232657f4ca0d95ea31c702eb66b739
ENV COREUTILS_FILE coreutils-${COREUTILS_VERSION}.tar.gz
ENV COREUTILS_DIR=${HOME}/build-coreutils
ENV BUSYBOX_VERSION=1.35.0
ENV BUSYBOX_HASH=faeeb244c35a348a334f4a59e44626ee870fb07b6884d68c10ae8bc19f83a694
ENV BUSYBOX_SITE=https://busybox.net/downloads
ENV BUSYBOX_FILE=busybox-${BUSYBOX_VERSION}.tar.bz2
ENV BUSYBOX_DIR ${HOME}/build-busybox
ENV BINUTILS_VERSION 2.41
ENV BINUTILS_HASH ae9a5789e23459e59606e6714723f2d3ffc31c03174191ef0d015bdf06007450
ENV BINUTILS_SITE https://ftp.gnu.org/gnu/binutils
ENV BINUTILS_FILE binutils-${BINUTILS_VERSION}.tar.xz
ENV BINUTILS_DIR ${HOME}/build-binutils
ENV MAKE_VERSION 4.4
ENV MAKE_HASH 581f4d4e872da74b3941c874215898a7d35802f03732bdccee1d4a7979105d18
ENV MAKE_SITE https://ftp.gnu.org/gnu/make
ENV MAKE_FILE make-${MAKE_VERSION}.tar.gz
ENV MAKE_DIR ${HOME}/build-make
ENV GCC_VERSION 13.1.0
ENV GCC_HASH 61d684f0aa5e76ac6585ad8898a2427aade8979ed5e7f85492286c4dfc13ee86
ENV GCC_SITE https://mirrors.kernel.org/gnu/gcc/gcc-${GCC_VERSION}
ENV GCC_FILE gcc-$GCC_VERSION.tar.xz
ENV GCC_DIR ${HOME}/build-gcc
ENV GMP_VERSION 6.2.1
ENV GMP_HASH eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c
ENV GMP_SITE https://gcc.gnu.org/pub/gcc/infrastructure/
ENV GMP_FILE gmp-${GMP_VERSION}.tar.bz2
ENV GMP_DIR ${HOME}/build-gmp
ENV MPFR_VERSION 4.1.0
ENV MPFR_HASH feced2d430dd5a97805fa289fed3fc8ff2b094c02d05287fd6133e7f1f0ec926
ENV MPFR_SITE https://gcc.gnu.org/pub/gcc/infrastructure/
ENV MPFR_FILE mpfr-${MPFR_VERSION}.tar.bz2
ENV MPFR_DIR ${HOME}/build-mpfr
ENV MPC_VERSION 1.2.1
ENV MPC_HASH 17503d2c395dfcf106b622dc142683c1199431d095367c6aacba6eec30340459
ENV MPC_SITE https://gcc.gnu.org/pub/gcc/infrastructure/
ENV MPC_FILE mpc-${MPC_VERSION}.tar.gz
ENV MPC_DIR ${HOME}/build-mpc
ENV ISL_VERSION 0.24
ENV ISL_HASH fcf78dd9656c10eb8cf9fbd5f59a0b6b01386205fe1934b3b287a0a1898145c0
ENV ISL_SITE https://gcc.gnu.org/pub/gcc/infrastructure/
ENV ISL_FILE isl-${ISL_VERSION}.tar.bz2
ENV ISL_DIR ${HOME}/build-isl
ENV LINUX_SITE https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/
ENV LINUX_VERSION 6.6
ENV LINUX_HASH d926a06c63dd8ac7df3f86ee1ffc2ce2a3b81a2d168484e76b5b389aba8e56d0
ENV LINUX_FILE linux-${LINUX_VERSION}.tar.xz
ENV LINUX_DIR ${HOME}/build-linux
FROM base as fetch
WORKDIR /home/user
RUN set -eux; \
curl -OJ ${LINUX_SITE}/${LINUX_FILE}; \
echo "${LINUX_HASH} ${LINUX_FILE}" | sha256sum -c; \
curl --insecure -OJ ${MUSL_SITE}/${MUSL_FILE}; \
echo "${MUSL_HASH} ${MUSL_FILE}" | sha256sum -c; \
curl --insecure -OJ ${BASH_SITE}/${BASH_FILE}; \
echo "${BASH_HASH} ${BASH_FILE}" | sha256sum -c; \
curl --insecure -OJ ${COREUTILS_SITE}/${COREUTILS_FILE}; \
echo "${COREUTILS_HASH} ${COREUTILS_FILE}" | sha256sum -c
curl --insecure -OJ ${BUSYBOX_SITE}/${BUSYBOX_FILE}; \
echo "${BUSYBOX_HASH} ${BUSYBOX_FILE}" | sha256sum -c; \
curl --insecure -OJ ${BINUTILS_SITE}/${BINUTILS_FILE}; \
echo "${BINUTILS_HASH} ${BINUTILS_FILE}" | sha256sum -c; \
curl --insecure -OJ ${MAKE_SITE}/${MAKE_FILE}; \
echo "${MAKE_HASH} ${MAKE_FILE}" | sha256sum -c; \
curl --insecure -OJ ${GCC_SITE}/${GCC_FILE}; \
echo "${GCC_HASH} ${GCC_FILE}" | sha256sum -c; \
curl --insecure -OJ ${GMP_SITE}/${GMP_FILE}; \
echo "${GMP_HASH} ${GMP_FILE}" | sha256sum -c; \
curl --insecure -OJ ${MPFR_SITE}/${MPFR_FILE}; \
echo "${MPFR_HASH} ${MPFR_FILE}" | sha256sum -c; \
curl --insecure -OJ ${MPC_SITE}/${MPC_FILE}; \
echo "${MPC_HASH} ${MPC_FILE}" | sha256sum -c; \
curl --insecure -OJ ${ISL_SITE}/${ISL_FILE}; \
echo "${ISL_HASH} ${ISL_FILE}" | sha256sum -c
FROM fetch as build
FROM fetch as extract
RUN set -eux; \
tar -xzf ${MUSL_FILE}; \
tar -xzf ${BASH_FILE}; \
tar -xzf ${COREUTILS_FILE}
tar -xf ${LINUX_FILE}; \
tar -kxzf ${MUSL_FILE}; \
tar -kxjf ${BUSYBOX_FILE}; \
tar -kxf ${BINUTILS_FILE}; \
tar -kxzf ${MAKE_FILE}; \
tar -kxf ${GCC_FILE}
FROM extract as build
WORKDIR ${MUSL_DIR}
RUN set -eux; \
../musl-${MUSL_VERSION}/configure \
--prefix= \
--prefix=/usr \
--build=${BUILD} \
--host=${TARGET}; \
make
WORKDIR ${BASH_DIR}
WORKDIR ${BINUTILS_DIR}
RUN set -eux; \
echo "${BASH_VERSION_}"; \
../bash-${BASH_VERSION_}/configure \
../binutils-${BINUTILS_VERSION}/configure \
--build=${BUILD} \
--host=${TARGET} \
--prefix=/usr \
--bindir=/bin \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--sysconfdir=/etc \
--disable-nls \
--enable-readline \
--without-curses \
--without-bash-malloc; \
--disable-werror \
--disable-gprofng \
--disable-multilib \
--disable-gdb \
--enable-deterministic-archives \
--enable-threads \
--with-mmap \
--with-pic; \
make
WORKDIR ${COREUTILS_DIR}
RUN set -eux; \
echo "${COREUTILS_VERSION}"; \
../coreutils-${COREUTILS_VERSION}/configure \
WORKDIR ${MAKE_DIR}
RUN set -ex; \
../make-${MAKE_VERSION}/configure \
--build=${BUILD} \
--host=${TARGET} \
--prefix=/usr \
--bindir=/bin \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--disable-nls; \
make
WORKDIR ${GCC_DIR}
RUN set -eux; \
cp ../*.tar.* ../gcc-${GCC_VERSION}; \
env -C ${HOME}/gcc-${GCC_VERSION} ./contrib/download_prerequisites; \
../gcc-${GCC_VERSION}/configure \
--build=${BUILD} \
--host=${TARGET} \
--target=${TARGET} \
--prefix=/usr \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--libdir=/usr/lib \
--disable-cet \
--disable-fixed-point \
--disable-libstdcxx-pch \
--disable-multilib \
--disable-libsanitizer \
--disable-nls \
--enable-single-binary=symlinks; \
--disable-werror \
--enable-__cxa_atexit \
--enable-default-pie \
--enable-default-ssp \
--enable-languages=c,c++ \
--enable-link-serialization=2 \
--enable-linker-build-id; \
make
WORKDIR ${BUSYBOX_DIR}
RUN set -eux; \
setConfs=' \
CONFIG_AR=y \
CONFIG_FEATURE_AR_CREATE=y \
CONFIG_FEATURE_AR_LONG_FILENAMES=y \
CONFIG_LAST_SUPPORTED_WCHAR=0 \
CONFIG_STATIC=y \
'; \
unsetConfs=' \
CONFIG_FEATURE_SYNC_FANCY \
CONFIG_FEATURE_HAVE_RPC \
CONFIG_FEATURE_INETD_RPC \
CONFIG_FEATURE_UTMP \
CONFIG_FEATURE_WTMP \
'; \
make \
-f ../busybox-${BUSYBOX_VERSION}/Makefile \
KBUILD_SRC=../busybox-${BUSYBOX_VERSION} \
CROSS_COMPILE=${TARGET}- \
defconfig; \
for conf in $unsetConfs; do \
sed -i \
-e "s!^$conf=.*\$!# $conf is not set!" \
.config; \
done; \
for confV in $setConfs; do \
conf="${confV%=*}"; \
sed -i \
-e "s!^$conf=.*\$!$confV!" \
-e "s!^# $conf is not set\$!$confV!" \
.config; \
if ! grep -q "^$confV\$" .config; then \
echo "$confV" >> .config; \
fi; \
done; \
make oldconfig CROSS_COMPILE=${TARGET}-; \
for conf in $unsetConfs; do \
! grep -q "^$conf=" .config; \
done; \
for confV in $setConfs; do \
grep -q "^$confV\$" .config; \
done; \
make CROSS_COMPILE=${TARGET}-
# Phase 7: Generate linux headers
WORKDIR ${HOME}/linux-${LINUX_VERSION}
RUN set -eux; \
make ARCH=${ARCH} headers; \
find usr/include -name '.*' -delete; \
rm usr/include/Makefile; \
rm usr/include/headers_check.pl; \
cp -rv usr/include ${LINUX_DIR}
FROM build as install
USER 0:0
RUN set -eux; \
env -C ${MUSL_DIR} make DESTDIR=/rootfs install; \
env -C ${BASH_DIR} make DESTDIR=/rootfs install; \
env -C ${COREUTILS_DIR} make DESTDIR=/rootfs install; \
env -C ${BINUTILS_DIR} make DESTDIR=/rootfs install; \
env -C ${MAKE_DIR} make DESTDIR=/rootfs install; \
env -C ${GCC_DIR} make DESTDIR=/rootfs install; \
env -C ${BUSYBOX_DIR} make \
CROSS_COMPILE=${TARGET}- \
CONFIG_PREFIX=/rootfs \
install ; \
cp -Rv ${LINUX_DIR}/* /rootfs/usr/include/; \
mkdir -p /home/user; \
find /rootfs -exec touch -hcd "@0" "{}" +
FROM scratch as package
COPY --from=install /rootfs /
USER 1000:1000
ENTRYPOINT ["/bin/bash"]
ENV PATH=/x86_64-linux-musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENTRYPOINT ["/bin/sh"]
ENV ARCH=x86_64
ENV TARGET=${ARCH}-linux-musl
ENV HOST=${TARGET}
ENV BUILD=${TARGET}
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV USER=user
ENV HOME=/home/user
ENV TZ=UTC