summaryrefslogtreecommitdiff
path: root/functions.sh.in
diff options
context:
space:
mode:
authorDubiousjim <dubiousjim@gmail.com>2013-07-05 00:21:39 -0400
committerNatanael Copa <ncopa@alpinelinux.org>2013-07-09 07:13:46 +0000
commitcfa6c7d67ab934dfe1dd083f11f2ce4dcc400afc (patch)
treef0d6a0c1af2e1e8b0286b0435c5dcdc7958950ac /functions.sh.in
parent89afa4179287af307e298f6027dc4eee44bcf481 (diff)
downloadabuild-cfa6c7d67ab934dfe1dd083f11f2ce4dcc400afc.tar.gz
abuild-cfa6c7d67ab934dfe1dd083f11f2ce4dcc400afc.tar.bz2
abuild-cfa6c7d67ab934dfe1dd083f11f2ce4dcc400afc.tar.xz
abuild-cfa6c7d67ab934dfe1dd083f11f2ce4dcc400afc.zip
various: fancier readconfig, permit env overrides
Diffstat (limited to 'functions.sh.in')
-rw-r--r--functions.sh.in75
1 files changed, 61 insertions, 14 deletions
diff --git a/functions.sh.in b/functions.sh.in
index ab4dff5..0b0bc3b 100644
--- a/functions.sh.in
+++ b/functions.sh.in
@@ -3,20 +3,67 @@
sysconfdir=@sysconfdir@
prog=${0##*/}
-
-abuild_conf=${ABUILD_CONF:-"$sysconfdir/abuild.conf"}
-abuild_home=${ABUILD_USERDIR:-"$HOME/.abuild"}
-abuild_userconf=${ABUILD_USERCONF:-"$abuild_home/abuild.conf"}
-
-# read config
-if [ -f "$abuild_conf" ]; then
- . "$abuild_conf" || abuild_conf=
-fi
-
-# read user config if exists
-if [ -f "$abuild_userconf" ]; then
- . "$abuild_userconf" || abuild_userconf=
-fi
+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
+ 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
# expects $1 to be a package directory in the aports tree ('foo' or 'main/foo')