-
-
Save RandyMcMillan/0eb93fe72bb68bf23b34d0cb71d380d8 to your computer and use it in GitHub Desktop.
Alpine Linux cross-compiler setup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CTARGET="$1" | |
if [ -z "$CTARGET" ]; then | |
program=$(basename $0) | |
echo "usage: $program TARGET_ARCH" | |
return 1 | |
fi | |
# get abuild configurables | |
[ -e /usr/share/abuild/functions.sh ] || (echo "abuild not found" ; exit 1) | |
. /usr/share/abuild/functions.sh | |
[ -z "$CBUILD_ARCH" ] && die "abuild is too old" | |
# deduce aports directory | |
[ -z "$APORTSDIR" ] && [[ APORTSDIR=$(realpath $(dirname $0)/../) && \ | |
[ -e "$APORTSDIR/main/build-base" ] || die "Unable to deduce aports base checkout" ]] | |
APK="apk --root $CBUILDROOT" | |
msg() { | |
local name="${BLUE}bootstrap-${CTARGET_ARCH}${NORMAL}" | |
printf "$GREEN>>>${NORMAL} ${name}: %s\n" "$1" >&2 | |
} | |
err() { | |
printf "$RED>>> ERROR${NORMAL}: %s\n" "$*" >&2 | |
} | |
die() { | |
err "$*" | |
exit 2 | |
} | |
if [ ! -d "$CBUILDROOT" ]; then | |
msg "Creating sysroot in $CBUILDROOT" | |
if [ -z "$PACKAGER_PRIVKEY" ] || [ ! -f "$PACKAGER_PRIVKEY" ]; then | |
abuild-keygen -i -a || exit 2 | |
. ~/.abuild/abuild.conf | |
fi | |
APK_ROOT_CONF="$CBUILDROOT/etc/apk" | |
mkdir -p "$APK_ROOT_CONF/keys" | |
cp /etc/apk/repositories "$APK_ROOT_CONF/" | |
case $CTARGET_ARCH in # HACK | |
armv7) keypath=/usr/share/apk/keys/armhf ;; | |
*) keypath=/usr/share/apk/keys/$CTARGET_ARCH ;; | |
esac | |
cp $keypath/* "$APK_ROOT_CONF/keys/" | |
cp $PACKAGER_PRIVKEY.pub "$APK_ROOT_CONF/keys/" | |
$APK add --update --initdb --arch $CTARGET_ARCH libc-dev libgcc || | |
die "failed to initialize target APK repository" | |
fi | |
msg "Building cross-compiler" | |
export CBUILD CHOST CTARGET BOOTSTRAP=nobase | |
# Build and install cross binutils (--with-sysroot) | |
APKBUILD=$(aports_buildscript binutils) abuild -r || | |
die "failed to build binutils-$CTARGET_ARCH" | |
# Full cross GCC | |
EXTRADEPENDS_TARGET="musl musl-dev" \ | |
LANG_ADA=false LANG_D=false LANG_OBJC=false LANG_GO=false LANG_FORTRAN=false \ | |
APKBUILD=$(any_buildscript gcc) abuild -r || | |
die "failed to build gcc-$CTARGET_ARCH" | |
# Cross build-base | |
APKBUILD=$(aports_buildscript build-base) abuild -r || | |
die "failed to build build-base" | |
msg "Done" | |
echo "To install the cross-compiler use 'apk --repository $REPODEST/main --keys-dir ~/.abuild add build-base-$CTARGET_ARCH'" | |
echo "To build Alpine packages for '$CTARGET_ARCH' use 'CHOST=$CTARGET_ARCH abuild -r'" | |
echo "To explicitly install cross-build libraries use '$APK add --no-scripts <pkg>'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment