# vim:set ft=sh: git clone --depth=1 --recursive https://github.com/fosslinux/live-bootstrap cd live-bootstrap ./rootfs.py -c --external-sources --cores $(nproc) umount target/dev/shm # double mounted? umount target/dev/shm target/sys target/proc target/tmp # Optional: back up the system env -i chroot target tar --sort=name -cf /target.tar / env -i chroot target bzip2 -9v /target.tar # Goal: # install cross compiler in /cross # cross compiled system in /gentoo mount -t proc proc target/proc mount -t sysfs sysfs target/sys mount -t devtmpfs devtmpfs target/dev mount -t devpts devpts target/dev/pts env -i chroot target source /steps/env cd /tmp curl -LO https://github.com/ninja-build/ninja/archive/v1.11.1/ninja-1.11.1.tar.gz curl -LO https://github.com/mesonbuild/meson/releases/download/1.4.1/meson-1.4.1.tar.gz curl -LO http://gitweb.gentoo.org/proj/portage.git/snapshot/portage-3.0.65.tar.bz2 curl -LO https://github.com/plougher/squashfs-tools/archive/refs/tags/4.6.1/squashfs-tools-4.6.1.tar.gz curl -LO http://distfiles.gentoo.org/snapshots/squashfs/gentoo-20240801.xz.sqfs cat > portage.patch << 'EOF' +++ b/lib/portage/util/compression_probe.py @@ -1,13 +1,13 @@ # Copyright 2015-2020 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 -import ctypes import errno import re from portage import _encodings, _unicode_encode from portage.exception import FileNotFound, PermissionDenied +from portage.util._ctypes import ctypes _compressors = { "bzip2": { @@ -49,7 +49,7 @@ _compressors = { # if the current architecture can support it, which is true when # sizeof(long) is at least 8 bytes. "decompress": "zstd -d" - + (" --long=31" if ctypes.sizeof(ctypes.c_long) >= 8 else ""), + + (" --long=31" if ctypes and ctypes.sizeof(ctypes.c_long) >= 8 else ""), "package": "app-arch/zstd", }, } EOF tar xf ninja-1.11.1.tar.gz cd ninja-1.11.1 ./configure.py --bootstrap install -m755 ninja /usr/bin cd .. rm -rf ninja-1.11.1 tar xf meson-1.4.1.tar.gz cd meson-1.4.1 python setup.py install cd .. rm -rf meson-1.4.1 tar xf portage-3.0.65.tar.bz2 cd portage-3.0.65 patch -p1 -i ../portage.patch meson setup build --prefix /usr meson install -C build cd .. rm -rf portage-3.0.65 tar xf squashfs-tools-4.6.1.tar.gz cd squashfs-tools-4.6.1 make -C squashfs-tools install \ INSTALL_PREFIX=/usr \ XZ_SUPPORT=1 cd .. rm -rf squashfs-tools-4.6.1 unsquashfs gentoo-20240801.xz.sqfs mkdir -p /var/db/repos rm -rf /var/db/repos/gentoo mv squashfs-root /var/db/repos/gentoo # Configure portage echo 'portage:x:250:250:portage:/var/tmp/portage:/bin/false' >> /etc/passwd echo 'portage::250:portage' >> /etc/group mkdir -p /etc/portage/make.profile cat > /etc/portage/make.profile/make.defaults << 'EOF' FEATURES="-news -sandbox -usersandbox -pid-sandbox -parallel-fetch" BINPKG_COMPRESS="bzip2" ARCH="x86" ABI="$ARCH" DEFAULT_ABI="$ARCH" ACCEPT_KEYWORDS="$ARCH" CHOST="i386-unknown-linux-musl" LIBDIR_x86="lib/i386-unknown-linux-musl" PKG_CONFIG_PATH="/usr/lib/i386-unknown-linux-musl/pkgconfig" PYTHON_COMPAT_OVERRIDE="python3_11" IUSE_IMPLICIT="kernel_linux elibc_glibc elibc_musl prefix prefix-guest" USE="kernel_linux elibc_musl python_targets_python3_11" EOF # Install extra dependencies FETCHCOMMAND="curl -o \"\${DISTDIR}/\${FILE}\" -L \"\${URI}\"" FETCHCOMMAND="$FETCHCOMMAND" MAKEOPTS=-j1 emerge -O1 dev-build/make FETCHCOMMAND="$FETCHCOMMAND" emerge -O1 app-arch/lzip FETCHCOMMAND="$FETCHCOMMAND" emerge -O1 net-misc/wget # Fix "find" warnings in emerge emerge -O1 sys-apps/findutils # Set up python for dev-build/meson-format-array py=python3.11 mkdir -p /usr/lib/python-exec/$py ln -sv python3 /usr/lib/python-exec/$py/python ln -svr /usr/bin/$py /usr/lib/python-exec/$py/python3 emerge -O1 dev-lang/python-exec # Allow stripping binaries by installing "scanelf" emerge -O1 dev-build/meson-format-array emerge -O1 app-misc/pax-utils # Install tooling around autoconf/automake for sys-devel/binutils and sys-devel/gcc emerge -O1 sys-devel/gnuconfig sys-apps/gentoo-functions app-portage/elt-patches sys-devel/binutils-config sys-devel/gcc-config # Install rsync for sys-kernel/linux-headers emerge -O1 dev-build/autoconf dev-build/autoconf-wrapper emerge -O1 dev-build/automake dev-build/automake-wrapper emerge -O1 net-misc/rsync # Set up cross compiler mkdir -p /cross/etc/portage ln -sf /etc/portage/make.profile /cross/etc/portage/make.profile cat > /cross/etc/portage/make.conf << 'EOF' USE="prefix multilib" CTARGET="x86_64-bootstrap-linux-gnu" LIBDIR_x86="lib" LIBDIR_amd64="lib64" DEFAULT_ABI="amd64" MULTILIB_ABIS="amd64 x86" EOF mkdir -p /cross/etc/portage/env/sys-devel cat > /cross/etc/portage/env/sys-devel/gcc << 'EOF' EXTRA_ECONF='--with-sysroot=$EPREFIX/usr/$CTARGET' EOF cat > /cross/etc/portage/package.use << 'EOF' sys-devel/gcc -sanitize EOF #EXTRA_EMAKE='MAKE=make MAKE+=libsuffix=../lib64' # Set path for emerge builds cat > /etc/env.d/50baselayout << 'EOF' PATH=/cross/usr/bin:/usr/bin ROOTPATH=/cross/usr/bin:/usr/bin EOF env-update # TODO: Build sys-libs/glibc in /gentoo instead, to avoid extra rebuilding PORTAGE_CONFIGROOT=/cross EPREFIX=/cross emerge -O1 sys-devel/binutils PORTAGE_CONFIGROOT=/cross EPREFIX=/cross USE='headers-only' emerge -O1 sys-kernel/linux-headers PORTAGE_CONFIGROOT=/cross EPREFIX=/cross USE='headers-only -multilib' emerge -O1 sys-libs/glibc PORTAGE_CONFIGROOT=/cross EPREFIX=/cross USE='-cxx -fortran' emerge -O1 sys-devel/gcc PORTAGE_CONFIGROOT=/cross EPREFIX=/cross emerge -O1 sys-kernel/linux-headers PORTAGE_CONFIGROOT=/cross EPREFIX=/cross emerge -O1 sys-libs/glibc PORTAGE_CONFIGROOT=/cross EPREFIX=/cross emerge -O1 sys-devel/gcc # Get extra BDEPENDs for the final system emerge -O1 dev-util/pkgconf # dev-lang/python requires --keep-system-libs emerge -O1 dev-libs/mpdecimal # dev-lang/python (host) emerge -O1 dev-libs/expat # dev-lang/python (host) # TODO: verify bzip2 dep mv /bin/bzip2 /bin/bzip2-reference ln -s bzip2-reference /bin/bzip2 emerge -O1 app-arch/bzip2 # dev-lang/python (build) # TODO: move python build so we don't need python-exec hack # ... or switch to only using python3.11 USE='-*' emerge -O1 dev-lang/python # cross compiling python programs needs same version emerge -O1 dev-lang/python-exec-conf USE='python_targets_python3_12' emerge -O1 dev-lang/python-exec # Allow meson to still be ran despite python upgrade PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/gpep517 emerge -O1 app-arch/unzip PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/installer PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/flit-core PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/packaging PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/more-itertools PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/ordered-set PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/jaraco-text PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/jaraco-functools PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/jaraco-context PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/wheel PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-python/setuptools PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 dev-build/meson PYTHON_COMPAT_OVERRIDE=python3_12 emerge -O1 sys-apps/portage # Reconfigure cross toolchain for final system cat > /cross/usr/lib/gcc/x86_64-bootstrap-linux-gnu/specs << 'EOF' *link: + %{!shared:%{!static:%{!static-pie:-dynamic-linker %{m32:/lib/ld-linux.so.2;:/lib64/ld-linux-x86-64.so.2}}}} EOF for tool in gcc g++; do rm -f /cross/usr/bin/x86_64-bootstrap-linux-gnu-$tool cat > /cross/usr/bin/x86_64-bootstrap-linux-gnu-$tool << EOF #!/bin/sh exec /cross/usr/i386-unknown-linux-musl/x86_64-bootstrap-linux-gnu/gcc-bin/*/x86_64-bootstrap-linux-gnu-$tool --sysroot=/gentoo "\$@" EOF chmod +x /cross/usr/bin/x86_64-bootstrap-linux-gnu-$tool done # TODO: Do I need this? cat > /cross/usr/bin/x86_64-bootstrap-linux-gnu-pkg-config << 'EOF' #!/bin/sh export PKG_CONFIG_SYSROOT_DIR=/gentoo export PKG_CONFIG_LIBDIR=/gentoo/usr/lib64/pkgconfig export PKG_CONFIG_PATH=/gentoo/usr/share/pkgconfig export PKG_CONFIG_SYSTEM_INCLUDE_PATH=/gentoo/usr/include export PKG_CONFIG_SYSTEM_LIBRARY_PATH=/gentoo/lib64:/gentoo/usr/lib64 exec pkg-config "$@" EOF chmod +x /cross/usr/bin/x86_64-bootstrap-linux-gnu-pkg-config # Compile final system (hopefully) # TODO: Try to get rid of CFLAGS_x86 override mkdir -p /gentoo/etc/portage ln -sf /var/db/repos/gentoo/profiles/default/linux/amd64/23.0 /gentoo/etc/portage/make.profile cat > /gentoo/etc/portage/make.conf << 'EOF' FEATURES="-news -sandbox -usersandbox -pid-sandbox -parallel-fetch" BINPKG_COMPRESS="bzip2" CBUILD="i386-unknown-linux-musl" CHOST="x86_64-bootstrap-linux-gnu" CFLAGS_x86=-m32 USE="-* build python_targets_$PYTHON_SINGLE_TARGET" CONFIG_SITE="$PORTAGE_CONFIGROOT/etc/portage/config.site" EOF cat > /gentoo/etc/portage/config.site << 'EOF' if [ "${CBUILD:-${CHOST}}" != "${CHOST}" ]; then # Settings grabbed from crossdev ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no fi EOF # TODO: Build gcc with openmp (required by zstd) PORTAGE_CONFIGROOT=/gentoo ROOT=/gentoo SYSROOT=/gentoo emerge -O1n \ sys-apps/baselayout \ sys-kernel/linux-headers \ sys-libs/glibc \ sys-devel/binutils \ dev-libs/gmp \ dev-libs/mpfr \ dev-libs/mpc \ sys-devel/gcc \ \ app-arch/bzip2 \ app-arch/xz-utils \ dev-libs/expat \ dev-libs/libffi \ dev-libs/mpdecimal \ sys-apps/util-linux \ sys-libs/libxcrypt \ sys-libs/zlib \ dev-lang/python:3.12 \ \ dev-lang/python-exec \ sys-apps/portage \ \ sys-libs/ncurses \ sys-libs/readline \ app-shells/bash \ \ sys-apps/coreutils \ sys-apps/findutils \ app-arch/tar \ app-arch/gzip \ sys-apps/sed \ sys-apps/grep \ sys-devel/patch \ sys-apps/gawk \ dev-build/make # TODO: Un-hardcode python 3.12 # TODO: Avoid gzip, sed and grep? # Fetch some extra source code DISTDIR=/gentoo/var/cache/distfiles \ PORTAGE_CONFIGROOT=/gentoo ROOT=/gentoo SYSROOT=/gentoo emerge -O1f \ app-misc/ca-certificates \ dev-lang/perl \ dev-libs/openssl \ dev-util/pkgconf \ net-misc/wget # From here you just chroot into /gentoo, clean /etc/portage (leaving only make.profile), install wget, and run "emerge -DN @world", untangling dependencies until it works # TODO: Draw the rest of the fucking owl