Newer
Older
case "$j" in
!*) continue;;
esac
for j in $pkgname $subpackages; do
echo -n "d ${j%%:*} $1"
shift
while [ $# -gt 0 ]; do
echo -n ",$1"
shift
done
echo
local deps= i=
# strip versions from deps
for i in "$@"; do
done
[ -z "$deps" ] && return 0
( depparse_aports
if [ -z "$upgrade" ]; then
# list installed pkgs and prefix with 'i '
$APK info -q | sort | sed 's/^/i /'
) | awk -v pkgs="$deps" '
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
function depgraph(pkg, a, i) {
if (visited[pkg])
return 0;
visited[pkg] = 1;
split(deps[pkg], a, ",");
for (i in a)
depgraph(a[i]);
print pkg ":" origin[pkg];
}
$1 == "i" { visited[$2] = 1 }
$1 == "o" { origin[$2] = $3 }
$1 == "d" { deps[$2] = $3 }
END {
split(pkgs, pkgarray);
for (i in pkgarray)
depgraph(pkgarray[i]);
}
'
}
# build and install dependencies
builddeps() {
local deps= alldeps= pkg= i= dir= ver= missing= installed_deps=
local filtered_deps= conflicts=
[ -n "$nodeps" ] && return 0
Natanael Copa
committed
msg "Analyzing dependencies..."
# add depends unless it is a subpackage or package itself
for i in $BUILD_BASE $depends $makedepends; do
[ "$pkgname" = "${i%%[<>=]*}" ] && continue
subpackages_has ${i%%[<>=]*} || deps="$deps $i"
done
installed_deps=$($APK info -e $deps)
# find which deps are missing
for i in $deps; do
if [ "${i#\!}" != "$i" ]; then
$APK info -q -e "${i#\!}" \
&& conflicts="$conflicts ${i#\!}"
elif ! deplist_has $i $installed_deps || [ -n "$upgrade" ]; then
missing="$missing $i"
fi
done
if [ -n "$conflicts" ]; then
error "Conflicting package(s) installed:$conflicts"
return 1
fi
if [ -z "$install_deps" ] && [ -z "$recursive" ]; then
# if we dont have any missing deps we are done now
[ -z "$missing" ] && return 0
error "Missing dependencies: $missing Use -r to autoinstall or -R to build"
return 1
fi
uninstall_after=".makedepends-$pkgname $uninstall_after"
if [ -n "$install_deps" ] && [ -z "$recursive" ] && [ -n "$deps" ]; then
# make a --simluate run first to detect missing deps
# apk-tools --virtual is no goot at reporting those.
$SUDO $APK add --repository "$abuildrepo" \
--wait 30 \
--simulate --quiet $deps || return 1
$SUDO $APK add --repository "$abuildrepo" \
--wait 30 \
--virtual .makedepends-$pkgname $deps \
&& return 0
[ -z "$recursive" ] && return 1
# find dependencies that are installed but missing in repo.
for i in $deps; do
local m=$($APK search --repository "$abuildrepo" ${i%%[<>=]*})
missing="$missing $i"
fi
done
for i in $(deptrace $missing); do
# i = pkg:dir
local dir=${i#*:}
local pkg=${i%:*}
# ignore if dependency is in other repo
[ -d "$dir" ] || continue
# break cricular deps
list_has $pkg $ABUILD_VISITED && continue
export ABUILD_VISITED="$ABUILD_VISITED $pkg"
msg "Entering $dir"
cd "$dir" && $0 $forceroot $keep $quiet $install_deps \
$recursive $upgrade $color_opt abuildindex || return 1
$SUDO $APK add -u --repository "$abuildrepo" \
--wait 30 \
--virtual .makedepends-$pkgname $deps
# replace the md5sums in the APKBUILD
[ -z "$source" ] && return 0
msg "Updating the md5sums in APKBUILD..."
for s in $source; do
files="$files ${s##*/}"
done
md5sums="$(cd "$srcdir" && md5sum $files)" || die "md5sum failed"
sed -i -e '/^md5sums="/,/"\$/d; /^md5sums=''/,/''\$/d' "$APKBUILD"
echo "md5sums=\"$md5sums\"" >>"$APKBUILD"
if options_has "!strip" || [ "$arch" = "noarch" ]; then
return 0
fi
cd "${subpkgdir:-$pkgdir}" || return 1
msg "Stripping binaries"
scanelf --recursive --nobanner --etype "ET_DYN,ET_EXEC" . \
| sed -e 's:^ET_DYN ::' -e 's:^ET_EXEC ::' \
| xargs -r strip
# simply list target apks
listpkg() {
getpkgver || return 1
for name in $(listpkgnames) ; do
echo "$name-$pkgver-r$pkgrel.apk"
source_has() {
local i
for i in $source; do
[ "$1" = "${i##*/}" ] && return 0
done
return 1
}
subpackages_has() {
local i
for i in $subpackages; do
[ "$1" = "${i%:*}" ] && return 0
done
return 1
}
list_has() {
local needle="$1"
local i
shift
for i in $@; do
[ "$needle" = "$i" ] && return 0
[ "$needle" = "!$i" ] && return 1
done
return 1
}
# same as list_has but we filter version info
deplist_has() {
local needle="$1"
local i
shift
for i in $@; do
[ "$needle" = "$i" ] && return 0
[ "$needle" = "!$i" ] && return 1
done
return 1
}
options_has() {
list_has "$1" $options
}
depends_has() {
deplist_has "$1" $depends
}
deplist_has "$1" $makedepends
md5sums_has() {
list_has "$1" $md5sums
}
install_has() {
list_has "$1" $install
}
getpkgver || return 1
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 }')
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"
installdeps() {
local deps i
$SUDO $APK add --wait 30 --repository "$abuildrepo" \
--virtual .makedepends-$pkgname \
$makedepends
}
uninstalldeps (){
$SUDO $APK del .makedepends-$pkgname
}
if ! [ -n "$force" ]; then
check_arch || return 0
fi
if up2date && [ -z "$force" ]; then
msg "Package is up to date"
else
echo "$program $abuild_ver"
echo "usage: $program [options] [-i PKG] [-P REPODEST] [-p PKGDEST]"
echo " [-s SRCDEST] [cmd] ..."
echo " $program [-c] -n PKGNAME[-PKGVER]"
echo " -c Enable colored output"
echo " -d Disable dependency checking"
echo " -f Force specified cmd, even if they are already done"
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"
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)"
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 " sourcecheck Check if remote source package exists upstream"
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"
echo ""
exit 0
}
APKBUILD="${APKBUILD:-./APKBUILD}"
while getopts "cdfFhi:kimnp:P:qrRs:u" opt; do
'c') default_colors
color_opt="-c";;
'f') force="-f";;
'F') forceroot="-F";;
'h') usage;;
'i') install_after="$install_after $OPTARG";;
'k') keep="-k";;
'm') monochrome
color_opt="-m";;
'n') die "Use newapkbuild to create new aports";;
'p') PKGDEST=$OPTARG;;
'P') REPODEST=$OPTARG;;
'q') quiet="-q";;
'r') install_deps="-r";;
'R') recursive="-R";;
's') SRCDEST=$OPTARG;;
'u') upgrade="-u"
recursive="-R";;
# 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
origsubpackages="$subpackages"
controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}
fi
while [ $# -gt 0 ]; do
runpart $1
shift
done