alpine-overlay/aarch64-toolchain.sh

68 lines
2.3 KiB
Bash
Raw Permalink Normal View History

2022-10-05 16:57:46 +00:00
#!/bin/sh
set -ex
TARGET_ARCH=aarch64
SUDO_APK=abuild-apk
APORTS=/home/alpine/aports
export CBUILDROOT="/home/alpine/sysroot-aarch64/"
export CBUILD="x86_64-alpine-linux-musl"
apkbuildname() {
local repo="${1%%/*}"
local pkg="${1##*/}"
[ "$repo" = "$1" ] && repo="main"
echo $APORTS/$repo/$pkg/APKBUILD
}
msg() {
[ -n "$quiet" ] && return 0
local prompt="$GREEN>>>${NORMAL}"
local name="${BLUE}bootstrap-${TARGET_ARCH}${NORMAL}"
printf "${prompt} ${name}: %s\n" "$1" >&2
}
if [ ! -d "$CBUILDROOT" ]; then
msg "Creating sysroot in $CBUILDROOT"
mkdir -p "$CBUILDROOT/etc/apk/keys"
# /etc/apk/keys and ~/.abuild/ can contain files with the same names.
# if that is the case, cp will abort copying and fail. Then on the next
# run of the bootstrap script, 1) the keys are not in the sysroot and
# 2) the apk database is not initialized the sysroot
# Thus it's unusable at that point and needs to be deleted manually.
cp -a /etc/apk/keys/* "$CBUILDROOT/etc/apk/keys"
cp -a ~/.abuild/*.pub "$CBUILDROOT/etc/apk/keys"
${SUDO_APK} add --quiet --initdb --arch $TARGET_ARCH --root $CBUILDROOT
fi
msg "Building cross-compiler"
# Build and install cross binutils (--with-sysroot)
CTARGET=$TARGET_ARCH BOOTSTRAP=nobase APKBUILD=$(apkbuildname binutils) abuild -r
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 "Copying cross toolchain packages into kubezero repository"
cp packages/main/x86_64/* packages/kubezero/x86_64 && rm packages/kubezero/x86_64/gcc-pass2-aarch64-*.apk
cd packages/kubezero/x86_64 && apk index -o APKINDEX.tar.gz *.apk && abuild-sign APKINDEX.tar.gz