diff options
author | Timo Teräs <timo.teras@iki.fi> | 2016-07-22 13:54:31 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2016-08-01 14:28:44 +0300 |
commit | 26ec31c6c2b10a9afe93335a948797a3ceeebfd5 (patch) | |
tree | 627cab456f00d345cdefb31ca2ee59fb212da2fe | |
parent | 9f8ef6b8706100172b64e586be3147cf84b32f59 (diff) | |
download | abuild-26ec31c6c2b10a9afe93335a948797a3ceeebfd5.tar.gz abuild-26ec31c6c2b10a9afe93335a948797a3ceeebfd5.tar.bz2 abuild-26ec31c6c2b10a9afe93335a948797a3ceeebfd5.tar.xz abuild-26ec31c6c2b10a9afe93335a948797a3ceeebfd5.zip |
abuild: improve cross compiling support
-rw-r--r-- | abuild.in | 4 | ||||
-rw-r--r-- | functions.sh.in | 39 |
2 files changed, 43 insertions, 0 deletions
@@ -2184,6 +2184,10 @@ Commands: up2date Compare target and sources dates verify Verify checksums +To activate cross compilation specify in environment: + CHOST Arch or hostspec of machine to generate packages for + CTARGET Arch or hostspec of machine to generate compiler for + EOF exit 0 } 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 |