2013-07-05 04:21:16 +00:00
|
|
|
# /usr/share/abuild/functions.sh
|
|
|
|
|
|
|
|
sysconfdir=@sysconfdir@
|
|
|
|
prog=${0##*/}
|
|
|
|
|
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}
|
|
|
|
gitbase=$(git rev-parse --show-toplevel 2>/dev/null) # already is -P
|
|
|
|
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}
|
|
|
|
}
|
|
|
|
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:29 +00:00
|
|
|
|
2013-07-05 04:21:16 +00:00
|
|
|
# output functions
|
|
|
|
case $prog in
|
|
|
|
abuild)
|
|
|
|
if [ -n "$USE_COLORS" ]; then
|
|
|
|
NORMAL="\033[1;0m"
|
|
|
|
STRONG="\033[1;1m"
|
|
|
|
RED="\033[1;31m"
|
|
|
|
GREEN="\033[1;32m"
|
|
|
|
YELLOW="\033[1;33m"
|
|
|
|
BLUE="\033[1;34m"
|
|
|
|
fi
|
|
|
|
|
|
|
|
msg() {
|
|
|
|
local prompt="$GREEN>>>${NORMAL}"
|
|
|
|
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
|
|
|
|
local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
|
2013-07-09 11:14:29 +00:00
|
|
|
if [ -z "$quiet" ]; then
|
|
|
|
printf "${prompt} ${name}${fake}: $@\n" >&2
|
|
|
|
fi
|
2013-07-05 04:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
warning() {
|
|
|
|
local prompt="${YELLOW}>>> WARNING:${NORMAL}"
|
|
|
|
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
|
|
|
|
local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
|
|
|
|
printf "${prompt} ${name}${fake}: $@\n" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
local prompt="${RED}>>> ERROR:${NORMAL}"
|
|
|
|
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
|
|
|
|
local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
|
|
|
|
printf "${prompt} ${name}${fake}: $@\n" >&2
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
msg() {
|
|
|
|
# Here we write to stdout, but abuild's fancier messages write to stderr
|
2013-07-09 11:14:29 +00:00
|
|
|
if [ -z "$quiet" ]; then
|
|
|
|
echo "$@"
|
|
|
|
fi
|
2013-07-05 04:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
2013-07-05 04:21:37 +00:00
|
|
|
echo "$prog: $@" >&2
|
2013-07-05 04:21:16 +00:00
|
|
|
}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# caller may override
|
|
|
|
cleanup() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
|
|
|
error "$@"
|
|
|
|
cleanup
|
|
|
|
exit 1
|
|
|
|
}
|