From 26ec31c6c2b10a9afe93335a948797a3ceeebfd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Fri, 22 Jul 2016 13:54:31 +0300 Subject: abuild: improve cross compiling support --- functions.sh.in | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'functions.sh.in') diff --git a/functions.sh.in b/functions.sh.in index 9c0cc57..6a24d21 100644 --- a/functions.sh.in +++ b/functions.sh.in @@ -3,6 +3,17 @@ sysconfdir=@sysconfdir@ program=${0##*/} +arch_to_hostspec() { + case "$1" in + aarch64) echo "aarch64-alpine-linux-musl" ;; + armhf) echo "armhf-alpine-linux-muslgnueabihf" ;; + armv7) echo "armv7-alpine-linux-musleabihf" ;; + x86) echo "i586-alpine-linux-musl" ;; + x86_64) echo "x86_64-alpine-linux-musl" ;; + *) echo "unknown" ;; + esac +} + hostspec_to_arch() { case "$1" in aarch64*-*-*-*) echo "aarch64" ;; @@ -89,11 +100,39 @@ readconfig() { [ -z "$CBUILD" ] && CBUILD="$(gcc -dumpmachine)" [ -z "$CHOST" ] && CHOST="$CBUILD" [ -z "$CTARGET" ] && CTARGET="$CHOST" + [ "$(arch_to_hostspec $CBUILD)" != "unknown" ] && CBUILD="$(arch_to_hostspec $CBUILD)" + [ "$(arch_to_hostspec $CHOST)" != "unknown" ] && CHOST="$(arch_to_hostspec $CHOST)" + [ "$(arch_to_hostspec $CTARGET)" != "unknown" ] && CTARGET="$(arch_to_hostspec $CTARGET)" + [ -z "$CARCH" ] && CARCH="$(hostspec_to_arch $CHOST)" [ -z "$CLIBC" ] && CLIBC="$(hostspec_to_libc $CHOST)" [ -z "$CTARGET_ARCH" ] && CTARGET_ARCH="$(hostspec_to_arch $CTARGET)" [ -z "$CTARGET_LIBC" ] && CTARGET_LIBC="$(hostspec_to_libc $CTARGET)" + if [ "$CHOST" != "$CTARGET" ]; then + # setup environment for creating cross compiler + [ -z "$CBUILDROOT" ] && export CBUILDROOT="$HOME/sysroot-$CTARGET_ARCH/" + elif [ "$CBUILD" != "$CHOST" ]; then + # setup build root + [ -z "$CBUILDROOT" ] && export CBUILDROOT="$HOME/sysroot-$CTARGET_ARCH/" + # prepare pkg-config for cross building + [ -z "$PKG_CONFIG_PATH" ] && export PKG_CONFIG_PATH="${CBUILDROOT}/usr/lib/pkgconfig/" + [ -z "$PKG_CONFIG_SYSROOT_DIR" ] && export PKG_CONFIG_SYSROOT_DIR="${CBUILDROOT}" + # libtool bug workaround for extra rpaths + [ -z "$lt_cv_sys_lib_dlsearch_path_spec" ] && \ + export lt_cv_sys_lib_dlsearch_path_spec="${CBUILDROOT}/lib ${CBUILDROOT}/usr/lib /usr/lib /lib /usr/local/lib" + # setup cross-compiler + if [ -z "$CROSS_COMPILE" ]; then + export CROSS_COMPILE="${CHOST}-" + export CC=${CROSS_COMPILE}gcc + export CXX=${CROSS_COMPILE}g++ + export LD=${CROSS_COMPILE}ld + export CPPFLAGS="--sysroot=${CBUILDROOT} $CPPFLAGS" + export CXXFLAGS="--sysroot=${CBUILDROOT} $CXXFLAGS" + export CFLAGS="--sysroot=${CBUILDROOT} $CFLAGS" + export LDFLAGS="--sysroot=${CBUILDROOT} $LDFLAGS" + fi + fi } readconfig -- cgit v1.2.3