2013-07-05 04:21:16 +00:00
|
|
|
# /usr/share/abuild/functions.sh
|
|
|
|
|
|
|
|
sysconfdir=@sysconfdir@
|
2013-10-25 07:24:46 +00:00
|
|
|
program=${0##*/}
|
2013-07-05 04:21:16 +00:00
|
|
|
|
2016-07-22 10:54:31 +00:00
|
|
|
arch_to_hostspec() {
|
|
|
|
case "$1" in
|
|
|
|
aarch64) echo "aarch64-alpine-linux-musl" ;;
|
2017-06-01 10:55:30 +00:00
|
|
|
armel) echo "armv5-alpine-linux-musleabi" ;;
|
2017-02-14 05:52:54 +00:00
|
|
|
armhf) echo "armv6-alpine-linux-muslgnueabihf" ;;
|
2016-07-22 10:54:31 +00:00
|
|
|
armv7) echo "armv7-alpine-linux-musleabihf" ;;
|
2017-01-24 01:20:34 +00:00
|
|
|
ppc) echo "powerpc-alpine-linux-musl" ;;
|
|
|
|
ppc64) echo "powerpc64-alpine-linux-musl" ;;
|
2017-01-16 19:08:35 +00:00
|
|
|
ppc64le) echo "powerpc64le-alpine-linux-musl" ;;
|
2016-07-26 15:20:31 +00:00
|
|
|
s390x) echo "s390x-alpine-linux-musl" ;;
|
2016-07-22 10:54:31 +00:00
|
|
|
x86) echo "i586-alpine-linux-musl" ;;
|
|
|
|
x86_64) echo "x86_64-alpine-linux-musl" ;;
|
|
|
|
*) echo "unknown" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2013-10-25 07:07:50 +00:00
|
|
|
hostspec_to_arch() {
|
|
|
|
case "$1" in
|
2016-07-08 06:56:14 +00:00
|
|
|
aarch64*-*-*-*) echo "aarch64" ;;
|
2013-10-25 07:07:50 +00:00
|
|
|
arm*-*-*-*eabi) echo "armel" ;;
|
2015-11-12 07:20:29 +00:00
|
|
|
armv6*-*-*-*eabihf) echo "armhf" ;;
|
|
|
|
armv7*-*-*-*eabihf) echo "armv7" ;;
|
2013-10-25 07:07:50 +00:00
|
|
|
i[0-9]86-*-*-*) echo "x86" ;;
|
2017-01-24 01:20:34 +00:00
|
|
|
powerpc-*-*-*) echo "ppc" ;;
|
|
|
|
powerpc64-*-*-*) echo "ppc64" ;;
|
2017-01-16 19:08:35 +00:00
|
|
|
powerpc64le-*-*-*) echo "ppc64le" ;;
|
2016-07-26 15:20:31 +00:00
|
|
|
s390x-*-*-*) echo "s390x" ;;
|
2013-10-25 07:07:50 +00:00
|
|
|
x86_64-*-*-*) echo "x86_64" ;;
|
|
|
|
*) echo "unknown" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
hostspec_to_libc() {
|
|
|
|
case "$1" in
|
|
|
|
*-*-*-uclibc*) echo "uclibc" ;;
|
|
|
|
*-*-*-musl*) echo "musl" ;;
|
2014-06-20 08:38:03 +00:00
|
|
|
*-*-*-gnu*) echo "glibc" ;;
|
|
|
|
*) echo "unknown" ;;
|
2013-10-25 07:07:50 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2013-07-05 04:21:39 +00:00
|
|
|
readconfig() {
|
|
|
|
local _APORTSDIR _BUILDDIR _PKGDEST _SRCPKGDEST _REPODEST _SRCDEST
|
|
|
|
local _CARCH _CHOST _CTARGET _CPPFLAGS _CFLAGS _CXXFLAGS _LDFLAGS
|
|
|
|
local _JOBS _MAKEFLAGS _PACKAGER _USE_COLORS
|
|
|
|
local gitbase=
|
|
|
|
[ -n "${APORTSDIR+x}" ] && _APORTSDIR=$APORTSDIR
|
|
|
|
[ -n "${BUILDDIR+x}" ] && _BUILDDIR=$BUILDDIR
|
|
|
|
[ -n "${PKGDEST+x}" ] && _PKGDEST=$PKGDEST
|
|
|
|
[ -n "${SRCPKGDEST+x}" ] && _SRCPKGDEST=$SRCPKGDEST
|
|
|
|
[ -n "${REPODEST+x}" ] && _REPODEST=$REPODEST
|
|
|
|
[ -n "${SRCDEST+x}" ] && _SRCDEST=$SRCDEST
|
|
|
|
[ -n "${CARCH+x}" ] && _CARCH=$CARCH
|
|
|
|
[ -n "${CHOST+x}" ] && _CHOST=$CHOST
|
|
|
|
[ -n "${CTARGET+x}" ] && _CTARGET=$CTARGET
|
|
|
|
[ -n "${CPPFLAGS+x}" ] && _CPPFLAGS=$CPPFLAGS
|
|
|
|
[ -n "${CFLAGS+x}" ] && _CFLAGS=$CFLAGS
|
|
|
|
[ -n "${CXXFLAGS+x}" ] && _CXXFLAGS=$CXXFLAGS
|
|
|
|
[ -n "${LDFLAGS+x}" ] && _LDFLAGS=$LDFLAGS
|
|
|
|
[ -n "${JOBS+x}" ] && _JOBS=$JOBS
|
|
|
|
[ -n "${MAKEFLAGS+x}" ] && _MAKEFLAGS=$MAKEFLAGS
|
|
|
|
[ -n "${PACKAGER+x}" ] && _PACKAGER=$PACKAGER
|
|
|
|
[ -n "${USE_COLORS+x}" ] && _USE_COLORS="$USE_COLORS"
|
|
|
|
: ${ABUILD_CONF:=$sysconfdir/abuild.conf}
|
|
|
|
: ${ABUILD_USERDIR:=$HOME/.abuild}
|
|
|
|
: ${ABUILD_USERCONF:=$ABUILD_USERDIR/abuild.conf}
|
|
|
|
[ -f "$ABUILD_CONF" ] && . "$ABUILD_CONF"
|
|
|
|
[ -f "$ABUILD_USERCONF" ] && . "$ABUILD_USERCONF"
|
|
|
|
APORTSDIR=${_APORTSDIR-$APORTSDIR}
|
2017-03-20 16:13:07 +00:00
|
|
|
gitbase=$(git rev-parse --show-toplevel 2>/dev/null) || true # already is -P
|
2013-07-05 04:21:39 +00:00
|
|
|
if [ -d "$APORTSDIR" ]; then
|
|
|
|
APORTSDIR=$(cd "$APORTSDIR"; pwd -P)
|
|
|
|
elif [ -z "$APORTSDIR" ] && [ -d "$HOME/aports" ]; then
|
|
|
|
APORTSDIR=$(cd "$HOME/aports"; pwd -P)
|
|
|
|
else
|
|
|
|
if [ -n "$gitbase" ]; then
|
|
|
|
case $(git config remote.origin.url) in
|
|
|
|
*/aports) APORTSDIR=$gitbase ;;
|
|
|
|
*) APORTSDIR= ;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
APORTSDIR=
|
|
|
|
fi
|
|
|
|
fi
|
2013-07-05 04:21:40 +00:00
|
|
|
# source any .abuild file at the aports root, but only if we are currently in aports tree
|
|
|
|
[ -n "$APORTSDIR" ] && [ -f "$APORTSDIR/.abuild" ] && [ "$APORTSDIR" = "$gitbase" ] && . "$APORTSDIR/.abuild"
|
2013-07-05 04:21:39 +00:00
|
|
|
BUILDDIR=${_BUILDDIR-$BUILDDIR}
|
|
|
|
PKGDEST=${_PKGDEST-$PKGDEST}
|
|
|
|
SRCPKGDEST=${_SRCPKGDEST-$SRCPKGDEST}
|
|
|
|
REPODEST=${_REPODEST-$REPODEST}
|
|
|
|
SRCDEST=${_SRCDEST-$SRCDEST}
|
|
|
|
CARCH=${_CARCH-$CARCH}
|
|
|
|
CHOST=${_CHOST-$CHOST}
|
|
|
|
CTARGET=${_CTARGET-$CTARGET}
|
|
|
|
CPPFLAGS=${_CPPFLAGS-$CPPFLAGS}
|
|
|
|
CFLAGS=${_CFLAGS-$CFLAGS}
|
|
|
|
CXXFLAGS=${_CXXFLAGS-$CXXFLAGS}
|
|
|
|
LDFLAGS=${_LDFLAGS-$LDFLAGS}
|
|
|
|
JOBS=${_JOBS-$JOBS}
|
|
|
|
MAKEFLAGS=${_MAKEFLAGS-$MAKEFLAGS}
|
|
|
|
PACKAGER=${_PACKAGER-$PACKAGER}
|
|
|
|
USE_COLORS=${_USE_COLORS-$USE_COLORS}
|
2013-10-25 07:07:50 +00:00
|
|
|
|
2016-07-22 10:10:40 +00:00
|
|
|
[ -z "$CBUILD" ] && CBUILD="$(gcc -dumpmachine)"
|
|
|
|
[ -z "$CHOST" ] && CHOST="$CBUILD"
|
2013-10-25 07:07:50 +00:00
|
|
|
[ -z "$CTARGET" ] && CTARGET="$CHOST"
|
2016-07-22 10:54:31 +00:00
|
|
|
[ "$(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)"
|
|
|
|
|
2013-10-25 07:07:50 +00:00
|
|
|
[ -z "$CARCH" ] && CARCH="$(hostspec_to_arch $CHOST)"
|
|
|
|
[ -z "$CLIBC" ] && CLIBC="$(hostspec_to_libc $CHOST)"
|
2016-07-25 05:50:20 +00:00
|
|
|
[ -z "$CBUILD_ARCH" ] && CBUILD_ARCH="$(hostspec_to_arch $CBUILD)"
|
2013-10-25 07:07:50 +00:00
|
|
|
[ -z "$CTARGET_ARCH" ] && CTARGET_ARCH="$(hostspec_to_arch $CTARGET)"
|
|
|
|
[ -z "$CTARGET_LIBC" ] && CTARGET_LIBC="$(hostspec_to_libc $CTARGET)"
|
|
|
|
|
2016-07-22 10:54:31 +00:00
|
|
|
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}-"
|
2017-02-24 08:19:47 +00:00
|
|
|
export HOSTCC="$CC"
|
|
|
|
export HOSTCXX="$CXX"
|
|
|
|
export HOSTLD="$LD"
|
|
|
|
export HOSTCPPFLAGS="$CPPFLAGS"
|
|
|
|
export HOSTCXXFLAGS="$CXXFLAGS"
|
|
|
|
export HOSTCFLAGS="$CFLAGS"
|
|
|
|
export HOSTLDFLAGS="$LDFLAGS"
|
2016-07-22 10:54:31 +00:00
|
|
|
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
|
2017-04-21 02:53:18 +00:00
|
|
|
return 0
|
2013-07-05 04:21:39 +00:00
|
|
|
}
|
|
|
|
readconfig
|
2013-07-05 04:21:16 +00:00
|
|
|
|
2013-07-05 04:21:29 +00:00
|
|
|
# expects $1 to be a package directory in the aports tree ('foo' or 'main/foo')
|
|
|
|
# outputs APKBUILD's path if successful
|
|
|
|
aports_buildscript() {
|
|
|
|
[ -n "$APORTSDIR" ] || return 1
|
|
|
|
if [ "${1#*/}" != "$1" ]; then
|
|
|
|
( cd "$APORTSDIR/$1" && [ -f APKBUILD ] && echo "$PWD/APKBUILD" )
|
|
|
|
else
|
|
|
|
( cd "$APORTSDIR"/*/"$1" && [ -f APKBUILD ] && echo "$PWD/APKBUILD" )
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-07-05 04:21:38 +00:00
|
|
|
# expects $1 to be a file, or a directory containing an APKBUILD, or a package directory in the aports tree
|
|
|
|
# outputs APKBUILD's path if successful (doesn't verify that it's a valid APKBUILD)
|
|
|
|
any_buildscript() {
|
|
|
|
if [ -f "$1" ]; then
|
|
|
|
echo "$1"
|
|
|
|
elif [ -d "$1" ]; then
|
|
|
|
[ -f "$1/APKBUILD" ] || return 1
|
|
|
|
echo "$1/APKBUILD"
|
|
|
|
else
|
|
|
|
aports_buildscript "$1" || return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-07-05 04:21:16 +00:00
|
|
|
# output functions
|
2013-10-25 07:07:50 +00:00
|
|
|
msg() {
|
|
|
|
[ -n "$quiet" ] && return 0
|
|
|
|
local prompt="$GREEN>>>${NORMAL}"
|
|
|
|
printf "${prompt} %s\n" "$1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
msg2() {
|
|
|
|
[ -n "$quiet" ] && return 0
|
|
|
|
# ">>> %s"
|
|
|
|
printf " %s\n" "$1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
warning() {
|
|
|
|
local prompt="${YELLOW}>>> WARNING:${NORMAL}"
|
|
|
|
printf "${prompt} %s\n" "$1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
warning2() {
|
|
|
|
# ">>> WARNING: %s\n"
|
|
|
|
printf " %s\n" "$1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
local prompt="${RED}>>> ERROR:${NORMAL}"
|
|
|
|
printf "${prompt} %s\n" "$1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
error2() {
|
|
|
|
# ">>> ERROR:
|
|
|
|
printf " %s\n" "$1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
set_xterm_title() {
|
|
|
|
if [ "$TERM" = xterm ] && [ -n "$USE_COLORS" ]; then
|
|
|
|
printf "\033]0;$1\007" >&2
|
2013-07-05 04:21:16 +00:00
|
|
|
fi
|
2013-10-25 07:07:50 +00:00
|
|
|
}
|
2013-07-05 04:21:16 +00:00
|
|
|
|
2013-10-25 07:07:50 +00:00
|
|
|
disable_colors() {
|
|
|
|
NORMAL=""
|
|
|
|
STRONG=""
|
|
|
|
RED=""
|
|
|
|
GREEN=""
|
|
|
|
YELLOW=""
|
|
|
|
BLUE=""
|
|
|
|
}
|
|
|
|
|
|
|
|
enable_colors() {
|
|
|
|
NORMAL="\033[1;0m"
|
|
|
|
STRONG="\033[1;1m"
|
|
|
|
RED="\033[1;31m"
|
|
|
|
GREEN="\033[1;32m"
|
|
|
|
YELLOW="\033[1;33m"
|
|
|
|
BLUE="\033[1;34m"
|
|
|
|
}
|
2013-07-05 04:21:16 +00:00
|
|
|
|
2014-04-30 13:53:17 +00:00
|
|
|
if [ -n "$USE_COLORS" ] && [ -t 1 ]; then
|
2013-10-25 07:07:50 +00:00
|
|
|
enable_colors
|
|
|
|
else
|
|
|
|
disable_colors
|
|
|
|
fi
|
2013-07-05 04:21:16 +00:00
|
|
|
|
|
|
|
# caller may override
|
|
|
|
cleanup() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
|
|
|
error "$@"
|
|
|
|
cleanup
|
|
|
|
exit 1
|
|
|
|
}
|