Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] xbps-src: multiple performance improvements
@ 2019-07-03 17:49 voidlinux-github
  2019-07-03 17:52 ` voidlinux-github
                   ` (45 more replies)
  0 siblings, 46 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-03 17:49 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]

There is a new pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 67755 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/3] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/3] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/3] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
@ 2019-07-03 17:52 ` voidlinux-github
  2019-07-03 18:34 ` voidlinux-github
                   ` (44 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-03 17:52 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 354 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508193818
Comment:
CC @pullmoll @Duncaen 

I tested this branch this way:

- xbps-src bootstrap
- xbps-src -Nt pkg xbps
- xbps-src -a aarch64-musl -Nt pkg xbps

@pullmoll please test if you have some time! it's way faster now

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
  2019-07-03 17:52 ` voidlinux-github
@ 2019-07-03 18:34 ` voidlinux-github
  2019-07-03 18:40 ` [PR PATCH] [Updated] " voidlinux-github
                   ` (43 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-03 18:34 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 203 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508208811
Comment:
Hmm, my latest change broke cross compilation... looking at it.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (2 preceding siblings ...)
  2019-07-03 18:40 ` [PR PATCH] [Updated] " voidlinux-github
@ 2019-07-03 18:40 ` voidlinux-github
  2019-07-03 18:40 ` voidlinux-github
                   ` (41 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-03 18:40 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 69035 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/4] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/4] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/4] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

From 3c1cd8351e0225eae344e80e350853ee98f7b156 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 20:39:21 +0200
Subject: [PATCH 4/4] xbps-src: fix XBPS_CHECKVERS_XCMD.

Needs to set -r $XBPS_CROSS_BASE to use correct dbdir.
---
 common/xbps-src/shutils/common.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index dea6e2b3bdd..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
  2019-07-03 17:52 ` voidlinux-github
  2019-07-03 18:34 ` voidlinux-github
@ 2019-07-03 18:40 ` voidlinux-github
  2019-07-03 18:40 ` voidlinux-github
                   ` (42 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-03 18:40 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 69035 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/4] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/4] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/4] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

From 3c1cd8351e0225eae344e80e350853ee98f7b156 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 20:39:21 +0200
Subject: [PATCH 4/4] xbps-src: fix XBPS_CHECKVERS_XCMD.

Needs to set -r $XBPS_CROSS_BASE to use correct dbdir.
---
 common/xbps-src/shutils/common.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index dea6e2b3bdd..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (3 preceding siblings ...)
  2019-07-03 18:40 ` voidlinux-github
@ 2019-07-03 18:40 ` voidlinux-github
  2019-07-03 19:00 ` voidlinux-github
                   ` (40 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-03 18:40 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 149 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508211022
Comment:
Fixed :-)

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (4 preceding siblings ...)
  2019-07-03 18:40 ` voidlinux-github
@ 2019-07-03 19:00 ` voidlinux-github
  2019-07-03 20:58 ` voidlinux-github
                   ` (39 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-03 19:00 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 197 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508217781
Comment:
Success! the error is due to xlint being too much strict.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (5 preceding siblings ...)
  2019-07-03 19:00 ` voidlinux-github
@ 2019-07-03 20:58 ` voidlinux-github
  2019-07-03 21:38 ` voidlinux-github
                   ` (38 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-03 20:58 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 209 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508252618
Comment:
Please review! I'll push it in 12h approx if there are no objections.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (6 preceding siblings ...)
  2019-07-03 20:58 ` voidlinux-github
@ 2019-07-03 21:38 ` voidlinux-github
  2019-07-03 21:43 ` voidlinux-github
                   ` (37 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-03 21:38 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 185 bytes --]

New comment by jnbr on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508264069
Comment:
There is a python3 update between these commits.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (7 preceding siblings ...)
  2019-07-03 21:38 ` voidlinux-github
@ 2019-07-03 21:43 ` voidlinux-github
  2019-07-04  5:06 ` voidlinux-github
                   ` (36 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-03 21:43 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 510 bytes --]

New comment by jnbr on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508265126
Comment:
this looks strange, not sure if related to python bump or other changes
```
=> python3-3.6.9_1: running post-install hook: 06-strip-and-debug-pkgs ...
   Stripped position-independent executable: /usr/bin/python3.6m
   Stripped position-independent executable: /usr/bin/python3.6
objcopy: /destdir//python3-3.6.9/usr/bin/stHxfGoT: debuglink section already exists
```

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (8 preceding siblings ...)
  2019-07-03 21:43 ` voidlinux-github
@ 2019-07-04  5:06 ` voidlinux-github
  2019-07-04  5:57 ` [PR PATCH] [Updated] " voidlinux-github
                   ` (35 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04  5:06 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 350 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508339578
Comment:
@jnbr I added the python3 update for testing. About objcopy, this is normal behaviour with hard links.

```
[juan@leysa ~]$ stat --printf='%i\n' /usr/bin/python3.6{,m}
1451894
1451894
[juan@leysa ~]$
```

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (10 preceding siblings ...)
  2019-07-04  5:57 ` [PR PATCH] [Updated] " voidlinux-github
@ 2019-07-04  5:57 ` voidlinux-github
  2019-07-04  9:03 ` voidlinux-github
                   ` (33 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04  5:57 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 69847 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/5] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/5] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/5] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

From 3c1cd8351e0225eae344e80e350853ee98f7b156 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 20:39:21 +0200
Subject: [PATCH 4/5] xbps-src: fix XBPS_CHECKVERS_XCMD.

Needs to set -r $XBPS_CROSS_BASE to use correct dbdir.
---
 common/xbps-src/shutils/common.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index dea6e2b3bdd..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS

From 70a75ddcaa71b28511c0c6b56e21ad7c337aa938 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 07:56:17 +0200
Subject: [PATCH 5/5] xbps-src: fix reconfiguration of bootstrap pkgs.

---
 xbps-src | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xbps-src b/xbps-src
index f72cc7002c9..b494306f58e 100755
--- a/xbps-src
+++ b/xbps-src
@@ -311,8 +311,8 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if $XBPS_QUERY_CMD $f &>/dev/null; then
-            $XBPS_RECONFIGURE_CMD -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (9 preceding siblings ...)
  2019-07-04  5:06 ` voidlinux-github
@ 2019-07-04  5:57 ` voidlinux-github
  2019-07-04  5:57 ` voidlinux-github
                   ` (34 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04  5:57 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 69847 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/5] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/5] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/5] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

From 3c1cd8351e0225eae344e80e350853ee98f7b156 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 20:39:21 +0200
Subject: [PATCH 4/5] xbps-src: fix XBPS_CHECKVERS_XCMD.

Needs to set -r $XBPS_CROSS_BASE to use correct dbdir.
---
 common/xbps-src/shutils/common.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index dea6e2b3bdd..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS

From 70a75ddcaa71b28511c0c6b56e21ad7c337aa938 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 07:56:17 +0200
Subject: [PATCH 5/5] xbps-src: fix reconfiguration of bootstrap pkgs.

---
 xbps-src | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xbps-src b/xbps-src
index f72cc7002c9..b494306f58e 100755
--- a/xbps-src
+++ b/xbps-src
@@ -311,8 +311,8 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if $XBPS_QUERY_CMD $f &>/dev/null; then
-            $XBPS_RECONFIGURE_CMD -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (12 preceding siblings ...)
  2019-07-04  9:03 ` voidlinux-github
@ 2019-07-04  9:03 ` voidlinux-github
  2019-07-04  9:53 ` voidlinux-github
                   ` (31 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04  9:03 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 72028 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/6] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/6] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/6] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

From 3c1cd8351e0225eae344e80e350853ee98f7b156 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 20:39:21 +0200
Subject: [PATCH 4/6] xbps-src: fix XBPS_CHECKVERS_XCMD.

Needs to set -r $XBPS_CROSS_BASE to use correct dbdir.
---
 common/xbps-src/shutils/common.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index dea6e2b3bdd..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS

From 70a75ddcaa71b28511c0c6b56e21ad7c337aa938 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 07:56:17 +0200
Subject: [PATCH 5/6] xbps-src: fix reconfiguration of bootstrap pkgs.

---
 xbps-src | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xbps-src b/xbps-src
index f72cc7002c9..b494306f58e 100755
--- a/xbps-src
+++ b/xbps-src
@@ -311,8 +311,8 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if $XBPS_QUERY_CMD $f &>/dev/null; then
-            $XBPS_RECONFIGURE_CMD -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile

From fce0a81ec88f2595b575ab7d6984c310772f2e44 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 11:00:13 +0200
Subject: [PATCH 6/6] xbps-src: improve bulk_sortdeps().

./xbps-src sort-dependencies $(./xbps-src show-build-deps xbps)

0.202s vs 0.514s
---
 common/xbps-src/shutils/bulk.sh | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 2d1d612c966..3a44dd1539e 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,24 +1,29 @@
 # vim: set ts=4 sw=4 et:
 
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
-    pkgs="$@"
     tmpf=$(mktemp) || exit 1
 
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+    # Perform a topological sort of all build dependencies.
+    if [ $NRUNNING -eq $NPROCS ]; then
+        NRUNNING=0
+        wait
+    fi
+
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            for f in ${pkgs}; do
-                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
+        # async/parallel execution
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
@@ -30,7 +35,7 @@ bulk_build() {
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
     bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (11 preceding siblings ...)
  2019-07-04  5:57 ` voidlinux-github
@ 2019-07-04  9:03 ` voidlinux-github
  2019-07-04  9:03 ` voidlinux-github
                   ` (32 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04  9:03 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 72028 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/6] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/6] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/6] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

From 3c1cd8351e0225eae344e80e350853ee98f7b156 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 20:39:21 +0200
Subject: [PATCH 4/6] xbps-src: fix XBPS_CHECKVERS_XCMD.

Needs to set -r $XBPS_CROSS_BASE to use correct dbdir.
---
 common/xbps-src/shutils/common.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index dea6e2b3bdd..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS

From 70a75ddcaa71b28511c0c6b56e21ad7c337aa938 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 07:56:17 +0200
Subject: [PATCH 5/6] xbps-src: fix reconfiguration of bootstrap pkgs.

---
 xbps-src | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xbps-src b/xbps-src
index f72cc7002c9..b494306f58e 100755
--- a/xbps-src
+++ b/xbps-src
@@ -311,8 +311,8 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if $XBPS_QUERY_CMD $f &>/dev/null; then
-            $XBPS_RECONFIGURE_CMD -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile

From fce0a81ec88f2595b575ab7d6984c310772f2e44 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 11:00:13 +0200
Subject: [PATCH 6/6] xbps-src: improve bulk_sortdeps().

./xbps-src sort-dependencies $(./xbps-src show-build-deps xbps)

0.202s vs 0.514s
---
 common/xbps-src/shutils/bulk.sh | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 2d1d612c966..3a44dd1539e 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,24 +1,29 @@
 # vim: set ts=4 sw=4 et:
 
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
-    pkgs="$@"
     tmpf=$(mktemp) || exit 1
 
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+    # Perform a topological sort of all build dependencies.
+    if [ $NRUNNING -eq $NPROCS ]; then
+        NRUNNING=0
+        wait
+    fi
+
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            for f in ${pkgs}; do
-                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
+        # async/parallel execution
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
@@ -30,7 +35,7 @@ bulk_build() {
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
     bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (14 preceding siblings ...)
  2019-07-04  9:53 ` voidlinux-github
@ 2019-07-04  9:53 ` voidlinux-github
  2019-07-04 10:07 ` voidlinux-github
                   ` (29 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04  9:53 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 74686 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/7] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/7] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/7] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

From 3c1cd8351e0225eae344e80e350853ee98f7b156 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 20:39:21 +0200
Subject: [PATCH 4/7] xbps-src: fix XBPS_CHECKVERS_XCMD.

Needs to set -r $XBPS_CROSS_BASE to use correct dbdir.
---
 common/xbps-src/shutils/common.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index dea6e2b3bdd..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS

From 70a75ddcaa71b28511c0c6b56e21ad7c337aa938 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 07:56:17 +0200
Subject: [PATCH 5/7] xbps-src: fix reconfiguration of bootstrap pkgs.

---
 xbps-src | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xbps-src b/xbps-src
index f72cc7002c9..b494306f58e 100755
--- a/xbps-src
+++ b/xbps-src
@@ -311,8 +311,8 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if $XBPS_QUERY_CMD $f &>/dev/null; then
-            $XBPS_RECONFIGURE_CMD -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile

From fce0a81ec88f2595b575ab7d6984c310772f2e44 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 11:00:13 +0200
Subject: [PATCH 6/7] xbps-src: improve bulk_sortdeps().

./xbps-src sort-dependencies $(./xbps-src show-build-deps xbps)

0.202s vs 0.514s
---
 common/xbps-src/shutils/bulk.sh | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 2d1d612c966..3a44dd1539e 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,24 +1,29 @@
 # vim: set ts=4 sw=4 et:
 
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
-    pkgs="$@"
     tmpf=$(mktemp) || exit 1
 
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+    # Perform a topological sort of all build dependencies.
+    if [ $NRUNNING -eq $NPROCS ]; then
+        NRUNNING=0
+        wait
+    fi
+
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            for f in ${pkgs}; do
-                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
+        # async/parallel execution
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
@@ -30,7 +35,7 @@ bulk_build() {
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
     bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"

From 43de379081ed35dbd0fce59913ed37f132c13893 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 11:51:24 +0200
Subject: [PATCH 7/7] xbps-src: improve bulk code a bit more.

- use `show-avail` to discard broken pkgs.
- the parallel logic was incomplete.
- avoid unnecessary sorting.
---
 common/xbps-src/shutils/bulk.sh | 45 +++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 3a44dd1539e..964be3b66ff 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -8,14 +8,13 @@ bulk_sortdeps() {
 
     tmpf=$(mktemp) || exit 1
 
-    # Perform a topological sort of all build dependencies.
-    if [ $NRUNNING -eq $NPROCS ]; then
-        NRUNNING=0
-        wait
-    fi
-
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        # async/parallel execution
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
         (
             for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
                 echo "$pkg $_pkg" >> $tmpf
@@ -29,6 +28,9 @@ bulk_sortdeps() {
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
@@ -38,21 +40,38 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            if ./xbps-src show-avail $f &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (13 preceding siblings ...)
  2019-07-04  9:03 ` voidlinux-github
@ 2019-07-04  9:53 ` voidlinux-github
  2019-07-04  9:53 ` voidlinux-github
                   ` (30 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04  9:53 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 74686 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/7] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/7] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/7] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

From 3c1cd8351e0225eae344e80e350853ee98f7b156 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 20:39:21 +0200
Subject: [PATCH 4/7] xbps-src: fix XBPS_CHECKVERS_XCMD.

Needs to set -r $XBPS_CROSS_BASE to use correct dbdir.
---
 common/xbps-src/shutils/common.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index dea6e2b3bdd..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS

From 70a75ddcaa71b28511c0c6b56e21ad7c337aa938 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 07:56:17 +0200
Subject: [PATCH 5/7] xbps-src: fix reconfiguration of bootstrap pkgs.

---
 xbps-src | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xbps-src b/xbps-src
index f72cc7002c9..b494306f58e 100755
--- a/xbps-src
+++ b/xbps-src
@@ -311,8 +311,8 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if $XBPS_QUERY_CMD $f &>/dev/null; then
-            $XBPS_RECONFIGURE_CMD -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile

From fce0a81ec88f2595b575ab7d6984c310772f2e44 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 11:00:13 +0200
Subject: [PATCH 6/7] xbps-src: improve bulk_sortdeps().

./xbps-src sort-dependencies $(./xbps-src show-build-deps xbps)

0.202s vs 0.514s
---
 common/xbps-src/shutils/bulk.sh | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 2d1d612c966..3a44dd1539e 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,24 +1,29 @@
 # vim: set ts=4 sw=4 et:
 
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
-    pkgs="$@"
     tmpf=$(mktemp) || exit 1
 
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+    # Perform a topological sort of all build dependencies.
+    if [ $NRUNNING -eq $NPROCS ]; then
+        NRUNNING=0
+        wait
+    fi
+
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            for f in ${pkgs}; do
-                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
+        # async/parallel execution
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
@@ -30,7 +35,7 @@ bulk_build() {
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
     bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"

From 43de379081ed35dbd0fce59913ed37f132c13893 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 11:51:24 +0200
Subject: [PATCH 7/7] xbps-src: improve bulk code a bit more.

- use `show-avail` to discard broken pkgs.
- the parallel logic was incomplete.
- avoid unnecessary sorting.
---
 common/xbps-src/shutils/bulk.sh | 45 +++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 3a44dd1539e..964be3b66ff 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -8,14 +8,13 @@ bulk_sortdeps() {
 
     tmpf=$(mktemp) || exit 1
 
-    # Perform a topological sort of all build dependencies.
-    if [ $NRUNNING -eq $NPROCS ]; then
-        NRUNNING=0
-        wait
-    fi
-
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        # async/parallel execution
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
         (
             for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
                 echo "$pkg $_pkg" >> $tmpf
@@ -29,6 +28,9 @@ bulk_sortdeps() {
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
@@ -38,21 +40,38 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            if ./xbps-src show-avail $f &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (16 preceding siblings ...)
  2019-07-04 10:07 ` voidlinux-github
@ 2019-07-04 10:07 ` voidlinux-github
  2019-07-04 10:48 ` voidlinux-github
                   ` (27 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04 10:07 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 76089 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/9] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/9] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/9] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

From 3c1cd8351e0225eae344e80e350853ee98f7b156 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 20:39:21 +0200
Subject: [PATCH 4/9] xbps-src: fix XBPS_CHECKVERS_XCMD.

Needs to set -r $XBPS_CROSS_BASE to use correct dbdir.
---
 common/xbps-src/shutils/common.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index dea6e2b3bdd..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS

From 70a75ddcaa71b28511c0c6b56e21ad7c337aa938 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 07:56:17 +0200
Subject: [PATCH 5/9] xbps-src: fix reconfiguration of bootstrap pkgs.

---
 xbps-src | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xbps-src b/xbps-src
index f72cc7002c9..b494306f58e 100755
--- a/xbps-src
+++ b/xbps-src
@@ -311,8 +311,8 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if $XBPS_QUERY_CMD $f &>/dev/null; then
-            $XBPS_RECONFIGURE_CMD -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile

From fce0a81ec88f2595b575ab7d6984c310772f2e44 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 11:00:13 +0200
Subject: [PATCH 6/9] xbps-src: improve bulk_sortdeps().

./xbps-src sort-dependencies $(./xbps-src show-build-deps xbps)

0.202s vs 0.514s
---
 common/xbps-src/shutils/bulk.sh | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 2d1d612c966..3a44dd1539e 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,24 +1,29 @@
 # vim: set ts=4 sw=4 et:
 
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
-    pkgs="$@"
     tmpf=$(mktemp) || exit 1
 
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+    # Perform a topological sort of all build dependencies.
+    if [ $NRUNNING -eq $NPROCS ]; then
+        NRUNNING=0
+        wait
+    fi
+
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            for f in ${pkgs}; do
-                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
+        # async/parallel execution
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
@@ -30,7 +35,7 @@ bulk_build() {
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
     bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"

From 43de379081ed35dbd0fce59913ed37f132c13893 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 11:51:24 +0200
Subject: [PATCH 7/9] xbps-src: improve bulk code a bit more.

- use `show-avail` to discard broken pkgs.
- the parallel logic was incomplete.
- avoid unnecessary sorting.
---
 common/xbps-src/shutils/bulk.sh | 45 +++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 3a44dd1539e..964be3b66ff 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -8,14 +8,13 @@ bulk_sortdeps() {
 
     tmpf=$(mktemp) || exit 1
 
-    # Perform a topological sort of all build dependencies.
-    if [ $NRUNNING -eq $NPROCS ]; then
-        NRUNNING=0
-        wait
-    fi
-
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        # async/parallel execution
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
         (
             for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
                 echo "$pkg $_pkg" >> $tmpf
@@ -29,6 +28,9 @@ bulk_sortdeps() {
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
@@ -38,21 +40,38 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            if ./xbps-src show-avail $f &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg

From 4949a8625c449481d7f357aaea2ef151d74455c5 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 12:05:05 +0200
Subject: [PATCH 8/9] xbps-src: silence `show-avail`

---
 xbps-src | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xbps-src b/xbps-src
index b494306f58e..66078530bdd 100755
--- a/xbps-src
+++ b/xbps-src
@@ -794,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)

From a49fa898d2b70b5062bc151c5826e05319c6b6d6 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 12:06:38 +0200
Subject: [PATCH 9/9] xbps-src: bulk_build() use existing shell funcs.

... rather than forking xbps-src again.
---
 common/xbps-src/shutils/bulk.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 964be3b66ff..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -53,7 +53,8 @@ bulk_build() {
         fi
         NRUNNING=$((NRUNNING+1))
         (
-            if ./xbps-src show-avail $f &>/dev/null; then
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
                 echo "$f"
             fi
         ) &

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (15 preceding siblings ...)
  2019-07-04  9:53 ` voidlinux-github
@ 2019-07-04 10:07 ` voidlinux-github
  2019-07-04 10:07 ` voidlinux-github
                   ` (28 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04 10:07 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 76089 bytes --]

From 0838bbca58817c1d625b7899a8704cc183796fbe Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:36:22 +0200
Subject: [PATCH 1/9] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/shutils/build_dependencies.sh | 486 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  40 +-
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 324 ++++++------
 13 files changed, 401 insertions(+), 602 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..3c49fc650bc 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,65 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_depname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +91,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +103,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +114,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +139,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1)
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +304,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +334,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..2d1d612c966 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,36 +1,11 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
     local _pkgs _pkg pkgs pkg found f x tmpf
 
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
-
+    pkgs="$@"
     tmpf=$(mktemp) || exit 1
+
     # Now make the real dependency graph of all pkgs to build.
     # Perform a topological sort of all pkgs but only with build dependencies
     # that are found in previous step.
@@ -38,16 +13,11 @@ bulk_sortdeps() {
         _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
         found=0
         for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
             for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
             done
         done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
     done
     tsort $tmpf|tac
     rm -f $tmpf
@@ -63,7 +33,7 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
 }
 
 bulk_update() {
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..dea6e2b3bdd 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..f72cc7002c9 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if $XBPS_QUERY_CMD $f &>/dev/null; then
+            $XBPS_RECONFIGURE_CMD -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+
+mkdir -p $XBPS_MASTERDIR $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 16d7592da6061a6c3a2a1da75ad1bed43d9e0573 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:46:37 +0200
Subject: [PATCH 2/9] python3: update to 3.6.9.

---
 srcpkgs/python3/patches/CVE-2019-5010.patch | 32 ---------------------
 srcpkgs/python3/template                    |  6 ++--
 2 files changed, 3 insertions(+), 35 deletions(-)
 delete mode 100644 srcpkgs/python3/patches/CVE-2019-5010.patch

diff --git a/srcpkgs/python3/patches/CVE-2019-5010.patch b/srcpkgs/python3/patches/CVE-2019-5010.patch
deleted file mode 100644
index a3b1579bb12..00000000000
--- a/srcpkgs/python3/patches/CVE-2019-5010.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-commit 216a4d83c3b72f4fdcd81b588dc3f42cc461739a
-Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
-Date:   Tue Jan 15 17:16:36 2019 -0800
-
-    bpo-35746: Fix segfault in ssl's cert parser (GH-11569) (GH-11573)
-    
-    Fix a NULL pointer deref in ssl module. The cert parser did not handle CRL
-    distribution points with empty DP or URI correctly. A malicious or buggy
-    certificate can result into segfault.
-    
-    Signed-off-by: Christian Heimes <christian@python.org>
-    
-    https://bugs.python.org/issue35746
-    (cherry picked from commit a37f52436f9aa4b9292878b72f3ff1480e2606c3)
-    
-    Co-authored-by: Christian Heimes <christian@python.org>
-
-diff --git Modules/_ssl.c Modules/_ssl.c
-index a188d6a729..7365630a5e 100644
---- Modules/_ssl.c
-+++ Modules/_ssl.c
-@@ -1338,6 +1338,10 @@ _get_crl_dp(X509 *certificate) {
-         STACK_OF(GENERAL_NAME) *gns;
- 
-         dp = sk_DIST_POINT_value(dps, i);
-+        if (dp->distpoint == NULL) {
-+            /* Ignore empty DP value, CVE-2019-5010 */
-+            continue;
-+        }
-         gns = dp->distpoint->name.fullname;
- 
-         for (j=0; j < sk_GENERAL_NAME_num(gns); j++) {
diff --git a/srcpkgs/python3/template b/srcpkgs/python3/template
index 400b8a519f2..336b6a4d4a1 100644
--- a/srcpkgs/python3/template
+++ b/srcpkgs/python3/template
@@ -3,15 +3,15 @@
 # THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python3-tkinter".
 #
 pkgname=python3
-version=3.6.8
-revision=4
+version=3.6.9
+revision=1
 wrksrc="Python-${version}"
 short_desc="Interpreted, interactive, object-oriented programming language (${version%.*} series)"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://www.python.org"
 license="Python-2.0"
 distfiles="https://www.python.org/ftp/python/${version}/Python-${version}.tar.xz"
-checksum=35446241e995773b1bed7d196f4b624dadcadc8429f26282e756b2fb8a351193
+checksum=5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da
 
 pycompile_dirs="usr/lib/python${version%.*}"
 hostmakedepends="pkg-config"

From 21806aef3ba7051a994a556ebc771fef923c70c2 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 19:47:19 +0200
Subject: [PATCH 3/9] pkg-config: get rid of a redundant host dep.

---
 srcpkgs/pkg-config/template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/srcpkgs/pkg-config/template b/srcpkgs/pkg-config/template
index 68a910e6d1e..9caf7a14948 100644
--- a/srcpkgs/pkg-config/template
+++ b/srcpkgs/pkg-config/template
@@ -5,8 +5,6 @@ revision=2
 bootstrap=yes
 build_style=gnu-configure
 configure_args="--with-internal-glib --disable-host-tool"
-# required for gcc6 bootstrap
-hostmakedepends="gcc"
 short_desc="System for managing library compile/link flags"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2"

From 3c1cd8351e0225eae344e80e350853ee98f7b156 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 3 Jul 2019 20:39:21 +0200
Subject: [PATCH 4/9] xbps-src: fix XBPS_CHECKVERS_XCMD.

Needs to set -r $XBPS_CROSS_BASE to use correct dbdir.
---
 common/xbps-src/shutils/common.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index dea6e2b3bdd..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers --repository=$XBPS_REPOSITORY"
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS

From 70a75ddcaa71b28511c0c6b56e21ad7c337aa938 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 07:56:17 +0200
Subject: [PATCH 5/9] xbps-src: fix reconfiguration of bootstrap pkgs.

---
 xbps-src | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xbps-src b/xbps-src
index f72cc7002c9..b494306f58e 100755
--- a/xbps-src
+++ b/xbps-src
@@ -311,8 +311,8 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if $XBPS_QUERY_CMD $f &>/dev/null; then
-            $XBPS_RECONFIGURE_CMD -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile

From fce0a81ec88f2595b575ab7d6984c310772f2e44 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 11:00:13 +0200
Subject: [PATCH 6/9] xbps-src: improve bulk_sortdeps().

./xbps-src sort-dependencies $(./xbps-src show-build-deps xbps)

0.202s vs 0.514s
---
 common/xbps-src/shutils/bulk.sh | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 2d1d612c966..3a44dd1539e 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,24 +1,29 @@
 # vim: set ts=4 sw=4 et:
 
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
-    pkgs="$@"
     tmpf=$(mktemp) || exit 1
 
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+    # Perform a topological sort of all build dependencies.
+    if [ $NRUNNING -eq $NPROCS ]; then
+        NRUNNING=0
+        wait
+    fi
+
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            for f in ${pkgs}; do
-                [[ $f == $x ]] && found=1 && echo "${pkg} ${f}" >> $tmpf
+        # async/parallel execution
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [[ $found -eq 0 ]] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
@@ -30,7 +35,7 @@ bulk_build() {
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
     bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"

From 43de379081ed35dbd0fce59913ed37f132c13893 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 11:51:24 +0200
Subject: [PATCH 7/9] xbps-src: improve bulk code a bit more.

- use `show-avail` to discard broken pkgs.
- the parallel logic was incomplete.
- avoid unnecessary sorting.
---
 common/xbps-src/shutils/bulk.sh | 45 +++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 3a44dd1539e..964be3b66ff 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -8,14 +8,13 @@ bulk_sortdeps() {
 
     tmpf=$(mktemp) || exit 1
 
-    # Perform a topological sort of all build dependencies.
-    if [ $NRUNNING -eq $NPROCS ]; then
-        NRUNNING=0
-        wait
-    fi
-
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        # async/parallel execution
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
         (
             for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
                 echo "$pkg $_pkg" >> $tmpf
@@ -29,6 +28,9 @@ bulk_sortdeps() {
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
@@ -38,21 +40,38 @@ bulk_build() {
         msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers -f '%n' ${1} --distdir=$XBPS_DISTDIR)"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            if ./xbps-src show-avail $f &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg

From 4949a8625c449481d7f357aaea2ef151d74455c5 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 12:05:05 +0200
Subject: [PATCH 8/9] xbps-src: silence `show-avail`

---
 xbps-src | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xbps-src b/xbps-src
index b494306f58e..66078530bdd 100755
--- a/xbps-src
+++ b/xbps-src
@@ -794,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)

From a49fa898d2b70b5062bc151c5826e05319c6b6d6 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Thu, 4 Jul 2019 12:06:38 +0200
Subject: [PATCH 9/9] xbps-src: bulk_build() use existing shell funcs.

... rather than forking xbps-src again.
---
 common/xbps-src/shutils/bulk.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 964be3b66ff..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -53,7 +53,8 @@ bulk_build() {
         fi
         NRUNNING=$((NRUNNING+1))
         (
-            if ./xbps-src show-avail $f &>/dev/null; then
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
                 echo "$f"
             fi
         ) &

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (17 preceding siblings ...)
  2019-07-04 10:07 ` voidlinux-github
@ 2019-07-04 10:48 ` voidlinux-github
  2019-07-04 12:56 ` voidlinux-github
                   ` (26 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04 10:48 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 239 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508437582
Comment:
I'm running a bulk build via xbps-fbulk(1) for x86_64-musl. Will report results when it's finished.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (18 preceding siblings ...)
  2019-07-04 10:48 ` voidlinux-github
@ 2019-07-04 12:56 ` voidlinux-github
  2019-07-04 13:15 ` voidlinux-github
                   ` (25 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04 12:56 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 398 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508473148
Comment:
```
x86_64-musl bulk build started at 2019-07-04 12:24:08.269790074 +0200
x86_64-musl bulk build 16% completed, 14% success
  Total:   7011
  Success: 1019
  Fail:    36
  Skipped: 56
  Depfail: 70
```

My poor i5-3550 (ivybridge) is getting hot...

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (19 preceding siblings ...)
  2019-07-04 12:56 ` voidlinux-github
@ 2019-07-04 13:15 ` voidlinux-github
  2019-07-04 13:35 ` voidlinux-github
                   ` (24 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04 13:15 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 184 bytes --]

New comment by pullmoll on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508478752
Comment:
Sorry, I'm currently too busy to test xbps.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (20 preceding siblings ...)
  2019-07-04 13:15 ` voidlinux-github
@ 2019-07-04 13:35 ` voidlinux-github
  2019-07-04 13:39 ` voidlinux-github
                   ` (23 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04 13:35 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 172 bytes --]

New comment by Piraty on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508485079
Comment:
@xtraeme don't rush things please

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (21 preceding siblings ...)
  2019-07-04 13:35 ` voidlinux-github
@ 2019-07-04 13:39 ` voidlinux-github
  2019-07-04 15:03 ` voidlinux-github
                   ` (22 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04 13:39 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 216 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508486147
Comment:
I'm not rushing anything, @Piraty 

I'm running a bulk build for testing. 

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (22 preceding siblings ...)
  2019-07-04 13:39 ` voidlinux-github
@ 2019-07-04 15:03 ` voidlinux-github
  2019-07-04 19:32 ` voidlinux-github
                   ` (21 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04 15:03 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 363 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508512520
Comment:
```
(x86_64-musl) started at 2019-07-04 15:19:02.197073026 +0200
(x86_64-musl) 1762 of 7011 processed, 163 failed (36 failed, 50 skipped, 77 deps)
```

Still running, let's hope it does not take the whole weekend :-)


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (23 preceding siblings ...)
  2019-07-04 15:03 ` voidlinux-github
@ 2019-07-04 19:32 ` voidlinux-github
  2019-07-05  7:00 ` voidlinux-github
                   ` (20 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-04 19:32 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 297 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508562711
Comment:
```
x86_64-musl) started at 2019-07-04 15:19:02.197073026 +0200
(x86_64-musl) 2469 (35%) of 7011 processed, 2224 ok, 245 failed (76 skipped, 109 deps)
```

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (24 preceding siblings ...)
  2019-07-04 19:32 ` voidlinux-github
@ 2019-07-05  7:00 ` voidlinux-github
  2019-07-05  7:01 ` voidlinux-github
                   ` (19 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-05  7:00 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 484 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508653201
Comment:
```
(x86_64-musl) started at 2019-07-04 15:19:02.197073026 +0200
(x86_64-musl) 2469 (35%) of 7011 processed, 2224 ok, 245 failed (76 skipped, 109 deps)
```

Looks like I ran out of space and some pkgs failed. Will restart after the first pass.

I can see that only packages that use "virtual?" now fail, will get fixed for the next pass.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (25 preceding siblings ...)
  2019-07-05  7:00 ` voidlinux-github
@ 2019-07-05  7:01 ` voidlinux-github
  2019-07-05  9:47 ` [PR PATCH] [Closed]: " voidlinux-github
                   ` (18 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-05  7:01 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 485 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508653201
Comment:
```
(x86_64-musl) started at 2019-07-04 15:19:02.197073026 +0200
(x86_64-musl) 3544 (50%) of 7011 processed, 3060 ok, 484 failed (100 skipped, 280 deps)
```

Looks like I ran out of space and some pkgs failed. Will restart after the first pass.

I can see that only packages that use "virtual?" now fail, will get fixed for the next pass.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Closed]: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (26 preceding siblings ...)
  2019-07-05  7:01 ` voidlinux-github
@ 2019-07-05  9:47 ` voidlinux-github
  2019-07-05  9:54 ` voidlinux-github
                   ` (17 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-05  9:47 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 925 bytes --]

There's a closed pull request on the void-packages repository

xbps-src: multiple performance improvements
https://github.com/void-linux/void-packages/pull/12797
Description: xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (27 preceding siblings ...)
  2019-07-05  9:47 ` [PR PATCH] [Closed]: " voidlinux-github
@ 2019-07-05  9:54 ` voidlinux-github
  2019-07-05 10:09 ` voidlinux-github
                   ` (16 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-05  9:54 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 150 bytes --]

New comment by pullmoll on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508703950
Comment:
Shoot me.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (28 preceding siblings ...)
  2019-07-05  9:54 ` voidlinux-github
@ 2019-07-05 10:09 ` voidlinux-github
  2019-07-05 18:20 ` voidlinux-github
                   ` (15 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-05 10:09 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 196 bytes --]

New comment by pullmoll on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508708027
Comment:
Reverted except for the python3 and pkg-config updates.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (29 preceding siblings ...)
  2019-07-05 10:09 ` voidlinux-github
@ 2019-07-05 18:20 ` voidlinux-github
  2019-07-06  8:17 ` voidlinux-github
                   ` (14 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-05 18:20 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 165 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508832838
Comment:
Ok, no problem @pullmoll 

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (30 preceding siblings ...)
  2019-07-05 18:20 ` voidlinux-github
@ 2019-07-06  8:17 ` voidlinux-github
  2019-07-07  6:24 ` [PR PATCH] [Updated] " voidlinux-github
                   ` (13 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-06  8:17 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 500 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508907286
Comment:
I fixed the issue with packages that had `depends="virtual?foo"`.

```
(x86_64) started at 2019-07-06 08:23:32.854570446 +0200
(x86_64) 4512 (64%) of 7010 processed, 2232 ok, 2280 failed (47 skipped, 2175 deps)
```

I also moved to another fs with 250GB, so that it's building pkgs that failed previously due to ENOSPC.

I'll report results soon :-)


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (31 preceding siblings ...)
  2019-07-06  8:17 ` voidlinux-github
@ 2019-07-07  6:24 ` voidlinux-github
  2019-07-07  6:24 ` voidlinux-github
                   ` (12 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  6:24 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 67284 bytes --]

From 78833dc38097626f7dbee029cb17d8e9347f0bad Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:23:28 +0200
Subject: [PATCH] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the show-build-deps target is now much faster.
- the update-bulk/show-repo-updates targets are now much faster.
- the update-sys/show-sys-updates targets are now much faster.
- the bootstrap target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on #12433

Close #12433
Close #11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/libexec/xbps-src-doinstall.sh |   2 +-
 common/xbps-src/libexec/xbps-src-prepkg.sh    |   2 +-
 common/xbps-src/shutils/build_dependencies.sh | 488 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  95 ++--
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 326 ++++++------
 15 files changed, 446 insertions(+), 620 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/libexec/xbps-src-doinstall.sh b/common/xbps-src/libexec/xbps-src-doinstall.sh
index b3d5d7276f8..14e117a923b 100755
--- a/common/xbps-src/libexec/xbps-src-doinstall.sh
+++ b/common/xbps-src/libexec/xbps-src-doinstall.sh
@@ -63,7 +63,7 @@ if [ ! -f $XBPS_SUBPKG_INSTALL_DONE ]; then
             run_func pkg_install
         fi
     fi
-    setup_pkg_depends ${pkgname:=$PKGNAME}
+    setup_pkg_depends ${pkgname:=$PKGNAME} || exit 1
     run_pkg_hooks post-install
     touch -f $XBPS_SUBPKG_INSTALL_DONE
 fi
diff --git a/common/xbps-src/libexec/xbps-src-prepkg.sh b/common/xbps-src/libexec/xbps-src-prepkg.sh
index 4be45fd0a14..34f91b3f5f9 100755
--- a/common/xbps-src/libexec/xbps-src-prepkg.sh
+++ b/common/xbps-src/libexec/xbps-src-prepkg.sh
@@ -43,7 +43,7 @@ if [ "$sourcepkg" != "$PKGNAME" ]; then
 fi
 
 source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
-setup_pkg_depends $pkgname
+setup_pkg_depends $pkgname || exit 1
 run_pkg_hooks pre-pkg
 
 touch -f $XBPS_PREPKG_DONE
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..fd327066e17 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname _pkgname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,67 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            _pkgname=$(xbps-uhelper getpkgname $_depname 2>/dev/null)
+            [ -z "$_pkgname" ] && _pkgname="$_depname"
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +93,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +105,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +116,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +141,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1) || exit 1
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +306,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +336,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,83 +1,78 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
-
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     tmpf=$(mktemp) || exit 1
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
-            for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..c7c41f47193 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
+[ ! -d $XBPS_MASTERDIR ] &&  mkdir -p $XBPS_MASTERDIR
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -780,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (32 preceding siblings ...)
  2019-07-07  6:24 ` [PR PATCH] [Updated] " voidlinux-github
@ 2019-07-07  6:24 ` voidlinux-github
  2019-07-07  6:27 ` voidlinux-github
                   ` (11 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  6:24 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 67284 bytes --]

From 78833dc38097626f7dbee029cb17d8e9347f0bad Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:23:28 +0200
Subject: [PATCH] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the show-build-deps target is now much faster.
- the update-bulk/show-repo-updates targets are now much faster.
- the update-sys/show-sys-updates targets are now much faster.
- the bootstrap target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on #12433

Close #12433
Close #11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/libexec/xbps-src-doinstall.sh |   2 +-
 common/xbps-src/libexec/xbps-src-prepkg.sh    |   2 +-
 common/xbps-src/shutils/build_dependencies.sh | 488 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  95 ++--
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 326 ++++++------
 15 files changed, 446 insertions(+), 620 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/libexec/xbps-src-doinstall.sh b/common/xbps-src/libexec/xbps-src-doinstall.sh
index b3d5d7276f8..14e117a923b 100755
--- a/common/xbps-src/libexec/xbps-src-doinstall.sh
+++ b/common/xbps-src/libexec/xbps-src-doinstall.sh
@@ -63,7 +63,7 @@ if [ ! -f $XBPS_SUBPKG_INSTALL_DONE ]; then
             run_func pkg_install
         fi
     fi
-    setup_pkg_depends ${pkgname:=$PKGNAME}
+    setup_pkg_depends ${pkgname:=$PKGNAME} || exit 1
     run_pkg_hooks post-install
     touch -f $XBPS_SUBPKG_INSTALL_DONE
 fi
diff --git a/common/xbps-src/libexec/xbps-src-prepkg.sh b/common/xbps-src/libexec/xbps-src-prepkg.sh
index 4be45fd0a14..34f91b3f5f9 100755
--- a/common/xbps-src/libexec/xbps-src-prepkg.sh
+++ b/common/xbps-src/libexec/xbps-src-prepkg.sh
@@ -43,7 +43,7 @@ if [ "$sourcepkg" != "$PKGNAME" ]; then
 fi
 
 source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
-setup_pkg_depends $pkgname
+setup_pkg_depends $pkgname || exit 1
 run_pkg_hooks pre-pkg
 
 touch -f $XBPS_PREPKG_DONE
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..fd327066e17 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname _pkgname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,67 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            _pkgname=$(xbps-uhelper getpkgname $_depname 2>/dev/null)
+            [ -z "$_pkgname" ] && _pkgname="$_depname"
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +93,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +105,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +116,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +141,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1) || exit 1
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +306,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +336,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,83 +1,78 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
-
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     tmpf=$(mktemp) || exit 1
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
-            for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..c7c41f47193 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
+[ ! -d $XBPS_MASTERDIR ] &&  mkdir -p $XBPS_MASTERDIR
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -780,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (33 preceding siblings ...)
  2019-07-07  6:24 ` voidlinux-github
@ 2019-07-07  6:27 ` voidlinux-github
  2019-07-07  6:35 ` voidlinux-github
                   ` (10 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  6:27 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508974945
Comment:
This is the final version. No issues compared to current master. All build issues are unrelated to these changes (missing distfiles, gcc-9.x warnings, broken dependencies).



^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (34 preceding siblings ...)
  2019-07-07  6:27 ` voidlinux-github
@ 2019-07-07  6:35 ` voidlinux-github
  2019-07-07  6:36 ` [PR PATCH] [Updated] " voidlinux-github
                   ` (9 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  6:35 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508975335
Comment:
Also added a check to verify that all dependencies exist:

```
[juan@leysa void-packages]$ ./xbps-src -Nt install autofs
=> autofs-5.1.5_3: building [gnu-configure] ...
=> ERROR: autofs-5.1.5_3: host dependency 'rpcgen' does not exist!
[juan@leysa void-packages]$
```

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (36 preceding siblings ...)
  2019-07-07  6:36 ` [PR PATCH] [Updated] " voidlinux-github
@ 2019-07-07  6:36 ` voidlinux-github
  2019-07-07  7:00 ` voidlinux-github
                   ` (7 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  6:36 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 69904 bytes --]

From 78833dc38097626f7dbee029cb17d8e9347f0bad Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:23:28 +0200
Subject: [PATCH 1/2] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the show-build-deps target is now much faster.
- the update-bulk/show-repo-updates targets are now much faster.
- the update-sys/show-sys-updates targets are now much faster.
- the bootstrap target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on #12433

Close #12433
Close #11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/libexec/xbps-src-doinstall.sh |   2 +-
 common/xbps-src/libexec/xbps-src-prepkg.sh    |   2 +-
 common/xbps-src/shutils/build_dependencies.sh | 488 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  95 ++--
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 326 ++++++------
 15 files changed, 446 insertions(+), 620 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/libexec/xbps-src-doinstall.sh b/common/xbps-src/libexec/xbps-src-doinstall.sh
index b3d5d7276f8..14e117a923b 100755
--- a/common/xbps-src/libexec/xbps-src-doinstall.sh
+++ b/common/xbps-src/libexec/xbps-src-doinstall.sh
@@ -63,7 +63,7 @@ if [ ! -f $XBPS_SUBPKG_INSTALL_DONE ]; then
             run_func pkg_install
         fi
     fi
-    setup_pkg_depends ${pkgname:=$PKGNAME}
+    setup_pkg_depends ${pkgname:=$PKGNAME} || exit 1
     run_pkg_hooks post-install
     touch -f $XBPS_SUBPKG_INSTALL_DONE
 fi
diff --git a/common/xbps-src/libexec/xbps-src-prepkg.sh b/common/xbps-src/libexec/xbps-src-prepkg.sh
index 4be45fd0a14..34f91b3f5f9 100755
--- a/common/xbps-src/libexec/xbps-src-prepkg.sh
+++ b/common/xbps-src/libexec/xbps-src-prepkg.sh
@@ -43,7 +43,7 @@ if [ "$sourcepkg" != "$PKGNAME" ]; then
 fi
 
 source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
-setup_pkg_depends $pkgname
+setup_pkg_depends $pkgname || exit 1
 run_pkg_hooks pre-pkg
 
 touch -f $XBPS_PREPKG_DONE
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..fd327066e17 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname _pkgname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,67 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            _pkgname=$(xbps-uhelper getpkgname $_depname 2>/dev/null)
+            [ -z "$_pkgname" ] && _pkgname="$_depname"
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +93,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +105,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +116,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +141,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1) || exit 1
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +306,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +336,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,83 +1,78 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
-
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     tmpf=$(mktemp) || exit 1
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
-            for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..c7c41f47193 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
+[ ! -d $XBPS_MASTERDIR ] &&  mkdir -p $XBPS_MASTERDIR
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -780,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 48cecafe7516e07861451a08526914d7c07bc19c Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:36:05 +0200
Subject: [PATCH 2/2] xbps-src: verify all deps exist in srcpkgs.

---
 common/xbps-src/shutils/build_dependencies.sh | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index fd327066e17..6d9d727e0d3 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -145,6 +145,12 @@ install_pkg_deps() {
     # Host build dependencies.
     #
     if [[ ${hostmakedepends} ]]; then
+        # check validity
+        for f in ${hostmakedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: host dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -180,6 +186,12 @@ install_pkg_deps() {
     # Host check dependencies.
     #
     if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        # check validity
+        for f in ${checkdepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: check dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -215,6 +227,12 @@ install_pkg_deps() {
     # Target build dependencies.
     #
     if [[ ${makedepends} ]]; then
+        # check validity
+        for f in ${makedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: target dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -251,6 +269,11 @@ install_pkg_deps() {
     #
     if [[ ${depends} ]]; then
         _deps=$(setup_pkg_depends "" 1) || exit 1
+        for f in ${_deps}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: runtime dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (35 preceding siblings ...)
  2019-07-07  6:35 ` voidlinux-github
@ 2019-07-07  6:36 ` voidlinux-github
  2019-07-07  6:36 ` voidlinux-github
                   ` (8 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  6:36 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 69904 bytes --]

From 78833dc38097626f7dbee029cb17d8e9347f0bad Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:23:28 +0200
Subject: [PATCH 1/2] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the show-build-deps target is now much faster.
- the update-bulk/show-repo-updates targets are now much faster.
- the update-sys/show-sys-updates targets are now much faster.
- the bootstrap target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on #12433

Close #12433
Close #11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/libexec/xbps-src-doinstall.sh |   2 +-
 common/xbps-src/libexec/xbps-src-prepkg.sh    |   2 +-
 common/xbps-src/shutils/build_dependencies.sh | 488 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  95 ++--
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 326 ++++++------
 15 files changed, 446 insertions(+), 620 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/libexec/xbps-src-doinstall.sh b/common/xbps-src/libexec/xbps-src-doinstall.sh
index b3d5d7276f8..14e117a923b 100755
--- a/common/xbps-src/libexec/xbps-src-doinstall.sh
+++ b/common/xbps-src/libexec/xbps-src-doinstall.sh
@@ -63,7 +63,7 @@ if [ ! -f $XBPS_SUBPKG_INSTALL_DONE ]; then
             run_func pkg_install
         fi
     fi
-    setup_pkg_depends ${pkgname:=$PKGNAME}
+    setup_pkg_depends ${pkgname:=$PKGNAME} || exit 1
     run_pkg_hooks post-install
     touch -f $XBPS_SUBPKG_INSTALL_DONE
 fi
diff --git a/common/xbps-src/libexec/xbps-src-prepkg.sh b/common/xbps-src/libexec/xbps-src-prepkg.sh
index 4be45fd0a14..34f91b3f5f9 100755
--- a/common/xbps-src/libexec/xbps-src-prepkg.sh
+++ b/common/xbps-src/libexec/xbps-src-prepkg.sh
@@ -43,7 +43,7 @@ if [ "$sourcepkg" != "$PKGNAME" ]; then
 fi
 
 source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
-setup_pkg_depends $pkgname
+setup_pkg_depends $pkgname || exit 1
 run_pkg_hooks pre-pkg
 
 touch -f $XBPS_PREPKG_DONE
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..fd327066e17 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname _pkgname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,67 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            _pkgname=$(xbps-uhelper getpkgname $_depname 2>/dev/null)
+            [ -z "$_pkgname" ] && _pkgname="$_depname"
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +93,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +105,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +116,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +141,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1) || exit 1
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +306,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +336,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,83 +1,78 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
-
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     tmpf=$(mktemp) || exit 1
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
-            for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..c7c41f47193 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
+[ ! -d $XBPS_MASTERDIR ] &&  mkdir -p $XBPS_MASTERDIR
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -780,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 48cecafe7516e07861451a08526914d7c07bc19c Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:36:05 +0200
Subject: [PATCH 2/2] xbps-src: verify all deps exist in srcpkgs.

---
 common/xbps-src/shutils/build_dependencies.sh | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index fd327066e17..6d9d727e0d3 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -145,6 +145,12 @@ install_pkg_deps() {
     # Host build dependencies.
     #
     if [[ ${hostmakedepends} ]]; then
+        # check validity
+        for f in ${hostmakedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: host dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -180,6 +186,12 @@ install_pkg_deps() {
     # Host check dependencies.
     #
     if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        # check validity
+        for f in ${checkdepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: check dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -215,6 +227,12 @@ install_pkg_deps() {
     # Target build dependencies.
     #
     if [[ ${makedepends} ]]; then
+        # check validity
+        for f in ${makedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: target dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -251,6 +269,11 @@ install_pkg_deps() {
     #
     if [[ ${depends} ]]; then
         _deps=$(setup_pkg_depends "" 1) || exit 1
+        for f in ${_deps}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: runtime dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (38 preceding siblings ...)
  2019-07-07  7:00 ` voidlinux-github
@ 2019-07-07  7:00 ` voidlinux-github
  2019-07-07  7:38 ` voidlinux-github
                   ` (5 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  7:00 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 70734 bytes --]

From 78833dc38097626f7dbee029cb17d8e9347f0bad Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:23:28 +0200
Subject: [PATCH 1/3] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the show-build-deps target is now much faster.
- the update-bulk/show-repo-updates targets are now much faster.
- the update-sys/show-sys-updates targets are now much faster.
- the bootstrap target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on #12433

Close #12433
Close #11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/libexec/xbps-src-doinstall.sh |   2 +-
 common/xbps-src/libexec/xbps-src-prepkg.sh    |   2 +-
 common/xbps-src/shutils/build_dependencies.sh | 488 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  95 ++--
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 326 ++++++------
 15 files changed, 446 insertions(+), 620 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/libexec/xbps-src-doinstall.sh b/common/xbps-src/libexec/xbps-src-doinstall.sh
index b3d5d7276f8..14e117a923b 100755
--- a/common/xbps-src/libexec/xbps-src-doinstall.sh
+++ b/common/xbps-src/libexec/xbps-src-doinstall.sh
@@ -63,7 +63,7 @@ if [ ! -f $XBPS_SUBPKG_INSTALL_DONE ]; then
             run_func pkg_install
         fi
     fi
-    setup_pkg_depends ${pkgname:=$PKGNAME}
+    setup_pkg_depends ${pkgname:=$PKGNAME} || exit 1
     run_pkg_hooks post-install
     touch -f $XBPS_SUBPKG_INSTALL_DONE
 fi
diff --git a/common/xbps-src/libexec/xbps-src-prepkg.sh b/common/xbps-src/libexec/xbps-src-prepkg.sh
index 4be45fd0a14..34f91b3f5f9 100755
--- a/common/xbps-src/libexec/xbps-src-prepkg.sh
+++ b/common/xbps-src/libexec/xbps-src-prepkg.sh
@@ -43,7 +43,7 @@ if [ "$sourcepkg" != "$PKGNAME" ]; then
 fi
 
 source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
-setup_pkg_depends $pkgname
+setup_pkg_depends $pkgname || exit 1
 run_pkg_hooks pre-pkg
 
 touch -f $XBPS_PREPKG_DONE
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..fd327066e17 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname _pkgname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,67 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            _pkgname=$(xbps-uhelper getpkgname $_depname 2>/dev/null)
+            [ -z "$_pkgname" ] && _pkgname="$_depname"
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +93,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +105,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +116,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +141,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1) || exit 1
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +306,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +336,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,83 +1,78 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
-
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     tmpf=$(mktemp) || exit 1
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
-            for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..c7c41f47193 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
+[ ! -d $XBPS_MASTERDIR ] &&  mkdir -p $XBPS_MASTERDIR
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -780,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 48cecafe7516e07861451a08526914d7c07bc19c Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:36:05 +0200
Subject: [PATCH 2/3] xbps-src: verify all deps exist in srcpkgs.

---
 common/xbps-src/shutils/build_dependencies.sh | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index fd327066e17..6d9d727e0d3 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -145,6 +145,12 @@ install_pkg_deps() {
     # Host build dependencies.
     #
     if [[ ${hostmakedepends} ]]; then
+        # check validity
+        for f in ${hostmakedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: host dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -180,6 +186,12 @@ install_pkg_deps() {
     # Host check dependencies.
     #
     if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        # check validity
+        for f in ${checkdepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: check dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -215,6 +227,12 @@ install_pkg_deps() {
     # Target build dependencies.
     #
     if [[ ${makedepends} ]]; then
+        # check validity
+        for f in ${makedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: target dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -251,6 +269,11 @@ install_pkg_deps() {
     #
     if [[ ${depends} ]]; then
         _deps=$(setup_pkg_depends "" 1) || exit 1
+        for f in ${_deps}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: runtime dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo

From 5048a2c73c226afe300a787d72ed2f062c9e9bf0 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:59:22 +0200
Subject: [PATCH 3/3] xbps-src/show.sh: error out if dep does not exist.

---
 common/xbps-src/shutils/show.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index 67b2ec14810..d0c260ed0ae 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -68,6 +68,9 @@ show_pkg_build_depends() {
 
     # build time deps
     for f in ${_deps}; do
+        if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+            msg_error "$pkgver: dependency '$f' does not exist!\n"
+        fi
         # ignore virtual dependencies
         [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (37 preceding siblings ...)
  2019-07-07  6:36 ` voidlinux-github
@ 2019-07-07  7:00 ` voidlinux-github
  2019-07-07  7:00 ` voidlinux-github
                   ` (6 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  7:00 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 70734 bytes --]

From 78833dc38097626f7dbee029cb17d8e9347f0bad Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:23:28 +0200
Subject: [PATCH 1/3] xbps-src: multiple performance improvements.

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the show-build-deps target is now much faster.
- the update-bulk/show-repo-updates targets are now much faster.
- the update-sys/show-sys-updates targets are now much faster.
- the bootstrap target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on #12433

Close #12433
Close #11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/libexec/xbps-src-doinstall.sh |   2 +-
 common/xbps-src/libexec/xbps-src-prepkg.sh    |   2 +-
 common/xbps-src/shutils/build_dependencies.sh | 488 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  95 ++--
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  41 +-
 xbps-src                                      | 326 ++++++------
 15 files changed, 446 insertions(+), 620 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/libexec/xbps-src-doinstall.sh b/common/xbps-src/libexec/xbps-src-doinstall.sh
index b3d5d7276f8..14e117a923b 100755
--- a/common/xbps-src/libexec/xbps-src-doinstall.sh
+++ b/common/xbps-src/libexec/xbps-src-doinstall.sh
@@ -63,7 +63,7 @@ if [ ! -f $XBPS_SUBPKG_INSTALL_DONE ]; then
             run_func pkg_install
         fi
     fi
-    setup_pkg_depends ${pkgname:=$PKGNAME}
+    setup_pkg_depends ${pkgname:=$PKGNAME} || exit 1
     run_pkg_hooks post-install
     touch -f $XBPS_SUBPKG_INSTALL_DONE
 fi
diff --git a/common/xbps-src/libexec/xbps-src-prepkg.sh b/common/xbps-src/libexec/xbps-src-prepkg.sh
index 4be45fd0a14..34f91b3f5f9 100755
--- a/common/xbps-src/libexec/xbps-src-prepkg.sh
+++ b/common/xbps-src/libexec/xbps-src-prepkg.sh
@@ -43,7 +43,7 @@ if [ "$sourcepkg" != "$PKGNAME" ]; then
 fi
 
 source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
-setup_pkg_depends $pkgname
+setup_pkg_depends $pkgname || exit 1
 run_pkg_hooks pre-pkg
 
 touch -f $XBPS_PREPKG_DONE
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..fd327066e17 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname _pkgname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,67 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            _pkgname=$(xbps-uhelper getpkgname $_depname 2>/dev/null)
+            [ -z "$_pkgname" ] && _pkgname="$_depname"
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +93,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +105,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +116,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +141,151 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
+    if [[ ${hostmakedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+    if [[ ${makedepends} ]]; then
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
-            fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
-        done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1) || exit 1
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +306,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +336,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,83 +1,78 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
-
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     tmpf=$(mktemp) || exit 1
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
-            for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 17ba9dde6ca..7e28f1120dd 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..67b2ec14810 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,22 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
         # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
-        fi
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +86,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..c7c41f47193 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
+[ ! -d $XBPS_MASTERDIR ] &&  mkdir -p $XBPS_MASTERDIR
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -780,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 48cecafe7516e07861451a08526914d7c07bc19c Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:36:05 +0200
Subject: [PATCH 2/3] xbps-src: verify all deps exist in srcpkgs.

---
 common/xbps-src/shutils/build_dependencies.sh | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index fd327066e17..6d9d727e0d3 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -145,6 +145,12 @@ install_pkg_deps() {
     # Host build dependencies.
     #
     if [[ ${hostmakedepends} ]]; then
+        # check validity
+        for f in ${hostmakedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: host dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -180,6 +186,12 @@ install_pkg_deps() {
     # Host check dependencies.
     #
     if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        # check validity
+        for f in ${checkdepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: check dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -215,6 +227,12 @@ install_pkg_deps() {
     # Target build dependencies.
     #
     if [[ ${makedepends} ]]; then
+        # check validity
+        for f in ${makedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: target dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo
@@ -251,6 +269,11 @@ install_pkg_deps() {
     #
     if [[ ${depends} ]]; then
         _deps=$(setup_pkg_depends "" 1) || exit 1
+        for f in ${_deps}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: runtime dependency '$f' does not exist!\n"
+            fi
+        done
         while read -r _depname _deprepover _depver _subpkg _repourl; do
             _vpkg=${_subpkg}-${_depver}
             # binary package found in a repo

From 5048a2c73c226afe300a787d72ed2f062c9e9bf0 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 08:59:22 +0200
Subject: [PATCH 3/3] xbps-src/show.sh: error out if dep does not exist.

---
 common/xbps-src/shutils/show.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index 67b2ec14810..d0c260ed0ae 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -68,6 +68,9 @@ show_pkg_build_depends() {
 
     # build time deps
     for f in ${_deps}; do
+        if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+            msg_error "$pkgver: dependency '$f' does not exist!\n"
+        fi
         # ignore virtual dependencies
         [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (39 preceding siblings ...)
  2019-07-07  7:00 ` voidlinux-github
@ 2019-07-07  7:38 ` voidlinux-github
  2019-07-07  7:38 ` voidlinux-github
                   ` (4 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  7:38 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 68301 bytes --]

From f98674428db7f8f337508a7dc0c2d35355693209 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 09:37:56 +0200
Subject: [PATCH] xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the show-build-deps target is now much faster.
- the update-bulk/show-repo-updates targets are now much faster.
- the update-sys/show-sys-updates targets are now much faster.
- the bootstrap target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on #12433

Close #12433
Close #11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/libexec/xbps-src-doinstall.sh |   2 +-
 common/xbps-src/libexec/xbps-src-prepkg.sh    |   2 +-
 common/xbps-src/shutils/build_dependencies.sh | 505 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  95 ++--
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  44 +-
 xbps-src                                      | 326 +++++------
 15 files changed, 469 insertions(+), 617 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/libexec/xbps-src-doinstall.sh b/common/xbps-src/libexec/xbps-src-doinstall.sh
index b3d5d7276f8..14e117a923b 100755
--- a/common/xbps-src/libexec/xbps-src-doinstall.sh
+++ b/common/xbps-src/libexec/xbps-src-doinstall.sh
@@ -63,7 +63,7 @@ if [ ! -f $XBPS_SUBPKG_INSTALL_DONE ]; then
             run_func pkg_install
         fi
     fi
-    setup_pkg_depends ${pkgname:=$PKGNAME}
+    setup_pkg_depends ${pkgname:=$PKGNAME} || exit 1
     run_pkg_hooks post-install
     touch -f $XBPS_SUBPKG_INSTALL_DONE
 fi
diff --git a/common/xbps-src/libexec/xbps-src-prepkg.sh b/common/xbps-src/libexec/xbps-src-prepkg.sh
index 4be45fd0a14..34f91b3f5f9 100755
--- a/common/xbps-src/libexec/xbps-src-prepkg.sh
+++ b/common/xbps-src/libexec/xbps-src-prepkg.sh
@@ -43,7 +43,7 @@ if [ "$sourcepkg" != "$PKGNAME" ]; then
 fi
 
 source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
-setup_pkg_depends $pkgname
+setup_pkg_depends $pkgname || exit 1
 run_pkg_hooks pre-pkg
 
 touch -f $XBPS_PREPKG_DONE
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..6d9d727e0d3 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname _pkgname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,67 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            _pkgname=$(xbps-uhelper getpkgname $_depname 2>/dev/null)
+            [ -z "$_pkgname" ] && _pkgname="$_depname"
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +93,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +105,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +116,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +141,174 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
-                continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
+    if [[ ${hostmakedepends} ]]; then
+        # check validity
+        for f in ${hostmakedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: host dependency '$f' does not exist!\n"
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
+        done
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
-                continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        # check validity
+        for f in ${checkdepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: check dependency '$f' does not exist!\n"
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
+        done
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
+    if [[ ${makedepends} ]]; then
+        # check validity
+        for f in ${makedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: target dependency '$f' does not exist!\n"
+            fi
         done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1) || exit 1
+        for f in ${_deps}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: runtime dependency '$f' does not exist!\n"
             fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
         done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +329,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +359,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,83 +1,78 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
-
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     tmpf=$(mktemp) || exit 1
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
-            for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index dec8fa36117..49fa05f79b5 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin:$PATH" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..d0c260ed0ae 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,25 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
-        # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
+        if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+            msg_error "$pkgver: dependency '$f' does not exist!\n"
         fi
+        # ignore virtual dependencies
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +89,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..c7c41f47193 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
+[ ! -d $XBPS_MASTERDIR ] &&  mkdir -p $XBPS_MASTERDIR
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -780,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (40 preceding siblings ...)
  2019-07-07  7:38 ` voidlinux-github
@ 2019-07-07  7:38 ` voidlinux-github
  2019-07-07  9:31 ` voidlinux-github
                   ` (3 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  7:38 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 68301 bytes --]

From f98674428db7f8f337508a7dc0c2d35355693209 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 7 Jul 2019 09:37:56 +0200
Subject: [PATCH] xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the show-build-deps target is now much faster.
- the update-bulk/show-repo-updates targets are now much faster.
- the update-sys/show-sys-updates targets are now much faster.
- the bootstrap target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on #12433

Close #12433
Close #11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/libexec/xbps-src-doinstall.sh |   2 +-
 common/xbps-src/libexec/xbps-src-prepkg.sh    |   2 +-
 common/xbps-src/shutils/build_dependencies.sh | 505 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  95 ++--
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  44 +-
 xbps-src                                      | 326 +++++------
 15 files changed, 469 insertions(+), 617 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/libexec/xbps-src-doinstall.sh b/common/xbps-src/libexec/xbps-src-doinstall.sh
index b3d5d7276f8..14e117a923b 100755
--- a/common/xbps-src/libexec/xbps-src-doinstall.sh
+++ b/common/xbps-src/libexec/xbps-src-doinstall.sh
@@ -63,7 +63,7 @@ if [ ! -f $XBPS_SUBPKG_INSTALL_DONE ]; then
             run_func pkg_install
         fi
     fi
-    setup_pkg_depends ${pkgname:=$PKGNAME}
+    setup_pkg_depends ${pkgname:=$PKGNAME} || exit 1
     run_pkg_hooks post-install
     touch -f $XBPS_SUBPKG_INSTALL_DONE
 fi
diff --git a/common/xbps-src/libexec/xbps-src-prepkg.sh b/common/xbps-src/libexec/xbps-src-prepkg.sh
index 4be45fd0a14..34f91b3f5f9 100755
--- a/common/xbps-src/libexec/xbps-src-prepkg.sh
+++ b/common/xbps-src/libexec/xbps-src-prepkg.sh
@@ -43,7 +43,7 @@ if [ "$sourcepkg" != "$PKGNAME" ]; then
 fi
 
 source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
-setup_pkg_depends $pkgname
+setup_pkg_depends $pkgname || exit 1
 run_pkg_hooks pre-pkg
 
 touch -f $XBPS_PREPKG_DONE
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..6d9d727e0d3 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname _pkgname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,67 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            _pkgname=$(xbps-uhelper getpkgname $_depname 2>/dev/null)
+            [ -z "$_pkgname" ] && _pkgname="$_depname"
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +93,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +105,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +116,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +141,174 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
-                continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
+    if [[ ${hostmakedepends} ]]; then
+        # check validity
+        for f in ${hostmakedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: host dependency '$f' does not exist!\n"
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
+        done
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
-                continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        # check validity
+        for f in ${checkdepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: check dependency '$f' does not exist!\n"
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
+        done
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
+    if [[ ${makedepends} ]]; then
+        # check validity
+        for f in ${makedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: target dependency '$f' does not exist!\n"
+            fi
         done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1) || exit 1
+        for f in ${_deps}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: runtime dependency '$f' does not exist!\n"
             fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
         done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +329,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +359,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,83 +1,78 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
-
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     tmpf=$(mktemp) || exit 1
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
-            for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index dec8fa36117..49fa05f79b5 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin:$PATH" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..d0c260ed0ae 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,25 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
-        # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
+        if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+            msg_error "$pkgver: dependency '$f' does not exist!\n"
         fi
+        # ignore virtual dependencies
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +89,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..c7c41f47193 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
+[ ! -d $XBPS_MASTERDIR ] &&  mkdir -p $XBPS_MASTERDIR
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -780,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (41 preceding siblings ...)
  2019-07-07  7:38 ` voidlinux-github
@ 2019-07-07  9:31 ` voidlinux-github
  2019-07-10 17:51 ` [PR PATCH] [Updated] " voidlinux-github
                   ` (2 subsequent siblings)
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-07  9:31 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 204 bytes --]

New comment by xtraeme on void-packages repository

https://github.com/void-linux/void-packages/pull/12797#issuecomment-508985251
Comment:
Please test and review, will merge next friday if no objections.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (43 preceding siblings ...)
  2019-07-10 17:51 ` [PR PATCH] [Updated] " voidlinux-github
@ 2019-07-10 17:51 ` voidlinux-github
  2019-07-10 18:28 ` [PR PATCH] [Merged]: " voidlinux-github
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-10 17:51 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 71292 bytes --]

From 57083272892cc20f541b69975d6ba2b1e003ab12 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 10 Jul 2019 19:48:54 +0200
Subject: [PATCH 1/4] xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the show-build-deps target is now much faster.
- the update-bulk/show-repo-updates targets are now much faster.
- the update-sys/show-sys-updates targets are now much faster.
- the bootstrap target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on #12433

Close #12433
Close #11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/libexec/xbps-src-doinstall.sh |   2 +-
 common/xbps-src/libexec/xbps-src-prepkg.sh    |   2 +-
 common/xbps-src/shutils/build_dependencies.sh | 505 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  95 ++--
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  44 +-
 xbps-src                                      | 326 +++++------
 15 files changed, 469 insertions(+), 617 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/libexec/xbps-src-doinstall.sh b/common/xbps-src/libexec/xbps-src-doinstall.sh
index b3d5d7276f8..14e117a923b 100755
--- a/common/xbps-src/libexec/xbps-src-doinstall.sh
+++ b/common/xbps-src/libexec/xbps-src-doinstall.sh
@@ -63,7 +63,7 @@ if [ ! -f $XBPS_SUBPKG_INSTALL_DONE ]; then
             run_func pkg_install
         fi
     fi
-    setup_pkg_depends ${pkgname:=$PKGNAME}
+    setup_pkg_depends ${pkgname:=$PKGNAME} || exit 1
     run_pkg_hooks post-install
     touch -f $XBPS_SUBPKG_INSTALL_DONE
 fi
diff --git a/common/xbps-src/libexec/xbps-src-prepkg.sh b/common/xbps-src/libexec/xbps-src-prepkg.sh
index 4be45fd0a14..34f91b3f5f9 100755
--- a/common/xbps-src/libexec/xbps-src-prepkg.sh
+++ b/common/xbps-src/libexec/xbps-src-prepkg.sh
@@ -43,7 +43,7 @@ if [ "$sourcepkg" != "$PKGNAME" ]; then
 fi
 
 source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
-setup_pkg_depends $pkgname
+setup_pkg_depends $pkgname || exit 1
 run_pkg_hooks pre-pkg
 
 touch -f $XBPS_PREPKG_DONE
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..6d9d727e0d3 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname _pkgname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,67 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            _pkgname=$(xbps-uhelper getpkgname $_depname 2>/dev/null)
+            [ -z "$_pkgname" ] && _pkgname="$_depname"
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +93,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +105,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +116,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +141,174 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
-                continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
+    if [[ ${hostmakedepends} ]]; then
+        # check validity
+        for f in ${hostmakedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: host dependency '$f' does not exist!\n"
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
+        done
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
-                continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        # check validity
+        for f in ${checkdepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: check dependency '$f' does not exist!\n"
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
+        done
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
+    if [[ ${makedepends} ]]; then
+        # check validity
+        for f in ${makedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: target dependency '$f' does not exist!\n"
+            fi
         done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1) || exit 1
+        for f in ${_deps}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: runtime dependency '$f' does not exist!\n"
             fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
         done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +329,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +359,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,83 +1,78 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
-
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     tmpf=$(mktemp) || exit 1
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
-            for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index dec8fa36117..49fa05f79b5 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin:$PATH" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..d0c260ed0ae 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,25 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
-        # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
+        if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+            msg_error "$pkgver: dependency '$f' does not exist!\n"
         fi
+        # ignore virtual dependencies
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +89,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..c7c41f47193 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
+[ ! -d $XBPS_MASTERDIR ] &&  mkdir -p $XBPS_MASTERDIR
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -780,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 8f74846ff8e4ed079225cf412f11cdc432733a7d Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 10 Jul 2019 19:49:39 +0200
Subject: [PATCH 2/4] qt5: use a working distfile mirror.

---
 srcpkgs/qt5/template | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/srcpkgs/qt5/template b/srcpkgs/qt5/template
index 8d170535e89..2293f512d0a 100644
--- a/srcpkgs/qt5/template
+++ b/srcpkgs/qt5/template
@@ -20,7 +20,7 @@ short_desc="Cross-platform application and UI framework (QT5)"
 maintainer="Jürgen Buchmüller <pullmoll@t-online.de>"
 license="GPL-3.0-or-later, LGPL-2.1-or-later"
 homepage="https://qt.io/"
-distfiles="http://download.qt.io/official_releases/qt/${version%.*}/${version}/single/qt-everywhere-src-${version}.tar.xz"
+distfiles="http://mirrors.ukfast.co.uk/sites/qt.io/archive/qt/${version%.*}/${version}/single/qt-everywhere-src-${version}.tar.xz"
 checksum=859417642713cee2493ee3646a7fee782c9f1db39e41d7bb1322bba0c5f0ff4d
 replaces="qt5-doc<5.6.0 qt5-quick1<5.6.0 qt5-quick1-devel<5.6.0 qt5-webkit<5.6.0 qt5-webkit-devel<5.6.0
  qt5-enginio<5.7.1 qt5-enginio-devel<5.7.1 qt5-plugin-gtk<5.7.1"

From 7bc928b0aa08eb9344802b28606ae5be81b8bb46 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 10 Jul 2019 19:50:09 +0200
Subject: [PATCH 3/4] bash-completion: a runtime dependency on bash is enough.

---
 srcpkgs/bash-completion/template | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/srcpkgs/bash-completion/template b/srcpkgs/bash-completion/template
index 01ecdd0a726..80c273f8713 100644
--- a/srcpkgs/bash-completion/template
+++ b/srcpkgs/bash-completion/template
@@ -5,8 +5,7 @@ revision=1
 archs=noarch
 build_style=gnu-configure
 make_install_args="profiledir=/etc/bash/bashrc.d"
-makedepends="bash"
-depends="${makedepends}"
+depends="bash"
 short_desc="Programmable completion for the GNU Bash shell"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2.0-or-later"

From 3a160bf0ecbef6fe8780f4f1281403655f852abc Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 10 Jul 2019 19:50:33 +0200
Subject: [PATCH 4/4] docbook2x: a runtime dependency on texinfo is enough.

---
 srcpkgs/docbook2x/template | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/srcpkgs/docbook2x/template b/srcpkgs/docbook2x/template
index cc93280cd93..614a2c65477 100644
--- a/srcpkgs/docbook2x/template
+++ b/srcpkgs/docbook2x/template
@@ -6,8 +6,8 @@ patch_args="-Np1"
 wrksrc="docbook2X-${version}"
 build_style=gnu-configure
 configure_args="--without-resolver-jars --without-saxon-jars --without-xalan-jars"
-hostmakedepends="texinfo libxslt docbook docbook-dsssl docbook-xsl perl-XML-SAX"
-depends="${hostmakedepends}"
+hostmakedepends="libxslt docbook docbook-dsssl docbook-xsl perl-XML-SAX"
+depends="texinfo ${hostmakedepends}"
 xml_entries="
  nextCatalog /usr/share/docbook2X/dtd/catalog.xml --
  nextCatalog /usr/share/docbook2X/xslt/catalog.xml --"

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Updated] xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (42 preceding siblings ...)
  2019-07-07  9:31 ` voidlinux-github
@ 2019-07-10 17:51 ` voidlinux-github
  2019-07-10 17:51 ` voidlinux-github
  2019-07-10 18:28 ` [PR PATCH] [Merged]: " voidlinux-github
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-10 17:51 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

There is an updated pull request by xtraeme against master on the void-packages repository

https://github.com/xtraeme/void-packages xbps-src-ultra-fast
https://github.com/void-linux/void-packages/pull/12797

xbps-src: multiple performance improvements
xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

A patch file from https://github.com/void-linux/void-packages/pull/12797.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-xbps-src-ultra-fast-12797.patch --]
[-- Type: application/text/x-diff, Size: 71292 bytes --]

From 57083272892cc20f541b69975d6ba2b1e003ab12 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 10 Jul 2019 19:48:54 +0200
Subject: [PATCH 1/4] xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the show-build-deps target is now much faster.
- the update-bulk/show-repo-updates targets are now much faster.
- the update-sys/show-sys-updates targets are now much faster.
- the bootstrap target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

Based on work started by @Duncaen on #12433

Close #12433
Close #11282
---
 .gitignore                                    |   1 +
 common/hooks/do-pkg/00-gen-pkg.sh             |   8 +-
 .../hooks/pre-pkg/04-generate-runtime-deps.sh |  41 +-
 common/hooks/pre-pkg/99-pkglint.sh            |   4 +-
 common/xbps-src/libexec/build.sh              |   4 -
 common/xbps-src/libexec/xbps-src-doinstall.sh |   2 +-
 common/xbps-src/libexec/xbps-src-prepkg.sh    |   2 +-
 common/xbps-src/shutils/build_dependencies.sh | 505 +++++++-----------
 common/xbps-src/shutils/bulk.sh               |  95 ++--
 common/xbps-src/shutils/chroot.sh             |  21 +-
 common/xbps-src/shutils/common.sh             |  16 +-
 common/xbps-src/shutils/cross.sh              |  13 +-
 common/xbps-src/shutils/pkgtarget.sh          |   4 +
 common/xbps-src/shutils/show.sh               |  44 +-
 xbps-src                                      | 326 +++++------
 15 files changed, 469 insertions(+), 617 deletions(-)

diff --git a/.gitignore b/.gitignore
index acc6bf33479..591b3507593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ masterdir*
 hostdir*
 etc/conf
 etc/virtual
+.xbps-checkvers.plist
diff --git a/common/hooks/do-pkg/00-gen-pkg.sh b/common/hooks/do-pkg/00-gen-pkg.sh
index 78ec2a1422a..c0ed088da9d 100644
--- a/common/hooks/do-pkg/00-gen-pkg.sh
+++ b/common/hooks/do-pkg/00-gen-pkg.sh
@@ -32,16 +32,16 @@ genpkg() {
 
 	_preserve=${preserve:+-p}
 	if [ -s ${PKGDESTDIR}/rdeps ]; then
-		_deps="$(cat ${PKGDESTDIR}/rdeps)"
+		_deps="$(<${PKGDESTDIR}/rdeps)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-provides ]; then
-		_shprovides="$(cat ${PKGDESTDIR}/shlib-provides)"
+		_shprovides="$(<${PKGDESTDIR}/shlib-provides)"
 	fi
 	if [ -s ${PKGDESTDIR}/shlib-requires ]; then
-		_shrequires="$(cat ${PKGDESTDIR}/shlib-requires)"
+		_shrequires="$(<${PKGDESTDIR}/shlib-requires)"
 	fi
 	if [ -s ${XBPS_STATEDIR}/gitrev ]; then
-		_gitrevs="$(cat ${XBPS_STATEDIR}/gitrev)"
+		_gitrevs="$(<${XBPS_STATEDIR}/gitrev)"
 	fi
 
 	# Stripping whitespaces
diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
index 62077022711..6e45b7dd3c3 100644
--- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh
+++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh
@@ -5,7 +5,7 @@
 #	- Generates shlib-requires file for xbps-create(1)
 
 add_rundep() {
-    local dep="$1" i= rpkgdep= _depname= _rdeps= found=
+    local dep="$1" i= rpkgdep= _depname= found=
 
     _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
     if [ -z "${_depname}" ]; then
@@ -68,26 +68,19 @@ hook() {
     exec < $depsftmp
     while read f; do
         lf=${f#${PKGDESTDIR}}
-	if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
-		msg_normal "Skipping dependency scan for ${lf}\n"
-		continue
-	fi
+	    if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
+		    msg_normal "Skipping dependency scan for ${lf}\n"
+		    continue
+	    fi
         case "$(file -bi "$f")" in
             application/x-*executable*|application/x-sharedlib*)
                 for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
-                    if [ -z "$verify_deps" ]; then
-                        verify_deps="$nlib"
-                        continue
-                    fi
+                    [ -z "$verify_deps" ] && verify_deps="$nlib" && continue
+                    found=0
                     for j in ${verify_deps}; do
-                        [ "$j" != "$nlib" ] && continue
-                        found_dup=1
-                        break
+                        [[ $j == $nlib ]] && found=1 && break
                     done
-                    if [ -z "$found_dup" ]; then
-                        verify_deps="$verify_deps $nlib"
-                    fi
-                    unset found_dup
+                    [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
                 done
                 ;;
         esac
@@ -97,13 +90,13 @@ hook() {
 
     #
     # Add required run time packages by using required shlibs resolved
-    # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
+    # above, the mapping is done thru the common/shlibs file.
     #
     for f in ${verify_deps}; do
         unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
         _f=$(echo "$f"|sed -E 's|\+|\\+|g')
-        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
-        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
+        rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2)"
+        rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|cut -d ' ' -f2|wc -l)"
         if [ -z "$rdep" ]; then
             # Ignore libs by current pkg
             soname=$(find ${PKGDESTDIR} -name "$f")
@@ -121,15 +114,9 @@ hook() {
                 _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
                 # if there's a SONAME matching pkgname, use it.
                 for x in ${pkgname} ${subpackages}; do
-                    if [ "${_pkgname}" = "${x}" ]; then
-                        found=1
-                        break
-                    fi
+                    [[ $_pkgname == $x ]] && found=1 && break
                 done
-                if [ -n "$found" ]; then
-                    _rdep=$j
-                    break
-                fi
+                [[ $found ]] && _rdep=$j && break
             done
             if [ -z "${_rdep}" ]; then
                 # otherwise pick up the first one.
diff --git a/common/hooks/pre-pkg/99-pkglint.sh b/common/hooks/pre-pkg/99-pkglint.sh
index 7ae183ae8e8..ab2b215508e 100644
--- a/common/hooks/pre-pkg/99-pkglint.sh
+++ b/common/hooks/pre-pkg/99-pkglint.sh
@@ -119,7 +119,7 @@ hook() {
 				msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
 				msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
 				msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
-				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|awk '{print $1}')
+				_revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
 				for x in ${_revdeps}; do
 					msg_red "   ${x%:}\n"
 				done
@@ -128,7 +128,7 @@ hook() {
 			# Try to match provided shlibs in virtual packages.
 			for f in ${provides}; do
 				_vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
-				_spkgname="$(grep "^${filename}" $mapshlibs | awk '{print $2}')"
+				_spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
 				_libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
 				if [ -z "${_spkgname}" -o  -z "${_libpkgname}" ]; then
 					continue
diff --git a/common/xbps-src/libexec/build.sh b/common/xbps-src/libexec/build.sh
index 9908b336957..1f751ca13b9 100755
--- a/common/xbps-src/libexec/build.sh
+++ b/common/xbps-src/libexec/build.sh
@@ -43,10 +43,6 @@ if [ "$PKGNAME" != "$XBPS_TARGET_PKG" -o -z "$XBPS_SKIP_DEPS" ]; then
     install_pkg_deps $PKGNAME $XBPS_TARGET_PKG pkg $XBPS_CROSS_BUILD $XBPS_CROSS_PREPARE || exit $?
 fi
 
-if [ -z "$XBPS_CROSS_PREPARE" ]; then
-    install_cross_pkg $XBPS_CROSS_BUILD || exit $?
-fi
-
 # Fetch distfiles after installing required dependencies,
 # because some of them might be required for do_fetch().
 $XBPS_LIBEXECDIR/xbps-src-dofetch.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
diff --git a/common/xbps-src/libexec/xbps-src-doinstall.sh b/common/xbps-src/libexec/xbps-src-doinstall.sh
index b3d5d7276f8..14e117a923b 100755
--- a/common/xbps-src/libexec/xbps-src-doinstall.sh
+++ b/common/xbps-src/libexec/xbps-src-doinstall.sh
@@ -63,7 +63,7 @@ if [ ! -f $XBPS_SUBPKG_INSTALL_DONE ]; then
             run_func pkg_install
         fi
     fi
-    setup_pkg_depends ${pkgname:=$PKGNAME}
+    setup_pkg_depends ${pkgname:=$PKGNAME} || exit 1
     run_pkg_hooks post-install
     touch -f $XBPS_SUBPKG_INSTALL_DONE
 fi
diff --git a/common/xbps-src/libexec/xbps-src-prepkg.sh b/common/xbps-src/libexec/xbps-src-prepkg.sh
index 4be45fd0a14..34f91b3f5f9 100755
--- a/common/xbps-src/libexec/xbps-src-prepkg.sh
+++ b/common/xbps-src/libexec/xbps-src-prepkg.sh
@@ -43,7 +43,7 @@ if [ "$sourcepkg" != "$PKGNAME" ]; then
 fi
 
 source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
-setup_pkg_depends $pkgname
+setup_pkg_depends $pkgname || exit 1
 run_pkg_hooks pre-pkg
 
 touch -f $XBPS_PREPKG_DONE
diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 9bf37cdfc9d..6d9d727e0d3 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,9 +1,9 @@
 # vim: set ts=4 sw=4 et:
 #
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" out="$2" j _rpkgname _depname _pkgname foo _deps
 
-    if [ -n "$pkg" ]; then
+    if [[ $pkg ]]; then
         # subpkg
         if declare -f ${pkg}_package >/dev/null; then
             ${pkg}_package
@@ -13,85 +13,67 @@ setup_pkg_depends() {
     for j in ${depends}; do
         _rpkgname="${j%\?*}"
         _depname="${j#*\?}"
-        _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
-        if [ -z "${_pkgdepname}" ]; then
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
-        fi
-        if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
-        elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
-            _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
-        fi
-        if [ "${_rpkgname}" = "virtual" ]; then
-            if [ -z "${_replacement}" ]; then
-                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
-            fi
-            _pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
+        if [[ ${_rpkgname} == virtual ]]; then
+            _pkgname=$(xbps-uhelper getpkgname $_depname 2>/dev/null)
+            [ -z "$_pkgname" ] && _pkgname="$_depname"
+            if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
+            elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
+                foo=$(egrep "^${_pkgname}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
             fi
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdepname="${_replacement}>=0"
+            if [ -z "$foo" ]; then
+                msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
-            #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
+            _deps+="$foo "
         else
-            if [ -z "${_pkgdepname}" ]; then
-                _pkgdep="${_depname}>=0"
-            else
-                _pkgdep="${_depname}"
+            foo="$($XBPS_UHELPER_CMD getpkgdepname ${_depname} 2>/dev/null)"
+            if [ -z "$foo" ]; then
+                foo="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
+                [ -z "$foo" ] && foo="${_depname}"
             fi
-            run_depends+=" ${_pkgdep}"
+            _deps+="$foo "
         fi
+        run_depends+="${_depname} "
     done
-    for j in ${hostmakedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        host_build_depends+=" ${_depname}-${_depver}"
-    done
-    if [ -n "$XBPS_CHECK_PKGS" ]; then
-        for j in ${checkdepends}; do
-            _depname="${j%\?*}"
-            _depver=$(srcpkg_get_version ${_depname}) || exit $?
-            host_check_depends+=" ${_depname}-${_depver}"
-        done
-    fi
-    for j in ${makedepends}; do
-        _depname="${j%\?*}"
-        _depver=$(srcpkg_get_version ${_depname}) || exit $?
-        build_depends+=" ${_depname}-${_depver}"
-    done
+
+    [[ $out && $_deps ]] && echo "$_deps"
+    return 0
 }
 
-# Install a required package dependency, like:
 #
-#	xbps-install -IAy <pkgname>
+# Install required package dependencies, like:
+#
+#	xbps-install -AIy <pkgs>
+#
+#       -A automatic mode
+#       -I to ignore file conflicts
+#       -y yes
 #
 # Returns 0 if package already installed or installed successfully.
 # Any other error number otherwise.
 #
+# SUCCESS  (0): package installed successfully.
+# ENOENT   (2): package missing in repositories.
+# ENXIO    (6): package depends on invalid dependencies.
+# EAGAIN  (11): package conflicts.
+# EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
+# ENODEV  (19): package depends on missing dependencies.
+# ENOTSUP (95): no repositories registered.
+#
 install_pkg_from_repos() {
-    local pkg="$1" cross="$2" rval= tmplogf=
+    local cross="$1" rval tmplogf cmd
+    shift
+
+    [ $# -eq 0 ] && return 0
 
     mkdir -p $XBPS_STATEDIR
     tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep_${pkg}.log
 
-    if [ -n "$cross" ]; then
-        $XBPS_INSTALL_XCMD -IAy "$pkg" >$tmplogf 2>&1
-    else
-        $XBPS_INSTALL_CMD -IAy "$pkg" >$tmplogf 2>&1
-    fi
+    cmd=$XBPS_INSTALL_CMD
+    [[ $cross ]] && cmd=$XBPS_INSTALL_XCMD
+    $cmd ${XBPS_SKIP_REMOTEREPOS:+-i} -AIy "$@" >$tmplogf 2>&1
     rval=$?
-    # xbps-install can return:
-    #
-    # SUCCESS  (0): package installed successfully.
-    # ENOENT   (2): package missing in repositories.
-    # ENXIO    (6): package depends on invalid dependencies.
-    # EAGAIN  (11): package conflicts.
-    # EEXIST  (17): file conflicts in transaction (XBPS_FLAG_IGNORE_FILE_CONFLICTS unset)
-    # ENODEV  (19): package depends on missing dependencies.
-    # ENOTSUP (95): no repositories registered.
-    #
+
     case "$rval" in
         0) # success, check if there are errors.
            errortmpf=$(mktemp) || exit 1
@@ -111,39 +93,6 @@ install_pkg_from_repos() {
     return $rval
 }
 
-#
-# Returns 0 if pkgpattern in $1 is matched against current installed
-# package, 1 if no match and 2 if not installed.
-#
-check_pkgdep_matched() {
-    local pkg="$1" checkver="$2" cross="$3" uhelper= pkgn= iver=
-
-    [ "$build_style" = "meta" ] && return 2
-    [ -z "$pkg" ] && return 255
-
-    pkgn="$($XBPS_UHELPER_CMD getpkgdepname ${pkg} 2>/dev/null)"
-    if [ -z "$pkgn" ]; then
-        pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg} 2>/dev/null)"
-    fi
-    [ -z "$pkgn" ] && return 255
-
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
-    iver="$($uhelper $checkver $pkgn)"
-    if [ $? -eq 0 -a -n "$iver" ]; then
-        $XBPS_UHELPER_CMD pkgmatch "${pkgn}-${iver}" "${pkg}"
-        [ $? -eq 1 ] && return 0
-    else
-        return 2
-    fi
-
-    return 1
-}
-
 #
 # Returns 0 if pkgpattern in $1 is installed and greater than current
 # installed package, otherwise 1.
@@ -156,12 +105,8 @@ check_installed_pkg() {
     pkgn="$($XBPS_UHELPER_CMD getpkgname ${pkg})"
     [ -z "$pkgn" ] && return 2
 
-    if [ -n "$cross" ]; then
-        uhelper="$XBPS_UHELPER_XCMD"
-    else
-        uhelper="$XBPS_UHELPER_CMD"
-    fi
-
+    uhelper=$XBPS_UHELPER_CMD
+    [[ $cross ]] && uhelper=$XBPS_UHELPER_XCMD
     iver="$($uhelper version $pkgn)"
     if [ $? -eq 0 -a -n "$iver" ]; then
         $XBPS_CMPVER_CMD "${pkgn}-${iver}" "${pkg}"
@@ -171,42 +116,20 @@ check_installed_pkg() {
     return 1
 }
 
-srcpkg_get_version() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
-srcpkg_get_pkgver() {
-    local pkg="$1"
-    # Run this in a sub-shell to avoid polluting our env.
-    (
-    unset XBPS_BINPKG_EXISTS
-    setup_pkg $pkg || exit $?
-    echo "${sourcepkg}-${version}_${revision}"
-    ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
-}
-
 #
-# Installs all dependencies required by a package.
+# Build all dependencies required to build and run.
 #
 install_pkg_deps() {
     local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
-    local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
-    local i j found rundep repo style
+    local _vpkg curpkgdepname
+    local i j found style
 
-    local -a host_binpkg_deps check_binpkg_deps binpkg_deps
-    local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
+    local -a host_binpkg_deps binpkg_deps
+    local -a host_missing_deps missing_deps missing_rdeps
 
     [ -z "$pkgname" ] && return 2
-
-    setup_pkg_depends
-
-    [ -n "$build_style" ] && style=" [$build_style]"
+    [ -z "$XBPS_CHECK_PKGS" ] && unset checkdepends
+    [[ $build_style ]] && style=" [$build_style]"
 
     for s in $build_helper; do
         style+=" [$s]"
@@ -218,197 +141,174 @@ install_pkg_deps() {
         msg_normal "$pkgver: building${style} ...\n"
     fi
 
-    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
-        return 0
-    fi
-
     #
     # Host build dependencies.
     #
-    for i in ${host_build_depends}; do
-        _realpkg=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [host] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [host] ${i}: installed $iver (virtualpkg)."
-                continue
-            else
-                echo "   [host] ${i}: unresolved build dependency!"
-                return 1
+    if [[ ${hostmakedepends} ]]; then
+        # check validity
+        for f in ${hostmakedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: host dependency '$f' does not exist!\n"
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [host] ${i}: found ($repo)"
-                host_binpkg_deps+=("${i}")
+        done
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [host] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [host] ${i}: not found."
-                if [ -z "$cross" ]; then
-                    if [ "${_realpkg}" = "$targetpkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                    elif [ "${_realpkg}" = "$pkg" ]; then
-                        msg_error "${pkg}: [host] build loop detected: $pkg <-> ${_realpkg}\n"
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
                     fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [host] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [host] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [host] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${hostmakedepends})
+    fi
 
     #
     # Host check dependencies.
     #
-    for i in ${host_check_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        check_pkgdep_matched "$i" version
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [check] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_CMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [check] ${i}: installed $iver (virtualpkg)."
-                continue
-            else
-                echo "   [check] ${i}: unresolved check dependency!"
-                return 1
+    if [[ ${checkdepends} ]] && [[ $XBPS_CHECK_PKGS ]]; then
+        # check validity
+        for f in ${checkdepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: check dependency '$f' does not exist!\n"
             fi
-        else
-            repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [check] ${i}: found ($repo)"
-                check_binpkg_deps+=("${i}")
+        done
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [check] ${_vpkg}: found (${_repourl})"
+                host_binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [check] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]!\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [check] build loop detected: $pkg <-> ${_realpkg}\n"
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [check] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [check] ${_vpkg}: not found"
+                    host_missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [check] ${_vpkg}: not found"
+                host_missing_deps+=("$_vpkg")
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+        done < <($XBPS_CHECKVERS_CMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${checkdepends})
+    fi
 
     #
     # Target build dependencies.
     #
-    for i in ${build_depends}; do
-        _realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${_realpkg}" ] && found=1 && break
+    if [[ ${makedepends} ]]; then
+        # check validity
+        for f in ${makedepends}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: target dependency '$f' does not exist!\n"
+            fi
         done
-        [ -n "$found" ] && continue
-        check_pkgdep_matched "${i}" version $cross
-        local rval=$?
-        if [ $rval -eq 0 ]; then
-            echo "   [target] ${i}: installed."
-            continue
-        elif [ $rval -eq 1 ]; then
-            iver=$($XBPS_UHELPER_XCMD version ${_realpkg})
-            if [ $? -eq 0 -a -n "$iver" ]; then
-                echo "   [target] ${i}: installed $iver (virtualpkg)."
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [target] ${_vpkg}: found (${_repourl})"
+                binpkg_deps+=("${_vpkg}")
                 continue
-            else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
             fi
-        else
-            repo=$($XBPS_QUERY_XCMD -R -prepository ${i} 2>/dev/null)
-            if [ -n "${repo}" ]; then
-                echo "   [target] ${i}: found ($repo)"
-                binpkg_deps+=("${i}")
-                continue
-            else
-                echo "   [target] ${i}: not found."
-                if [ "${_realpkg}" = "$targetpkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-                elif [ "${_realpkg}" = "$pkg" ]; then
-                    msg_error "${pkg}: [target] build loop detected: $pkg <-> ${_realpkg}\n"
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [target] ${_vpkg}: not found (subpkg, ignored)"
+                else
+                    echo "   [target] ${_vpkg}: not found"
+                    missing_deps+=("$_vpkg")
                 fi
+            else
+                echo "   [target] ${_vpkg}: not found"
+                missing_deps+=("$_vpkg")
             fi
-        fi
-        missing_deps+=("${i}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm ${makedepends})
+    fi
 
     #
     # Target run time dependencies
     #
-    for i in ${run_depends}; do
-        _realpkg="${i%\?*}"
-        _curpkg="${_realpkg}"
-        _vpkg="${i#*\?}"
-        if [ "${_realpkg}" != "${_vpkg}" ]; then
-            _realpkg="${_vpkg}"
-        else
-            unset _curpkg
-        fi
-        pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
-        if [ -z "$pkgn" ]; then
-            pkgn=$($XBPS_UHELPER_CMD getpkgname "${_realpkg}")
-            if [ -z "$pkgn" ]; then
-                msg_error "$pkgver: invalid runtime dependency: ${_realpkg}\n"
+    if [[ ${depends} ]]; then
+        _deps=$(setup_pkg_depends "" 1) || exit 1
+        for f in ${_deps}; do
+            if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+                msg_error "$pkgver: runtime dependency '$f' does not exist!\n"
             fi
-        fi
-        # Check if dependency is a subpkg, if it is, ignore it.
-        unset found
-        for j in ${subpackages}; do
-            [ "$j" = "${pkgn}" ] && found=1 && break
         done
-        [ -n "$found" ] && continue
-        _props=$($XBPS_QUERY_XCMD -R -ppkgver,repository ${_realpkg} 2>/dev/null)
-        if [ -n "${_props}" ]; then
-            set -- ${_props}
-            $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
-            if [ $? -eq 1 ]; then
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
-                else
-                    echo "   [runtime] ${_realpkg}: found $1 ($2)"
-                fi
-                shift 2
+        while read -r _depname _deprepover _depver _subpkg _repourl; do
+            _vpkg=${_subpkg}-${_depver}
+            # binary package found in a repo
+            if [[ ${_depver} == ${_deprepover} ]]; then
+                echo "   [runtime] ${_vpkg}: found (${_repourl})"
                 continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
+            fi
+            # binary package not found
+            if [[ $_depname != $_subpkg ]]; then
+                # subpkg, check if it's a subpkg of itself
+                found=0
+                for f in ${subpackages}; do
+                    if [[ ${_subpkg} == ${f} ]]; then
+                        found=1
+                        break
+                    fi
+                done
+                if [[ $found -eq 1 ]]; then
+                    echo "   [runtime] ${_vpkg}: not found (subpkg, ignored)"
                 else
-                    echo "   [runtime] ${_realpkg}: not found."
+                    echo "   [runtime] ${_vpkg}: not found"
+                    missing_rdeps+=("$_vpkg")
                 fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
             else
-                echo "   [runtime] ${_realpkg}: not found."
+                echo "   [runtime] ${_vpkg}: not found"
+                missing_rdeps+=("$_vpkg")
             fi
-        fi
-        if [ "${_realpkg}" = "$targetpkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: ${_realpkg} <-> ${targetpkg} [depends on itself]\n"
-        elif [ "${_realpkg}" = "$pkg" ]; then
-            msg_error "${pkg}: [run] build loop detected: $pkg <-> ${_realpkg}\n"
-        fi
-        missing_rdeps+=("${_realpkg}")
-    done
+        done < <($XBPS_CHECKVERS_XCMD ${XBPS_SKIP_REMOTEREPOS:+-i} -D $XBPS_DISTDIR -sm $_deps)
+        unset _deps
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
-           for i in ${check_missing_deps[@]}; do
-                   msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
-           done
            for i in ${missing_rdeps[@]}; do
                    msg_error "dep ${i} not found: -1 passed: instructed not to build\n"
            done
@@ -429,18 +329,6 @@ install_pkg_deps() {
         host_binpkg_deps+=("$i")
     done
 
-    # Missing check dependencies, build from srcpkgs.
-    for i in ${check_missing_deps[@]}; do
-        # packages not found in repos, install from source.
-        (
-        curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
-        setup_pkg $curpkgdepname
-        exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
-            $XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
-        ) || exit $?
-        check_binpkg_deps+=("$i")
-    done
-
     # Missing target dependencies, build from srcpkgs.
     for i in ${missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -471,22 +359,25 @@ install_pkg_deps() {
         ) || exit $?
     done
 
-    if [ "$pkg" != "$targetpkg" ]; then
-        msg_normal "$pkg: building${style} (dependency of $targetpkg) ...\n"
+    if [[ ${host_binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing host dependencies: ${host_binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "" "${host_binpkg_deps[@]}"
     fi
 
-    for i in ${host_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing host dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
-
-    for i in ${check_binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing check dependency '$i' ...\n"
-        install_pkg_from_repos "${i}"
-    done
+    if [[ ${binpkg_deps} ]]; then
+        if [ -z "$XBPS_QUIET" ]; then
+            # normal messages in bold
+            [[ $NOCOLORS ]] || printf "\033[1m"
+            echo "=> $pkgver: installing target dependencies: ${binpkg_deps[@]} ..."
+            [[ $NOCOLORS ]] || printf "\033[m"
+        fi
+        install_pkg_from_repos "$cross" "${binpkg_deps[@]}"
+    fi
 
-    for i in ${binpkg_deps[@]}; do
-        msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
-    done
+    return 0
 }
diff --git a/common/xbps-src/shutils/bulk.sh b/common/xbps-src/shutils/bulk.sh
index 73947965282..ed5c4ce192d 100644
--- a/common/xbps-src/shutils/bulk.sh
+++ b/common/xbps-src/shutils/bulk.sh
@@ -1,83 +1,78 @@
 # vim: set ts=4 sw=4 et:
 
-bulk_getlink() {
-    local p="${1##*/}"
-    local target="$(readlink $XBPS_SRCPKGDIR/$p)"
-
-    if [ $? -eq 0 -a -n "$target" ]; then
-        p=$target
-    fi
-    echo $p
-}
-
 bulk_sortdeps() {
-    local _pkgs _pkg pkgs pkg found f x tmpf
-
-    _pkgs="$@"
-    # Iterate over the list and make sure that only real pkgs are
-    # added to our pkglist.
-    for pkg in ${_pkgs}; do
-        found=0
-        f=$(bulk_getlink $pkg)
-        for x in ${pkgs}; do
-            if [ "$x" = "${f}" ]; then
-                found=1
-                break
-            fi
-        done
-        if [ $found -eq 0 ]; then
-            pkgs+="${f} "
-        fi
-    done
+    local pkgs="$@"
+    local pkg _pkg
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     tmpf=$(mktemp) || exit 1
-    # Now make the real dependency graph of all pkgs to build.
-    # Perform a topological sort of all pkgs but only with build dependencies
-    # that are found in previous step.
+
+    # Perform a topological sort of all *direct* build dependencies.
     for pkg in ${pkgs}; do
-        _pkgs="$(./xbps-src show-build-deps $pkg 2>/dev/null)"
-        found=0
-        for x in ${_pkgs}; do
-            _pkg=$(bulk_getlink $x)
-            for f in ${pkgs}; do
-                if [ "${f}" != "${_pkg}" ]; then
-                    continue
-                fi
-                found=1
-                echo "${pkg} ${f}" >> $tmpf
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            for _pkg in $(./xbps-src show-build-deps $pkg 2>/dev/null); do
+                echo "$pkg $_pkg" >> $tmpf
             done
-        done
-        [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
+            echo "$pkg $pkg" >> $tmpf
+        ) &
     done
+    wait
     tsort $tmpf|tac
     rm -f $tmpf
 }
 
 bulk_build() {
+    local sys="$1"
+    local NPROCS=$(($(nproc)*2))
+    local NRUNNING=0
 
     if [ "$XBPS_CROSS_BUILD" ]; then
         source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
         export XBPS_ARCH=${XBPS_TARGET_MACHINE}
     fi
     if ! command -v xbps-checkvers &>/dev/null; then
-        msg_error "xbps-src: cannot find xbps-checkvers(8) command!\n"
+        msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
     fi
 
-    bulk_sortdeps "$(xbps-checkvers ${1} --distdir=$XBPS_DISTDIR | awk '{print $2}')"
+    # Compare installed pkg versions vs srcpkgs
+    if [[ $sys ]]; then
+        xbps-checkvers -f '%n' -I -D $XBPS_DISTDIR
+        return $?
+    fi
+    # compare repo pkg versions vs srcpkgs
+    for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
+        if [ $NRUNNING -eq $NPROCS ]; then
+            NRUNNING=0
+            wait
+        fi
+        NRUNNING=$((NRUNNING+1))
+        (
+            setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
+            if show_avail &>/dev/null; then
+                echo "$f"
+            fi
+        ) &
+    done
+    wait
+    return $?
 }
 
 bulk_update() {
     local args="$1" pkgs f rval
 
     pkgs="$(bulk_build ${args})"
-    if [ -z "$pkgs" ]; then
-        return 0
-    fi
+    [[ -z $pkgs ]] && return 0
+
     msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
     for f in ${pkgs}; do
-        echo "   $f"
+        echo " $f"
     done
-    echo
     for f in ${pkgs}; do
         XBPS_TARGET_PKG=$f
         read_pkg
diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index dec8fa36117..49fa05f79b5 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -169,7 +169,7 @@ chroot_handler() {
     [ -z "$action" -a -z "$pkg" ] && return 1
 
     case "$action" in
-        fetch|extract|patch|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
+        fetch|extract|patch|configure|build|check|install|pkg|bootstrap-update|chroot)
             chroot_prepare || return $?
             chroot_init || return $?
             chroot_sync_repos || return $?
@@ -181,30 +181,13 @@ chroot_handler() {
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" /bin/xbps-shell
         rv=$?
     else
-        [ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
-        [ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
-        [ -n "$NOCOLORS" ] && arg="$arg -L"
-        [ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
-        [ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
-        [ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
-        [ -n "$XBPS_CHECK_PKGS" ] && arg="$arg -Q"
-        [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ] && arg="$arg -1"
-        [ -n "$XBPS_QUIET" ] && arg="$arg -q"
-        [ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
-        [ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
-        [ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
-        [ -n "$XBPS_PKG_OPTIONS" ] && arg="$arg -o $XBPS_PKG_OPTIONS"
-        [ -n "$XBPS_TEMP_MASTERDIR" ] && arg="$arg -t -C"
-        [ -n "$XBPS_BINPKG_EXISTS" ] && arg="$arg -E"
-
-        action="$arg $action"
         env -i -- PATH="/usr/bin:$PATH" SHELL=/bin/sh \
             HOME=/tmp IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 \
             SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
             XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \
             $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \
             $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \
-            /void-packages/xbps-src $action $pkg
+            /void-packages/xbps-src $XBPS_OPTIONS $action $pkg
         rv=$?
     fi
 
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 5567619f8f3..b8d601d3fb2 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -294,7 +294,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_REMOVE_CMD -r $XBPS_CROSS_BASE"
         XBPS_RINDEX_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE $XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-uhelper -r $XBPS_CROSS_BASE"
-
+        XBPS_CHECKVERS_XCMD="env XBPS_TARGET_ARCH=$XBPS_TARGET_MACHINE xbps-checkvers -r $XBPS_CROSS_BASE --repository=$XBPS_REPOSITORY"
     else
         export XBPS_TARGET_MACHINE=${XBPS_ARCH:-$XBPS_MACHINE}
         unset XBPS_CROSS_BASE XBPS_CROSS_LDFLAGS XBPS_CROSS_FFLAGS
@@ -307,7 +307,7 @@ setup_pkg() {
         XBPS_REMOVE_XCMD="$XBPS_REMOVE_CMD"
         XBPS_RINDEX_XCMD="$XBPS_RINDEX_CMD"
         XBPS_UHELPER_XCMD="$XBPS_UHELPER_CMD"
-
+        XBPS_CHECKVERS_XCMD="$XBPS_CHECKVERS_CMD"
     fi
 
     export XBPS_INSTALL_XCMD XBPS_QUERY_XCMD XBPS_RECONFIGURE_XCMD \
@@ -402,7 +402,7 @@ setup_pkg() {
         arch="$XBPS_TARGET_MACHINE"
     fi
     if [ -n "$XBPS_BINPKG_EXISTS" ]; then
-        if [ "$($XBPS_QUERY_XCMD -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
+        if [ "$($XBPS_QUERY_XCMD -i -R -ppkgver $pkgver 2>/dev/null)" = "$pkgver" ]; then
             exit_and_cleanup
         fi
     fi
@@ -556,17 +556,17 @@ setup_pkg() {
         wrksrc="$XBPS_BUILDDIR/$wrksrc"
     fi
 
-    if [ "$cross" -a "$nocross" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ "$cross" -a "$nocross" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be cross compiled, exiting...\n"
         msg_red "$pkgver: $nocross\n"
         exit 2
-    elif [ "$broken" -a "z$show_problems" != "zignore-problems" ]; then
+    elif [ "$broken" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: cannot be built, it's currently broken; see the build log:\n"
         msg_red "$pkgver: $broken\n"
         exit 2
     fi
 
-    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "z$show_problems" != "zignore-problems" ]; then
+    if [ -n "$restricted" -a -z "$XBPS_ALLOW_RESTRICTED" -a "$show_problems" != "ignore-problems" ]; then
         msg_red "$pkgver: does not allow redistribution of sources/binaries (restricted license).\n"
         msg_red "If you really need this software, run 'echo XBPS_ALLOW_RESTRICTED=yes >> etc/conf'\n"
         exit 2
@@ -575,9 +575,7 @@ setup_pkg() {
     export XBPS_STATEDIR="${XBPS_BUILDDIR}/.xbps-${sourcepkg}"
     export XBPS_WRAPPERDIR="${XBPS_STATEDIR}/wrappers"
 
-    if [ -n "$bootstrap" -a -z "$CHROOT_READY" -o -n "$IN_CHROOT" ]; then
-        mkdir -p $XBPS_WRAPPERDIR
-    fi
+    mkdir -p $XBPS_STATEDIR $XBPS_WRAPPERDIR
 
     source_file $XBPS_COMMONDIR/environment/build-style/${build_style}.sh
 
diff --git a/common/xbps-src/shutils/cross.sh b/common/xbps-src/shutils/cross.sh
index 12c9efa9b49..e72100986dd 100644
--- a/common/xbps-src/shutils/cross.sh
+++ b/common/xbps-src/shutils/cross.sh
@@ -24,11 +24,12 @@ remove_pkg_cross_deps() {
 
 prepare_cross_sysroot() {
     local cross="$1"
+    local statefile="$XBPS_MASTERDIR/.xbps-${cross}-done"
 
-    [ -z "$cross" -o "$cross" = "" ] && return 0
+    [ -z "$cross" -o "$cross" = "" -o -f $statefile ] && return 0
 
     # Check for cross-vpkg-dummy available for the target arch, otherwise build it.
-    pkg_available 'cross-vpkg-dummy>=0.30_1' $cross
+    pkg_available 'cross-vpkg-dummy>=0.31_1' $cross
     if [ $? -eq 0 ]; then
         $XBPS_LIBEXECDIR/build.sh cross-vpkg-dummy cross-vpkg-dummy pkg $cross init || return $?
     fi
@@ -40,7 +41,7 @@ prepare_cross_sysroot() {
     errlog=$(mktemp) || exit 1
     $XBPS_INSTALL_XCMD -Syfd cross-vpkg-dummy &>$errlog
     rval=$?
-    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+    if [ $rval -ne 0 ]; then
         msg_red "failed to install cross-vpkg-dummy (error $rval)\n"
         cat $errlog
         rm -f $errlog
@@ -48,11 +49,15 @@ prepare_cross_sysroot() {
     fi
     rm -f $errlog
     # Create top level symlinks in sysroot.
-    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-directories base-files &>/dev/null
+    XBPS_ARCH=$XBPS_TARGET_MACHINE xbps-reconfigure -r $XBPS_CROSS_BASE -f base-files &>/dev/null
     # Create a sysroot/include and sysroot/lib symlink just in case.
     ln -s usr/include ${XBPS_CROSS_BASE}/include
     ln -s usr/lib ${XBPS_CROSS_BASE}/lib
 
+    install_cross_pkg $cross || return 1
+
+    touch -f $statefile
+
     return 0
 }
 
diff --git a/common/xbps-src/shutils/pkgtarget.sh b/common/xbps-src/shutils/pkgtarget.sh
index a7be624173e..7d3ed1c78f4 100644
--- a/common/xbps-src/shutils/pkgtarget.sh
+++ b/common/xbps-src/shutils/pkgtarget.sh
@@ -54,6 +54,10 @@ remove_pkg_autodeps() {
     $XBPS_RECONFIGURE_CMD -a >> $tmplogf 2>&1
     echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
     rval=$?
+    if [ $rval -eq 0 ]; then
+        echo yes | $XBPS_REMOVE_CMD -Ryod >> $tmplogf 2>&1
+        rval=$?
+    fi
 
     if [ $rval -ne 0 ]; then
         msg_red "${pkgver:-xbps-src}: failed to remove autodeps: (returned $rval)\n"
diff --git a/common/xbps-src/shutils/show.sh b/common/xbps-src/shutils/show.sh
index e2fc956514e..d0c260ed0ae 100644
--- a/common/xbps-src/shutils/show.sh
+++ b/common/xbps-src/shutils/show.sh
@@ -61,44 +61,25 @@ show_avail() {
 }
 
 show_pkg_build_depends() {
-    local f x _pkgname _srcpkg _dep found result
+    local f x _pkgname _srcpkg found result
     local _deps="$1"
 
     result=$(mktemp) || exit 1
 
     # build time deps
     for f in ${_deps}; do
-        # ignore virtual deps
-        local _rpkg="${f%\?*}"
-        local _vpkg="${f#*\?}"
-
-        # ignore virtual dependencies
-        if [ "${_rpkg}" != "${_vpkg}" ]; then
-            f="${_vpkg}"
+        if [ ! -f $XBPS_SRCPKGDIR/$f/template ]; then
+            msg_error "$pkgver: dependency '$f' does not exist!\n"
         fi
+        # ignore virtual dependencies
+        [[ ${f%\?*} != ${f#*\?} ]] && f=${f#*\?}
         unset found
         # check for subpkgs
         for x in ${subpackages}; do
-            _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-            if [ -z "${_pkgname}" ]; then
-                _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-            fi
-            if [ "${_pkgname}" = "$x" ]; then
-                found=1
-                break
-            fi
+            [[ $f == $x ]] && found=1 && break
         done
-        if [ -n "$found" ]; then
-            continue
-        fi
-        _pkgname="$($XBPS_UHELPER_CMD getpkgdepname $f 2>/dev/null)"
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$($XBPS_UHELPER_CMD getpkgname $f 2>/dev/null)"
-        fi
-        if [ -z "${_pkgname}" ]; then
-            _pkgname="$f"
-        fi
-        _pkgname=${_pkgname/-32bit}
+        [[ $found ]] && continue
+        _pkgname=${f/-32bit}
         _srcpkg=$(readlink -f ${XBPS_SRCPKGDIR}/${_pkgname})
         _srcpkg=${_srcpkg##*/}
         echo "${_srcpkg}" >> $result
@@ -108,18 +89,15 @@ show_pkg_build_depends() {
 }
 
 show_pkg_build_deps() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends} ${build_depends} ${run_depends}"
+    show_pkg_build_depends "${hostmakedepends} ${makedepends} $(setup_pkg_depends '' 1)"
 }
 
 show_pkg_hostmakedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${host_build_depends}"
+    show_pkg_build_depends "${hostmakedepends}"
 }
 
 show_pkg_makedepends() {
-    setup_pkg_depends
-    show_pkg_build_depends "${build_depends}"
+    show_pkg_build_depends "${makedepends}"
 }
 
 show_pkg_build_options() {
diff --git a/xbps-src b/xbps-src
index 23d6164b18a..c7c41f47193 100755
--- a/xbps-src
+++ b/xbps-src
@@ -1,8 +1,6 @@
 #!/bin/bash
 # vim: set ts=4 sw=4 et:
 
-readonly PROGNAME="${0##*/}"
-
 print_cross_targets() {
     local f
     for f in common/cross-profiles/*.sh; do
@@ -210,7 +208,7 @@ _EOF
 check_reqhost_utils() {
     local broken
 
-    [ -n "$IN_CHROOT" ] && return 0
+    [ "$IN_CHROOT" ] && return 0
 
     for f in ${REQHOST_UTILS}; do
         if ! command -v ${f} &>/dev/null; then
@@ -218,7 +216,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
+    [ "$broken" ] && exit 1
     [ -z "$1" ] && return 0
 
     for f in ${REQHOST_UTILS_BOOTSTRAP}; do
@@ -227,24 +225,7 @@ check_reqhost_utils() {
             broken=1
         fi
     done
-    [ -n "$broken" ] && exit 1
-}
-
-check_config_vars() {
-    if [ -s "$XBPS_CONFIG_FILE" ]; then
-        . $XBPS_CONFIG_FILE &>/dev/null
-    fi
-    if [ -z "$XBPS_MASTERDIR" ]; then
-        export XBPS_MASTERDIR="${XBPS_DISTDIR}/masterdir"
-    fi
-    if [ -z "$XBPS_HOSTDIR" ]; then
-        export XBPS_HOSTDIR="${XBPS_DISTDIR}/hostdir"
-        [ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
-    fi
-    if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
-        echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
-        exit 1
-    fi
+    [ "$broken" ] && exit 1
 }
 
 check_build_requirements() {
@@ -264,20 +245,42 @@ check_build_requirements() {
     fi
 }
 
+chroot_check() {
+    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
+        export CHROOT_READY=1
+    fi
+}
+
+check_native_arch() {
+    if [ "$CHROOT_READY" ]; then
+        if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
+            export XBPS_ARCH=$(<$XBPS_MASTERDIR/.xbps_chroot_init)
+        else
+            export XBPS_ARCH=$(xbps-uhelper arch)
+        fi
+    else
+        LDD=$(ldd --version 2>&1|head -1)
+        if [[ $LDD == *musl* ]]; then
+            export XBPS_ARCH=${XBPS_MACHINE%-musl}-musl
+        else
+            # XBPS_ARCH == $(uname -m)
+            export XBPS_ARCH=$(uname -m)
+        fi
+    fi
+}
+
 install_bbootstrap() {
-    [ -n "$CHROOT_READY" ] && return
+    [ "$CHROOT_READY" ] && return
     if [ "$1" = "bootstrap" ]; then
         unset XBPS_TARGET_PKG XBPS_INSTALL_ARGS
     else
         XBPS_TARGET_PKG="$1"
     fi
-    if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
-        unset XBPS_INSTALL_ARGS
-    fi
+    [ "$XBPS_SKIP_REMOTEREPOS" ] && unset XBPS_INSTALL_ARGS
     # binary bootstrap
     msg_normal "Installing bootstrap from binary package repositories...\n"
     # XBPS_TARGET_PKG == arch
-    if [ -n "$XBPS_TARGET_PKG" ]; then
+    if [ "$XBPS_TARGET_PKG" ]; then
         _bootstrap_arch="env XBPS_TARGET_ARCH=$XBPS_TARGET_PKG"
         if [ "${XBPS_TARGET_PKG}" != "${XBPS_TARGET_PKG#*-}" ]; then
             _subarch="-${XBPS_TARGET_PKG#*-}"
@@ -308,17 +311,15 @@ reconfigure_bootstrap_pkgs() {
     # Reconfigure ca-certificates.
     msg_normal "Reconfiguring bootstrap packages...\n"
     for f in ${pkgs}; do
-        if xbps-query $f &>/dev/null; then
-            xbps-reconfigure -f $f
+        if xbps-query -r $XBPS_MASTERDIR $f &>/dev/null; then
+            xbps-reconfigure -r $XBPS_MASTERDIR -f $f
         fi
     done
     touch -f $statefile
 }
 
 bootstrap_update() {
-    if [ -z "$CHROOT_READY" ]; then
-        return
-    fi
+    [ -z "$CHROOT_READY" ] && return
     remove_pkg_autodeps
     msg_normal "xbps-src: cleaning up masterdir...\n"
     rm -rf $XBPS_MASTERDIR/builddir $XBPS_MASTERDIR/destdir
@@ -347,7 +348,7 @@ masterdir_zap() {
 
 exit_func() {
     wait
-    if [ -n "$sourcepkg" ]; then
+    if [ "$sourcepkg" ]; then
         remove_pkg $XBPS_CROSS_BUILD
     fi
     if [ -z "$IN_CHROOT" ]; then
@@ -390,14 +391,17 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.55"
-readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
-readonly XBPS_SRC_VERSION="113"
-export XBPS_MACHINE=$(xbps-uhelper arch)
-
 #
 # main()
 #
+readonly PROGNAME="${0##*/}"
+readonly XBPS_VERSION_REQ="0.55"
+XBPS_VERSION=$(xbps-uhelper -V)
+XBPS_VERSION=${XBPS_VERSION%%API*}
+XBPS_VERSION=${XBPS_VERSION##*:}
+readonly XBPS_SRC_VERSION="113"
+export XBPS_MACHINE=$(xbps-uhelper -C /dev/null arch)
+
 XBPS_OPTIONS=
 XBPS_OPTSTRING="1a:CEfgGhH:iIj:Lm:No:qQr:tV"
 
@@ -407,26 +411,26 @@ eval set -- $(getopt "$XBPS_OPTSTRING" "$@");
 while getopts "$XBPS_OPTSTRING" opt; do
     case $opt in
         1) export XBPS_BUILD_ONLY_ONE_PKG=yes; XBPS_OPTIONS+=" -1";;
-        a) readonly XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
-        C) readonly XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
+        a) export XBPS_CROSS_BUILD="$OPTARG"; XBPS_OPTIONS+=" -a $OPTARG";;
+        C) export XBPS_KEEP_ALL=1; XBPS_OPTIONS+=" -C";;
         E) export XBPS_BINPKG_EXISTS=1; XBPS_OPTIONS+=" -E";;
-        f) readonly XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
-        G) readonly XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
-        g) readonly XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
-        H) readonly XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
+        f) export XBPS_BUILD_FORCEMODE=1; XBPS_OPTIONS+=" -f";;
+        G) export XBPS_USE_GIT_REVS=1; XBPS_OPTIONS+=" -G";;
+        g) export XBPS_DEBUG_PKGS=1; XBPS_OPTIONS+=" -g";;
+        H) export XBPS_HOSTDIR="$(readlink -f $OPTARG 2>/dev/null)"; XBPS_OPTIONS+=" -H $XBPS_HOSTDIR";;
         h) usage && exit 0;;
         i) export XBPS_INFORMATIVE_RUN=1; XBPS_OPTIONS+=" -i";;
-        I) readonly XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
+        I) export XBPS_SKIP_DEPS=1; XBPS_OPTIONS+=" -I";;
         j) export XBPS_MAKEJOBS="$OPTARG"; XBPS_OPTIONS+=" -j $OPTARG";;
         L) export NOCOLORS=1; XBPS_OPTIONS+=" -L";;
-        m) readonly XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
-        N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
-        o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
+        m) export XBPS_MASTERDIR=$(readlink -f $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
+        N) export XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
+        o) export XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
         q) export XBPS_QUIET=1; XBPS_OPTIONS+=" -q";;
         Q) export XBPS_CHECK_PKGS=1; XBPS_OPTIONS+=" -Q";;
-        r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
+        r) export XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
         t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
-        V) echo $XBPS_SRC_VERSION && exit 0;;
+        V) echo "xbps-src-$XBPS_SRC_VERSION $(xbps-uhelper -V)" && exit 0;;
         --) shift; break;;
     esac
 done
@@ -437,10 +441,11 @@ shift $(($OPTIND - 1))
 # Check if stdout is a tty; if false disable colors.
 test -t 1 || export NOCOLORS=1
 # http://no-color.org
-if [ -n "${NO_COLOR+x}" ]; then
+if [ "${NO_COLOR+x}" ]; then
     export NOCOLORS=1
 fi
 
+# sane umask
 umask 022
 
 #
@@ -456,22 +461,13 @@ readonly REQHOST_UTILS="xbps-install xbps-query xbps-rindex xbps-uhelper \
 
 check_reqhost_utils
 
-# Try using chroot-git then git from the host system
-if command -v chroot-git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v chroot-git)
-elif command -v git &>/dev/null; then
-	XBPS_GIT_CMD=$(command -v git)
-else
-    echo "neither chroot-git or git are available in your system!"
-    exit 1
-fi
-
-readonly XBPS_GIT_CMD
-
-if [ -n "$IN_CHROOT" ]; then
+#
+# Set XBPS_CONFIG_FILE, XBPS_DISTDIR, XBPS_MASTERDIR
+# and XBPS_HOSTDIR.
+#
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_CONFIG_FILE=/etc/xbps/xbps-src.conf
     readonly XBPS_DISTDIR=/void-packages
-    # needed before call to check_config_vars
     readonly XBPS_MASTERDIR=/
     readonly XBPS_HOSTDIR=/host
 else
@@ -491,18 +487,37 @@ else
     elif [ -s $HOME/.xbps-src.conf ]; then
         # ... fallback to ~/.xbps-src.conf otherwise.
         readonly XBPS_CONFIG_FILE=$HOME/.xbps-src.conf
-        . $XBPS_CONFIG_FILE
     fi
 fi
+# Read settings from config file
+[ -s "$XBPS_CONFIG_FILE" ] && . $XBPS_CONFIG_FILE &>/dev/null
 
-#
-# Check configuration vars before anyting else, and set defaults vars.
-#
-check_config_vars
+# if XBPS_MASTERDIR unset, defaults to $XBPS_DISTDIR/masterdir.
+: ${XBPS_MASTERDIR:=$XBPS_DISTDIR/masterdir}
+[ ! -d $XBPS_MASTERDIR ] &&  mkdir -p $XBPS_MASTERDIR
 
-for f in $XBPS_DISTDIR/common/xbps-src/shutils/*.sh; do
-    [ -r $f ] && . $f
-done
+# if XBPS_HOSTDIR unset, defaults to $XBPS_DISTDIR/hostdir.
+: ${XBPS_HOSTDIR:=$XBPS_DISTDIR/hostdir}
+[ ! -d $XBPS_HOSTDIR ] && mkdir -p $XBPS_HOSTDIR
+
+if [ -d "$XBPS_MASTERDIR" -a ! -w "$XBPS_MASTERDIR" ]; then
+    echo "ERROR: can't write to masterdir $XBPS_MASTERDIR."
+    exit 1
+elif [ -d "$XBPS_HOSTDIR" -a ! -w "$XBPS_HOSTDIR" ]; then
+    echo "ERROR: can't write to hostdir: $XBPS_HOSTDIR."
+    exit 1
+fi
+
+# Try using chroot-git then git from the host system
+if command -v chroot-git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v chroot-git)
+elif command -v git &>/dev/null; then
+    XBPS_GIT_CMD=$(command -v git)
+else
+    echo "neither chroot-git or git are available in your system!"
+    exit 1
+fi
+readonly XBPS_GIT_CMD
 
 if [ -n "$XBPS_HOSTDIR" ]; then
     export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs
@@ -516,80 +531,62 @@ fi
 if [ -z "$XBPS_ALT_REPOSITORY" ]; then
     pushd "$PWD" &>/dev/null
     cd $XBPS_DISTDIR
-    if [ -n "$IN_CHROOT" ]; then
-        _gitbranch="$(chroot-git symbolic-ref --short HEAD 2>/dev/null)"
-    else
-        _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
-    fi
-    if [ -n "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
+    _gitbranch="$($XBPS_GIT_CMD symbolic-ref --short HEAD 2>/dev/null)"
+    if [ "${_gitbranch}" -a "${_gitbranch}" != "master" ]; then
         export XBPS_ALT_REPOSITORY="${_gitbranch}"
         export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${_gitbranch}"
-        if [ -z "$IN_CHROOT" ]; then
-            msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-        fi
      fi
      popd &>/dev/null
 else
     export XBPS_REPOSITORY="${XBPS_REPOSITORY}/${XBPS_ALT_REPOSITORY}"
-    if [ -z "$IN_CHROOT" ]; then
-        msg_normal "Using \`$XBPS_REPOSITORY\' as local repository.\n"
-    fi
 fi
 
-if [ -n "$IN_CHROOT" ]; then
+readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
+readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
+readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
+readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
+readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
+readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
+readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
+
+if [ "$IN_CHROOT" ]; then
     readonly XBPS_UHELPER_CMD="xbps-uhelper"
-    readonly XBPS_INSTALL_CMD="xbps-install"
-    readonly XBPS_QUERY_CMD="xbps-query"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install --repository=$XBPS_REPOSITORY"
+    readonly XBPS_QUERY_CMD="xbps-query --repository=$XBPS_REPOSITORY"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure"
     readonly XBPS_REMOVE_CMD="xbps-remove"
-    readonly XBPS_SRCPKGDIR=/void-packages/srcpkgs
-    readonly XBPS_COMMONDIR=/void-packages/common
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=/destdir
     readonly XBPS_BUILDDIR=/builddir
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 else
     readonly XBPS_UHELPER_CMD="xbps-uhelper -r $XBPS_MASTERDIR"
-    readonly XBPS_INSTALL_CMD="xbps-install -C /dev/null -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_QUERY_CMD="xbps-query -C /dev/null -c $XBPS_HOSTDIR/repocache -i --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
-    readonly XBPS_RINDEX_CMD="xbps-rindex"
+    readonly XBPS_INSTALL_CMD="xbps-install -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
+    readonly XBPS_QUERY_CMD="xbps-query -c $XBPS_HOSTDIR/repocache --repository=$XBPS_REPOSITORY -r $XBPS_MASTERDIR"
     readonly XBPS_RECONFIGURE_CMD="xbps-reconfigure -r $XBPS_MASTERDIR"
     readonly XBPS_REMOVE_CMD="xbps-remove -r $XBPS_MASTERDIR"
-    readonly XBPS_SRCPKGDIR=$XBPS_DISTDIR/srcpkgs
-    readonly XBPS_COMMONDIR=$XBPS_DISTDIR/common
-    readonly XBPS_SHUTILSDIR=$XBPS_COMMONDIR/xbps-src/shutils
+    readonly XBPS_CHECKVERS_CMD="xbps-checkvers --repository=$XBPS_REPOSITORY"
     readonly XBPS_DESTDIR=$XBPS_MASTERDIR/destdir
     readonly XBPS_BUILDDIR=$XBPS_MASTERDIR/builddir
-    readonly XBPS_TRIGGERSDIR=$XBPS_SRCPKGDIR/xbps-triggers/files
-    readonly XBPS_CROSSPFDIR=$XBPS_COMMONDIR/cross-profiles
-    readonly XBPS_BUILDSTYLEDIR=$XBPS_COMMONDIR/build-style
-    readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
-    readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
+readonly XBPS_RINDEX_CMD="xbps-rindex"
 readonly XBPS_FETCH_CMD="xbps-fetch"
 readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"
-if [ -n "$2" ]; then
+if [ "$2" ]; then
     XBPS_TARGET_PKG="${2##*/}"
 fi
 
-chroot_check() {
-    if [ -f $XBPS_MASTERDIR/.xbps_chroot_init -o "$XBPS_CHROOT_CMD" = "ethereal" ]; then
-        export CHROOT_READY=1
-    fi
-}
-
+# Check for CHROOT_READY and set up XBPS_ARCH environment var for xbps.
 chroot_check
+check_native_arch
 
+# Reconfigure pkgs for 32bit on x86_64 and reexec itself.
+# XXX: how about 32bit userland on 64bit CPUs? (ppc, arm, etc).
 if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
-    export XBPS_ARCH=${XBPS_ARCH:-$(cat $XBPS_MASTERDIR/.xbps_chroot_init)}
+    export XBPS_ARCH=${XBPS_ARCH:-$(<$XBPS_MASTERDIR/.xbps_chroot_init)}
     if [[ $XBPS_MACHINE == x86_64* ]] && [[ $XBPS_ARCH == i686* ]]; then
         # reconfigure pkgs via linux32
         linux32 xbps-reconfigure -r ${XBPS_MASTERDIR} -a &>/dev/null
@@ -598,20 +595,21 @@ if [ -z "$XBPS_REINIT" -a -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
         exec linux32 $0 ${XBPS_OPTIONS} $@
     fi
 fi
-if [ -n "$XBPS_ARCH" ]; then
+if [ "$XBPS_ARCH" ]; then
     export XBPS_MACHINE=$XBPS_ARCH
 fi
+# At this point if XBPS_TARGET_MACHINE isn't defined we assume
+# it's a native build.
 if [ -z "$XBPS_TARGET_MACHINE" ]; then
-    export XBPS_TARGET_MACHINE=${XBPS_ARCH:=$XBPS_MACHINE}
+        export XBPS_TARGET_MACHINE=$XBPS_MACHINE
 fi
 
-
 export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
-    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR XBPS_REPO_DELTAS \
+    XBPS_SRCPKGDIR XBPS_COMMONDIR XBPS_BUILDDIR \
     XBPS_REPOSITORY XBPS_ALT_REPOSITORY XBPS_SRCDISTDIR XBPS_DIGEST_CMD \
     XBPS_UHELPER_CMD XBPS_INSTALL_CMD XBPS_QUERY_CMD XBPS_BUILD_ONLY_ONE_PKG \
-    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD \
-    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER XBPS_BUILDSTYLEDIR \
+    XBPS_RINDEX_CMD XBPS_RECONFIGURE_CMD XBPS_REMOVE_CMD XBPS_CHECKVERS_CMD \
+    XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_BUILDSTYLEDIR \
     XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_FFLAGS XBPS_LDFLAGS \
     XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
     XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
@@ -629,7 +627,7 @@ for i in REPOSITORY DESTDIR BUILDDIR SRCDISTDIR; do
     unset val
 done
 
-# A temporary masterdir requires xbps-uchroot(8) and -O to use overlayfs
+# A temporary masterdir requires xbps-uchroot(1) and -O to use overlayfs
 # on tmpfs (available with xbps-0.45).
 if [ -z "$IN_CHROOT" -a -n "$XBPS_TEMP_MASTERDIR" ]; then
     export XBPS_CHROOT_CMD="uchroot"
@@ -640,31 +638,35 @@ fi
 #
 if [ -z "$IN_CHROOT" ]; then
     # In non chroot case always prefer host tools.
-    MYPATH="$XBPS_MASTERDIR/usr/bin:$XBPS_MASTERDIR/usr/sbin"
-    export PATH="$PATH:$MYPATH"
-else
-    MYPATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
-    export PATH="$MYPATH"
-    if [ -n "$XBPS_CCACHE" ]; then
-        CCACHEPATH="/usr/lib/ccache/bin"
-        export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
-        # Avoid not using cached files just due to compiler mtime
-        # changes when e.g. bootstrapping
-        export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
-        export PATH="$CCACHEPATH:$PATH"
-        mkdir -p $CCACHE_DIR
-    fi
-    if [ -n "$XBPS_DISTCC" ]; then
-        if [ -n "$XBPS_CCACHE" ]; then
-            export CCACHE_PREFIX="/usr/bin/distcc"
-        else
-            DISTCCPATH="/usr/lib/distcc/bin"
-            export PATH="$DISTCCPATH:$PATH"
-        fi
-        export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
-        export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
-        mkdir -p $DISTCC_DIR
+    export PATH="$PATH:$XBPS_MASTERDIR/usr/bin"
+fi
+
+#
+# Set up ccache
+#
+if [ "$XBPS_CCACHE" ]; then
+    export CCACHEPATH="/usr/lib/ccache/bin"
+    export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
+    # Avoid not using cached files just due to compiler mtime
+    # changes when e.g. bootstrapping
+    export CCACHE_COMPILERCHECK=content CCACHE_COMPRESS=1
+    export PATH="$CCACHEPATH:$PATH"
+    mkdir -p $CCACHE_DIR
+fi
+
+#
+# Set up distcc
+#
+if [ "$XBPS_DISTCC" ]; then
+    if [ "$XBPS_CCACHE" ]; then
+        export CCACHE_PREFIX="/usr/bin/distcc"
+    else
+        DISTCCPATH="/usr/lib/distcc/bin"
+        export PATH="$DISTCCPATH:$PATH"
     fi
+    export DISTCC_DIR="$XBPS_HOSTDIR/distcc-${XBPS_CROSS_BUILD:-${XBPS_MACHINE}}"
+    export DISTCC_HOSTS="$XBPS_DISTCC_HOSTS"
+    mkdir -p $DISTCC_DIR
 fi
 
 check_build_requirements
@@ -675,6 +677,12 @@ if [ -z "$IN_CHROOT" ]; then
         setup_distfiles_mirror
     fi
 fi
+#
+# Read funcs from helpers
+#
+for f in ${XBPS_SHUTILSDIR}/*.sh; do
+    [ -r "$f" ] && . $f
+done
 
 reconfigure_bootstrap_pkgs
 
@@ -689,18 +697,24 @@ case "$XBPS_TARGET" in
         # bootstrap from sources
         # check for required host utils
         check_reqhost_utils bootstrap
-        [ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
-            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
+        [[ $XBPS_MACHINE =~ musl ]] && subarch="-musl"
+        [ ! -d $XBPS_SRCPKGDIR/base-chroot${subarch} ] && \
+            msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot${subarch} directory!\n"
         bootstrap_vpkg=${XBPS_MASTERDIR}/etc/xbps.d/bootstrap-vpkgs.conf
         mkdir -p ${XBPS_MASTERDIR}/etc/xbps.d
         if [ ! -s ${bootstrap_vpkg} ]; then
             # Fool xbps to resolve dependencies.
-            echo 'virtualpkg=libgcc-4.4.0_1:base-files' >> ${bootstrap_vpkg}
-            echo 'virtualpkg=libstdc++-4.4.0_1:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libgcc:base-files' >> ${bootstrap_vpkg}
+            echo 'virtualpkg=libstdc++:base-files' >> ${bootstrap_vpkg}
         fi
-        $XBPS_LIBEXECDIR/build.sh base-chroot base-chroot $XBPS_TARGET || exit 1
+        (
+            export XBPS_ARCH=$XBPS_MACHINE
+            export XBPS_SKIP_REMOTEREPOS=1
+            $XBPS_LIBEXECDIR/build.sh \
+                base-chroot${subarch} base-chroot${subarch} $XBPS_TARGET || exit 1
+        ) || exit 1
         [ -d $XBPS_MASTERDIR ] && rm -rf $XBPS_MASTERDIR
-        install_bbootstrap bootstrap
+        install_bbootstrap ${XBPS_TARGET_PKG:=$XBPS_MACHINE}
         ;;
     bootstrap-update)
         if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
@@ -780,7 +794,7 @@ case "$XBPS_TARGET" in
         show_pkg
         ;;
     show-avail)
-        read_pkg
+        read_pkg &>/dev/null
         show_avail
         ;;
     show-files)
@@ -857,7 +871,7 @@ case "$XBPS_TARGET" in
         bulk_build
         ;;
     show-sys-updates)
-        bulk_build -i
+        bulk_build -I
         ;;
     sort-dependencies)
         bulk_sortdeps ${@/$XBPS_TARGET/}
@@ -866,7 +880,7 @@ case "$XBPS_TARGET" in
         bulk_update
         ;;
     update-sys)
-        bulk_update -i
+        bulk_update -I
         ;;
     update-check)
         read_pkg ignore-problems

From 8f74846ff8e4ed079225cf412f11cdc432733a7d Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 10 Jul 2019 19:49:39 +0200
Subject: [PATCH 2/4] qt5: use a working distfile mirror.

---
 srcpkgs/qt5/template | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/srcpkgs/qt5/template b/srcpkgs/qt5/template
index 8d170535e89..2293f512d0a 100644
--- a/srcpkgs/qt5/template
+++ b/srcpkgs/qt5/template
@@ -20,7 +20,7 @@ short_desc="Cross-platform application and UI framework (QT5)"
 maintainer="Jürgen Buchmüller <pullmoll@t-online.de>"
 license="GPL-3.0-or-later, LGPL-2.1-or-later"
 homepage="https://qt.io/"
-distfiles="http://download.qt.io/official_releases/qt/${version%.*}/${version}/single/qt-everywhere-src-${version}.tar.xz"
+distfiles="http://mirrors.ukfast.co.uk/sites/qt.io/archive/qt/${version%.*}/${version}/single/qt-everywhere-src-${version}.tar.xz"
 checksum=859417642713cee2493ee3646a7fee782c9f1db39e41d7bb1322bba0c5f0ff4d
 replaces="qt5-doc<5.6.0 qt5-quick1<5.6.0 qt5-quick1-devel<5.6.0 qt5-webkit<5.6.0 qt5-webkit-devel<5.6.0
  qt5-enginio<5.7.1 qt5-enginio-devel<5.7.1 qt5-plugin-gtk<5.7.1"

From 7bc928b0aa08eb9344802b28606ae5be81b8bb46 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 10 Jul 2019 19:50:09 +0200
Subject: [PATCH 3/4] bash-completion: a runtime dependency on bash is enough.

---
 srcpkgs/bash-completion/template | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/srcpkgs/bash-completion/template b/srcpkgs/bash-completion/template
index 01ecdd0a726..80c273f8713 100644
--- a/srcpkgs/bash-completion/template
+++ b/srcpkgs/bash-completion/template
@@ -5,8 +5,7 @@ revision=1
 archs=noarch
 build_style=gnu-configure
 make_install_args="profiledir=/etc/bash/bashrc.d"
-makedepends="bash"
-depends="${makedepends}"
+depends="bash"
 short_desc="Programmable completion for the GNU Bash shell"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="GPL-2.0-or-later"

From 3a160bf0ecbef6fe8780f4f1281403655f852abc Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Wed, 10 Jul 2019 19:50:33 +0200
Subject: [PATCH 4/4] docbook2x: a runtime dependency on texinfo is enough.

---
 srcpkgs/docbook2x/template | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/srcpkgs/docbook2x/template b/srcpkgs/docbook2x/template
index cc93280cd93..614a2c65477 100644
--- a/srcpkgs/docbook2x/template
+++ b/srcpkgs/docbook2x/template
@@ -6,8 +6,8 @@ patch_args="-Np1"
 wrksrc="docbook2X-${version}"
 build_style=gnu-configure
 configure_args="--without-resolver-jars --without-saxon-jars --without-xalan-jars"
-hostmakedepends="texinfo libxslt docbook docbook-dsssl docbook-xsl perl-XML-SAX"
-depends="${hostmakedepends}"
+hostmakedepends="libxslt docbook docbook-dsssl docbook-xsl perl-XML-SAX"
+depends="texinfo ${hostmakedepends}"
 xml_entries="
  nextCatalog /usr/share/docbook2X/dtd/catalog.xml --
  nextCatalog /usr/share/docbook2X/xslt/catalog.xml --"

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PR PATCH] [Merged]: xbps-src: multiple performance improvements
  2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
                   ` (44 preceding siblings ...)
  2019-07-10 17:51 ` voidlinux-github
@ 2019-07-10 18:28 ` voidlinux-github
  45 siblings, 0 replies; 47+ messages in thread
From: voidlinux-github @ 2019-07-10 18:28 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 925 bytes --]

There's a merged pull request on the void-packages repository

xbps-src: multiple performance improvements
https://github.com/void-linux/void-packages/pull/12797
Description: xbps-src: multiple performance improvements

- use xbps-checkvers(1) to resolve dependencies.
- all dependencies are installed at once for the host and target.
- the `show-build-deps` target is now much faster.
- the `update-bulk/show-repo-updates` targets are now much faster.
- the `update-sys/show-sys-updates` targets are now much faster.
- the `bootstrap` target now works on musl hosts.
- simplified some loops.
- use cut(1) rather than awk(1) where applicable.
- multiple random changes to improve performance.

 Based on work started by @Duncaen on https://github.com/void-linux/void-packages/pull/12433

Close https://github.com/void-linux/void-packages/pull/12433
Close https://github.com/void-linux/void-packages/pull/11282

^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2019-07-10 18:28 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-03 17:49 [PR PATCH] xbps-src: multiple performance improvements voidlinux-github
2019-07-03 17:52 ` voidlinux-github
2019-07-03 18:34 ` voidlinux-github
2019-07-03 18:40 ` [PR PATCH] [Updated] " voidlinux-github
2019-07-03 18:40 ` voidlinux-github
2019-07-03 18:40 ` voidlinux-github
2019-07-03 19:00 ` voidlinux-github
2019-07-03 20:58 ` voidlinux-github
2019-07-03 21:38 ` voidlinux-github
2019-07-03 21:43 ` voidlinux-github
2019-07-04  5:06 ` voidlinux-github
2019-07-04  5:57 ` [PR PATCH] [Updated] " voidlinux-github
2019-07-04  5:57 ` voidlinux-github
2019-07-04  9:03 ` voidlinux-github
2019-07-04  9:03 ` voidlinux-github
2019-07-04  9:53 ` voidlinux-github
2019-07-04  9:53 ` voidlinux-github
2019-07-04 10:07 ` voidlinux-github
2019-07-04 10:07 ` voidlinux-github
2019-07-04 10:48 ` voidlinux-github
2019-07-04 12:56 ` voidlinux-github
2019-07-04 13:15 ` voidlinux-github
2019-07-04 13:35 ` voidlinux-github
2019-07-04 13:39 ` voidlinux-github
2019-07-04 15:03 ` voidlinux-github
2019-07-04 19:32 ` voidlinux-github
2019-07-05  7:00 ` voidlinux-github
2019-07-05  7:01 ` voidlinux-github
2019-07-05  9:47 ` [PR PATCH] [Closed]: " voidlinux-github
2019-07-05  9:54 ` voidlinux-github
2019-07-05 10:09 ` voidlinux-github
2019-07-05 18:20 ` voidlinux-github
2019-07-06  8:17 ` voidlinux-github
2019-07-07  6:24 ` [PR PATCH] [Updated] " voidlinux-github
2019-07-07  6:24 ` voidlinux-github
2019-07-07  6:27 ` voidlinux-github
2019-07-07  6:35 ` voidlinux-github
2019-07-07  6:36 ` [PR PATCH] [Updated] " voidlinux-github
2019-07-07  6:36 ` voidlinux-github
2019-07-07  7:00 ` voidlinux-github
2019-07-07  7:00 ` voidlinux-github
2019-07-07  7:38 ` voidlinux-github
2019-07-07  7:38 ` voidlinux-github
2019-07-07  9:31 ` voidlinux-github
2019-07-10 17:51 ` [PR PATCH] [Updated] " voidlinux-github
2019-07-10 17:51 ` voidlinux-github
2019-07-10 18:28 ` [PR PATCH] [Merged]: " voidlinux-github

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).