Skip to content
Snippets Groups Projects
abuild.in 27 KiB
Newer Older
	deplist_has "$1" $makedepends
md5sums_has() {
	list_has "$1" $md5sums
}

install_has() {
	list_has "$1" $install
}

Natanael Copa's avatar
Natanael Copa committed
# install package after build
post_add() {
Natanael Copa's avatar
Natanael Copa committed
	local pkgf="$PKGDEST/$1-$pkgver-r$pkgrel.apk"
	local deps i
	if ! subpackages_has $1 && [ "$1" != "$pkgname" ]; then
		die "$1 is not built by this APKBUILD"
	fi
	# recursively install dependencies that are provided by this APKBUILD
	deps=$($APK index "$pkgf" 2>/dev/null | awk -F: '$1=="D" { print $2 }')
Natanael Copa's avatar
Natanael Copa committed
	for i in $deps; do
		if subpackages_has $i || [ "$i" = "$pkgname" ]; then
			post_add $i || return 1
		fi
	done
	$SUDO $APK add --wait 30 -u "$pkgf" || die "Failed to install $1"
Natanael Copa's avatar
Natanael Copa committed
}

	sudo $APK add --wait 30 --repository "$abuildrepo" \
		--virtual .makedepends-$pkgname \
	sudo $APK del .makedepends-$pkgname

all() {
	if up2date && [ -z "$force" ]; then
		msg "Package is up to date"
	else
Natanael Copa's avatar
Natanael Copa committed
usage() {
	echo "$program $abuild_ver"
	echo "usage: $program [options] [-i PKG] [-P REPODEST] [-p PKGDEST]"
	echo "              [-s SRCDEST] [cmd] ..."
	echo "       $program [-c] -n PKGNAME[-PKGVER]"
Natanael Copa's avatar
Natanael Copa committed
	echo "Options:"
	echo " -c  Enable colored output"
	echo " -d  Disable dependency checking"
Natanael Copa's avatar
Natanael Copa committed
	echo " -f  Force specified cmd, even if they are already done"
	echo " -F  Force run as root"
	echo " -h  Show this help"
	echo " -i  Install PKG after successul build"
	echo " -k  Keep built packages, even if APKBUILD or sources are newer"
	echo " -m  Disable colors (monochrome)"
	echo " -p  Set package destination directory"
	echo " -P  Set PKGDEST to REPODEST/<repo>, where repo is the parents dir name" 
Natanael Copa's avatar
Natanael Copa committed
	echo " -q  Quiet"
	echo " -r  Install missing dependencies from system repository (using sudo)"
	echo " -R  Recursively build and install missing dependencies (using sudo)"
	echo " -s  Set source package destination directory"
	echo " -u  Recursively build and upgrade all dependencies (using sudo)"
Natanael Copa's avatar
Natanael Copa committed
	echo ""
	echo "Commands:"
	echo "  checksum    Generate checksum to be included in APKBUILD"
	echo "  fetch       Fetch sources to \$SRCDEST and verify checksums"
	echo "  sanitycheck Basic sanity check of APKBUILD"
	echo "  md5check    Check md5sums"
	echo "  unpack      Unpack sources to \$srcdir"
	echo "  build       Compile and install package into \$pkgdir"
	echo "  listpkg     List target packages"
	echo "  package     Create package in \$PKGDEST"
	echo "  rootpkg     Run '$0 build package' as fakeroot"
	echo "  clean       Remove temp build and install dirs"
	echo "  cleanoldpkg Remove binary packages except current version"
	echo "  cleanpkg    Remove already built binary and source package"
	echo "  cleancache  Remove downloaded files from \$SRCDEST"
	echo "  srcpkg      Make a source package"
	echo "  up2date     Compare target and sources dates"
	echo "  installdeps Install packages listed in makedepends and depends"
	echo "  uninstalldeps Uninstall packages listed in makedepends and depends"
Natanael Copa's avatar
Natanael Copa committed
	echo ""
	exit 0
}

APKBUILD="${APKBUILD:-./APKBUILD}"
unset force
unset recursive
while getopts "cdfFhi:kimnp:P:qrRs:u" opt; do
Natanael Copa's avatar
Natanael Copa committed
	case $opt in
		'c') default_colors
		     color_opt="-c";;
		'f') force="-f";;
		'F') forceroot="-F";;
		'h') usage;;
		'i') install_after="$install_after $OPTARG";;
		'n') die "Use newapkbuild to create new aports";;
		'q') quiet="-q";;
		'r') install_deps="-r";;
		'R') recursive="-R";;
		'u') upgrade="-u"
		     recursive="-R";;
Natanael Copa's avatar
Natanael Copa committed
	esac
done
shift $(( $OPTIND - 1 ))

# check so we are not root
if [ "$(whoami)" = "root" ] && [ -z "$FAKEROOTKEY" ]; then
	[ -z "$forceroot" ] && die "Do not run abuild as root"
	SUDO=
	FAKEROOT=
fi

# find startdir
[ -f "$APKBUILD" ] || die "Could not find $APKBUILD (PWD=$PWD)"
APKBUILD=$(readlink -f "$APKBUILD")

startdir="${APKBUILD%/*}"
srcdir=${srcdir:-"$startdir/src"}
pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
pkgrel=0
repo=${startdir%/*}
repo=${repo##*/}

SRCDEST=${SRCDEST:-$startdir}
PKGDEST=${PKGDEST:-$startdir}

cd "$startdir" || die
. "$APKBUILD"

# If REPODEST is set then it will override the PKGDEST
if [ -n "$REPODEST" ]; then
	PKGDEST="$REPODEST/$repo"
fi

# If we are handling a sub package then reset subpackages and install
if [ -n "$subpkgname" ]; then
	origsubpackages="$subpackages"
pkgdir="$pkgbasedir/$pkgname"
controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}
Natanael Copa's avatar
Natanael Copa committed

trap 'die "Aborted by user"' INT
Linux User's avatar
Linux User committed
set_xterm_title "abuild: $pkgname"
Natanael Copa's avatar
Natanael Copa committed

if [ -z "$1" ]; then
Natanael Copa's avatar
Natanael Copa committed
fi

while [ $# -gt 0 ]; do
	runpart $1
	shift
done

for i in $install_after; do
Natanael Copa's avatar
Natanael Copa committed
	post_add $i
Linux User's avatar
Linux User committed
cleanup
Natanael Copa's avatar
Natanael Copa committed