summaryrefslogtreecommitdiffstats
path: root/functions.sh.in
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2016-07-22 13:54:31 +0300
committerTimo Teräs <timo.teras@iki.fi>2016-08-01 14:28:44 +0300
commit26ec31c6c2b10a9afe93335a948797a3ceeebfd5 (patch)
tree627cab456f00d345cdefb31ca2ee59fb212da2fe /functions.sh.in
parent9f8ef6b8706100172b64e586be3147cf84b32f59 (diff)
downloadabuild-26ec31c6c2b10a9afe93335a948797a3ceeebfd5.tar.bz2
abuild-26ec31c6c2b10a9afe93335a948797a3ceeebfd5.tar.xz
abuild: improve cross compiling support
Diffstat (limited to 'functions.sh.in')
-rw-r--r--functions.sh.in39
1 files changed, 39 insertions, 0 deletions
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