#!/bin/sh -e #=============================================================== # README #=============================================================== # # overview # -------- # # Given a basic development environment ("Baseline System") that # contains standard system utilities, this script bootstraps the # Adélie Linux distribution for any suported target architecture # (assuming that musl, gcc, etc. have been ported to it) without # requiring 'root' privileges. The procedure is outlined below: # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # (unstable, everything provided by user) # # +-----------------+ User-provided tools. Dependency # | Baseline System | of 'mcmtools', which will verify # +-----------------+ that these tools are available. # | # +----------+ Script to build pinned versions # | mcmtools | of common system utilities, a # +----------+ host-arch host-libc toolchain, a # | host-arch musl-libc toolchain... # | # - - - - -|- - - - - - - - - - - - - - - - - - - - - - - - # | (stable versions, unstable libc) # | # +-------------+ ...and a 'chroot'-able rootfs. A # | seed rootfs | sane, but not clean, environment # +-------------+ in which we begin the bootstrap. # | # +-----------+ Script to build 'PRoot' and its # | emulators | dependencies, as well as static # +-----------+ QEMU user binaries. Add to seed. # | # +---------------+ Static musl libc cross toolchain # | musl cross tc | targeting a given architecture. # +---------------+ Output binaries will run via the # | 'binfmt_misc' mechanism + QEMU. # | # +-------------+ Script to build Alpine Package # | build tools | Keeper (APK) and dependencies. # +-------------+ All binaries are cross-compiled! # | # | # +-------------+ Script to build the minimum set # | seed rootfs | of tools to start building the # +-------------+ "system/" package repository. # # mcmtools; a separate script # that # mcmtools provides almost everything needed to build 'abuild', # and it is a hard dependency for our bootstrap process now. # # https://git.zv.io/toolchains/bootstrap # # The output of this step is a host-native toolchain with fixed # versions of development utilities, and a host-architecture hosted toolchain that cross-compiles to both musl and/or # a foreign CPU architecture. (Table above prevents this). # HERE="$(dirname $(readlink -f ${0}))"; TEMP="$(mktemp -d)"; # do not change if not expert! #--------------------------------------------------------------- # initialization usage () { printf "Usage: %s ARCH\n\n" "${0}"; cat <&2 } if [ -z "$TARGET_ARCH" ]; then program=$(basename $0) cat </dev/null PACKAGER_PUBKEY= "${ABUILD_USERDIR}/abuild.conf" || printf >> "${ABUILD_USERDIR}/abuild.conf" "PACKAGER_PUBKEY=\"%s\"\n" "$CBUILDROOT/etc/apk/keys/${p##*/}"; fi ## # APK database. # if [ ! -f "${CBUILDROOT}/._database-${TARGET_ARCH}" ]; then mkdir -p "${CBUILDROOT}/var/log"; # why not created by default? ${SUDO_APK} add --quiet --initdb --arch $TARGET_ARCH --root $CBUILDROOT touch "${CBUILDROOT}/._database-${TARGET_ARCH}"; fi msg "Building cross-compiler" # Build and install cross binutils (--with-sysroot) CTARGET=$TARGET_ARCH BOOTSTRAP=nobase APKBUILD=$(apkbuildname binutils) abuild -r exit if ! CHOST=$TARGET_ARCH BOOTSTRAP=nolibc APKBUILD=$(apkbuildname musl) abuild up2date 2>/dev/null; then # C-library headers for target CHOST=$TARGET_ARCH BOOTSTRAP=nocc APKBUILD=$(apkbuildname musl) abuild -r # Minimal cross GCC EXTRADEPENDS_HOST="musl-dev" \ CTARGET=$TARGET_ARCH BOOTSTRAP=nolibc APKBUILD=$(apkbuildname gcc) abuild -r # Cross build bootstrap C-library for the target EXTRADEPENDS_BUILD="gcc-pass2-$TARGET_ARCH" \ CHOST=$TARGET_ARCH BOOTSTRAP=nolibc APKBUILD=$(apkbuildname musl) abuild -r fi # Full cross GCC EXTRADEPENDS_TARGET="musl musl-dev" \ CTARGET=$TARGET_ARCH BOOTSTRAP=nobase APKBUILD=$(apkbuildname gcc) abuild -r # Cross build-base CTARGET=$TARGET_ARCH BOOTSTRAP=nobase APKBUILD=$(apkbuildname build-base) abuild -r msg "Cross building base system" msg "Change your abuild.conf NOW to avoid build errors!!" read # add implicit target prerequisite packages apk info --quiet --installed --root "$CBUILDROOT" libgcc libstdc++ musl-dev || \ ${SUDO_APK} --root "$CBUILDROOT" add --repository "$REPODEST/system" libgcc libstdc++ musl-dev # ordered cross-build for PKG in musl pkgconf zlib \ gettext-tiny ncurses bash binutils make bison flex m4 \ openssl apk-tools linux-pam shadow \ gmp mpfr3 mpc1 isl gcc ca-certificates \ openrc libcap-ng coreutils sed gzip bzip2 diffutils \ attr libcap patch sudo acl fakeroot libarchive mawk \ pax-utils abuild grep findutils patch lzip unzip autoconf automake libtool \ ncurses util-linux lvm2 popt xz lddtree libssh2 curl build-tools pcre \ debianutils file shimmy procps zsh sharutils net-tools check kbd sysklogd vim db groff libpipeline man-db psmisc less \ adelie-base \ ; do CHOST=$TARGET_ARCH BOOTSTRAP=bootimage APKBUILD=$(apkbuildname $PKG) abuild -r case "$PKG" in fortify-headers | libc-dev | build-base) # headers packages which are implicit but mandatory dependency apk info --quiet --installed --root "$CBUILDROOT" $PKG || \ ${SUDO_APK} --update --root "$CBUILDROOT" --repository "$REPODEST/system" add $PKG ;; musl | gcc) # target libraries rebuilt, force upgrade [ "$(apk upgrade --root "$CBUILDROOT" --repository "$REPODEST/main" --available --simulate | wc -l)" -gt 1 ] && ${SUDO_APK} upgrade --root "$CBUILDROOT" --repository "$REPODEST/main" --available ;; esac done