From 072a704eeb7ae55c333cb734e5a659030700f27d Mon Sep 17 00:00:00 2001
From: Duncaen <duncaen@voidlinux.org>
Date: Wed, 12 Jun 2019 23:50:19 +0200
Subject: [PATCH 1/8] xbps-src: don't check if base-chroot is installed for
 every single sourced template

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

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index cdf1803a4d5..62d6ae30aec 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -372,12 +372,9 @@ setup_pkg() {
     esac
 
     # Check if base-chroot is already installed.
-    if [ -z "$bootstrap" -a "z$show_problems" != "zignore-problems" ]; then
-        check_installed_pkg base-chroot-0.1_1
-        if [ $? -ne 0 ]; then
-            msg_red "${pkg} is not a bootstrap package and cannot be built without it.\n"
-            msg_error "Please install bootstrap packages and try again.\n"
-        fi
+    if [ -z "$bootstrap" -a -z "$CHROOT_READY" -a "z$show_problems" != "zignore-problems" ]; then
+        msg_red "${pkg} is not a bootstrap package and cannot be built without it.\n"
+        msg_error "Please install bootstrap packages and try again.\n"
     fi
 
     sourcepkg="${pkgname}"

From c4b213777ff68e0bf071dc8c9ba4d96775685b24 Mon Sep 17 00:00:00 2001
From: Duncaen <duncaen@voidlinux.org>
Date: Wed, 12 Jun 2019 23:51:09 +0200
Subject: [PATCH 2/8] xbps-src: less forking in get_subpkgs and
 unset_package_funcs

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

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 62d6ae30aec..65ae50a00a0 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -258,21 +258,24 @@ run_pkg_hooks() {
 unset_package_funcs() {
     local f
 
-    for f in $(typeset -F|grep -E '_package$'); do
-        eval unset -f $f
+    for f in "$(typeset -F)"; do
+        case "$f" in
+        *_package)
+            unset -f "$f"
+            ;;
+        esac
     done
 }
 
 get_subpkgs() {
-    local args list
+    local f
 
-    args="$(typeset -F|grep -E '_package$')"
-    set -- ${args}
-    while [ $# -gt 0 ]; do
-        list+=" ${3%_package}"; shift 3
-    done
-    for f in ${list}; do
-        echo "$f"
+    for f in $(typeset -F); do
+        case "$f" in
+        *_package)
+            echo "${f%_package}"
+            ;;
+        esac
     done
 }
 

From 50f0ff8c108996bd13ba9530048be0c74aca8ac9 Mon Sep 17 00:00:00 2001
From: Duncaen <duncaen@voidlinux.org>
Date: Wed, 12 Jun 2019 23:52:24 +0200
Subject: [PATCH 3/8] xbps-src: simplify set_build_options

---
 common/xbps-src/shutils/common.sh | 47 +++++++++----------------------
 1 file changed, 13 insertions(+), 34 deletions(-)

diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 65ae50a00a0..c447e5fd850 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -154,7 +154,7 @@ msg_normal_append() {
 }
 
 set_build_options() {
-    local f j opt optval _optsset pkgopts _pkgname
+    local f j pkgopts _pkgname
     local -A options
 
     if [ -z "$build_options" ]; then
@@ -170,30 +170,21 @@ set_build_options() {
         fi
         OIFS="$IFS"; IFS=','
         for j in ${pkgopts}; do
-            opt=${j#\~}
-            opt_disabled=${j:0:1}
-            if [ "$opt" = "$f" ]; then
-                if [ "$opt_disabled" != "~" ]; then
-                    eval options[$opt]=1
-                else
-                    eval options[$opt]=0
-                fi
-            fi
+            case "$j" in
+            "$f") options[$j]=1 ;;
+            "~$f") options[${j#\~}]=0 ;;
+            esac
         done
         IFS="$OIFS"
     done
 
     for f in ${build_options_default}; do
-        optval=${options[$f]}
-        if [[ -z "$optval" ]] || [[ $optval -eq 1 ]]; then
-            options[$f]=1
-        fi
+        [[ -z "${options[$f]}" ]] && options[$f]=1
     done
 
     # Prepare final options.
     for f in ${!options[@]}; do
-        optval=${options[$f]}
-        if [[ $optval -eq 1 ]]; then
+        if [[ ${options[$f]} -eq 1 ]]; then
             eval export build_option_${f}=1
         else
             eval unset build_option_${f}
@@ -210,25 +201,13 @@ set_build_options() {
         return 0
     fi
 
-    for f in ${build_options}; do
-        eval optval=${options[$f]}
-        if [[ $optval -eq 1 ]]; then
-            _optsset+=" ${f}"
-        else
-            _optsset+=" ~${f}"
-        fi
-    done
-
-    for f in ${_optsset}; do
-        if [ -z "$PKG_BUILD_OPTIONS" ]; then
-            PKG_BUILD_OPTIONS="$f"
-        else
-            PKG_BUILD_OPTIONS+=" $f"
-        fi
-    done
-
     # Sort pkg build options alphabetically.
-    export PKG_BUILD_OPTIONS="$(echo "$PKG_BUILD_OPTIONS"|tr ' ' '\n'|sort|tr '\n' ' ')"
+    export PKG_BUILD_OPTIONS=$(
+        for f in ${build_options}; do
+            [[ "${options[$f]}" -eq 1 ]] || printf '~'
+            printf '%s\n' "$f"
+        done | sort
+    )
 }
 
 source_file() {

From 65f93b4496000119123a93ea567bbb6544e149d6 Mon Sep 17 00:00:00 2001
From: Duncaen <duncaen@voidlinux.org>
Date: Thu, 13 Jun 2019 00:29:49 +0200
Subject: [PATCH 4/8] xbps-src: open $XBPS_MASTERDIR/etc/xbps/xbps-src.conf
 only once

---
 common/xbps-src/shutils/chroot.sh | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 50eb195a4bd..968ea0e843a 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -3,17 +3,11 @@
 # FIXME: $XBPS_FFLAGS is not set when chroot_init() is run
 # It is set in common/build-profiles/bootstrap.sh but lost somewhere?
 chroot_init() {
-    XBPSSRC_CF=$XBPS_MASTERDIR/etc/xbps/xbps-src.conf
-
     mkdir -p $XBPS_MASTERDIR/etc/xbps
 
-    cat > $XBPSSRC_CF <<_EOF
+    cat > $XBPS_MASTERDIR/etc/xbps/xbps-src.conf <<_EOF
 # Generated configuration file by xbps-src, DO NOT EDIT!
-_EOF
-    if [ -e "$XBPS_CONFIG_FILE" ]; then
-        grep -E '^XBPS_.*' $XBPS_CONFIG_FILE >> $XBPSSRC_CF
-    fi
-    cat >> $XBPSSRC_CF <<_EOF
+$(grep -E '^XBPS_.*' "$XBPS_CONFIG_FILE")
 XBPS_MASTERDIR=/
 XBPS_CFLAGS="$XBPS_CFLAGS"
 XBPS_CXXFLAGS="$XBPS_CXXFLAGS"
@@ -21,10 +15,9 @@ XBPS_FFLAGS="-fPIC -pipe"
 XBPS_CPPFLAGS="$XBPS_CPPFLAGS"
 XBPS_LDFLAGS="$XBPS_LDFLAGS"
 XBPS_HOSTDIR=/host
+# End of configuration file.
 _EOF
 
-    echo "# End of configuration file." >> $XBPSSRC_CF
-
     # Create custom script to start the chroot bash shell.
     cat > $XBPS_MASTERDIR/bin/xbps-shell <<_EOF
 #!/bin/sh

From bcedf8256e97b33a4423e9f6a1fc94dc5514b26d Mon Sep 17 00:00:00 2001
From: Duncaen <duncaen@voidlinux.org>
Date: Thu, 13 Jun 2019 00:37:59 +0200
Subject: [PATCH 5/8] xbps-src: use substitutions instead of sed for xbps-shell

---
 common/xbps-src/shutils/chroot.sh | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh
index 968ea0e843a..ea8f7b62465 100644
--- a/common/xbps-src/shutils/chroot.sh
+++ b/common/xbps-src/shutils/chroot.sh
@@ -28,20 +28,12 @@ XBPS_SRC_VERSION="$XBPS_SRC_VERSION"
 
 PATH=/void-packages:/usr/bin:/usr/sbin
 
-exec env -i -- SHELL=/bin/sh PATH="\$PATH" DISTCC_HOSTS="\$XBPS_DISTCC_HOSTS" DISTCC_DIR="/host/distcc" @@XARCH@@ \
-    @@CHECK@@ CCACHE_DIR="/host/ccache" IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 TERM=linux HOME="/tmp" \
+exec env -i -- SHELL=/bin/sh PATH="\$PATH" DISTCC_HOSTS="\$XBPS_DISTCC_HOSTS" DISTCC_DIR="/host/distcc" \
+    ${XBPS_ARCH+XBPS_ARCH=$XBPS_ARCH} ${XBPS_CHECK_PKGS+XBPS_CHECK_PKGS=$XBPS_CHECK_PKGS} \
+    CCACHE_DIR="/host/ccache" IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 TERM=linux HOME="/tmp" \
     PS1="[\u@$XBPS_MASTERDIR \W]$ " /bin/bash +h
 _EOF
-    if [ -n "$XBPS_ARCH" ]; then
-        sed -e "s,@@XARCH@@,XBPS_ARCH=${XBPS_ARCH},g" -i $XBPS_MASTERDIR/bin/xbps-shell
-    else
-        sed -e 's,@@XARCH@@,,g' -i $XBPS_MASTERDIR/bin/xbps-shell
-    fi
-    if [ -z "$XBPS_CHECK_PKGS" ]; then
-        sed -e 's,@@CHECK@@,,g' -i $XBPS_MASTERDIR/bin/xbps-shell
-    else
-        sed -e "s,@@CHECK@@,XBPS_CHECK_PKGS=$XBPS_CHECK_PKGS,g" -i $XBPS_MASTERDIR/bin/xbps-shell
-    fi
+
     chmod 755 $XBPS_MASTERDIR/bin/xbps-shell
 
     cp -f /etc/resolv.conf $XBPS_MASTERDIR/etc

From 89e947dc947d6ac8ec3796e319c7d37a0235af16 Mon Sep 17 00:00:00 2001
From: Duncaen <duncaen@voidlinux.org>
Date: Thu, 13 Jun 2019 23:56:39 +0200
Subject: [PATCH 6/8] xbps: update to 0.54-git. DO NOT MERGE

---
 .../xbps/patches/fix-32-bit-formatting.patch  |  62 ---
 srcpkgs/xbps/patches/fix-confdir-size.patch   |  42 --
 srcpkgs/xbps/patches/fix-https-proxy.patch    |  52 --
 .../patches/fix-namespace-violation.patch     | 475 ------------------
 srcpkgs/xbps/patches/fix-rootdir-size.patch   |  25 -
 srcpkgs/xbps/patches/fix-strncat-dash.patch   |  14 -
 srcpkgs/xbps/template                         |  14 +-
 7 files changed, 8 insertions(+), 676 deletions(-)
 delete mode 100644 srcpkgs/xbps/patches/fix-32-bit-formatting.patch
 delete mode 100644 srcpkgs/xbps/patches/fix-confdir-size.patch
 delete mode 100644 srcpkgs/xbps/patches/fix-https-proxy.patch
 delete mode 100644 srcpkgs/xbps/patches/fix-namespace-violation.patch
 delete mode 100644 srcpkgs/xbps/patches/fix-rootdir-size.patch
 delete mode 100644 srcpkgs/xbps/patches/fix-strncat-dash.patch

diff --git a/srcpkgs/xbps/patches/fix-32-bit-formatting.patch b/srcpkgs/xbps/patches/fix-32-bit-formatting.patch
deleted file mode 100644
index 530292b9fa0..00000000000
--- a/srcpkgs/xbps/patches/fix-32-bit-formatting.patch
+++ /dev/null
@@ -1,62 +0,0 @@
-From 4eaf45a7679e59f6e24d5464dc1a122bd059dbb7 Mon Sep 17 00:00:00 2001
-From: Foxlet <foxlet@furcode.co>
-Date: Tue, 17 Jul 2018 20:26:08 -0400
-Subject: [PATCH] Fix string formatting of 64-bit unsigned integers
-
----
- bin/xbps-create/main.c | 4 ++--
- lib/package_unpack.c   | 6 +++---
- 2 files changed, 5 insertions(+), 5 deletions(-)
-
-diff --git bin/xbps-create/main.c bin/xbps-create/main.c
-index d03b9f39..aac9676a 100644
---- bin/xbps-create/main.c
-+++ bin/xbps-create/main.c
-@@ -426,7 +426,7 @@ ftw_cb(const char *fpath, const struct stat *sb, const struct dirent *dir _unuse
- 		TAILQ_FOREACH(xep, &xentry_list, entries) {
- 			if (sb->st_nlink > 1 && xep->inode == sb->st_ino) {
- 				/* matched */
--				printf("%lu %lu\n", xep->inode, sb->st_ino);
-+				printf("%"PRIu64" %"PRIu64"\n", xep->inode, sb->st_ino);
- 				hlink = true;
- 				break;
- 			}
-@@ -441,7 +441,7 @@ ftw_cb(const char *fpath, const struct stat *sb, const struct dirent *dir _unuse
- 			xbps_dictionary_get_uint64(linkinfo, "inode", &inode);
- 			if (inode == sb->st_ino) {
- 				/* matched */
--				printf("%lu %lu\n", inode, sb->st_ino);
-+				printf("%"PRIu64" %"PRIu64"\n", inode, sb->st_ino);
- 				break;
- 			}
- 		}
-diff --git lib/package_unpack.c lib/package_unpack.c
-index 6546a77a..25a6388e 100644
---- lib/package_unpack.c
-+++ lib/package_unpack.c
-@@ -377,13 +377,13 @@ unpack_archive(struct xbps_handle *xhp,
- 			    archive_entry_gid(entry)) != 0) {
- 				xbps_dbg_printf(xhp,
- 				    "%s: failed "
--				    "to set uid/gid to %zu:%zu (%s)\n",
-+				    "to set uid/gid to %"PRIu64":%"PRIu64" (%s)\n",
- 				    pkgver, archive_entry_uid(entry),
- 				    archive_entry_gid(entry),
- 				    strerror(errno));
- 			} else {
- 				xbps_dbg_printf(xhp, "%s: entry %s changed "
--				    "uid/gid to %zu:%zu.\n", pkgver, entry_pname,
-+				    "uid/gid to %"PRIu64":%"PRIu64".\n", pkgver, entry_pname,
- 				    archive_entry_uid(entry),
- 				    archive_entry_gid(entry));
- 			}
-@@ -426,7 +426,7 @@ unpack_archive(struct xbps_handle *xhp,
- 				      AT_SYMLINK_NOFOLLOW) == -1) {
- 				xbps_dbg_printf(xhp,
- 				    "%s: failed "
--				    "to set mtime %ju to %s: %s\n",
-+				    "to set mtime %lu to %s: %s\n",
- 				    pkgver, archive_entry_mtime_nsec(entry),
- 				    entry_pname,
- 				    strerror(errno));
-
diff --git a/srcpkgs/xbps/patches/fix-confdir-size.patch b/srcpkgs/xbps/patches/fix-confdir-size.patch
deleted file mode 100644
index fec9f99a816..00000000000
--- a/srcpkgs/xbps/patches/fix-confdir-size.patch
+++ /dev/null
@@ -1,42 +0,0 @@
---- tests/xbps/libxbps/config/main.c	2018-07-30 13:47:08.000000000 +0200
-+++ tests/xbps/libxbps/config/main.c	2018-08-07 08:37:37.900690953 +0200
-@@ -39,6 +39,8 @@
- 	struct xbps_handle xh;
- 	const char *tcsdir;
- 	char *buf, *buf2, pwd[PATH_MAX];
-+	char confdir[PATH_MAX + 1 + sizeof("xbps.d")];
-+	size_t len;
- 
- 	/* get test source dir */
- 	tcsdir = atf_tc_get_config_var(tc, "srcdir");
-@@ -48,7 +50,9 @@
- 
- 	xbps_strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir));
- 	xbps_strlcpy(xh.metadir, pwd, sizeof(xh.metadir));
--	snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd);
-+	len = snprintf(confdir, sizeof(confdir), "%s/xbps.d", pwd);
-+	ATF_REQUIRE_EQ((len < sizeof(xh.confdir)), 1);
-+	memcpy(xh.confdir, confdir, len + 1);
- 
- 	ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0);
- 
-@@ -88,6 +88,8 @@
- 	struct xbps_handle xh;
- 	const char *tcsdir;
- 	char *buf, *buf2, pwd[PATH_MAX];
-+	char confdir[PATH_MAX + 1 + sizeof("xbps.d")];
-+	size_t len;
- 
- 	/* get test source dir */
- 	tcsdir = atf_tc_get_config_var(tc, "srcdir");
-@@ -97,7 +99,9 @@
- 
- 	xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
- 	xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir));
--	snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd);
-+	len = snprintf(confdir, sizeof(confdir), "%s/xbps.d", pwd);
-+	ATF_REQUIRE_EQ((len < sizeof(xh.confdir)), 1);
-+	memcpy(xh.confdir, confdir, len + 1);
- 
- 	ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0);
- 
diff --git a/srcpkgs/xbps/patches/fix-https-proxy.patch b/srcpkgs/xbps/patches/fix-https-proxy.patch
deleted file mode 100644
index 860c245b3ae..00000000000
--- a/srcpkgs/xbps/patches/fix-https-proxy.patch
+++ /dev/null
@@ -1,52 +0,0 @@
-From 07ec982b078f8672c8cdbb42bf2e861c969ab40b Mon Sep 17 00:00:00 2001
-From: Duncaen <mail@duncano.de>
-Date: Mon, 8 Apr 2019 13:16:53 +0200
-Subject: [PATCH] lib/fetch/http.c: ignore headers after CONNECT response
-
----
- lib/fetch/http.c | 19 ++++++++++++++++++-
- 1 file changed, 18 insertions(+), 1 deletion(-)
-
-diff --git lib/fetch/http.c lib/fetch/http.c
-index dcc7bf7d..cb27905e 100644
---- lib/fetch/http.c
-+++ lib/fetch/http.c
-@@ -721,6 +721,8 @@ http_connect(struct url *URL, struct url *purl, const char *flags, int *cached)
- {
- 	struct url *curl;
- 	conn_t *conn;
-+	const char *p;
-+	hdr_t h;
- 	int af, verbose;
- #ifdef TCP_NOPUSH
- 	int val;
-@@ -759,10 +761,25 @@ http_connect(struct url *URL, struct url *purl, const char *flags, int *cached)
- 		http_cmd(conn, "\r\n");
- 
- 		if (http_get_reply(conn) != HTTP_OK) {
-+			http_seterr(conn->err);
- 			fetch_close(conn);
- 			return (NULL);
- 		}
--		http_get_reply(conn);
-+		/* Read and discard the rest of the proxy response */
-+		do {
-+			switch ((h = http_next_header(conn, &p))) {
-+			case hdr_syserror:
-+				fetch_syserr();
-+				fetch_close(conn);
-+				return (NULL);
-+			case hdr_error:
-+				http_seterr(HTTP_PROTOCOL_ERROR);
-+				fetch_close(conn);
-+				return (NULL);
-+			default:
-+				/* ignore */ ;
-+			}
-+		} while (h > hdr_end);
- 	}
- 	if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 &&
- 	    fetch_ssl(conn, URL, verbose) == -1) {
--- 
-2.21.0
-
diff --git a/srcpkgs/xbps/patches/fix-namespace-violation.patch b/srcpkgs/xbps/patches/fix-namespace-violation.patch
deleted file mode 100644
index 67b0202d88e..00000000000
--- a/srcpkgs/xbps/patches/fix-namespace-violation.patch
+++ /dev/null
@@ -1,475 +0,0 @@
-From 0f338597015271ee504100c32fd2c4926efdb423 Mon Sep 17 00:00:00 2001
-From: Foxlet <foxlet@furcode.co>
-Date: Tue, 17 Jul 2018 22:24:26 -0400
-Subject: [PATCH] Fix namespace violation
-
----
- bin/xbps-alternatives/main.c        |  2 +-
- bin/xbps-create/main.c              |  4 +--
- bin/xbps-install/main.c             |  4 +--
- bin/xbps-install/state_cb.c         |  2 +-
- bin/xbps-pkgdb/check.c              |  6 ++---
- bin/xbps-pkgdb/check_pkg_unneeded.c |  2 +-
- bin/xbps-query/list.c               | 38 ++++++++++++++---------------
- bin/xbps-query/ownedby.c            | 10 ++++----
- bin/xbps-query/search.c             |  8 +++---
- bin/xbps-reconfigure/main.c         |  2 +-
- bin/xbps-remove/clean-cache.c       |  4 +--
- bin/xbps-remove/main.c              |  2 +-
- bin/xbps-rindex/index-clean.c       |  4 +--
- bin/xbps-rindex/remove-obsoletes.c  |  2 +-
- bin/xbps-uchroot/main.c             |  4 +--
- configure                           |  2 +-
- lib/package_orphans.c               |  2 +-
- lib/plist_fetch.c                   |  6 ++---
- lib/rpool.c                         |  6 ++---
- lib/transaction_conflicts.c         |  2 +-
- 20 files changed, 56 insertions(+), 56 deletions(-)
-
-diff --git bin/xbps-alternatives/main.c bin/xbps-alternatives/main.c
-index c722a74b..94ab31e8 100644
---- bin/xbps-alternatives/main.c
-+++ bin/xbps-alternatives/main.c
-@@ -55,7 +55,7 @@ usage(bool fail)
- }
- 
- static int
--state_cb(const struct xbps_state_cb_data *xscd, void *cbd _unused)
-+state_cb(const struct xbps_state_cb_data *xscd, void *cbd UNUSED)
- {
- 	bool slog = false;
- 
-diff --git bin/xbps-create/main.c bin/xbps-create/main.c
-index aac9676a..2c211215 100644
---- bin/xbps-create/main.c
-+++ bin/xbps-create/main.c
-@@ -199,7 +199,7 @@ process_one_alternative(const char *altgrname, const char *val)
- 
- 
- static void
--process_dict_of_arrays(const char *key _unused, const char *val)
-+process_dict_of_arrays(const char *key UNUSED, const char *val)
- {
- 	char *altgrname, *args, *p, *saveptr;
- 
-@@ -302,7 +302,7 @@ entry_is_conf_file(const char *file)
- }
- 
- static int
--ftw_cb(const char *fpath, const struct stat *sb, const struct dirent *dir _unused)
-+ftw_cb(const char *fpath, const struct stat *sb, const struct dirent *dir UNUSED)
- {
- 	struct xentry *xe = NULL;
- 	xbps_dictionary_t fileinfo = NULL;
-diff --git bin/xbps-install/main.c bin/xbps-install/main.c
-index b57f2fe9..da20da1a 100644
---- bin/xbps-install/main.c
-+++ bin/xbps-install/main.c
-@@ -68,7 +68,7 @@ usage(bool fail)
- }
- 
- static void
--unpack_progress_cb(const struct xbps_unpack_cb_data *xpd, void *cbdata _unused)
-+unpack_progress_cb(const struct xbps_unpack_cb_data *xpd, void *cbdata UNUSED)
- {
- 	if (xpd->entry == NULL || xpd->entry_total_count <= 0)
- 		return;
-@@ -80,7 +80,7 @@ unpack_progress_cb(const struct xbps_unpack_cb_data *xpd, void *cbdata _unused)
- }
- 
- static int
--repo_import_key_cb(struct xbps_repo *repo, void *arg _unused, bool *done _unused)
-+repo_import_key_cb(struct xbps_repo *repo, void *arg UNUSED, bool *done UNUSED)
- {
- 	int rv;
- 
-diff --git bin/xbps-install/state_cb.c bin/xbps-install/state_cb.c
-index 5189b9a9..a2063cea 100644
---- bin/xbps-install/state_cb.c
-+++ bin/xbps-install/state_cb.c
-@@ -32,7 +32,7 @@
- #include "defs.h"
- 
- int
--state_cb(const struct xbps_state_cb_data *xscd, void *cbdata _unused)
-+state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
- {
- 	xbps_dictionary_t pkgd;
- 	const char *instver, *newver;
-diff --git bin/xbps-pkgdb/check.c bin/xbps-pkgdb/check.c
-index ed393398..6ae11db7 100644
---- bin/xbps-pkgdb/check.c
-+++ bin/xbps-pkgdb/check.c
-@@ -36,11 +36,11 @@
- #include "defs.h"
- 
- static int
--pkgdb_cb(struct xbps_handle *xhp _unused,
-+pkgdb_cb(struct xbps_handle *xhp UNUSED,
- 		xbps_object_t obj,
--		const char *key _unused,
-+		const char *key UNUSED,
- 		void *arg,
--		bool *done _unused)
-+		bool *done UNUSED)
- {
- 	const char *pkgver;
- 	char *pkgname;
-diff --git bin/xbps-pkgdb/check_pkg_unneeded.c bin/xbps-pkgdb/check_pkg_unneeded.c
-index d2249304..2b137b3f 100644
---- bin/xbps-pkgdb/check_pkg_unneeded.c
-+++ bin/xbps-pkgdb/check_pkg_unneeded.c
-@@ -43,7 +43,7 @@
-  * 	  and remove them if that was true.
-  */
- int
--check_pkg_unneeded(struct xbps_handle *xhp _unused, const char *pkgname, void *arg)
-+check_pkg_unneeded(struct xbps_handle *xhp UNUSED, const char *pkgname, void *arg)
- {
- 	xbps_array_t replaces;
- 	xbps_dictionary_t pkgd = arg;
-diff --git bin/xbps-query/list.c bin/xbps-query/list.c
-index ddda8be8..f08334c3 100644
---- bin/xbps-query/list.c
-+++ bin/xbps-query/list.c
-@@ -38,11 +38,11 @@ struct list_pkgver_cb {
- };
- 
- int
--list_pkgs_in_dict(struct xbps_handle *xhp _unused,
-+list_pkgs_in_dict(struct xbps_handle *xhp UNUSED,
- 		  xbps_object_t obj,
--		  const char *key _unused,
-+		  const char *key UNUSED,
- 		  void *arg,
--		  bool *loop_done _unused)
-+		  bool *loop_done UNUSED)
- {
- 	struct list_pkgver_cb *lpc = arg;
- 	const char *pkgver, *short_desc, *state_str;
-@@ -88,11 +88,11 @@ list_pkgs_in_dict(struct xbps_handle *xhp _unused,
- }
- 
- int
--list_manual_pkgs(struct xbps_handle *xhp _unused,
-+list_manual_pkgs(struct xbps_handle *xhp UNUSED,
- 		 xbps_object_t obj,
--		 const char *key _unused,
--		 void *arg _unused,
--		 bool *loop_done _unused)
-+		 const char *key UNUSED,
-+		 void *arg UNUSED,
-+		 bool *loop_done UNUSED)
- {
- 	const char *pkgver;
- 	bool automatic = false;
-@@ -107,11 +107,11 @@ list_manual_pkgs(struct xbps_handle *xhp _unused,
- }
- 
- int
--list_hold_pkgs(struct xbps_handle *xhp _unused,
-+list_hold_pkgs(struct xbps_handle *xhp UNUSED,
- 		xbps_object_t obj,
--		const char *key _unused,
--		void *arg _unused,
--		bool *loop_done _unused)
-+		const char *key UNUSED,
-+		void *arg UNUSED,
-+		bool *loop_done UNUSED)
- {
- 	const char *pkgver;
- 
-@@ -124,11 +124,11 @@ list_hold_pkgs(struct xbps_handle *xhp _unused,
- }
- 
- int
--list_repolock_pkgs(struct xbps_handle *xhp _unused,
-+list_repolock_pkgs(struct xbps_handle *xhp UNUSED,
- 		xbps_object_t obj,
--		const char *key _unused,
--		void *arg _unused,
--		bool *loop_done _unused)
-+		const char *key UNUSED,
-+		void *arg UNUSED,
-+		bool *loop_done UNUSED)
- {
- 	const char *pkgver;
- 
-@@ -171,7 +171,7 @@ list_pkgs_pkgdb(struct xbps_handle *xhp)
- }
- 
- static int
--repo_list_uri_cb(struct xbps_repo *repo, void *arg _unused, bool *done _unused)
-+repo_list_uri_cb(struct xbps_repo *repo, void *arg UNUSED, bool *done UNUSED)
- {
- 	const char *signedby = NULL;
- 	uint16_t pubkeysize = 0;
-@@ -219,11 +219,11 @@ struct fflongest {
- };
- 
- static int
--_find_longest_pkgver_cb(struct xbps_handle *xhp _unused,
-+_find_longest_pkgver_cb(struct xbps_handle *xhp UNUSED,
- 			xbps_object_t obj,
--			const char *key _unused,
-+			const char *key UNUSED,
- 			void *arg,
--			bool *loop_done _unused)
-+			bool *loop_done UNUSED)
- {
- 	struct fflongest *ffl = arg;
- 	const char *pkgver;
-diff --git bin/xbps-query/ownedby.c bin/xbps-query/ownedby.c
-index fc8684dc..11f76a99 100644
---- bin/xbps-query/ownedby.c
-+++ bin/xbps-query/ownedby.c
-@@ -97,9 +97,9 @@ match_files_by_pattern(xbps_dictionary_t pkg_filesd,
- static int
- ownedby_pkgdb_cb(struct xbps_handle *xhp,
- 		xbps_object_t obj,
--		const char *obj_key _unused,
-+		const char *obj_key UNUSED,
- 		void *arg,
--		bool *done _unused)
-+		bool *done UNUSED)
- {
- 	xbps_dictionary_t pkgmetad;
- 	xbps_array_t files_keys;
-@@ -129,9 +129,9 @@ ownedby_pkgdb_cb(struct xbps_handle *xhp,
- static int
- repo_match_cb(struct xbps_handle *xhp,
- 		xbps_object_t obj,
--		const char *key _unused,
-+		const char *key UNUSED,
- 		void *arg,
--		bool *done _unused)
-+		bool *done UNUSED)
- {
- 	xbps_dictionary_t filesd;
- 	xbps_array_t files_keys;
-@@ -163,7 +163,7 @@ repo_match_cb(struct xbps_handle *xhp,
- }
- 
- static int
--repo_ownedby_cb(struct xbps_repo *repo, void *arg, bool *done _unused)
-+repo_ownedby_cb(struct xbps_repo *repo, void *arg, bool *done UNUSED)
- {
- 	xbps_array_t allkeys;
- 	struct ffdata *ffd = arg;
-diff --git bin/xbps-query/search.c bin/xbps-query/search.c
-index 4b7ef054..41e1211d 100644
---- bin/xbps-query/search.c
-+++ bin/xbps-query/search.c
-@@ -94,11 +94,11 @@ print_results(struct xbps_handle *xhp, struct search_data *sd)
- }
- 
- static int
--search_array_cb(struct xbps_handle *xhp _unused,
-+search_array_cb(struct xbps_handle *xhp UNUSED,
- 		xbps_object_t obj,
--		const char *key _unused,
-+		const char *key UNUSED,
- 		void *arg,
--		bool *done _unused)
-+		bool *done UNUSED)
- {
- 	xbps_object_t obj2;
- 	struct search_data *sd = arg;
-@@ -210,7 +210,7 @@ search_array_cb(struct xbps_handle *xhp _unused,
- }
- 
- static int
--search_repo_cb(struct xbps_repo *repo, void *arg, bool *done _unused)
-+search_repo_cb(struct xbps_repo *repo, void *arg, bool *done UNUSED)
- {
- 	xbps_array_t allkeys;
- 	struct search_data *sd = arg;
-diff --git bin/xbps-reconfigure/main.c bin/xbps-reconfigure/main.c
-index 814959a8..1508c375 100644
---- bin/xbps-reconfigure/main.c
-+++ bin/xbps-reconfigure/main.c
-@@ -52,7 +52,7 @@ usage(bool fail)
- }
- 
- static int
--state_cb(const struct xbps_state_cb_data *xscd, void *cbd _unused)
-+state_cb(const struct xbps_state_cb_data *xscd, void *cbd UNUSED)
- {
- 	bool slog = false;
- 
-diff --git bin/xbps-remove/clean-cache.c bin/xbps-remove/clean-cache.c
-index dacc9a59..b3e00622 100644
---- bin/xbps-remove/clean-cache.c
-+++ bin/xbps-remove/clean-cache.c
-@@ -38,8 +38,8 @@
- 
- static int
- cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
--		const char *key _unused, void *arg,
--		bool *done _unused)
-+		const char *key UNUSED, void *arg,
-+		bool *done UNUSED)
- {
- 	xbps_dictionary_t repo_pkgd;
- 	const char *binpkg, *rsha256;
-diff --git bin/xbps-remove/main.c bin/xbps-remove/main.c
-index 25554e8c..838e610b 100644
---- bin/xbps-remove/main.c
-+++ bin/xbps-remove/main.c
-@@ -64,7 +64,7 @@ usage(bool fail)
- }
- 
- static int
--state_cb_rm(const struct xbps_state_cb_data *xscd, void *cbdata _unused)
-+state_cb_rm(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
- {
- 	bool slog = false;
- 
-diff --git bin/xbps-rindex/index-clean.c bin/xbps-rindex/index-clean.c
-index 364d57ed..27cedd6e 100644
---- bin/xbps-rindex/index-clean.c
-+++ bin/xbps-rindex/index-clean.c
-@@ -47,9 +47,9 @@ struct CleanerCbInfo {
- static int
- idx_cleaner_cb(struct xbps_handle *xhp,
- 		xbps_object_t obj,
--		const char *key _unused,
-+		const char *key UNUSED,
- 		void *arg,
--		bool *done _unused)
-+		bool *done UNUSED)
- {
- 	struct CleanerCbInfo *info = arg;
- 	const char *arch, *pkgver, *sha256;
-diff --git bin/xbps-rindex/remove-obsoletes.c bin/xbps-rindex/remove-obsoletes.c
-index f426fe7c..80cf2fff 100644
---- bin/xbps-rindex/remove-obsoletes.c
-+++ bin/xbps-rindex/remove-obsoletes.c
-@@ -65,7 +65,7 @@ remove_pkg(const char *repodir, const char *file)
- }
- 
- static int
--cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, const char *key _unused, void *arg, bool *done _unused)
-+cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, const char *key UNUSED, void *arg, bool *done UNUSED)
- {
- 	struct xbps_repo *repo = ((struct xbps_repo **)arg)[0], *stage = ((struct xbps_repo **)arg)[1];
- 	const char *binpkg;
-diff --git bin/xbps-uchroot/main.c bin/xbps-uchroot/main.c
-index 0ee13253..c232de8e 100644
---- bin/xbps-uchroot/main.c
-+++ bin/xbps-uchroot/main.c
-@@ -109,8 +109,8 @@ die(const char *fmt, ...)
- }
- 
- static int
--ftw_cb(const char *fpath, const struct stat *sb _unused, int type,
--		struct FTW *ftwbuf _unused)
-+ftw_cb(const char *fpath, const struct stat *sb UNUSED, int type,
-+		struct FTW *ftwbuf UNUSED)
- {
- 	int sverrno = 0;
- 
-diff --git configure configure
-index 32cc5569..ebef990a 100755
---- configure
-+++ configure
-@@ -192,7 +192,7 @@ echo "CPPFLAGS +=	-DXBPS_SYSCONF_PATH=\\\"${ETCDIR}\\\"" >>$CONFIG_MK
- echo "CPPFLAGS +=	-DXBPS_SYSDEFCONF_PATH=\\\"${SHAREDIR}/xbps.d\\\"" >>$CONFIG_MK
- echo "CPPFLAGS +=	-DXBPS_VERSION=\\\"${VERSION}\\\"" >>$CONFIG_MK
- echo "CPPFLAGS +=	-DXBPS_META_PATH=\\\"${DBDIR}\\\"" >>$CONFIG_MK
--echo "CPPFLAGS +=	-D_unused=\"__attribute__((__unused__))\"" >>$CONFIG_MK
-+echo "CPPFLAGS +=	-DUNUSED=\"__attribute__((__unused__))\"" >>$CONFIG_MK
- 
- if [ -d .git ]; then
- 	_gitrev=$(git rev-parse --short HEAD)
-diff --git lib/package_orphans.c lib/package_orphans.c
-index 4a31fe1d..b908c049 100644
---- lib/package_orphans.c
-+++ lib/package_orphans.c
-@@ -60,7 +60,7 @@
-  */
- 
- xbps_array_t
--xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user _unused)
-+xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user UNUSED)
- {
- 	xbps_array_t rdeps, reqby, array = NULL;
- 	xbps_dictionary_t pkgd, deppkgd;
-diff --git lib/plist_fetch.c lib/plist_fetch.c
-index a1535515..fedd8ce8 100644
---- lib/plist_fetch.c
-+++ lib/plist_fetch.c
-@@ -46,7 +46,7 @@ struct fetch_archive {
- };
- 
- static int
--fetch_archive_open(struct archive *a _unused, void *client_data)
-+fetch_archive_open(struct archive *a UNUSED, void *client_data)
- {
- 	struct fetch_archive *f = client_data;
- 
-@@ -59,7 +59,7 @@ fetch_archive_open(struct archive *a _unused, void *client_data)
- }
- 
- static ssize_t
--fetch_archive_read(struct archive *a _unused, void *client_data, const void **buf)
-+fetch_archive_read(struct archive *a UNUSED, void *client_data, const void **buf)
- {
- 	struct fetch_archive *f = client_data;
- 
-@@ -68,7 +68,7 @@ fetch_archive_read(struct archive *a _unused, void *client_data, const void **bu
- }
- 
- static int
--fetch_archive_close(struct archive *a _unused, void *client_data)
-+fetch_archive_close(struct archive *a UNUSED, void *client_data)
- {
- 	struct fetch_archive *f = client_data;
- 
-diff --git lib/rpool.c lib/rpool.c
-index 9acc1181..94af7298 100644
---- lib/rpool.c
-+++ lib/rpool.c
-@@ -120,7 +120,7 @@ xbps_rpool_get_repo(const char *url)
- }
- 
- void
--xbps_rpool_release(struct xbps_handle *xhp _unused)
-+xbps_rpool_release(struct xbps_handle *xhp UNUSED)
- {
- 	struct xbps_repo *repo;
- 
-@@ -195,7 +195,7 @@ find_pkg_cb(struct xbps_repo *repo, void *arg, bool *done)
- }
- 
- static int
--find_pkg_revdeps_cb(struct xbps_repo *repo, void *arg, bool *done _unused)
-+find_pkg_revdeps_cb(struct xbps_repo *repo, void *arg, bool *done UNUSED)
- {
- 	struct rpool_fpkg *rpf = arg;
- 	xbps_array_t revdeps = NULL;
-@@ -216,7 +216,7 @@ find_pkg_revdeps_cb(struct xbps_repo *repo, void *arg, bool *done _unused)
- }
- 
- static int
--find_best_pkg_cb(struct xbps_repo *repo, void *arg, bool *done _unused)
-+find_best_pkg_cb(struct xbps_repo *repo, void *arg, bool *done UNUSED)
- {
- 	struct rpool_fpkg *rpf = arg;
- 	xbps_dictionary_t pkgd;
-diff --git lib/transaction_conflicts.c lib/transaction_conflicts.c
-index 09975cee..387895a4 100644
---- lib/transaction_conflicts.c
-+++ lib/transaction_conflicts.c
-@@ -148,7 +148,7 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
- 
- static int
- pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
--		const char *key _unused, void *arg, bool *done _unused)
-+		const char *key UNUSED, void *arg, bool *done UNUSED)
- {
- 	xbps_array_t pkg_cflicts, trans_cflicts, pkgs = arg;
- 	xbps_dictionary_t pkgd;
--- 
-2.19.1
-
diff --git a/srcpkgs/xbps/patches/fix-rootdir-size.patch b/srcpkgs/xbps/patches/fix-rootdir-size.patch
deleted file mode 100644
index d7ca7b26588..00000000000
--- a/srcpkgs/xbps/patches/fix-rootdir-size.patch
+++ /dev/null
@@ -1,25 +0,0 @@
---- lib/initend.c	2018-07-30 13:47:08.000000000 +0200
-+++ lib/initend.c	2018-08-07 08:28:24.261662391 +0200
-@@ -398,6 +398,7 @@
- {
- 	struct utsname un;
- 	char cwd[PATH_MAX-1], sysconfdir[XBPS_MAXPATH+sizeof(XBPS_SYSDEFCONF_PATH)], *buf;
-+	char relpath[PATH_MAX+1+XBPS_MAXPATH];
- 	const char *repodir, *native_arch;
- 	int rv;
- 
-@@ -412,9 +413,13 @@
- 		xhp->rootdir[0] = '/';
- 		xhp->rootdir[1] = '\0';
- 	} else if (xhp->rootdir[0] != '/') {
-+		size_t len;
- 		buf = strdup(xhp->rootdir);
--		snprintf(xhp->rootdir, sizeof(xhp->rootdir), "%s/%s", cwd, buf);
-+		len = snprintf(relpath, sizeof(relpath), "%s/%s", cwd, buf);
- 		free(buf);
-+		if (len >= XBPS_MAXPATH)
-+			return ENOTSUP;
-+		memcpy(xhp->rootdir, relpath, len + 1);
- 	}
- 	xbps_dbg_printf(xhp, "%s\n", XBPS_RELVER);
- 	/* set confdir */
diff --git a/srcpkgs/xbps/patches/fix-strncat-dash.patch b/srcpkgs/xbps/patches/fix-strncat-dash.patch
deleted file mode 100644
index acabf41865d..00000000000
--- a/srcpkgs/xbps/patches/fix-strncat-dash.patch
+++ /dev/null
@@ -1,14 +0,0 @@
---- bin/xbps-checkvers/main.c	2018-07-30 13:47:08.000000000 +0200
-+++ bin/xbps-checkvers/main.c	2018-08-07 08:47:03.070720109 +0200
-@@ -599,9 +599,9 @@
- 	else
- 		rcv->pkgd = xbps_rpool_get_pkg(&rcv->xhp, srcver);
- 
--	srcver = strncat(srcver, "-", 1);
-+	srcver = strncat(srcver, "-", 2);
- 	srcver = strncat(srcver, version.v.s, version.v.len);
--	srcver = strncat(srcver, "_", 1);
-+	srcver = strncat(srcver, "_", 2);
- 	srcver = strncat(srcver, revision.v.s, revision.v.len);
- 
- 	xbps_dictionary_get_cstring_nocopy(rcv->pkgd, "pkgver", &repover);
diff --git a/srcpkgs/xbps/template b/srcpkgs/xbps/template
index 23c8d900c4a..c42c1fb385d 100644
--- a/srcpkgs/xbps/template
+++ b/srcpkgs/xbps/template
@@ -1,15 +1,17 @@
 # Template file for 'xbps'
 pkgname=xbps
-version=0.53
-revision=10
+version=0.54
+revision=1
+_gitrev="f18cf87e3a59bed0ebed5cced6469c11791d33ed"
+wrksrc="xbps-${_gitrev}"
 bootstrap=yes
 build_style=configure
 short_desc="The XBPS package system utilities"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 homepage="https://github.com/void-linux/xbps"
 license="BSD-2-Clause"
-distfiles="https://github.com/void-linux/xbps/archive/${version}.tar.gz"
-checksum=360b3149141fec46dd6da9019605bcee48ee4d29bffe5aa47a9fd5fa68ccd5f4
+distfiles="https://github.com/void-linux/xbps/archive/${_gitrev}.tar.gz"
+checksum=5175370c48752e48f6ba6a1dec72601a753d6037be40738107f5331b78768be5
 
 hostmakedepends="pkg-config"
 checkdepends="kyua"
@@ -48,8 +50,8 @@ post_install() {
 			${DESTDIR}/usr/share/xbps.d/00-repository-main.conf
 		;;
 	esac
-	vlicense COPYING
-	vlicense COPYING.3RDPARTY
+	vlicense LICENSE.md
+	vlicense LICENSE.3RDPARTY
 }
 
 libxbps_package() {

From f206e5b3880fd654d3174dfbd26778247be12816 Mon Sep 17 00:00:00 2001
From: Duncaen <duncaen@voidlinux.org>
Date: Thu, 13 Jun 2019 23:57:27 +0200
Subject: [PATCH 7/8] xbps-src: update for xbps 0.54

---
 xbps-src | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xbps-src b/xbps-src
index 65c45ada56d..25e0eff8254 100755
--- a/xbps-src
+++ b/xbps-src
@@ -416,7 +416,7 @@ setup_distfiles_mirror() {
     done
 }
 
-readonly XBPS_VERSION_REQ="0.46"
+readonly XBPS_VERSION_REQ="0.54"
 readonly XBPS_VERSION=$(xbps-uhelper -V|awk '{print $2}')
 readonly XBPS_SRC_VERSION="113"
 export XBPS_MACHINE=$(xbps-uhelper arch)
@@ -561,8 +561,8 @@ else
     readonly XBPS_LIBEXECDIR=$XBPS_COMMONDIR/xbps-src/libexec
     readonly XBPS_BUILDHELPERDIR=$XBPS_COMMONDIR/build-helper
 fi
-readonly XBPS_FETCH_CMD="xbps-uhelper fetch"
-readonly XBPS_DIGEST_CMD="xbps-uhelper digest"
+readonly XBPS_FETCH_CMD="xbps-fetch"
+readonly XBPS_DIGEST_CMD="xbps-digest"
 readonly XBPS_CMPVER_CMD="xbps-uhelper cmpver"
 
 readonly XBPS_TARGET="$1"

From 35c74885e3677cff6e6b1231d62344f5026b3ccd Mon Sep 17 00:00:00 2001
From: Duncaen <duncaen@voidlinux.org>
Date: Fri, 14 Jun 2019 01:20:26 +0200
Subject: [PATCH 8/8] xbps-src: use xbps-checkvers to find
 {host,check,make,}depends

---
 common/xbps-src/shutils/build_dependencies.sh | 291 +++++++-----------
 1 file changed, 109 insertions(+), 182 deletions(-)

diff --git a/common/xbps-src/shutils/build_dependencies.sh b/common/xbps-src/shutils/build_dependencies.sh
index 55a8ee635cd..834fc5a6827 100644
--- a/common/xbps-src/shutils/build_dependencies.sh
+++ b/common/xbps-src/shutils/build_dependencies.sh
@@ -1,7 +1,14 @@
 # vim: set ts=4 sw=4 et:
 #
+template_pkgvers() {
+    xbps-checkvers -D /void-packages -sm "$@" | \
+        while read -r _depname _deprepover _depver; do
+            echo "${_depname}-${_depver}"
+        done
+}
+
 setup_pkg_depends() {
-    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _depver _replacement
+    local pkg="$1" j _pkgdepname _pkgdep _rpkgname _depname _deprepover _depver _replacement
 
     if [ -n "$pkg" ]; then
         # subpkg
@@ -33,7 +40,8 @@ setup_pkg_depends() {
             if [ -z "${_pkgdepname}" ]; then
                 _pkgdepname="${_replacement}>=0"
             fi
-            run_depends+=" ${_depname}?${_pkgdepname}"
+            # run_depends+=" ${_depname}?${_pkgdepname}"
+            run_depends+=" ${_pkgdepname}"
             #echo "Adding dependency virtual:  ${_depname}?${_pkgdepname}"
         else
             if [ -z "${_pkgdepname}" ]; then
@@ -44,23 +52,7 @@ setup_pkg_depends() {
             run_depends+=" ${_pkgdep}"
         fi
     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
+
 }
 
 # Install a required package dependency, like:
@@ -102,6 +94,42 @@ install_pkg_from_repos() {
     return $rval
 }
 
+install_pkgs_from_repos() {
+    local cross="$1" rval= tmplogf=
+    shift 1
+
+    [ $# -eq 0 ] && return 0
+
+    mkdir -p $XBPS_STATEDIR
+    tmplogf=${XBPS_STATEDIR}/xbps_${XBPS_TARGET_MACHINE}_bdep.log
+
+    if [ -n "$cross" ]; then
+        $XBPS_INSTALL_XCMD -Ayd "$@" >$tmplogf 2>&1
+    else
+        $XBPS_INSTALL_CMD -Ayd "$@" >$tmplogf 2>&1
+    fi
+    rval=$?
+    if [ $rval -ne 0 -a $rval -ne 17 ]; then
+        # 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): package already installed.
+        # ENODEV  (19): package depends on missing dependencies.
+        # ENOTSUP (95): no repositories registered.
+        #
+        [ -z "$XBPS_KEEP_ALL" ] && remove_pkg_autodeps
+        # msg_red "$pkgver: failed to install '$1' dependency! (error $rval)\n"
+        cat $tmplogf
+        msg_error "Please see above for the real error, exiting...\n"
+    fi
+    [ $rval -eq 17 ] && rval=0
+    return $rval
+}
+
+
 #
 # Returns 0 if pkgpattern in $1 is matched against current installed
 # package, 1 if no match and 2 if not installed.
@@ -197,6 +225,7 @@ install_pkg_deps() {
 
     setup_pkg_depends
 
+    
     [ -n "$build_style" ] && style=" [$build_style]"
 
     for s in $build_helper; do
@@ -209,189 +238,84 @@ 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
-            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
+    if [ -n "${hostdepends}" ]; then
+        local -a _hostdepends
+        for i in ${hostdepends}; do
+            _hostdepends+=("$i")
+        done
+        i=0
+        while read -r _depname _deprepover _depver; do
+            _depname=${_hostdepends[$(( i++ ))]}
+            if [ "$_depver" != "$_deprepover" ]; then
+                host_missing_deps+=("${_depname}-${_depver}")
             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
-                fi
+                host_binpkg_deps+=" ${_depname}-${_depver}"
             fi
-        fi
-        host_missing_deps+=("${i}")
-    done
+            host_build_depends+=" ${_depname}-${_depver}"
+        done < <(xbps-checkvers -D /void-packages -sm $(printf "srcpkgs/%s/template\n" ${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
-            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
+    if [ -n "$XBPS_CHECK_PKGS" -a -n "${checkdepends}" ]; then
+        local -a _checkdepends
+        for i in ${checkdepends}; do
+            _checkdepends+=("$i")
+        done
+        i=0
+        while read -r _depname _deprepover _depver; do
+            _depname=${_checkdepends[$(( i++ ))]}
+            if [ "$_depver" != "$_deprepover" ]; then
+                host_missing_deps+=("${_depname}-${_depver}")
             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
+                host_binpkg_deps+=" ${_depname}-${_depver}"
             fi
-        fi
-        check_missing_deps+=("${i}")
-    done
-
+            host_check_depends+=" ${_depname}-${_depver}"
+        done < <(xbps-checkvers -D /void-packages -sm $(printf "srcpkgs/%s/template\n" ${hostcheckdepends}))
+    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 [ -n "${makedepends}" ]; then
+        local -a _makedepends
+        for i in ${makedepends}; do
+            _makedepends+=("$i")
         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)."
-                continue
+        i=0
+        while read -r _depname _deprepover _depver; do
+            _depname=${_makedepends[$(( i++ ))]}
+            if [ "$_depver" != "$_deprepover" ]; then
+                missing_deps+=("${_depname}-${_depver}")
             else
-                echo "   [target] ${i}: unresolved build dependency!"
-                return 1
+                binpkg_deps+=" ${_depname}-${_depver}"
             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"
-                fi
-            fi
-        fi
-        missing_deps+=("${i}")
-    done
+            build_depends+=" ${_depname}-${_depver}"
+        done < <(xbps-checkvers -D /void-packages -sm $(printf "srcpkgs/%s/template\n" ${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
+    if [ -n "${depends}" ]; then
+        local -a _depends
+        for i in ${depends}; do
+            _depends+=("$i")
         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
-                continue
-            else
-                if [ -n "${_curpkg}" ]; then
-                    echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
-                else
-                    echo "   [runtime] ${_realpkg}: not found."
-                fi
-            fi
-            shift 2
-        else
-            if [ -n "${_curpkg}" ]; then
-                echo "   [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
-            else
-                echo "   [runtime] ${_realpkg}: not found."
+        i=0
+        while read -r _depname _deprepover _depver; do
+            _depname=${_depends[$(( i++ ))]}
+            if [ "$_depver" != "$_deprepover" ]; then
+                missing_deps+=("${_depname}-${_depver}")
             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
+            build_depends+=" ${_depname}-${_depver}"
+        done < <(xbps-checkvers -D /void-packages -sm $(printf "srcpkgs/%s/template\n" ${run_depends}))
+    fi
 
     if [ -n "$XBPS_BUILD_ONLY_ONE_PKG" ]; then
            for i in ${host_missing_deps[@]}; do
@@ -408,6 +332,10 @@ install_pkg_deps() {
            done
     fi
 
+    if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
+        return 0
+    fi
+
     # Missing host dependencies, build from srcpkgs.
     for i in ${host_missing_deps[@]}; do
         # packages not found in repos, install from source.
@@ -468,16 +396,15 @@ install_pkg_deps() {
 
     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
+    install_pkgs_from_repos "" ${host_binpkg_deps[@]} ${check_binpkg_deps[@]}
+
 
     for i in ${binpkg_deps[@]}; do
         msg_normal "$pkgver: installing target dependency '$i' ...\n"
-        install_pkg_from_repos "$i" $cross
     done
+    install_pkgs_from_repos "$cross" ${binpkg_deps[@]}
 }
