public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2015-02-24  1:26 Mike Frysinger
  0 siblings, 0 replies; 31+ messages in thread
From: Mike Frysinger @ 2015-02-24  1:26 UTC (permalink / raw
  To: gentoo-commits

commit:     373a921bffef672d0fd9da62dcbca18330a838b8
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 22 19:38:49 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Feb 22 19:40:14 2015 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=373a921b

drop unused "item" member of set logic

This was nominally used by qmerge to hold the SLOT, but we're scrapping
that in favor of proper atoms, so unwind the item entirely.

---
 libq/virtuals.c | 52 +++++++---------------------------------------------
 main.c          |  2 +-
 qlist.c         |  2 +-
 qmerge.c        | 38 ++++++--------------------------------
 qpkg.c          |  2 +-
 qsize.c         |  2 +-
 6 files changed, 17 insertions(+), 81 deletions(-)

diff --git a/libq/virtuals.c b/libq/virtuals.c
index 18663e0..536c622 100644
--- a/libq/virtuals.c
+++ b/libq/virtuals.c
@@ -14,7 +14,6 @@
 /* used to queue a lot of things */
 struct queue_t {
 	char *name;
-	char *item;
 	struct queue_t *next;
 };
 
@@ -38,47 +37,13 @@ append_set(queue *q, queue *ll)
 
 /* add a set to a cache */
 _q_static queue *
-add_set(const char *vv, const char *ss, queue *q)
+add_set(const char *name, queue *q)
 {
-	queue *ll;
-	char *s, *ptr;
-	char *v, *vptr;
-
-	s = xstrdup(ss);
-	v = xstrdup(vv);
-	ptr = xmalloc(strlen(ss));
-	vptr = xmalloc(strlen(vv));
-
-	do {
-		*ptr = 0;
-		*vptr = 0;
-		rmspace(ptr);
-		rmspace(s);
-		rmspace(vptr);
-		rmspace(v);
-
-		ll = xmalloc(sizeof(queue));
-		ll->next = NULL;
-		ll->name = xmalloc(strlen(v) + 1);
-		ll->item = xmalloc(strlen(s) + 1);
-		strcpy(ll->item, s);
-		strcpy(ll->name, v);
-
-		q = append_set(q, ll);
-
-		*v = 0;
-		strcpy(v, vptr);
-		*s = 0;
-		strcpy(s, ptr);
-
-	} while (v[0]);
-
-	free(s);
-	free(ptr);
-	free(v);
-	free(vptr);
-
-	return q;
+	queue *ll = xmalloc(sizeof(*ll));
+	ll->next = NULL;
+	ll->name = xstrdup(name);
+	rmspace(ll->name);
+	return append_set(q, ll);
 }
 
 /* remove a set from a cache. matches ->name and frees name,item */
@@ -96,14 +61,12 @@ del_set(char *s, queue *q, int *ok)
 			if (ll == list) {
 				list = (ll->next);
 				free(ll->name);
-				free(ll->item);
 				free(ll);
 				ll = list;
 
 			} else {
 				old->next = ll->next;
 				free(ll->name);
-				free(ll->item);
 				free(ll);
 				ll = old->next;
 			}
@@ -125,7 +88,6 @@ free_sets(queue *list)
 	while (ll != NULL) {
 		q = ll->next;
 		free(ll->name);
-		free(ll->item);
 		free(ll);
 		ll = q;
 	}
@@ -136,5 +98,5 @@ void print_sets(const queue *list)
 {
 	const queue *ll;
 	for (ll = list; ll != NULL; ll = ll->next)
-		printf("%s -> %s\n", ll->name, ll->item);
+		puts(ll->name);
 }

diff --git a/main.c b/main.c
index c06cf49..1ee8816 100644
--- a/main.c
+++ b/main.c
@@ -1290,7 +1290,7 @@ _q_static queue *get_vdb_atoms(int fullcpv)
 				snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN);
 			}
 			atom_implode(atom);
-			cpf = add_set(buf, slot, cpf);
+			cpf = add_set(buf, cpf);
 		}
 		scandir_free(pf, dfd);
 	}

diff --git a/qlist.c b/qlist.c
index cccea33..d17ba5e 100644
--- a/qlist.c
+++ b/qlist.c
@@ -86,7 +86,7 @@ static char *grab_pkg_umap(q_vdb_pkg_ctx *pkg_ctx)
 	for (i = 1; i < use_argc; i++) {
 		int ok = 0;
 		sets = del_set(use_argv[i], sets, &ok);
-		sets = add_set(use_argv[i], use_argv[i], sets);
+		sets = add_set(use_argv[i], sets);
 	}
 	umap[0] = '\0'; /* reset the buffer */
 	for (ll = sets; ll != NULL; ll = ll->next) {

diff --git a/qmerge.c b/qmerge.c
index b2ef9a7..7556b4b 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -567,7 +567,7 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
 #if 0		/* We filter out "dir" as it's generally unnecessary cruft */
 			/* syntax: dir dirname */
 			fprintf(contents, "dir %s\n", cpath);
-			*objs = add_set(cpath, "", *objs);
+			*objs = add_set(cpath, *objs);
 			qprintf("%s>>>%s %s%s%s/\n", GREEN, NORM, DKBLUE, cpath, NORM);
 #endif
 
@@ -614,7 +614,7 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
 				dname = name;
 				qprintf("%s>>>%s %s\n", GREEN, NORM, cpath);
 			}
-			*objs = add_set(cpath, "", *objs);
+			*objs = add_set(cpath, *objs);
 
 			/* First try fast path -- src/dst are same device */
 			if (renameat(subfd_src, dname, subfd_dst, name) == 0)
@@ -690,7 +690,7 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
 			/* syntax: sym src -> dst mtime */
 			fprintf(contents, "sym %s -> %s %"PRIu64"u\n", cpath, sym, (uint64_t)st.st_mtime);
 			qprintf("%s>>>%s %s%s -> %s%s\n", GREEN, NORM, CYAN, cpath, sym, NORM);
-			*objs = add_set(cpath, "", *objs);
+			*objs = add_set(cpath, *objs);
 
 			/* Make it in the dest tree */
 			if (symlinkat(sym, subfd_dst, name)) {
@@ -1241,15 +1241,6 @@ _q_static int match_pkg(queue *ll, const struct pkg_t *pkg)
 	if (match)
 		goto match_done;
 
-	if (ll->item) {
-		depend_atom *subatom = atom_explode(ll->name);
-		if (subatom == NULL)
-			goto match_done;
-		if (strcmp(atom->PN, subatom->PN) == 0)
-			match = 1;
-		atom_implode(subatom);
-	}
-
 match_done:
 	atom_implode(atom);
 
@@ -1809,23 +1800,6 @@ parse_packages(queue *todo)
 }
 
 _q_static queue *
-qmerge_add_set_atom(char *satom, queue *set)
-{
-	char *p;
-	const char *slot = "";
-
-	if (!uninstall) {
-		if ((p = strchr(satom, ':')) != NULL) {
-			*p = 0;
-			slot = p + 1;
-		} else
-			slot = "0";
-	}
-
-	return add_set(satom, slot, set);
-}
-
-_q_static queue *
 qmerge_add_set_file(const char *dir, const char *file, queue *set)
 {
 	FILE *fp;
@@ -1846,7 +1820,7 @@ qmerge_add_set_file(const char *dir, const char *file, queue *set)
 	buf = NULL;
 	while (getline(&buf, &buflen, fp) != -1) {
 		rmspace(buf);
-		set = qmerge_add_set_atom(buf, set);
+		set = add_set(buf, set);
 	}
 	free(buf);
 
@@ -1868,7 +1842,7 @@ qmerge_add_set_system(void *data, char *buf)
 
 	s = buf;
 	if (*s == '*')
-		set = add_set(s + 1, "", set);
+		set = add_set(s + 1, set);
 	else if (s[0] == '-' && s[1] == '*') {
 		int ok;
 		set = del_set(s + 2, set, &ok);
@@ -1892,7 +1866,7 @@ qmerge_add_set(char *buf, queue *set)
 	else if (buf[0] == '@')
 		return qmerge_add_set_file("/etc/portage", buf+1, set);
 	else
-		return qmerge_add_set_atom(buf, set);
+		return add_set(buf, set);
 }
 
 _q_static int

diff --git a/qpkg.c b/qpkg.c
index 4a5d9fd..5b63ec2 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -157,7 +157,7 @@ int qpkg_clean(char *dirp)
 
 				/* num_all_bytes will be off when pretend and eclean are enabled together */
 				/* vdb = del_set(buf, vdb, &i); */
-				vdb = add_set(buf, "0", vdb);
+				vdb = add_set(buf, vdb);
 			}
 
 			free(buf);

diff --git a/qsize.c b/qsize.c
index 83ad8b1..486edcf 100644
--- a/qsize.c
+++ b/qsize.c
@@ -65,7 +65,7 @@ int qsize_main(int argc, char **argv)
 		case 'm': disp_units = MEGABYTE; str_disp_units = "MiB"; break;
 		case 'k': disp_units = KILOBYTE; str_disp_units = "KiB"; break;
 		case 'b': disp_units = 1; str_disp_units = "bytes"; break;
-		case 'i': ignore_regexp = add_set(optarg, optarg, ignore_regexp); break;
+		case 'i': ignore_regexp = add_set(optarg, ignore_regexp); break;
 		}
 	}
 	if ((argc == optind) && !search_all)


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2015-11-28  2:44 Mike Frysinger
  0 siblings, 0 replies; 31+ messages in thread
From: Mike Frysinger @ 2015-11-28  2:44 UTC (permalink / raw
  To: gentoo-commits

commit:     7a07798e6a7ce183ed53e6ad19d0c3a7205aae52
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 27 23:19:05 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Nov 27 23:19:05 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7a07798e

main: optimize portdir setup slightly

 libq/xarray.c | 6 ++++--
 main.c        | 9 +++------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/libq/xarray.c b/libq/xarray.c
index 56f04da..339d759 100644
--- a/libq/xarray.c
+++ b/libq/xarray.c
@@ -24,11 +24,13 @@ typedef struct {
 #define array_cnt(arr) (arr)->num
 #define DECLARE_ARRAY(arr) array_t _##arr = array_init_decl, *arr = &_##arr
 
-static void xarraypush(array_t *arr, const void *ele, size_t ele_len)
+static void *xarraypush(array_t *arr, const void *ele, size_t ele_len)
 {
+	void *nele;
 	size_t n = arr->num++;
 	arr->eles = xrealloc_array(arr->eles, arr->num, sizeof(ele));
-	arr->eles[n] = xmemdup(ele, ele_len);
+	arr->eles[n] = nele = xmemdup(ele, ele_len);
+	return nele;
 }
 #define xarraypush_str(arr, ele) xarraypush(arr, ele, strlen(ele) + 1 /*NUL*/)
 

diff --git a/main.c b/main.c
index 42a3f26..9361b98 100644
--- a/main.c
+++ b/main.c
@@ -445,12 +445,9 @@ static void read_one_repos_conf(const char *repos_conf)
 		xasprintf(&conf, "%s:location", repo);
 		path = iniparser_getstring(dict, conf, NULL);
 		if (path) {
-			if (main_repo && !strcmp(repo, main_repo)) {
-				free(portdir);
-				portdir = xstrdup(path);
-			}
-
-			xarraypush_str(overlays, path);
+			void *ele = xarraypush_str(overlays, path);
+			if (main_repo && !strcmp(repo, main_repo))
+				portdir = ele;
 		}
 		free(conf);
 	}


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2016-11-26 23:17 Mike Frysinger
  0 siblings, 0 replies; 31+ messages in thread
From: Mike Frysinger @ 2016-11-26 23:17 UTC (permalink / raw
  To: gentoo-commits

commit:     b1558916d2ca76d7cd4c81248d5b220aaa46a728
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 26 23:15:22 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Nov 26 23:15:22 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b1558916

--quiet: do not suppress fatal error messages

Rework how we write to stderr so that --quiet will automatically
suppress warnings but not any fatal error messages.

URL: https://bugs.gentoo.org/585248
Reported-by: Ulrich Müller <ulm <AT> gentoo.org>

 libq/libq.h |  4 +++-
 main.c      | 34 +++++++++++++++++-----------------
 qdepends.c  |  2 +-
 3 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/libq/libq.h b/libq/libq.h
index 5cc3689..6a74a48 100644
--- a/libq/libq.h
+++ b/libq/libq.h
@@ -1,9 +1,10 @@
 /* we need the space before the last comma or we trigger a bug in gcc-2 :( */
+FILE *warnout;
 #if defined OPTIMIZE_FOR_SIZE && (OPTIMIZE_FOR_SIZE > 1)
 #define warn(fmt, args...)
 #else
 #define warn(fmt, args...) \
-	fprintf(stderr, _("%s%s%s: " fmt "\n"), RED, argv0, NORM , ## args)
+	fprintf(warnout, _("%s%s%s: " fmt "\n"), RED, argv0, NORM , ## args)
 #endif
 #define warnf(fmt, args...) warn("%s%s()%s: " fmt, YELLOW, __func__, NORM , ## args)
 #define warnl(fmt, args...) warn("%s%i()%s: " fmt, YELLOW, __LINE__, NORM , ## args)
@@ -11,6 +12,7 @@
 #define warnfp(fmt, args...) warnf(fmt ": %s" , ## args , strerror(errno))
 #define _err(wfunc, fmt, args...) \
 	do { \
+	warnout = stderr; \
 	wfunc(fmt , ## args); \
 	exit(EXIT_FAILURE); \
 	} while (0)

diff --git a/main.c b/main.c
index 76e5bad..8e0e2ad 100644
--- a/main.c
+++ b/main.c
@@ -107,7 +107,7 @@ void no_colors(void)
 #define COMMON_GETOPTS_CASES(applet) \
 	case 0x1: portroot = optarg; break; \
 	case 'v': ++verbose; break; \
-	case 'q': ++quiet; if (freopen("/dev/null", "w", stderr)) { /* ignore errors */ } break; \
+	case 'q': ++quiet; warnout = fopen("/dev/null", "we"); break; \
 	case 'V': version_barf(); break; \
 	case 'h': applet ## _usage(EXIT_SUCCESS); break; \
 	case 'C': no_colors(); break; \
@@ -121,31 +121,31 @@ static void usage(int status, const char *flags, struct option const opts[],
 	const char a_arg[] = "<arg>";
 	size_t a_arg_len = strlen(a_arg) + 1;
 	size_t i, optlen;
+	FILE *fp = status == EXIT_SUCCESS ? stdout : warnout;
 
-	if (status != EXIT_SUCCESS)
-		dup2(STDERR_FILENO, STDOUT_FILENO);
 	if (blabber == 0) {
-		printf("%sUsage:%s %sq%s %s<applet> <args>%s  : %s"
+		fprintf(fp, "%sUsage:%s %sq%s %s<applet> <args>%s  : %s"
 			"invoke a portage utility applet\n\n", GREEN,
 			NORM, YELLOW, NORM, DKBLUE, RED, NORM);
-		printf("%sCurrently defined applets:%s\n", GREEN, NORM);
+		fprintf(fp, "%sCurrently defined applets:%s\n", GREEN, NORM);
 		for (i = 0; applets[i].desc; ++i)
 			if (applets[i].func)
-				printf(" %s%8s%s %s%-16s%s%s:%s %s\n",
+				fprintf(fp, " %s%8s%s %s%-16s%s%s:%s %s\n",
 					YELLOW, applets[i].name, NORM,
 					DKBLUE, applets[i].opts, NORM,
 					RED, NORM, _(applets[i].desc));
 	} else if (blabber > 0) {
-		printf("%sUsage:%s %s%s%s [opts] %s%s%s %s:%s %s\n",
+		fprintf(fp, "%sUsage:%s %s%s%s [opts] %s%s%s %s:%s %s\n",
 			GREEN, NORM,
 			YELLOW, applets[blabber].name, NORM,
 			DKBLUE, applets[blabber].opts, NORM,
 			RED, NORM, _(applets[blabber].desc));
 		if (desc)
-			printf("\n%s\n", desc);
+			fprintf(fp, "\n%s\n", desc);
 	}
 	if (module_name != NULL)
-		printf("%sLoaded module:%s\n%s%8s%s %s<args>%s\n", GREEN, NORM, YELLOW, module_name, NORM, DKBLUE, NORM);
+		fprintf(fp, "%sLoaded module:%s\n%s%8s%s %s<args>%s\n",
+			GREEN, NORM, YELLOW, module_name, NORM, DKBLUE, NORM);
 
 	/* Prescan the --long opt length to auto-align. */
 	optlen = 0;
@@ -156,23 +156,23 @@ static void usage(int status, const char *flags, struct option const opts[],
 		optlen = MAX(l, optlen);
 	}
 
-	printf("\n%sOptions:%s -[%s]\n", GREEN, NORM, flags);
+	fprintf(fp, "\n%sOptions:%s -[%s]\n", GREEN, NORM, flags);
 	for (i = 0; opts[i].name; ++i) {
 		/* this assert is a life saver when adding new applets. */
 		assert(help[i] != NULL);
 
 		/* first output the short flag if it has one */
 		if (opts[i].val > '~' || opts[i].val < ' ')
-			printf("      ");
+			fprintf(fp, "      ");
 		else
-			printf("  -%c, ", opts[i].val);
+			fprintf(fp, "  -%c, ", opts[i].val);
 
 		/* then the long flag + help text */
 		if (opts[i].has_arg == no_argument)
-			printf("--%-*s %s*%s %s\n", (int)optlen, opts[i].name,
+			fprintf(fp, "--%-*s %s*%s %s\n", (int)optlen, opts[i].name,
 				RED, NORM, _(help[i]));
 		else
-			printf("--%s %s%s%s%*s %s*%s %s\n",
+			fprintf(fp, "--%s %s%s%s%*s %s*%s %s\n",
 				opts[i].name,
 				DKBLUE, (opts[i].has_arg == a_argument ? a_arg : opt_arg), NORM,
 				(int)(optlen - strlen(opts[i].name) - a_arg_len), "",
@@ -985,9 +985,8 @@ initialize_flat(const char *overlay, int cache_type, bool force)
 				return cache_file;
 	}
 
-	if (!quiet)
-		warn("Updating ebuild %scache in %s ... ",
-			cache_type == CACHE_EBUILD ? "" : "meta", overlay);
+	warn("Updating ebuild %scache in %s ... ",
+		cache_type == CACHE_EBUILD ? "" : "meta", overlay);
 
 	count = frac = secs = 0;
 
@@ -1421,6 +1420,7 @@ void cleanup(void)
 int main(int argc, char **argv)
 {
 	struct stat st;
+	warnout = stderr;
 	IF_DEBUG(init_coredumps());
 	argv0 = argv[0];
 

diff --git a/qdepends.c b/qdepends.c
index 7337c61..3c90863 100644
--- a/qdepends.c
+++ b/qdepends.c
@@ -596,7 +596,7 @@ int qdepends_main(int argc, char **argv)
 		atom_implode(atom);
 	xarrayfree_int(atoms);
 
-	if (!ret && !quiet)
+	if (!ret)
 		warn("no matches found for your query");
 	return ret ? EXIT_SUCCESS : EXIT_FAILURE;
 }


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2016-12-29  2:25 Mike Frysinger
  0 siblings, 0 replies; 31+ messages in thread
From: Mike Frysinger @ 2016-12-29  2:25 UTC (permalink / raw
  To: gentoo-commits

commit:     8f6a879b16fc664b03c361ae203def52220d0cb9
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 28 22:54:08 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Wed Dec 28 22:54:08 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8f6a879b

add cleanup logic to handle specific leaks

There's a few code paths that we leak resources because we know
we're exiting (soon).  Add some logic to avoid false positives.

 libq/libq.h |  4 ++++
 main.c      |  6 ++++--
 main.h      | 13 +++++++++++++
 q.c         |  8 ++++----
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/libq/libq.h b/libq/libq.h
index 6a74a48..94254e1 100644
--- a/libq/libq.h
+++ b/libq/libq.h
@@ -12,6 +12,10 @@ FILE *warnout;
 #define warnfp(fmt, args...) warnf(fmt ": %s" , ## args , strerror(errno))
 #define _err(wfunc, fmt, args...) \
 	do { \
+	if (USE_CLEANUP) { \
+		if (warnout != stderr) \
+			fclose(warnout); \
+	} \
 	warnout = stderr; \
 	wfunc(fmt , ## args); \
 	exit(EXIT_FAILURE); \

diff --git a/main.c b/main.c
index 543ac36..9921363 100644
--- a/main.c
+++ b/main.c
@@ -1102,13 +1102,15 @@ void reinitialize_as_needed(void)
 	if (reinitialize)
 		array_for_each(overlays, n, overlay) {
 			ret = initialize_flat(overlay, CACHE_EBUILD, true);
-			IF_DEBUG(free((void *)ret));
+			if (USE_CLEANUP)
+				free((void *)ret);
 		}
 
 	if (reinitialize_metacache)
 		array_for_each(overlays, n, overlay) {
 			ret = initialize_flat(overlay, CACHE_METADATA, true);
-			IF_DEBUG(free((void *)ret));
+			if (USE_CLEANUP)
+				free((void *)ret);
 		}
 }
 

diff --git a/main.h b/main.h
index 6848a9f..d3df8b1 100644
--- a/main.h
+++ b/main.h
@@ -95,6 +95,19 @@
 # define IF_DEBUG(x)
 #endif
 
+#undef USE_CLEANUP
+/* LSAN (Leak Sanitizer) will complain about things we leak. */
+#ifdef __SANITIZE_ADDRESS__
+# define USE_CLEANUP 1
+#endif
+/* Coverity catches some things we leak on purpose. */
+#ifdef __COVERITY__
+# define USE_CLEANUP 1
+#endif
+#ifndef USE_CLEANUP
+# define USE_CLEANUP 0
+#endif
+
 #define GETOPT_LONG(A, a, ex) \
 	getopt_long(argc, argv, ex A ## _FLAGS, a ## _long_opts, NULL)
 

diff --git a/q.c b/q.c
index 6ee9aef..ea1fb4d 100644
--- a/q.c
+++ b/q.c
@@ -87,8 +87,8 @@ int q_main(int argc, char **argv)
 		case 'm':
 			if (optarg) {
 				const char *path = initialize_flat(optarg, CACHE_METADATA, true);
-				if (path) { /* silence warning */ }
-				IF_DEBUG(free((void *)path));
+				if (USE_CLEANUP)
+					free((void *)path);
 				reinitialize_metacache = -1;
 			} else
 				reinitialize_metacache = 1;
@@ -96,8 +96,8 @@ int q_main(int argc, char **argv)
 		case 'r':
 			if (optarg) {
 				const char *path = initialize_flat(optarg, CACHE_EBUILD, true);
-				if (path) { /* silence warning */ }
-				IF_DEBUG(free((void *)path));
+				if (USE_CLEANUP)
+					free((void *)path);
 				reinitialize = -1;
 			} else
 				reinitialize = 1;


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2018-03-23 11:56 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2018-03-23 11:56 UTC (permalink / raw
  To: gentoo-commits

commit:     beb68b28d4694aa576d0e06fc37deb31d83cef80
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Mar 23 11:55:26 2018 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Mar 23 11:55:26 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=beb68b28

getline: fix comparison of integers of different signs

Just use an int to store getline return, then ensure it is positive,
such that a cast to size_t is guaranteed to result in the same value.

 libq/profile.c |  7 ++++---
 qcache.c       | 14 ++++++++------
 qlop.c         | 17 ++++++++++-------
 qmerge.c       | 14 ++++++++------
 qsearch.c      | 12 +++++++-----
 quse.c         | 29 ++++++++++++++++++-----------
 6 files changed, 55 insertions(+), 38 deletions(-)

diff --git a/libq/profile.c b/libq/profile.c
index c954ba6..ad631a1 100644
--- a/libq/profile.c
+++ b/libq/profile.c
@@ -6,7 +6,8 @@ q_profile_walk_at(int dir_fd, const char *dir, const char *file,
 {
 	FILE *fp;
 	int subdir_fd, fd;
-	size_t buflen, linelen;
+	int linelen;
+	size_t buflen;
 	char *buf;
 
 	/* Pop open this profile dir */
@@ -46,10 +47,10 @@ q_profile_walk_at(int dir_fd, const char *dir, const char *file,
 	}
 
 	buf = NULL;
-	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
+	while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
 		char *s;
 
-		rmspace_len(buf, linelen);
+		rmspace_len(buf, (size_t)linelen);
 
 		s = strchr(buf, '#');
 		if (s)

diff --git a/qcache.c b/qcache.c
index 7cd100e..0082e5b 100644
--- a/qcache.c
+++ b/qcache.c
@@ -220,7 +220,8 @@ qcache_read_cache_file(const char *filename)
 	char *buf;
 	FILE *f;
 	portage_cache *ret = NULL;
-	size_t len, buflen, linelen;
+	int linelen;
+	size_t len, buflen;
 
 	if ((f = fopen(filename, "r")) == NULL)
 		goto err;
@@ -234,8 +235,8 @@ qcache_read_cache_file(const char *filename)
 	len = sizeof(*ret) + s.st_size + 1;
 	ret = xzalloc(len);
 
-	while ((linelen = getline(&buf, &buflen, f)) != -1) {
-		rmspace_len(buf, linelen);
+	while ((linelen = getline(&buf, &buflen, f)) >= 0) {
+		rmspace_len(buf, (size_t)linelen);
 
 		if (strncmp(buf, "DEPEND=", 7) == 0)
 			ret->DEPEND = xstrdup(buf + 7);
@@ -868,7 +869,8 @@ qcache_load_arches(const char *overlay)
 {
 	FILE *fp;
 	char *filename, *s;
-	size_t buflen, linelen;
+	int linelen;
+	size_t buflen;
 	char *buf;
 
 	xasprintf(&filename, "%s/profiles/arch.list", overlay);
@@ -879,8 +881,8 @@ qcache_load_arches(const char *overlay)
 	archlist_count = 0;
 	arch_longest_len = 0;
 	buf = NULL;
-	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
-		rmspace_len(buf, linelen);
+	while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
+		rmspace_len(buf, (size_t)linelen);
 
 		if ((s = strchr(buf, '#')) != NULL)
 			*s = '\0';

diff --git a/qlop.c b/qlop.c
index f0c35b7..5be2ddd 100644
--- a/qlop.c
+++ b/qlop.c
@@ -232,7 +232,8 @@ show_emerge_history(int listflag, array_t *atoms, const char *logfile,
                     time_t start_time, time_t end_time)
 {
 	FILE *fp;
-	size_t buflen, linelen;
+	int linelen;
+	size_t buflen;
 	char *buf, merged;
 	char *p, *q;
 	bool showit;
@@ -246,16 +247,17 @@ show_emerge_history(int listflag, array_t *atoms, const char *logfile,
 	}
 
 	buf = NULL;
-	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
+	while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
 		if (linelen < 30)
 			continue;
 
-		rmspace_len(buf, linelen);
+		rmspace_len(buf, (size_t)linelen);
 		if ((p = strchr(buf, ':')) == NULL)
 			continue;
 		*p = 0;
 		q = p + 3;
-		/* Make sure there's leading white space and not a truncated string. #573106 */
+		/* Make sure there's leading white space and not a truncated
+		 * string. #573106 */
 		if (p[1] != ' ' || p[2] != ' ')
 			continue;
 
@@ -331,7 +333,8 @@ static void
 show_sync_history(const char *logfile, time_t start_time, time_t end_time)
 {
 	FILE *fp;
-	size_t buflen, linelen;
+	int linelen;
+	size_t buflen;
 	char *buf, *p;
 	time_t t;
 
@@ -342,7 +345,7 @@ show_sync_history(const char *logfile, time_t start_time, time_t end_time)
 
 	buf = NULL;
 	/* Just find the finish lines. */
-	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
+	while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
 		/* This cuts out like ~10% of the log. */
 		if (linelen < 35)
 			continue;
@@ -356,7 +359,7 @@ show_sync_history(const char *logfile, time_t start_time, time_t end_time)
 			continue;
 		p += 19;
 
-		rmspace_len(buf, linelen);
+		rmspace_len(buf, (size_t)linelen);
 
 		t = (time_t)atol(buf);
 		if (t < start_time || t > end_time)

diff --git a/qmerge.c b/qmerge.c
index 1f75acc..960a9a4 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1653,7 +1653,8 @@ static int
 parse_packages(queue *todo)
 {
 	FILE *fp;
-	size_t buflen, linelen;
+	int linelen;
+	size_t buflen;
 	char *buf, *p;
 	struct pkg_t Pkg;
 	depend_atom *pkg_atom;
@@ -1665,8 +1666,8 @@ parse_packages(queue *todo)
 	repo[0] = '\0';
 
 	/* First consume the header with the common data. */
-	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
-		rmspace_len(buf, linelen);
+	while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
+		rmspace_len(buf, (size_t)linelen);
 		if (buf[0] == '\0')
 			break;
 
@@ -1785,7 +1786,8 @@ static queue *
 qmerge_add_set_file(const char *dir, const char *file, queue *set)
 {
 	FILE *fp;
-	size_t buflen, linelen;
+	int linelen;
+	size_t buflen;
 	char *buf, *fname;
 
 	/* Find the file to read */
@@ -1800,8 +1802,8 @@ qmerge_add_set_file(const char *dir, const char *file, queue *set)
 
 	/* Load each entry */
 	buf = NULL;
-	while ((linelen = getline(&buf, &buflen, fp)) != -1) {
-		rmspace_len(buf, linelen);
+	while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
+		rmspace_len(buf, (size_t)linelen);
 		set = add_set(buf, set);
 	}
 	free(buf);

diff --git a/qsearch.c b/qsearch.c
index 1ebfccf..c2b2ebe 100644
--- a/qsearch.c
+++ b/qsearch.c
@@ -101,8 +101,9 @@ qsearch_ebuild_ebuild(int overlay_fd, const char *ebuild, const char *search_me,
 	}
 
 	char *buf = NULL;
-	size_t buflen, linelen;
-	while ((linelen = getline(&buf, &buflen, ebuildfp)) != -1) {
+	int linelen;
+	size_t buflen;
+	while ((linelen = getline(&buf, &buflen, ebuildfp)) >= 0) {
 		if (linelen <= search_len)
 			continue;
 		if (strncmp(buf, search_var, search_len) != 0)
@@ -194,10 +195,11 @@ int qsearch_main(int argc, char **argv)
 			continue;
 		}
 
-		size_t buflen, linelen;
+		int linelen;
+		size_t buflen;
 		char *buf = NULL;
-		while ((linelen = getline(&buf, &buflen, fp)) != -1) {
-			rmspace_len(buf, linelen);
+		while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
+			rmspace_len(buf, (size_t)linelen);
 			if (!buf[0])
 				continue;
 

diff --git a/quse.c b/quse.c
index 81d99d8..ea8a326 100644
--- a/quse.c
+++ b/quse.c
@@ -82,7 +82,8 @@ static void
 quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, char **argv)
 {
 #define NUM_SEARCH_FILES ARRAY_SIZE(search_files)
-	size_t buflen, linelen;
+	int linelen;
+	size_t buflen;
 	char *buf, *p;
 	unsigned int i, f;
 	size_t s;
@@ -110,8 +111,8 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
 			if (fp[f] == NULL)
 				continue;
 
-			while ((linelen = getline(&buf, &buflen, fp[f])) != -1) {
-				rmspace_len(buf, linelen);
+			while ((linelen = getline(&buf, &buflen, fp[f])) >= 0) {
+				rmspace_len(buf, (size_t)linelen);
 				if (buf[0] == '#' || buf[0] == '\0')
 					continue;
 
@@ -119,7 +120,9 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
 					case 0: /* Global use.desc */
 						if (!strncmp(buf, argv[i], s))
 							if (buf[s] == ' ' && buf[s + 1] == '-') {
-								printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf + s + 3);
+								printf(" %sglobal%s:%s%s%s: %s\n",
+										BOLD, NORM, BLUE, argv[i], NORM,
+										buf + s + 3);
 								goto skip_file;
 							}
 						break;
@@ -131,14 +134,17 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
 						if (!strncmp(p, argv[i], s)) {
 							if (p[s] == ' ' && p[s + 1] == '-') {
 								*p = '\0';
-								printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p + s + 3);
+								printf(" %slocal%s:%s%s%s:%s%s%s %s\n",
+										BOLD, NORM, BLUE, argv[i], NORM,
+										BOLD, buf, NORM, p + s + 3);
 							}
 						}
 						break;
 
 					case 2: /* Architectures arch.list */
 						if (!strcmp(buf, argv[i])) {
-							printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
+							printf(" %sarch%s:%s%s%s: %s architecture\n",
+									BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
 							goto skip_file;
 						}
 						break;
@@ -191,8 +197,8 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
 		/* Chop the trailing .desc for better display */
 		*p = '\0';
 
-		while ((linelen = getline(&buf, &buflen, fp[0])) != -1) {
-			rmspace_len(buf, linelen);
+		while ((linelen = getline(&buf, &buflen, fp[0])) >= 0) {
+			rmspace_len(buf, (size_t)linelen);
 			if (buf[0] == '#' || buf[0] == '\0')
 				continue;
 
@@ -231,7 +237,8 @@ int quse_main(int argc, char **argv)
 	char buf1[_Q_PATH_MAX];
 	char buf2[_Q_PATH_MAX];
 
-	size_t ebuildlen, linelen;
+	int linelen;
+	size_t ebuildlen;
 	char *ebuild;
 
 	const char *search_var = NULL;
@@ -279,11 +286,11 @@ int quse_main(int argc, char **argv)
 		int overlay_fd = open(overlay, O_RDONLY|O_CLOEXEC|O_PATH);
 
 		ebuild = NULL;
-		while ((linelen = getline(&ebuild, &ebuildlen, fp)) != -1) {
+		while ((linelen = getline(&ebuild, &ebuildlen, fp)) >= 0) {
 			FILE *newfp;
 			int fd;
 
-			rmspace_len(ebuild, linelen);
+			rmspace_len(ebuild, (size_t)linelen);
 
 			fd = openat(overlay_fd, ebuild, O_RDONLY|O_CLOEXEC);
 			if (fd < 0)


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-03-09 18:58 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-03-09 18:58 UTC (permalink / raw
  To: gentoo-commits

commit:     affdba842a41c49b71911109272186acf36cfd8a
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Mar  9 18:55:47 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Mar  9 18:58:23 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=affdba84

libq: introduce set to replace virtuals (queue)

The virtuals file contained some queue functions which actually were
list functions.  Replaced this with a proper set, which hash backend to
speed up many search operations.  Changed throughout the code to use
more efficient path.

While at it, merge xstrdup wrappers in xmalloc, and use wrappers more
consistently.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 .depend         |  18 ++---
 Makefile.am     |   3 +-
 TODO.md         |   3 +-
 libq/basename.c |   3 +-
 libq/libq.c     |  12 ++-
 libq/rmspace.c  |   1 -
 libq/set.c      | 239 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 libq/virtuals.c | 120 ----------------------------
 libq/xmalloc.c  |  24 ++++--
 libq/xstrdup.c  |  53 -------------
 main.c          |  17 ++--
 qcache.c        |  81 +++++++++++--------
 qlist.c         |   2 -
 qmerge.c        | 120 ++++++++++++++++------------
 qpkg.c          |  58 +++++++-------
 15 files changed, 438 insertions(+), 316 deletions(-)

diff --git a/.depend b/.depend
index f823923..d5d2228 100644
--- a/.depend
+++ b/.depend
@@ -1,10 +1,10 @@
 main.o: main.c porting.h main.h libq/libq.c libq/busybox.h libq/i18n.h \
- libq/libq.h libq/colors.c libq/xmalloc.c libq/xstrdup.c libq/xasprintf.c \
- libq/hash_fd.c libq/md5_sha1_sum.c libq/human_readable.c libq/rmspace.c \
- libq/compat.c libq/copy_file.c libq/safe_io.c libq/xchdir.c \
- libq/xmkdir.c libq/xregex.c libq/xsystem.c libq/xarray.c \
- libq/atom_explode.c libq/atom_compare.c libq/basename.c libq/scandirat.c \
- libq/prelink.c libq/profile.c libq/vdb.c libq/vdb_get_next_dir.c \
- libq/virtuals.c applets.h include_applets.h q.c qcheck.c qdepends.c \
- qfile.c qlist.c qlop.c qsearch.c qsize.c qtbz2.c quse.c qxpak.c qpkg.c \
- qgrep.c qatom.c qmerge.c qcache.c qtegrity.c
+ libq/libq.h libq/colors.c libq/xmalloc.c libq/xasprintf.c libq/hash_fd.c \
+ libq/md5_sha1_sum.c libq/human_readable.c libq/rmspace.c libq/compat.c \
+ libq/copy_file.c libq/safe_io.c libq/xchdir.c libq/xmkdir.c \
+ libq/xregex.c libq/xsystem.c libq/xarray.c libq/atom_explode.c \
+ libq/atom_compare.c libq/basename.c libq/scandirat.c libq/prelink.c \
+ libq/profile.c libq/vdb.c libq/vdb_get_next_dir.c libq/set.c applets.h \
+ include_applets.h q.c qcheck.c qdepends.c qfile.c qlist.c qlop.c \
+ qsearch.c qsize.c qtbz2.c quse.c qxpak.c qpkg.c qgrep.c qatom.c qmerge.c \
+ qcache.c qtegrity.c

diff --git a/Makefile.am b/Makefile.am
index db20879..2e6f985 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -119,16 +119,15 @@ EXTRA_DIST += \
 	libq/rmspace.c \
 	libq/safe_io.c \
 	libq/scandirat.c \
+	libq/set.c \
 	libq/vdb.c \
 	libq/vdb_get_next_dir.c \
-	libq/virtuals.c \
 	libq/xarray.c \
 	libq/xasprintf.c \
 	libq/xchdir.c \
 	libq/xmalloc.c \
 	libq/xmkdir.c \
 	libq/xregex.c \
-	libq/xstrdup.c \
 	libq/xsystem.c \
 	main.c \
 	main.h \

diff --git a/TODO.md b/TODO.md
index 24e5eca..31d916d 100644
--- a/TODO.md
+++ b/TODO.md
@@ -11,7 +11,8 @@
 
 - standardize/unify/clean up misc handling of colors
 
-- speed up queue structure ... append walks the whole list
+- remove odd rmspace for each string in libq/set.c (allows a lot less
+  malloc/frees)
 
 - equiv of `equery m` (metadata)
 

diff --git a/libq/basename.c b/libq/basename.c
index dcf3cce..2a3b2e6 100644
--- a/libq/basename.c
+++ b/libq/basename.c
@@ -1,8 +1,9 @@
 /*
- * Copyright 2014 Gentoo Foundation
+ * Copyright 2014-2019 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  */
 
+/* our own basename which does not modify its input */
 static const char *_basename(const char *filename)
 {
 	const char *p = strrchr(filename, '/');

diff --git a/libq/libq.c b/libq/libq.c
index 28fe5d1..a9e5b6a 100644
--- a/libq/libq.c
+++ b/libq/libq.c
@@ -1,3 +1,12 @@
+/*
+ * Copyright 2005-2018 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ *
+ * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
+ * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
+ * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
+ */
+
 #if defined(__linux__)
 # include <endian.h>
 # include <byteswap.h>
@@ -11,7 +20,6 @@
 #include "libq.h"
 #include "colors.c"
 #include "xmalloc.c"
-#include "xstrdup.c"
 #include "xasprintf.c"
 #include "hash_fd.c"
 #include "md5_sha1_sum.c"
@@ -38,5 +46,5 @@
 # include "profile.c"
 # include "vdb.c"
 # include "vdb_get_next_dir.c"
-# include "virtuals.c"
+# include "set.c"
 #endif

diff --git a/libq/rmspace.c b/libq/rmspace.c
index 40c3808..3159b08 100644
--- a/libq/rmspace.c
+++ b/libq/rmspace.c
@@ -7,7 +7,6 @@
  * Copyright 2019-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-
 /* remove leading/trailing extraneous white space */
 static char *rmspace_len(char *s, size_t len)
 {

diff --git a/libq/set.c b/libq/set.c
new file mode 100644
index 0000000..68799fe
--- /dev/null
+++ b/libq/set.c
@@ -0,0 +1,239 @@
+/*
+ * Copyright 2005-2019 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ *
+ * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
+ * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
+ * Copyright 2019-     Fabian Groffen  - <grobian@gentoo.org>
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef struct elem_t elem;
+typedef struct set_t set;
+
+struct elem_t {
+	char *name;
+	unsigned int hash;  /* FNV1a32 */
+	elem *next;
+};
+
+#define _SET_HASH_SIZE 128
+struct set_t {
+	elem *buckets[_SET_HASH_SIZE];
+	size_t len;
+};
+
+static unsigned int
+fnv1a32(char *s)
+{
+	unsigned int ret = 2166136261UL;
+	for (; *s != '\0'; s++)
+		ret = (ret ^ (unsigned int)*s) * 16777619;
+	return ret;
+}
+
+/* create a set */
+static set *
+create_set(void)
+{
+	return xzalloc(sizeof(set));
+}
+
+/* add elem to a set (unpure: could add duplicates) */
+static set *
+add_set(const char *name, set *q)
+{
+	int pos;
+	elem *ll = xmalloc(sizeof(*ll));
+	elem *w;
+
+	if (q == NULL)
+		q = create_set();
+
+	ll->next = NULL;
+	ll->name = xstrdup(name);
+	rmspace(ll->name);
+	ll->hash = fnv1a32(ll->name);
+
+	pos = ll->hash % _SET_HASH_SIZE;
+	if (q->buckets[pos] == NULL) {
+		q->buckets[pos] = ll;
+	} else {
+		for (w = q->buckets[pos]; w->next != NULL; w = w->next)
+			;
+		w->next = ll;
+	}
+
+	q->len++;
+	return q;
+}
+
+/* add elem to set if it doesn't exist yet (pure definition of set) */
+static set *
+add_set_unique(const char *name, set *q, bool *unique)
+{
+	char *mname = xstrdup(name);
+	int hash;
+	int pos;
+	elem *ll;
+	elem *w;
+
+	if (q == NULL)
+		q = create_set();
+
+	rmspace(mname);
+	hash = fnv1a32(mname);
+	pos = hash % _SET_HASH_SIZE;
+
+	if (q->buckets[pos] == NULL) {
+		q->buckets[pos] = ll = xmalloc(sizeof(*ll));
+		ll->next = NULL;
+		ll->name = mname;
+		ll->hash = hash;
+		*unique = true;
+	} else {
+		ll = NULL;
+		for (w = q->buckets[pos]; w != NULL; ll = w, w = w->next) {
+			if (w->hash == hash && strcmp(w->name, mname) == 0) {
+				free(mname);
+				*unique = false;
+				break;
+			}
+		}
+		if (w == NULL) {
+			ll = ll->next = xmalloc(sizeof(*ll));
+			ll->next = NULL;
+			ll->name = mname;
+			ll->hash = hash;
+			*unique = true;
+		}
+	}
+
+	if (*unique)
+		q->len++;
+	return q;
+}
+
+/* returns whether s is in set */
+static bool
+contains_set(char *s, set *q)
+{
+	char *mname = xstrdup(s);
+	int hash;
+	int pos;
+	elem *w;
+	bool found;
+
+	rmspace(mname);
+	hash = fnv1a32(mname);
+	pos = hash % _SET_HASH_SIZE;
+
+	found = false;
+	if (q->buckets[pos] != NULL) {
+		for (w = q->buckets[pos]; w != NULL; w = w->next) {
+			if (w->hash == hash && strcmp(w->name, mname) == 0) {
+				found = true;
+				break;
+			}
+		}
+	}
+
+	free(mname);
+	return found;
+}
+
+/* remove elem from a set. matches ->name and frees name,item */
+static set *
+del_set(char *s, set *q, bool *removed)
+{
+	char *mname = xstrdup(s);
+	unsigned int hash;
+	int pos;
+	elem *ll;
+	elem *w;
+
+	rmspace(mname);
+	hash = fnv1a32(mname);
+	pos = hash % _SET_HASH_SIZE;
+
+	*removed = false;
+	if (q->buckets[pos] != NULL) {
+		ll = NULL;
+		for (w = q->buckets[pos]; w != NULL; ll = w, w = w->next) {
+			if (w->hash == hash && strcmp(w->name, mname) == 0) {
+				free(mname);
+				if (ll == NULL) {
+					q->buckets[pos] = w->next;
+				} else {
+					ll->next = w->next;
+				}
+				free(w->name);
+				free(w);
+				*removed = true;
+				break;
+			}
+		}
+	}
+
+	if (*removed)
+		q->len--;
+	return q;
+}
+
+/* return the contents of a set as an array of strings
+ * the length of the list is returned, and the array is terminated with
+ * a NULL (not included in returned length)
+ * the caller should free l, but not the strings within */
+static size_t
+list_set(set *q, char ***l)
+{
+	int i;
+	elem *w;
+	char **ret;
+
+	ret = *l = xmalloc(sizeof(char **) * (q->len + 1));
+	for (i = 0; i < _SET_HASH_SIZE; i++) {
+		for (w = q->buckets[i]; w != NULL; w = w->next) {
+			*ret = w->name;
+			ret++;
+		}
+	}
+	*ret = NULL;
+	return q->len;
+}
+
+/* clear out a set */
+static void
+free_set(set *q)
+{
+	int i;
+	elem *w;
+	elem *e;
+
+	for (i = 0; i < _SET_HASH_SIZE; i++) {
+		for (w = q->buckets[i]; w != NULL; w = e) {
+			e = w->next;
+			free(w->name);
+			free(w);
+		}
+	}
+	free(q);
+}
+
+#ifdef EBUG
+static void
+print_set(const set *q)
+{
+	elem *w;
+	int i;
+
+	for (i = 0; i < _SET_HASH_SIZE; i++) {
+		for (w = q->buckets[i]; w != NULL; w = w->next)
+			puts(w->name);
+	}
+}
+#endif

diff --git a/libq/virtuals.c b/libq/virtuals.c
deleted file mode 100644
index f96b207..0000000
--- a/libq/virtuals.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright 2005-2018 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- *
- * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
- * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
-/* used to queue a lot of things */
-struct queue_t {
-	char *name;
-	struct queue_t *next;
-};
-
-typedef struct queue_t queue;
-
-static queue *
-append_set(queue *q, queue *ll)
-{
-	queue *z;
-
-	if (!q)
-		return ll;
-
-	z = q;
-	while (z->next)
-		z = z->next;
-	z->next = ll;
-
-	return q;
-}
-
-/* add a set to a cache */
-static queue *
-add_set(const char *name, queue *q)
-{
-	queue *ll = xmalloc(sizeof(*ll));
-	ll->next = NULL;
-	ll->name = xstrdup(name);
-	rmspace(ll->name);
-	return append_set(q, ll);
-}
-
-/* Performance here is terrible.  Should use a hash at some point. */
-static queue *
-add_set_unique(const char *name, queue *q, bool *ok)
-{
-	queue *ll = q;
-	while (ll) {
-		if (!strcmp(ll->name, name)) {
-			*ok = false;
-			return q;
-		}
-		ll = ll->next;
-	}
-	*ok = true;
-	return add_set(name, q);
-}
-
-/* remove a set from a cache. matches ->name and frees name,item */
-static queue *
-del_set(char *s, queue *q, int *ok)
-{
-	queue *ll, *list, *old;
-	ll = q;
-	list = q;
-	old = q;
-	*ok = 0;
-
-	while (ll != NULL) {
-		if (strcmp(ll->name, s) == 0) {
-			if (ll == list) {
-				list = (ll->next);
-				free(ll->name);
-				free(ll);
-				ll = list;
-
-			} else {
-				old->next = ll->next;
-				free(ll->name);
-				free(ll);
-				ll = old->next;
-			}
-			*ok = 1;
-		} else {
-			old = ll;
-			ll = ll->next;
-		}
-	}
-	return list;
-}
-
-/* clear out a list */
-static void
-free_sets(queue *list)
-{
-	queue *ll, *q;
-	ll = list;
-	while (ll != NULL) {
-		q = ll->next;
-		free(ll->name);
-		free(ll);
-		ll = q;
-	}
-}
-
-#ifdef EBUG
-static void
-print_sets(const queue *list)
-{
-	const queue *ll;
-	for (ll = list; ll != NULL; ll = ll->next)
-		puts(ll->name);
-}
-#endif

diff --git a/libq/xmalloc.c b/libq/xmalloc.c
index 9a9173d..3d4537d 100644
--- a/libq/xmalloc.c
+++ b/libq/xmalloc.c
@@ -3,6 +3,7 @@
  * Utility routines.
  *
  * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 2019-        Fabian Groffen <grobian@gentoo.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,13 +20,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <fcntl.h>
 
 static void *xmalloc(size_t size)
 {
@@ -46,8 +43,6 @@ static void *xcalloc(size_t nmemb, size_t size)
 static void *xzalloc(size_t size)
 {
 	void *ptr = xmalloc(size);
-	if (unlikely(ptr == NULL))
-		err("Out of memory");
 	memset(ptr, 0x00, size);
 	return ptr;
 }
@@ -66,3 +61,20 @@ static void *xmemdup(const void *src, size_t n)
 	memcpy(ret, src, n);
 	return ret;
 }
+
+static char *xstrdup_len(const char *s, size_t *len)
+{
+
+	if (s == NULL)
+		return NULL;
+
+	*len = strlen(s);
+	return xmemdup(s, *len + 1);
+}
+
+static char *xstrdup(const char *s)
+{
+	size_t len;
+
+	return xstrdup_len(s, &len);
+}

diff --git a/libq/xstrdup.c b/libq/xstrdup.c
deleted file mode 100644
index e069c9d..0000000
--- a/libq/xstrdup.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-static char *xstrdup(const char *s)
-{
-	void *t;
-
-	if (s == NULL)
-		return NULL;
-
-	t = (void *)strdup(s);
-	if (unlikely(t == NULL))
-		err("Out of memory");
-
-	return (char *)t;
-}
-
-static char *xstrdup_len(const char *s, size_t *len)
-{
-	char *ret;
-
-	*len = strlen(s);
-	ret = xmalloc(*len + 1);
-	memcpy(ret, s, *len + 1);
-
-	return ret;
-}

diff --git a/main.c b/main.c
index 2eeb21b..044777c 100644
--- a/main.c
+++ b/main.c
@@ -1423,7 +1423,7 @@ atom_to_pvr(depend_atom *atom) {
 }
 
 /* TODO: Merge this into libq/vdb.c somehow. */
-static queue *
+static set *
 get_vdb_atoms(int fullcpv)
 {
 	q_vdb_ctx *ctx;
@@ -1440,18 +1440,21 @@ get_vdb_atoms(int fullcpv)
 	struct dirent **pf;
 
 	depend_atom *atom = NULL;
-	queue *cpf = NULL;
+	set *cpf = NULL;
 
 	ctx = q_vdb_open();
 	if (!ctx)
 		return NULL;
 
 	/* scan the cat first */
-	if ((cfd = scandirat(ctx->vdb_fd, ".", &cat, q_vdb_filter_cat, alphasort)) < 0)
+	cfd = scandirat(ctx->vdb_fd, ".", &cat, q_vdb_filter_cat, alphasort);
+	if (cfd < 0)
 		goto fuckit;
 
 	for (j = 0; j < cfd; j++) {
-		if ((dfd = scandirat(ctx->vdb_fd, cat[j]->d_name, &pf, q_vdb_filter_pkg, alphasort)) < 0)
+		dfd = scandirat(ctx->vdb_fd, cat[j]->d_name,
+				&pf, q_vdb_filter_pkg, alphasort);
+		if (dfd < 0)
 			continue;
 		for (i = 0; i < dfd; i++) {
 			int blen = snprintf(buf, sizeof(buf), "%s/%s/SLOT",
@@ -1475,9 +1478,11 @@ get_vdb_atoms(int fullcpv)
 
 			if (fullcpv) {
 				if (atom->PR_int)
-					snprintf(buf, sizeof(buf), "%s/%s-%s-r%i", atom->CATEGORY, atom->PN, atom->PV, atom->PR_int);
+					snprintf(buf, sizeof(buf), "%s/%s-%s-r%i",
+							atom->CATEGORY, atom->PN, atom->PV, atom->PR_int);
 				else
-					snprintf(buf, sizeof(buf), "%s/%s-%s", atom->CATEGORY, atom->PN, atom->PV);
+					snprintf(buf, sizeof(buf), "%s/%s-%s",
+							atom->CATEGORY, atom->PN, atom->PV);
 			} else {
 				snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN);
 			}

diff --git a/qcache.c b/qcache.c
index 831af2e..e4b6a7e 100644
--- a/qcache.c
+++ b/qcache.c
@@ -54,7 +54,8 @@ typedef struct {
 /* Global Variables                                                 */
 /********************************************************************/
 
-static queue *arches;
+static set *archs;
+static char **archlist;
 static int archlist_count;
 static size_t arch_longest_len;
 const char status[3] = {'-', '~', '+'};
@@ -99,12 +100,12 @@ decode_status(char c)
  * IN:
  *  const char *arch - name of an arch (alpha, amd64, ...)
  * OUT:
- *  int pos - location of arch in archlist[]
+ *  int - position in keywords, or -1 if not found
  */
 static int
 decode_arch(const char *arch)
 {
-	queue *q = arches;
+	char **q;
 	int a;
 	const char *p;
 
@@ -112,12 +113,9 @@ decode_arch(const char *arch)
 	if (*p == '~' || *p == '-')
 		p++;
 
-	a = 0;
-	while (q) {
-		if (strcmp(q->name, p) == 0)
+	for (q = archlist, a = 0; *q != NULL; q++, a++) {
+		if (strcmp(*q, p) == 0)
 			return a;
-		++a;
-		q = q->next;
 	}
 
 	return -1;
@@ -135,7 +133,7 @@ decode_arch(const char *arch)
 static void
 print_keywords(const char *category, const char *ebuild, int *keywords)
 {
-	queue *arch = arches;
+	char **arch = archlist;
 	int a;
 	char *package;
 
@@ -143,16 +141,15 @@ print_keywords(const char *category, const char *ebuild, int *keywords)
 	package[strlen(ebuild)-7] = '\0';
 
 	printf("%s%s/%s%s%s ", BOLD, category, BLUE, package, NORM);
-	for (a = 0; a < archlist_count; ++a) {
+	for (a = 0; a < archlist_count; a++) {
 		switch (keywords[a]) {
 			case stable:
-				printf("%s%c%s%s ", GREEN, status[keywords[a]], arch->name, NORM);
+				printf("%s%c%s%s ", GREEN, status[keywords[a]], arch[a], NORM);
 				break;
 			case testing:
-				printf("%s%c%s%s ", YELLOW, status[keywords[a]], arch->name, NORM);
+				printf("%s%c%s%s ", YELLOW, status[keywords[a]], arch[0], NORM);
 				break;
 		}
-		arch = arch->next;
 	}
 
 	printf("\n");
@@ -182,6 +179,7 @@ read_keywords(char *s, int *keywords)
 
 	memset(keywords, 0, sizeof(*keywords) * archlist_count);
 
+	/* handle -* */
 	slen = strlen(s);
 	if (slen >= 2 && s[0] == '-' && s[1] == '*')
 		for (a = 0; a < archlist_count; ++a)
@@ -696,7 +694,7 @@ static void
 qcache_stats(qcache_data *data)
 {
 	static time_t runtime;
-	static queue *allcats;
+	static set *allcats;
 	static const char *last_overlay;
 	static int numpkg  = 0;
 	static int numebld = 0;
@@ -709,15 +707,20 @@ qcache_stats(qcache_data *data)
 
 	/* Is this the last time we'll be called? */
 	if (!data) {
+		char **arch;
 		const char border[] = "------------------------------------------------------------------";
 
 		printf("+%.*s+\n", 25, border);
 		printf("|   general statistics    |\n");
 		printf("+%.*s+\n", 25, border);
-		printf("| %s%13s%s | %s%7d%s |\n", GREEN, "architectures", NORM, BLUE, archlist_count, NORM);
-		printf("| %s%13s%s | %s%7d%s |\n", GREEN, "categories", NORM, BLUE, numcat, NORM);
-		printf("| %s%13s%s | %s%7d%s |\n", GREEN, "packages", NORM, BLUE, numpkg, NORM);
-		printf("| %s%13s%s | %s%7d%s |\n", GREEN, "ebuilds", NORM, BLUE, numebld, NORM);
+		printf("| %s%13s%s | %s%7d%s |\n",
+				GREEN, "architectures", NORM, BLUE, archlist_count, NORM);
+		printf("| %s%13s%s | %s%7d%s |\n",
+				GREEN, "categories", NORM, BLUE, numcat, NORM);
+		printf("| %s%13s%s | %s%7d%s |\n",
+				GREEN, "packages", NORM, BLUE, numpkg, NORM);
+		printf("| %s%13s%s | %s%7d%s |\n",
+				GREEN, "ebuilds", NORM, BLUE, numebld, NORM);
 		printf("+%.*s+\n\n", 25, border);
 
 		printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
@@ -725,20 +728,23 @@ qcache_stats(qcache_data *data)
 			(int)arch_longest_len, "");
 		printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
 		printf("| %s%*s%s |%s%8s%s |%s%8s%s |%s%8s%s | %s%8s%s |\n",
-			RED, (int)arch_longest_len, "architecture", NORM, RED, "stable", NORM,
+			RED, (int)arch_longest_len, "architecture", NORM,
+			RED, "stable", NORM,
 			RED, "~arch", NORM, RED, "total", NORM, RED, "total/#pkgs", NORM);
 		printf("| %*s |         |%s%8s%s |         |             |\n",
 			(int)arch_longest_len, "", RED, "only", NORM);
 		printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
 
-		queue *arch = arches;
-		for (a = 0; a < archlist_count; ++a) {
-			printf("| %s%*s%s |", GREEN, (int)arch_longest_len, arch->name, NORM);
+		arch = archlist;
+		for (a = 0; a < archlist_count; a++) {
+			printf("| %s%*s%s |", GREEN, (int)arch_longest_len, arch[a], NORM);
 			printf("%s%8d%s |", BLUE, packages_stable[a], NORM);
 			printf("%s%8d%s |", BLUE, packages_testing[a], NORM);
-			printf("%s%8d%s |", BLUE, packages_testing[a]+packages_stable[a], NORM);
-			printf("%s%11.2f%s%% |\n", BLUE, (100.0*(packages_testing[a]+packages_stable[a]))/numpkg, NORM);
-			arch = arch->next;
+			printf("%s%8d%s |",
+					BLUE, packages_testing[a] + packages_stable[a], NORM);
+			printf("%s%11.2f%s%% |\n", BLUE,
+					(100.0*(packages_testing[a]+packages_stable[a]))/numpkg,
+					NORM);
 		}
 
 		printf("+%.*s+\n\n", (int)(arch_longest_len + 46), border);
@@ -751,7 +757,7 @@ qcache_stats(qcache_data *data)
 		free(packages_testing);
 		free(keywords);
 		free(current_package_keywords);
-		free_sets(allcats);
+		free_set(allcats);
 		return;
 	}
 
@@ -797,15 +803,20 @@ qcache_stats(qcache_data *data)
 	}
 
 	if (!numpkg) {
-		packages_stable          = xcalloc(archlist_count, sizeof(*packages_stable));
-		packages_testing         = xcalloc(archlist_count, sizeof(*packages_testing));
-		keywords                 = xcalloc(archlist_count, sizeof(*keywords));
-		current_package_keywords = xcalloc(archlist_count, sizeof(*current_package_keywords));
+		packages_stable          =
+			xcalloc(archlist_count, sizeof(*packages_stable));
+		packages_testing         =
+			xcalloc(archlist_count, sizeof(*packages_testing));
+		keywords                 =
+			xcalloc(archlist_count, sizeof(*keywords));
+		current_package_keywords =
+			xcalloc(archlist_count, sizeof(*current_package_keywords));
 	}
 
 	if (data->cur == 1) {
 		numpkg++;
-		memset(current_package_keywords, 0, archlist_count * sizeof(*current_package_keywords));
+		memset(current_package_keywords, 0,
+				archlist_count * sizeof(*current_package_keywords));
 	}
 	++numebld;
 
@@ -914,7 +925,7 @@ qcache_load_arches(const char *overlay)
 			continue;
 
 		bool ok;
-		arches = add_set_unique(buf, arches, &ok);
+		archs = add_set_unique(buf, archs, &ok);
 		if (ok) {
 			++archlist_count;
 			arch_longest_len = MAX(arch_longest_len, strlen(buf));
@@ -922,6 +933,9 @@ qcache_load_arches(const char *overlay)
 	}
 	free(buf);
 
+	/* materialise into a list */
+	list_set(archs, &archlist);
+
 	fclose(fp);
  done:
 	free(filename);
@@ -935,7 +949,8 @@ qcache_load_arches(const char *overlay)
 static void
 qcache_free(void)
 {
-	free_sets(arches);
+	free(archlist);
+	free_set(archs);
 }
 
 /********************************************************************/

diff --git a/qlist.c b/qlist.c
index 3ca3f5e..6addc14 100644
--- a/qlist.c
+++ b/qlist.c
@@ -313,7 +313,6 @@ struct qlist_opt_state {
 	bool show_umap;
 	bool show_dbg;
 	bool columns;
-	queue *sets;
 	char *buf;
 	size_t buflen;
 };
@@ -434,7 +433,6 @@ int qlist_main(int argc, char **argv)
 		.show_umap = false,
 		.show_dbg = false,
 		.columns = false,
-		.sets = NULL,
 		.buflen = _Q_PATH_MAX,
 	};
 	int i, ret;

diff --git a/qmerge.c b/qmerge.c
index 195d92b..aec51be 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -101,7 +101,7 @@ typedef struct llist_char_t llist_char;
 
 static void pkg_fetch(int, const depend_atom *, const struct pkg_t *);
 static void pkg_merge(int, const depend_atom *, const struct pkg_t *);
-static int pkg_unmerge(q_vdb_pkg_ctx *, queue *, int, char **, int, char **);
+static int pkg_unmerge(q_vdb_pkg_ctx *, set *, int, char **, int, char **);
 static struct pkg_t *grab_binpkg_info(const char *);
 static char *find_binpkg(const char *);
 
@@ -684,7 +684,7 @@ pkg_run_func_at(int dirfd, const char *vdb_path, const char *phases, const char
 /* Copy one tree (the single package) to another tree (ROOT) */
 static int
 merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
-              FILE *contents, queue **objs, char **cpathp,
+              FILE *contents, set **objs, char **cpathp,
               int cp_argc, char **cp_argv, int cpm_argc, char **cpm_argv)
 {
 	int i, ret, subfd_src, subfd_dst;
@@ -919,7 +919,7 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
 static void
 pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 {
-	queue *objs;
+	set *objs;
 	q_vdb_ctx *vdb_ctx;
 	q_vdb_cat_ctx *cat_ctx;
 	FILE *fp, *contents;
@@ -1305,7 +1305,7 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 	freeargv(cpm_argc, cpm_argv);
 
 	/* Clean up the package state */
-	free_sets(objs);
+	free_set(objs);
 	free(D);
 	free(T);
 
@@ -1341,7 +1341,7 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 }
 
 static int
-pkg_unmerge(q_vdb_pkg_ctx *pkg_ctx, queue *keep,
+pkg_unmerge(q_vdb_pkg_ctx *pkg_ctx, set *keep,
 		int cp_argc, char **cp_argv, int cpm_argc, char **cpm_argv)
 {
 	q_vdb_cat_ctx *cat_ctx = pkg_ctx->cat_ctx;
@@ -1385,7 +1385,7 @@ pkg_unmerge(q_vdb_pkg_ctx *pkg_ctx, queue *keep,
 		strstr(features, "config-protect-if-modified") != NULL;
 
 	while (getline(&buf, &buflen, fp) != -1) {
-		queue *q;
+		bool del;
 		contents_entry *e;
 		char zing[20];
 		int protected = 0;
@@ -1455,21 +1455,16 @@ pkg_unmerge(q_vdb_pkg_ctx *pkg_ctx, queue *keep,
 		}
 
 		/* See if this was updated */
-		q = keep;
-		while (q) {
-			if (!strcmp(q->name, e->name)) {
-				/* XXX: could remove this from the queue */
-				strcpy(zing, "---");
-				q = NULL;
-				break;
-			}
-			q = q->next;
-		}
+		del = false;
+		if (keep != NULL)
+			(void)del_set(e->name, keep, &del);
+		if (del)
+			strcpy(zing, "---");
 
 		/* No match, so unmerge it */
 		if (!quiet)
 			printf("%s %s\n", zing, e->name);
-		if (!keep || q) {
+		if (!keep || !del) {
 			char *p;
 
 			if (!pretend && unlinkat(portroot_fd, e->name + 1, 0)) {
@@ -1599,7 +1594,9 @@ pkg_fetch(int level, const depend_atom *atom, const struct pkg_t *pkg)
 
 	/* XXX: should do a size check here for partial downloads */
 
-	if (force_download && (access(buf, R_OK) == 0) && (pkg->SHA1[0] || pkg->MD5[0])) {
+	if (force_download && (access(buf, R_OK) == 0) &&
+			(pkg->SHA1[0] || pkg->MD5[0]))
+	{
 		if (pkg_verify_checksums(buf, pkg, atom, 0, 0) != 0)
 			unlink(buf);
 	}
@@ -1608,7 +1605,9 @@ pkg_fetch(int level, const depend_atom *atom, const struct pkg_t *pkg)
 			warn("No checksum data for %s (try `emaint binhost --fix`)", buf);
 			return;
 		} else {
-			if (pkg_verify_checksums(buf, pkg, atom, qmerge_strict, !quiet) == 0) {
+			if (pkg_verify_checksums(buf, pkg, atom, qmerge_strict, !quiet)
+					== 0)
+			{
 				pkg_merge(0, atom, pkg);
 				return;
 			}
@@ -1700,21 +1699,23 @@ print_Pkg(int full, const depend_atom *atom, const struct pkg_t *pkg)
 static int
 qmerge_unmerge_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 {
-	queue *todo = priv;
 	int cp_argc;
 	int cpm_argc;
 	char **cp_argv;
 	char **cpm_argv;
+	char **todo;
+	char **p;
 
 	makeargv(config_protect, &cp_argc, &cp_argv);
 	makeargv(config_protect_mask, &cpm_argc, &cpm_argv);
 
-	while (todo) {
-		if (qlist_match(pkg_ctx, todo->name, NULL, true))
+	(void)list_set(priv, &todo);
+	for (p = todo; *p != NULL; p++) {
+		if (qlist_match(pkg_ctx, *p, NULL, true))
 			pkg_unmerge(pkg_ctx, NULL, cp_argc, cp_argv, cpm_argc, cpm_argv);
-		todo = todo->next;
 	}
 
+	free(todo);
 	freeargv(cp_argc, cp_argv);
 	freeargv(cpm_argc, cpm_argv);
 
@@ -1722,7 +1723,7 @@ qmerge_unmerge_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 }
 
 static int
-unmerge_packages(queue *todo)
+unmerge_packages(set *todo)
 {
 	return q_vdb_foreach_pkg(qmerge_unmerge_cb, todo, NULL);
 }
@@ -2000,7 +2001,7 @@ find_binpkg(const char *name)
 }
 
 static int
-parse_packages(queue *todo)
+parse_packages(set *todo)
 {
 	FILE *fp;
 	int linelen;
@@ -2009,10 +2010,16 @@ parse_packages(queue *todo)
 	struct pkg_t Pkg;
 	depend_atom *pkg_atom;
 	char repo[sizeof(Pkg.REPO)];
+	depend_atom **todo_atoms;
+	size_t todo_cnt;
+	size_t i;
 
 	fp = open_binpkg_index();
+	if (fp == NULL)
+		return EXIT_FAILURE;
 
 	buf = NULL;
+	buflen = 0;  /* make getline allocate */
 	repo[0] = '\0';
 
 	/* First consume the header with the common data. */
@@ -2040,6 +2047,16 @@ parse_packages(queue *todo)
 	memset(&Pkg, 0, sizeof(Pkg));
 	strcpy(Pkg.SLOT, "0");
 
+	/* build list with exploded atoms for each access below */
+	{
+		char **todo_strs;
+		todo_cnt = list_set(todo, &todo_strs);
+		todo_atoms = xmalloc(sizeof(*todo_atoms) * todo_cnt);
+		for (i = 0; i < todo_cnt; i++)
+			todo_atoms[i] = atom_explode(todo_strs[i]);
+		free(todo_strs);
+	}
+
 	/* Then walk all the package entries. */
 	while (getline(&buf, &buflen, fp) != -1) {
 		if (*buf == '\n') {
@@ -2047,20 +2064,15 @@ parse_packages(queue *todo)
 				if (search_pkgs && !todo) {
 					print_Pkg(verbose, pkg_atom, &Pkg);
 				} else {
-					const queue *ll = todo;
-					depend_atom *todo_atom;
-					while (ll) {
-						todo_atom = atom_explode(ll->name);
-						pkg_atom->REPO = todo_atom->REPO ? Pkg.REPO : NULL;
-						pkg_atom->SLOT = todo_atom->SLOT ? Pkg.SLOT : NULL;
-						if (atom_compare(todo_atom, pkg_atom) == EQUAL) {
+					for (i = 0; i < todo_cnt; i++) {
+						pkg_atom->REPO = todo_atoms[i]->REPO ? Pkg.REPO : NULL;
+						pkg_atom->SLOT = todo_atoms[i]->SLOT ? Pkg.SLOT : NULL;
+						if (atom_compare(todo_atoms[i], pkg_atom) == EQUAL) {
 							if (search_pkgs)
 								print_Pkg(verbose, pkg_atom, &Pkg);
 							else
 								pkg_fetch(0, pkg_atom, &Pkg);
 						}
-						atom_implode(todo_atom);
-						ll = ll->next;
 					}
 				}
 
@@ -2155,11 +2167,15 @@ parse_packages(queue *todo)
 	if (pkg_atom)
 		atom_implode(pkg_atom);
 
+	for (i = 0; i < todo_cnt; i++)
+		atom_implode(todo_atoms[i]);
+	free(todo_atoms);
+
 	return EXIT_SUCCESS;
 }
 
-static queue *
-qmerge_add_set_file(const char *dir, const char *file, queue *set)
+static set *
+qmerge_add_set_file(const char *dir, const char *file, set *q)
 {
 	FILE *fp;
 	int linelen;
@@ -2180,19 +2196,19 @@ qmerge_add_set_file(const char *dir, const char *file, queue *set)
 	buf = NULL;
 	while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
 		rmspace_len(buf, (size_t)linelen);
-		set = add_set(buf, set);
+		q = add_set(buf, q);
 	}
 	free(buf);
 
 	fclose(fp);
 
-	return set;
+	return q;
 }
 
 static void *
 qmerge_add_set_system(void *data, char *buf)
 {
-	queue *set = data;
+	set *q = data;
 	char *s;
 
 	s = strchr(buf, '#');
@@ -2202,35 +2218,35 @@ qmerge_add_set_system(void *data, char *buf)
 
 	s = buf;
 	if (*s == '*')
-		set = add_set(s + 1, set);
+		q = add_set(s + 1, q);
 	else if (s[0] == '-' && s[1] == '*') {
-		int ok;
-		set = del_set(s + 2, set, &ok);
+		bool ok;
+		q = del_set(s + 2, q, &ok);
 	}
 
-	return set;
+	return q;
 }
 
 /* XXX: note, this doesn't handle more complicated set files like
  *      the portage .ini files in /usr/share/portage/sets/ */
 /* XXX: this code does not combine duplicate dependencies */
-static queue *
-qmerge_add_set(char *buf, queue *set)
+static set *
+qmerge_add_set(char *buf, set *q)
 {
 	if (strcmp(buf, "world") == 0)
-		return qmerge_add_set_file("/var/lib/portage", "world", set);
+		return qmerge_add_set_file("/var/lib/portage", "world", q);
 	else if (strcmp(buf, "all") == 0)
 		return get_vdb_atoms(0);
 	else if (strcmp(buf, "system") == 0)
-		return q_profile_walk("packages", qmerge_add_set_system, set);
+		return q_profile_walk("packages", qmerge_add_set_system, q);
 	else if (buf[0] == '@')
-		return qmerge_add_set_file("/etc/portage", buf+1, set);
+		return qmerge_add_set_file("/etc/portage", buf+1, q);
 	else
-		return add_set(buf, set);
+		return add_set(buf, q);
 }
 
 static int
-qmerge_run(queue *todo)
+qmerge_run(set *todo)
 {
 	if (uninstall)
 		return unmerge_packages(todo);
@@ -2241,7 +2257,7 @@ qmerge_run(queue *todo)
 int qmerge_main(int argc, char **argv)
 {
 	int i, ret;
-	queue *todo;
+	set *todo;
 
 	if (argc < 2)
 		qmerge_usage(EXIT_FAILURE);
@@ -2310,7 +2326,7 @@ int qmerge_main(int argc, char **argv)
 	}
 
 	ret = qmerge_run(todo);
-	free_sets(todo);
+	free_set(todo);
 	return ret;
 }
 

diff --git a/qpkg.c b/qpkg.c
index dcdc190..05c8505 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -44,15 +44,17 @@ filter_tbz2(const struct dirent *dentry)
 
 /* process a single dir for cleaning. dir can be a $PKGDIR, $PKGDIR/All/, $PKGDIR/$CAT */
 static uint64_t
-qpkg_clean_dir(char *dirp, queue *vdb)
+qpkg_clean_dir(char *dirp, set *vdb)
 {
-	queue *ll;
+	set *ll = NULL;
 	struct dirent **fnames;
 	int i, count;
 	char buf[_Q_PATH_MAX];
 	struct stat st;
 	uint64_t num_all_bytes = 0;
 	size_t disp_units = 0;
+	char **t;
+	bool ignore;
 
 	if (dirp == NULL)
 		return 0;
@@ -61,18 +63,13 @@ qpkg_clean_dir(char *dirp, queue *vdb)
 	if ((count = scandir(".", &fnames, filter_tbz2, alphasort)) < 0)
 		return 0;
 
+	/* create copy of vdb with only basenames */
+	for ((void)list_set(vdb, &t); *t != NULL; t++)
+		ll = add_set_unique(basename(*t), ll, &ignore);
+
 	for (i = 0; i < count; i++) {
-		int del = 1;
 		fnames[i]->d_name[strlen(fnames[i]->d_name)-5] = 0;
-		for (ll = vdb; ll != NULL; ll = ll->next) {
-			if (1) {
-				if (strcmp(fnames[i]->d_name, basename(ll->name)) == 0) {
-					del = 0;
-					break;
-				}
-			}
-		}
-		if (!del)
+		if (contains_set(fnames[i]->d_name, ll))
 			continue;
 		snprintf(buf, sizeof(buf), "%s.tbz2", fnames[i]->d_name);
 		if (lstat(buf, &st) != -1) {
@@ -81,14 +78,19 @@ qpkg_clean_dir(char *dirp, queue *vdb)
 				if ((st.st_size / KILOBYTE) > 1000)
 					disp_units = MEGABYTE;
 				num_all_bytes += st.st_size;
-				qprintf(" %s[%s%s %3s %s %s%s]%s %s%s/%s%s\n", DKBLUE, NORM, GREEN, make_human_readable_str(st.st_size, 1, disp_units),
-					disp_units == MEGABYTE ? "M" : "K", NORM, DKBLUE, NORM, CYAN, basename(dirp), fnames[i]->d_name, NORM);
+				qprintf(" %s[%s%s %3s %s %s%s]%s %s%s/%s%s\n",
+						DKBLUE, NORM, GREEN,
+						make_human_readable_str(st.st_size, 1, disp_units),
+						disp_units == MEGABYTE ? "M" : "K",
+						NORM, DKBLUE, NORM, CYAN,
+						basename(dirp), fnames[i]->d_name, NORM);
 			}
 			if (!pretend)
 				unlink(buf);
 		}
 	}
 
+	free_set(ll);
 	scandir_free(fnames, count);
 
 	return num_all_bytes;
@@ -103,18 +105,14 @@ qpkg_clean(char *dirp)
 	size_t disp_units = 0;
 	uint64_t num_all_bytes;
 	struct dirent **dnames;
-	queue *vdb;
-
-	vdb = get_vdb_atoms(1);
+	set *vdb;
 
-	if (chdir(dirp) != 0) {
-		free_sets(vdb);
+	if (chdir(dirp) != 0)
 		return 1;
-	}
-	if ((count = scandir(".", &dnames, filter_hidden, alphasort)) < 0) {
-		free_sets(vdb);
+	if ((count = scandir(".", &dnames, filter_hidden, alphasort)) < 0)
 		return 1;
-	}
+
+	vdb = get_vdb_atoms(1);
 
 	if (eclean) {
 		size_t n;
@@ -141,11 +139,13 @@ qpkg_clean(char *dirp)
 				if ((p = strrchr(buf, '/')) == NULL)
 					continue;
 				*p = 0;
-				/* these strcat() are safe. the name is extracted from buf already. */
+				/* these strcat() are safe. the name is extracted from
+				 * buf already. */
 				strcat(buf, "/");
 				strcat(buf, name);
 
-				/* num_all_bytes will be off when pretend and eclean are enabled together */
+				/* num_all_bytes will be off when pretend and eclean are
+				 * enabled together */
 				/* vdb = del_set(buf, vdb, &i); */
 				vdb = add_set(buf, vdb);
 			}
@@ -164,13 +164,15 @@ qpkg_clean(char *dirp)
 	}
 	scandir_free(dnames, count);
 
-	free_sets(vdb);
+	free_set(vdb);
 
 	disp_units = KILOBYTE;
 	if ((num_all_bytes / KILOBYTE) > 1000)
 		disp_units = MEGABYTE;
-	qprintf(" %s*%s Total space that would be freed in packages directory: %s%s %c%s\n", GREEN, NORM, RED,
-		make_human_readable_str(num_all_bytes, 1, disp_units), disp_units == MEGABYTE ? 'M' : 'K', NORM);
+	qprintf(" %s*%s Total space that would be freed in packages "
+			"directory: %s%s %c%s\n", GREEN, NORM, RED,
+			make_human_readable_str(num_all_bytes, 1, disp_units),
+			disp_units == MEGABYTE ? 'M' : 'K', NORM);
 
 	return 0;
 }


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-03-19 20:32 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-03-19 20:32 UTC (permalink / raw
  To: gentoo-commits

commit:     4bca3f140de3896f0a7531bc372a7240486aef19
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 18 13:39:15 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Mar 18 13:39:15 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=4bca3f14

build: add autoconf helper files

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 Makefile.in      |    15 +-
 ar-lib           |   270 ++
 autogen.sh       |     7 -
 compile          |   348 ++
 config.guess     |  1477 +++++++
 config.sub       |  1866 +++++++++
 configure        |     8 +-
 configure.ac     |     1 -
 depcomp          |   791 ++++
 install-sh       |   508 +++
 libq/Makefile.in |     5 +-
 ltmain.sh        | 11210 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 missing          |   215 +
 13 files changed, 16694 insertions(+), 27 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index adcf717..93c04f8 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -299,7 +299,7 @@ am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 am__v_at_1 = 
 DEFAULT_INCLUDES = -I.@am__isrc@
-depcomp = $(SHELL) $(top_srcdir)/autotools/depcomp
+depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -369,17 +369,8 @@ CTAGS = ctags
 CSCOPE = cscope
 DIST_SUBDIRS = $(SUBDIRS)
 am__DIST_COMMON = $(dist_man_MANS) $(srcdir)/Makefile.in \
-	$(srcdir)/config.h.in $(top_srcdir)/autotools/ar-lib \
-	$(top_srcdir)/autotools/compile \
-	$(top_srcdir)/autotools/config.guess \
-	$(top_srcdir)/autotools/config.sub \
-	$(top_srcdir)/autotools/depcomp \
-	$(top_srcdir)/autotools/install-sh \
-	$(top_srcdir)/autotools/ltmain.sh \
-	$(top_srcdir)/autotools/missing COPYING INSTALL \
-	autotools/ar-lib autotools/compile autotools/config.guess \
-	autotools/config.sub autotools/depcomp autotools/install-sh \
-	autotools/ltmain.sh autotools/missing
+	$(srcdir)/config.h.in COPYING INSTALL ar-lib compile \
+	config.guess config.sub depcomp install-sh ltmain.sh missing
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 distdir = $(PACKAGE)-$(VERSION)
 top_distdir = $(distdir)

diff --git a/ar-lib b/ar-lib
new file mode 100755
index 0000000..05094d3
--- /dev/null
+++ b/ar-lib
@@ -0,0 +1,270 @@
+#! /bin/sh
+# Wrapper for Microsoft lib.exe
+
+me=ar-lib
+scriptversion=2012-03-01.08; # UTC
+
+# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+# Written by Peter Rosin <peda@lysator.liu.se>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to <bug-automake@gnu.org> or send patches to
+# <automake-patches@gnu.org>.
+
+
+# func_error message
+func_error ()
+{
+  echo "$me: $1" 1>&2
+  exit 1
+}
+
+file_conv=
+
+# func_file_conv build_file
+# Convert a $build file to $host form and store it in $file
+# Currently only supports Windows hosts.
+func_file_conv ()
+{
+  file=$1
+  case $file in
+    / | /[!/]*) # absolute file, and not a UNC file
+      if test -z "$file_conv"; then
+	# lazily determine how to convert abs files
+	case `uname -s` in
+	  MINGW*)
+	    file_conv=mingw
+	    ;;
+	  CYGWIN*)
+	    file_conv=cygwin
+	    ;;
+	  *)
+	    file_conv=wine
+	    ;;
+	esac
+      fi
+      case $file_conv in
+	mingw)
+	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
+	  ;;
+	cygwin)
+	  file=`cygpath -m "$file" || echo "$file"`
+	  ;;
+	wine)
+	  file=`winepath -w "$file" || echo "$file"`
+	  ;;
+      esac
+      ;;
+  esac
+}
+
+# func_at_file at_file operation archive
+# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE
+# for each of them.
+# When interpreting the content of the @FILE, do NOT use func_file_conv,
+# since the user would need to supply preconverted file names to
+# binutils ar, at least for MinGW.
+func_at_file ()
+{
+  operation=$2
+  archive=$3
+  at_file_contents=`cat "$1"`
+  eval set x "$at_file_contents"
+  shift
+
+  for member
+  do
+    $AR -NOLOGO $operation:"$member" "$archive" || exit $?
+  done
+}
+
+case $1 in
+  '')
+     func_error "no command.  Try '$0 --help' for more information."
+     ;;
+  -h | --h*)
+    cat <<EOF
+Usage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]
+
+Members may be specified in a file named with @FILE.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "$me, version $scriptversion"
+    exit $?
+    ;;
+esac
+
+if test $# -lt 3; then
+  func_error "you must specify a program, an action and an archive"
+fi
+
+AR=$1
+shift
+while :
+do
+  if test $# -lt 2; then
+    func_error "you must specify a program, an action and an archive"
+  fi
+  case $1 in
+    -lib | -LIB \
+    | -ltcg | -LTCG \
+    | -machine* | -MACHINE* \
+    | -subsystem* | -SUBSYSTEM* \
+    | -verbose | -VERBOSE \
+    | -wx* | -WX* )
+      AR="$AR $1"
+      shift
+      ;;
+    *)
+      action=$1
+      shift
+      break
+      ;;
+  esac
+done
+orig_archive=$1
+shift
+func_file_conv "$orig_archive"
+archive=$file
+
+# strip leading dash in $action
+action=${action#-}
+
+delete=
+extract=
+list=
+quick=
+replace=
+index=
+create=
+
+while test -n "$action"
+do
+  case $action in
+    d*) delete=yes  ;;
+    x*) extract=yes ;;
+    t*) list=yes    ;;
+    q*) quick=yes   ;;
+    r*) replace=yes ;;
+    s*) index=yes   ;;
+    S*)             ;; # the index is always updated implicitly
+    c*) create=yes  ;;
+    u*)             ;; # TODO: don't ignore the update modifier
+    v*)             ;; # TODO: don't ignore the verbose modifier
+    *)
+      func_error "unknown action specified"
+      ;;
+  esac
+  action=${action#?}
+done
+
+case $delete$extract$list$quick$replace,$index in
+  yes,* | ,yes)
+    ;;
+  yesyes*)
+    func_error "more than one action specified"
+    ;;
+  *)
+    func_error "no action specified"
+    ;;
+esac
+
+if test -n "$delete"; then
+  if test ! -f "$orig_archive"; then
+    func_error "archive not found"
+  fi
+  for member
+  do
+    case $1 in
+      @*)
+        func_at_file "${1#@}" -REMOVE "$archive"
+        ;;
+      *)
+        func_file_conv "$1"
+        $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
+        ;;
+    esac
+  done
+
+elif test -n "$extract"; then
+  if test ! -f "$orig_archive"; then
+    func_error "archive not found"
+  fi
+  if test $# -gt 0; then
+    for member
+    do
+      case $1 in
+        @*)
+          func_at_file "${1#@}" -EXTRACT "$archive"
+          ;;
+        *)
+          func_file_conv "$1"
+          $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
+          ;;
+      esac
+    done
+  else
+    $AR -NOLOGO -LIST "$archive" | sed -e 's/\\/\\\\/g' | while read member
+    do
+      $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
+    done
+  fi
+
+elif test -n "$quick$replace"; then
+  if test ! -f "$orig_archive"; then
+    if test -z "$create"; then
+      echo "$me: creating $orig_archive"
+    fi
+    orig_archive=
+  else
+    orig_archive=$archive
+  fi
+
+  for member
+  do
+    case $1 in
+    @*)
+      func_file_conv "${1#@}"
+      set x "$@" "@$file"
+      ;;
+    *)
+      func_file_conv "$1"
+      set x "$@" "$file"
+      ;;
+    esac
+    shift
+    shift
+  done
+
+  if test -n "$orig_archive"; then
+    $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
+  else
+    $AR -NOLOGO -OUT:"$archive" "$@" || exit $?
+  fi
+
+elif test -n "$list"; then
+  if test ! -f "$orig_archive"; then
+    func_error "archive not found"
+  fi
+  $AR -NOLOGO -LIST "$archive" || exit $?
+fi

diff --git a/autogen.sh b/autogen.sh
index 4313a84..04b74c3 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -5,9 +5,6 @@ v() { echo "$@"; "$@"; }
 m4dir="autotools/m4"
 
 v rm -rf autotools
-if [[ $1 != "--from=make" ]] ; then
-	v ${MAKE:-make} autotools-update
-fi
 
 # reload the gnulib code if possible
 PATH=/usr/local/src/gnu/gnulib:${PATH}
@@ -50,7 +47,3 @@ done
 
 export AUTOMAKE="automake --foreign"
 v autoreconf -i -f
-
-if [[ -x ./test.sh ]] ; then
-	exec ./test.sh "$@"
-fi

diff --git a/compile b/compile
new file mode 100755
index 0000000..2ab71e4
--- /dev/null
+++ b/compile
@@ -0,0 +1,348 @@
+#! /bin/sh
+# Wrapper for compilers which do not understand '-c -o'.
+
+scriptversion=2016-01-11.22; # UTC
+
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+# Written by Tom Tromey <tromey@cygnus.com>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to <bug-automake@gnu.org> or send patches to
+# <automake-patches@gnu.org>.
+
+nl='
+'
+
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent tools from complaining about whitespace usage.
+IFS=" ""	$nl"
+
+file_conv=
+
+# func_file_conv build_file lazy
+# Convert a $build file to $host form and store it in $file
+# Currently only supports Windows hosts. If the determined conversion
+# type is listed in (the comma separated) LAZY, no conversion will
+# take place.
+func_file_conv ()
+{
+  file=$1
+  case $file in
+    / | /[!/]*) # absolute file, and not a UNC file
+      if test -z "$file_conv"; then
+	# lazily determine how to convert abs files
+	case `uname -s` in
+	  MINGW*)
+	    file_conv=mingw
+	    ;;
+	  CYGWIN*)
+	    file_conv=cygwin
+	    ;;
+	  *)
+	    file_conv=wine
+	    ;;
+	esac
+      fi
+      case $file_conv/,$2, in
+	*,$file_conv,*)
+	  ;;
+	mingw/*)
+	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
+	  ;;
+	cygwin/*)
+	  file=`cygpath -m "$file" || echo "$file"`
+	  ;;
+	wine/*)
+	  file=`winepath -w "$file" || echo "$file"`
+	  ;;
+      esac
+      ;;
+  esac
+}
+
+# func_cl_dashL linkdir
+# Make cl look for libraries in LINKDIR
+func_cl_dashL ()
+{
+  func_file_conv "$1"
+  if test -z "$lib_path"; then
+    lib_path=$file
+  else
+    lib_path="$lib_path;$file"
+  fi
+  linker_opts="$linker_opts -LIBPATH:$file"
+}
+
+# func_cl_dashl library
+# Do a library search-path lookup for cl
+func_cl_dashl ()
+{
+  lib=$1
+  found=no
+  save_IFS=$IFS
+  IFS=';'
+  for dir in $lib_path $LIB
+  do
+    IFS=$save_IFS
+    if $shared && test -f "$dir/$lib.dll.lib"; then
+      found=yes
+      lib=$dir/$lib.dll.lib
+      break
+    fi
+    if test -f "$dir/$lib.lib"; then
+      found=yes
+      lib=$dir/$lib.lib
+      break
+    fi
+    if test -f "$dir/lib$lib.a"; then
+      found=yes
+      lib=$dir/lib$lib.a
+      break
+    fi
+  done
+  IFS=$save_IFS
+
+  if test "$found" != yes; then
+    lib=$lib.lib
+  fi
+}
+
+# func_cl_wrapper cl arg...
+# Adjust compile command to suit cl
+func_cl_wrapper ()
+{
+  # Assume a capable shell
+  lib_path=
+  shared=:
+  linker_opts=
+  for arg
+  do
+    if test -n "$eat"; then
+      eat=
+    else
+      case $1 in
+	-o)
+	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
+	  eat=1
+	  case $2 in
+	    *.o | *.[oO][bB][jJ])
+	      func_file_conv "$2"
+	      set x "$@" -Fo"$file"
+	      shift
+	      ;;
+	    *)
+	      func_file_conv "$2"
+	      set x "$@" -Fe"$file"
+	      shift
+	      ;;
+	  esac
+	  ;;
+	-I)
+	  eat=1
+	  func_file_conv "$2" mingw
+	  set x "$@" -I"$file"
+	  shift
+	  ;;
+	-I*)
+	  func_file_conv "${1#-I}" mingw
+	  set x "$@" -I"$file"
+	  shift
+	  ;;
+	-l)
+	  eat=1
+	  func_cl_dashl "$2"
+	  set x "$@" "$lib"
+	  shift
+	  ;;
+	-l*)
+	  func_cl_dashl "${1#-l}"
+	  set x "$@" "$lib"
+	  shift
+	  ;;
+	-L)
+	  eat=1
+	  func_cl_dashL "$2"
+	  ;;
+	-L*)
+	  func_cl_dashL "${1#-L}"
+	  ;;
+	-static)
+	  shared=false
+	  ;;
+	-Wl,*)
+	  arg=${1#-Wl,}
+	  save_ifs="$IFS"; IFS=','
+	  for flag in $arg; do
+	    IFS="$save_ifs"
+	    linker_opts="$linker_opts $flag"
+	  done
+	  IFS="$save_ifs"
+	  ;;
+	-Xlinker)
+	  eat=1
+	  linker_opts="$linker_opts $2"
+	  ;;
+	-*)
+	  set x "$@" "$1"
+	  shift
+	  ;;
+	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
+	  func_file_conv "$1"
+	  set x "$@" -Tp"$file"
+	  shift
+	  ;;
+	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
+	  func_file_conv "$1" mingw
+	  set x "$@" "$file"
+	  shift
+	  ;;
+	*)
+	  set x "$@" "$1"
+	  shift
+	  ;;
+      esac
+    fi
+    shift
+  done
+  if test -n "$linker_opts"; then
+    linker_opts="-link$linker_opts"
+  fi
+  exec "$@" $linker_opts
+  exit 1
+}
+
+eat=
+
+case $1 in
+  '')
+     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: compile [--help] [--version] PROGRAM [ARGS]
+
+Wrapper for compilers which do not understand '-c -o'.
+Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
+arguments, and rename the output as expected.
+
+If you are trying to build a whole package this is not the
+right script to run: please start by reading the file 'INSTALL'.
+
+Report bugs to <bug-automake@gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "compile $scriptversion"
+    exit $?
+    ;;
+  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
+  icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
+    func_cl_wrapper "$@"      # Doesn't return...
+    ;;
+esac
+
+ofile=
+cfile=
+
+for arg
+do
+  if test -n "$eat"; then
+    eat=
+  else
+    case $1 in
+      -o)
+	# configure might choose to run compile as 'compile cc -o foo foo.c'.
+	# So we strip '-o arg' only if arg is an object.
+	eat=1
+	case $2 in
+	  *.o | *.obj)
+	    ofile=$2
+	    ;;
+	  *)
+	    set x "$@" -o "$2"
+	    shift
+	    ;;
+	esac
+	;;
+      *.c)
+	cfile=$1
+	set x "$@" "$1"
+	shift
+	;;
+      *)
+	set x "$@" "$1"
+	shift
+	;;
+    esac
+  fi
+  shift
+done
+
+if test -z "$ofile" || test -z "$cfile"; then
+  # If no '-o' option was seen then we might have been invoked from a
+  # pattern rule where we don't need one.  That is ok -- this is a
+  # normal compilation that the losing compiler can handle.  If no
+  # '.c' file was seen then we are probably linking.  That is also
+  # ok.
+  exec "$@"
+fi
+
+# Name of file we expect compiler to create.
+cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
+
+# Create the lock directory.
+# Note: use '[/\\:.-]' here to ensure that we don't use the same name
+# that we are using for the .o file.  Also, base the name on the expected
+# object file name, since that is what matters with a parallel build.
+lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
+while true; do
+  if mkdir "$lockdir" >/dev/null 2>&1; then
+    break
+  fi
+  sleep 1
+done
+# FIXME: race condition here if user kills between mkdir and trap.
+trap "rmdir '$lockdir'; exit 1" 1 2 15
+
+# Run the compile.
+"$@"
+ret=$?
+
+if test -f "$cofile"; then
+  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
+elif test -f "${cofile}bj"; then
+  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
+fi
+
+rmdir "$lockdir"
+exit $ret
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC0"
+# time-stamp-end: "; # UTC"
+# End:

diff --git a/config.guess b/config.guess
new file mode 100755
index 0000000..3ecb90b
--- /dev/null
+++ b/config.guess
@@ -0,0 +1,1477 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+#   Copyright 1992-2018 Free Software Foundation, Inc.
+
+timestamp='2018-01-01'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <https://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that
+# program.  This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
+#
+# Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
+#
+# You can get the latest version of this script from:
+# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
+#
+# Please send patches to <config-patches@gnu.org>.
+
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Options:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright 1992-2018 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help" >&2
+       exit 1 ;;
+    * )
+       break ;;
+  esac
+done
+
+if test $# != 0; then
+  echo "$me: too many arguments$help" >&2
+  exit 1
+fi
+
+trap 'exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
+# compiler to aid in system detection is discouraged as it requires
+# temporary files to be created and, as you can see below, it is a
+# headache to deal with in a portable fashion.
+
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+# Portable tmp directory creation inspired by the Autoconf team.
+
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
+case $CC_FOR_BUILD,$HOST_CC,$CC in
+ ,,)    echo "int x;" > $dummy.c ;
+	for c in cc gcc c89 c99 ; do
+	  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
+	     CC_FOR_BUILD="$c"; break ;
+	  fi ;
+	done ;
+	if test x"$CC_FOR_BUILD" = x ; then
+	  CC_FOR_BUILD=no_compiler_found ;
+	fi
+	;;
+ ,,*)   CC_FOR_BUILD=$CC ;;
+ ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
+esac ; set_cc_for_build= ;'
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi@noc.rutgers.edu 1994-08-24)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+	PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+case "${UNAME_SYSTEM}" in
+Linux|GNU|GNU/*)
+	# If the system lacks a compiler, then just pick glibc.
+	# We could probably try harder.
+	LIBC=gnu
+
+	eval $set_cc_for_build
+	cat <<-EOF > $dummy.c
+	#include <features.h>
+	#if defined(__UCLIBC__)
+	LIBC=uclibc
+	#elif defined(__dietlibc__)
+	LIBC=dietlibc
+	#else
+	LIBC=gnu
+	#endif
+	EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`
+	;;
+esac
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+    *:NetBSD:*:*)
+	# NetBSD (nbsd) targets should (where applicable) match one or
+	# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
+	# *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
+	# switched to ELF, *-*-netbsd* would select the old
+	# object file format.  This provides both forward
+	# compatibility and a consistent mechanism for selecting the
+	# object file format.
+	#
+	# Note: NetBSD doesn't particularly care about the vendor
+	# portion of the name.  We always set it to "unknown".
+	sysctl="sysctl -n hw.machine_arch"
+	UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \
+	    /sbin/$sysctl 2>/dev/null || \
+	    /usr/sbin/$sysctl 2>/dev/null || \
+	    echo unknown)`
+	case "${UNAME_MACHINE_ARCH}" in
+	    armeb) machine=armeb-unknown ;;
+	    arm*) machine=arm-unknown ;;
+	    sh3el) machine=shl-unknown ;;
+	    sh3eb) machine=sh-unknown ;;
+	    sh5el) machine=sh5le-unknown ;;
+	    earmv*)
+		arch=`echo ${UNAME_MACHINE_ARCH} | sed -e 's,^e\(armv[0-9]\).*$,\1,'`
+		endian=`echo ${UNAME_MACHINE_ARCH} | sed -ne 's,^.*\(eb\)$,\1,p'`
+		machine=${arch}${endian}-unknown
+		;;
+	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+	esac
+	# The Operating System including object format, if it has switched
+	# to ELF recently (or will in the future) and ABI.
+	case "${UNAME_MACHINE_ARCH}" in
+	    earm*)
+		os=netbsdelf
+		;;
+	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
+		eval $set_cc_for_build
+		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+			| grep -q __ELF__
+		then
+		    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+		    # Return netbsd for either.  FIX?
+		    os=netbsd
+		else
+		    os=netbsdelf
+		fi
+		;;
+	    *)
+		os=netbsd
+		;;
+	esac
+	# Determine ABI tags.
+	case "${UNAME_MACHINE_ARCH}" in
+	    earm*)
+		expr='s/^earmv[0-9]/-eabi/;s/eb$//'
+		abi=`echo ${UNAME_MACHINE_ARCH} | sed -e "$expr"`
+		;;
+	esac
+	# The OS release
+	# Debian GNU/NetBSD machines have a different userland, and
+	# thus, need a distinct triplet. However, they do not need
+	# kernel version information, so it can be replaced with a
+	# suitable tag, in the style of linux-gnu.
+	case "${UNAME_VERSION}" in
+	    Debian*)
+		release='-gnu'
+		;;
+	    *)
+		release=`echo ${UNAME_RELEASE} | sed -e 's/[-_].*//' | cut -d. -f1,2`
+		;;
+	esac
+	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+	# contains redundant information, the shorter form:
+	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+	echo "${machine}-${os}${release}${abi}"
+	exit ;;
+    *:Bitrig:*:*)
+	UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE}
+	exit ;;
+    *:OpenBSD:*:*)
+	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+	exit ;;
+    *:LibertyBSD:*:*)
+	UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-libertybsd${UNAME_RELEASE}
+	exit ;;
+    *:MidnightBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-midnightbsd${UNAME_RELEASE}
+	exit ;;
+    *:ekkoBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
+	exit ;;
+    *:SolidBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
+	exit ;;
+    macppc:MirBSD:*:*)
+	echo powerpc-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    *:MirBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    *:Sortix:*:*)
+	echo ${UNAME_MACHINE}-unknown-sortix
+	exit ;;
+    *:Redox:*:*)
+	echo ${UNAME_MACHINE}-unknown-redox
+	exit ;;
+    mips:OSF1:*.*)
+        echo mips-dec-osf1
+        exit ;;
+    alpha:OSF1:*:*)
+	case $UNAME_RELEASE in
+	*4.0)
+		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+		;;
+	*5.*)
+		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+		;;
+	esac
+	# According to Compaq, /usr/sbin/psrinfo has been available on
+	# OSF/1 and Tru64 systems produced since 1995.  I hope that
+	# covers most systems running today.  This code pipes the CPU
+	# types through head -n 1, so we only detect the type of CPU 0.
+	ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+	case "$ALPHA_CPU_TYPE" in
+	    "EV4 (21064)")
+		UNAME_MACHINE=alpha ;;
+	    "EV4.5 (21064)")
+		UNAME_MACHINE=alpha ;;
+	    "LCA4 (21066/21068)")
+		UNAME_MACHINE=alpha ;;
+	    "EV5 (21164)")
+		UNAME_MACHINE=alphaev5 ;;
+	    "EV5.6 (21164A)")
+		UNAME_MACHINE=alphaev56 ;;
+	    "EV5.6 (21164PC)")
+		UNAME_MACHINE=alphapca56 ;;
+	    "EV5.7 (21164PC)")
+		UNAME_MACHINE=alphapca57 ;;
+	    "EV6 (21264)")
+		UNAME_MACHINE=alphaev6 ;;
+	    "EV6.7 (21264A)")
+		UNAME_MACHINE=alphaev67 ;;
+	    "EV6.8CB (21264C)")
+		UNAME_MACHINE=alphaev68 ;;
+	    "EV6.8AL (21264B)")
+		UNAME_MACHINE=alphaev68 ;;
+	    "EV6.8CX (21264D)")
+		UNAME_MACHINE=alphaev68 ;;
+	    "EV6.9A (21264/EV69A)")
+		UNAME_MACHINE=alphaev69 ;;
+	    "EV7 (21364)")
+		UNAME_MACHINE=alphaev7 ;;
+	    "EV7.9 (21364A)")
+		UNAME_MACHINE=alphaev79 ;;
+	esac
+	# A Pn.n version is a patched version.
+	# A Vn.n version is a released version.
+	# A Tn.n version is a released field test version.
+	# A Xn.n version is an unreleased experimental baselevel.
+	# 1.2 uses "1.2" for uname -r.
+	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
+	# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
+	exitcode=$?
+	trap '' 0
+	exit $exitcode ;;
+    Amiga*:UNIX_System_V:4.0:*)
+	echo m68k-unknown-sysv4
+	exit ;;
+    *:[Aa]miga[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-amigaos
+	exit ;;
+    *:[Mm]orph[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-morphos
+	exit ;;
+    *:OS/390:*:*)
+	echo i370-ibm-openedition
+	exit ;;
+    *:z/VM:*:*)
+	echo s390-ibm-zvmoe
+	exit ;;
+    *:OS400:*:*)
+	echo powerpc-ibm-os400
+	exit ;;
+    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+	echo arm-acorn-riscix${UNAME_RELEASE}
+	exit ;;
+    arm*:riscos:*:*|arm*:RISCOS:*:*)
+	echo arm-unknown-riscos
+	exit ;;
+    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
+	echo hppa1.1-hitachi-hiuxmpp
+	exit ;;
+    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+	# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+	if test "`(/bin/universe) 2>/dev/null`" = att ; then
+		echo pyramid-pyramid-sysv3
+	else
+		echo pyramid-pyramid-bsd
+	fi
+	exit ;;
+    NILE*:*:*:dcosx)
+	echo pyramid-pyramid-svr4
+	exit ;;
+    DRS?6000:unix:4.0:6*)
+	echo sparc-icl-nx6
+	exit ;;
+    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
+	case `/usr/bin/uname -p` in
+	    sparc) echo sparc-icl-nx7; exit ;;
+	esac ;;
+    s390x:SunOS:*:*)
+	echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4H:SunOS:5.*:*)
+	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
+	echo i386-pc-auroraux${UNAME_RELEASE}
+	exit ;;
+    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
+	eval $set_cc_for_build
+	SUN_ARCH=i386
+	# If there is a compiler, see if it is configured for 64-bit objects.
+	# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
+	# This test works for both compilers.
+	if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
+	    if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
+		(CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
+		grep IS_64BIT_ARCH >/dev/null
+	    then
+		SUN_ARCH=x86_64
+	    fi
+	fi
+	echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:6*:*)
+	# According to config.sub, this is the proper way to canonicalize
+	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
+	# it's likely to be more like Solaris than SunOS4.
+	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:*:*)
+	case "`/usr/bin/arch -k`" in
+	    Series*|S4*)
+		UNAME_RELEASE=`uname -v`
+		;;
+	esac
+	# Japanese Language versions have a version number like `4.1.3-JL'.
+	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+	exit ;;
+    sun3*:SunOS:*:*)
+	echo m68k-sun-sunos${UNAME_RELEASE}
+	exit ;;
+    sun*:*:4.2BSD:*)
+	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+	test "x${UNAME_RELEASE}" = x && UNAME_RELEASE=3
+	case "`/bin/arch`" in
+	    sun3)
+		echo m68k-sun-sunos${UNAME_RELEASE}
+		;;
+	    sun4)
+		echo sparc-sun-sunos${UNAME_RELEASE}
+		;;
+	esac
+	exit ;;
+    aushp:SunOS:*:*)
+	echo sparc-auspex-sunos${UNAME_RELEASE}
+	exit ;;
+    # The situation for MiNT is a little confusing.  The machine name
+    # can be virtually everything (everything which is not
+    # "atarist" or "atariste" at least should have a processor
+    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
+    # to the lowercase version "mint" (or "freemint").  Finally
+    # the system name "TOS" denotes a system which is actually not
+    # MiNT.  But MiNT is downward compatible to TOS, so this should
+    # be no problem.
+    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+	echo m68k-milan-mint${UNAME_RELEASE}
+	exit ;;
+    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+	echo m68k-hades-mint${UNAME_RELEASE}
+	exit ;;
+    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+	echo m68k-unknown-mint${UNAME_RELEASE}
+	exit ;;
+    m68k:machten:*:*)
+	echo m68k-apple-machten${UNAME_RELEASE}
+	exit ;;
+    powerpc:machten:*:*)
+	echo powerpc-apple-machten${UNAME_RELEASE}
+	exit ;;
+    RISC*:Mach:*:*)
+	echo mips-dec-mach_bsd4.3
+	exit ;;
+    RISC*:ULTRIX:*:*)
+	echo mips-dec-ultrix${UNAME_RELEASE}
+	exit ;;
+    VAX*:ULTRIX*:*:*)
+	echo vax-dec-ultrix${UNAME_RELEASE}
+	exit ;;
+    2020:CLIX:*:* | 2430:CLIX:*:*)
+	echo clipper-intergraph-clix${UNAME_RELEASE}
+	exit ;;
+    mips:*:*:UMIPS | mips:*:*:RISCos)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+	int main (int argc, char *argv[]) {
+#else
+	int main (argc, argv) int argc; char *argv[]; {
+#endif
+	#if defined (host_mips) && defined (MIPSEB)
+	#if defined (SYSTYPE_SYSV)
+	  printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_SVR4)
+	  printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+	  printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0);
+	#endif
+	#endif
+	  exit (-1);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c &&
+	  dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
+	  SYSTEM_NAME=`$dummy $dummyarg` &&
+	    { echo "$SYSTEM_NAME"; exit; }
+	echo mips-mips-riscos${UNAME_RELEASE}
+	exit ;;
+    Motorola:PowerMAX_OS:*:*)
+	echo powerpc-motorola-powermax
+	exit ;;
+    Motorola:*:4.3:PL8-*)
+	echo powerpc-harris-powermax
+	exit ;;
+    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
+	echo powerpc-harris-powermax
+	exit ;;
+    Night_Hawk:Power_UNIX:*:*)
+	echo powerpc-harris-powerunix
+	exit ;;
+    m88k:CX/UX:7*:*)
+	echo m88k-harris-cxux7
+	exit ;;
+    m88k:*:4*:R4*)
+	echo m88k-motorola-sysv4
+	exit ;;
+    m88k:*:3*:R3*)
+	echo m88k-motorola-sysv3
+	exit ;;
+    AViiON:dgux:*:*)
+	# DG/UX returns AViiON for all architectures
+	UNAME_PROCESSOR=`/usr/bin/uname -p`
+	if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+	then
+	    if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+	       [ ${TARGET_BINARY_INTERFACE}x = x ]
+	    then
+		echo m88k-dg-dgux${UNAME_RELEASE}
+	    else
+		echo m88k-dg-dguxbcs${UNAME_RELEASE}
+	    fi
+	else
+	    echo i586-dg-dgux${UNAME_RELEASE}
+	fi
+	exit ;;
+    M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
+	echo m88k-dolphin-sysv3
+	exit ;;
+    M88*:*:R3*:*)
+	# Delta 88k system running SVR3
+	echo m88k-motorola-sysv3
+	exit ;;
+    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+	echo m88k-tektronix-sysv3
+	exit ;;
+    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+	echo m68k-tektronix-bsd
+	exit ;;
+    *:IRIX*:*:*)
+	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+	exit ;;
+    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+	echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
+	exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
+    i*86:AIX:*:*)
+	echo i386-ibm-aix
+	exit ;;
+    ia64:AIX:*:*)
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
+	exit ;;
+    *:AIX:2:3)
+	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+		eval $set_cc_for_build
+		sed 's/^		//' << EOF >$dummy.c
+		#include <sys/systemcfg.h>
+
+		main()
+			{
+			if (!__power_pc())
+				exit(1);
+			puts("powerpc-ibm-aix3.2.5");
+			exit(0);
+			}
+EOF
+		if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
+		then
+			echo "$SYSTEM_NAME"
+		else
+			echo rs6000-ibm-aix3.2.5
+		fi
+	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+		echo rs6000-ibm-aix3.2.4
+	else
+		echo rs6000-ibm-aix3.2
+	fi
+	exit ;;
+    *:AIX:*:[4567])
+	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
+	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
+		IBM_ARCH=rs6000
+	else
+		IBM_ARCH=powerpc
+	fi
+	if [ -x /usr/bin/lslpp ] ; then
+		IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc |
+			   awk -F: '{ print $3 }' | sed s/[0-9]*$/0/`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+	exit ;;
+    *:AIX:*:*)
+	echo rs6000-ibm-aix
+	exit ;;
+    ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*)
+	echo romp-ibm-bsd4.4
+	exit ;;
+    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
+	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
+	exit ;;                             # report: romp-ibm BSD 4.3
+    *:BOSX:*:*)
+	echo rs6000-bull-bosx
+	exit ;;
+    DPX/2?00:B.O.S.:*:*)
+	echo m68k-bull-sysv3
+	exit ;;
+    9000/[34]??:4.3bsd:1.*:*)
+	echo m68k-hp-bsd
+	exit ;;
+    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+	echo m68k-hp-bsd4.4
+	exit ;;
+    9000/[34678]??:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	case "${UNAME_MACHINE}" in
+	    9000/31?)            HP_ARCH=m68000 ;;
+	    9000/[34]??)         HP_ARCH=m68k ;;
+	    9000/[678][0-9][0-9])
+		if [ -x /usr/bin/getconf ]; then
+		    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
+		    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+		    case "${sc_cpu_version}" in
+		      523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0
+		      528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1
+		      532)                      # CPU_PA_RISC2_0
+			case "${sc_kernel_bits}" in
+			  32) HP_ARCH=hppa2.0n ;;
+			  64) HP_ARCH=hppa2.0w ;;
+			  '') HP_ARCH=hppa2.0 ;;   # HP-UX 10.20
+			esac ;;
+		    esac
+		fi
+		if [ "${HP_ARCH}" = "" ]; then
+		    eval $set_cc_for_build
+		    sed 's/^		//' << EOF >$dummy.c
+
+		#define _HPUX_SOURCE
+		#include <stdlib.h>
+		#include <unistd.h>
+
+		int main ()
+		{
+		#if defined(_SC_KERNEL_BITS)
+		    long bits = sysconf(_SC_KERNEL_BITS);
+		#endif
+		    long cpu  = sysconf (_SC_CPU_VERSION);
+
+		    switch (cpu)
+			{
+			case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+			case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+			case CPU_PA_RISC2_0:
+		#if defined(_SC_KERNEL_BITS)
+			    switch (bits)
+				{
+				case 64: puts ("hppa2.0w"); break;
+				case 32: puts ("hppa2.0n"); break;
+				default: puts ("hppa2.0"); break;
+				} break;
+		#else  /* !defined(_SC_KERNEL_BITS) */
+			    puts ("hppa2.0"); break;
+		#endif
+			default: puts ("hppa1.0"); break;
+			}
+		    exit (0);
+		}
+EOF
+		    (CCOPTS="" $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+		    test -z "$HP_ARCH" && HP_ARCH=hppa
+		fi ;;
+	esac
+	if [ ${HP_ARCH} = hppa2.0w ]
+	then
+	    eval $set_cc_for_build
+
+	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
+	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
+	    # generating 64-bit code.  GNU and HP use different nomenclature:
+	    #
+	    # $ CC_FOR_BUILD=cc ./config.guess
+	    # => hppa2.0w-hp-hpux11.23
+	    # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
+	    # => hppa64-hp-hpux11.23
+
+	    if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) |
+		grep -q __LP64__
+	    then
+		HP_ARCH=hppa2.0w
+	    else
+		HP_ARCH=hppa64
+	    fi
+	fi
+	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+	exit ;;
+    ia64:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	echo ia64-hp-hpux${HPUX_REV}
+	exit ;;
+    3050*:HI-UX:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <unistd.h>
+	int
+	main ()
+	{
+	  long cpu = sysconf (_SC_CPU_VERSION);
+	  /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+	     true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
+	     results, however.  */
+	  if (CPU_IS_PA_RISC (cpu))
+	    {
+	      switch (cpu)
+		{
+		  case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+		  default: puts ("hppa-hitachi-hiuxwe2"); break;
+		}
+	    }
+	  else if (CPU_IS_HP_MC68K (cpu))
+	    puts ("m68k-hitachi-hiuxwe2");
+	  else puts ("unknown-hitachi-hiuxwe2");
+	  exit (0);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
+		{ echo "$SYSTEM_NAME"; exit; }
+	echo unknown-hitachi-hiuxwe2
+	exit ;;
+    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*)
+	echo hppa1.1-hp-bsd
+	exit ;;
+    9000/8??:4.3bsd:*:*)
+	echo hppa1.0-hp-bsd
+	exit ;;
+    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
+	echo hppa1.0-hp-mpeix
+	exit ;;
+    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*)
+	echo hppa1.1-hp-osf
+	exit ;;
+    hp8??:OSF1:*:*)
+	echo hppa1.0-hp-osf
+	exit ;;
+    i*86:OSF1:*:*)
+	if [ -x /usr/sbin/sysversion ] ; then
+	    echo ${UNAME_MACHINE}-unknown-osf1mk
+	else
+	    echo ${UNAME_MACHINE}-unknown-osf1
+	fi
+	exit ;;
+    parisc*:Lites*:*:*)
+	echo hppa1.1-hp-lites
+	exit ;;
+    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+	echo c1-convex-bsd
+	exit ;;
+    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+	if getsysinfo -f scalar_acc
+	then echo c32-convex-bsd
+	else echo c2-convex-bsd
+	fi
+	exit ;;
+    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+	echo c34-convex-bsd
+	exit ;;
+    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+	echo c38-convex-bsd
+	exit ;;
+    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+	echo c4-convex-bsd
+	exit ;;
+    CRAY*Y-MP:*:*:*)
+	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*[A-Z]90:*:*:*)
+	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
+	      -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*TS:*:*:*)
+	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*T3E:*:*:*)
+	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*SV1:*:*:*)
+	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    *:UNICOS/mp:*:*)
+	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
+	FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
+	FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
+	FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+	echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	exit ;;
+    5000:UNIX_System_V:4.*:*)
+	FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
+	FUJITSU_REL=`echo ${UNAME_RELEASE} | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'`
+	echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	exit ;;
+    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+	exit ;;
+    sparc*:BSD/OS:*:*)
+	echo sparc-unknown-bsdi${UNAME_RELEASE}
+	exit ;;
+    *:BSD/OS:*:*)
+	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+	exit ;;
+    *:FreeBSD:*:*)
+	UNAME_PROCESSOR=`/usr/bin/uname -p`
+	case ${UNAME_PROCESSOR} in
+	    amd64)
+		UNAME_PROCESSOR=x86_64 ;;
+	    i386)
+		UNAME_PROCESSOR=i586 ;;
+	esac
+	echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+	exit ;;
+    i*:CYGWIN*:*)
+	echo ${UNAME_MACHINE}-pc-cygwin
+	exit ;;
+    *:MINGW64*:*)
+	echo ${UNAME_MACHINE}-pc-mingw64
+	exit ;;
+    *:MINGW*:*)
+	echo ${UNAME_MACHINE}-pc-mingw32
+	exit ;;
+    *:MSYS*:*)
+	echo ${UNAME_MACHINE}-pc-msys
+	exit ;;
+    i*:PW*:*)
+	echo ${UNAME_MACHINE}-pc-pw32
+	exit ;;
+    *:Interix*:*)
+	case ${UNAME_MACHINE} in
+	    x86)
+		echo i586-pc-interix${UNAME_RELEASE}
+		exit ;;
+	    authenticamd | genuineintel | EM64T)
+		echo x86_64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	    IA64)
+		echo ia64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	esac ;;
+    i*:UWIN*:*)
+	echo ${UNAME_MACHINE}-pc-uwin
+	exit ;;
+    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+	echo x86_64-unknown-cygwin
+	exit ;;
+    prep*:SunOS:5.*:*)
+	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    *:GNU:*:*)
+	# the GNU system
+	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+	exit ;;
+    *:GNU/*:*:*)
+	# other systems with GNU libc and userland
+	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
+	exit ;;
+    i*86:Minix:*:*)
+	echo ${UNAME_MACHINE}-pc-minix
+	exit ;;
+    aarch64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    aarch64_be:Linux:*:*)
+	UNAME_MACHINE=aarch64_be
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    alpha:Linux:*:*)
+	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+	  EV5)   UNAME_MACHINE=alphaev5 ;;
+	  EV56)  UNAME_MACHINE=alphaev56 ;;
+	  PCA56) UNAME_MACHINE=alphapca56 ;;
+	  PCA57) UNAME_MACHINE=alphapca56 ;;
+	  EV6)   UNAME_MACHINE=alphaev6 ;;
+	  EV67)  UNAME_MACHINE=alphaev67 ;;
+	  EV68*) UNAME_MACHINE=alphaev68 ;;
+	esac
+	objdump --private-headers /bin/sh | grep -q ld.so.1
+	if test "$?" = 0 ; then LIBC=gnulibc1 ; fi
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    arc:Linux:*:* | arceb:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    arm*:Linux:*:*)
+	eval $set_cc_for_build
+	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
+	    | grep -q __ARM_EABI__
+	then
+	    echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	else
+	    if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
+		| grep -q __ARM_PCS_VFP
+	    then
+		echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi
+	    else
+		echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf
+	    fi
+	fi
+	exit ;;
+    avr32*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    cris:Linux:*:*)
+	echo ${UNAME_MACHINE}-axis-linux-${LIBC}
+	exit ;;
+    crisv32:Linux:*:*)
+	echo ${UNAME_MACHINE}-axis-linux-${LIBC}
+	exit ;;
+    e2k:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    frv:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    hexagon:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    i*86:Linux:*:*)
+	echo ${UNAME_MACHINE}-pc-linux-${LIBC}
+	exit ;;
+    ia64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    k1om:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    m32r*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    m68*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    mips:Linux:*:* | mips64:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef ${UNAME_MACHINE}
+	#undef ${UNAME_MACHINE}el
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=${UNAME_MACHINE}el
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=${UNAME_MACHINE}
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
+	;;
+    mips64el:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    openrisc*:Linux:*:*)
+	echo or1k-unknown-linux-${LIBC}
+	exit ;;
+    or32:Linux:*:* | or1k*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    padre:Linux:*:*)
+	echo sparc-unknown-linux-${LIBC}
+	exit ;;
+    parisc64:Linux:*:* | hppa64:Linux:*:*)
+	echo hppa64-unknown-linux-${LIBC}
+	exit ;;
+    parisc:Linux:*:* | hppa:Linux:*:*)
+	# Look for CPU level
+	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
+	  PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
+	  PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
+	  *)    echo hppa-unknown-linux-${LIBC} ;;
+	esac
+	exit ;;
+    ppc64:Linux:*:*)
+	echo powerpc64-unknown-linux-${LIBC}
+	exit ;;
+    ppc:Linux:*:*)
+	echo powerpc-unknown-linux-${LIBC}
+	exit ;;
+    ppc64le:Linux:*:*)
+	echo powerpc64le-unknown-linux-${LIBC}
+	exit ;;
+    ppcle:Linux:*:*)
+	echo powerpcle-unknown-linux-${LIBC}
+	exit ;;
+    riscv32:Linux:*:* | riscv64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    s390:Linux:*:* | s390x:Linux:*:*)
+	echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
+	exit ;;
+    sh64*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    sh*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    sparc:Linux:*:* | sparc64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    tile*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    vax:Linux:*:*)
+	echo ${UNAME_MACHINE}-dec-linux-${LIBC}
+	exit ;;
+    x86_64:Linux:*:*)
+	eval $set_cc_for_build
+	X86_64_ABI=
+	# If there is a compiler, see if it is configured for 32-bit objects.
+	if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+	    if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \
+		(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+		grep IS_X32 >/dev/null
+	    then
+		X86_64_ABI=x32
+	    fi
+	fi
+	echo ${UNAME_MACHINE}-pc-linux-${LIBC}${X86_64_ABI}
+	exit ;;
+    xtensa*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    i*86:DYNIX/ptx:4*:*)
+	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
+	# earlier versions are messed up and put the nodename in both
+	# sysname and nodename.
+	echo i386-sequent-sysv4
+	exit ;;
+    i*86:UNIX_SV:4.2MP:2.*)
+	# Unixware is an offshoot of SVR4, but it has its own version
+	# number series starting with 2...
+	# I am not positive that other SVR4 systems won't match this,
+	# I just have to hope.  -- rms.
+	# Use sysv4.2uw... so that sysv4* matches it.
+	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+	exit ;;
+    i*86:OS/2:*:*)
+	# If we were able to find `uname', then EMX Unix compatibility
+	# is probably installed.
+	echo ${UNAME_MACHINE}-pc-os2-emx
+	exit ;;
+    i*86:XTS-300:*:STOP)
+	echo ${UNAME_MACHINE}-unknown-stop
+	exit ;;
+    i*86:atheos:*:*)
+	echo ${UNAME_MACHINE}-unknown-atheos
+	exit ;;
+    i*86:syllable:*:*)
+	echo ${UNAME_MACHINE}-pc-syllable
+	exit ;;
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
+	echo i386-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    i*86:*DOS:*:*)
+	echo ${UNAME_MACHINE}-pc-msdosdjgpp
+	exit ;;
+    i*86:*:4.*:*)
+	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+		echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+	else
+		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+	fi
+	exit ;;
+    i*86:*:5:[678]*)
+	# UnixWare 7.x, OpenUNIX and OpenServer 6.
+	case `/bin/uname -X | grep "^Machine"` in
+	    *486*)	     UNAME_MACHINE=i486 ;;
+	    *Pentium)	     UNAME_MACHINE=i586 ;;
+	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
+	esac
+	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
+	exit ;;
+    i*86:*:3.2:*)
+	if test -f /usr/options/cb.name; then
+		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+		echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+	elif /bin/uname -X 2>/dev/null >/dev/null ; then
+		UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
+		(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
+		(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
+			&& UNAME_MACHINE=i586
+		(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+	else
+		echo ${UNAME_MACHINE}-pc-sysv32
+	fi
+	exit ;;
+    pc:*:*:*)
+	# Left here for compatibility:
+	# uname -m prints for DJGPP always 'pc', but it prints nothing about
+	# the processor, so we play safe by assuming i586.
+	# Note: whatever this is, it MUST be the same as what config.sub
+	# prints for the "djgpp" host, or else GDB configure will decide that
+	# this is a cross-build.
+	echo i586-pc-msdosdjgpp
+	exit ;;
+    Intel:Mach:3*:*)
+	echo i386-pc-mach3
+	exit ;;
+    paragon:*:*:*)
+	echo i860-intel-osf1
+	exit ;;
+    i860:*:4.*:*) # i860-SVR4
+	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+	else # Add other i860-SVR4 vendors below as they are discovered.
+	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
+	fi
+	exit ;;
+    mini*:CTIX:SYS*5:*)
+	# "miniframe"
+	echo m68010-convergent-sysv
+	exit ;;
+    mc68k:UNIX:SYSTEM5:3.51m)
+	echo m68k-convergent-sysv
+	exit ;;
+    M680?0:D-NIX:5.3:*)
+	echo m68k-diab-dnix
+	exit ;;
+    M68*:*:R3V[5678]*:*)
+	test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
+    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
+	OS_REL=''
+	test -r /etc/.relid \
+	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	  && { echo i486-ncr-sysv4; exit; } ;;
+    NCR*:*:4.2:* | MPRAS*:*:4.2:*)
+	OS_REL='.3'
+	test -r /etc/.relid \
+	    && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	    && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
+	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
+	echo m68k-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    mc68030:UNIX_System_V:4.*:*)
+	echo m68k-atari-sysv4
+	exit ;;
+    TSUNAMI:LynxOS:2.*:*)
+	echo sparc-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    rs6000:LynxOS:2.*:*)
+	echo rs6000-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
+	echo powerpc-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    SM[BE]S:UNIX_SV:*:*)
+	echo mips-dde-sysv${UNAME_RELEASE}
+	exit ;;
+    RM*:ReliantUNIX-*:*:*)
+	echo mips-sni-sysv4
+	exit ;;
+    RM*:SINIX-*:*:*)
+	echo mips-sni-sysv4
+	exit ;;
+    *:SINIX-*:*:*)
+	if uname -p 2>/dev/null >/dev/null ; then
+		UNAME_MACHINE=`(uname -p) 2>/dev/null`
+		echo ${UNAME_MACHINE}-sni-sysv4
+	else
+		echo ns32k-sni-sysv
+	fi
+	exit ;;
+    PENTIUM:*:4.0*:*)	# Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+			# says <Richard.M.Bartel@ccMail.Census.GOV>
+	echo i586-unisys-sysv4
+	exit ;;
+    *:UNIX_System_V:4*:FTX*)
+	# From Gerald Hewes <hewes@openmarket.com>.
+	# How about differentiating between stratus architectures? -djm
+	echo hppa1.1-stratus-sysv4
+	exit ;;
+    *:*:*:FTX*)
+	# From seanf@swdc.stratus.com.
+	echo i860-stratus-sysv4
+	exit ;;
+    i*86:VOS:*:*)
+	# From Paul.Green@stratus.com.
+	echo ${UNAME_MACHINE}-stratus-vos
+	exit ;;
+    *:VOS:*:*)
+	# From Paul.Green@stratus.com.
+	echo hppa1.1-stratus-vos
+	exit ;;
+    mc68*:A/UX:*:*)
+	echo m68k-apple-aux${UNAME_RELEASE}
+	exit ;;
+    news*:NEWS-OS:6*:*)
+	echo mips-sony-newsos6
+	exit ;;
+    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+	if [ -d /usr/nec ]; then
+		echo mips-nec-sysv${UNAME_RELEASE}
+	else
+		echo mips-unknown-sysv${UNAME_RELEASE}
+	fi
+	exit ;;
+    BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
+	echo powerpc-be-beos
+	exit ;;
+    BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
+	echo powerpc-apple-beos
+	exit ;;
+    BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
+	echo i586-pc-beos
+	exit ;;
+    BePC:Haiku:*:*)	# Haiku running on Intel PC compatible.
+	echo i586-pc-haiku
+	exit ;;
+    x86_64:Haiku:*:*)
+	echo x86_64-unknown-haiku
+	exit ;;
+    SX-4:SUPER-UX:*:*)
+	echo sx4-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-5:SUPER-UX:*:*)
+	echo sx5-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-6:SUPER-UX:*:*)
+	echo sx6-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-7:SUPER-UX:*:*)
+	echo sx7-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8:SUPER-UX:*:*)
+	echo sx8-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8R:SUPER-UX:*:*)
+	echo sx8r-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-ACE:SUPER-UX:*:*)
+	echo sxace-nec-superux${UNAME_RELEASE}
+	exit ;;
+    Power*:Rhapsody:*:*)
+	echo powerpc-apple-rhapsody${UNAME_RELEASE}
+	exit ;;
+    *:Rhapsody:*:*)
+	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+	exit ;;
+    *:Darwin:*:*)
+	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+	eval $set_cc_for_build
+	if test "$UNAME_PROCESSOR" = unknown ; then
+	    UNAME_PROCESSOR=powerpc
+	fi
+	if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then
+	    if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
+		if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
+		       (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
+		       grep IS_64BIT_ARCH >/dev/null
+		then
+		    case $UNAME_PROCESSOR in
+			i386) UNAME_PROCESSOR=x86_64 ;;
+			powerpc) UNAME_PROCESSOR=powerpc64 ;;
+		    esac
+		fi
+		# On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc
+		if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \
+		       (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
+		       grep IS_PPC >/dev/null
+		then
+		    UNAME_PROCESSOR=powerpc
+		fi
+	    fi
+	elif test "$UNAME_PROCESSOR" = i386 ; then
+	    # Avoid executing cc on OS X 10.9, as it ships with a stub
+	    # that puts up a graphical alert prompting to install
+	    # developer tools.  Any system running Mac OS X 10.7 or
+	    # later (Darwin 11 and later) is required to have a 64-bit
+	    # processor. This is not true of the ARM version of Darwin
+	    # that Apple uses in portable devices.
+	    UNAME_PROCESSOR=x86_64
+	fi
+	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
+	exit ;;
+    *:procnto*:*:* | *:QNX:[0123456789]*:*)
+	UNAME_PROCESSOR=`uname -p`
+	if test "$UNAME_PROCESSOR" = x86; then
+		UNAME_PROCESSOR=i386
+		UNAME_MACHINE=pc
+	fi
+	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
+	exit ;;
+    *:QNX:*:4*)
+	echo i386-pc-qnx
+	exit ;;
+    NEO-*:NONSTOP_KERNEL:*:*)
+	echo neo-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSE-*:NONSTOP_KERNEL:*:*)
+	echo nse-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSR-*:NONSTOP_KERNEL:*:*)
+	echo nsr-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSX-*:NONSTOP_KERNEL:*:*)
+	echo nsx-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    *:NonStop-UX:*:*)
+	echo mips-compaq-nonstopux
+	exit ;;
+    BS2000:POSIX*:*:*)
+	echo bs2000-siemens-sysv
+	exit ;;
+    DS/*:UNIX_System_V:*:*)
+	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+	exit ;;
+    *:Plan9:*:*)
+	# "uname -m" is not consistent, so use $cputype instead. 386
+	# is converted to i386 for consistency with other x86
+	# operating systems.
+	if test "$cputype" = 386; then
+	    UNAME_MACHINE=i386
+	else
+	    UNAME_MACHINE="$cputype"
+	fi
+	echo ${UNAME_MACHINE}-unknown-plan9
+	exit ;;
+    *:TOPS-10:*:*)
+	echo pdp10-unknown-tops10
+	exit ;;
+    *:TENEX:*:*)
+	echo pdp10-unknown-tenex
+	exit ;;
+    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
+	echo pdp10-dec-tops20
+	exit ;;
+    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
+	echo pdp10-xkl-tops20
+	exit ;;
+    *:TOPS-20:*:*)
+	echo pdp10-unknown-tops20
+	exit ;;
+    *:ITS:*:*)
+	echo pdp10-unknown-its
+	exit ;;
+    SEI:*:*:SEIUX)
+	echo mips-sei-seiux${UNAME_RELEASE}
+	exit ;;
+    *:DragonFly:*:*)
+	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+	exit ;;
+    *:*VMS:*:*)
+	UNAME_MACHINE=`(uname -p) 2>/dev/null`
+	case "${UNAME_MACHINE}" in
+	    A*) echo alpha-dec-vms ; exit ;;
+	    I*) echo ia64-dec-vms ; exit ;;
+	    V*) echo vax-dec-vms ; exit ;;
+	esac ;;
+    *:XENIX:*:SysV)
+	echo i386-pc-xenix
+	exit ;;
+    i*86:skyos:*:*)
+	echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE} | sed -e 's/ .*$//'`
+	exit ;;
+    i*86:rdos:*:*)
+	echo ${UNAME_MACHINE}-pc-rdos
+	exit ;;
+    i*86:AROS:*:*)
+	echo ${UNAME_MACHINE}-pc-aros
+	exit ;;
+    x86_64:VMkernel:*:*)
+	echo ${UNAME_MACHINE}-unknown-esx
+	exit ;;
+    amd64:Isilon\ OneFS:*:*)
+	echo x86_64-unknown-onefs
+	exit ;;
+esac
+
+echo "$0: unable to guess system type" >&2
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}" in
+    mips:Linux | mips64:Linux)
+	# If we got here on MIPS GNU/Linux, output extra information.
+	cat >&2 <<EOF
+
+NOTE: MIPS GNU/Linux systems require a C compiler to fully recognize
+the system type. Please install a C compiler and try again.
+EOF
+	;;
+esac
+
+cat >&2 <<EOF
+
+This script (version $timestamp), has failed to recognize the
+operating system you are using. If your script is old, overwrite *all*
+copies of config.guess and config.sub with the latest versions from:
+
+  https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
+and
+  https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
+
+If $0 has already been updated, send the following data and any
+information you think might be pertinent to config-patches@gnu.org to
+provide the necessary information to handle your system.
+
+config.guess timestamp = $timestamp
+
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
+
+hostinfo               = `(hostinfo) 2>/dev/null`
+/bin/universe          = `(/bin/universe) 2>/dev/null`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
+/bin/arch              = `(/bin/arch) 2>/dev/null`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
+
+UNAME_MACHINE = ${UNAME_MACHINE}
+UNAME_RELEASE = ${UNAME_RELEASE}
+UNAME_SYSTEM  = ${UNAME_SYSTEM}
+UNAME_VERSION = ${UNAME_VERSION}
+EOF
+
+exit 1
+
+# Local variables:
+# eval: (add-hook 'write-file-functions 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:

diff --git a/config.sub b/config.sub
new file mode 100755
index 0000000..47515cc
--- /dev/null
+++ b/config.sub
@@ -0,0 +1,1866 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+#   Copyright 1992-2018 Free Software Foundation, Inc.
+
+timestamp='2018-01-01'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <https://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that
+# program.  This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
+
+
+# Please send patches to <config-patches@gnu.org>.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# You can get the latest version of this script from:
+# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS
+
+Canonicalize a configuration name.
+
+Options:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright 1992-2018 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help"
+       exit 1 ;;
+
+    *local*)
+       # First pass through any local machine types.
+       echo $1
+       exit ;;
+
+    * )
+       break ;;
+  esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+    exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+    exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+  nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
+  linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
+  knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \
+  kopensolaris*-gnu* | cloudabi*-eabi* | \
+  storm-chaos* | os2-emx* | rtmk-nova*)
+    os=-$maybe_os
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    ;;
+  android-linux)
+    os=-linux-android
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
+    ;;
+  *)
+    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+    if [ $basic_machine != $1 ]
+    then os=`echo $1 | sed 's/.*-/-/'`
+    else os=; fi
+    ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work.  We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+	-sun*os*)
+		# Prevent following clause from handling this invalid input.
+		;;
+	-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+	-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+	-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+	-apple | -axis | -knuth | -cray | -microblaze*)
+		os=
+		basic_machine=$1
+		;;
+	-bluegene*)
+		os=-cnk
+		;;
+	-sim | -cisco | -oki | -wec | -winbond)
+		os=
+		basic_machine=$1
+		;;
+	-scout)
+		;;
+	-wrs)
+		os=-vxworks
+		basic_machine=$1
+		;;
+	-chorusos*)
+		os=-chorusos
+		basic_machine=$1
+		;;
+	-chorusrdb)
+		os=-chorusrdb
+		basic_machine=$1
+		;;
+	-hiux*)
+		os=-hiuxwe2
+		;;
+	-sco6)
+		os=-sco5v6
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5)
+		os=-sco3.2v5
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco4)
+		os=-sco3.2v4
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2.[4-9]*)
+		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2v[4-9]*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5v6*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco*)
+		os=-sco3.2v2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-udk*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-isc)
+		os=-isc2.2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-clix*)
+		basic_machine=clipper-intergraph
+		;;
+	-isc*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-lynx*178)
+		os=-lynxos178
+		;;
+	-lynx*5)
+		os=-lynxos5
+		;;
+	-lynx*)
+		os=-lynxos
+		;;
+	-ptx*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+		;;
+	-psos*)
+		os=-psos
+		;;
+	-mint | -mint[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+	# Recognize the basic CPU types without company name.
+	# Some are omitted here because they have special meanings below.
+	1750a | 580 \
+	| a29k \
+	| aarch64 | aarch64_be \
+	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
+	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+	| am33_2.0 \
+	| arc | arceb \
+	| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
+	| avr | avr32 \
+	| ba \
+	| be32 | be64 \
+	| bfin \
+	| c4x | c8051 | clipper \
+	| d10v | d30v | dlx | dsp16xx | dvp \
+	| e2k | epiphany \
+	| fido | fr30 | frv | ft32 \
+	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+	| hexagon \
+	| i370 | i860 | i960 | ia16 | ia64 \
+	| ip2k | iq2000 \
+	| k1om \
+	| le32 | le64 \
+	| lm32 \
+	| m32c | m32r | m32rle | m68000 | m68k | m88k \
+	| maxq | mb | microblaze | microblazeel | mcore | mep | metag \
+	| mips | mipsbe | mipseb | mipsel | mipsle \
+	| mips16 \
+	| mips64 | mips64el \
+	| mips64octeon | mips64octeonel \
+	| mips64orion | mips64orionel \
+	| mips64r5900 | mips64r5900el \
+	| mips64vr | mips64vrel \
+	| mips64vr4100 | mips64vr4100el \
+	| mips64vr4300 | mips64vr4300el \
+	| mips64vr5000 | mips64vr5000el \
+	| mips64vr5900 | mips64vr5900el \
+	| mipsisa32 | mipsisa32el \
+	| mipsisa32r2 | mipsisa32r2el \
+	| mipsisa32r6 | mipsisa32r6el \
+	| mipsisa64 | mipsisa64el \
+	| mipsisa64r2 | mipsisa64r2el \
+	| mipsisa64r6 | mipsisa64r6el \
+	| mipsisa64sb1 | mipsisa64sb1el \
+	| mipsisa64sr71k | mipsisa64sr71kel \
+	| mipsr5900 | mipsr5900el \
+	| mipstx39 | mipstx39el \
+	| mn10200 | mn10300 \
+	| moxie \
+	| mt \
+	| msp430 \
+	| nds32 | nds32le | nds32be \
+	| nios | nios2 | nios2eb | nios2el \
+	| ns16k | ns32k \
+	| open8 | or1k | or1knd | or32 \
+	| pdp10 | pdp11 | pj | pjl \
+	| powerpc | powerpc64 | powerpc64le | powerpcle \
+	| pru \
+	| pyramid \
+	| riscv32 | riscv64 \
+	| rl78 | rx \
+	| score \
+	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+	| sh64 | sh64le \
+	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+	| spu \
+	| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
+	| ubicom32 \
+	| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
+	| visium \
+	| wasm32 \
+	| x86 | xc16x | xstormy16 | xtensa \
+	| z8k | z80)
+		basic_machine=$basic_machine-unknown
+		;;
+	c54x)
+		basic_machine=tic54x-unknown
+		;;
+	c55x)
+		basic_machine=tic55x-unknown
+		;;
+	c6x)
+		basic_machine=tic6x-unknown
+		;;
+	leon|leon[3-9])
+		basic_machine=sparc-$basic_machine
+		;;
+	m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+		;;
+	ms1)
+		basic_machine=mt-unknown
+		;;
+
+	strongarm | thumb | xscale)
+		basic_machine=arm-unknown
+		;;
+	xgate)
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	xscaleeb)
+		basic_machine=armeb-unknown
+		;;
+
+	xscaleel)
+		basic_machine=armel-unknown
+		;;
+
+	# We use `pc' rather than `unknown'
+	# because (1) that's what they normally are, and
+	# (2) the word "unknown" tends to confuse beginning users.
+	i*86 | x86_64)
+	  basic_machine=$basic_machine-pc
+	  ;;
+	# Object if more than one company name word.
+	*-*-*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+	# Recognize the basic CPU types with company name.
+	580-* \
+	| a29k-* \
+	| aarch64-* | aarch64_be-* \
+	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
+	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
+	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
+	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
+	| avr-* | avr32-* \
+	| ba-* \
+	| be32-* | be64-* \
+	| bfin-* | bs2000-* \
+	| c[123]* | c30-* | [cjt]90-* | c4x-* \
+	| c8051-* | clipper-* | craynv-* | cydra-* \
+	| d10v-* | d30v-* | dlx-* \
+	| e2k-* | elxsi-* \
+	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
+	| h8300-* | h8500-* \
+	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+	| hexagon-* \
+	| i*86-* | i860-* | i960-* | ia16-* | ia64-* \
+	| ip2k-* | iq2000-* \
+	| k1om-* \
+	| le32-* | le64-* \
+	| lm32-* \
+	| m32c-* | m32r-* | m32rle-* \
+	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
+	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
+	| microblaze-* | microblazeel-* \
+	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
+	| mips16-* \
+	| mips64-* | mips64el-* \
+	| mips64octeon-* | mips64octeonel-* \
+	| mips64orion-* | mips64orionel-* \
+	| mips64r5900-* | mips64r5900el-* \
+	| mips64vr-* | mips64vrel-* \
+	| mips64vr4100-* | mips64vr4100el-* \
+	| mips64vr4300-* | mips64vr4300el-* \
+	| mips64vr5000-* | mips64vr5000el-* \
+	| mips64vr5900-* | mips64vr5900el-* \
+	| mipsisa32-* | mipsisa32el-* \
+	| mipsisa32r2-* | mipsisa32r2el-* \
+	| mipsisa32r6-* | mipsisa32r6el-* \
+	| mipsisa64-* | mipsisa64el-* \
+	| mipsisa64r2-* | mipsisa64r2el-* \
+	| mipsisa64r6-* | mipsisa64r6el-* \
+	| mipsisa64sb1-* | mipsisa64sb1el-* \
+	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
+	| mipsr5900-* | mipsr5900el-* \
+	| mipstx39-* | mipstx39el-* \
+	| mmix-* \
+	| mt-* \
+	| msp430-* \
+	| nds32-* | nds32le-* | nds32be-* \
+	| nios-* | nios2-* | nios2eb-* | nios2el-* \
+	| none-* | np1-* | ns16k-* | ns32k-* \
+	| open8-* \
+	| or1k*-* \
+	| orion-* \
+	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
+	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
+	| pru-* \
+	| pyramid-* \
+	| riscv32-* | riscv64-* \
+	| rl78-* | romp-* | rs6000-* | rx-* \
+	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
+	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
+	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
+	| sparclite-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \
+	| tahoe-* \
+	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+	| tile*-* \
+	| tron-* \
+	| ubicom32-* \
+	| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
+	| vax-* \
+	| visium-* \
+	| wasm32-* \
+	| we32k-* \
+	| x86-* | x86_64-* | xc16x-* | xps100-* \
+	| xstormy16-* | xtensa*-* \
+	| ymp-* \
+	| z8k-* | z80-*)
+		;;
+	# Recognize the basic CPU types without company name, with glob match.
+	xtensa*)
+		basic_machine=$basic_machine-unknown
+		;;
+	# Recognize the various machine names and aliases which stand
+	# for a CPU type and a company and sometimes even an OS.
+	386bsd)
+		basic_machine=i386-unknown
+		os=-bsd
+		;;
+	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+		basic_machine=m68000-att
+		;;
+	3b*)
+		basic_machine=we32k-att
+		;;
+	a29khif)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	abacus)
+		basic_machine=abacus-unknown
+		;;
+	adobe68k)
+		basic_machine=m68010-adobe
+		os=-scout
+		;;
+	alliant | fx80)
+		basic_machine=fx80-alliant
+		;;
+	altos | altos3068)
+		basic_machine=m68k-altos
+		;;
+	am29k)
+		basic_machine=a29k-none
+		os=-bsd
+		;;
+	amd64)
+		basic_machine=x86_64-pc
+		;;
+	amd64-*)
+		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	amdahl)
+		basic_machine=580-amdahl
+		os=-sysv
+		;;
+	amiga | amiga-*)
+		basic_machine=m68k-unknown
+		;;
+	amigaos | amigados)
+		basic_machine=m68k-unknown
+		os=-amigaos
+		;;
+	amigaunix | amix)
+		basic_machine=m68k-unknown
+		os=-sysv4
+		;;
+	apollo68)
+		basic_machine=m68k-apollo
+		os=-sysv
+		;;
+	apollo68bsd)
+		basic_machine=m68k-apollo
+		os=-bsd
+		;;
+	aros)
+		basic_machine=i386-pc
+		os=-aros
+		;;
+	asmjs)
+		basic_machine=asmjs-unknown
+		;;
+	aux)
+		basic_machine=m68k-apple
+		os=-aux
+		;;
+	balance)
+		basic_machine=ns32k-sequent
+		os=-dynix
+		;;
+	blackfin)
+		basic_machine=bfin-unknown
+		os=-linux
+		;;
+	blackfin-*)
+		basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	bluegene*)
+		basic_machine=powerpc-ibm
+		os=-cnk
+		;;
+	c54x-*)
+		basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c55x-*)
+		basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c6x-*)
+		basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c90)
+		basic_machine=c90-cray
+		os=-unicos
+		;;
+	cegcc)
+		basic_machine=arm-unknown
+		os=-cegcc
+		;;
+	convex-c1)
+		basic_machine=c1-convex
+		os=-bsd
+		;;
+	convex-c2)
+		basic_machine=c2-convex
+		os=-bsd
+		;;
+	convex-c32)
+		basic_machine=c32-convex
+		os=-bsd
+		;;
+	convex-c34)
+		basic_machine=c34-convex
+		os=-bsd
+		;;
+	convex-c38)
+		basic_machine=c38-convex
+		os=-bsd
+		;;
+	cray | j90)
+		basic_machine=j90-cray
+		os=-unicos
+		;;
+	craynv)
+		basic_machine=craynv-cray
+		os=-unicosmp
+		;;
+	cr16 | cr16-*)
+		basic_machine=cr16-unknown
+		os=-elf
+		;;
+	crds | unos)
+		basic_machine=m68k-crds
+		;;
+	crisv32 | crisv32-* | etraxfs*)
+		basic_machine=crisv32-axis
+		;;
+	cris | cris-* | etrax*)
+		basic_machine=cris-axis
+		;;
+	crx)
+		basic_machine=crx-unknown
+		os=-elf
+		;;
+	da30 | da30-*)
+		basic_machine=m68k-da30
+		;;
+	decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+		basic_machine=mips-dec
+		;;
+	decsystem10* | dec10*)
+		basic_machine=pdp10-dec
+		os=-tops10
+		;;
+	decsystem20* | dec20*)
+		basic_machine=pdp10-dec
+		os=-tops20
+		;;
+	delta | 3300 | motorola-3300 | motorola-delta \
+	      | 3300-motorola | delta-motorola)
+		basic_machine=m68k-motorola
+		;;
+	delta88)
+		basic_machine=m88k-motorola
+		os=-sysv3
+		;;
+	dicos)
+		basic_machine=i686-pc
+		os=-dicos
+		;;
+	djgpp)
+		basic_machine=i586-pc
+		os=-msdosdjgpp
+		;;
+	dpx20 | dpx20-*)
+		basic_machine=rs6000-bull
+		os=-bosx
+		;;
+	dpx2*)
+		basic_machine=m68k-bull
+		os=-sysv3
+		;;
+	e500v[12])
+		basic_machine=powerpc-unknown
+		os=$os"spe"
+		;;
+	e500v[12]-*)
+		basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=$os"spe"
+		;;
+	ebmon29k)
+		basic_machine=a29k-amd
+		os=-ebmon
+		;;
+	elxsi)
+		basic_machine=elxsi-elxsi
+		os=-bsd
+		;;
+	encore | umax | mmax)
+		basic_machine=ns32k-encore
+		;;
+	es1800 | OSE68k | ose68k | ose | OSE)
+		basic_machine=m68k-ericsson
+		os=-ose
+		;;
+	fx2800)
+		basic_machine=i860-alliant
+		;;
+	genix)
+		basic_machine=ns32k-ns
+		;;
+	gmicro)
+		basic_machine=tron-gmicro
+		os=-sysv
+		;;
+	go32)
+		basic_machine=i386-pc
+		os=-go32
+		;;
+	h3050r* | hiux*)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	h8300hms)
+		basic_machine=h8300-hitachi
+		os=-hms
+		;;
+	h8300xray)
+		basic_machine=h8300-hitachi
+		os=-xray
+		;;
+	h8500hms)
+		basic_machine=h8500-hitachi
+		os=-hms
+		;;
+	harris)
+		basic_machine=m88k-harris
+		os=-sysv3
+		;;
+	hp300-*)
+		basic_machine=m68k-hp
+		;;
+	hp300bsd)
+		basic_machine=m68k-hp
+		os=-bsd
+		;;
+	hp300hpux)
+		basic_machine=m68k-hp
+		os=-hpux
+		;;
+	hp3k9[0-9][0-9] | hp9[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k2[0-9][0-9] | hp9k31[0-9])
+		basic_machine=m68000-hp
+		;;
+	hp9k3[2-9][0-9])
+		basic_machine=m68k-hp
+		;;
+	hp9k6[0-9][0-9] | hp6[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k7[0-79][0-9] | hp7[0-79][0-9])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k78[0-9] | hp78[0-9])
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][13679] | hp8[0-9][13679])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][0-9] | hp8[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hppa-next)
+		os=-nextstep3
+		;;
+	hppaosf)
+		basic_machine=hppa1.1-hp
+		os=-osf
+		;;
+	hppro)
+		basic_machine=hppa1.1-hp
+		os=-proelf
+		;;
+	i370-ibm* | ibm*)
+		basic_machine=i370-ibm
+		;;
+	i*86v32)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv32
+		;;
+	i*86v4*)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv4
+		;;
+	i*86v)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv
+		;;
+	i*86sol2)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-solaris2
+		;;
+	i386mach)
+		basic_machine=i386-mach
+		os=-mach
+		;;
+	i386-vsta | vsta)
+		basic_machine=i386-unknown
+		os=-vsta
+		;;
+	iris | iris4d)
+		basic_machine=mips-sgi
+		case $os in
+		    -irix*)
+			;;
+		    *)
+			os=-irix4
+			;;
+		esac
+		;;
+	isi68 | isi)
+		basic_machine=m68k-isi
+		os=-sysv
+		;;
+	leon-*|leon[3-9]-*)
+		basic_machine=sparc-`echo $basic_machine | sed 's/-.*//'`
+		;;
+	m68knommu)
+		basic_machine=m68k-unknown
+		os=-linux
+		;;
+	m68knommu-*)
+		basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	m88k-omron*)
+		basic_machine=m88k-omron
+		;;
+	magnum | m3230)
+		basic_machine=mips-mips
+		os=-sysv
+		;;
+	merlin)
+		basic_machine=ns32k-utek
+		os=-sysv
+		;;
+	microblaze*)
+		basic_machine=microblaze-xilinx
+		;;
+	mingw64)
+		basic_machine=x86_64-pc
+		os=-mingw64
+		;;
+	mingw32)
+		basic_machine=i686-pc
+		os=-mingw32
+		;;
+	mingw32ce)
+		basic_machine=arm-unknown
+		os=-mingw32ce
+		;;
+	miniframe)
+		basic_machine=m68000-convergent
+		;;
+	*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+	mipsEE* | ee | ps2)
+		basic_machine=mips64r5900el-scei
+		case $os in
+		    -linux*)
+			;;
+		    *)
+			os=-elf
+			;;
+		esac
+		;;
+	iop)
+		basic_machine=mipsel-scei
+		os=-irx
+		;;
+	dvp)
+		basic_machine=dvp-scei
+		os=-elf
+		;;
+	mips3*-*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+		;;
+	mips3*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+		;;
+	monitor)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	morphos)
+		basic_machine=powerpc-unknown
+		os=-morphos
+		;;
+	moxiebox)
+		basic_machine=moxie-unknown
+		os=-moxiebox
+		;;
+	msdos)
+		basic_machine=i386-pc
+		os=-msdos
+		;;
+	ms1-*)
+		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+		;;
+	msys)
+		basic_machine=i686-pc
+		os=-msys
+		;;
+	mvs)
+		basic_machine=i370-ibm
+		os=-mvs
+		;;
+	nacl)
+		basic_machine=le32-unknown
+		os=-nacl
+		;;
+	ncr3000)
+		basic_machine=i486-ncr
+		os=-sysv4
+		;;
+	netbsd386)
+		basic_machine=i386-unknown
+		os=-netbsd
+		;;
+	netwinder)
+		basic_machine=armv4l-rebel
+		os=-linux
+		;;
+	news | news700 | news800 | news900)
+		basic_machine=m68k-sony
+		os=-newsos
+		;;
+	news1000)
+		basic_machine=m68030-sony
+		os=-newsos
+		;;
+	news-3600 | risc-news)
+		basic_machine=mips-sony
+		os=-newsos
+		;;
+	necv70)
+		basic_machine=v70-nec
+		os=-sysv
+		;;
+	next | m*-next)
+		basic_machine=m68k-next
+		case $os in
+		    -nextstep* )
+			;;
+		    -ns2*)
+		      os=-nextstep2
+			;;
+		    *)
+		      os=-nextstep3
+			;;
+		esac
+		;;
+	nh3000)
+		basic_machine=m68k-harris
+		os=-cxux
+		;;
+	nh[45]000)
+		basic_machine=m88k-harris
+		os=-cxux
+		;;
+	nindy960)
+		basic_machine=i960-intel
+		os=-nindy
+		;;
+	mon960)
+		basic_machine=i960-intel
+		os=-mon960
+		;;
+	nonstopux)
+		basic_machine=mips-compaq
+		os=-nonstopux
+		;;
+	np1)
+		basic_machine=np1-gould
+		;;
+	neo-tandem)
+		basic_machine=neo-tandem
+		;;
+	nse-tandem)
+		basic_machine=nse-tandem
+		;;
+	nsr-tandem)
+		basic_machine=nsr-tandem
+		;;
+	nsx-tandem)
+		basic_machine=nsx-tandem
+		;;
+	op50n-* | op60c-*)
+		basic_machine=hppa1.1-oki
+		os=-proelf
+		;;
+	openrisc | openrisc-*)
+		basic_machine=or32-unknown
+		;;
+	os400)
+		basic_machine=powerpc-ibm
+		os=-os400
+		;;
+	OSE68000 | ose68000)
+		basic_machine=m68000-ericsson
+		os=-ose
+		;;
+	os68k)
+		basic_machine=m68k-none
+		os=-os68k
+		;;
+	pa-hitachi)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	paragon)
+		basic_machine=i860-intel
+		os=-osf
+		;;
+	parisc)
+		basic_machine=hppa-unknown
+		os=-linux
+		;;
+	parisc-*)
+		basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	pbd)
+		basic_machine=sparc-tti
+		;;
+	pbb)
+		basic_machine=m68k-tti
+		;;
+	pc532 | pc532-*)
+		basic_machine=ns32k-pc532
+		;;
+	pc98)
+		basic_machine=i386-pc
+		;;
+	pc98-*)
+		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium | p5 | k5 | k6 | nexgen | viac3)
+		basic_machine=i586-pc
+		;;
+	pentiumpro | p6 | 6x86 | athlon | athlon_*)
+		basic_machine=i686-pc
+		;;
+	pentiumii | pentium2 | pentiumiii | pentium3)
+		basic_machine=i686-pc
+		;;
+	pentium4)
+		basic_machine=i786-pc
+		;;
+	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumpro-* | p6-* | 6x86-* | athlon-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium4-*)
+		basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pn)
+		basic_machine=pn-gould
+		;;
+	power)	basic_machine=power-ibm
+		;;
+	ppc | ppcbe)	basic_machine=powerpc-unknown
+		;;
+	ppc-* | ppcbe-*)
+		basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppcle | powerpclittle)
+		basic_machine=powerpcle-unknown
+		;;
+	ppcle-* | powerpclittle-*)
+		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64)	basic_machine=powerpc64-unknown
+		;;
+	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64le | powerpc64little)
+		basic_machine=powerpc64le-unknown
+		;;
+	ppc64le-* | powerpc64little-*)
+		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ps2)
+		basic_machine=i386-ibm
+		;;
+	pw32)
+		basic_machine=i586-unknown
+		os=-pw32
+		;;
+	rdos | rdos64)
+		basic_machine=x86_64-pc
+		os=-rdos
+		;;
+	rdos32)
+		basic_machine=i386-pc
+		os=-rdos
+		;;
+	rom68k)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	rm[46]00)
+		basic_machine=mips-siemens
+		;;
+	rtpc | rtpc-*)
+		basic_machine=romp-ibm
+		;;
+	s390 | s390-*)
+		basic_machine=s390-ibm
+		;;
+	s390x | s390x-*)
+		basic_machine=s390x-ibm
+		;;
+	sa29200)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	sb1)
+		basic_machine=mipsisa64sb1-unknown
+		;;
+	sb1el)
+		basic_machine=mipsisa64sb1el-unknown
+		;;
+	sde)
+		basic_machine=mipsisa32-sde
+		os=-elf
+		;;
+	sei)
+		basic_machine=mips-sei
+		os=-seiux
+		;;
+	sequent)
+		basic_machine=i386-sequent
+		;;
+	sh)
+		basic_machine=sh-hitachi
+		os=-hms
+		;;
+	sh5el)
+		basic_machine=sh5le-unknown
+		;;
+	sh64)
+		basic_machine=sh64-unknown
+		;;
+	sparclite-wrs | simso-wrs)
+		basic_machine=sparclite-wrs
+		os=-vxworks
+		;;
+	sps7)
+		basic_machine=m68k-bull
+		os=-sysv2
+		;;
+	spur)
+		basic_machine=spur-unknown
+		;;
+	st2000)
+		basic_machine=m68k-tandem
+		;;
+	stratus)
+		basic_machine=i860-stratus
+		os=-sysv4
+		;;
+	strongarm-* | thumb-*)
+		basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	sun2)
+		basic_machine=m68000-sun
+		;;
+	sun2os3)
+		basic_machine=m68000-sun
+		os=-sunos3
+		;;
+	sun2os4)
+		basic_machine=m68000-sun
+		os=-sunos4
+		;;
+	sun3os3)
+		basic_machine=m68k-sun
+		os=-sunos3
+		;;
+	sun3os4)
+		basic_machine=m68k-sun
+		os=-sunos4
+		;;
+	sun4os3)
+		basic_machine=sparc-sun
+		os=-sunos3
+		;;
+	sun4os4)
+		basic_machine=sparc-sun
+		os=-sunos4
+		;;
+	sun4sol2)
+		basic_machine=sparc-sun
+		os=-solaris2
+		;;
+	sun3 | sun3-*)
+		basic_machine=m68k-sun
+		;;
+	sun4)
+		basic_machine=sparc-sun
+		;;
+	sun386 | sun386i | roadrunner)
+		basic_machine=i386-sun
+		;;
+	sv1)
+		basic_machine=sv1-cray
+		os=-unicos
+		;;
+	symmetry)
+		basic_machine=i386-sequent
+		os=-dynix
+		;;
+	t3e)
+		basic_machine=alphaev5-cray
+		os=-unicos
+		;;
+	t90)
+		basic_machine=t90-cray
+		os=-unicos
+		;;
+	tile*)
+		basic_machine=$basic_machine-unknown
+		os=-linux-gnu
+		;;
+	tx39)
+		basic_machine=mipstx39-unknown
+		;;
+	tx39el)
+		basic_machine=mipstx39el-unknown
+		;;
+	toad1)
+		basic_machine=pdp10-xkl
+		os=-tops20
+		;;
+	tower | tower-32)
+		basic_machine=m68k-ncr
+		;;
+	tpf)
+		basic_machine=s390x-ibm
+		os=-tpf
+		;;
+	udi29k)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	ultra3)
+		basic_machine=a29k-nyu
+		os=-sym1
+		;;
+	v810 | necv810)
+		basic_machine=v810-nec
+		os=-none
+		;;
+	vaxv)
+		basic_machine=vax-dec
+		os=-sysv
+		;;
+	vms)
+		basic_machine=vax-dec
+		os=-vms
+		;;
+	vpp*|vx|vx-*)
+		basic_machine=f301-fujitsu
+		;;
+	vxworks960)
+		basic_machine=i960-wrs
+		os=-vxworks
+		;;
+	vxworks68)
+		basic_machine=m68k-wrs
+		os=-vxworks
+		;;
+	vxworks29k)
+		basic_machine=a29k-wrs
+		os=-vxworks
+		;;
+	wasm32)
+		basic_machine=wasm32-unknown
+		;;
+	w65*)
+		basic_machine=w65-wdc
+		os=-none
+		;;
+	w89k-*)
+		basic_machine=hppa1.1-winbond
+		os=-proelf
+		;;
+	x64)
+		basic_machine=x86_64-pc
+		;;
+	xbox)
+		basic_machine=i686-pc
+		os=-mingw32
+		;;
+	xps | xps100)
+		basic_machine=xps100-honeywell
+		;;
+	xscale-* | xscalee[bl]-*)
+		basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
+		;;
+	ymp)
+		basic_machine=ymp-cray
+		os=-unicos
+		;;
+	z8k-*-coff)
+		basic_machine=z8k-unknown
+		os=-sim
+		;;
+	z80-*-coff)
+		basic_machine=z80-unknown
+		os=-sim
+		;;
+	none)
+		basic_machine=none-none
+		os=-none
+		;;
+
+# Here we handle the default manufacturer of certain CPU types.  It is in
+# some cases the only manufacturer, in others, it is the most popular.
+	w89k)
+		basic_machine=hppa1.1-winbond
+		;;
+	op50n)
+		basic_machine=hppa1.1-oki
+		;;
+	op60c)
+		basic_machine=hppa1.1-oki
+		;;
+	romp)
+		basic_machine=romp-ibm
+		;;
+	mmix)
+		basic_machine=mmix-knuth
+		;;
+	rs6000)
+		basic_machine=rs6000-ibm
+		;;
+	vax)
+		basic_machine=vax-dec
+		;;
+	pdp10)
+		# there are many clones, so DEC is not a safe bet
+		basic_machine=pdp10-unknown
+		;;
+	pdp11)
+		basic_machine=pdp11-dec
+		;;
+	we32k)
+		basic_machine=we32k-att
+		;;
+	sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
+		basic_machine=sh-unknown
+		;;
+	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
+		basic_machine=sparc-sun
+		;;
+	cydra)
+		basic_machine=cydra-cydrome
+		;;
+	orion)
+		basic_machine=orion-highlevel
+		;;
+	orion105)
+		basic_machine=clipper-highlevel
+		;;
+	mac | mpw | mac-mpw)
+		basic_machine=m68k-apple
+		;;
+	pmac | pmac-mpw)
+		basic_machine=powerpc-apple
+		;;
+	*-unknown)
+		# Make sure to match an already-canonicalized machine name.
+		;;
+	*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+	*-digital*)
+		basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+		;;
+	*-commodore*)
+		basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+		;;
+	*)
+		;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+	# First match some system type aliases that might get confused
+	# with valid system types.
+	# -solaris* is a basic system type, with this one exception.
+	-auroraux)
+		os=-auroraux
+		;;
+	-solaris1 | -solaris1.*)
+		os=`echo $os | sed -e 's|solaris1|sunos4|'`
+		;;
+	-solaris)
+		os=-solaris2
+		;;
+	-svr4*)
+		os=-sysv4
+		;;
+	-unixware*)
+		os=-sysv4.2uw
+		;;
+	-gnu/linux*)
+		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+		;;
+	# Now accept the basic system types.
+	# The portable systems comes first.
+	# Each alternative MUST end in a * to match a version number.
+	# -sysv* is not here because it comes later, after sysvr4.
+	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
+	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
+	      | -sym* | -kopensolaris* | -plan9* \
+	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+	      | -aos* | -aros* | -cloudabi* | -sortix* \
+	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+	      | -bitrig* | -openbsd* | -solidbsd* | -libertybsd* \
+	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+	      | -chorusos* | -chorusrdb* | -cegcc* | -glidix* \
+	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+	      | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
+	      | -linux-newlib* | -linux-musl* | -linux-uclibc* \
+	      | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
+	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* | -irx* \
+	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
+	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
+	      | -onefs* | -tirtos* | -phoenix* | -fuchsia* | -redox* | -bme*)
+	# Remember, each alternative MUST END IN *, to match a version number.
+		;;
+	-qnx*)
+		case $basic_machine in
+		    x86-* | i*86-*)
+			;;
+		    *)
+			os=-nto$os
+			;;
+		esac
+		;;
+	-nto-qnx*)
+		;;
+	-nto*)
+		os=`echo $os | sed -e 's|nto|nto-qnx|'`
+		;;
+	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+		;;
+	-mac*)
+		os=`echo $os | sed -e 's|mac|macos|'`
+		;;
+	-linux-dietlibc)
+		os=-linux-dietlibc
+		;;
+	-linux*)
+		os=`echo $os | sed -e 's|linux|linux-gnu|'`
+		;;
+	-sunos5*)
+		os=`echo $os | sed -e 's|sunos5|solaris2|'`
+		;;
+	-sunos6*)
+		os=`echo $os | sed -e 's|sunos6|solaris3|'`
+		;;
+	-opened*)
+		os=-openedition
+		;;
+	-os400*)
+		os=-os400
+		;;
+	-wince*)
+		os=-wince
+		;;
+	-osfrose*)
+		os=-osfrose
+		;;
+	-osf*)
+		os=-osf
+		;;
+	-utek*)
+		os=-bsd
+		;;
+	-dynix*)
+		os=-bsd
+		;;
+	-acis*)
+		os=-aos
+		;;
+	-atheos*)
+		os=-atheos
+		;;
+	-syllable*)
+		os=-syllable
+		;;
+	-386bsd)
+		os=-bsd
+		;;
+	-ctix* | -uts*)
+		os=-sysv
+		;;
+	-nova*)
+		os=-rtmk-nova
+		;;
+	-ns2)
+		os=-nextstep2
+		;;
+	-nsk*)
+		os=-nsk
+		;;
+	# Preserve the version number of sinix5.
+	-sinix5.*)
+		os=`echo $os | sed -e 's|sinix|sysv|'`
+		;;
+	-sinix*)
+		os=-sysv4
+		;;
+	-tpf*)
+		os=-tpf
+		;;
+	-triton*)
+		os=-sysv3
+		;;
+	-oss*)
+		os=-sysv3
+		;;
+	-svr4)
+		os=-sysv4
+		;;
+	-svr3)
+		os=-sysv3
+		;;
+	-sysvr4)
+		os=-sysv4
+		;;
+	# This must come after -sysvr4.
+	-sysv*)
+		;;
+	-ose*)
+		os=-ose
+		;;
+	-es1800*)
+		os=-ose
+		;;
+	-xenix)
+		os=-xenix
+		;;
+	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+		os=-mint
+		;;
+	-aros*)
+		os=-aros
+		;;
+	-zvmoe)
+		os=-zvmoe
+		;;
+	-dicos*)
+		os=-dicos
+		;;
+	-pikeos*)
+		# Until real need of OS specific support for
+		# particular features comes up, bare metal
+		# configurations are quite functional.
+		case $basic_machine in
+		    arm*)
+			os=-eabi
+			;;
+		    *)
+			os=-elf
+			;;
+		esac
+		;;
+	-nacl*)
+		;;
+	-ios)
+		;;
+	-none)
+		;;
+	*)
+		# Get rid of the `-' at the beginning of $os.
+		os=`echo $os | sed 's/[^-]*-//'`
+		echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+		exit 1
+		;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+	score-*)
+		os=-elf
+		;;
+	spu-*)
+		os=-elf
+		;;
+	*-acorn)
+		os=-riscix1.2
+		;;
+	arm*-rebel)
+		os=-linux
+		;;
+	arm*-semi)
+		os=-aout
+		;;
+	c4x-* | tic4x-*)
+		os=-coff
+		;;
+	c8051-*)
+		os=-elf
+		;;
+	hexagon-*)
+		os=-elf
+		;;
+	tic54x-*)
+		os=-coff
+		;;
+	tic55x-*)
+		os=-coff
+		;;
+	tic6x-*)
+		os=-coff
+		;;
+	# This must come before the *-dec entry.
+	pdp10-*)
+		os=-tops20
+		;;
+	pdp11-*)
+		os=-none
+		;;
+	*-dec | vax-*)
+		os=-ultrix4.2
+		;;
+	m68*-apollo)
+		os=-domain
+		;;
+	i386-sun)
+		os=-sunos4.0.2
+		;;
+	m68000-sun)
+		os=-sunos3
+		;;
+	m68*-cisco)
+		os=-aout
+		;;
+	mep-*)
+		os=-elf
+		;;
+	mips*-cisco)
+		os=-elf
+		;;
+	mips*-*)
+		os=-elf
+		;;
+	or32-*)
+		os=-coff
+		;;
+	*-tti)	# must be before sparc entry or we get the wrong os.
+		os=-sysv3
+		;;
+	sparc-* | *-sun)
+		os=-sunos4.1.1
+		;;
+	pru-*)
+		os=-elf
+		;;
+	*-be)
+		os=-beos
+		;;
+	*-haiku)
+		os=-haiku
+		;;
+	*-ibm)
+		os=-aix
+		;;
+	*-knuth)
+		os=-mmixware
+		;;
+	*-wec)
+		os=-proelf
+		;;
+	*-winbond)
+		os=-proelf
+		;;
+	*-oki)
+		os=-proelf
+		;;
+	*-hp)
+		os=-hpux
+		;;
+	*-hitachi)
+		os=-hiux
+		;;
+	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+		os=-sysv
+		;;
+	*-cbm)
+		os=-amigaos
+		;;
+	*-dg)
+		os=-dgux
+		;;
+	*-dolphin)
+		os=-sysv3
+		;;
+	m68k-ccur)
+		os=-rtu
+		;;
+	m88k-omron*)
+		os=-luna
+		;;
+	*-next)
+		os=-nextstep
+		;;
+	*-sequent)
+		os=-ptx
+		;;
+	*-crds)
+		os=-unos
+		;;
+	*-ns)
+		os=-genix
+		;;
+	i370-*)
+		os=-mvs
+		;;
+	*-next)
+		os=-nextstep3
+		;;
+	*-gould)
+		os=-sysv
+		;;
+	*-highlevel)
+		os=-bsd
+		;;
+	*-encore)
+		os=-bsd
+		;;
+	*-sgi)
+		os=-irix
+		;;
+	*-siemens)
+		os=-sysv4
+		;;
+	*-masscomp)
+		os=-rtu
+		;;
+	f30[01]-fujitsu | f700-fujitsu)
+		os=-uxpv
+		;;
+	*-rom68k)
+		os=-coff
+		;;
+	*-*bug)
+		os=-coff
+		;;
+	*-apple)
+		os=-macos
+		;;
+	*-atari*)
+		os=-mint
+		;;
+	*)
+		os=-none
+		;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+	*-unknown)
+		case $os in
+			-riscix*)
+				vendor=acorn
+				;;
+			-sunos*)
+				vendor=sun
+				;;
+			-cnk*|-aix*)
+				vendor=ibm
+				;;
+			-beos*)
+				vendor=be
+				;;
+			-hpux*)
+				vendor=hp
+				;;
+			-mpeix*)
+				vendor=hp
+				;;
+			-hiux*)
+				vendor=hitachi
+				;;
+			-unos*)
+				vendor=crds
+				;;
+			-dgux*)
+				vendor=dg
+				;;
+			-luna*)
+				vendor=omron
+				;;
+			-genix*)
+				vendor=ns
+				;;
+			-mvs* | -opened*)
+				vendor=ibm
+				;;
+			-os400*)
+				vendor=ibm
+				;;
+			-ptx*)
+				vendor=sequent
+				;;
+			-tpf*)
+				vendor=ibm
+				;;
+			-vxsim* | -vxworks* | -windiss*)
+				vendor=wrs
+				;;
+			-aux*)
+				vendor=apple
+				;;
+			-hms*)
+				vendor=hitachi
+				;;
+			-mpw* | -macos*)
+				vendor=apple
+				;;
+			-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+				vendor=atari
+				;;
+			-vos*)
+				vendor=stratus
+				;;
+		esac
+		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+		;;
+esac
+
+echo $basic_machine$os
+exit
+
+# Local variables:
+# eval: (add-hook 'write-file-functions 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:

diff --git a/configure b/configure
index 1d185ee..9c3e033 100755
--- a/configure
+++ b/configure
@@ -3633,8 +3633,10 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
+am__api_version='1.15'
+
 ac_aux_dir=
-for ac_dir in autotools "$srcdir"/autotools; do
+for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
   if test -f "$ac_dir/install-sh"; then
     ac_aux_dir=$ac_dir
     ac_install_sh="$ac_aux_dir/install-sh -c"
@@ -3650,7 +3652,7 @@ for ac_dir in autotools "$srcdir"/autotools; do
   fi
 done
 if test -z "$ac_aux_dir"; then
-  as_fn_error $? "cannot find install-sh, install.sh, or shtool in autotools \"$srcdir\"/autotools" "$LINENO" 5
+  as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
 fi
 
 # These three variables are undocumented and unsupported,
@@ -3662,8 +3664,6 @@ ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
 ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
 
 
-am__api_version='1.15'
-
 # Find a good install program.  We prefer a C program (faster),
 # so one script is as good as another.  But avoid the broken or
 # incompatible versions:

diff --git a/configure.ac b/configure.ac
index b0bc499..775bb19 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,5 @@
 AC_PREREQ([2.65])
 AC_INIT([portage-utils], [git])
-AC_CONFIG_AUX_DIR([autotools])
 AM_INIT_AUTOMAKE([1.11 dist-xz no-dist-gzip silent-rules -Wall])
 AM_SILENT_RULES([yes]) # AM_INIT_AUTOMAKE([silent-rules]) is broken atm
 AC_CONFIG_HEADER([config.h])

diff --git a/depcomp b/depcomp
new file mode 100755
index 0000000..b39f98f
--- /dev/null
+++ b/depcomp
@@ -0,0 +1,791 @@
+#! /bin/sh
+# depcomp - compile a program generating dependencies as side-effects
+
+scriptversion=2016-01-11.22; # UTC
+
+# Copyright (C) 1999-2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
+
+case $1 in
+  '')
+    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
+    exit 1;
+    ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: depcomp [--help] [--version] PROGRAM [ARGS]
+
+Run PROGRAMS ARGS to compile a file, generating dependencies
+as side-effects.
+
+Environment variables:
+  depmode     Dependency tracking mode.
+  source      Source file read by 'PROGRAMS ARGS'.
+  object      Object file output by 'PROGRAMS ARGS'.
+  DEPDIR      directory where to store dependencies.
+  depfile     Dependency file to output.
+  tmpdepfile  Temporary file to use when outputting dependencies.
+  libtool     Whether libtool is used (yes/no).
+
+Report bugs to <bug-automake@gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "depcomp $scriptversion"
+    exit $?
+    ;;
+esac
+
+# Get the directory component of the given path, and save it in the
+# global variables '$dir'.  Note that this directory component will
+# be either empty or ending with a '/' character.  This is deliberate.
+set_dir_from ()
+{
+  case $1 in
+    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
+      *) dir=;;
+  esac
+}
+
+# Get the suffix-stripped basename of the given path, and save it the
+# global variable '$base'.
+set_base_from ()
+{
+  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
+}
+
+# If no dependency file was actually created by the compiler invocation,
+# we still have to create a dummy depfile, to avoid errors with the
+# Makefile "include basename.Plo" scheme.
+make_dummy_depfile ()
+{
+  echo "#dummy" > "$depfile"
+}
+
+# Factor out some common post-processing of the generated depfile.
+# Requires the auxiliary global variable '$tmpdepfile' to be set.
+aix_post_process_depfile ()
+{
+  # If the compiler actually managed to produce a dependency file,
+  # post-process it.
+  if test -f "$tmpdepfile"; then
+    # Each line is of the form 'foo.o: dependency.h'.
+    # Do two passes, one to just change these to
+    #   $object: dependency.h
+    # and one to simply output
+    #   dependency.h:
+    # which is needed to avoid the deleted-header problem.
+    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
+      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
+    } > "$depfile"
+    rm -f "$tmpdepfile"
+  else
+    make_dummy_depfile
+  fi
+}
+
+# A tabulation character.
+tab='	'
+# A newline character.
+nl='
+'
+# Character ranges might be problematic outside the C locale.
+# These definitions help.
+upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
+lower=abcdefghijklmnopqrstuvwxyz
+digits=0123456789
+alpha=${upper}${lower}
+
+if test -z "$depmode" || test -z "$source" || test -z "$object"; then
+  echo "depcomp: Variables source, object and depmode must be set" 1>&2
+  exit 1
+fi
+
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
+depfile=${depfile-`echo "$object" |
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
+tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
+
+rm -f "$tmpdepfile"
+
+# Avoid interferences from the environment.
+gccflag= dashmflag=
+
+# Some modes work just like other modes, but use different flags.  We
+# parameterize here, but still list the modes in the big case below,
+# to make depend.m4 easier to write.  Note that we *cannot* use a case
+# here, because this file can only contain one case statement.
+if test "$depmode" = hp; then
+  # HP compiler uses -M and no extra arg.
+  gccflag=-M
+  depmode=gcc
+fi
+
+if test "$depmode" = dashXmstdout; then
+  # This is just like dashmstdout with a different argument.
+  dashmflag=-xM
+  depmode=dashmstdout
+fi
+
+cygpath_u="cygpath -u -f -"
+if test "$depmode" = msvcmsys; then
+  # This is just like msvisualcpp but w/o cygpath translation.
+  # Just convert the backslash-escaped backslashes to single forward
+  # slashes to satisfy depend.m4
+  cygpath_u='sed s,\\\\,/,g'
+  depmode=msvisualcpp
+fi
+
+if test "$depmode" = msvc7msys; then
+  # This is just like msvc7 but w/o cygpath translation.
+  # Just convert the backslash-escaped backslashes to single forward
+  # slashes to satisfy depend.m4
+  cygpath_u='sed s,\\\\,/,g'
+  depmode=msvc7
+fi
+
+if test "$depmode" = xlc; then
+  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
+  gccflag=-qmakedep=gcc,-MF
+  depmode=gcc
+fi
+
+case "$depmode" in
+gcc3)
+## gcc 3 implements dependency tracking that does exactly what
+## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
+## it if -MD -MP comes after the -MF stuff.  Hmm.
+## Unfortunately, FreeBSD c89 acceptance of flags depends upon
+## the command line argument order; so add the flags where they
+## appear in depend2.am.  Note that the slowdown incurred here
+## affects only configure: in makefiles, %FASTDEP% shortcuts this.
+  for arg
+  do
+    case $arg in
+    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
+    *)  set fnord "$@" "$arg" ;;
+    esac
+    shift # fnord
+    shift # $arg
+  done
+  "$@"
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  mv "$tmpdepfile" "$depfile"
+  ;;
+
+gcc)
+## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
+## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
+## (see the conditional assignment to $gccflag above).
+## There are various ways to get dependency output from gcc.  Here's
+## why we pick this rather obscure method:
+## - Don't want to use -MD because we'd like the dependencies to end
+##   up in a subdir.  Having to rename by hand is ugly.
+##   (We might end up doing this anyway to support other compilers.)
+## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
+##   -MM, not -M (despite what the docs say).  Also, it might not be
+##   supported by the other compilers which use the 'gcc' depmode.
+## - Using -M directly means running the compiler twice (even worse
+##   than renaming).
+  if test -z "$gccflag"; then
+    gccflag=-MD,
+  fi
+  "$@" -Wp,"$gccflag$tmpdepfile"
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  # The second -e expression handles DOS-style file names with drive
+  # letters.
+  sed -e 's/^[^:]*: / /' \
+      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
+## This next piece of magic avoids the "deleted header file" problem.
+## The problem is that when a header file which appears in a .P file
+## is deleted, the dependency causes make to die (because there is
+## typically no way to rebuild the header).  We avoid this by adding
+## dummy dependencies for each header file.  Too bad gcc doesn't do
+## this for us directly.
+## Some versions of gcc put a space before the ':'.  On the theory
+## that the space means something, we add a space to the output as
+## well.  hp depmode also adds that space, but also prefixes the VPATH
+## to the object.  Take care to not repeat it in the output.
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+  tr ' ' "$nl" < "$tmpdepfile" \
+    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
+    | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+sgi)
+  if test "$libtool" = yes; then
+    "$@" "-Wp,-MDupdate,$tmpdepfile"
+  else
+    "$@" -MDupdate "$tmpdepfile"
+  fi
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+
+  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
+    echo "$object : \\" > "$depfile"
+    # Clip off the initial element (the dependent).  Don't try to be
+    # clever and replace this with sed code, as IRIX sed won't handle
+    # lines with more than a fixed number of characters (4096 in
+    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
+    # the IRIX cc adds comments like '#:fec' to the end of the
+    # dependency line.
+    tr ' ' "$nl" < "$tmpdepfile" \
+      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
+      | tr "$nl" ' ' >> "$depfile"
+    echo >> "$depfile"
+    # The second pass generates a dummy entry for each header file.
+    tr ' ' "$nl" < "$tmpdepfile" \
+      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
+      >> "$depfile"
+  else
+    make_dummy_depfile
+  fi
+  rm -f "$tmpdepfile"
+  ;;
+
+xlc)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+aix)
+  # The C for AIX Compiler uses -M and outputs the dependencies
+  # in a .u file.  In older versions, this file always lives in the
+  # current directory.  Also, the AIX compiler puts '$object:' at the
+  # start of each line; $object doesn't have directory information.
+  # Version 6 uses the directory in both cases.
+  set_dir_from "$object"
+  set_base_from "$object"
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$base.u
+    tmpdepfile3=$dir.libs/$base.u
+    "$@" -Wc,-M
+  else
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$dir$base.u
+    tmpdepfile3=$dir$base.u
+    "$@" -M
+  fi
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+    exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  aix_post_process_depfile
+  ;;
+
+tcc)
+  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
+  # FIXME: That version still under development at the moment of writing.
+  #        Make that this statement remains true also for stable, released
+  #        versions.
+  # It will wrap lines (doesn't matter whether long or short) with a
+  # trailing '\', as in:
+  #
+  #   foo.o : \
+  #    foo.c \
+  #    foo.h \
+  #
+  # It will put a trailing '\' even on the last line, and will use leading
+  # spaces rather than leading tabs (at least since its commit 0394caf7
+  # "Emit spaces for -MD").
+  "$@" -MD -MF "$tmpdepfile"
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
+  # We have to change lines of the first kind to '$object: \'.
+  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
+  # And for each line of the second kind, we have to emit a 'dep.h:'
+  # dummy dependency, to avoid the deleted-header problem.
+  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+## The order of this option in the case statement is important, since the
+## shell code in configure will try each of these formats in the order
+## listed in this file.  A plain '-MD' option would be understood by many
+## compilers, so we must ensure this comes after the gcc and icc options.
+pgcc)
+  # Portland's C compiler understands '-MD'.
+  # Will always output deps to 'file.d' where file is the root name of the
+  # source file under compilation, even if file resides in a subdirectory.
+  # The object file name does not affect the name of the '.d' file.
+  # pgcc 10.2 will output
+  #    foo.o: sub/foo.c sub/foo.h
+  # and will wrap long lines using '\' :
+  #    foo.o: sub/foo.c ... \
+  #     sub/foo.h ... \
+  #     ...
+  set_dir_from "$object"
+  # Use the source, not the object, to determine the base name, since
+  # that's sadly what pgcc will do too.
+  set_base_from "$source"
+  tmpdepfile=$base.d
+
+  # For projects that build the same source file twice into different object
+  # files, the pgcc approach of using the *source* file root name can cause
+  # problems in parallel builds.  Use a locking strategy to avoid stomping on
+  # the same $tmpdepfile.
+  lockdir=$base.d-lock
+  trap "
+    echo '$0: caught signal, cleaning up...' >&2
+    rmdir '$lockdir'
+    exit 1
+  " 1 2 13 15
+  numtries=100
+  i=$numtries
+  while test $i -gt 0; do
+    # mkdir is a portable test-and-set.
+    if mkdir "$lockdir" 2>/dev/null; then
+      # This process acquired the lock.
+      "$@" -MD
+      stat=$?
+      # Release the lock.
+      rmdir "$lockdir"
+      break
+    else
+      # If the lock is being held by a different process, wait
+      # until the winning process is done or we timeout.
+      while test -d "$lockdir" && test $i -gt 0; do
+        sleep 1
+        i=`expr $i - 1`
+      done
+    fi
+    i=`expr $i - 1`
+  done
+  trap - 1 2 13 15
+  if test $i -le 0; then
+    echo "$0: failed to acquire lock after $numtries attempts" >&2
+    echo "$0: check lockdir '$lockdir'" >&2
+    exit 1
+  fi
+
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  # Each line is of the form `foo.o: dependent.h',
+  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
+  # Do two passes, one to just change these to
+  # `$object: dependent.h' and one to simply `dependent.h:'.
+  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
+    | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp2)
+  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
+  # compilers, which have integrated preprocessors.  The correct option
+  # to use with these is +Maked; it writes dependencies to a file named
+  # 'foo.d', which lands next to the object file, wherever that
+  # happens to be.
+  # Much of this is similar to the tru64 case; see comments there.
+  set_dir_from  "$object"
+  set_base_from "$object"
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir.libs/$base.d
+    "$@" -Wc,+Maked
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    "$@" +Maked
+  fi
+  stat=$?
+  if test $stat -ne 0; then
+     rm -f "$tmpdepfile1" "$tmpdepfile2"
+     exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
+    # Add 'dependent.h:' lines.
+    sed -ne '2,${
+               s/^ *//
+               s/ \\*$//
+               s/$/:/
+               p
+             }' "$tmpdepfile" >> "$depfile"
+  else
+    make_dummy_depfile
+  fi
+  rm -f "$tmpdepfile" "$tmpdepfile2"
+  ;;
+
+tru64)
+  # The Tru64 compiler uses -MD to generate dependencies as a side
+  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
+  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
+  # dependencies in 'foo.d' instead, so we check for that too.
+  # Subdirectories are respected.
+  set_dir_from  "$object"
+  set_base_from "$object"
+
+  if test "$libtool" = yes; then
+    # Libtool generates 2 separate objects for the 2 libraries.  These
+    # two compilations output dependencies in $dir.libs/$base.o.d and
+    # in $dir$base.o.d.  We have to check for both files, because
+    # one of the two compilations can be disabled.  We should prefer
+    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+    # automatically cleaned when .libs/ is deleted, while ignoring
+    # the former would cause a distcleancheck panic.
+    tmpdepfile1=$dir$base.o.d          # libtool 1.5
+    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
+    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
+    "$@" -Wc,-MD
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    tmpdepfile3=$dir$base.d
+    "$@" -MD
+  fi
+
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+    exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  # Same post-processing that is required for AIX mode.
+  aix_post_process_depfile
+  ;;
+
+msvc7)
+  if test "$libtool" = yes; then
+    showIncludes=-Wc,-showIncludes
+  else
+    showIncludes=-showIncludes
+  fi
+  "$@" $showIncludes > "$tmpdepfile"
+  stat=$?
+  grep -v '^Note: including file: ' "$tmpdepfile"
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  # The first sed program below extracts the file names and escapes
+  # backslashes for cygpath.  The second sed program outputs the file
+  # name when reading, but also accumulates all include files in the
+  # hold buffer in order to output them again at the end.  This only
+  # works with sed implementations that can handle large buffers.
+  sed < "$tmpdepfile" -n '
+/^Note: including file:  *\(.*\)/ {
+  s//\1/
+  s/\\/\\\\/g
+  p
+}' | $cygpath_u | sort -u | sed -n '
+s/ /\\ /g
+s/\(.*\)/'"$tab"'\1 \\/p
+s/.\(.*\) \\/\1:/
+H
+$ {
+  s/.*/'"$tab"'/
+  G
+  p
+}' >> "$depfile"
+  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
+  rm -f "$tmpdepfile"
+  ;;
+
+msvc7msys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+#nosideeffect)
+  # This comment above is used by automake to tell side-effect
+  # dependency tracking mechanisms from slower ones.
+
+dashmstdout)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout, regardless of -o.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove '-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  test -z "$dashmflag" && dashmflag=-M
+  # Require at least two characters before searching for ':'
+  # in the target name.  This is to cope with DOS-style filenames:
+  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
+  "$@" $dashmflag |
+    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
+  rm -f "$depfile"
+  cat < "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this sed invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  tr ' ' "$nl" < "$tmpdepfile" \
+    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
+    | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+dashXmstdout)
+  # This case only exists to satisfy depend.m4.  It is never actually
+  # run, as this mode is specially recognized in the preamble.
+  exit 1
+  ;;
+
+makedepend)
+  "$@" || exit $?
+  # Remove any Libtool call
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+  # X makedepend
+  shift
+  cleared=no eat=no
+  for arg
+  do
+    case $cleared in
+    no)
+      set ""; shift
+      cleared=yes ;;
+    esac
+    if test $eat = yes; then
+      eat=no
+      continue
+    fi
+    case "$arg" in
+    -D*|-I*)
+      set fnord "$@" "$arg"; shift ;;
+    # Strip any option that makedepend may not understand.  Remove
+    # the object too, otherwise makedepend will parse it as a source file.
+    -arch)
+      eat=yes ;;
+    -*|$object)
+      ;;
+    *)
+      set fnord "$@" "$arg"; shift ;;
+    esac
+  done
+  obj_suffix=`echo "$object" | sed 's/^.*\././'`
+  touch "$tmpdepfile"
+  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
+  rm -f "$depfile"
+  # makedepend may prepend the VPATH from the source file name to the object.
+  # No need to regex-escape $object, excess matching of '.' is harmless.
+  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process the last invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed '1,2d' "$tmpdepfile" \
+    | tr ' ' "$nl" \
+    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
+    | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile" "$tmpdepfile".bak
+  ;;
+
+cpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove '-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  "$@" -E \
+    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+    | sed '$ s: \\$::' > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  cat < "$tmpdepfile" >> "$depfile"
+  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvisualcpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  IFS=" "
+  for arg
+  do
+    case "$arg" in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
+        set fnord "$@"
+        shift
+        shift
+        ;;
+    *)
+        set fnord "$@" "$arg"
+        shift
+        shift
+        ;;
+    esac
+  done
+  "$@" -E 2>/dev/null |
+  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
+  echo "$tab" >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvcmsys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+none)
+  exec "$@"
+  ;;
+
+*)
+  echo "Unknown depmode $depmode" 1>&2
+  exit 1
+  ;;
+esac
+
+exit 0
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC0"
+# time-stamp-end: "; # UTC"
+# End:

diff --git a/install-sh b/install-sh
new file mode 100755
index 0000000..c143b86
--- /dev/null
+++ b/install-sh
@@ -0,0 +1,508 @@
+#!/bin/sh
+# install - install a program, script, or datafile
+
+scriptversion=2016-01-11.22; # UTC
+
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
+# later released in X11R6 (xc/config/util/install.sh) with the
+# following copyright and license.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# 'make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+
+tab='	'
+nl='
+'
+IFS=" $tab$nl"
+
+# Set DOITPROG to "echo" to test this script.
+
+doit=${DOITPROG-}
+doit_exec=${doit:-exec}
+
+# Put in absolute file names if you don't have them in your path;
+# or use environment vars.
+
+chgrpprog=${CHGRPPROG-chgrp}
+chmodprog=${CHMODPROG-chmod}
+chownprog=${CHOWNPROG-chown}
+cmpprog=${CMPPROG-cmp}
+cpprog=${CPPROG-cp}
+mkdirprog=${MKDIRPROG-mkdir}
+mvprog=${MVPROG-mv}
+rmprog=${RMPROG-rm}
+stripprog=${STRIPPROG-strip}
+
+posix_mkdir=
+
+# Desired mode of installed file.
+mode=0755
+
+chgrpcmd=
+chmodcmd=$chmodprog
+chowncmd=
+mvcmd=$mvprog
+rmcmd="$rmprog -f"
+stripcmd=
+
+src=
+dst=
+dir_arg=
+dst_arg=
+
+copy_on_change=false
+is_target_a_directory=possibly
+
+usage="\
+Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
+
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
+
+Options:
+     --help     display this help and exit.
+     --version  display version info and exit.
+
+  -c            (ignored)
+  -C            install only if different (preserve the last data modification time)
+  -d            create directories instead of installing files.
+  -g GROUP      $chgrpprog installed files to GROUP.
+  -m MODE       $chmodprog installed files to MODE.
+  -o USER       $chownprog installed files to USER.
+  -s            $stripprog installed files.
+  -t DIRECTORY  install into DIRECTORY.
+  -T            report an error if DSTFILE is a directory.
+
+Environment variables override the default commands:
+  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
+  RMPROG STRIPPROG
+"
+
+while test $# -ne 0; do
+  case $1 in
+    -c) ;;
+
+    -C) copy_on_change=true;;
+
+    -d) dir_arg=true;;
+
+    -g) chgrpcmd="$chgrpprog $2"
+        shift;;
+
+    --help) echo "$usage"; exit $?;;
+
+    -m) mode=$2
+        case $mode in
+          *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
+            echo "$0: invalid mode: $mode" >&2
+            exit 1;;
+        esac
+        shift;;
+
+    -o) chowncmd="$chownprog $2"
+        shift;;
+
+    -s) stripcmd=$stripprog;;
+
+    -t)
+        is_target_a_directory=always
+        dst_arg=$2
+        # Protect names problematic for 'test' and other utilities.
+        case $dst_arg in
+          -* | [=\(\)!]) dst_arg=./$dst_arg;;
+        esac
+        shift;;
+
+    -T) is_target_a_directory=never;;
+
+    --version) echo "$0 $scriptversion"; exit $?;;
+
+    --) shift
+        break;;
+
+    -*) echo "$0: invalid option: $1" >&2
+        exit 1;;
+
+    *)  break;;
+  esac
+  shift
+done
+
+# We allow the use of options -d and -T together, by making -d
+# take the precedence; this is for compatibility with GNU install.
+
+if test -n "$dir_arg"; then
+  if test -n "$dst_arg"; then
+    echo "$0: target directory not allowed when installing a directory." >&2
+    exit 1
+  fi
+fi
+
+if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
+  # When -d is used, all remaining arguments are directories to create.
+  # When -t is used, the destination is already specified.
+  # Otherwise, the last argument is the destination.  Remove it from $@.
+  for arg
+  do
+    if test -n "$dst_arg"; then
+      # $@ is not empty: it contains at least $arg.
+      set fnord "$@" "$dst_arg"
+      shift # fnord
+    fi
+    shift # arg
+    dst_arg=$arg
+    # Protect names problematic for 'test' and other utilities.
+    case $dst_arg in
+      -* | [=\(\)!]) dst_arg=./$dst_arg;;
+    esac
+  done
+fi
+
+if test $# -eq 0; then
+  if test -z "$dir_arg"; then
+    echo "$0: no input file specified." >&2
+    exit 1
+  fi
+  # It's OK to call 'install-sh -d' without argument.
+  # This can happen when creating conditional directories.
+  exit 0
+fi
+
+if test -z "$dir_arg"; then
+  if test $# -gt 1 || test "$is_target_a_directory" = always; then
+    if test ! -d "$dst_arg"; then
+      echo "$0: $dst_arg: Is not a directory." >&2
+      exit 1
+    fi
+  fi
+fi
+
+if test -z "$dir_arg"; then
+  do_exit='(exit $ret); exit $ret'
+  trap "ret=129; $do_exit" 1
+  trap "ret=130; $do_exit" 2
+  trap "ret=141; $do_exit" 13
+  trap "ret=143; $do_exit" 15
+
+  # Set umask so as not to create temps with too-generous modes.
+  # However, 'strip' requires both read and write access to temps.
+  case $mode in
+    # Optimize common cases.
+    *644) cp_umask=133;;
+    *755) cp_umask=22;;
+
+    *[0-7])
+      if test -z "$stripcmd"; then
+        u_plus_rw=
+      else
+        u_plus_rw='% 200'
+      fi
+      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
+    *)
+      if test -z "$stripcmd"; then
+        u_plus_rw=
+      else
+        u_plus_rw=,u+rw
+      fi
+      cp_umask=$mode$u_plus_rw;;
+  esac
+fi
+
+for src
+do
+  # Protect names problematic for 'test' and other utilities.
+  case $src in
+    -* | [=\(\)!]) src=./$src;;
+  esac
+
+  if test -n "$dir_arg"; then
+    dst=$src
+    dstdir=$dst
+    test -d "$dstdir"
+    dstdir_status=$?
+  else
+
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+    # might cause directories to be created, which would be especially bad
+    # if $src (and thus $dsttmp) contains '*'.
+    if test ! -f "$src" && test ! -d "$src"; then
+      echo "$0: $src does not exist." >&2
+      exit 1
+    fi
+
+    if test -z "$dst_arg"; then
+      echo "$0: no destination specified." >&2
+      exit 1
+    fi
+    dst=$dst_arg
+
+    # If destination is a directory, append the input filename; won't work
+    # if double slashes aren't ignored.
+    if test -d "$dst"; then
+      if test "$is_target_a_directory" = never; then
+        echo "$0: $dst_arg: Is a directory" >&2
+        exit 1
+      fi
+      dstdir=$dst
+      dst=$dstdir/`basename "$src"`
+      dstdir_status=0
+    else
+      dstdir=`dirname "$dst"`
+      test -d "$dstdir"
+      dstdir_status=$?
+    fi
+  fi
+
+  obsolete_mkdir_used=false
+
+  if test $dstdir_status != 0; then
+    case $posix_mkdir in
+      '')
+        # Create intermediate dirs using mode 755 as modified by the umask.
+        # This is like FreeBSD 'install' as of 1997-10-28.
+        umask=`umask`
+        case $stripcmd.$umask in
+          # Optimize common cases.
+          *[2367][2367]) mkdir_umask=$umask;;
+          .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
+
+          *[0-7])
+            mkdir_umask=`expr $umask + 22 \
+              - $umask % 100 % 40 + $umask % 20 \
+              - $umask % 10 % 4 + $umask % 2
+            `;;
+          *) mkdir_umask=$umask,go-w;;
+        esac
+
+        # With -d, create the new directory with the user-specified mode.
+        # Otherwise, rely on $mkdir_umask.
+        if test -n "$dir_arg"; then
+          mkdir_mode=-m$mode
+        else
+          mkdir_mode=
+        fi
+
+        posix_mkdir=false
+        case $umask in
+          *[123567][0-7][0-7])
+            # POSIX mkdir -p sets u+wx bits regardless of umask, which
+            # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
+            ;;
+          *)
+            # $RANDOM is not portable (e.g. dash);  use it when possible to
+            # lower collision chance
+            tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
+            trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0
+
+            # As "mkdir -p" follows symlinks and we work in /tmp possibly;  so
+            # create the $tmpdir first (and fail if unsuccessful) to make sure
+            # that nobody tries to guess the $tmpdir name.
+            if (umask $mkdir_umask &&
+                $mkdirprog $mkdir_mode "$tmpdir" &&
+                exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
+            then
+              if test -z "$dir_arg" || {
+                   # Check for POSIX incompatibilities with -m.
+                   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
+                   # other-writable bit of parent directory when it shouldn't.
+                   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
+                   test_tmpdir="$tmpdir/a"
+                   ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
+                   case $ls_ld_tmpdir in
+                     d????-?r-*) different_mode=700;;
+                     d????-?--*) different_mode=755;;
+                     *) false;;
+                   esac &&
+                   $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
+                     ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
+                     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
+                   }
+                 }
+              then posix_mkdir=:
+              fi
+              rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
+            else
+              # Remove any dirs left behind by ancient mkdir implementations.
+              rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
+            fi
+            trap '' 0;;
+        esac;;
+    esac
+
+    if
+      $posix_mkdir && (
+        umask $mkdir_umask &&
+        $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
+      )
+    then :
+    else
+
+      # The umask is ridiculous, or mkdir does not conform to POSIX,
+      # or it failed possibly due to a race condition.  Create the
+      # directory the slow way, step by step, checking for races as we go.
+
+      case $dstdir in
+        /*) prefix='/';;
+        [-=\(\)!]*) prefix='./';;
+        *)  prefix='';;
+      esac
+
+      oIFS=$IFS
+      IFS=/
+      set -f
+      set fnord $dstdir
+      shift
+      set +f
+      IFS=$oIFS
+
+      prefixes=
+
+      for d
+      do
+        test X"$d" = X && continue
+
+        prefix=$prefix$d
+        if test -d "$prefix"; then
+          prefixes=
+        else
+          if $posix_mkdir; then
+            (umask=$mkdir_umask &&
+             $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
+            # Don't fail if two instances are running concurrently.
+            test -d "$prefix" || exit 1
+          else
+            case $prefix in
+              *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
+              *) qprefix=$prefix;;
+            esac
+            prefixes="$prefixes '$qprefix'"
+          fi
+        fi
+        prefix=$prefix/
+      done
+
+      if test -n "$prefixes"; then
+        # Don't fail if two instances are running concurrently.
+        (umask $mkdir_umask &&
+         eval "\$doit_exec \$mkdirprog $prefixes") ||
+          test -d "$dstdir" || exit 1
+        obsolete_mkdir_used=true
+      fi
+    fi
+  fi
+
+  if test -n "$dir_arg"; then
+    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
+    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
+      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
+  else
+
+    # Make a couple of temp file names in the proper directory.
+    dsttmp=$dstdir/_inst.$$_
+    rmtmp=$dstdir/_rm.$$_
+
+    # Trap to clean up those temp files at exit.
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+
+    # Copy the file name to the temp name.
+    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
+
+    # and set any options; do chmod last to preserve setuid bits.
+    #
+    # If any of these fail, we abort the whole thing.  If we want to
+    # ignore errors from any of these, just make sure not to ignore
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
+    #
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
+    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
+    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
+
+    # If -C, don't bother to copy if it wouldn't change the file.
+    if $copy_on_change &&
+       old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
+       new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
+       set -f &&
+       set X $old && old=:$2:$4:$5:$6 &&
+       set X $new && new=:$2:$4:$5:$6 &&
+       set +f &&
+       test "$old" = "$new" &&
+       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
+    then
+      rm -f "$dsttmp"
+    else
+      # Rename the file to the real destination.
+      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
+
+      # The rename failed, perhaps because mv can't rename something else
+      # to itself, or perhaps because mv is so ancient that it does not
+      # support -f.
+      {
+        # Now remove or move aside any old file at destination location.
+        # We try this two ways since rm can't unlink itself on some
+        # systems and the destination file might be busy for other
+        # reasons.  In this case, the final cleanup might fail but the new
+        # file should still install successfully.
+        {
+          test ! -f "$dst" ||
+          $doit $rmcmd -f "$dst" 2>/dev/null ||
+          { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
+            { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
+          } ||
+          { echo "$0: cannot unlink or rename $dst" >&2
+            (exit 1); exit 1
+          }
+        } &&
+
+        # Now rename the file to the real destination.
+        $doit $mvcmd "$dsttmp" "$dst"
+      }
+    fi || exit 1
+
+    trap '' 0
+  fi
+done
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC0"
+# time-stamp-end: "; # UTC"
+# End:

diff --git a/libq/Makefile.in b/libq/Makefile.in
index 1911efe..96e9580 100644
--- a/libq/Makefile.in
+++ b/libq/Makefile.in
@@ -264,7 +264,7 @@ am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 am__v_at_1 = 
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
-depcomp = $(SHELL) $(top_srcdir)/autotools/depcomp
+depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -311,8 +311,7 @@ am__define_uniq_tagged_files = \
   done | $(am__uniquify_input)`
 ETAGS = etags
 CTAGS = ctags
-am__DIST_COMMON = $(srcdir)/Makefile.in \
-	$(top_srcdir)/autotools/depcomp
+am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 ALLOCA = @ALLOCA@

diff --git a/ltmain.sh b/ltmain.sh
new file mode 100644
index 0000000..e774ddf
--- /dev/null
+++ b/ltmain.sh
@@ -0,0 +1,11210 @@
+#! /bin/sh
+## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
+##               by inline-source v2014-01-03.01
+
+# libtool (GNU libtool) 2.4.6
+# Provide generalized library-building support services.
+# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
+
+# Copyright (C) 1996-2015 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# GNU Libtool is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+PROGRAM=libtool
+PACKAGE=libtool
+VERSION=2.4.6
+package_revision=2.4.6
+
+
+## ------ ##
+## Usage. ##
+## ------ ##
+
+# Run './libtool --help' for help with using this script from the
+# command line.
+
+
+## ------------------------------- ##
+## User overridable command paths. ##
+## ------------------------------- ##
+
+# After configure completes, it has a better idea of some of the
+# shell tools we need than the defaults used by the functions shared
+# with bootstrap, so set those here where they can still be over-
+# ridden by the user, but otherwise take precedence.
+
+: ${AUTOCONF="autoconf"}
+: ${AUTOMAKE="automake"}
+
+
+## -------------------------- ##
+## Source external libraries. ##
+## -------------------------- ##
+
+# Much of our low-level functionality needs to be sourced from external
+# libraries, which are installed to $pkgauxdir.
+
+# Set a version string for this script.
+scriptversion=2015-10-04.22; # UTC
+
+# General shell script boiler plate, and helper functions.
+# Written by Gary V. Vaughan, 2004
+
+# Copyright (C) 2004-2015 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# As a special exception to the GNU General Public License, if you distribute
+# this file as part of a program or library that is built using GNU Libtool,
+# you may include this file under the same distribution terms that you use
+# for the rest of that program.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Please report bugs or propose patches to gary@gnu.org.
+
+
+## ------ ##
+## Usage. ##
+## ------ ##
+
+# Evaluate this file near the top of your script to gain access to
+# the functions and variables defined here:
+#
+#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
+#
+# If you need to override any of the default environment variable
+# settings, do that before evaluating this file.
+
+
+## -------------------- ##
+## Shell normalisation. ##
+## -------------------- ##
+
+# Some shells need a little help to be as Bourne compatible as possible.
+# Before doing anything else, make sure all that help has been provided!
+
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
+fi
+
+# NLS nuisances: We save the old values in case they are required later.
+_G_user_locale=
+_G_safe_locale=
+for _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+do
+  eval "if test set = \"\${$_G_var+set}\"; then
+          save_$_G_var=\$$_G_var
+          $_G_var=C
+	  export $_G_var
+	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
+	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
+	fi"
+done
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+# Make sure IFS has a sensible default
+sp=' '
+nl='
+'
+IFS="$sp	$nl"
+
+# There are apparently some retarded systems that use ';' as a PATH separator!
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+
+## ------------------------- ##
+## Locate command utilities. ##
+## ------------------------- ##
+
+
+# func_executable_p FILE
+# ----------------------
+# Check that FILE is an executable regular file.
+func_executable_p ()
+{
+    test -f "$1" && test -x "$1"
+}
+
+
+# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
+# --------------------------------------------
+# Search for either a program that responds to --version with output
+# containing "GNU", or else returned by CHECK_FUNC otherwise, by
+# trying all the directories in PATH with each of the elements of
+# PROGS_LIST.
+#
+# CHECK_FUNC should accept the path to a candidate program, and
+# set $func_check_prog_result if it truncates its output less than
+# $_G_path_prog_max characters.
+func_path_progs ()
+{
+    _G_progs_list=$1
+    _G_check_func=$2
+    _G_PATH=${3-"$PATH"}
+
+    _G_path_prog_max=0
+    _G_path_prog_found=false
+    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
+    for _G_dir in $_G_PATH; do
+      IFS=$_G_save_IFS
+      test -z "$_G_dir" && _G_dir=.
+      for _G_prog_name in $_G_progs_list; do
+        for _exeext in '' .EXE; do
+          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
+          func_executable_p "$_G_path_prog" || continue
+          case `"$_G_path_prog" --version 2>&1` in
+            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
+            *)     $_G_check_func $_G_path_prog
+		   func_path_progs_result=$func_check_prog_result
+		   ;;
+          esac
+          $_G_path_prog_found && break 3
+        done
+      done
+    done
+    IFS=$_G_save_IFS
+    test -z "$func_path_progs_result" && {
+      echo "no acceptable sed could be found in \$PATH" >&2
+      exit 1
+    }
+}
+
+
+# We want to be able to use the functions in this file before configure
+# has figured out where the best binaries are kept, which means we have
+# to search for them ourselves - except when the results are already set
+# where we skip the searches.
+
+# Unless the user overrides by setting SED, search the path for either GNU
+# sed, or the sed that truncates its output the least.
+test -z "$SED" && {
+  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
+  for _G_i in 1 2 3 4 5 6 7; do
+    _G_sed_script=$_G_sed_script$nl$_G_sed_script
+  done
+  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
+  _G_sed_script=
+
+  func_check_prog_sed ()
+  {
+    _G_path_prog=$1
+
+    _G_count=0
+    printf 0123456789 >conftest.in
+    while :
+    do
+      cat conftest.in conftest.in >conftest.tmp
+      mv conftest.tmp conftest.in
+      cp conftest.in conftest.nl
+      echo '' >> conftest.nl
+      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
+      diff conftest.out conftest.nl >/dev/null 2>&1 || break
+      _G_count=`expr $_G_count + 1`
+      if test "$_G_count" -gt "$_G_path_prog_max"; then
+        # Best one so far, save it but keep looking for a better one
+        func_check_prog_result=$_G_path_prog
+        _G_path_prog_max=$_G_count
+      fi
+      # 10*(2^10) chars as input seems more than enough
+      test 10 -lt "$_G_count" && break
+    done
+    rm -f conftest.in conftest.tmp conftest.nl conftest.out
+  }
+
+  func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
+  rm -f conftest.sed
+  SED=$func_path_progs_result
+}
+
+
+# Unless the user overrides by setting GREP, search the path for either GNU
+# grep, or the grep that truncates its output the least.
+test -z "$GREP" && {
+  func_check_prog_grep ()
+  {
+    _G_path_prog=$1
+
+    _G_count=0
+    _G_path_prog_max=0
+    printf 0123456789 >conftest.in
+    while :
+    do
+      cat conftest.in conftest.in >conftest.tmp
+      mv conftest.tmp conftest.in
+      cp conftest.in conftest.nl
+      echo 'GREP' >> conftest.nl
+      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
+      diff conftest.out conftest.nl >/dev/null 2>&1 || break
+      _G_count=`expr $_G_count + 1`
+      if test "$_G_count" -gt "$_G_path_prog_max"; then
+        # Best one so far, save it but keep looking for a better one
+        func_check_prog_result=$_G_path_prog
+        _G_path_prog_max=$_G_count
+      fi
+      # 10*(2^10) chars as input seems more than enough
+      test 10 -lt "$_G_count" && break
+    done
+    rm -f conftest.in conftest.tmp conftest.nl conftest.out
+  }
+
+  func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
+  GREP=$func_path_progs_result
+}
+
+
+## ------------------------------- ##
+## User overridable command paths. ##
+## ------------------------------- ##
+
+# All uppercase variable names are used for environment variables.  These
+# variables can be overridden by the user before calling a script that
+# uses them if a suitable command of that name is not already available
+# in the command search PATH.
+
+: ${CP="cp -f"}
+: ${ECHO="printf %s\n"}
+: ${EGREP="$GREP -E"}
+: ${FGREP="$GREP -F"}
+: ${LN_S="ln -s"}
+: ${MAKE="make"}
+: ${MKDIR="mkdir"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
+
+
+## -------------------- ##
+## Useful sed snippets. ##
+## -------------------- ##
+
+sed_dirname='s|/[^/]*$||'
+sed_basename='s|^.*/||'
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
+
+# Same as above, but do not quote variable references.
+sed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
+
+# Sed substitution that turns a string into a regex matching for the
+# string literally.
+sed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
+
+# Sed substitution that converts a w32 file name or path
+# that contains forward slashes, into one that contains
+# (escaped) backslashes.  A very naive implementation.
+sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+
+# Re-'\' parameter expansions in output of sed_double_quote_subst that
+# were '\'-ed in input to the same.  If an odd number of '\' preceded a
+# '$' in input to sed_double_quote_subst, that '$' was protected from
+# expansion.  Since each input '\' is now two '\'s, look for any number
+# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
+_G_bs='\\'
+_G_bs2='\\\\'
+_G_bs4='\\\\\\\\'
+_G_dollar='\$'
+sed_double_backslash="\
+  s/$_G_bs4/&\\
+/g
+  s/^$_G_bs2$_G_dollar/$_G_bs&/
+  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
+  s/\n//g"
+
+
+## ----------------- ##
+## Global variables. ##
+## ----------------- ##
+
+# Except for the global variables explicitly listed below, the following
+# functions in the '^func_' namespace, and the '^require_' namespace
+# variables initialised in the 'Resource management' section, sourcing
+# this file will not pollute your global namespace with anything
+# else. There's no portable way to scope variables in Bourne shell
+# though, so actually running these functions will sometimes place
+# results into a variable named after the function, and often use
+# temporary variables in the '^_G_' namespace. If you are careful to
+# avoid using those namespaces casually in your sourcing script, things
+# should continue to work as you expect. And, of course, you can freely
+# overwrite any of the functions or variables defined here before
+# calling anything to customize them.
+
+EXIT_SUCCESS=0
+EXIT_FAILURE=1
+EXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
+EXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
+
+# Allow overriding, eg assuming that you follow the convention of
+# putting '$debug_cmd' at the start of all your functions, you can get
+# bash to show function call trace with:
+#
+#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
+debug_cmd=${debug_cmd-":"}
+exit_cmd=:
+
+# By convention, finish your script with:
+#
+#    exit $exit_status
+#
+# so that you can set exit_status to non-zero if you want to indicate
+# something went wrong during execution without actually bailing out at
+# the point of failure.
+exit_status=$EXIT_SUCCESS
+
+# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
+# is ksh but when the shell is invoked as "sh" and the current value of
+# the _XPG environment variable is not equal to 1 (one), the special
+# positional parameter $0, within a function call, is the name of the
+# function.
+progpath=$0
+
+# The name of this program.
+progname=`$ECHO "$progpath" |$SED "$sed_basename"`
+
+# Make sure we have an absolute progpath for reexecution:
+case $progpath in
+  [\\/]*|[A-Za-z]:\\*) ;;
+  *[\\/]*)
+     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
+     progdir=`cd "$progdir" && pwd`
+     progpath=$progdir/$progname
+     ;;
+  *)
+     _G_IFS=$IFS
+     IFS=${PATH_SEPARATOR-:}
+     for progdir in $PATH; do
+       IFS=$_G_IFS
+       test -x "$progdir/$progname" && break
+     done
+     IFS=$_G_IFS
+     test -n "$progdir" || progdir=`pwd`
+     progpath=$progdir/$progname
+     ;;
+esac
+
+
+## ----------------- ##
+## Standard options. ##
+## ----------------- ##
+
+# The following options affect the operation of the functions defined
+# below, and should be set appropriately depending on run-time para-
+# meters passed on the command line.
+
+opt_dry_run=false
+opt_quiet=false
+opt_verbose=false
+
+# Categories 'all' and 'none' are always available.  Append any others
+# you will pass as the first argument to func_warning from your own
+# code.
+warning_categories=
+
+# By default, display warnings according to 'opt_warning_types'.  Set
+# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
+# treat the next displayed warning as a fatal error.
+warning_func=func_warn_and_continue
+
+# Set to 'all' to display all warnings, 'none' to suppress all
+# warnings, or a space delimited list of some subset of
+# 'warning_categories' to display only the listed warnings.
+opt_warning_types=all
+
+
+## -------------------- ##
+## Resource management. ##
+## -------------------- ##
+
+# This section contains definitions for functions that each ensure a
+# particular resource (a file, or a non-empty configuration variable for
+# example) is available, and if appropriate to extract default values
+# from pertinent package files. Call them using their associated
+# 'require_*' variable to ensure that they are executed, at most, once.
+#
+# It's entirely deliberate that calling these functions can set
+# variables that don't obey the namespace limitations obeyed by the rest
+# of this file, in order that that they be as useful as possible to
+# callers.
+
+
+# require_term_colors
+# -------------------
+# Allow display of bold text on terminals that support it.
+require_term_colors=func_require_term_colors
+func_require_term_colors ()
+{
+    $debug_cmd
+
+    test -t 1 && {
+      # COLORTERM and USE_ANSI_COLORS environment variables take
+      # precedence, because most terminfo databases neglect to describe
+      # whether color sequences are supported.
+      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
+
+      if test 1 = "$USE_ANSI_COLORS"; then
+        # Standard ANSI escape sequences
+        tc_reset='^[[0m'
+        tc_bold='^[[1m';   tc_standout='^[[7m'
+        tc_red='^[[31m';   tc_green='^[[32m'
+        tc_blue='^[[34m';  tc_cyan='^[[36m'
+      else
+        # Otherwise trust the terminfo database after all.
+        test -n "`tput sgr0 2>/dev/null`" && {
+          tc_reset=`tput sgr0`
+          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
+          tc_standout=$tc_bold
+          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
+          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
+          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
+          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
+          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
+        }
+      fi
+    }
+
+    require_term_colors=:
+}
+
+
+## ----------------- ##
+## Function library. ##
+## ----------------- ##
+
+# This section contains a variety of useful functions to call in your
+# scripts. Take note of the portable wrappers for features provided by
+# some modern shells, which will fall back to slower equivalents on
+# less featureful shells.
+
+
+# func_append VAR VALUE
+# ---------------------
+# Append VALUE onto the existing contents of VAR.
+
+  # We should try to minimise forks, especially on Windows where they are
+  # unreasonably slow, so skip the feature probes when bash or zsh are
+  # being used:
+  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
+    : ${_G_HAVE_ARITH_OP="yes"}
+    : ${_G_HAVE_XSI_OPS="yes"}
+    # The += operator was introduced in bash 3.1
+    case $BASH_VERSION in
+      [12].* | 3.0 | 3.0*) ;;
+      *)
+        : ${_G_HAVE_PLUSEQ_OP="yes"}
+        ;;
+    esac
+  fi
+
+  # _G_HAVE_PLUSEQ_OP
+  # Can be empty, in which case the shell is probed, "yes" if += is
+  # useable or anything else if it does not work.
+  test -z "$_G_HAVE_PLUSEQ_OP" \
+    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
+    && _G_HAVE_PLUSEQ_OP=yes
+
+if test yes = "$_G_HAVE_PLUSEQ_OP"
+then
+  # This is an XSI compatible shell, allowing a faster implementation...
+  eval 'func_append ()
+  {
+    $debug_cmd
+
+    eval "$1+=\$2"
+  }'
+else
+  # ...otherwise fall back to using expr, which is often a shell builtin.
+  func_append ()
+  {
+    $debug_cmd
+
+    eval "$1=\$$1\$2"
+  }
+fi
+
+
+# func_append_quoted VAR VALUE
+# ----------------------------
+# Quote VALUE and append to the end of shell variable VAR, separated
+# by a space.
+if test yes = "$_G_HAVE_PLUSEQ_OP"; then
+  eval 'func_append_quoted ()
+  {
+    $debug_cmd
+
+    func_quote_for_eval "$2"
+    eval "$1+=\\ \$func_quote_for_eval_result"
+  }'
+else
+  func_append_quoted ()
+  {
+    $debug_cmd
+
+    func_quote_for_eval "$2"
+    eval "$1=\$$1\\ \$func_quote_for_eval_result"
+  }
+fi
+
+
+# func_append_uniq VAR VALUE
+# --------------------------
+# Append unique VALUE onto the existing contents of VAR, assuming
+# entries are delimited by the first character of VALUE.  For example:
+#
+#   func_append_uniq options " --another-option option-argument"
+#
+# will only append to $options if " --another-option option-argument "
+# is not already present somewhere in $options already (note spaces at
+# each end implied by leading space in second argument).
+func_append_uniq ()
+{
+    $debug_cmd
+
+    eval _G_current_value='`$ECHO $'$1'`'
+    _G_delim=`expr "$2" : '\(.\)'`
+
+    case $_G_delim$_G_current_value$_G_delim in
+      *"$2$_G_delim"*) ;;
+      *) func_append "$@" ;;
+    esac
+}
+
+
+# func_arith TERM...
+# ------------------
+# Set func_arith_result to the result of evaluating TERMs.
+  test -z "$_G_HAVE_ARITH_OP" \
+    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
+    && _G_HAVE_ARITH_OP=yes
+
+if test yes = "$_G_HAVE_ARITH_OP"; then
+  eval 'func_arith ()
+  {
+    $debug_cmd
+
+    func_arith_result=$(( $* ))
+  }'
+else
+  func_arith ()
+  {
+    $debug_cmd
+
+    func_arith_result=`expr "$@"`
+  }
+fi
+
+
+# func_basename FILE
+# ------------------
+# Set func_basename_result to FILE with everything up to and including
+# the last / stripped.
+if test yes = "$_G_HAVE_XSI_OPS"; then
+  # If this shell supports suffix pattern removal, then use it to avoid
+  # forking. Hide the definitions single quotes in case the shell chokes
+  # on unsupported syntax...
+  _b='func_basename_result=${1##*/}'
+  _d='case $1 in
+        */*) func_dirname_result=${1%/*}$2 ;;
+        *  ) func_dirname_result=$3        ;;
+      esac'
+
+else
+  # ...otherwise fall back to using sed.
+  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
+  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
+      if test "X$func_dirname_result" = "X$1"; then
+        func_dirname_result=$3
+      else
+        func_append func_dirname_result "$2"
+      fi'
+fi
+
+eval 'func_basename ()
+{
+    $debug_cmd
+
+    '"$_b"'
+}'
+
+
+# func_dirname FILE APPEND NONDIR_REPLACEMENT
+# -------------------------------------------
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+eval 'func_dirname ()
+{
+    $debug_cmd
+
+    '"$_d"'
+}'
+
+
+# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
+# --------------------------------------------------------
+# Perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# For efficiency, we do not delegate to the functions above but instead
+# duplicate the functionality here.
+eval 'func_dirname_and_basename ()
+{
+    $debug_cmd
+
+    '"$_b"'
+    '"$_d"'
+}'
+
+
+# func_echo ARG...
+# ----------------
+# Echo program name prefixed message.
+func_echo ()
+{
+    $debug_cmd
+
+    _G_message=$*
+
+    func_echo_IFS=$IFS
+    IFS=$nl
+    for _G_line in $_G_message; do
+      IFS=$func_echo_IFS
+      $ECHO "$progname: $_G_line"
+    done
+    IFS=$func_echo_IFS
+}
+
+
+# func_echo_all ARG...
+# --------------------
+# Invoke $ECHO with all args, space-separated.
+func_echo_all ()
+{
+    $ECHO "$*"
+}
+
+
+# func_echo_infix_1 INFIX ARG...
+# ------------------------------
+# Echo program name, followed by INFIX on the first line, with any
+# additional lines not showing INFIX.
+func_echo_infix_1 ()
+{
+    $debug_cmd
+
+    $require_term_colors
+
+    _G_infix=$1; shift
+    _G_indent=$_G_infix
+    _G_prefix="$progname: $_G_infix: "
+    _G_message=$*
+
+    # Strip color escape sequences before counting printable length
+    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
+    do
+      test -n "$_G_tc" && {
+        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
+        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
+      }
+    done
+    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
+
+    func_echo_infix_1_IFS=$IFS
+    IFS=$nl
+    for _G_line in $_G_message; do
+      IFS=$func_echo_infix_1_IFS
+      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
+      _G_prefix=$_G_indent
+    done
+    IFS=$func_echo_infix_1_IFS
+}
+
+
+# func_error ARG...
+# -----------------
+# Echo program name prefixed message to standard error.
+func_error ()
+{
+    $debug_cmd
+
+    $require_term_colors
+
+    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
+}
+
+
+# func_fatal_error ARG...
+# -----------------------
+# Echo program name prefixed message to standard error, and exit.
+func_fatal_error ()
+{
+    $debug_cmd
+
+    func_error "$*"
+    exit $EXIT_FAILURE
+}
+
+
+# func_grep EXPRESSION FILENAME
+# -----------------------------
+# Check whether EXPRESSION matches any line of FILENAME, without output.
+func_grep ()
+{
+    $debug_cmd
+
+    $GREP "$1" "$2" >/dev/null 2>&1
+}
+
+
+# func_len STRING
+# ---------------
+# Set func_len_result to the length of STRING. STRING may not
+# start with a hyphen.
+  test -z "$_G_HAVE_XSI_OPS" \
+    && (eval 'x=a/b/c;
+      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
+    && _G_HAVE_XSI_OPS=yes
+
+if test yes = "$_G_HAVE_XSI_OPS"; then
+  eval 'func_len ()
+  {
+    $debug_cmd
+
+    func_len_result=${#1}
+  }'
+else
+  func_len ()
+  {
+    $debug_cmd
+
+    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
+  }
+fi
+
+
+# func_mkdir_p DIRECTORY-PATH
+# ---------------------------
+# Make sure the entire path to DIRECTORY-PATH is available.
+func_mkdir_p ()
+{
+    $debug_cmd
+
+    _G_directory_path=$1
+    _G_dir_list=
+
+    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
+
+      # Protect directory names starting with '-'
+      case $_G_directory_path in
+        -*) _G_directory_path=./$_G_directory_path ;;
+      esac
+
+      # While some portion of DIR does not yet exist...
+      while test ! -d "$_G_directory_path"; do
+        # ...make a list in topmost first order.  Use a colon delimited
+	# list incase some portion of path contains whitespace.
+        _G_dir_list=$_G_directory_path:$_G_dir_list
+
+        # If the last portion added has no slash in it, the list is done
+        case $_G_directory_path in */*) ;; *) break ;; esac
+
+        # ...otherwise throw away the child directory and loop
+        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
+      done
+      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
+
+      func_mkdir_p_IFS=$IFS; IFS=:
+      for _G_dir in $_G_dir_list; do
+	IFS=$func_mkdir_p_IFS
+        # mkdir can fail with a 'File exist' error if two processes
+        # try to create one of the directories concurrently.  Don't
+        # stop in that case!
+        $MKDIR "$_G_dir" 2>/dev/null || :
+      done
+      IFS=$func_mkdir_p_IFS
+
+      # Bail out if we (or some other process) failed to create a directory.
+      test -d "$_G_directory_path" || \
+        func_fatal_error "Failed to create '$1'"
+    fi
+}
+
+
+# func_mktempdir [BASENAME]
+# -------------------------
+# Make a temporary directory that won't clash with other running
+# libtool processes, and avoids race conditions if possible.  If
+# given, BASENAME is the basename for that directory.
+func_mktempdir ()
+{
+    $debug_cmd
+
+    _G_template=${TMPDIR-/tmp}/${1-$progname}
+
+    if test : = "$opt_dry_run"; then
+      # Return a directory name, but don't create it in dry-run mode
+      _G_tmpdir=$_G_template-$$
+    else
+
+      # If mktemp works, use that first and foremost
+      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
+
+      if test ! -d "$_G_tmpdir"; then
+        # Failing that, at least try and use $RANDOM to avoid a race
+        _G_tmpdir=$_G_template-${RANDOM-0}$$
+
+        func_mktempdir_umask=`umask`
+        umask 0077
+        $MKDIR "$_G_tmpdir"
+        umask $func_mktempdir_umask
+      fi
+
+      # If we're not in dry-run mode, bomb out on failure
+      test -d "$_G_tmpdir" || \
+        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
+    fi
+
+    $ECHO "$_G_tmpdir"
+}
+
+
+# func_normal_abspath PATH
+# ------------------------
+# Remove doubled-up and trailing slashes, "." path components,
+# and cancel out any ".." path components in PATH after making
+# it an absolute path.
+func_normal_abspath ()
+{
+    $debug_cmd
+
+    # These SED scripts presuppose an absolute path with a trailing slash.
+    _G_pathcar='s|^/\([^/]*\).*$|\1|'
+    _G_pathcdr='s|^/[^/]*||'
+    _G_removedotparts=':dotsl
+		s|/\./|/|g
+		t dotsl
+		s|/\.$|/|'
+    _G_collapseslashes='s|/\{1,\}|/|g'
+    _G_finalslash='s|/*$|/|'
+
+    # Start from root dir and reassemble the path.
+    func_normal_abspath_result=
+    func_normal_abspath_tpath=$1
+    func_normal_abspath_altnamespace=
+    case $func_normal_abspath_tpath in
+      "")
+        # Empty path, that just means $cwd.
+        func_stripname '' '/' "`pwd`"
+        func_normal_abspath_result=$func_stripname_result
+        return
+        ;;
+      # The next three entries are used to spot a run of precisely
+      # two leading slashes without using negated character classes;
+      # we take advantage of case's first-match behaviour.
+      ///*)
+        # Unusual form of absolute path, do nothing.
+        ;;
+      //*)
+        # Not necessarily an ordinary path; POSIX reserves leading '//'
+        # and for example Cygwin uses it to access remote file shares
+        # over CIFS/SMB, so we conserve a leading double slash if found.
+        func_normal_abspath_altnamespace=/
+        ;;
+      /*)
+        # Absolute path, do nothing.
+        ;;
+      *)
+        # Relative path, prepend $cwd.
+        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
+        ;;
+    esac
+
+    # Cancel out all the simple stuff to save iterations.  We also want
+    # the path to end with a slash for ease of parsing, so make sure
+    # there is one (and only one) here.
+    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
+          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
+    while :; do
+      # Processed it all yet?
+      if test / = "$func_normal_abspath_tpath"; then
+        # If we ascended to the root using ".." the result may be empty now.
+        if test -z "$func_normal_abspath_result"; then
+          func_normal_abspath_result=/
+        fi
+        break
+      fi
+      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
+          -e "$_G_pathcar"`
+      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
+          -e "$_G_pathcdr"`
+      # Figure out what to do with it
+      case $func_normal_abspath_tcomponent in
+        "")
+          # Trailing empty path component, ignore it.
+          ;;
+        ..)
+          # Parent dir; strip last assembled component from result.
+          func_dirname "$func_normal_abspath_result"
+          func_normal_abspath_result=$func_dirname_result
+          ;;
+        *)
+          # Actual path component, append it.
+          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
+          ;;
+      esac
+    done
+    # Restore leading double-slash if one was found on entry.
+    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
+}
+
+
+# func_notquiet ARG...
+# --------------------
+# Echo program name prefixed message only when not in quiet mode.
+func_notquiet ()
+{
+    $debug_cmd
+
+    $opt_quiet || func_echo ${1+"$@"}
+
+    # A bug in bash halts the script if the last line of a function
+    # fails when set -e is in force, so we need another command to
+    # work around that:
+    :
+}
+
+
+# func_relative_path SRCDIR DSTDIR
+# --------------------------------
+# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
+func_relative_path ()
+{
+    $debug_cmd
+
+    func_relative_path_result=
+    func_normal_abspath "$1"
+    func_relative_path_tlibdir=$func_normal_abspath_result
+    func_normal_abspath "$2"
+    func_relative_path_tbindir=$func_normal_abspath_result
+
+    # Ascend the tree starting from libdir
+    while :; do
+      # check if we have found a prefix of bindir
+      case $func_relative_path_tbindir in
+        $func_relative_path_tlibdir)
+          # found an exact match
+          func_relative_path_tcancelled=
+          break
+          ;;
+        $func_relative_path_tlibdir*)
+          # found a matching prefix
+          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
+          func_relative_path_tcancelled=$func_stripname_result
+          if test -z "$func_relative_path_result"; then
+            func_relative_path_result=.
+          fi
+          break
+          ;;
+        *)
+          func_dirname $func_relative_path_tlibdir
+          func_relative_path_tlibdir=$func_dirname_result
+          if test -z "$func_relative_path_tlibdir"; then
+            # Have to descend all the way to the root!
+            func_relative_path_result=../$func_relative_path_result
+            func_relative_path_tcancelled=$func_relative_path_tbindir
+            break
+          fi
+          func_relative_path_result=../$func_relative_path_result
+          ;;
+      esac
+    done
+
+    # Now calculate path; take care to avoid doubling-up slashes.
+    func_stripname '' '/' "$func_relative_path_result"
+    func_relative_path_result=$func_stripname_result
+    func_stripname '/' '/' "$func_relative_path_tcancelled"
+    if test -n "$func_stripname_result"; then
+      func_append func_relative_path_result "/$func_stripname_result"
+    fi
+
+    # Normalisation. If bindir is libdir, return '.' else relative path.
+    if test -n "$func_relative_path_result"; then
+      func_stripname './' '' "$func_relative_path_result"
+      func_relative_path_result=$func_stripname_result
+    fi
+
+    test -n "$func_relative_path_result" || func_relative_path_result=.
+
+    :
+}
+
+
+# func_quote ARG
+# --------------
+# Aesthetically quote one ARG, store the result into $func_quote_result.  Note
+# that we keep attention to performance here (so far O(N) complexity as long as
+# func_append is O(1)).
+func_quote ()
+{
+    $debug_cmd
+
+    func_quote_result=$1
+
+    case $func_quote_result in
+      *[\\\`\"\$]*)
+        case $func_quote_result in
+          *[\[\*\?]*)
+            func_quote_result=`$ECHO "$func_quote_result" | $SED "$sed_quote_subst"`
+            return 0
+            ;;
+        esac
+
+        func_quote_old_IFS=$IFS
+        for _G_char in '\' '`' '"' '$'
+        do
+          # STATE($1) PREV($2) SEPARATOR($3)
+          set start "" ""
+          func_quote_result=dummy"$_G_char$func_quote_result$_G_char"dummy
+          IFS=$_G_char
+          for _G_part in $func_quote_result
+          do
+            case $1 in
+            quote)
+              func_append func_quote_result "$3$2"
+              set quote "$_G_part" "\\$_G_char"
+              ;;
+            start)
+              set first "" ""
+              func_quote_result=
+              ;;
+            first)
+              set quote "$_G_part" ""
+              ;;
+            esac
+          done
+          IFS=$func_quote_old_IFS
+        done
+        ;;
+      *) ;;
+    esac
+}
+
+
+# func_quote_for_eval ARG...
+# --------------------------
+# Aesthetically quote ARGs to be evaled later.
+# This function returns two values:
+#   i) func_quote_for_eval_result
+#      double-quoted, suitable for a subsequent eval
+#  ii) func_quote_for_eval_unquoted_result
+#      has all characters that are still active within double
+#      quotes backslashified.
+func_quote_for_eval ()
+{
+    $debug_cmd
+
+    func_quote_for_eval_unquoted_result=
+    func_quote_for_eval_result=
+    while test 0 -lt $#; do
+      func_quote "$1"
+      _G_unquoted_arg=$func_quote_result
+      if test -n "$func_quote_for_eval_unquoted_result"; then
+	func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
+      else
+        func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
+      fi
+
+      case $_G_unquoted_arg in
+        # Double-quote args containing shell metacharacters to delay
+        # word splitting, command substitution and variable expansion
+        # for a subsequent eval.
+        # Many Bourne shells cannot handle close brackets correctly
+        # in scan sets, so we specify it separately.
+        *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+          _G_quoted_arg=\"$_G_unquoted_arg\"
+          ;;
+        *)
+          _G_quoted_arg=$_G_unquoted_arg
+	  ;;
+      esac
+
+      if test -n "$func_quote_for_eval_result"; then
+	func_append func_quote_for_eval_result " $_G_quoted_arg"
+      else
+        func_append func_quote_for_eval_result "$_G_quoted_arg"
+      fi
+      shift
+    done
+}
+
+
+# func_quote_for_expand ARG
+# -------------------------
+# Aesthetically quote ARG to be evaled later; same as above,
+# but do not quote variable references.
+func_quote_for_expand ()
+{
+    $debug_cmd
+
+    case $1 in
+      *[\\\`\"]*)
+	_G_arg=`$ECHO "$1" | $SED \
+	    -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
+      *)
+        _G_arg=$1 ;;
+    esac
+
+    case $_G_arg in
+      # Double-quote args containing shell metacharacters to delay
+      # word splitting and command substitution for a subsequent eval.
+      # Many Bourne shells cannot handle close brackets correctly
+      # in scan sets, so we specify it separately.
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+        _G_arg=\"$_G_arg\"
+        ;;
+    esac
+
+    func_quote_for_expand_result=$_G_arg
+}
+
+
+# func_stripname PREFIX SUFFIX NAME
+# ---------------------------------
+# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+if test yes = "$_G_HAVE_XSI_OPS"; then
+  eval 'func_stripname ()
+  {
+    $debug_cmd
+
+    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
+    # positional parameters, so assign one to ordinary variable first.
+    func_stripname_result=$3
+    func_stripname_result=${func_stripname_result#"$1"}
+    func_stripname_result=${func_stripname_result%"$2"}
+  }'
+else
+  func_stripname ()
+  {
+    $debug_cmd
+
+    case $2 in
+      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
+      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
+    esac
+  }
+fi
+
+
+# func_show_eval CMD [FAIL_EXP]
+# -----------------------------
+# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
+# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
+# is given, then evaluate it.
+func_show_eval ()
+{
+    $debug_cmd
+
+    _G_cmd=$1
+    _G_fail_exp=${2-':'}
+
+    func_quote_for_expand "$_G_cmd"
+    eval "func_notquiet $func_quote_for_expand_result"
+
+    $opt_dry_run || {
+      eval "$_G_cmd"
+      _G_status=$?
+      if test 0 -ne "$_G_status"; then
+	eval "(exit $_G_status); $_G_fail_exp"
+      fi
+    }
+}
+
+
+# func_show_eval_locale CMD [FAIL_EXP]
+# ------------------------------------
+# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
+# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
+# is given, then evaluate it.  Use the saved locale for evaluation.
+func_show_eval_locale ()
+{
+    $debug_cmd
+
+    _G_cmd=$1
+    _G_fail_exp=${2-':'}
+
+    $opt_quiet || {
+      func_quote_for_expand "$_G_cmd"
+      eval "func_echo $func_quote_for_expand_result"
+    }
+
+    $opt_dry_run || {
+      eval "$_G_user_locale
+	    $_G_cmd"
+      _G_status=$?
+      eval "$_G_safe_locale"
+      if test 0 -ne "$_G_status"; then
+	eval "(exit $_G_status); $_G_fail_exp"
+      fi
+    }
+}
+
+
+# func_tr_sh
+# ----------
+# Turn $1 into a string suitable for a shell variable name.
+# Result is stored in $func_tr_sh_result.  All characters
+# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
+# if $1 begins with a digit, a '_' is prepended as well.
+func_tr_sh ()
+{
+    $debug_cmd
+
+    case $1 in
+    [0-9]* | *[!a-zA-Z0-9_]*)
+      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
+      ;;
+    * )
+      func_tr_sh_result=$1
+      ;;
+    esac
+}
+
+
+# func_verbose ARG...
+# -------------------
+# Echo program name prefixed message in verbose mode only.
+func_verbose ()
+{
+    $debug_cmd
+
+    $opt_verbose && func_echo "$*"
+
+    :
+}
+
+
+# func_warn_and_continue ARG...
+# -----------------------------
+# Echo program name prefixed warning message to standard error.
+func_warn_and_continue ()
+{
+    $debug_cmd
+
+    $require_term_colors
+
+    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
+}
+
+
+# func_warning CATEGORY ARG...
+# ----------------------------
+# Echo program name prefixed warning message to standard error. Warning
+# messages can be filtered according to CATEGORY, where this function
+# elides messages where CATEGORY is not listed in the global variable
+# 'opt_warning_types'.
+func_warning ()
+{
+    $debug_cmd
+
+    # CATEGORY must be in the warning_categories list!
+    case " $warning_categories " in
+      *" $1 "*) ;;
+      *) func_internal_error "invalid warning category '$1'" ;;
+    esac
+
+    _G_category=$1
+    shift
+
+    case " $opt_warning_types " in
+      *" $_G_category "*) $warning_func ${1+"$@"} ;;
+    esac
+}
+
+
+# func_sort_ver VER1 VER2
+# -----------------------
+# 'sort -V' is not generally available.
+# Note this deviates from the version comparison in automake
+# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
+# but this should suffice as we won't be specifying old
+# version formats or redundant trailing .0 in bootstrap.conf.
+# If we did want full compatibility then we should probably
+# use m4_version_compare from autoconf.
+func_sort_ver ()
+{
+    $debug_cmd
+
+    printf '%s\n%s\n' "$1" "$2" \
+      | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n -k 6,6n -k 7,7n -k 8,8n -k 9,9n
+}
+
+# func_lt_ver PREV CURR
+# ---------------------
+# Return true if PREV and CURR are in the correct order according to
+# func_sort_ver, otherwise false.  Use it like this:
+#
+#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
+func_lt_ver ()
+{
+    $debug_cmd
+
+    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
+}
+
+
+# Local variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'before-save-hook 'time-stamp)
+# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
+# time-stamp-time-zone: "UTC"
+# End:
+#! /bin/sh
+
+# Set a version string for this script.
+scriptversion=2014-01-07.03; # UTC
+
+# A portable, pluggable option parser for Bourne shell.
+# Written by Gary V. Vaughan, 2010
+
+# Copyright (C) 2010-2015 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Please report bugs or propose patches to gary@gnu.org.
+
+
+## ------ ##
+## Usage. ##
+## ------ ##
+
+# This file is a library for parsing options in your shell scripts along
+# with assorted other useful supporting features that you can make use
+# of too.
+#
+# For the simplest scripts you might need only:
+#
+#   #!/bin/sh
+#   . relative/path/to/funclib.sh
+#   . relative/path/to/options-parser
+#   scriptversion=1.0
+#   func_options ${1+"$@"}
+#   eval set dummy "$func_options_result"; shift
+#   ...rest of your script...
+#
+# In order for the '--version' option to work, you will need to have a
+# suitably formatted comment like the one at the top of this file
+# starting with '# Written by ' and ending with '# warranty; '.
+#
+# For '-h' and '--help' to work, you will also need a one line
+# description of your script's purpose in a comment directly above the
+# '# Written by ' line, like the one at the top of this file.
+#
+# The default options also support '--debug', which will turn on shell
+# execution tracing (see the comment above debug_cmd below for another
+# use), and '--verbose' and the func_verbose function to allow your script
+# to display verbose messages only when your user has specified
+# '--verbose'.
+#
+# After sourcing this file, you can plug processing for additional
+# options by amending the variables from the 'Configuration' section
+# below, and following the instructions in the 'Option parsing'
+# section further down.
+
+## -------------- ##
+## Configuration. ##
+## -------------- ##
+
+# You should override these variables in your script after sourcing this
+# file so that they reflect the customisations you have added to the
+# option parser.
+
+# The usage line for option parsing errors and the start of '-h' and
+# '--help' output messages. You can embed shell variables for delayed
+# expansion at the time the message is displayed, but you will need to
+# quote other shell meta-characters carefully to prevent them being
+# expanded when the contents are evaled.
+usage='$progpath [OPTION]...'
+
+# Short help message in response to '-h' and '--help'.  Add to this or
+# override it after sourcing this library to reflect the full set of
+# options your script accepts.
+usage_message="\
+       --debug        enable verbose shell tracing
+   -W, --warnings=CATEGORY
+                      report the warnings falling in CATEGORY [all]
+   -v, --verbose      verbosely report processing
+       --version      print version information and exit
+   -h, --help         print short or long help message and exit
+"
+
+# Additional text appended to 'usage_message' in response to '--help'.
+long_help_message="
+Warning categories include:
+       'all'          show all warnings
+       'none'         turn off all the warnings
+       'error'        warnings are treated as fatal errors"
+
+# Help message printed before fatal option parsing errors.
+fatal_help="Try '\$progname --help' for more information."
+
+
+
+## ------------------------- ##
+## Hook function management. ##
+## ------------------------- ##
+
+# This section contains functions for adding, removing, and running hooks
+# to the main code.  A hook is just a named list of of function, that can
+# be run in order later on.
+
+# func_hookable FUNC_NAME
+# -----------------------
+# Declare that FUNC_NAME will run hooks added with
+# 'func_add_hook FUNC_NAME ...'.
+func_hookable ()
+{
+    $debug_cmd
+
+    func_append hookable_fns " $1"
+}
+
+
+# func_add_hook FUNC_NAME HOOK_FUNC
+# ---------------------------------
+# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
+# first have been declared "hookable" by a call to 'func_hookable'.
+func_add_hook ()
+{
+    $debug_cmd
+
+    case " $hookable_fns " in
+      *" $1 "*) ;;
+      *) func_fatal_error "'$1' does not accept hook functions." ;;
+    esac
+
+    eval func_append ${1}_hooks '" $2"'
+}
+
+
+# func_remove_hook FUNC_NAME HOOK_FUNC
+# ------------------------------------
+# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
+func_remove_hook ()
+{
+    $debug_cmd
+
+    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
+}
+
+
+# func_run_hooks FUNC_NAME [ARG]...
+# ---------------------------------
+# Run all hook functions registered to FUNC_NAME.
+# It is assumed that the list of hook functions contains nothing more
+# than a whitespace-delimited list of legal shell function names, and
+# no effort is wasted trying to catch shell meta-characters or preserve
+# whitespace.
+func_run_hooks ()
+{
+    $debug_cmd
+
+    case " $hookable_fns " in
+      *" $1 "*) ;;
+      *) func_fatal_error "'$1' does not support hook funcions.n" ;;
+    esac
+
+    eval _G_hook_fns=\$$1_hooks; shift
+
+    for _G_hook in $_G_hook_fns; do
+      eval $_G_hook '"$@"'
+
+      # store returned options list back into positional
+      # parameters for next 'cmd' execution.
+      eval _G_hook_result=\$${_G_hook}_result
+      eval set dummy "$_G_hook_result"; shift
+    done
+
+    func_quote_for_eval ${1+"$@"}
+    func_run_hooks_result=$func_quote_for_eval_result
+}
+
+
+
+## --------------- ##
+## Option parsing. ##
+## --------------- ##
+
+# In order to add your own option parsing hooks, you must accept the
+# full positional parameter list in your hook function, remove any
+# options that you action, and then pass back the remaining unprocessed
+# options in '<hooked_function_name>_result', escaped suitably for
+# 'eval'.  Like this:
+#
+#    my_options_prep ()
+#    {
+#        $debug_cmd
+#
+#        # Extend the existing usage message.
+#        usage_message=$usage_message'
+#      -s, --silent       don'\''t print informational messages
+#    '
+#
+#        func_quote_for_eval ${1+"$@"}
+#        my_options_prep_result=$func_quote_for_eval_result
+#    }
+#    func_add_hook func_options_prep my_options_prep
+#
+#
+#    my_silent_option ()
+#    {
+#        $debug_cmd
+#
+#        # Note that for efficiency, we parse as many options as we can
+#        # recognise in a loop before passing the remainder back to the
+#        # caller on the first unrecognised argument we encounter.
+#        while test $# -gt 0; do
+#          opt=$1; shift
+#          case $opt in
+#            --silent|-s) opt_silent=: ;;
+#            # Separate non-argument short options:
+#            -s*)         func_split_short_opt "$_G_opt"
+#                         set dummy "$func_split_short_opt_name" \
+#                             "-$func_split_short_opt_arg" ${1+"$@"}
+#                         shift
+#                         ;;
+#            *)            set dummy "$_G_opt" "$*"; shift; break ;;
+#          esac
+#        done
+#
+#        func_quote_for_eval ${1+"$@"}
+#        my_silent_option_result=$func_quote_for_eval_result
+#    }
+#    func_add_hook func_parse_options my_silent_option
+#
+#
+#    my_option_validation ()
+#    {
+#        $debug_cmd
+#
+#        $opt_silent && $opt_verbose && func_fatal_help "\
+#    '--silent' and '--verbose' options are mutually exclusive."
+#
+#        func_quote_for_eval ${1+"$@"}
+#        my_option_validation_result=$func_quote_for_eval_result
+#    }
+#    func_add_hook func_validate_options my_option_validation
+#
+# You'll alse need to manually amend $usage_message to reflect the extra
+# options you parse.  It's preferable to append if you can, so that
+# multiple option parsing hooks can be added safely.
+
+
+# func_options [ARG]...
+# ---------------------
+# All the functions called inside func_options are hookable. See the
+# individual implementations for details.
+func_hookable func_options
+func_options ()
+{
+    $debug_cmd
+
+    func_options_prep ${1+"$@"}
+    eval func_parse_options \
+        ${func_options_prep_result+"$func_options_prep_result"}
+    eval func_validate_options \
+        ${func_parse_options_result+"$func_parse_options_result"}
+
+    eval func_run_hooks func_options \
+        ${func_validate_options_result+"$func_validate_options_result"}
+
+    # save modified positional parameters for caller
+    func_options_result=$func_run_hooks_result
+}
+
+
+# func_options_prep [ARG]...
+# --------------------------
+# All initialisations required before starting the option parse loop.
+# Note that when calling hook functions, we pass through the list of
+# positional parameters.  If a hook function modifies that list, and
+# needs to propogate that back to rest of this script, then the complete
+# modified list must be put in 'func_run_hooks_result' before
+# returning.
+func_hookable func_options_prep
+func_options_prep ()
+{
+    $debug_cmd
+
+    # Option defaults:
+    opt_verbose=false
+    opt_warning_types=
+
+    func_run_hooks func_options_prep ${1+"$@"}
+
+    # save modified positional parameters for caller
+    func_options_prep_result=$func_run_hooks_result
+}
+
+
+# func_parse_options [ARG]...
+# ---------------------------
+# The main option parsing loop.
+func_hookable func_parse_options
+func_parse_options ()
+{
+    $debug_cmd
+
+    func_parse_options_result=
+
+    # this just eases exit handling
+    while test $# -gt 0; do
+      # Defer to hook functions for initial option parsing, so they
+      # get priority in the event of reusing an option name.
+      func_run_hooks func_parse_options ${1+"$@"}
+
+      # Adjust func_parse_options positional parameters to match
+      eval set dummy "$func_run_hooks_result"; shift
+
+      # Break out of the loop if we already parsed every option.
+      test $# -gt 0 || break
+
+      _G_opt=$1
+      shift
+      case $_G_opt in
+        --debug|-x)   debug_cmd='set -x'
+                      func_echo "enabling shell trace mode"
+                      $debug_cmd
+                      ;;
+
+        --no-warnings|--no-warning|--no-warn)
+                      set dummy --warnings none ${1+"$@"}
+                      shift
+		      ;;
+
+        --warnings|--warning|-W)
+                      test $# = 0 && func_missing_arg $_G_opt && break
+                      case " $warning_categories $1" in
+                        *" $1 "*)
+                          # trailing space prevents matching last $1 above
+                          func_append_uniq opt_warning_types " $1"
+                          ;;
+                        *all)
+                          opt_warning_types=$warning_categories
+                          ;;
+                        *none)
+                          opt_warning_types=none
+                          warning_func=:
+                          ;;
+                        *error)
+                          opt_warning_types=$warning_categories
+                          warning_func=func_fatal_error
+                          ;;
+                        *)
+                          func_fatal_error \
+                             "unsupported warning category: '$1'"
+                          ;;
+                      esac
+                      shift
+                      ;;
+
+        --verbose|-v) opt_verbose=: ;;
+        --version)    func_version ;;
+        -\?|-h)       func_usage ;;
+        --help)       func_help ;;
+
+	# Separate optargs to long options (plugins may need this):
+	--*=*)        func_split_equals "$_G_opt"
+	              set dummy "$func_split_equals_lhs" \
+                          "$func_split_equals_rhs" ${1+"$@"}
+                      shift
+                      ;;
+
+       # Separate optargs to short options:
+        -W*)
+                      func_split_short_opt "$_G_opt"
+                      set dummy "$func_split_short_opt_name" \
+                          "$func_split_short_opt_arg" ${1+"$@"}
+                      shift
+                      ;;
+
+        # Separate non-argument short options:
+        -\?*|-h*|-v*|-x*)
+                      func_split_short_opt "$_G_opt"
+                      set dummy "$func_split_short_opt_name" \
+                          "-$func_split_short_opt_arg" ${1+"$@"}
+                      shift
+                      ;;
+
+        --)           break ;;
+        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
+        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
+      esac
+    done
+
+    # save modified positional parameters for caller
+    func_quote_for_eval ${1+"$@"}
+    func_parse_options_result=$func_quote_for_eval_result
+}
+
+
+# func_validate_options [ARG]...
+# ------------------------------
+# Perform any sanity checks on option settings and/or unconsumed
+# arguments.
+func_hookable func_validate_options
+func_validate_options ()
+{
+    $debug_cmd
+
+    # Display all warnings if -W was not given.
+    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
+
+    func_run_hooks func_validate_options ${1+"$@"}
+
+    # Bail if the options were screwed!
+    $exit_cmd $EXIT_FAILURE
+
+    # save modified positional parameters for caller
+    func_validate_options_result=$func_run_hooks_result
+}
+
+
+
+## ----------------- ##
+## Helper functions. ##
+## ----------------- ##
+
+# This section contains the helper functions used by the rest of the
+# hookable option parser framework in ascii-betical order.
+
+
+# func_fatal_help ARG...
+# ----------------------
+# Echo program name prefixed message to standard error, followed by
+# a help hint, and exit.
+func_fatal_help ()
+{
+    $debug_cmd
+
+    eval \$ECHO \""Usage: $usage"\"
+    eval \$ECHO \""$fatal_help"\"
+    func_error ${1+"$@"}
+    exit $EXIT_FAILURE
+}
+
+
+# func_help
+# ---------
+# Echo long help message to standard output and exit.
+func_help ()
+{
+    $debug_cmd
+
+    func_usage_message
+    $ECHO "$long_help_message"
+    exit 0
+}
+
+
+# func_missing_arg ARGNAME
+# ------------------------
+# Echo program name prefixed message to standard error and set global
+# exit_cmd.
+func_missing_arg ()
+{
+    $debug_cmd
+
+    func_error "Missing argument for '$1'."
+    exit_cmd=exit
+}
+
+
+# func_split_equals STRING
+# ------------------------
+# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
+# splitting STRING at the '=' sign.
+test -z "$_G_HAVE_XSI_OPS" \
+    && (eval 'x=a/b/c;
+      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
+    && _G_HAVE_XSI_OPS=yes
+
+if test yes = "$_G_HAVE_XSI_OPS"
+then
+  # This is an XSI compatible shell, allowing a faster implementation...
+  eval 'func_split_equals ()
+  {
+      $debug_cmd
+
+      func_split_equals_lhs=${1%%=*}
+      func_split_equals_rhs=${1#*=}
+      test "x$func_split_equals_lhs" = "x$1" \
+        && func_split_equals_rhs=
+  }'
+else
+  # ...otherwise fall back to using expr, which is often a shell builtin.
+  func_split_equals ()
+  {
+      $debug_cmd
+
+      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
+      func_split_equals_rhs=
+      test "x$func_split_equals_lhs" = "x$1" \
+        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
+  }
+fi #func_split_equals
+
+
+# func_split_short_opt SHORTOPT
+# -----------------------------
+# Set func_split_short_opt_name and func_split_short_opt_arg shell
+# variables after splitting SHORTOPT after the 2nd character.
+if test yes = "$_G_HAVE_XSI_OPS"
+then
+  # This is an XSI compatible shell, allowing a faster implementation...
+  eval 'func_split_short_opt ()
+  {
+      $debug_cmd
+
+      func_split_short_opt_arg=${1#??}
+      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
+  }'
+else
+  # ...otherwise fall back to using expr, which is often a shell builtin.
+  func_split_short_opt ()
+  {
+      $debug_cmd
+
+      func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
+      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
+  }
+fi #func_split_short_opt
+
+
+# func_usage
+# ----------
+# Echo short help message to standard output and exit.
+func_usage ()
+{
+    $debug_cmd
+
+    func_usage_message
+    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
+    exit 0
+}
+
+
+# func_usage_message
+# ------------------
+# Echo short help message to standard output.
+func_usage_message ()
+{
+    $debug_cmd
+
+    eval \$ECHO \""Usage: $usage"\"
+    echo
+    $SED -n 's|^# ||
+        /^Written by/{
+          x;p;x
+        }
+	h
+	/^Written by/q' < "$progpath"
+    echo
+    eval \$ECHO \""$usage_message"\"
+}
+
+
+# func_version
+# ------------
+# Echo version message to standard output and exit.
+func_version ()
+{
+    $debug_cmd
+
+    printf '%s\n' "$progname $scriptversion"
+    $SED -n '
+        /(C)/!b go
+        :more
+        /\./!{
+          N
+          s|\n# | |
+          b more
+        }
+        :go
+        /^# Written by /,/# warranty; / {
+          s|^# ||
+          s|^# *$||
+          s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
+          p
+        }
+        /^# Written by / {
+          s|^# ||
+          p
+        }
+        /^warranty; /q' < "$progpath"
+
+    exit $?
+}
+
+
+# Local variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'before-save-hook 'time-stamp)
+# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
+# time-stamp-time-zone: "UTC"
+# End:
+
+# Set a version string.
+scriptversion='(GNU libtool) 2.4.6'
+
+
+# func_echo ARG...
+# ----------------
+# Libtool also displays the current mode in messages, so override
+# funclib.sh func_echo with this custom definition.
+func_echo ()
+{
+    $debug_cmd
+
+    _G_message=$*
+
+    func_echo_IFS=$IFS
+    IFS=$nl
+    for _G_line in $_G_message; do
+      IFS=$func_echo_IFS
+      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
+    done
+    IFS=$func_echo_IFS
+}
+
+
+# func_warning ARG...
+# -------------------
+# Libtool warnings are not categorized, so override funclib.sh
+# func_warning with this simpler definition.
+func_warning ()
+{
+    $debug_cmd
+
+    $warning_func ${1+"$@"}
+}
+
+
+## ---------------- ##
+## Options parsing. ##
+## ---------------- ##
+
+# Hook in the functions to make sure our own options are parsed during
+# the option parsing loop.
+
+usage='$progpath [OPTION]... [MODE-ARG]...'
+
+# Short help message in response to '-h'.
+usage_message="Options:
+       --config             show all configuration variables
+       --debug              enable verbose shell tracing
+   -n, --dry-run            display commands without modifying any files
+       --features           display basic configuration information and exit
+       --mode=MODE          use operation mode MODE
+       --no-warnings        equivalent to '-Wnone'
+       --preserve-dup-deps  don't remove duplicate dependency libraries
+       --quiet, --silent    don't print informational messages
+       --tag=TAG            use configuration variables from tag TAG
+   -v, --verbose            print more informational messages than default
+       --version            print version information
+   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
+   -h, --help, --help-all   print short, long, or detailed help message
+"
+
+# Additional text appended to 'usage_message' in response to '--help'.
+func_help ()
+{
+    $debug_cmd
+
+    func_usage_message
+    $ECHO "$long_help_message
+
+MODE must be one of the following:
+
+       clean           remove files from the build directory
+       compile         compile a source file into a libtool object
+       execute         automatically set library path, then run a program
+       finish          complete the installation of libtool libraries
+       install         install libraries or executables
+       link            create a library or an executable
+       uninstall       remove libraries from an installed directory
+
+MODE-ARGS vary depending on the MODE.  When passed as first option,
+'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
+Try '$progname --help --mode=MODE' for a more detailed description of MODE.
+
+When reporting a bug, please describe a test case to reproduce it and
+include the following information:
+
+       host-triplet:   $host
+       shell:          $SHELL
+       compiler:       $LTCC
+       compiler flags: $LTCFLAGS
+       linker:         $LD (gnu? $with_gnu_ld)
+       version:        $progname (GNU libtool) 2.4.6
+       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
+       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
+
+Report bugs to <bug-libtool@gnu.org>.
+GNU libtool home page: <http://www.gnu.org/software/libtool/>.
+General help using GNU software: <http://www.gnu.org/gethelp/>."
+    exit 0
+}
+
+
+# func_lo2o OBJECT-NAME
+# ---------------------
+# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
+# object suffix.
+
+lo2o=s/\\.lo\$/.$objext/
+o2lo=s/\\.$objext\$/.lo/
+
+if test yes = "$_G_HAVE_XSI_OPS"; then
+  eval 'func_lo2o ()
+  {
+    case $1 in
+      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
+      *   ) func_lo2o_result=$1               ;;
+    esac
+  }'
+
+  # func_xform LIBOBJ-OR-SOURCE
+  # ---------------------------
+  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
+  # suffix to a '.lo' libtool-object suffix.
+  eval 'func_xform ()
+  {
+    func_xform_result=${1%.*}.lo
+  }'
+else
+  # ...otherwise fall back to using sed.
+  func_lo2o ()
+  {
+    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
+  }
+
+  func_xform ()
+  {
+    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
+  }
+fi
+
+
+# func_fatal_configuration ARG...
+# -------------------------------
+# Echo program name prefixed message to standard error, followed by
+# a configuration failure hint, and exit.
+func_fatal_configuration ()
+{
+    func__fatal_error ${1+"$@"} \
+      "See the $PACKAGE documentation for more information." \
+      "Fatal configuration error."
+}
+
+
+# func_config
+# -----------
+# Display the configuration for all the tags in this script.
+func_config ()
+{
+    re_begincf='^# ### BEGIN LIBTOOL'
+    re_endcf='^# ### END LIBTOOL'
+
+    # Default configuration.
+    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
+
+    # Now print the configurations for the tags.
+    for tagname in $taglist; do
+      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
+    done
+
+    exit $?
+}
+
+
+# func_features
+# -------------
+# Display the features supported by this script.
+func_features ()
+{
+    echo "host: $host"
+    if test yes = "$build_libtool_libs"; then
+      echo "enable shared libraries"
+    else
+      echo "disable shared libraries"
+    fi
+    if test yes = "$build_old_libs"; then
+      echo "enable static libraries"
+    else
+      echo "disable static libraries"
+    fi
+
+    exit $?
+}
+
+
+# func_enable_tag TAGNAME
+# -----------------------
+# Verify that TAGNAME is valid, and either flag an error and exit, or
+# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
+# variable here.
+func_enable_tag ()
+{
+    # Global variable:
+    tagname=$1
+
+    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
+    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
+    sed_extractcf=/$re_begincf/,/$re_endcf/p
+
+    # Validate tagname.
+    case $tagname in
+      *[!-_A-Za-z0-9,/]*)
+        func_fatal_error "invalid tag name: $tagname"
+        ;;
+    esac
+
+    # Don't test for the "default" C tag, as we know it's
+    # there but not specially marked.
+    case $tagname in
+        CC) ;;
+    *)
+        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
+	  taglist="$taglist $tagname"
+
+	  # Evaluate the configuration.  Be careful to quote the path
+	  # and the sed script, to avoid splitting on whitespace, but
+	  # also don't use non-portable quotes within backquotes within
+	  # quotes we have to do it in 2 steps:
+	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
+	  eval "$extractedcf"
+        else
+	  func_error "ignoring unknown tag $tagname"
+        fi
+        ;;
+    esac
+}
+
+
+# func_check_version_match
+# ------------------------
+# Ensure that we are using m4 macros, and libtool script from the same
+# release of libtool.
+func_check_version_match ()
+{
+    if test "$package_revision" != "$macro_revision"; then
+      if test "$VERSION" != "$macro_version"; then
+        if test -z "$macro_version"; then
+          cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from an older release.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+        else
+          cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+        fi
+      else
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
+$progname: but the definition of this LT_INIT comes from revision $macro_revision.
+$progname: You should recreate aclocal.m4 with macros from revision $package_revision
+$progname: of $PACKAGE $VERSION and run autoconf again.
+_LT_EOF
+      fi
+
+      exit $EXIT_MISMATCH
+    fi
+}
+
+
+# libtool_options_prep [ARG]...
+# -----------------------------
+# Preparation for options parsed by libtool.
+libtool_options_prep ()
+{
+    $debug_mode
+
+    # Option defaults:
+    opt_config=false
+    opt_dlopen=
+    opt_dry_run=false
+    opt_help=false
+    opt_mode=
+    opt_preserve_dup_deps=false
+    opt_quiet=false
+
+    nonopt=
+    preserve_args=
+
+    # Shorthand for --mode=foo, only valid as the first argument
+    case $1 in
+    clean|clea|cle|cl)
+      shift; set dummy --mode clean ${1+"$@"}; shift
+      ;;
+    compile|compil|compi|comp|com|co|c)
+      shift; set dummy --mode compile ${1+"$@"}; shift
+      ;;
+    execute|execut|execu|exec|exe|ex|e)
+      shift; set dummy --mode execute ${1+"$@"}; shift
+      ;;
+    finish|finis|fini|fin|fi|f)
+      shift; set dummy --mode finish ${1+"$@"}; shift
+      ;;
+    install|instal|insta|inst|ins|in|i)
+      shift; set dummy --mode install ${1+"$@"}; shift
+      ;;
+    link|lin|li|l)
+      shift; set dummy --mode link ${1+"$@"}; shift
+      ;;
+    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
+      shift; set dummy --mode uninstall ${1+"$@"}; shift
+      ;;
+    esac
+
+    # Pass back the list of options.
+    func_quote_for_eval ${1+"$@"}
+    libtool_options_prep_result=$func_quote_for_eval_result
+}
+func_add_hook func_options_prep libtool_options_prep
+
+
+# libtool_parse_options [ARG]...
+# ---------------------------------
+# Provide handling for libtool specific options.
+libtool_parse_options ()
+{
+    $debug_cmd
+
+    # Perform our own loop to consume as many options as possible in
+    # each iteration.
+    while test $# -gt 0; do
+      _G_opt=$1
+      shift
+      case $_G_opt in
+        --dry-run|--dryrun|-n)
+                        opt_dry_run=:
+                        ;;
+
+        --config)       func_config ;;
+
+        --dlopen|-dlopen)
+                        opt_dlopen="${opt_dlopen+$opt_dlopen
+}$1"
+                        shift
+                        ;;
+
+        --preserve-dup-deps)
+                        opt_preserve_dup_deps=: ;;
+
+        --features)     func_features ;;
+
+        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
+
+        --help)         opt_help=: ;;
+
+        --help-all)     opt_help=': help-all' ;;
+
+        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
+                        opt_mode=$1
+                        case $1 in
+                          # Valid mode arguments:
+                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
+
+                          # Catch anything else as an error
+                          *) func_error "invalid argument for $_G_opt"
+                             exit_cmd=exit
+                             break
+                             ;;
+                        esac
+                        shift
+                        ;;
+
+        --no-silent|--no-quiet)
+                        opt_quiet=false
+                        func_append preserve_args " $_G_opt"
+                        ;;
+
+        --no-warnings|--no-warning|--no-warn)
+                        opt_warning=false
+                        func_append preserve_args " $_G_opt"
+                        ;;
+
+        --no-verbose)
+                        opt_verbose=false
+                        func_append preserve_args " $_G_opt"
+                        ;;
+
+        --silent|--quiet)
+                        opt_quiet=:
+                        opt_verbose=false
+                        func_append preserve_args " $_G_opt"
+                        ;;
+
+        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
+                        opt_tag=$1
+                        func_append preserve_args " $_G_opt $1"
+                        func_enable_tag "$1"
+                        shift
+                        ;;
+
+        --verbose|-v)   opt_quiet=false
+                        opt_verbose=:
+                        func_append preserve_args " $_G_opt"
+                        ;;
+
+	# An option not handled by this hook function:
+        *)		set dummy "$_G_opt" ${1+"$@"};	shift; break  ;;
+      esac
+    done
+
+
+    # save modified positional parameters for caller
+    func_quote_for_eval ${1+"$@"}
+    libtool_parse_options_result=$func_quote_for_eval_result
+}
+func_add_hook func_parse_options libtool_parse_options
+
+
+
+# libtool_validate_options [ARG]...
+# ---------------------------------
+# Perform any sanity checks on option settings and/or unconsumed
+# arguments.
+libtool_validate_options ()
+{
+    # save first non-option argument
+    if test 0 -lt $#; then
+      nonopt=$1
+      shift
+    fi
+
+    # preserve --debug
+    test : = "$debug_cmd" || func_append preserve_args " --debug"
+
+    case $host in
+      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
+      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
+      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
+        # don't eliminate duplications in $postdeps and $predeps
+        opt_duplicate_compiler_generated_deps=:
+        ;;
+      *)
+        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
+        ;;
+    esac
+
+    $opt_help || {
+      # Sanity checks first:
+      func_check_version_match
+
+      test yes != "$build_libtool_libs" \
+        && test yes != "$build_old_libs" \
+        && func_fatal_configuration "not configured to build any kind of library"
+
+      # Darwin sucks
+      eval std_shrext=\"$shrext_cmds\"
+
+      # Only execute mode is allowed to have -dlopen flags.
+      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
+        func_error "unrecognized option '-dlopen'"
+        $ECHO "$help" 1>&2
+        exit $EXIT_FAILURE
+      fi
+
+      # Change the help message to a mode-specific one.
+      generic_help=$help
+      help="Try '$progname --help --mode=$opt_mode' for more information."
+    }
+
+    # Pass back the unparsed argument list
+    func_quote_for_eval ${1+"$@"}
+    libtool_validate_options_result=$func_quote_for_eval_result
+}
+func_add_hook func_validate_options libtool_validate_options
+
+
+# Process options as early as possible so that --help and --version
+# can return quickly.
+func_options ${1+"$@"}
+eval set dummy "$func_options_result"; shift
+
+
+
+## ----------- ##
+##    Main.    ##
+## ----------- ##
+
+magic='%%%MAGIC variable%%%'
+magic_exe='%%%MAGIC EXE variable%%%'
+
+# Global variables.
+extracted_archives=
+extracted_serial=0
+
+# If this variable is set in any of the actions, the command in it
+# will be execed at the end.  This prevents here-documents from being
+# left over by shells.
+exec_cmd=
+
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+  eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+}
+
+# func_generated_by_libtool
+# True iff stdin has been generated by Libtool. This function is only
+# a basic sanity check; it will hardly flush out determined imposters.
+func_generated_by_libtool_p ()
+{
+  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
+}
+
+# func_lalib_p file
+# True iff FILE is a libtool '.la' library or '.lo' object file.
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_lalib_p ()
+{
+    test -f "$1" &&
+      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
+}
+
+# func_lalib_unsafe_p file
+# True iff FILE is a libtool '.la' library or '.lo' object file.
+# This function implements the same check as func_lalib_p without
+# resorting to external programs.  To this end, it redirects stdin and
+# closes it afterwards, without saving the original file descriptor.
+# As a safety measure, use it only where a negative result would be
+# fatal anyway.  Works if 'file' does not exist.
+func_lalib_unsafe_p ()
+{
+    lalib_p=no
+    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
+	for lalib_p_l in 1 2 3 4
+	do
+	    read lalib_p_line
+	    case $lalib_p_line in
+		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
+	    esac
+	done
+	exec 0<&5 5<&-
+    fi
+    test yes = "$lalib_p"
+}
+
+# func_ltwrapper_script_p file
+# True iff FILE is a libtool wrapper script
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_script_p ()
+{
+    test -f "$1" &&
+      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
+}
+
+# func_ltwrapper_executable_p file
+# True iff FILE is a libtool wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_executable_p ()
+{
+    func_ltwrapper_exec_suffix=
+    case $1 in
+    *.exe) ;;
+    *) func_ltwrapper_exec_suffix=.exe ;;
+    esac
+    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
+}
+
+# func_ltwrapper_scriptname file
+# Assumes file is an ltwrapper_executable
+# uses $file to determine the appropriate filename for a
+# temporary ltwrapper_script.
+func_ltwrapper_scriptname ()
+{
+    func_dirname_and_basename "$1" "" "."
+    func_stripname '' '.exe' "$func_basename_result"
+    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
+}
+
+# func_ltwrapper_p file
+# True iff FILE is a libtool wrapper script or wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_p ()
+{
+    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
+}
+
+
+# func_execute_cmds commands fail_cmd
+# Execute tilde-delimited COMMANDS.
+# If FAIL_CMD is given, eval that upon failure.
+# FAIL_CMD may read-access the current command in variable CMD!
+func_execute_cmds ()
+{
+    $debug_cmd
+
+    save_ifs=$IFS; IFS='~'
+    for cmd in $1; do
+      IFS=$sp$nl
+      eval cmd=\"$cmd\"
+      IFS=$save_ifs
+      func_show_eval "$cmd" "${2-:}"
+    done
+    IFS=$save_ifs
+}
+
+
+# func_source file
+# Source FILE, adding directory component if necessary.
+# Note that it is not necessary on cygwin/mingw to append a dot to
+# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
+# behavior happens only for exec(3), not for open(2)!  Also, sourcing
+# 'FILE.' does not work on cygwin managed mounts.
+func_source ()
+{
+    $debug_cmd
+
+    case $1 in
+    */* | *\\*)	. "$1" ;;
+    *)		. "./$1" ;;
+    esac
+}
+
+
+# func_resolve_sysroot PATH
+# Replace a leading = in PATH with a sysroot.  Store the result into
+# func_resolve_sysroot_result
+func_resolve_sysroot ()
+{
+  func_resolve_sysroot_result=$1
+  case $func_resolve_sysroot_result in
+  =*)
+    func_stripname '=' '' "$func_resolve_sysroot_result"
+    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
+    ;;
+  esac
+}
+
+# func_replace_sysroot PATH
+# If PATH begins with the sysroot, replace it with = and
+# store the result into func_replace_sysroot_result.
+func_replace_sysroot ()
+{
+  case $lt_sysroot:$1 in
+  ?*:"$lt_sysroot"*)
+    func_stripname "$lt_sysroot" '' "$1"
+    func_replace_sysroot_result='='$func_stripname_result
+    ;;
+  *)
+    # Including no sysroot.
+    func_replace_sysroot_result=$1
+    ;;
+  esac
+}
+
+# func_infer_tag arg
+# Infer tagged configuration to use if any are available and
+# if one wasn't chosen via the "--tag" command line option.
+# Only attempt this if the compiler in the base compile
+# command doesn't match the default compiler.
+# arg is usually of the form 'gcc ...'
+func_infer_tag ()
+{
+    $debug_cmd
+
+    if test -n "$available_tags" && test -z "$tagname"; then
+      CC_quoted=
+      for arg in $CC; do
+	func_append_quoted CC_quoted "$arg"
+      done
+      CC_expanded=`func_echo_all $CC`
+      CC_quoted_expanded=`func_echo_all $CC_quoted`
+      case $@ in
+      # Blanks in the command may have been stripped by the calling shell,
+      # but not from the CC environment variable when configure was run.
+      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
+      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
+      # Blanks at the start of $base_compile will cause this to fail
+      # if we don't check for them as well.
+      *)
+	for z in $available_tags; do
+	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
+	    # Evaluate the configuration.
+	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
+	    CC_quoted=
+	    for arg in $CC; do
+	      # Double-quote args containing other shell metacharacters.
+	      func_append_quoted CC_quoted "$arg"
+	    done
+	    CC_expanded=`func_echo_all $CC`
+	    CC_quoted_expanded=`func_echo_all $CC_quoted`
+	    case "$@ " in
+	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
+	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
+	      # The compiler in the base compile command matches
+	      # the one in the tagged configuration.
+	      # Assume this is the tagged configuration we want.
+	      tagname=$z
+	      break
+	      ;;
+	    esac
+	  fi
+	done
+	# If $tagname still isn't set, then no tagged configuration
+	# was found and let the user know that the "--tag" command
+	# line option must be used.
+	if test -z "$tagname"; then
+	  func_echo "unable to infer tagged configuration"
+	  func_fatal_error "specify a tag with '--tag'"
+#	else
+#	  func_verbose "using $tagname tagged configuration"
+	fi
+	;;
+      esac
+    fi
+}
+
+
+
+# func_write_libtool_object output_name pic_name nonpic_name
+# Create a libtool object file (analogous to a ".la" file),
+# but don't create it if we're doing a dry run.
+func_write_libtool_object ()
+{
+    write_libobj=$1
+    if test yes = "$build_libtool_libs"; then
+      write_lobj=\'$2\'
+    else
+      write_lobj=none
+    fi
+
+    if test yes = "$build_old_libs"; then
+      write_oldobj=\'$3\'
+    else
+      write_oldobj=none
+    fi
+
+    $opt_dry_run || {
+      cat >${write_libobj}T <<EOF
+# $write_libobj - a libtool object file
+# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
+pic_object=$write_lobj
+
+# Name of the non-PIC object
+non_pic_object=$write_oldobj
+
+EOF
+      $MV "${write_libobj}T" "$write_libobj"
+    }
+}
+
+
+##################################################
+# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
+##################################################
+
+# func_convert_core_file_wine_to_w32 ARG
+# Helper function used by file name conversion functions when $build is *nix,
+# and $host is mingw, cygwin, or some other w32 environment. Relies on a
+# correctly configured wine environment available, with the winepath program
+# in $build's $PATH.
+#
+# ARG is the $build file name to be converted to w32 format.
+# Result is available in $func_convert_core_file_wine_to_w32_result, and will
+# be empty on error (or when ARG is empty)
+func_convert_core_file_wine_to_w32 ()
+{
+  $debug_cmd
+
+  func_convert_core_file_wine_to_w32_result=$1
+  if test -n "$1"; then
+    # Unfortunately, winepath does not exit with a non-zero error code, so we
+    # are forced to check the contents of stdout. On the other hand, if the
+    # command is not found, the shell will set an exit code of 127 and print
+    # *an error message* to stdout. So we must check for both error code of
+    # zero AND non-empty stdout, which explains the odd construction:
+    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
+    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
+      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
+        $SED -e "$sed_naive_backslashify"`
+    else
+      func_convert_core_file_wine_to_w32_result=
+    fi
+  fi
+}
+# end: func_convert_core_file_wine_to_w32
+
+
+# func_convert_core_path_wine_to_w32 ARG
+# Helper function used by path conversion functions when $build is *nix, and
+# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
+# configured wine environment available, with the winepath program in $build's
+# $PATH. Assumes ARG has no leading or trailing path separator characters.
+#
+# ARG is path to be converted from $build format to win32.
+# Result is available in $func_convert_core_path_wine_to_w32_result.
+# Unconvertible file (directory) names in ARG are skipped; if no directory names
+# are convertible, then the result may be empty.
+func_convert_core_path_wine_to_w32 ()
+{
+  $debug_cmd
+
+  # unfortunately, winepath doesn't convert paths, only file names
+  func_convert_core_path_wine_to_w32_result=
+  if test -n "$1"; then
+    oldIFS=$IFS
+    IFS=:
+    for func_convert_core_path_wine_to_w32_f in $1; do
+      IFS=$oldIFS
+      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
+      if test -n "$func_convert_core_file_wine_to_w32_result"; then
+        if test -z "$func_convert_core_path_wine_to_w32_result"; then
+          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
+        else
+          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
+        fi
+      fi
+    done
+    IFS=$oldIFS
+  fi
+}
+# end: func_convert_core_path_wine_to_w32
+
+
+# func_cygpath ARGS...
+# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
+# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
+# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
+# (2), returns the Cygwin file name or path in func_cygpath_result (input
+# file name or path is assumed to be in w32 format, as previously converted
+# from $build's *nix or MSYS format). In case (3), returns the w32 file name
+# or path in func_cygpath_result (input file name or path is assumed to be in
+# Cygwin format). Returns an empty string on error.
+#
+# ARGS are passed to cygpath, with the last one being the file name or path to
+# be converted.
+#
+# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
+# environment variable; do not put it in $PATH.
+func_cygpath ()
+{
+  $debug_cmd
+
+  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
+    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
+    if test "$?" -ne 0; then
+      # on failure, ensure result is empty
+      func_cygpath_result=
+    fi
+  else
+    func_cygpath_result=
+    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
+  fi
+}
+#end: func_cygpath
+
+
+# func_convert_core_msys_to_w32 ARG
+# Convert file name or path ARG from MSYS format to w32 format.  Return
+# result in func_convert_core_msys_to_w32_result.
+func_convert_core_msys_to_w32 ()
+{
+  $debug_cmd
+
+  # awkward: cmd appends spaces to result
+  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
+    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
+}
+#end: func_convert_core_msys_to_w32
+
+
+# func_convert_file_check ARG1 ARG2
+# Verify that ARG1 (a file name in $build format) was converted to $host
+# format in ARG2. Otherwise, emit an error message, but continue (resetting
+# func_to_host_file_result to ARG1).
+func_convert_file_check ()
+{
+  $debug_cmd
+
+  if test -z "$2" && test -n "$1"; then
+    func_error "Could not determine host file name corresponding to"
+    func_error "  '$1'"
+    func_error "Continuing, but uninstalled executables may not work."
+    # Fallback:
+    func_to_host_file_result=$1
+  fi
+}
+# end func_convert_file_check
+
+
+# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
+# Verify that FROM_PATH (a path in $build format) was converted to $host
+# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
+# func_to_host_file_result to a simplistic fallback value (see below).
+func_convert_path_check ()
+{
+  $debug_cmd
+
+  if test -z "$4" && test -n "$3"; then
+    func_error "Could not determine the host path corresponding to"
+    func_error "  '$3'"
+    func_error "Continuing, but uninstalled executables may not work."
+    # Fallback.  This is a deliberately simplistic "conversion" and
+    # should not be "improved".  See libtool.info.
+    if test "x$1" != "x$2"; then
+      lt_replace_pathsep_chars="s|$1|$2|g"
+      func_to_host_path_result=`echo "$3" |
+        $SED -e "$lt_replace_pathsep_chars"`
+    else
+      func_to_host_path_result=$3
+    fi
+  fi
+}
+# end func_convert_path_check
+
+
+# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
+# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
+# and appending REPL if ORIG matches BACKPAT.
+func_convert_path_front_back_pathsep ()
+{
+  $debug_cmd
+
+  case $4 in
+  $1 ) func_to_host_path_result=$3$func_to_host_path_result
+    ;;
+  esac
+  case $4 in
+  $2 ) func_append func_to_host_path_result "$3"
+    ;;
+  esac
+}
+# end func_convert_path_front_back_pathsep
+
+
+##################################################
+# $build to $host FILE NAME CONVERSION FUNCTIONS #
+##################################################
+# invoked via '$to_host_file_cmd ARG'
+#
+# In each case, ARG is the path to be converted from $build to $host format.
+# Result will be available in $func_to_host_file_result.
+
+
+# func_to_host_file ARG
+# Converts the file name ARG from $build format to $host format. Return result
+# in func_to_host_file_result.
+func_to_host_file ()
+{
+  $debug_cmd
+
+  $to_host_file_cmd "$1"
+}
+# end func_to_host_file
+
+
+# func_to_tool_file ARG LAZY
+# converts the file name ARG from $build format to toolchain format. Return
+# result in func_to_tool_file_result.  If the conversion in use is listed
+# in (the comma separated) LAZY, no conversion takes place.
+func_to_tool_file ()
+{
+  $debug_cmd
+
+  case ,$2, in
+    *,"$to_tool_file_cmd",*)
+      func_to_tool_file_result=$1
+      ;;
+    *)
+      $to_tool_file_cmd "$1"
+      func_to_tool_file_result=$func_to_host_file_result
+      ;;
+  esac
+}
+# end func_to_tool_file
+
+
+# func_convert_file_noop ARG
+# Copy ARG to func_to_host_file_result.
+func_convert_file_noop ()
+{
+  func_to_host_file_result=$1
+}
+# end func_convert_file_noop
+
+
+# func_convert_file_msys_to_w32 ARG
+# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
+# conversion to w32 is not available inside the cwrapper.  Returns result in
+# func_to_host_file_result.
+func_convert_file_msys_to_w32 ()
+{
+  $debug_cmd
+
+  func_to_host_file_result=$1
+  if test -n "$1"; then
+    func_convert_core_msys_to_w32 "$1"
+    func_to_host_file_result=$func_convert_core_msys_to_w32_result
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_msys_to_w32
+
+
+# func_convert_file_cygwin_to_w32 ARG
+# Convert file name ARG from Cygwin to w32 format.  Returns result in
+# func_to_host_file_result.
+func_convert_file_cygwin_to_w32 ()
+{
+  $debug_cmd
+
+  func_to_host_file_result=$1
+  if test -n "$1"; then
+    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
+    # LT_CYGPATH in this case.
+    func_to_host_file_result=`cygpath -m "$1"`
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_cygwin_to_w32
+
+
+# func_convert_file_nix_to_w32 ARG
+# Convert file name ARG from *nix to w32 format.  Requires a wine environment
+# and a working winepath. Returns result in func_to_host_file_result.
+func_convert_file_nix_to_w32 ()
+{
+  $debug_cmd
+
+  func_to_host_file_result=$1
+  if test -n "$1"; then
+    func_convert_core_file_wine_to_w32 "$1"
+    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_nix_to_w32
+
+
+# func_convert_file_msys_to_cygwin ARG
+# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
+# Returns result in func_to_host_file_result.
+func_convert_file_msys_to_cygwin ()
+{
+  $debug_cmd
+
+  func_to_host_file_result=$1
+  if test -n "$1"; then
+    func_convert_core_msys_to_w32 "$1"
+    func_cygpath -u "$func_convert_core_msys_to_w32_result"
+    func_to_host_file_result=$func_cygpath_result
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_msys_to_cygwin
+
+
+# func_convert_file_nix_to_cygwin ARG
+# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
+# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
+# in func_to_host_file_result.
+func_convert_file_nix_to_cygwin ()
+{
+  $debug_cmd
+
+  func_to_host_file_result=$1
+  if test -n "$1"; then
+    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
+    func_convert_core_file_wine_to_w32 "$1"
+    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
+    func_to_host_file_result=$func_cygpath_result
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_nix_to_cygwin
+
+
+#############################################
+# $build to $host PATH CONVERSION FUNCTIONS #
+#############################################
+# invoked via '$to_host_path_cmd ARG'
+#
+# In each case, ARG is the path to be converted from $build to $host format.
+# The result will be available in $func_to_host_path_result.
+#
+# Path separators are also converted from $build format to $host format.  If
+# ARG begins or ends with a path separator character, it is preserved (but
+# converted to $host format) on output.
+#
+# All path conversion functions are named using the following convention:
+#   file name conversion function    : func_convert_file_X_to_Y ()
+#   path conversion function         : func_convert_path_X_to_Y ()
+# where, for any given $build/$host combination the 'X_to_Y' value is the
+# same.  If conversion functions are added for new $build/$host combinations,
+# the two new functions must follow this pattern, or func_init_to_host_path_cmd
+# will break.
+
+
+# func_init_to_host_path_cmd
+# Ensures that function "pointer" variable $to_host_path_cmd is set to the
+# appropriate value, based on the value of $to_host_file_cmd.
+to_host_path_cmd=
+func_init_to_host_path_cmd ()
+{
+  $debug_cmd
+
+  if test -z "$to_host_path_cmd"; then
+    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
+    to_host_path_cmd=func_convert_path_$func_stripname_result
+  fi
+}
+
+
+# func_to_host_path ARG
+# Converts the path ARG from $build format to $host format. Return result
+# in func_to_host_path_result.
+func_to_host_path ()
+{
+  $debug_cmd
+
+  func_init_to_host_path_cmd
+  $to_host_path_cmd "$1"
+}
+# end func_to_host_path
+
+
+# func_convert_path_noop ARG
+# Copy ARG to func_to_host_path_result.
+func_convert_path_noop ()
+{
+  func_to_host_path_result=$1
+}
+# end func_convert_path_noop
+
+
+# func_convert_path_msys_to_w32 ARG
+# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
+# conversion to w32 is not available inside the cwrapper.  Returns result in
+# func_to_host_path_result.
+func_convert_path_msys_to_w32 ()
+{
+  $debug_cmd
+
+  func_to_host_path_result=$1
+  if test -n "$1"; then
+    # Remove leading and trailing path separator characters from ARG.  MSYS
+    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
+    # and winepath ignores them completely.
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
+    func_to_host_path_result=$func_convert_core_msys_to_w32_result
+    func_convert_path_check : ";" \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
+  fi
+}
+# end func_convert_path_msys_to_w32
+
+
+# func_convert_path_cygwin_to_w32 ARG
+# Convert path ARG from Cygwin to w32 format.  Returns result in
+# func_to_host_file_result.
+func_convert_path_cygwin_to_w32 ()
+{
+  $debug_cmd
+
+  func_to_host_path_result=$1
+  if test -n "$1"; then
+    # See func_convert_path_msys_to_w32:
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
+    func_convert_path_check : ";" \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
+  fi
+}
+# end func_convert_path_cygwin_to_w32
+
+
+# func_convert_path_nix_to_w32 ARG
+# Convert path ARG from *nix to w32 format.  Requires a wine environment and
+# a working winepath.  Returns result in func_to_host_file_result.
+func_convert_path_nix_to_w32 ()
+{
+  $debug_cmd
+
+  func_to_host_path_result=$1
+  if test -n "$1"; then
+    # See func_convert_path_msys_to_w32:
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
+    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
+    func_convert_path_check : ";" \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
+  fi
+}
+# end func_convert_path_nix_to_w32
+
+
+# func_convert_path_msys_to_cygwin ARG
+# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
+# Returns result in func_to_host_file_result.
+func_convert_path_msys_to_cygwin ()
+{
+  $debug_cmd
+
+  func_to_host_path_result=$1
+  if test -n "$1"; then
+    # See func_convert_path_msys_to_w32:
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
+    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
+    func_to_host_path_result=$func_cygpath_result
+    func_convert_path_check : : \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
+  fi
+}
+# end func_convert_path_msys_to_cygwin
+
+
+# func_convert_path_nix_to_cygwin ARG
+# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
+# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
+# func_to_host_file_result.
+func_convert_path_nix_to_cygwin ()
+{
+  $debug_cmd
+
+  func_to_host_path_result=$1
+  if test -n "$1"; then
+    # Remove leading and trailing path separator characters from
+    # ARG. msys behavior is inconsistent here, cygpath turns them
+    # into '.;' and ';.', and winepath ignores them completely.
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
+    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
+    func_to_host_path_result=$func_cygpath_result
+    func_convert_path_check : : \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
+  fi
+}
+# end func_convert_path_nix_to_cygwin
+
+
+# func_dll_def_p FILE
+# True iff FILE is a Windows DLL '.def' file.
+# Keep in sync with _LT_DLL_DEF_P in libtool.m4
+func_dll_def_p ()
+{
+  $debug_cmd
+
+  func_dll_def_p_tmp=`$SED -n \
+    -e 's/^[	 ]*//' \
+    -e '/^\(;.*\)*$/d' \
+    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
+    -e q \
+    "$1"`
+  test DEF = "$func_dll_def_p_tmp"
+}
+
+
+# func_mode_compile arg...
+func_mode_compile ()
+{
+    $debug_cmd
+
+    # Get the compilation command and the source file.
+    base_compile=
+    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
+    suppress_opt=yes
+    suppress_output=
+    arg_mode=normal
+    libobj=
+    later=
+    pie_flag=
+
+    for arg
+    do
+      case $arg_mode in
+      arg  )
+	# do not "continue".  Instead, add this to base_compile
+	lastarg=$arg
+	arg_mode=normal
+	;;
+
+      target )
+	libobj=$arg
+	arg_mode=normal
+	continue
+	;;
+
+      normal )
+	# Accept any command-line options.
+	case $arg in
+	-o)
+	  test -n "$libobj" && \
+	    func_fatal_error "you cannot specify '-o' more than once"
+	  arg_mode=target
+	  continue
+	  ;;
+
+	-pie | -fpie | -fPIE)
+          func_append pie_flag " $arg"
+	  continue
+	  ;;
+
+	-shared | -static | -prefer-pic | -prefer-non-pic)
+	  func_append later " $arg"
+	  continue
+	  ;;
+
+	-no-suppress)
+	  suppress_opt=no
+	  continue
+	  ;;
+
+	-Xcompiler)
+	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
+	  continue      #  The current "srcfile" will either be retained or
+	  ;;            #  replaced later.  I would guess that would be a bug.
+
+	-Wc,*)
+	  func_stripname '-Wc,' '' "$arg"
+	  args=$func_stripname_result
+	  lastarg=
+	  save_ifs=$IFS; IFS=,
+	  for arg in $args; do
+	    IFS=$save_ifs
+	    func_append_quoted lastarg "$arg"
+	  done
+	  IFS=$save_ifs
+	  func_stripname ' ' '' "$lastarg"
+	  lastarg=$func_stripname_result
+
+	  # Add the arguments to base_compile.
+	  func_append base_compile " $lastarg"
+	  continue
+	  ;;
+
+	*)
+	  # Accept the current argument as the source file.
+	  # The previous "srcfile" becomes the current argument.
+	  #
+	  lastarg=$srcfile
+	  srcfile=$arg
+	  ;;
+	esac  #  case $arg
+	;;
+      esac    #  case $arg_mode
+
+      # Aesthetically quote the previous argument.
+      func_append_quoted base_compile "$lastarg"
+    done # for arg
+
+    case $arg_mode in
+    arg)
+      func_fatal_error "you must specify an argument for -Xcompile"
+      ;;
+    target)
+      func_fatal_error "you must specify a target with '-o'"
+      ;;
+    *)
+      # Get the name of the library object.
+      test -z "$libobj" && {
+	func_basename "$srcfile"
+	libobj=$func_basename_result
+      }
+      ;;
+    esac
+
+    # Recognize several different file suffixes.
+    # If the user specifies -o file.o, it is replaced with file.lo
+    case $libobj in
+    *.[cCFSifmso] | \
+    *.ada | *.adb | *.ads | *.asm | \
+    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
+    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
+      func_xform "$libobj"
+      libobj=$func_xform_result
+      ;;
+    esac
+
+    case $libobj in
+    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
+    *)
+      func_fatal_error "cannot determine name of library object from '$libobj'"
+      ;;
+    esac
+
+    func_infer_tag $base_compile
+
+    for arg in $later; do
+      case $arg in
+      -shared)
+	test yes = "$build_libtool_libs" \
+	  || func_fatal_configuration "cannot build a shared library"
+	build_old_libs=no
+	continue
+	;;
+
+      -static)
+	build_libtool_libs=no
+	build_old_libs=yes
+	continue
+	;;
+
+      -prefer-pic)
+	pic_mode=yes
+	continue
+	;;
+
+      -prefer-non-pic)
+	pic_mode=no
+	continue
+	;;
+      esac
+    done
+
+    func_quote_for_eval "$libobj"
+    test "X$libobj" != "X$func_quote_for_eval_result" \
+      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
+      && func_warning "libobj name '$libobj' may not contain shell special characters."
+    func_dirname_and_basename "$obj" "/" ""
+    objname=$func_basename_result
+    xdir=$func_dirname_result
+    lobj=$xdir$objdir/$objname
+
+    test -z "$base_compile" && \
+      func_fatal_help "you must specify a compilation command"
+
+    # Delete any leftover library objects.
+    if test yes = "$build_old_libs"; then
+      removelist="$obj $lobj $libobj ${libobj}T"
+    else
+      removelist="$lobj $libobj ${libobj}T"
+    fi
+
+    # On Cygwin there's no "real" PIC flag so we must build both object types
+    case $host_os in
+    cygwin* | mingw* | pw32* | os2* | cegcc*)
+      pic_mode=default
+      ;;
+    esac
+    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
+      # non-PIC code in shared libraries is not supported
+      pic_mode=default
+    fi
+
+    # Calculate the filename of the output object if compiler does
+    # not support -o with -c
+    if test no = "$compiler_c_o"; then
+      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
+      lockfile=$output_obj.lock
+    else
+      output_obj=
+      need_locks=no
+      lockfile=
+    fi
+
+    # Lock this critical section if it is needed
+    # We use this script file to make the link, it avoids creating a new file
+    if test yes = "$need_locks"; then
+      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
+	func_echo "Waiting for $lockfile to be removed"
+	sleep 2
+      done
+    elif test warn = "$need_locks"; then
+      if test -f "$lockfile"; then
+	$ECHO "\
+*** ERROR, $lockfile exists and contains:
+`cat $lockfile 2>/dev/null`
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support '-c' and '-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+      func_append removelist " $output_obj"
+      $ECHO "$srcfile" > "$lockfile"
+    fi
+
+    $opt_dry_run || $RM $removelist
+    func_append removelist " $lockfile"
+    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
+
+    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
+    srcfile=$func_to_tool_file_result
+    func_quote_for_eval "$srcfile"
+    qsrcfile=$func_quote_for_eval_result
+
+    # Only build a PIC object if we are building libtool libraries.
+    if test yes = "$build_libtool_libs"; then
+      # Without this assignment, base_compile gets emptied.
+      fbsd_hideous_sh_bug=$base_compile
+
+      if test no != "$pic_mode"; then
+	command="$base_compile $qsrcfile $pic_flag"
+      else
+	# Don't build PIC code
+	command="$base_compile $qsrcfile"
+      fi
+
+      func_mkdir_p "$xdir$objdir"
+
+      if test -z "$output_obj"; then
+	# Place PIC objects in $objdir
+	func_append command " -o $lobj"
+      fi
+
+      func_show_eval_locale "$command"	\
+          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
+
+      if test warn = "$need_locks" &&
+	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+	$ECHO "\
+*** ERROR, $lockfile contains:
+`cat $lockfile 2>/dev/null`
+
+but it should contain:
+$srcfile
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support '-c' and '-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+
+      # Just move the object if needed, then go on to compile the next one
+      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
+	func_show_eval '$MV "$output_obj" "$lobj"' \
+	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
+      fi
+
+      # Allow error messages only from the first compilation.
+      if test yes = "$suppress_opt"; then
+	suppress_output=' >/dev/null 2>&1'
+      fi
+    fi
+
+    # Only build a position-dependent object if we build old libraries.
+    if test yes = "$build_old_libs"; then
+      if test yes != "$pic_mode"; then
+	# Don't build PIC code
+	command="$base_compile $qsrcfile$pie_flag"
+      else
+	command="$base_compile $qsrcfile $pic_flag"
+      fi
+      if test yes = "$compiler_c_o"; then
+	func_append command " -o $obj"
+      fi
+
+      # Suppress compiler output if we already did a PIC compilation.
+      func_append command "$suppress_output"
+      func_show_eval_locale "$command" \
+        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
+
+      if test warn = "$need_locks" &&
+	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+	$ECHO "\
+*** ERROR, $lockfile contains:
+`cat $lockfile 2>/dev/null`
+
+but it should contain:
+$srcfile
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support '-c' and '-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+
+      # Just move the object if needed
+      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
+	func_show_eval '$MV "$output_obj" "$obj"' \
+	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
+      fi
+    fi
+
+    $opt_dry_run || {
+      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
+
+      # Unlock the critical section if it was locked
+      if test no != "$need_locks"; then
+	removelist=$lockfile
+        $RM "$lockfile"
+      fi
+    }
+
+    exit $EXIT_SUCCESS
+}
+
+$opt_help || {
+  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
+}
+
+func_mode_help ()
+{
+    # We need to display help for each of the modes.
+    case $opt_mode in
+      "")
+        # Generic help is extracted from the usage comments
+        # at the start of this file.
+        func_help
+        ;;
+
+      clean)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
+
+Remove files from the build directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
+to RM.
+
+If FILE is a libtool library, object or program, all the files associated
+with it are deleted. Otherwise, only FILE itself is deleted using RM."
+        ;;
+
+      compile)
+      $ECHO \
+"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
+
+Compile a source file into a libtool library object.
+
+This mode accepts the following additional options:
+
+  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
+  -no-suppress      do not suppress compiler output for multiple passes
+  -prefer-pic       try to build PIC objects only
+  -prefer-non-pic   try to build non-PIC objects only
+  -shared           do not build a '.o' file suitable for static linking
+  -static           only build a '.o' file suitable for static linking
+  -Wc,FLAG          pass FLAG directly to the compiler
+
+COMPILE-COMMAND is a command to be used in creating a 'standard' object file
+from the given SOURCEFILE.
+
+The output file name is determined by removing the directory component from
+SOURCEFILE, then substituting the C source code suffix '.c' with the
+library object suffix, '.lo'."
+        ;;
+
+      execute)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
+
+Automatically set library path, then run a program.
+
+This mode accepts the following additional options:
+
+  -dlopen FILE      add the directory containing FILE to the library path
+
+This mode sets the library path environment variable according to '-dlopen'
+flags.
+
+If any of the ARGS are libtool executable wrappers, then they are translated
+into their corresponding uninstalled binary, and any of their required library
+directories are added to the library path.
+
+Then, COMMAND is executed, with ARGS as arguments."
+        ;;
+
+      finish)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
+
+Complete the installation of libtool libraries.
+
+Each LIBDIR is a directory that contains libtool libraries.
+
+The commands that this mode executes may require superuser privileges.  Use
+the '--dry-run' option if you just want to see what would be executed."
+        ;;
+
+      install)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
+
+Install executables or libraries.
+
+INSTALL-COMMAND is the installation command.  The first component should be
+either the 'install' or 'cp' program.
+
+The following components of INSTALL-COMMAND are treated specially:
+
+  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
+
+The rest of the components are interpreted as arguments to that command (only
+BSD-compatible install options are recognized)."
+        ;;
+
+      link)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
+
+Link object files or libraries together to form another library, or to
+create an executable program.
+
+LINK-COMMAND is a command using the C compiler that you would use to create
+a program from several object files.
+
+The following components of LINK-COMMAND are treated specially:
+
+  -all-static       do not do any dynamic linking at all
+  -avoid-version    do not add a version suffix if possible
+  -bindir BINDIR    specify path to binaries directory (for systems where
+                    libraries must be found in the PATH setting at runtime)
+  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
+  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
+  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
+  -export-symbols SYMFILE
+                    try to export only the symbols listed in SYMFILE
+  -export-symbols-regex REGEX
+                    try to export only the symbols matching REGEX
+  -LLIBDIR          search LIBDIR for required installed libraries
+  -lNAME            OUTPUT-FILE requires the installed library libNAME
+  -module           build a library that can dlopened
+  -no-fast-install  disable the fast-install mode
+  -no-install       link a not-installable executable
+  -no-undefined     declare that a library does not refer to external symbols
+  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
+  -objectlist FILE  use a list of object files found in FILE to specify objects
+  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
+  -precious-files-regex REGEX
+                    don't remove output files matching REGEX
+  -release RELEASE  specify package release information
+  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
+  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
+  -shared           only do dynamic linking of libtool libraries
+  -shrext SUFFIX    override the standard shared library file extension
+  -static           do not do any dynamic linking of uninstalled libtool libraries
+  -static-libtool-libs
+                    do not do any dynamic linking of libtool libraries
+  -version-info CURRENT[:REVISION[:AGE]]
+                    specify library version info [each variable defaults to 0]
+  -weak LIBNAME     declare that the target provides the LIBNAME interface
+  -Wc,FLAG
+  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
+  -Wl,FLAG
+  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
+  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
+
+All other options (arguments beginning with '-') are ignored.
+
+Every other argument is treated as a filename.  Files ending in '.la' are
+treated as uninstalled libtool libraries, other files are standard or library
+object files.
+
+If the OUTPUT-FILE ends in '.la', then a libtool library is created,
+only library objects ('.lo' files) may be specified, and '-rpath' is
+required, except when creating a convenience library.
+
+If OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
+using 'ar' and 'ranlib', or on Windows using 'lib'.
+
+If OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
+is created, otherwise an executable program is created."
+        ;;
+
+      uninstall)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
+
+Remove libraries from an installation directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
+to RM.
+
+If FILE is a libtool library, all the files associated with it are deleted.
+Otherwise, only FILE itself is deleted using RM."
+        ;;
+
+      *)
+        func_fatal_help "invalid operation mode '$opt_mode'"
+        ;;
+    esac
+
+    echo
+    $ECHO "Try '$progname --help' for more information about other modes."
+}
+
+# Now that we've collected a possible --mode arg, show help if necessary
+if $opt_help; then
+  if test : = "$opt_help"; then
+    func_mode_help
+  else
+    {
+      func_help noexit
+      for opt_mode in compile link execute install finish uninstall clean; do
+	func_mode_help
+      done
+    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
+    {
+      func_help noexit
+      for opt_mode in compile link execute install finish uninstall clean; do
+	echo
+	func_mode_help
+      done
+    } |
+    $SED '1d
+      /^When reporting/,/^Report/{
+	H
+	d
+      }
+      $x
+      /information about other modes/d
+      /more detailed .*MODE/d
+      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
+  fi
+  exit $?
+fi
+
+
+# func_mode_execute arg...
+func_mode_execute ()
+{
+    $debug_cmd
+
+    # The first argument is the command name.
+    cmd=$nonopt
+    test -z "$cmd" && \
+      func_fatal_help "you must specify a COMMAND"
+
+    # Handle -dlopen flags immediately.
+    for file in $opt_dlopen; do
+      test -f "$file" \
+	|| func_fatal_help "'$file' is not a file"
+
+      dir=
+      case $file in
+      *.la)
+	func_resolve_sysroot "$file"
+	file=$func_resolve_sysroot_result
+
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$file" \
+	  || func_fatal_help "'$lib' is not a valid libtool archive"
+
+	# Read the libtool library.
+	dlname=
+	library_names=
+	func_source "$file"
+
+	# Skip this library if it cannot be dlopened.
+	if test -z "$dlname"; then
+	  # Warn if it was a shared library.
+	  test -n "$library_names" && \
+	    func_warning "'$file' was not linked with '-export-dynamic'"
+	  continue
+	fi
+
+	func_dirname "$file" "" "."
+	dir=$func_dirname_result
+
+	if test -f "$dir/$objdir/$dlname"; then
+	  func_append dir "/$objdir"
+	else
+	  if test ! -f "$dir/$dlname"; then
+	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
+	  fi
+	fi
+	;;
+
+      *.lo)
+	# Just add the directory containing the .lo file.
+	func_dirname "$file" "" "."
+	dir=$func_dirname_result
+	;;
+
+      *)
+	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
+	continue
+	;;
+      esac
+
+      # Get the absolute pathname.
+      absdir=`cd "$dir" && pwd`
+      test -n "$absdir" && dir=$absdir
+
+      # Now add the directory to shlibpath_var.
+      if eval "test -z \"\$$shlibpath_var\""; then
+	eval "$shlibpath_var=\"\$dir\""
+      else
+	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
+      fi
+    done
+
+    # This variable tells wrapper scripts just to set shlibpath_var
+    # rather than running their programs.
+    libtool_execute_magic=$magic
+
+    # Check if any of the arguments is a wrapper script.
+    args=
+    for file
+    do
+      case $file in
+      -* | *.la | *.lo ) ;;
+      *)
+	# Do a test to see if this is really a libtool program.
+	if func_ltwrapper_script_p "$file"; then
+	  func_source "$file"
+	  # Transform arg to wrapped name.
+	  file=$progdir/$program
+	elif func_ltwrapper_executable_p "$file"; then
+	  func_ltwrapper_scriptname "$file"
+	  func_source "$func_ltwrapper_scriptname_result"
+	  # Transform arg to wrapped name.
+	  file=$progdir/$program
+	fi
+	;;
+      esac
+      # Quote arguments (to preserve shell metacharacters).
+      func_append_quoted args "$file"
+    done
+
+    if $opt_dry_run; then
+      # Display what would be done.
+      if test -n "$shlibpath_var"; then
+	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
+	echo "export $shlibpath_var"
+      fi
+      $ECHO "$cmd$args"
+      exit $EXIT_SUCCESS
+    else
+      if test -n "$shlibpath_var"; then
+	# Export the shlibpath_var.
+	eval "export $shlibpath_var"
+      fi
+
+      # Restore saved environment variables
+      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+      do
+	eval "if test \"\${save_$lt_var+set}\" = set; then
+                $lt_var=\$save_$lt_var; export $lt_var
+	      else
+		$lt_unset $lt_var
+	      fi"
+      done
+
+      # Now prepare to actually exec the command.
+      exec_cmd=\$cmd$args
+    fi
+}
+
+test execute = "$opt_mode" && func_mode_execute ${1+"$@"}
+
+
+# func_mode_finish arg...
+func_mode_finish ()
+{
+    $debug_cmd
+
+    libs=
+    libdirs=
+    admincmds=
+
+    for opt in "$nonopt" ${1+"$@"}
+    do
+      if test -d "$opt"; then
+	func_append libdirs " $opt"
+
+      elif test -f "$opt"; then
+	if func_lalib_unsafe_p "$opt"; then
+	  func_append libs " $opt"
+	else
+	  func_warning "'$opt' is not a valid libtool archive"
+	fi
+
+      else
+	func_fatal_error "invalid argument '$opt'"
+      fi
+    done
+
+    if test -n "$libs"; then
+      if test -n "$lt_sysroot"; then
+        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
+        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
+      else
+        sysroot_cmd=
+      fi
+
+      # Remove sysroot references
+      if $opt_dry_run; then
+        for lib in $libs; do
+          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
+        done
+      else
+        tmpdir=`func_mktempdir`
+        for lib in $libs; do
+	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
+	    > $tmpdir/tmp-la
+	  mv -f $tmpdir/tmp-la $lib
+	done
+        ${RM}r "$tmpdir"
+      fi
+    fi
+
+    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
+      for libdir in $libdirs; do
+	if test -n "$finish_cmds"; then
+	  # Do each command in the finish commands.
+	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
+'"$cmd"'"'
+	fi
+	if test -n "$finish_eval"; then
+	  # Do the single finish_eval.
+	  eval cmds=\"$finish_eval\"
+	  $opt_dry_run || eval "$cmds" || func_append admincmds "
+       $cmds"
+	fi
+      done
+    fi
+
+    # Exit here if they wanted silent mode.
+    $opt_quiet && exit $EXIT_SUCCESS
+
+    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
+      echo "----------------------------------------------------------------------"
+      echo "Libraries have been installed in:"
+      for libdir in $libdirs; do
+	$ECHO "   $libdir"
+      done
+      echo
+      echo "If you ever happen to want to link against installed libraries"
+      echo "in a given directory, LIBDIR, you must either use libtool, and"
+      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
+      echo "flag during linking and do at least one of the following:"
+      if test -n "$shlibpath_var"; then
+	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
+	echo "     during execution"
+      fi
+      if test -n "$runpath_var"; then
+	echo "   - add LIBDIR to the '$runpath_var' environment variable"
+	echo "     during linking"
+      fi
+      if test -n "$hardcode_libdir_flag_spec"; then
+	libdir=LIBDIR
+	eval flag=\"$hardcode_libdir_flag_spec\"
+
+	$ECHO "   - use the '$flag' linker flag"
+      fi
+      if test -n "$admincmds"; then
+	$ECHO "   - have your system administrator run these commands:$admincmds"
+      fi
+      if test -f /etc/ld.so.conf; then
+	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
+      fi
+      echo
+
+      echo "See any operating system documentation about shared libraries for"
+      case $host in
+	solaris2.[6789]|solaris2.1[0-9])
+	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
+	  echo "pages."
+	  ;;
+	*)
+	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
+	  ;;
+      esac
+      echo "----------------------------------------------------------------------"
+    fi
+    exit $EXIT_SUCCESS
+}
+
+test finish = "$opt_mode" && func_mode_finish ${1+"$@"}
+
+
+# func_mode_install arg...
+func_mode_install ()
+{
+    $debug_cmd
+
+    # There may be an optional sh(1) argument at the beginning of
+    # install_prog (especially on Windows NT).
+    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
+       # Allow the use of GNU shtool's install command.
+       case $nonopt in *shtool*) :;; *) false;; esac
+    then
+      # Aesthetically quote it.
+      func_quote_for_eval "$nonopt"
+      install_prog="$func_quote_for_eval_result "
+      arg=$1
+      shift
+    else
+      install_prog=
+      arg=$nonopt
+    fi
+
+    # The real first argument should be the name of the installation program.
+    # Aesthetically quote it.
+    func_quote_for_eval "$arg"
+    func_append install_prog "$func_quote_for_eval_result"
+    install_shared_prog=$install_prog
+    case " $install_prog " in
+      *[\\\ /]cp\ *) install_cp=: ;;
+      *) install_cp=false ;;
+    esac
+
+    # We need to accept at least all the BSD install flags.
+    dest=
+    files=
+    opts=
+    prev=
+    install_type=
+    isdir=false
+    stripme=
+    no_mode=:
+    for arg
+    do
+      arg2=
+      if test -n "$dest"; then
+	func_append files " $dest"
+	dest=$arg
+	continue
+      fi
+
+      case $arg in
+      -d) isdir=: ;;
+      -f)
+	if $install_cp; then :; else
+	  prev=$arg
+	fi
+	;;
+      -g | -m | -o)
+	prev=$arg
+	;;
+      -s)
+	stripme=" -s"
+	continue
+	;;
+      -*)
+	;;
+      *)
+	# If the previous option needed an argument, then skip it.
+	if test -n "$prev"; then
+	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
+	    arg2=$install_override_mode
+	    no_mode=false
+	  fi
+	  prev=
+	else
+	  dest=$arg
+	  continue
+	fi
+	;;
+      esac
+
+      # Aesthetically quote the argument.
+      func_quote_for_eval "$arg"
+      func_append install_prog " $func_quote_for_eval_result"
+      if test -n "$arg2"; then
+	func_quote_for_eval "$arg2"
+      fi
+      func_append install_shared_prog " $func_quote_for_eval_result"
+    done
+
+    test -z "$install_prog" && \
+      func_fatal_help "you must specify an install program"
+
+    test -n "$prev" && \
+      func_fatal_help "the '$prev' option requires an argument"
+
+    if test -n "$install_override_mode" && $no_mode; then
+      if $install_cp; then :; else
+	func_quote_for_eval "$install_override_mode"
+	func_append install_shared_prog " -m $func_quote_for_eval_result"
+      fi
+    fi
+
+    if test -z "$files"; then
+      if test -z "$dest"; then
+	func_fatal_help "no file or destination specified"
+      else
+	func_fatal_help "you must specify a destination"
+      fi
+    fi
+
+    # Strip any trailing slash from the destination.
+    func_stripname '' '/' "$dest"
+    dest=$func_stripname_result
+
+    # Check to see that the destination is a directory.
+    test -d "$dest" && isdir=:
+    if $isdir; then
+      destdir=$dest
+      destname=
+    else
+      func_dirname_and_basename "$dest" "" "."
+      destdir=$func_dirname_result
+      destname=$func_basename_result
+
+      # Not a directory, so check to see that there is only one file specified.
+      set dummy $files; shift
+      test "$#" -gt 1 && \
+	func_fatal_help "'$dest' is not a directory"
+    fi
+    case $destdir in
+    [\\/]* | [A-Za-z]:[\\/]*) ;;
+    *)
+      for file in $files; do
+	case $file in
+	*.lo) ;;
+	*)
+	  func_fatal_help "'$destdir' must be an absolute directory name"
+	  ;;
+	esac
+      done
+      ;;
+    esac
+
+    # This variable tells wrapper scripts just to set variables rather
+    # than running their programs.
+    libtool_install_magic=$magic
+
+    staticlibs=
+    future_libdirs=
+    current_libdirs=
+    for file in $files; do
+
+      # Do each installation.
+      case $file in
+      *.$libext)
+	# Do the static libraries later.
+	func_append staticlibs " $file"
+	;;
+
+      *.la)
+	func_resolve_sysroot "$file"
+	file=$func_resolve_sysroot_result
+
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$file" \
+	  || func_fatal_help "'$file' is not a valid libtool archive"
+
+	library_names=
+	old_library=
+	relink_command=
+	func_source "$file"
+
+	# Add the libdir to current_libdirs if it is the destination.
+	if test "X$destdir" = "X$libdir"; then
+	  case "$current_libdirs " in
+	  *" $libdir "*) ;;
+	  *) func_append current_libdirs " $libdir" ;;
+	  esac
+	else
+	  # Note the libdir as a future libdir.
+	  case "$future_libdirs " in
+	  *" $libdir "*) ;;
+	  *) func_append future_libdirs " $libdir" ;;
+	  esac
+	fi
+
+	func_dirname "$file" "/" ""
+	dir=$func_dirname_result
+	func_append dir "$objdir"
+
+	if test -n "$relink_command"; then
+	  # Determine the prefix the user has applied to our future dir.
+	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
+
+	  # Don't allow the user to place us outside of our expected
+	  # location b/c this prevents finding dependent libraries that
+	  # are installed to the same prefix.
+	  # At present, this check doesn't affect windows .dll's that
+	  # are installed into $libdir/../bin (currently, that works fine)
+	  # but it's something to keep an eye on.
+	  test "$inst_prefix_dir" = "$destdir" && \
+	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
+
+	  if test -n "$inst_prefix_dir"; then
+	    # Stick the inst_prefix_dir data into the link command.
+	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
+	  else
+	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
+	  fi
+
+	  func_warning "relinking '$file'"
+	  func_show_eval "$relink_command" \
+	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
+	fi
+
+	# See the names of the shared library.
+	set dummy $library_names; shift
+	if test -n "$1"; then
+	  realname=$1
+	  shift
+
+	  srcname=$realname
+	  test -n "$relink_command" && srcname=${realname}T
+
+	  # Install the shared library and build the symlinks.
+	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
+	      'exit $?'
+	  tstripme=$stripme
+	  case $host_os in
+	  cygwin* | mingw* | pw32* | cegcc*)
+	    case $realname in
+	    *.dll.a)
+	      tstripme=
+	      ;;
+	    esac
+	    ;;
+	  os2*)
+	    case $realname in
+	    *_dll.a)
+	      tstripme=
+	      ;;
+	    esac
+	    ;;
+	  esac
+	  if test -n "$tstripme" && test -n "$striplib"; then
+	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
+	  fi
+
+	  if test "$#" -gt 0; then
+	    # Delete the old symlinks, and create new ones.
+	    # Try 'ln -sf' first, because the 'ln' binary might depend on
+	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
+	    # so we also need to try rm && ln -s.
+	    for linkname
+	    do
+	      test "$linkname" != "$realname" \
+		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
+	    done
+	  fi
+
+	  # Do each command in the postinstall commands.
+	  lib=$destdir/$realname
+	  func_execute_cmds "$postinstall_cmds" 'exit $?'
+	fi
+
+	# Install the pseudo-library for information purposes.
+	func_basename "$file"
+	name=$func_basename_result
+	instname=$dir/${name}i
+	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
+
+	# Maybe install the static library, too.
+	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
+	;;
+
+      *.lo)
+	# Install (i.e. copy) a libtool object.
+
+	# Figure out destination file name, if it wasn't already specified.
+	if test -n "$destname"; then
+	  destfile=$destdir/$destname
+	else
+	  func_basename "$file"
+	  destfile=$func_basename_result
+	  destfile=$destdir/$destfile
+	fi
+
+	# Deduce the name of the destination old-style object file.
+	case $destfile in
+	*.lo)
+	  func_lo2o "$destfile"
+	  staticdest=$func_lo2o_result
+	  ;;
+	*.$objext)
+	  staticdest=$destfile
+	  destfile=
+	  ;;
+	*)
+	  func_fatal_help "cannot copy a libtool object to '$destfile'"
+	  ;;
+	esac
+
+	# Install the libtool object if requested.
+	test -n "$destfile" && \
+	  func_show_eval "$install_prog $file $destfile" 'exit $?'
+
+	# Install the old object if enabled.
+	if test yes = "$build_old_libs"; then
+	  # Deduce the name of the old-style object file.
+	  func_lo2o "$file"
+	  staticobj=$func_lo2o_result
+	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
+	fi
+	exit $EXIT_SUCCESS
+	;;
+
+      *)
+	# Figure out destination file name, if it wasn't already specified.
+	if test -n "$destname"; then
+	  destfile=$destdir/$destname
+	else
+	  func_basename "$file"
+	  destfile=$func_basename_result
+	  destfile=$destdir/$destfile
+	fi
+
+	# If the file is missing, and there is a .exe on the end, strip it
+	# because it is most likely a libtool script we actually want to
+	# install
+	stripped_ext=
+	case $file in
+	  *.exe)
+	    if test ! -f "$file"; then
+	      func_stripname '' '.exe' "$file"
+	      file=$func_stripname_result
+	      stripped_ext=.exe
+	    fi
+	    ;;
+	esac
+
+	# Do a test to see if this is really a libtool program.
+	case $host in
+	*cygwin* | *mingw*)
+	    if func_ltwrapper_executable_p "$file"; then
+	      func_ltwrapper_scriptname "$file"
+	      wrapper=$func_ltwrapper_scriptname_result
+	    else
+	      func_stripname '' '.exe' "$file"
+	      wrapper=$func_stripname_result
+	    fi
+	    ;;
+	*)
+	    wrapper=$file
+	    ;;
+	esac
+	if func_ltwrapper_script_p "$wrapper"; then
+	  notinst_deplibs=
+	  relink_command=
+
+	  func_source "$wrapper"
+
+	  # Check the variables that should have been set.
+	  test -z "$generated_by_libtool_version" && \
+	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
+
+	  finalize=:
+	  for lib in $notinst_deplibs; do
+	    # Check to see that each library is installed.
+	    libdir=
+	    if test -f "$lib"; then
+	      func_source "$lib"
+	    fi
+	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
+	    if test -n "$libdir" && test ! -f "$libfile"; then
+	      func_warning "'$lib' has not been installed in '$libdir'"
+	      finalize=false
+	    fi
+	  done
+
+	  relink_command=
+	  func_source "$wrapper"
+
+	  outputname=
+	  if test no = "$fast_install" && test -n "$relink_command"; then
+	    $opt_dry_run || {
+	      if $finalize; then
+	        tmpdir=`func_mktempdir`
+		func_basename "$file$stripped_ext"
+		file=$func_basename_result
+	        outputname=$tmpdir/$file
+	        # Replace the output file specification.
+	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
+
+	        $opt_quiet || {
+	          func_quote_for_expand "$relink_command"
+		  eval "func_echo $func_quote_for_expand_result"
+	        }
+	        if eval "$relink_command"; then :
+	          else
+		  func_error "error: relink '$file' with the above command before installing it"
+		  $opt_dry_run || ${RM}r "$tmpdir"
+		  continue
+	        fi
+	        file=$outputname
+	      else
+	        func_warning "cannot relink '$file'"
+	      fi
+	    }
+	  else
+	    # Install the binary that we compiled earlier.
+	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
+	  fi
+	fi
+
+	# remove .exe since cygwin /usr/bin/install will append another
+	# one anyway
+	case $install_prog,$host in
+	*/usr/bin/install*,*cygwin*)
+	  case $file:$destfile in
+	  *.exe:*.exe)
+	    # this is ok
+	    ;;
+	  *.exe:*)
+	    destfile=$destfile.exe
+	    ;;
+	  *:*.exe)
+	    func_stripname '' '.exe' "$destfile"
+	    destfile=$func_stripname_result
+	    ;;
+	  esac
+	  ;;
+	esac
+	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
+	$opt_dry_run || if test -n "$outputname"; then
+	  ${RM}r "$tmpdir"
+	fi
+	;;
+      esac
+    done
+
+    for file in $staticlibs; do
+      func_basename "$file"
+      name=$func_basename_result
+
+      # Set up the ranlib parameters.
+      oldlib=$destdir/$name
+      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
+      tool_oldlib=$func_to_tool_file_result
+
+      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
+
+      if test -n "$stripme" && test -n "$old_striplib"; then
+	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
+      fi
+
+      # Do each command in the postinstall commands.
+      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
+    done
+
+    test -n "$future_libdirs" && \
+      func_warning "remember to run '$progname --finish$future_libdirs'"
+
+    if test -n "$current_libdirs"; then
+      # Maybe just do a dry run.
+      $opt_dry_run && current_libdirs=" -n$current_libdirs"
+      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
+    else
+      exit $EXIT_SUCCESS
+    fi
+}
+
+test install = "$opt_mode" && func_mode_install ${1+"$@"}
+
+
+# func_generate_dlsyms outputname originator pic_p
+# Extract symbols from dlprefiles and create ${outputname}S.o with
+# a dlpreopen symbol table.
+func_generate_dlsyms ()
+{
+    $debug_cmd
+
+    my_outputname=$1
+    my_originator=$2
+    my_pic_p=${3-false}
+    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
+    my_dlsyms=
+
+    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
+      if test -n "$NM" && test -n "$global_symbol_pipe"; then
+	my_dlsyms=${my_outputname}S.c
+      else
+	func_error "not configured to extract global symbols from dlpreopened files"
+      fi
+    fi
+
+    if test -n "$my_dlsyms"; then
+      case $my_dlsyms in
+      "") ;;
+      *.c)
+	# Discover the nlist of each of the dlfiles.
+	nlist=$output_objdir/$my_outputname.nm
+
+	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
+
+	# Parse the name list into a source file.
+	func_verbose "creating $output_objdir/$my_dlsyms"
+
+	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
+/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
+/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
+
+#ifdef __cplusplus
+extern \"C\" {
+#endif
+
+#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
+#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
+#endif
+
+/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
+#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
+/* DATA imports from DLLs on WIN32 can't be const, because runtime
+   relocations are performed -- see ld's documentation on pseudo-relocs.  */
+# define LT_DLSYM_CONST
+#elif defined __osf__
+/* This system does not cope well with relocations in const data.  */
+# define LT_DLSYM_CONST
+#else
+# define LT_DLSYM_CONST const
+#endif
+
+#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
+
+/* External symbol declarations for the compiler. */\
+"
+
+	if test yes = "$dlself"; then
+	  func_verbose "generating symbol list for '$output'"
+
+	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
+
+	  # Add our own program objects to the symbol list.
+	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
+	  for progfile in $progfiles; do
+	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
+	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
+	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
+	  done
+
+	  if test -n "$exclude_expsyms"; then
+	    $opt_dry_run || {
+	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	    }
+	  fi
+
+	  if test -n "$export_symbols_regex"; then
+	    $opt_dry_run || {
+	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	    }
+	  fi
+
+	  # Prepare the list of exported symbols
+	  if test -z "$export_symbols"; then
+	    export_symbols=$output_objdir/$outputname.exp
+	    $opt_dry_run || {
+	      $RM $export_symbols
+	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
+	      case $host in
+	      *cygwin* | *mingw* | *cegcc* )
+                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
+	        ;;
+	      esac
+	    }
+	  else
+	    $opt_dry_run || {
+	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
+	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	      case $host in
+	        *cygwin* | *mingw* | *cegcc* )
+	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
+	          ;;
+	      esac
+	    }
+	  fi
+	fi
+
+	for dlprefile in $dlprefiles; do
+	  func_verbose "extracting global C symbols from '$dlprefile'"
+	  func_basename "$dlprefile"
+	  name=$func_basename_result
+          case $host in
+	    *cygwin* | *mingw* | *cegcc* )
+	      # if an import library, we need to obtain dlname
+	      if func_win32_import_lib_p "$dlprefile"; then
+	        func_tr_sh "$dlprefile"
+	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
+	        dlprefile_dlbasename=
+	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
+	          # Use subshell, to avoid clobbering current variable values
+	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
+	          if test -n "$dlprefile_dlname"; then
+	            func_basename "$dlprefile_dlname"
+	            dlprefile_dlbasename=$func_basename_result
+	          else
+	            # no lafile. user explicitly requested -dlpreopen <import library>.
+	            $sharedlib_from_linklib_cmd "$dlprefile"
+	            dlprefile_dlbasename=$sharedlib_from_linklib_result
+	          fi
+	        fi
+	        $opt_dry_run || {
+	          if test -n "$dlprefile_dlbasename"; then
+	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
+	          else
+	            func_warning "Could not compute DLL name from $name"
+	            eval '$ECHO ": $name " >> "$nlist"'
+	          fi
+	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
+	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
+	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
+	        }
+	      else # not an import lib
+	        $opt_dry_run || {
+	          eval '$ECHO ": $name " >> "$nlist"'
+	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
+	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
+	        }
+	      fi
+	    ;;
+	    *)
+	      $opt_dry_run || {
+	        eval '$ECHO ": $name " >> "$nlist"'
+	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
+	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
+	      }
+	    ;;
+          esac
+	done
+
+	$opt_dry_run || {
+	  # Make sure we have at least an empty file.
+	  test -f "$nlist" || : > "$nlist"
+
+	  if test -n "$exclude_expsyms"; then
+	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
+	    $MV "$nlist"T "$nlist"
+	  fi
+
+	  # Try sorting and uniquifying the output.
+	  if $GREP -v "^: " < "$nlist" |
+	      if sort -k 3 </dev/null >/dev/null 2>&1; then
+		sort -k 3
+	      else
+		sort +2
+	      fi |
+	      uniq > "$nlist"S; then
+	    :
+	  else
+	    $GREP -v "^: " < "$nlist" > "$nlist"S
+	  fi
+
+	  if test -f "$nlist"S; then
+	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
+	  else
+	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
+	  fi
+
+	  func_show_eval '$RM "${nlist}I"'
+	  if test -n "$global_symbol_to_import"; then
+	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
+	  fi
+
+	  echo >> "$output_objdir/$my_dlsyms" "\
+
+/* The mapping between symbol names and symbols.  */
+typedef struct {
+  const char *name;
+  void *address;
+} lt_dlsymlist;
+extern LT_DLSYM_CONST lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[];\
+"
+
+	  if test -s "$nlist"I; then
+	    echo >> "$output_objdir/$my_dlsyms" "\
+static void lt_syminit(void)
+{
+  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
+  for (; symbol->name; ++symbol)
+    {"
+	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
+	    echo >> "$output_objdir/$my_dlsyms" "\
+    }
+}"
+	  fi
+	  echo >> "$output_objdir/$my_dlsyms" "\
+LT_DLSYM_CONST lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[] =
+{ {\"$my_originator\", (void *) 0},"
+
+	  if test -s "$nlist"I; then
+	    echo >> "$output_objdir/$my_dlsyms" "\
+  {\"@INIT@\", (void *) &lt_syminit},"
+	  fi
+
+	  case $need_lib_prefix in
+	  no)
+	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
+	    ;;
+	  *)
+	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
+	    ;;
+	  esac
+	  echo >> "$output_objdir/$my_dlsyms" "\
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt_${my_prefix}_LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif\
+"
+	} # !$opt_dry_run
+
+	pic_flag_for_symtable=
+	case "$compile_command " in
+	*" -static "*) ;;
+	*)
+	  case $host in
+	  # compiling the symbol table file with pic_flag works around
+	  # a FreeBSD bug that causes programs to crash when -lm is
+	  # linked before any other PIC object.  But we must not use
+	  # pic_flag when linking with -static.  The problem exists in
+	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
+	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
+	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
+	  *-*-hpux*)
+	    pic_flag_for_symtable=" $pic_flag"  ;;
+	  *)
+	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
+	    ;;
+	  esac
+	  ;;
+	esac
+	symtab_cflags=
+	for arg in $LTCFLAGS; do
+	  case $arg in
+	  -pie | -fpie | -fPIE) ;;
+	  *) func_append symtab_cflags " $arg" ;;
+	  esac
+	done
+
+	# Now compile the dynamic symbol file.
+	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
+
+	# Clean up the generated files.
+	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
+
+	# Transform the symbol file into the correct name.
+	symfileobj=$output_objdir/${my_outputname}S.$objext
+	case $host in
+	*cygwin* | *mingw* | *cegcc* )
+	  if test -f "$output_objdir/$my_outputname.def"; then
+	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+	  else
+	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
+	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
+	  fi
+	  ;;
+	*)
+	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
+	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
+	  ;;
+	esac
+	;;
+      *)
+	func_fatal_error "unknown suffix for '$my_dlsyms'"
+	;;
+      esac
+    else
+      # We keep going just in case the user didn't refer to
+      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
+      # really was required.
+
+      # Nullify the symbol file.
+      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
+      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
+    fi
+}
+
+# func_cygming_gnu_implib_p ARG
+# This predicate returns with zero status (TRUE) if
+# ARG is a GNU/binutils-style import library. Returns
+# with nonzero status (FALSE) otherwise.
+func_cygming_gnu_implib_p ()
+{
+  $debug_cmd
+
+  func_to_tool_file "$1" func_convert_file_msys_to_w32
+  func_cygming_gnu_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $EGREP ' (_head_[A-Za-z0-9_]+_[ad]l*|[A-Za-z0-9_]+_[ad]l*_iname)$'`
+  test -n "$func_cygming_gnu_implib_tmp"
+}
+
+# func_cygming_ms_implib_p ARG
+# This predicate returns with zero status (TRUE) if
+# ARG is an MS-style import library. Returns
+# with nonzero status (FALSE) otherwise.
+func_cygming_ms_implib_p ()
+{
+  $debug_cmd
+
+  func_to_tool_file "$1" func_convert_file_msys_to_w32
+  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
+  test -n "$func_cygming_ms_implib_tmp"
+}
+
+# func_win32_libid arg
+# return the library type of file 'arg'
+#
+# Need a lot of goo to handle *both* DLLs and import libs
+# Has to be a shell function in order to 'eat' the argument
+# that is supplied when $file_magic_command is called.
+# Despite the name, also deal with 64 bit binaries.
+func_win32_libid ()
+{
+  $debug_cmd
+
+  win32_libid_type=unknown
+  win32_fileres=`file -L $1 2>/dev/null`
+  case $win32_fileres in
+  *ar\ archive\ import\ library*) # definitely import
+    win32_libid_type="x86 archive import"
+    ;;
+  *ar\ archive*) # could be an import, or static
+    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
+    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
+       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
+      case $nm_interface in
+      "MS dumpbin")
+	if func_cygming_ms_implib_p "$1" ||
+	   func_cygming_gnu_implib_p "$1"
+	then
+	  win32_nmres=import
+	else
+	  win32_nmres=
+	fi
+	;;
+      *)
+	func_to_tool_file "$1" func_convert_file_msys_to_w32
+	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
+	  $SED -n -e '
+	    1,100{
+		/ I /{
+		    s|.*|import|
+		    p
+		    q
+		}
+	    }'`
+	;;
+      esac
+      case $win32_nmres in
+      import*)  win32_libid_type="x86 archive import";;
+      *)        win32_libid_type="x86 archive static";;
+      esac
+    fi
+    ;;
+  *DLL*)
+    win32_libid_type="x86 DLL"
+    ;;
+  *executable*) # but shell scripts are "executable" too...
+    case $win32_fileres in
+    *MS\ Windows\ PE\ Intel*)
+      win32_libid_type="x86 DLL"
+      ;;
+    esac
+    ;;
+  esac
+  $ECHO "$win32_libid_type"
+}
+
+# func_cygming_dll_for_implib ARG
+#
+# Platform-specific function to extract the
+# name of the DLL associated with the specified
+# import library ARG.
+# Invoked by eval'ing the libtool variable
+#    $sharedlib_from_linklib_cmd
+# Result is available in the variable
+#    $sharedlib_from_linklib_result
+func_cygming_dll_for_implib ()
+{
+  $debug_cmd
+
+  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
+}
+
+# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
+#
+# The is the core of a fallback implementation of a
+# platform-specific function to extract the name of the
+# DLL associated with the specified import library LIBNAME.
+#
+# SECTION_NAME is either .idata$6 or .idata$7, depending
+# on the platform and compiler that created the implib.
+#
+# Echos the name of the DLL associated with the
+# specified import library.
+func_cygming_dll_for_implib_fallback_core ()
+{
+  $debug_cmd
+
+  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
+  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
+    $SED '/^Contents of section '"$match_literal"':/{
+      # Place marker at beginning of archive member dllname section
+      s/.*/====MARK====/
+      p
+      d
+    }
+    # These lines can sometimes be longer than 43 characters, but
+    # are always uninteresting
+    /:[	 ]*file format pe[i]\{,1\}-/d
+    /^In archive [^:]*:/d
+    # Ensure marker is printed
+    /^====MARK====/p
+    # Remove all lines with less than 43 characters
+    /^.\{43\}/!d
+    # From remaining lines, remove first 43 characters
+    s/^.\{43\}//' |
+    $SED -n '
+      # Join marker and all lines until next marker into a single line
+      /^====MARK====/ b para
+      H
+      $ b para
+      b
+      :para
+      x
+      s/\n//g
+      # Remove the marker
+      s/^====MARK====//
+      # Remove trailing dots and whitespace
+      s/[\. \t]*$//
+      # Print
+      /./p' |
+    # we now have a list, one entry per line, of the stringified
+    # contents of the appropriate section of all members of the
+    # archive that possess that section. Heuristic: eliminate
+    # all those that have a first or second character that is
+    # a '.' (that is, objdump's representation of an unprintable
+    # character.) This should work for all archives with less than
+    # 0x302f exports -- but will fail for DLLs whose name actually
+    # begins with a literal '.' or a single character followed by
+    # a '.'.
+    #
+    # Of those that remain, print the first one.
+    $SED -e '/^\./d;/^.\./d;q'
+}
+
+# func_cygming_dll_for_implib_fallback ARG
+# Platform-specific function to extract the
+# name of the DLL associated with the specified
+# import library ARG.
+#
+# This fallback implementation is for use when $DLLTOOL
+# does not support the --identify-strict option.
+# Invoked by eval'ing the libtool variable
+#    $sharedlib_from_linklib_cmd
+# Result is available in the variable
+#    $sharedlib_from_linklib_result
+func_cygming_dll_for_implib_fallback ()
+{
+  $debug_cmd
+
+  if func_cygming_gnu_implib_p "$1"; then
+    # binutils import library
+    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
+  elif func_cygming_ms_implib_p "$1"; then
+    # ms-generated import library
+    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
+  else
+    # unknown
+    sharedlib_from_linklib_result=
+  fi
+}
+
+
+# func_extract_an_archive dir oldlib
+func_extract_an_archive ()
+{
+    $debug_cmd
+
+    f_ex_an_ar_dir=$1; shift
+    f_ex_an_ar_oldlib=$1
+    if test yes = "$lock_old_archive_extraction"; then
+      lockfile=$f_ex_an_ar_oldlib.lock
+      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
+	func_echo "Waiting for $lockfile to be removed"
+	sleep 2
+      done
+    fi
+    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
+		   'stat=$?; rm -f "$lockfile"; exit $stat'
+    if test yes = "$lock_old_archive_extraction"; then
+      $opt_dry_run || rm -f "$lockfile"
+    fi
+    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
+     :
+    else
+      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
+    fi
+}
+
+
+# func_extract_archives gentop oldlib ...
+func_extract_archives ()
+{
+    $debug_cmd
+
+    my_gentop=$1; shift
+    my_oldlibs=${1+"$@"}
+    my_oldobjs=
+    my_xlib=
+    my_xabs=
+    my_xdir=
+
+    for my_xlib in $my_oldlibs; do
+      # Extract the objects.
+      case $my_xlib in
+	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
+	*) my_xabs=`pwd`"/$my_xlib" ;;
+      esac
+      func_basename "$my_xlib"
+      my_xlib=$func_basename_result
+      my_xlib_u=$my_xlib
+      while :; do
+        case " $extracted_archives " in
+	*" $my_xlib_u "*)
+	  func_arith $extracted_serial + 1
+	  extracted_serial=$func_arith_result
+	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
+	*) break ;;
+	esac
+      done
+      extracted_archives="$extracted_archives $my_xlib_u"
+      my_xdir=$my_gentop/$my_xlib_u
+
+      func_mkdir_p "$my_xdir"
+
+      case $host in
+      *-darwin*)
+	func_verbose "Extracting $my_xabs"
+	# Do not bother doing anything if just a dry run
+	$opt_dry_run || {
+	  darwin_orig_dir=`pwd`
+	  cd $my_xdir || exit $?
+	  darwin_archive=$my_xabs
+	  darwin_curdir=`pwd`
+	  func_basename "$darwin_archive"
+	  darwin_base_archive=$func_basename_result
+	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
+	  if test -n "$darwin_arches"; then
+	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
+	    darwin_arch=
+	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
+	    for darwin_arch in  $darwin_arches; do
+	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
+	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
+	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
+	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
+	      cd "$darwin_curdir"
+	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
+	    done # $darwin_arches
+            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
+	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
+	    darwin_file=
+	    darwin_files=
+	    for darwin_file in $darwin_filelist; do
+	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
+	      $LIPO -create -output "$darwin_file" $darwin_files
+	    done # $darwin_filelist
+	    $RM -rf unfat-$$
+	    cd "$darwin_orig_dir"
+	  else
+	    cd $darwin_orig_dir
+	    func_extract_an_archive "$my_xdir" "$my_xabs"
+	  fi # $darwin_arches
+	} # !$opt_dry_run
+	;;
+      *)
+        func_extract_an_archive "$my_xdir" "$my_xabs"
+	;;
+      esac
+      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
+    done
+
+    func_extract_archives_result=$my_oldobjs
+}
+
+
+# func_emit_wrapper [arg=no]
+#
+# Emit a libtool wrapper script on stdout.
+# Don't directly open a file because we may want to
+# incorporate the script contents within a cygwin/mingw
+# wrapper executable.  Must ONLY be called from within
+# func_mode_link because it depends on a number of variables
+# set therein.
+#
+# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
+# variable will take.  If 'yes', then the emitted script
+# will assume that the directory where it is stored is
+# the $objdir directory.  This is a cygwin/mingw-specific
+# behavior.
+func_emit_wrapper ()
+{
+	func_emit_wrapper_arg1=${1-no}
+
+	$ECHO "\
+#! $SHELL
+
+# $output - temporary wrapper script for $objdir/$outputname
+# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
+#
+# The $output program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='$sed_quote_subst'
+
+# Be Bourne compatible
+if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=\"$relink_command\"
+
+# This environment variable determines our operation mode.
+if test \"\$libtool_install_magic\" = \"$magic\"; then
+  # install mode needs the following variables:
+  generated_by_libtool_version='$macro_version'
+  notinst_deplibs='$notinst_deplibs'
+else
+  # When we are sourced in execute mode, \$file and \$ECHO are already set.
+  if test \"\$libtool_execute_magic\" != \"$magic\"; then
+    file=\"\$0\""
+
+    func_quote "$ECHO"
+    qECHO=$func_quote_result
+    $ECHO "\
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+  eval 'cat <<_LTECHO_EOF
+\$1
+_LTECHO_EOF'
+}
+    ECHO=\"$qECHO\"
+  fi
+
+# Very basic option parsing. These options are (a) specific to
+# the libtool wrapper, (b) are identical between the wrapper
+# /script/ and the wrapper /executable/ that is used only on
+# windows platforms, and (c) all begin with the string "--lt-"
+# (application programs are unlikely to have options that match
+# this pattern).
+#
+# There are only two supported options: --lt-debug and
+# --lt-dump-script. There is, deliberately, no --lt-help.
+#
+# The first argument to this parsing function should be the
+# script's $0 value, followed by "$@".
+lt_option_debug=
+func_parse_lt_options ()
+{
+  lt_script_arg0=\$0
+  shift
+  for lt_opt
+  do
+    case \"\$lt_opt\" in
+    --lt-debug) lt_option_debug=1 ;;
+    --lt-dump-script)
+        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
+        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
+        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
+        cat \"\$lt_dump_D/\$lt_dump_F\"
+        exit 0
+      ;;
+    --lt-*)
+        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
+        exit 1
+      ;;
+    esac
+  done
+
+  # Print the debug banner immediately:
+  if test -n \"\$lt_option_debug\"; then
+    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
+  fi
+}
+
+# Used when --lt-debug. Prints its arguments to stdout
+# (redirection is the responsibility of the caller)
+func_lt_dump_args ()
+{
+  lt_dump_args_N=1;
+  for lt_arg
+  do
+    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
+    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
+  done
+}
+
+# Core function for launching the target application
+func_exec_program_core ()
+{
+"
+  case $host in
+  # Backslashes separate directories on plain windows
+  *-*-mingw | *-*-os2* | *-cegcc*)
+    $ECHO "\
+      if test -n \"\$lt_option_debug\"; then
+        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
+        func_lt_dump_args \${1+\"\$@\"} 1>&2
+      fi
+      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
+"
+    ;;
+
+  *)
+    $ECHO "\
+      if test -n \"\$lt_option_debug\"; then
+        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
+        func_lt_dump_args \${1+\"\$@\"} 1>&2
+      fi
+      exec \"\$progdir/\$program\" \${1+\"\$@\"}
+"
+    ;;
+  esac
+  $ECHO "\
+      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
+      exit 1
+}
+
+# A function to encapsulate launching the target application
+# Strips options in the --lt-* namespace from \$@ and
+# launches target application with the remaining arguments.
+func_exec_program ()
+{
+  case \" \$* \" in
+  *\\ --lt-*)
+    for lt_wr_arg
+    do
+      case \$lt_wr_arg in
+      --lt-*) ;;
+      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
+      esac
+      shift
+    done ;;
+  esac
+  func_exec_program_core \${1+\"\$@\"}
+}
+
+  # Parse options
+  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
+
+  # Find the directory that this script lives in.
+  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
+  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
+
+  # Follow symbolic links until we get to the real thisdir.
+  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
+  while test -n \"\$file\"; do
+    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
+
+    # If there was a directory component, then change thisdir.
+    if test \"x\$destdir\" != \"x\$file\"; then
+      case \"\$destdir\" in
+      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
+      *) thisdir=\"\$thisdir/\$destdir\" ;;
+      esac
+    fi
+
+    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
+    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
+  done
+
+  # Usually 'no', except on cygwin/mingw when embedded into
+  # the cwrapper.
+  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
+  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
+    # special case for '.'
+    if test \"\$thisdir\" = \".\"; then
+      thisdir=\`pwd\`
+    fi
+    # remove .libs from thisdir
+    case \"\$thisdir\" in
+    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
+    $objdir )   thisdir=. ;;
+    esac
+  fi
+
+  # Try to get the absolute directory name.
+  absdir=\`cd \"\$thisdir\" && pwd\`
+  test -n \"\$absdir\" && thisdir=\"\$absdir\"
+"
+
+	if test yes = "$fast_install"; then
+	  $ECHO "\
+  program=lt-'$outputname'$exeext
+  progdir=\"\$thisdir/$objdir\"
+
+  if test ! -f \"\$progdir/\$program\" ||
+     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
+       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
+
+    file=\"\$\$-\$program\"
+
+    if test ! -d \"\$progdir\"; then
+      $MKDIR \"\$progdir\"
+    else
+      $RM \"\$progdir/\$file\"
+    fi"
+
+	  $ECHO "\
+
+    # relink executable if necessary
+    if test -n \"\$relink_command\"; then
+      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
+      else
+	\$ECHO \"\$relink_command_output\" >&2
+	$RM \"\$progdir/\$file\"
+	exit 1
+      fi
+    fi
+
+    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
+    { $RM \"\$progdir/\$program\";
+      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
+    $RM \"\$progdir/\$file\"
+  fi"
+	else
+	  $ECHO "\
+  program='$outputname'
+  progdir=\"\$thisdir/$objdir\"
+"
+	fi
+
+	$ECHO "\
+
+  if test -f \"\$progdir/\$program\"; then"
+
+	# fixup the dll searchpath if we need to.
+	#
+	# Fix the DLL searchpath if we need to.  Do this before prepending
+	# to shlibpath, because on Windows, both are PATH and uninstalled
+	# libraries must come first.
+	if test -n "$dllsearchpath"; then
+	  $ECHO "\
+    # Add the dll search path components to the executable PATH
+    PATH=$dllsearchpath:\$PATH
+"
+	fi
+
+	# Export our shlibpath_var if we have one.
+	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+	  $ECHO "\
+    # Add our own library path to $shlibpath_var
+    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
+
+    # Some systems cannot cope with colon-terminated $shlibpath_var
+    # The second colon is a workaround for a bug in BeOS R4 sed
+    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
+
+    export $shlibpath_var
+"
+	fi
+
+	$ECHO "\
+    if test \"\$libtool_execute_magic\" != \"$magic\"; then
+      # Run the actual program with our arguments.
+      func_exec_program \${1+\"\$@\"}
+    fi
+  else
+    # The program doesn't exist.
+    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
+    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
+    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
+    exit 1
+  fi
+fi\
+"
+}
+
+
+# func_emit_cwrapperexe_src
+# emit the source code for a wrapper executable on stdout
+# Must ONLY be called from within func_mode_link because
+# it depends on a number of variable set therein.
+func_emit_cwrapperexe_src ()
+{
+	cat <<EOF
+
+/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
+   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
+
+   The $output program cannot be directly executed until all the libtool
+   libraries that it depends on are installed.
+
+   This wrapper executable should never be moved out of the build directory.
+   If it is, it will not operate correctly.
+*/
+EOF
+	    cat <<"EOF"
+#ifdef _MSC_VER
+# define _CRT_SECURE_NO_DEPRECATE 1
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef _MSC_VER
+# include <direct.h>
+# include <process.h>
+# include <io.h>
+#else
+# include <unistd.h>
+# include <stdint.h>
+# ifdef __CYGWIN__
+#  include <io.h>
+# endif
+#endif
+#include <malloc.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
+
+/* declarations of non-ANSI functions */
+#if defined __MINGW32__
+# ifdef __STRICT_ANSI__
+int _putenv (const char *);
+# endif
+#elif defined __CYGWIN__
+# ifdef __STRICT_ANSI__
+char *realpath (const char *, char *);
+int putenv (char *);
+int setenv (const char *, const char *, int);
+# endif
+/* #elif defined other_platform || defined ... */
+#endif
+
+/* portability defines, excluding path handling macros */
+#if defined _MSC_VER
+# define setmode _setmode
+# define stat    _stat
+# define chmod   _chmod
+# define getcwd  _getcwd
+# define putenv  _putenv
+# define S_IXUSR _S_IEXEC
+#elif defined __MINGW32__
+# define setmode _setmode
+# define stat    _stat
+# define chmod   _chmod
+# define getcwd  _getcwd
+# define putenv  _putenv
+#elif defined __CYGWIN__
+# define HAVE_SETENV
+# define FOPEN_WB "wb"
+/* #elif defined other platforms ... */
+#endif
+
+#if defined PATH_MAX
+# define LT_PATHMAX PATH_MAX
+#elif defined MAXPATHLEN
+# define LT_PATHMAX MAXPATHLEN
+#else
+# define LT_PATHMAX 1024
+#endif
+
+#ifndef S_IXOTH
+# define S_IXOTH 0
+#endif
+#ifndef S_IXGRP
+# define S_IXGRP 0
+#endif
+
+/* path handling portability macros */
+#ifndef DIR_SEPARATOR
+# define DIR_SEPARATOR '/'
+# define PATH_SEPARATOR ':'
+#endif
+
+#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
+  defined __OS2__
+# define HAVE_DOS_BASED_FILE_SYSTEM
+# define FOPEN_WB "wb"
+# ifndef DIR_SEPARATOR_2
+#  define DIR_SEPARATOR_2 '\\'
+# endif
+# ifndef PATH_SEPARATOR_2
+#  define PATH_SEPARATOR_2 ';'
+# endif
+#endif
+
+#ifndef DIR_SEPARATOR_2
+# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else /* DIR_SEPARATOR_2 */
+# define IS_DIR_SEPARATOR(ch) \
+	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif /* DIR_SEPARATOR_2 */
+
+#ifndef PATH_SEPARATOR_2
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
+#else /* PATH_SEPARATOR_2 */
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
+#endif /* PATH_SEPARATOR_2 */
+
+#ifndef FOPEN_WB
+# define FOPEN_WB "w"
+#endif
+#ifndef _O_BINARY
+# define _O_BINARY 0
+#endif
+
+#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
+#define XFREE(stale) do { \
+  if (stale) { free (stale); stale = 0; } \
+} while (0)
+
+#if defined LT_DEBUGWRAPPER
+static int lt_debug = 1;
+#else
+static int lt_debug = 0;
+#endif
+
+const char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
+
+void *xmalloc (size_t num);
+char *xstrdup (const char *string);
+const char *base_name (const char *name);
+char *find_executable (const char *wrapper);
+char *chase_symlinks (const char *pathspec);
+int make_executable (const char *path);
+int check_executable (const char *path);
+char *strendzap (char *str, const char *pat);
+void lt_debugprintf (const char *file, int line, const char *fmt, ...);
+void lt_fatal (const char *file, int line, const char *message, ...);
+static const char *nonnull (const char *s);
+static const char *nonempty (const char *s);
+void lt_setenv (const char *name, const char *value);
+char *lt_extend_str (const char *orig_value, const char *add, int to_end);
+void lt_update_exe_path (const char *name, const char *value);
+void lt_update_lib_path (const char *name, const char *value);
+char **prepare_spawn (char **argv);
+void lt_dump_script (FILE *f);
+EOF
+
+	    cat <<EOF
+#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
+# define externally_visible volatile
+#else
+# define externally_visible __attribute__((externally_visible)) volatile
+#endif
+externally_visible const char * MAGIC_EXE = "$magic_exe";
+const char * LIB_PATH_VARNAME = "$shlibpath_var";
+EOF
+
+	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+              func_to_host_path "$temp_rpath"
+	      cat <<EOF
+const char * LIB_PATH_VALUE   = "$func_to_host_path_result";
+EOF
+	    else
+	      cat <<"EOF"
+const char * LIB_PATH_VALUE   = "";
+EOF
+	    fi
+
+	    if test -n "$dllsearchpath"; then
+              func_to_host_path "$dllsearchpath:"
+	      cat <<EOF
+const char * EXE_PATH_VARNAME = "PATH";
+const char * EXE_PATH_VALUE   = "$func_to_host_path_result";
+EOF
+	    else
+	      cat <<"EOF"
+const char * EXE_PATH_VARNAME = "";
+const char * EXE_PATH_VALUE   = "";
+EOF
+	    fi
+
+	    if test yes = "$fast_install"; then
+	      cat <<EOF
+const char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
+EOF
+	    else
+	      cat <<EOF
+const char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
+EOF
+	    fi
+
+
+	    cat <<"EOF"
+
+#define LTWRAPPER_OPTION_PREFIX         "--lt-"
+
+static const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
+static const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
+static const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
+
+int
+main (int argc, char *argv[])
+{
+  char **newargz;
+  int  newargc;
+  char *tmp_pathspec;
+  char *actual_cwrapper_path;
+  char *actual_cwrapper_name;
+  char *target_name;
+  char *lt_argv_zero;
+  int rval = 127;
+
+  int i;
+
+  program_name = (char *) xstrdup (base_name (argv[0]));
+  newargz = XMALLOC (char *, (size_t) argc + 1);
+
+  /* very simple arg parsing; don't want to rely on getopt
+   * also, copy all non cwrapper options to newargz, except
+   * argz[0], which is handled differently
+   */
+  newargc=0;
+  for (i = 1; i < argc; i++)
+    {
+      if (STREQ (argv[i], dumpscript_opt))
+	{
+EOF
+	    case $host in
+	      *mingw* | *cygwin* )
+		# make stdout use "unix" line endings
+		echo "          setmode(1,_O_BINARY);"
+		;;
+	      esac
+
+	    cat <<"EOF"
+	  lt_dump_script (stdout);
+	  return 0;
+	}
+      if (STREQ (argv[i], debug_opt))
+	{
+          lt_debug = 1;
+          continue;
+	}
+      if (STREQ (argv[i], ltwrapper_option_prefix))
+        {
+          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
+             namespace, but it is not one of the ones we know about and
+             have already dealt with, above (inluding dump-script), then
+             report an error. Otherwise, targets might begin to believe
+             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
+             namespace. The first time any user complains about this, we'll
+             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
+             or a configure.ac-settable value.
+           */
+          lt_fatal (__FILE__, __LINE__,
+		    "unrecognized %s option: '%s'",
+                    ltwrapper_option_prefix, argv[i]);
+        }
+      /* otherwise ... */
+      newargz[++newargc] = xstrdup (argv[i]);
+    }
+  newargz[++newargc] = NULL;
+
+EOF
+	    cat <<EOF
+  /* The GNU banner must be the first non-error debug message */
+  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
+EOF
+	    cat <<"EOF"
+  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
+  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
+
+  tmp_pathspec = find_executable (argv[0]);
+  if (tmp_pathspec == NULL)
+    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
+  lt_debugprintf (__FILE__, __LINE__,
+                  "(main) found exe (before symlink chase) at: %s\n",
+		  tmp_pathspec);
+
+  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
+  lt_debugprintf (__FILE__, __LINE__,
+                  "(main) found exe (after symlink chase) at: %s\n",
+		  actual_cwrapper_path);
+  XFREE (tmp_pathspec);
+
+  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
+  strendzap (actual_cwrapper_path, actual_cwrapper_name);
+
+  /* wrapper name transforms */
+  strendzap (actual_cwrapper_name, ".exe");
+  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
+  XFREE (actual_cwrapper_name);
+  actual_cwrapper_name = tmp_pathspec;
+  tmp_pathspec = 0;
+
+  /* target_name transforms -- use actual target program name; might have lt- prefix */
+  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
+  strendzap (target_name, ".exe");
+  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
+  XFREE (target_name);
+  target_name = tmp_pathspec;
+  tmp_pathspec = 0;
+
+  lt_debugprintf (__FILE__, __LINE__,
+		  "(main) libtool target name: %s\n",
+		  target_name);
+EOF
+
+	    cat <<EOF
+  newargz[0] =
+    XMALLOC (char, (strlen (actual_cwrapper_path) +
+		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
+  strcpy (newargz[0], actual_cwrapper_path);
+  strcat (newargz[0], "$objdir");
+  strcat (newargz[0], "/");
+EOF
+
+	    cat <<"EOF"
+  /* stop here, and copy so we don't have to do this twice */
+  tmp_pathspec = xstrdup (newargz[0]);
+
+  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
+  strcat (newargz[0], actual_cwrapper_name);
+
+  /* DO want the lt- prefix here if it exists, so use target_name */
+  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
+  XFREE (tmp_pathspec);
+  tmp_pathspec = NULL;
+EOF
+
+	    case $host_os in
+	      mingw*)
+	    cat <<"EOF"
+  {
+    char* p;
+    while ((p = strchr (newargz[0], '\\')) != NULL)
+      {
+	*p = '/';
+      }
+    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
+      {
+	*p = '/';
+      }
+  }
+EOF
+	    ;;
+	    esac
+
+	    cat <<"EOF"
+  XFREE (target_name);
+  XFREE (actual_cwrapper_path);
+  XFREE (actual_cwrapper_name);
+
+  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
+  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
+  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
+     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
+     because on Windows, both *_VARNAMEs are PATH but uninstalled
+     libraries must come first. */
+  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
+  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
+
+  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
+		  nonnull (lt_argv_zero));
+  for (i = 0; i < newargc; i++)
+    {
+      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
+		      i, nonnull (newargz[i]));
+    }
+
+EOF
+
+	    case $host_os in
+	      mingw*)
+		cat <<"EOF"
+  /* execv doesn't actually work on mingw as expected on unix */
+  newargz = prepare_spawn (newargz);
+  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
+  if (rval == -1)
+    {
+      /* failed to start process */
+      lt_debugprintf (__FILE__, __LINE__,
+		      "(main) failed to launch target \"%s\": %s\n",
+		      lt_argv_zero, nonnull (strerror (errno)));
+      return 127;
+    }
+  return rval;
+EOF
+		;;
+	      *)
+		cat <<"EOF"
+  execv (lt_argv_zero, newargz);
+  return rval; /* =127, but avoids unused variable warning */
+EOF
+		;;
+	    esac
+
+	    cat <<"EOF"
+}
+
+void *
+xmalloc (size_t num)
+{
+  void *p = (void *) malloc (num);
+  if (!p)
+    lt_fatal (__FILE__, __LINE__, "memory exhausted");
+
+  return p;
+}
+
+char *
+xstrdup (const char *string)
+{
+  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
+			  string) : NULL;
+}
+
+const char *
+base_name (const char *name)
+{
+  const char *base;
+
+#if defined HAVE_DOS_BASED_FILE_SYSTEM
+  /* Skip over the disk name in MSDOS pathnames. */
+  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
+    name += 2;
+#endif
+
+  for (base = name; *name; name++)
+    if (IS_DIR_SEPARATOR (*name))
+      base = name + 1;
+  return base;
+}
+
+int
+check_executable (const char *path)
+{
+  struct stat st;
+
+  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
+                  nonempty (path));
+  if ((!path) || (!*path))
+    return 0;
+
+  if ((stat (path, &st) >= 0)
+      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+    return 1;
+  else
+    return 0;
+}
+
+int
+make_executable (const char *path)
+{
+  int rval = 0;
+  struct stat st;
+
+  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
+                  nonempty (path));
+  if ((!path) || (!*path))
+    return 0;
+
+  if (stat (path, &st) >= 0)
+    {
+      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
+    }
+  return rval;
+}
+
+/* Searches for the full path of the wrapper.  Returns
+   newly allocated full path name if found, NULL otherwise
+   Does not chase symlinks, even on platforms that support them.
+*/
+char *
+find_executable (const char *wrapper)
+{
+  int has_slash = 0;
+  const char *p;
+  const char *p_next;
+  /* static buffer for getcwd */
+  char tmp[LT_PATHMAX + 1];
+  size_t tmp_len;
+  char *concat_name;
+
+  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
+                  nonempty (wrapper));
+
+  if ((wrapper == NULL) || (*wrapper == '\0'))
+    return NULL;
+
+  /* Absolute path? */
+#if defined HAVE_DOS_BASED_FILE_SYSTEM
+  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
+    {
+      concat_name = xstrdup (wrapper);
+      if (check_executable (concat_name))
+	return concat_name;
+      XFREE (concat_name);
+    }
+  else
+    {
+#endif
+      if (IS_DIR_SEPARATOR (wrapper[0]))
+	{
+	  concat_name = xstrdup (wrapper);
+	  if (check_executable (concat_name))
+	    return concat_name;
+	  XFREE (concat_name);
+	}
+#if defined HAVE_DOS_BASED_FILE_SYSTEM
+    }
+#endif
+
+  for (p = wrapper; *p; p++)
+    if (*p == '/')
+      {
+	has_slash = 1;
+	break;
+      }
+  if (!has_slash)
+    {
+      /* no slashes; search PATH */
+      const char *path = getenv ("PATH");
+      if (path != NULL)
+	{
+	  for (p = path; *p; p = p_next)
+	    {
+	      const char *q;
+	      size_t p_len;
+	      for (q = p; *q; q++)
+		if (IS_PATH_SEPARATOR (*q))
+		  break;
+	      p_len = (size_t) (q - p);
+	      p_next = (*q == '\0' ? q : q + 1);
+	      if (p_len == 0)
+		{
+		  /* empty path: current directory */
+		  if (getcwd (tmp, LT_PATHMAX) == NULL)
+		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
+                              nonnull (strerror (errno)));
+		  tmp_len = strlen (tmp);
+		  concat_name =
+		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
+		  memcpy (concat_name, tmp, tmp_len);
+		  concat_name[tmp_len] = '/';
+		  strcpy (concat_name + tmp_len + 1, wrapper);
+		}
+	      else
+		{
+		  concat_name =
+		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
+		  memcpy (concat_name, p, p_len);
+		  concat_name[p_len] = '/';
+		  strcpy (concat_name + p_len + 1, wrapper);
+		}
+	      if (check_executable (concat_name))
+		return concat_name;
+	      XFREE (concat_name);
+	    }
+	}
+      /* not found in PATH; assume curdir */
+    }
+  /* Relative path | not found in path: prepend cwd */
+  if (getcwd (tmp, LT_PATHMAX) == NULL)
+    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
+              nonnull (strerror (errno)));
+  tmp_len = strlen (tmp);
+  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
+  memcpy (concat_name, tmp, tmp_len);
+  concat_name[tmp_len] = '/';
+  strcpy (concat_name + tmp_len + 1, wrapper);
+
+  if (check_executable (concat_name))
+    return concat_name;
+  XFREE (concat_name);
+  return NULL;
+}
+
+char *
+chase_symlinks (const char *pathspec)
+{
+#ifndef S_ISLNK
+  return xstrdup (pathspec);
+#else
+  char buf[LT_PATHMAX];
+  struct stat s;
+  char *tmp_pathspec = xstrdup (pathspec);
+  char *p;
+  int has_symlinks = 0;
+  while (strlen (tmp_pathspec) && !has_symlinks)
+    {
+      lt_debugprintf (__FILE__, __LINE__,
+		      "checking path component for symlinks: %s\n",
+		      tmp_pathspec);
+      if (lstat (tmp_pathspec, &s) == 0)
+	{
+	  if (S_ISLNK (s.st_mode) != 0)
+	    {
+	      has_symlinks = 1;
+	      break;
+	    }
+
+	  /* search backwards for last DIR_SEPARATOR */
+	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
+	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
+	    p--;
+	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
+	    {
+	      /* no more DIR_SEPARATORS left */
+	      break;
+	    }
+	  *p = '\0';
+	}
+      else
+	{
+	  lt_fatal (__FILE__, __LINE__,
+		    "error accessing file \"%s\": %s",
+		    tmp_pathspec, nonnull (strerror (errno)));
+	}
+    }
+  XFREE (tmp_pathspec);
+
+  if (!has_symlinks)
+    {
+      return xstrdup (pathspec);
+    }
+
+  tmp_pathspec = realpath (pathspec, buf);
+  if (tmp_pathspec == 0)
+    {
+      lt_fatal (__FILE__, __LINE__,
+		"could not follow symlinks for %s", pathspec);
+    }
+  return xstrdup (tmp_pathspec);
+#endif
+}
+
+char *
+strendzap (char *str, const char *pat)
+{
+  size_t len, patlen;
+
+  assert (str != NULL);
+  assert (pat != NULL);
+
+  len = strlen (str);
+  patlen = strlen (pat);
+
+  if (patlen <= len)
+    {
+      str += len - patlen;
+      if (STREQ (str, pat))
+	*str = '\0';
+    }
+  return str;
+}
+
+void
+lt_debugprintf (const char *file, int line, const char *fmt, ...)
+{
+  va_list args;
+  if (lt_debug)
+    {
+      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
+      va_start (args, fmt);
+      (void) vfprintf (stderr, fmt, args);
+      va_end (args);
+    }
+}
+
+static void
+lt_error_core (int exit_status, const char *file,
+	       int line, const char *mode,
+	       const char *message, va_list ap)
+{
+  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
+  vfprintf (stderr, message, ap);
+  fprintf (stderr, ".\n");
+
+  if (exit_status >= 0)
+    exit (exit_status);
+}
+
+void
+lt_fatal (const char *file, int line, const char *message, ...)
+{
+  va_list ap;
+  va_start (ap, message);
+  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
+  va_end (ap);
+}
+
+static const char *
+nonnull (const char *s)
+{
+  return s ? s : "(null)";
+}
+
+static const char *
+nonempty (const char *s)
+{
+  return (s && !*s) ? "(empty)" : nonnull (s);
+}
+
+void
+lt_setenv (const char *name, const char *value)
+{
+  lt_debugprintf (__FILE__, __LINE__,
+		  "(lt_setenv) setting '%s' to '%s'\n",
+                  nonnull (name), nonnull (value));
+  {
+#ifdef HAVE_SETENV
+    /* always make a copy, for consistency with !HAVE_SETENV */
+    char *str = xstrdup (value);
+    setenv (name, str, 1);
+#else
+    size_t len = strlen (name) + 1 + strlen (value) + 1;
+    char *str = XMALLOC (char, len);
+    sprintf (str, "%s=%s", name, value);
+    if (putenv (str) != EXIT_SUCCESS)
+      {
+        XFREE (str);
+      }
+#endif
+  }
+}
+
+char *
+lt_extend_str (const char *orig_value, const char *add, int to_end)
+{
+  char *new_value;
+  if (orig_value && *orig_value)
+    {
+      size_t orig_value_len = strlen (orig_value);
+      size_t add_len = strlen (add);
+      new_value = XMALLOC (char, add_len + orig_value_len + 1);
+      if (to_end)
+        {
+          strcpy (new_value, orig_value);
+          strcpy (new_value + orig_value_len, add);
+        }
+      else
+        {
+          strcpy (new_value, add);
+          strcpy (new_value + add_len, orig_value);
+        }
+    }
+  else
+    {
+      new_value = xstrdup (add);
+    }
+  return new_value;
+}
+
+void
+lt_update_exe_path (const char *name, const char *value)
+{
+  lt_debugprintf (__FILE__, __LINE__,
+		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
+                  nonnull (name), nonnull (value));
+
+  if (name && *name && value && *value)
+    {
+      char *new_value = lt_extend_str (getenv (name), value, 0);
+      /* some systems can't cope with a ':'-terminated path #' */
+      size_t len = strlen (new_value);
+      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
+        {
+          new_value[--len] = '\0';
+        }
+      lt_setenv (name, new_value);
+      XFREE (new_value);
+    }
+}
+
+void
+lt_update_lib_path (const char *name, const char *value)
+{
+  lt_debugprintf (__FILE__, __LINE__,
+		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
+                  nonnull (name), nonnull (value));
+
+  if (name && *name && value && *value)
+    {
+      char *new_value = lt_extend_str (getenv (name), value, 0);
+      lt_setenv (name, new_value);
+      XFREE (new_value);
+    }
+}
+
+EOF
+	    case $host_os in
+	      mingw*)
+		cat <<"EOF"
+
+/* Prepares an argument vector before calling spawn().
+   Note that spawn() does not by itself call the command interpreter
+     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
+      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+         GetVersionEx(&v);
+         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
+      }) ? "cmd.exe" : "command.com").
+   Instead it simply concatenates the arguments, separated by ' ', and calls
+   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
+   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
+   special way:
+   - Space and tab are interpreted as delimiters. They are not treated as
+     delimiters if they are surrounded by double quotes: "...".
+   - Unescaped double quotes are removed from the input. Their only effect is
+     that within double quotes, space and tab are treated like normal
+     characters.
+   - Backslashes not followed by double quotes are not special.
+   - But 2*n+1 backslashes followed by a double quote become
+     n backslashes followed by a double quote (n >= 0):
+       \" -> "
+       \\\" -> \"
+       \\\\\" -> \\"
+ */
+#define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
+#define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
+char **
+prepare_spawn (char **argv)
+{
+  size_t argc;
+  char **new_argv;
+  size_t i;
+
+  /* Count number of arguments.  */
+  for (argc = 0; argv[argc] != NULL; argc++)
+    ;
+
+  /* Allocate new argument vector.  */
+  new_argv = XMALLOC (char *, argc + 1);
+
+  /* Put quoted arguments into the new argument vector.  */
+  for (i = 0; i < argc; i++)
+    {
+      const char *string = argv[i];
+
+      if (string[0] == '\0')
+	new_argv[i] = xstrdup ("\"\"");
+      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
+	{
+	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
+	  size_t length;
+	  unsigned int backslashes;
+	  const char *s;
+	  char *quoted_string;
+	  char *p;
+
+	  length = 0;
+	  backslashes = 0;
+	  if (quote_around)
+	    length++;
+	  for (s = string; *s != '\0'; s++)
+	    {
+	      char c = *s;
+	      if (c == '"')
+		length += backslashes + 1;
+	      length++;
+	      if (c == '\\')
+		backslashes++;
+	      else
+		backslashes = 0;
+	    }
+	  if (quote_around)
+	    length += backslashes + 1;
+
+	  quoted_string = XMALLOC (char, length + 1);
+
+	  p = quoted_string;
+	  backslashes = 0;
+	  if (quote_around)
+	    *p++ = '"';
+	  for (s = string; *s != '\0'; s++)
+	    {
+	      char c = *s;
+	      if (c == '"')
+		{
+		  unsigned int j;
+		  for (j = backslashes + 1; j > 0; j--)
+		    *p++ = '\\';
+		}
+	      *p++ = c;
+	      if (c == '\\')
+		backslashes++;
+	      else
+		backslashes = 0;
+	    }
+	  if (quote_around)
+	    {
+	      unsigned int j;
+	      for (j = backslashes; j > 0; j--)
+		*p++ = '\\';
+	      *p++ = '"';
+	    }
+	  *p = '\0';
+
+	  new_argv[i] = quoted_string;
+	}
+      else
+	new_argv[i] = (char *) string;
+    }
+  new_argv[argc] = NULL;
+
+  return new_argv;
+}
+EOF
+		;;
+	    esac
+
+            cat <<"EOF"
+void lt_dump_script (FILE* f)
+{
+EOF
+	    func_emit_wrapper yes |
+	      $SED -n -e '
+s/^\(.\{79\}\)\(..*\)/\1\
+\2/
+h
+s/\([\\"]\)/\\\1/g
+s/$/\\n/
+s/\([^\n]*\).*/  fputs ("\1", f);/p
+g
+D'
+            cat <<"EOF"
+}
+EOF
+}
+# end: func_emit_cwrapperexe_src
+
+# func_win32_import_lib_p ARG
+# True if ARG is an import lib, as indicated by $file_magic_cmd
+func_win32_import_lib_p ()
+{
+    $debug_cmd
+
+    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
+    *import*) : ;;
+    *) false ;;
+    esac
+}
+
+# func_suncc_cstd_abi
+# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
+# Several compiler flags select an ABI that is incompatible with the
+# Cstd library. Avoid specifying it if any are in CXXFLAGS.
+func_suncc_cstd_abi ()
+{
+    $debug_cmd
+
+    case " $compile_command " in
+    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
+      suncc_use_cstd_abi=no
+      ;;
+    *)
+      suncc_use_cstd_abi=yes
+      ;;
+    esac
+}
+
+# func_mode_link arg...
+func_mode_link ()
+{
+    $debug_cmd
+
+    case $host in
+    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+      # It is impossible to link a dll without this setting, and
+      # we shouldn't force the makefile maintainer to figure out
+      # what system we are compiling for in order to pass an extra
+      # flag for every libtool invocation.
+      # allow_undefined=no
+
+      # FIXME: Unfortunately, there are problems with the above when trying
+      # to make a dll that has undefined symbols, in which case not
+      # even a static library is built.  For now, we need to specify
+      # -no-undefined on the libtool link line when we can be certain
+      # that all symbols are satisfied, otherwise we get a static library.
+      allow_undefined=yes
+      ;;
+    *)
+      allow_undefined=yes
+      ;;
+    esac
+    libtool_args=$nonopt
+    base_compile="$nonopt $@"
+    compile_command=$nonopt
+    finalize_command=$nonopt
+
+    compile_rpath=
+    finalize_rpath=
+    compile_shlibpath=
+    finalize_shlibpath=
+    convenience=
+    old_convenience=
+    deplibs=
+    old_deplibs=
+    compiler_flags=
+    linker_flags=
+    dllsearchpath=
+    lib_search_path=`pwd`
+    inst_prefix_dir=
+    new_inherited_linker_flags=
+
+    avoid_version=no
+    bindir=
+    dlfiles=
+    dlprefiles=
+    dlself=no
+    export_dynamic=no
+    export_symbols=
+    export_symbols_regex=
+    generated=
+    libobjs=
+    ltlibs=
+    module=no
+    no_install=no
+    objs=
+    os2dllname=
+    non_pic_objects=
+    precious_files_regex=
+    prefer_static_libs=no
+    preload=false
+    prev=
+    prevarg=
+    release=
+    rpath=
+    xrpath=
+    perm_rpath=
+    temp_rpath=
+    thread_safe=no
+    vinfo=
+    vinfo_number=no
+    weak_libs=
+    single_module=$wl-single_module
+    func_infer_tag $base_compile
+
+    # We need to know -static, to get the right output filenames.
+    for arg
+    do
+      case $arg in
+      -shared)
+	test yes != "$build_libtool_libs" \
+	  && func_fatal_configuration "cannot build a shared library"
+	build_old_libs=no
+	break
+	;;
+      -all-static | -static | -static-libtool-libs)
+	case $arg in
+	-all-static)
+	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
+	    func_warning "complete static linking is impossible in this configuration"
+	  fi
+	  if test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=yes
+	  ;;
+	-static)
+	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=built
+	  ;;
+	-static-libtool-libs)
+	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=yes
+	  ;;
+	esac
+	build_libtool_libs=no
+	build_old_libs=yes
+	break
+	;;
+      esac
+    done
+
+    # See if our shared archives depend on static archives.
+    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
+
+    # Go through the arguments, transforming them on the way.
+    while test "$#" -gt 0; do
+      arg=$1
+      shift
+      func_quote_for_eval "$arg"
+      qarg=$func_quote_for_eval_unquoted_result
+      func_append libtool_args " $func_quote_for_eval_result"
+
+      # If the previous option needs an argument, assign it.
+      if test -n "$prev"; then
+	case $prev in
+	output)
+	  func_append compile_command " @OUTPUT@"
+	  func_append finalize_command " @OUTPUT@"
+	  ;;
+	esac
+
+	case $prev in
+	bindir)
+	  bindir=$arg
+	  prev=
+	  continue
+	  ;;
+	dlfiles|dlprefiles)
+	  $preload || {
+	    # Add the symbol object into the linking commands.
+	    func_append compile_command " @SYMFILE@"
+	    func_append finalize_command " @SYMFILE@"
+	    preload=:
+	  }
+	  case $arg in
+	  *.la | *.lo) ;;  # We handle these cases below.
+	  force)
+	    if test no = "$dlself"; then
+	      dlself=needless
+	      export_dynamic=yes
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  self)
+	    if test dlprefiles = "$prev"; then
+	      dlself=yes
+	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
+	      dlself=yes
+	    else
+	      dlself=needless
+	      export_dynamic=yes
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  *)
+	    if test dlfiles = "$prev"; then
+	      func_append dlfiles " $arg"
+	    else
+	      func_append dlprefiles " $arg"
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  esac
+	  ;;
+	expsyms)
+	  export_symbols=$arg
+	  test -f "$arg" \
+	    || func_fatal_error "symbol file '$arg' does not exist"
+	  prev=
+	  continue
+	  ;;
+	expsyms_regex)
+	  export_symbols_regex=$arg
+	  prev=
+	  continue
+	  ;;
+	framework)
+	  case $host in
+	    *-*-darwin*)
+	      case "$deplibs " in
+		*" $qarg.ltframework "*) ;;
+		*) func_append deplibs " $qarg.ltframework" # this is fixed later
+		   ;;
+	      esac
+	      ;;
+	  esac
+	  prev=
+	  continue
+	  ;;
+	inst_prefix)
+	  inst_prefix_dir=$arg
+	  prev=
+	  continue
+	  ;;
+	mllvm)
+	  # Clang does not use LLVM to link, so we can simply discard any
+	  # '-mllvm $arg' options when doing the link step.
+	  prev=
+	  continue
+	  ;;
+	objectlist)
+	  if test -f "$arg"; then
+	    save_arg=$arg
+	    moreargs=
+	    for fil in `cat "$save_arg"`
+	    do
+#	      func_append moreargs " $fil"
+	      arg=$fil
+	      # A libtool-controlled object.
+
+	      # Check to see that this really is a libtool object.
+	      if func_lalib_unsafe_p "$arg"; then
+		pic_object=
+		non_pic_object=
+
+		# Read the .lo file
+		func_source "$arg"
+
+		if test -z "$pic_object" ||
+		   test -z "$non_pic_object" ||
+		   test none = "$pic_object" &&
+		   test none = "$non_pic_object"; then
+		  func_fatal_error "cannot find name of object for '$arg'"
+		fi
+
+		# Extract subdirectory from the argument.
+		func_dirname "$arg" "/" ""
+		xdir=$func_dirname_result
+
+		if test none != "$pic_object"; then
+		  # Prepend the subdirectory the object is found in.
+		  pic_object=$xdir$pic_object
+
+		  if test dlfiles = "$prev"; then
+		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
+		      func_append dlfiles " $pic_object"
+		      prev=
+		      continue
+		    else
+		      # If libtool objects are unsupported, then we need to preload.
+		      prev=dlprefiles
+		    fi
+		  fi
+
+		  # CHECK ME:  I think I busted this.  -Ossama
+		  if test dlprefiles = "$prev"; then
+		    # Preload the old-style object.
+		    func_append dlprefiles " $pic_object"
+		    prev=
+		  fi
+
+		  # A PIC object.
+		  func_append libobjs " $pic_object"
+		  arg=$pic_object
+		fi
+
+		# Non-PIC object.
+		if test none != "$non_pic_object"; then
+		  # Prepend the subdirectory the object is found in.
+		  non_pic_object=$xdir$non_pic_object
+
+		  # A standard non-PIC object
+		  func_append non_pic_objects " $non_pic_object"
+		  if test -z "$pic_object" || test none = "$pic_object"; then
+		    arg=$non_pic_object
+		  fi
+		else
+		  # If the PIC object exists, use it instead.
+		  # $xdir was prepended to $pic_object above.
+		  non_pic_object=$pic_object
+		  func_append non_pic_objects " $non_pic_object"
+		fi
+	      else
+		# Only an error if not doing a dry-run.
+		if $opt_dry_run; then
+		  # Extract subdirectory from the argument.
+		  func_dirname "$arg" "/" ""
+		  xdir=$func_dirname_result
+
+		  func_lo2o "$arg"
+		  pic_object=$xdir$objdir/$func_lo2o_result
+		  non_pic_object=$xdir$func_lo2o_result
+		  func_append libobjs " $pic_object"
+		  func_append non_pic_objects " $non_pic_object"
+	        else
+		  func_fatal_error "'$arg' is not a valid libtool object"
+		fi
+	      fi
+	    done
+	  else
+	    func_fatal_error "link input file '$arg' does not exist"
+	  fi
+	  arg=$save_arg
+	  prev=
+	  continue
+	  ;;
+	os2dllname)
+	  os2dllname=$arg
+	  prev=
+	  continue
+	  ;;
+	precious_regex)
+	  precious_files_regex=$arg
+	  prev=
+	  continue
+	  ;;
+	release)
+	  release=-$arg
+	  prev=
+	  continue
+	  ;;
+	rpath | xrpath)
+	  # We need an absolute path.
+	  case $arg in
+	  [\\/]* | [A-Za-z]:[\\/]*) ;;
+	  *)
+	    func_fatal_error "only absolute run-paths are allowed"
+	    ;;
+	  esac
+	  if test rpath = "$prev"; then
+	    case "$rpath " in
+	    *" $arg "*) ;;
+	    *) func_append rpath " $arg" ;;
+	    esac
+	  else
+	    case "$xrpath " in
+	    *" $arg "*) ;;
+	    *) func_append xrpath " $arg" ;;
+	    esac
+	  fi
+	  prev=
+	  continue
+	  ;;
+	shrext)
+	  shrext_cmds=$arg
+	  prev=
+	  continue
+	  ;;
+	weak)
+	  func_append weak_libs " $arg"
+	  prev=
+	  continue
+	  ;;
+	xcclinker)
+	  func_append linker_flags " $qarg"
+	  func_append compiler_flags " $qarg"
+	  prev=
+	  func_append compile_command " $qarg"
+	  func_append finalize_command " $qarg"
+	  continue
+	  ;;
+	xcompiler)
+	  func_append compiler_flags " $qarg"
+	  prev=
+	  func_append compile_command " $qarg"
+	  func_append finalize_command " $qarg"
+	  continue
+	  ;;
+	xlinker)
+	  func_append linker_flags " $qarg"
+	  func_append compiler_flags " $wl$qarg"
+	  prev=
+	  func_append compile_command " $wl$qarg"
+	  func_append finalize_command " $wl$qarg"
+	  continue
+	  ;;
+	*)
+	  eval "$prev=\"\$arg\""
+	  prev=
+	  continue
+	  ;;
+	esac
+      fi # test -n "$prev"
+
+      prevarg=$arg
+
+      case $arg in
+      -all-static)
+	if test -n "$link_static_flag"; then
+	  # See comment for -static flag below, for more details.
+	  func_append compile_command " $link_static_flag"
+	  func_append finalize_command " $link_static_flag"
+	fi
+	continue
+	;;
+
+      -allow-undefined)
+	# FIXME: remove this flag sometime in the future.
+	func_fatal_error "'-allow-undefined' must not be used because it is the default"
+	;;
+
+      -avoid-version)
+	avoid_version=yes
+	continue
+	;;
+
+      -bindir)
+	prev=bindir
+	continue
+	;;
+
+      -dlopen)
+	prev=dlfiles
+	continue
+	;;
+
+      -dlpreopen)
+	prev=dlprefiles
+	continue
+	;;
+
+      -export-dynamic)
+	export_dynamic=yes
+	continue
+	;;
+
+      -export-symbols | -export-symbols-regex)
+	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
+	  func_fatal_error "more than one -exported-symbols argument is not allowed"
+	fi
+	if test X-export-symbols = "X$arg"; then
+	  prev=expsyms
+	else
+	  prev=expsyms_regex
+	fi
+	continue
+	;;
+
+      -framework)
+	prev=framework
+	continue
+	;;
+
+      -inst-prefix-dir)
+	prev=inst_prefix
+	continue
+	;;
+
+      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
+      # so, if we see these flags be careful not to treat them like -L
+      -L[A-Z][A-Z]*:*)
+	case $with_gcc/$host in
+	no/*-*-irix* | /*-*-irix*)
+	  func_append compile_command " $arg"
+	  func_append finalize_command " $arg"
+	  ;;
+	esac
+	continue
+	;;
+
+      -L*)
+	func_stripname "-L" '' "$arg"
+	if test -z "$func_stripname_result"; then
+	  if test "$#" -gt 0; then
+	    func_fatal_error "require no space between '-L' and '$1'"
+	  else
+	    func_fatal_error "need path for '-L' option"
+	  fi
+	fi
+	func_resolve_sysroot "$func_stripname_result"
+	dir=$func_resolve_sysroot_result
+	# We need an absolute path.
+	case $dir in
+	[\\/]* | [A-Za-z]:[\\/]*) ;;
+	*)
+	  absdir=`cd "$dir" && pwd`
+	  test -z "$absdir" && \
+	    func_fatal_error "cannot determine absolute directory name of '$dir'"
+	  dir=$absdir
+	  ;;
+	esac
+	case "$deplibs " in
+	*" -L$dir "* | *" $arg "*)
+	  # Will only happen for absolute or sysroot arguments
+	  ;;
+	*)
+	  # Preserve sysroot, but never include relative directories
+	  case $dir in
+	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
+	    *) func_append deplibs " -L$dir" ;;
+	  esac
+	  func_append lib_search_path " $dir"
+	  ;;
+	esac
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
+	  case :$dllsearchpath: in
+	  *":$dir:"*) ;;
+	  ::) dllsearchpath=$dir;;
+	  *) func_append dllsearchpath ":$dir";;
+	  esac
+	  case :$dllsearchpath: in
+	  *":$testbindir:"*) ;;
+	  ::) dllsearchpath=$testbindir;;
+	  *) func_append dllsearchpath ":$testbindir";;
+	  esac
+	  ;;
+	esac
+	continue
+	;;
+
+      -l*)
+	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
+	  case $host in
+	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
+	    # These systems don't actually have a C or math library (as such)
+	    continue
+	    ;;
+	  *-*-os2*)
+	    # These systems don't actually have a C library (as such)
+	    test X-lc = "X$arg" && continue
+	    ;;
+	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
+	    # Do not include libc due to us having libc/libc_r.
+	    test X-lc = "X$arg" && continue
+	    ;;
+	  *-*-rhapsody* | *-*-darwin1.[012])
+	    # Rhapsody C and math libraries are in the System framework
+	    func_append deplibs " System.ltframework"
+	    continue
+	    ;;
+	  *-*-sco3.2v5* | *-*-sco5v6*)
+	    # Causes problems with __ctype
+	    test X-lc = "X$arg" && continue
+	    ;;
+	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+	    # Compiler inserts libc in the correct place for threads to work
+	    test X-lc = "X$arg" && continue
+	    ;;
+	  esac
+	elif test X-lc_r = "X$arg"; then
+	 case $host in
+	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
+	   # Do not include libc_r directly, use -pthread flag.
+	   continue
+	   ;;
+	 esac
+	fi
+	func_append deplibs " $arg"
+	continue
+	;;
+
+      -mllvm)
+	prev=mllvm
+	continue
+	;;
+
+      -module)
+	module=yes
+	continue
+	;;
+
+      # Tru64 UNIX uses -model [arg] to determine the layout of C++
+      # classes, name mangling, and exception handling.
+      # Darwin uses the -arch flag to determine output architecture.
+      -model|-arch|-isysroot|--sysroot)
+	func_append compiler_flags " $arg"
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+	prev=xcompiler
+	continue
+	;;
+
+      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
+      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
+	func_append compiler_flags " $arg"
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+	case "$new_inherited_linker_flags " in
+	    *" $arg "*) ;;
+	    * ) func_append new_inherited_linker_flags " $arg" ;;
+	esac
+
+	# As we are forced to pass -nostdlib to g++ during linking, the option
+	# -pthread{,s} is not in effect;  add the -lpthread to $deplist
+	# explicitly to link correctly.
+	if test "$tagname" = CXX -a x"$with_gcc" = xyes; then
+	  case "$arg" in
+	    -pthread*) func_append deplibs " -lpthread" ;;
+	  esac
+	fi
+
+	continue
+	;;
+
+      -multi_module)
+	single_module=$wl-multi_module
+	continue
+	;;
+
+      -no-fast-install)
+	fast_install=no
+	continue
+	;;
+
+      -no-install)
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
+	  # The PATH hackery in wrapper scripts is required on Windows
+	  # and Darwin in order for the loader to find any dlls it needs.
+	  func_warning "'-no-install' is ignored for $host"
+	  func_warning "assuming '-no-fast-install' instead"
+	  fast_install=no
+	  ;;
+	*) no_install=yes ;;
+	esac
+	continue
+	;;
+
+      -no-undefined)
+	allow_undefined=no
+	continue
+	;;
+
+      -objectlist)
+	prev=objectlist
+	continue
+	;;
+
+      -os2dllname)
+	prev=os2dllname
+	continue
+	;;
+
+      -o) prev=output ;;
+
+      -precious-files-regex)
+	prev=precious_regex
+	continue
+	;;
+
+      -release)
+	prev=release
+	continue
+	;;
+
+      -rpath)
+	prev=rpath
+	continue
+	;;
+
+      -R)
+	prev=xrpath
+	continue
+	;;
+
+      -R*)
+	func_stripname '-R' '' "$arg"
+	dir=$func_stripname_result
+	# We need an absolute path.
+	case $dir in
+	[\\/]* | [A-Za-z]:[\\/]*) ;;
+	=*)
+	  func_stripname '=' '' "$dir"
+	  dir=$lt_sysroot$func_stripname_result
+	  ;;
+	*)
+	  func_fatal_error "only absolute run-paths are allowed"
+	  ;;
+	esac
+	case "$xrpath " in
+	*" $dir "*) ;;
+	*) func_append xrpath " $dir" ;;
+	esac
+	continue
+	;;
+
+      -shared)
+	# The effects of -shared are defined in a previous loop.
+	continue
+	;;
+
+      -shrext)
+	prev=shrext
+	continue
+	;;
+
+      -static | -static-libtool-libs)
+	# The effects of -static are defined in a previous loop.
+	# We used to do the same as -all-static on platforms that
+	# didn't have a PIC flag, but the assumption that the effects
+	# would be equivalent was wrong.  It would break on at least
+	# Digital Unix and AIX.
+	continue
+	;;
+
+      -thread-safe)
+	thread_safe=yes
+	continue
+	;;
+
+      -version-info)
+	prev=vinfo
+	continue
+	;;
+
+      -version-number)
+	prev=vinfo
+	vinfo_number=yes
+	continue
+	;;
+
+      -weak)
+        prev=weak
+	continue
+	;;
+
+      -Wc,*)
+	func_stripname '-Wc,' '' "$arg"
+	args=$func_stripname_result
+	arg=
+	save_ifs=$IFS; IFS=,
+	for flag in $args; do
+	  IFS=$save_ifs
+          func_quote_for_eval "$flag"
+	  func_append arg " $func_quote_for_eval_result"
+	  func_append compiler_flags " $func_quote_for_eval_result"
+	done
+	IFS=$save_ifs
+	func_stripname ' ' '' "$arg"
+	arg=$func_stripname_result
+	;;
+
+      -Wl,*)
+	func_stripname '-Wl,' '' "$arg"
+	args=$func_stripname_result
+	arg=
+	save_ifs=$IFS; IFS=,
+	for flag in $args; do
+	  IFS=$save_ifs
+          func_quote_for_eval "$flag"
+	  func_append arg " $wl$func_quote_for_eval_result"
+	  func_append compiler_flags " $wl$func_quote_for_eval_result"
+	  func_append linker_flags " $func_quote_for_eval_result"
+	done
+	IFS=$save_ifs
+	func_stripname ' ' '' "$arg"
+	arg=$func_stripname_result
+	;;
+
+      -Xcompiler)
+	prev=xcompiler
+	continue
+	;;
+
+      -Xlinker)
+	prev=xlinker
+	continue
+	;;
+
+      -XCClinker)
+	prev=xcclinker
+	continue
+	;;
+
+      # -msg_* for osf cc
+      -msg_*)
+	func_quote_for_eval "$arg"
+	arg=$func_quote_for_eval_result
+	;;
+
+      # Flags to be passed through unchanged, with rationale:
+      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
+      # -r[0-9][0-9]*        specify processor for the SGI compiler
+      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
+      # +DA*, +DD*           enable 64-bit mode for the HP compiler
+      # -q*                  compiler args for the IBM compiler
+      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
+      # -F/path              path to uninstalled frameworks, gcc on darwin
+      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
+      # -fstack-protector*   stack protector flags for GCC
+      # @file                GCC response files
+      # -tp=*                Portland pgcc target processor selection
+      # --sysroot=*          for sysroot support
+      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
+      # -specs=*             GCC specs files
+      # -stdlib=*            select c++ std lib with clang
+      # -fsanitize=*         Clang/GCC memory and address sanitizer
+      # -fuse-ld=*           Linker select flags for GCC
+      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
+      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
+      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
+      -specs=*|-fsanitize=*|-fuse-ld=*)
+        func_quote_for_eval "$arg"
+	arg=$func_quote_for_eval_result
+        func_append compile_command " $arg"
+        func_append finalize_command " $arg"
+        func_append compiler_flags " $arg"
+        continue
+        ;;
+
+      -Z*)
+        if test os2 = "`expr $host : '.*\(os2\)'`"; then
+          # OS/2 uses -Zxxx to specify OS/2-specific options
+	  compiler_flags="$compiler_flags $arg"
+	  func_append compile_command " $arg"
+	  func_append finalize_command " $arg"
+	  case $arg in
+	  -Zlinker | -Zstack)
+	    prev=xcompiler
+	    ;;
+	  esac
+	  continue
+        else
+	  # Otherwise treat like 'Some other compiler flag' below
+	  func_quote_for_eval "$arg"
+	  arg=$func_quote_for_eval_result
+        fi
+	;;
+
+      # Some other compiler flag.
+      -* | +*)
+        func_quote_for_eval "$arg"
+	arg=$func_quote_for_eval_result
+	;;
+
+      *.$objext)
+	# A standard object.
+	func_append objs " $arg"
+	;;
+
+      *.lo)
+	# A libtool-controlled object.
+
+	# Check to see that this really is a libtool object.
+	if func_lalib_unsafe_p "$arg"; then
+	  pic_object=
+	  non_pic_object=
+
+	  # Read the .lo file
+	  func_source "$arg"
+
+	  if test -z "$pic_object" ||
+	     test -z "$non_pic_object" ||
+	     test none = "$pic_object" &&
+	     test none = "$non_pic_object"; then
+	    func_fatal_error "cannot find name of object for '$arg'"
+	  fi
+
+	  # Extract subdirectory from the argument.
+	  func_dirname "$arg" "/" ""
+	  xdir=$func_dirname_result
+
+	  test none = "$pic_object" || {
+	    # Prepend the subdirectory the object is found in.
+	    pic_object=$xdir$pic_object
+
+	    if test dlfiles = "$prev"; then
+	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
+		func_append dlfiles " $pic_object"
+		prev=
+		continue
+	      else
+		# If libtool objects are unsupported, then we need to preload.
+		prev=dlprefiles
+	      fi
+	    fi
+
+	    # CHECK ME:  I think I busted this.  -Ossama
+	    if test dlprefiles = "$prev"; then
+	      # Preload the old-style object.
+	      func_append dlprefiles " $pic_object"
+	      prev=
+	    fi
+
+	    # A PIC object.
+	    func_append libobjs " $pic_object"
+	    arg=$pic_object
+	  }
+
+	  # Non-PIC object.
+	  if test none != "$non_pic_object"; then
+	    # Prepend the subdirectory the object is found in.
+	    non_pic_object=$xdir$non_pic_object
+
+	    # A standard non-PIC object
+	    func_append non_pic_objects " $non_pic_object"
+	    if test -z "$pic_object" || test none = "$pic_object"; then
+	      arg=$non_pic_object
+	    fi
+	  else
+	    # If the PIC object exists, use it instead.
+	    # $xdir was prepended to $pic_object above.
+	    non_pic_object=$pic_object
+	    func_append non_pic_objects " $non_pic_object"
+	  fi
+	else
+	  # Only an error if not doing a dry-run.
+	  if $opt_dry_run; then
+	    # Extract subdirectory from the argument.
+	    func_dirname "$arg" "/" ""
+	    xdir=$func_dirname_result
+
+	    func_lo2o "$arg"
+	    pic_object=$xdir$objdir/$func_lo2o_result
+	    non_pic_object=$xdir$func_lo2o_result
+	    func_append libobjs " $pic_object"
+	    func_append non_pic_objects " $non_pic_object"
+	  else
+	    func_fatal_error "'$arg' is not a valid libtool object"
+	  fi
+	fi
+	;;
+
+      *.$libext)
+	# An archive.
+	func_append deplibs " $arg"
+	func_append old_deplibs " $arg"
+	continue
+	;;
+
+      *.la)
+	# A libtool-controlled library.
+
+	func_resolve_sysroot "$arg"
+	if test dlfiles = "$prev"; then
+	  # This library was specified with -dlopen.
+	  func_append dlfiles " $func_resolve_sysroot_result"
+	  prev=
+	elif test dlprefiles = "$prev"; then
+	  # The library was specified with -dlpreopen.
+	  func_append dlprefiles " $func_resolve_sysroot_result"
+	  prev=
+	else
+	  func_append deplibs " $func_resolve_sysroot_result"
+	fi
+	continue
+	;;
+
+      # Some other compiler argument.
+      *)
+	# Unknown arguments in both finalize_command and compile_command need
+	# to be aesthetically quoted because they are evaled later.
+	func_quote_for_eval "$arg"
+	arg=$func_quote_for_eval_result
+	;;
+      esac # arg
+
+      # Now actually substitute the argument into the commands.
+      if test -n "$arg"; then
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+      fi
+    done # argument parsing loop
+
+    test -n "$prev" && \
+      func_fatal_help "the '$prevarg' option requires an argument"
+
+    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
+      eval arg=\"$export_dynamic_flag_spec\"
+      func_append compile_command " $arg"
+      func_append finalize_command " $arg"
+    fi
+
+    oldlibs=
+    # calculate the name of the file, without its directory
+    func_basename "$output"
+    outputname=$func_basename_result
+    libobjs_save=$libobjs
+
+    if test -n "$shlibpath_var"; then
+      # get the directories listed in $shlibpath_var
+      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
+    else
+      shlib_search_path=
+    fi
+    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
+    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
+
+    # Definition is injected by LT_CONFIG during libtool generation.
+    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
+
+    func_dirname "$output" "/" ""
+    output_objdir=$func_dirname_result$objdir
+    func_to_tool_file "$output_objdir/"
+    tool_output_objdir=$func_to_tool_file_result
+    # Create the object directory.
+    func_mkdir_p "$output_objdir"
+
+    # Determine the type of output
+    case $output in
+    "")
+      func_fatal_help "you must specify an output file"
+      ;;
+    *.$libext) linkmode=oldlib ;;
+    *.lo | *.$objext) linkmode=obj ;;
+    *.la) linkmode=lib ;;
+    *) linkmode=prog ;; # Anything else should be a program.
+    esac
+
+    specialdeplibs=
+
+    libs=
+    # Find all interdependent deplibs by searching for libraries
+    # that are linked more than once (e.g. -la -lb -la)
+    for deplib in $deplibs; do
+      if $opt_preserve_dup_deps; then
+	case "$libs " in
+	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
+	esac
+      fi
+      func_append libs " $deplib"
+    done
+
+    if test lib = "$linkmode"; then
+      libs="$predeps $libs $compiler_lib_search_path $postdeps"
+
+      # Compute libraries that are listed more than once in $predeps
+      # $postdeps and mark them as special (i.e., whose duplicates are
+      # not to be eliminated).
+      pre_post_deps=
+      if $opt_duplicate_compiler_generated_deps; then
+	for pre_post_dep in $predeps $postdeps; do
+	  case "$pre_post_deps " in
+	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
+	  esac
+	  func_append pre_post_deps " $pre_post_dep"
+	done
+      fi
+      pre_post_deps=
+    fi
+
+    deplibs=
+    newdependency_libs=
+    newlib_search_path=
+    need_relink=no # whether we're linking any uninstalled libtool libraries
+    notinst_deplibs= # not-installed libtool libraries
+    notinst_path= # paths that contain not-installed libtool libraries
+
+    case $linkmode in
+    lib)
+	passes="conv dlpreopen link"
+	for file in $dlfiles $dlprefiles; do
+	  case $file in
+	  *.la) ;;
+	  *)
+	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
+	    ;;
+	  esac
+	done
+	;;
+    prog)
+	compile_deplibs=
+	finalize_deplibs=
+	alldeplibs=false
+	newdlfiles=
+	newdlprefiles=
+	passes="conv scan dlopen dlpreopen link"
+	;;
+    *)  passes="conv"
+	;;
+    esac
+
+    for pass in $passes; do
+      # The preopen pass in lib mode reverses $deplibs; put it back here
+      # so that -L comes before libs that need it for instance...
+      if test lib,link = "$linkmode,$pass"; then
+	## FIXME: Find the place where the list is rebuilt in the wrong
+	##        order, and fix it there properly
+        tmp_deplibs=
+	for deplib in $deplibs; do
+	  tmp_deplibs="$deplib $tmp_deplibs"
+	done
+	deplibs=$tmp_deplibs
+      fi
+
+      if test lib,link = "$linkmode,$pass" ||
+	 test prog,scan = "$linkmode,$pass"; then
+	libs=$deplibs
+	deplibs=
+      fi
+      if test prog = "$linkmode"; then
+	case $pass in
+	dlopen) libs=$dlfiles ;;
+	dlpreopen) libs=$dlprefiles ;;
+	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
+	esac
+      fi
+      if test lib,dlpreopen = "$linkmode,$pass"; then
+	# Collect and forward deplibs of preopened libtool libs
+	for lib in $dlprefiles; do
+	  # Ignore non-libtool-libs
+	  dependency_libs=
+	  func_resolve_sysroot "$lib"
+	  case $lib in
+	  *.la)	func_source "$func_resolve_sysroot_result" ;;
+	  esac
+
+	  # Collect preopened libtool deplibs, except any this library
+	  # has declared as weak libs
+	  for deplib in $dependency_libs; do
+	    func_basename "$deplib"
+            deplib_base=$func_basename_result
+	    case " $weak_libs " in
+	    *" $deplib_base "*) ;;
+	    *) func_append deplibs " $deplib" ;;
+	    esac
+	  done
+	done
+	libs=$dlprefiles
+      fi
+      if test dlopen = "$pass"; then
+	# Collect dlpreopened libraries
+	save_deplibs=$deplibs
+	deplibs=
+      fi
+
+      for deplib in $libs; do
+	lib=
+	found=false
+	case $deplib in
+	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
+        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
+	  if test prog,link = "$linkmode,$pass"; then
+	    compile_deplibs="$deplib $compile_deplibs"
+	    finalize_deplibs="$deplib $finalize_deplibs"
+	  else
+	    func_append compiler_flags " $deplib"
+	    if test lib = "$linkmode"; then
+		case "$new_inherited_linker_flags " in
+		    *" $deplib "*) ;;
+		    * ) func_append new_inherited_linker_flags " $deplib" ;;
+		esac
+	    fi
+	  fi
+	  continue
+	  ;;
+	-l*)
+	  if test lib != "$linkmode" && test prog != "$linkmode"; then
+	    func_warning "'-l' is ignored for archives/objects"
+	    continue
+	  fi
+	  func_stripname '-l' '' "$deplib"
+	  name=$func_stripname_result
+	  if test lib = "$linkmode"; then
+	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
+	  else
+	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
+	  fi
+	  for searchdir in $searchdirs; do
+	    for search_ext in .la $std_shrext .so .a; do
+	      # Search the libtool library
+	      lib=$searchdir/lib$name$search_ext
+	      if test -f "$lib"; then
+		if test .la = "$search_ext"; then
+		  found=:
+		else
+		  found=false
+		fi
+		break 2
+	      fi
+	    done
+	  done
+	  if $found; then
+	    # deplib is a libtool library
+	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
+	    # We need to do some special things here, and not later.
+	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
+	      case " $predeps $postdeps " in
+	      *" $deplib "*)
+		if func_lalib_p "$lib"; then
+		  library_names=
+		  old_library=
+		  func_source "$lib"
+		  for l in $old_library $library_names; do
+		    ll=$l
+		  done
+		  if test "X$ll" = "X$old_library"; then # only static version available
+		    found=false
+		    func_dirname "$lib" "" "."
+		    ladir=$func_dirname_result
+		    lib=$ladir/$old_library
+		    if test prog,link = "$linkmode,$pass"; then
+		      compile_deplibs="$deplib $compile_deplibs"
+		      finalize_deplibs="$deplib $finalize_deplibs"
+		    else
+		      deplibs="$deplib $deplibs"
+		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
+		    fi
+		    continue
+		  fi
+		fi
+		;;
+	      *) ;;
+	      esac
+	    fi
+	  else
+	    # deplib doesn't seem to be a libtool library
+	    if test prog,link = "$linkmode,$pass"; then
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    else
+	      deplibs="$deplib $deplibs"
+	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
+	    fi
+	    continue
+	  fi
+	  ;; # -l
+	*.ltframework)
+	  if test prog,link = "$linkmode,$pass"; then
+	    compile_deplibs="$deplib $compile_deplibs"
+	    finalize_deplibs="$deplib $finalize_deplibs"
+	  else
+	    deplibs="$deplib $deplibs"
+	    if test lib = "$linkmode"; then
+		case "$new_inherited_linker_flags " in
+		    *" $deplib "*) ;;
+		    * ) func_append new_inherited_linker_flags " $deplib" ;;
+		esac
+	    fi
+	  fi
+	  continue
+	  ;;
+	-L*)
+	  case $linkmode in
+	  lib)
+	    deplibs="$deplib $deplibs"
+	    test conv = "$pass" && continue
+	    newdependency_libs="$deplib $newdependency_libs"
+	    func_stripname '-L' '' "$deplib"
+	    func_resolve_sysroot "$func_stripname_result"
+	    func_append newlib_search_path " $func_resolve_sysroot_result"
+	    ;;
+	  prog)
+	    if test conv = "$pass"; then
+	      deplibs="$deplib $deplibs"
+	      continue
+	    fi
+	    if test scan = "$pass"; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    fi
+	    func_stripname '-L' '' "$deplib"
+	    func_resolve_sysroot "$func_stripname_result"
+	    func_append newlib_search_path " $func_resolve_sysroot_result"
+	    ;;
+	  *)
+	    func_warning "'-L' is ignored for archives/objects"
+	    ;;
+	  esac # linkmode
+	  continue
+	  ;; # -L
+	-R*)
+	  if test link = "$pass"; then
+	    func_stripname '-R' '' "$deplib"
+	    func_resolve_sysroot "$func_stripname_result"
+	    dir=$func_resolve_sysroot_result
+	    # Make sure the xrpath contains only unique directories.
+	    case "$xrpath " in
+	    *" $dir "*) ;;
+	    *) func_append xrpath " $dir" ;;
+	    esac
+	  fi
+	  deplibs="$deplib $deplibs"
+	  continue
+	  ;;
+	*.la)
+	  func_resolve_sysroot "$deplib"
+	  lib=$func_resolve_sysroot_result
+	  ;;
+	*.$libext)
+	  if test conv = "$pass"; then
+	    deplibs="$deplib $deplibs"
+	    continue
+	  fi
+	  case $linkmode in
+	  lib)
+	    # Linking convenience modules into shared libraries is allowed,
+	    # but linking other static libraries is non-portable.
+	    case " $dlpreconveniencelibs " in
+	    *" $deplib "*) ;;
+	    *)
+	      valid_a_lib=false
+	      case $deplibs_check_method in
+		match_pattern*)
+		  set dummy $deplibs_check_method; shift
+		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
+		    | $EGREP "$match_pattern_regex" > /dev/null; then
+		    valid_a_lib=:
+		  fi
+		;;
+		pass_all)
+		  valid_a_lib=:
+		;;
+	      esac
+	      if $valid_a_lib; then
+		echo
+		$ECHO "*** Warning: Linking the shared library $output against the"
+		$ECHO "*** static library $deplib is not portable!"
+		deplibs="$deplib $deplibs"
+	      else
+		echo
+		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
+		echo "*** I have the capability to make that library automatically link in when"
+		echo "*** you link to this library.  But I can only do this if you have a"
+		echo "*** shared version of the library, which you do not appear to have"
+		echo "*** because the file extensions .$libext of this argument makes me believe"
+		echo "*** that it is just a static archive that I should not use here."
+	      fi
+	      ;;
+	    esac
+	    continue
+	    ;;
+	  prog)
+	    if test link != "$pass"; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    fi
+	    continue
+	    ;;
+	  esac # linkmode
+	  ;; # *.$libext
+	*.lo | *.$objext)
+	  if test conv = "$pass"; then
+	    deplibs="$deplib $deplibs"
+	  elif test prog = "$linkmode"; then
+	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
+	      # If there is no dlopen support or we're linking statically,
+	      # we need to preload.
+	      func_append newdlprefiles " $deplib"
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    else
+	      func_append newdlfiles " $deplib"
+	    fi
+	  fi
+	  continue
+	  ;;
+	%DEPLIBS%)
+	  alldeplibs=:
+	  continue
+	  ;;
+	esac # case $deplib
+
+	$found || test -f "$lib" \
+	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
+
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$lib" \
+	  || func_fatal_error "'$lib' is not a valid libtool archive"
+
+	func_dirname "$lib" "" "."
+	ladir=$func_dirname_result
+
+	dlname=
+	dlopen=
+	dlpreopen=
+	libdir=
+	library_names=
+	old_library=
+	inherited_linker_flags=
+	# If the library was installed with an old release of libtool,
+	# it will not redefine variables installed, or shouldnotlink
+	installed=yes
+	shouldnotlink=no
+	avoidtemprpath=
+
+
+	# Read the .la file
+	func_source "$lib"
+
+	# Convert "-framework foo" to "foo.ltframework"
+	if test -n "$inherited_linker_flags"; then
+	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
+	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
+	    case " $new_inherited_linker_flags " in
+	      *" $tmp_inherited_linker_flag "*) ;;
+	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
+	    esac
+	  done
+	fi
+	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	if test lib,link = "$linkmode,$pass" ||
+	   test prog,scan = "$linkmode,$pass" ||
+	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
+	  test -n "$dlopen" && func_append dlfiles " $dlopen"
+	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
+	fi
+
+	if test conv = "$pass"; then
+	  # Only check for convenience libraries
+	  deplibs="$lib $deplibs"
+	  if test -z "$libdir"; then
+	    if test -z "$old_library"; then
+	      func_fatal_error "cannot find name of link library for '$lib'"
+	    fi
+	    # It is a libtool convenience library, so add in its objects.
+	    func_append convenience " $ladir/$objdir/$old_library"
+	    func_append old_convenience " $ladir/$objdir/$old_library"
+	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
+	    func_fatal_error "'$lib' is not a convenience library"
+	  fi
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    deplibs="$deplib $deplibs"
+	    if $opt_preserve_dup_deps; then
+	      case "$tmp_libs " in
+	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
+	      esac
+	    fi
+	    func_append tmp_libs " $deplib"
+	  done
+	  continue
+	fi # $pass = conv
+
+
+	# Get the name of the library we link against.
+	linklib=
+	if test -n "$old_library" &&
+	   { test yes = "$prefer_static_libs" ||
+	     test built,no = "$prefer_static_libs,$installed"; }; then
+	  linklib=$old_library
+	else
+	  for l in $old_library $library_names; do
+	    linklib=$l
+	  done
+	fi
+	if test -z "$linklib"; then
+	  func_fatal_error "cannot find name of link library for '$lib'"
+	fi
+
+	# This library was specified with -dlopen.
+	if test dlopen = "$pass"; then
+	  test -z "$libdir" \
+	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
+	  if test -z "$dlname" ||
+	     test yes != "$dlopen_support" ||
+	     test no = "$build_libtool_libs"
+	  then
+	    # If there is no dlname, no dlopen support or we're linking
+	    # statically, we need to preload.  We also need to preload any
+	    # dependent libraries so libltdl's deplib preloader doesn't
+	    # bomb out in the load deplibs phase.
+	    func_append dlprefiles " $lib $dependency_libs"
+	  else
+	    func_append newdlfiles " $lib"
+	  fi
+	  continue
+	fi # $pass = dlopen
+
+	# We need an absolute path.
+	case $ladir in
+	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
+	*)
+	  abs_ladir=`cd "$ladir" && pwd`
+	  if test -z "$abs_ladir"; then
+	    func_warning "cannot determine absolute directory name of '$ladir'"
+	    func_warning "passing it literally to the linker, although it might fail"
+	    abs_ladir=$ladir
+	  fi
+	  ;;
+	esac
+	func_basename "$lib"
+	laname=$func_basename_result
+
+	# Find the relevant object directory and library name.
+	if test yes = "$installed"; then
+	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+	    func_warning "library '$lib' was moved."
+	    dir=$ladir
+	    absdir=$abs_ladir
+	    libdir=$abs_ladir
+	  else
+	    dir=$lt_sysroot$libdir
+	    absdir=$lt_sysroot$libdir
+	  fi
+	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
+	else
+	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+	    dir=$ladir
+	    absdir=$abs_ladir
+	    # Remove this search path later
+	    func_append notinst_path " $abs_ladir"
+	  else
+	    dir=$ladir/$objdir
+	    absdir=$abs_ladir/$objdir
+	    # Remove this search path later
+	    func_append notinst_path " $abs_ladir"
+	  fi
+	fi # $installed = yes
+	func_stripname 'lib' '.la' "$laname"
+	name=$func_stripname_result
+
+	# This library was specified with -dlpreopen.
+	if test dlpreopen = "$pass"; then
+	  if test -z "$libdir" && test prog = "$linkmode"; then
+	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
+	  fi
+	  case $host in
+	    # special handling for platforms with PE-DLLs.
+	    *cygwin* | *mingw* | *cegcc* )
+	      # Linker will automatically link against shared library if both
+	      # static and shared are present.  Therefore, ensure we extract
+	      # symbols from the import library if a shared library is present
+	      # (otherwise, the dlopen module name will be incorrect).  We do
+	      # this by putting the import library name into $newdlprefiles.
+	      # We recover the dlopen module name by 'saving' the la file
+	      # name in a special purpose variable, and (later) extracting the
+	      # dlname from the la file.
+	      if test -n "$dlname"; then
+	        func_tr_sh "$dir/$linklib"
+	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
+	        func_append newdlprefiles " $dir/$linklib"
+	      else
+	        func_append newdlprefiles " $dir/$old_library"
+	        # Keep a list of preopened convenience libraries to check
+	        # that they are being used correctly in the link pass.
+	        test -z "$libdir" && \
+	          func_append dlpreconveniencelibs " $dir/$old_library"
+	      fi
+	    ;;
+	    * )
+	      # Prefer using a static library (so that no silly _DYNAMIC symbols
+	      # are required to link).
+	      if test -n "$old_library"; then
+	        func_append newdlprefiles " $dir/$old_library"
+	        # Keep a list of preopened convenience libraries to check
+	        # that they are being used correctly in the link pass.
+	        test -z "$libdir" && \
+	          func_append dlpreconveniencelibs " $dir/$old_library"
+	      # Otherwise, use the dlname, so that lt_dlopen finds it.
+	      elif test -n "$dlname"; then
+	        func_append newdlprefiles " $dir/$dlname"
+	      else
+	        func_append newdlprefiles " $dir/$linklib"
+	      fi
+	    ;;
+	  esac
+	fi # $pass = dlpreopen
+
+	if test -z "$libdir"; then
+	  # Link the convenience library
+	  if test lib = "$linkmode"; then
+	    deplibs="$dir/$old_library $deplibs"
+	  elif test prog,link = "$linkmode,$pass"; then
+	    compile_deplibs="$dir/$old_library $compile_deplibs"
+	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
+	  else
+	    deplibs="$lib $deplibs" # used for prog,scan pass
+	  fi
+	  continue
+	fi
+
+
+	if test prog = "$linkmode" && test link != "$pass"; then
+	  func_append newlib_search_path " $ladir"
+	  deplibs="$lib $deplibs"
+
+	  linkalldeplibs=false
+	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
+	     test no = "$build_libtool_libs"; then
+	    linkalldeplibs=:
+	  fi
+
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    case $deplib in
+	    -L*) func_stripname '-L' '' "$deplib"
+	         func_resolve_sysroot "$func_stripname_result"
+	         func_append newlib_search_path " $func_resolve_sysroot_result"
+		 ;;
+	    esac
+	    # Need to link against all dependency_libs?
+	    if $linkalldeplibs; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      # Need to hardcode shared library paths
+	      # or/and link against static libraries
+	      newdependency_libs="$deplib $newdependency_libs"
+	    fi
+	    if $opt_preserve_dup_deps; then
+	      case "$tmp_libs " in
+	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
+	      esac
+	    fi
+	    func_append tmp_libs " $deplib"
+	  done # for deplib
+	  continue
+	fi # $linkmode = prog...
+
+	if test prog,link = "$linkmode,$pass"; then
+	  if test -n "$library_names" &&
+	     { { test no = "$prefer_static_libs" ||
+	         test built,yes = "$prefer_static_libs,$installed"; } ||
+	       test -z "$old_library"; }; then
+	    # We need to hardcode the library path
+	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
+	      # Make sure the rpath contains only unique directories.
+	      case $temp_rpath: in
+	      *"$absdir:"*) ;;
+	      *) func_append temp_rpath "$absdir:" ;;
+	      esac
+	    fi
+
+	    # Hardcode the library path.
+	    # Skip directories that are in the system default run-time
+	    # search path.
+	    case " $sys_lib_dlsearch_path " in
+	    *" $absdir "*) ;;
+	    *)
+	      case "$compile_rpath " in
+	      *" $absdir "*) ;;
+	      *) func_append compile_rpath " $absdir" ;;
+	      esac
+	      ;;
+	    esac
+	    case " $sys_lib_dlsearch_path " in
+	    *" $libdir "*) ;;
+	    *)
+	      case "$finalize_rpath " in
+	      *" $libdir "*) ;;
+	      *) func_append finalize_rpath " $libdir" ;;
+	      esac
+	      ;;
+	    esac
+	  fi # $linkmode,$pass = prog,link...
+
+	  if $alldeplibs &&
+	     { test pass_all = "$deplibs_check_method" ||
+	       { test yes = "$build_libtool_libs" &&
+		 test -n "$library_names"; }; }; then
+	    # We only need to search for static libraries
+	    continue
+	  fi
+	fi
+
+	link_static=no # Whether the deplib will be linked statically
+	use_static_libs=$prefer_static_libs
+	if test built = "$use_static_libs" && test yes = "$installed"; then
+	  use_static_libs=no
+	fi
+	if test -n "$library_names" &&
+	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
+	  case $host in
+	  *cygwin* | *mingw* | *cegcc* | *os2*)
+	      # No point in relinking DLLs because paths are not encoded
+	      func_append notinst_deplibs " $lib"
+	      need_relink=no
+	    ;;
+	  *)
+	    if test no = "$installed"; then
+	      func_append notinst_deplibs " $lib"
+	      need_relink=yes
+	    fi
+	    ;;
+	  esac
+	  # This is a shared library
+
+	  # Warn about portability, can't link against -module's on some
+	  # systems (darwin).  Don't bleat about dlopened modules though!
+	  dlopenmodule=
+	  for dlpremoduletest in $dlprefiles; do
+	    if test "X$dlpremoduletest" = "X$lib"; then
+	      dlopenmodule=$dlpremoduletest
+	      break
+	    fi
+	  done
+	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
+	    echo
+	    if test prog = "$linkmode"; then
+	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
+	    else
+	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
+	    fi
+	    $ECHO "*** $linklib is not portable!"
+	  fi
+	  if test lib = "$linkmode" &&
+	     test yes = "$hardcode_into_libs"; then
+	    # Hardcode the library path.
+	    # Skip directories that are in the system default run-time
+	    # search path.
+	    case " $sys_lib_dlsearch_path " in
+	    *" $absdir "*) ;;
+	    *)
+	      case "$compile_rpath " in
+	      *" $absdir "*) ;;
+	      *) func_append compile_rpath " $absdir" ;;
+	      esac
+	      ;;
+	    esac
+	    case " $sys_lib_dlsearch_path " in
+	    *" $libdir "*) ;;
+	    *)
+	      case "$finalize_rpath " in
+	      *" $libdir "*) ;;
+	      *) func_append finalize_rpath " $libdir" ;;
+	      esac
+	      ;;
+	    esac
+	  fi
+
+	  if test -n "$old_archive_from_expsyms_cmds"; then
+	    # figure out the soname
+	    set dummy $library_names
+	    shift
+	    realname=$1
+	    shift
+	    libname=`eval "\\$ECHO \"$libname_spec\""`
+	    # use dlname if we got it. it's perfectly good, no?
+	    if test -n "$dlname"; then
+	      soname=$dlname
+	    elif test -n "$soname_spec"; then
+	      # bleh windows
+	      case $host in
+	      *cygwin* | mingw* | *cegcc* | *os2*)
+	        func_arith $current - $age
+		major=$func_arith_result
+		versuffix=-$major
+		;;
+	      esac
+	      eval soname=\"$soname_spec\"
+	    else
+	      soname=$realname
+	    fi
+
+	    # Make a new name for the extract_expsyms_cmds to use
+	    soroot=$soname
+	    func_basename "$soroot"
+	    soname=$func_basename_result
+	    func_stripname 'lib' '.dll' "$soname"
+	    newlib=libimp-$func_stripname_result.a
+
+	    # If the library has no export list, then create one now
+	    if test -f "$output_objdir/$soname-def"; then :
+	    else
+	      func_verbose "extracting exported symbol list from '$soname'"
+	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
+	    fi
+
+	    # Create $newlib
+	    if test -f "$output_objdir/$newlib"; then :; else
+	      func_verbose "generating import library for '$soname'"
+	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
+	    fi
+	    # make sure the library variables are pointing to the new library
+	    dir=$output_objdir
+	    linklib=$newlib
+	  fi # test -n "$old_archive_from_expsyms_cmds"
+
+	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
+	    add_shlibpath=
+	    add_dir=
+	    add=
+	    lib_linked=yes
+	    case $hardcode_action in
+	    immediate | unsupported)
+	      if test no = "$hardcode_direct"; then
+		add=$dir/$linklib
+		case $host in
+		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
+		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
+		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
+		    *-*-unixware7*) add_dir=-L$dir ;;
+		  *-*-darwin* )
+		    # if the lib is a (non-dlopened) module then we cannot
+		    # link against it, someone is ignoring the earlier warnings
+		    if /usr/bin/file -L $add 2> /dev/null |
+			 $GREP ": [^:]* bundle" >/dev/null; then
+		      if test "X$dlopenmodule" != "X$lib"; then
+			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
+			if test -z "$old_library"; then
+			  echo
+			  echo "*** And there doesn't seem to be a static archive available"
+			  echo "*** The link will probably fail, sorry"
+			else
+			  add=$dir/$old_library
+			fi
+		      elif test -n "$old_library"; then
+			add=$dir/$old_library
+		      fi
+		    fi
+		esac
+	      elif test no = "$hardcode_minus_L"; then
+		case $host in
+		*-*-sunos*) add_shlibpath=$dir ;;
+		esac
+		add_dir=-L$dir
+		add=-l$name
+	      elif test no = "$hardcode_shlibpath_var"; then
+		add_shlibpath=$dir
+		add=-l$name
+	      else
+		lib_linked=no
+	      fi
+	      ;;
+	    relink)
+	      if test yes = "$hardcode_direct" &&
+	         test no = "$hardcode_direct_absolute"; then
+		add=$dir/$linklib
+	      elif test yes = "$hardcode_minus_L"; then
+		add_dir=-L$absdir
+		# Try looking first in the location we're being installed to.
+		if test -n "$inst_prefix_dir"; then
+		  case $libdir in
+		    [\\/]*)
+		      func_append add_dir " -L$inst_prefix_dir$libdir"
+		      ;;
+		  esac
+		fi
+		add=-l$name
+	      elif test yes = "$hardcode_shlibpath_var"; then
+		add_shlibpath=$dir
+		add=-l$name
+	      else
+		lib_linked=no
+	      fi
+	      ;;
+	    *) lib_linked=no ;;
+	    esac
+
+	    if test yes != "$lib_linked"; then
+	      func_fatal_configuration "unsupported hardcode properties"
+	    fi
+
+	    if test -n "$add_shlibpath"; then
+	      case :$compile_shlibpath: in
+	      *":$add_shlibpath:"*) ;;
+	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
+	      esac
+	    fi
+	    if test prog = "$linkmode"; then
+	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
+	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
+	    else
+	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
+	      test -n "$add" && deplibs="$add $deplibs"
+	      if test yes != "$hardcode_direct" &&
+		 test yes != "$hardcode_minus_L" &&
+		 test yes = "$hardcode_shlibpath_var"; then
+		case :$finalize_shlibpath: in
+		*":$libdir:"*) ;;
+		*) func_append finalize_shlibpath "$libdir:" ;;
+		esac
+	      fi
+	    fi
+	  fi
+
+	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
+	    add_shlibpath=
+	    add_dir=
+	    add=
+	    # Finalize command for both is simple: just hardcode it.
+	    if test yes = "$hardcode_direct" &&
+	       test no = "$hardcode_direct_absolute"; then
+	      add=$libdir/$linklib
+	    elif test yes = "$hardcode_minus_L"; then
+	      add_dir=-L$libdir
+	      add=-l$name
+	    elif test yes = "$hardcode_shlibpath_var"; then
+	      case :$finalize_shlibpath: in
+	      *":$libdir:"*) ;;
+	      *) func_append finalize_shlibpath "$libdir:" ;;
+	      esac
+	      add=-l$name
+	    elif test yes = "$hardcode_automatic"; then
+	      if test -n "$inst_prefix_dir" &&
+		 test -f "$inst_prefix_dir$libdir/$linklib"; then
+		add=$inst_prefix_dir$libdir/$linklib
+	      else
+		add=$libdir/$linklib
+	      fi
+	    else
+	      # We cannot seem to hardcode it, guess we'll fake it.
+	      add_dir=-L$libdir
+	      # Try looking first in the location we're being installed to.
+	      if test -n "$inst_prefix_dir"; then
+		case $libdir in
+		  [\\/]*)
+		    func_append add_dir " -L$inst_prefix_dir$libdir"
+		    ;;
+		esac
+	      fi
+	      add=-l$name
+	    fi
+
+	    if test prog = "$linkmode"; then
+	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
+	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
+	    else
+	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
+	      test -n "$add" && deplibs="$add $deplibs"
+	    fi
+	  fi
+	elif test prog = "$linkmode"; then
+	  # Here we assume that one of hardcode_direct or hardcode_minus_L
+	  # is not unsupported.  This is valid on all known static and
+	  # shared platforms.
+	  if test unsupported != "$hardcode_direct"; then
+	    test -n "$old_library" && linklib=$old_library
+	    compile_deplibs="$dir/$linklib $compile_deplibs"
+	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
+	  else
+	    compile_deplibs="-l$name -L$dir $compile_deplibs"
+	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
+	  fi
+	elif test yes = "$build_libtool_libs"; then
+	  # Not a shared library
+	  if test pass_all != "$deplibs_check_method"; then
+	    # We're trying link a shared library against a static one
+	    # but the system doesn't support it.
+
+	    # Just print a warning and add the library to dependency_libs so
+	    # that the program can be linked against the static library.
+	    echo
+	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
+	    echo "*** I have the capability to make that library automatically link in when"
+	    echo "*** you link to this library.  But I can only do this if you have a"
+	    echo "*** shared version of the library, which you do not appear to have."
+	    if test yes = "$module"; then
+	      echo "*** But as you try to build a module library, libtool will still create "
+	      echo "*** a static module, that should work as long as the dlopening application"
+	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
+	      if test -z "$global_symbol_pipe"; then
+		echo
+		echo "*** However, this would only work if libtool was able to extract symbol"
+		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
+		echo "*** not find such a program.  So, this module is probably useless."
+		echo "*** 'nm' from GNU binutils and a full rebuild may help."
+	      fi
+	      if test no = "$build_old_libs"; then
+		build_libtool_libs=module
+		build_old_libs=yes
+	      else
+		build_libtool_libs=no
+	      fi
+	    fi
+	  else
+	    deplibs="$dir/$old_library $deplibs"
+	    link_static=yes
+	  fi
+	fi # link shared/static library?
+
+	if test lib = "$linkmode"; then
+	  if test -n "$dependency_libs" &&
+	     { test yes != "$hardcode_into_libs" ||
+	       test yes = "$build_old_libs" ||
+	       test yes = "$link_static"; }; then
+	    # Extract -R from dependency_libs
+	    temp_deplibs=
+	    for libdir in $dependency_libs; do
+	      case $libdir in
+	      -R*) func_stripname '-R' '' "$libdir"
+	           temp_xrpath=$func_stripname_result
+		   case " $xrpath " in
+		   *" $temp_xrpath "*) ;;
+		   *) func_append xrpath " $temp_xrpath";;
+		   esac;;
+	      *) func_append temp_deplibs " $libdir";;
+	      esac
+	    done
+	    dependency_libs=$temp_deplibs
+	  fi
+
+	  func_append newlib_search_path " $absdir"
+	  # Link against this library
+	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
+	  # ... and its dependency_libs
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    newdependency_libs="$deplib $newdependency_libs"
+	    case $deplib in
+              -L*) func_stripname '-L' '' "$deplib"
+                   func_resolve_sysroot "$func_stripname_result";;
+              *) func_resolve_sysroot "$deplib" ;;
+            esac
+	    if $opt_preserve_dup_deps; then
+	      case "$tmp_libs " in
+	      *" $func_resolve_sysroot_result "*)
+                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
+	      esac
+	    fi
+	    func_append tmp_libs " $func_resolve_sysroot_result"
+	  done
+
+	  if test no != "$link_all_deplibs"; then
+	    # Add the search paths of all dependency libraries
+	    for deplib in $dependency_libs; do
+	      path=
+	      case $deplib in
+	      -L*) path=$deplib ;;
+	      *.la)
+	        func_resolve_sysroot "$deplib"
+	        deplib=$func_resolve_sysroot_result
+	        func_dirname "$deplib" "" "."
+		dir=$func_dirname_result
+		# We need an absolute path.
+		case $dir in
+		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
+		*)
+		  absdir=`cd "$dir" && pwd`
+		  if test -z "$absdir"; then
+		    func_warning "cannot determine absolute directory name of '$dir'"
+		    absdir=$dir
+		  fi
+		  ;;
+		esac
+		if $GREP "^installed=no" $deplib > /dev/null; then
+		case $host in
+		*-*-darwin*)
+		  depdepl=
+		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
+		  if test -n "$deplibrary_names"; then
+		    for tmp in $deplibrary_names; do
+		      depdepl=$tmp
+		    done
+		    if test -f "$absdir/$objdir/$depdepl"; then
+		      depdepl=$absdir/$objdir/$depdepl
+		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
+                      if test -z "$darwin_install_name"; then
+                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
+                      fi
+		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
+		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
+		      path=
+		    fi
+		  fi
+		  ;;
+		*)
+		  path=-L$absdir/$objdir
+		  ;;
+		esac
+		else
+		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+		  test -z "$libdir" && \
+		    func_fatal_error "'$deplib' is not a valid libtool archive"
+		  test "$absdir" != "$libdir" && \
+		    func_warning "'$deplib' seems to be moved"
+
+		  path=-L$absdir
+		fi
+		;;
+	      esac
+	      case " $deplibs " in
+	      *" $path "*) ;;
+	      *) deplibs="$path $deplibs" ;;
+	      esac
+	    done
+	  fi # link_all_deplibs != no
+	fi # linkmode = lib
+      done # for deplib in $libs
+      if test link = "$pass"; then
+	if test prog = "$linkmode"; then
+	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
+	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
+	else
+	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	fi
+      fi
+      dependency_libs=$newdependency_libs
+      if test dlpreopen = "$pass"; then
+	# Link the dlpreopened libraries before other libraries
+	for deplib in $save_deplibs; do
+	  deplibs="$deplib $deplibs"
+	done
+      fi
+      if test dlopen != "$pass"; then
+	test conv = "$pass" || {
+	  # Make sure lib_search_path contains only unique directories.
+	  lib_search_path=
+	  for dir in $newlib_search_path; do
+	    case "$lib_search_path " in
+	    *" $dir "*) ;;
+	    *) func_append lib_search_path " $dir" ;;
+	    esac
+	  done
+	  newlib_search_path=
+	}
+
+	if test prog,link = "$linkmode,$pass"; then
+	  vars="compile_deplibs finalize_deplibs"
+	else
+	  vars=deplibs
+	fi
+	for var in $vars dependency_libs; do
+	  # Add libraries to $var in reverse order
+	  eval tmp_libs=\"\$$var\"
+	  new_libs=
+	  for deplib in $tmp_libs; do
+	    # FIXME: Pedantically, this is the right thing to do, so
+	    #        that some nasty dependency loop isn't accidentally
+	    #        broken:
+	    #new_libs="$deplib $new_libs"
+	    # Pragmatically, this seems to cause very few problems in
+	    # practice:
+	    case $deplib in
+	    -L*) new_libs="$deplib $new_libs" ;;
+	    -R*) ;;
+	    *)
+	      # And here is the reason: when a library appears more
+	      # than once as an explicit dependence of a library, or
+	      # is implicitly linked in more than once by the
+	      # compiler, it is considered special, and multiple
+	      # occurrences thereof are not removed.  Compare this
+	      # with having the same library being listed as a
+	      # dependency of multiple other libraries: in this case,
+	      # we know (pedantically, we assume) the library does not
+	      # need to be listed more than once, so we keep only the
+	      # last copy.  This is not always right, but it is rare
+	      # enough that we require users that really mean to play
+	      # such unportable linking tricks to link the library
+	      # using -Wl,-lname, so that libtool does not consider it
+	      # for duplicate removal.
+	      case " $specialdeplibs " in
+	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
+	      *)
+		case " $new_libs " in
+		*" $deplib "*) ;;
+		*) new_libs="$deplib $new_libs" ;;
+		esac
+		;;
+	      esac
+	      ;;
+	    esac
+	  done
+	  tmp_libs=
+	  for deplib in $new_libs; do
+	    case $deplib in
+	    -L*)
+	      case " $tmp_libs " in
+	      *" $deplib "*) ;;
+	      *) func_append tmp_libs " $deplib" ;;
+	      esac
+	      ;;
+	    *) func_append tmp_libs " $deplib" ;;
+	    esac
+	  done
+	  eval $var=\"$tmp_libs\"
+	done # for var
+      fi
+
+      # Add Sun CC postdeps if required:
+      test CXX = "$tagname" && {
+        case $host_os in
+        linux*)
+          case `$CC -V 2>&1 | sed 5q` in
+          *Sun\ C*) # Sun C++ 5.9
+            func_suncc_cstd_abi
+
+            if test no != "$suncc_use_cstd_abi"; then
+              func_append postdeps ' -library=Cstd -library=Crun'
+            fi
+            ;;
+          esac
+          ;;
+
+        solaris*)
+          func_cc_basename "$CC"
+          case $func_cc_basename_result in
+          CC* | sunCC*)
+            func_suncc_cstd_abi
+
+            if test no != "$suncc_use_cstd_abi"; then
+              func_append postdeps ' -library=Cstd -library=Crun'
+            fi
+            ;;
+          esac
+          ;;
+        esac
+      }
+
+      # Last step: remove runtime libs from dependency_libs
+      # (they stay in deplibs)
+      tmp_libs=
+      for i in $dependency_libs; do
+	case " $predeps $postdeps $compiler_lib_search_path " in
+	*" $i "*)
+	  i=
+	  ;;
+	esac
+	if test -n "$i"; then
+	  func_append tmp_libs " $i"
+	fi
+      done
+      dependency_libs=$tmp_libs
+    done # for pass
+    if test prog = "$linkmode"; then
+      dlfiles=$newdlfiles
+    fi
+    if test prog = "$linkmode" || test lib = "$linkmode"; then
+      dlprefiles=$newdlprefiles
+    fi
+
+    case $linkmode in
+    oldlib)
+      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
+	func_warning "'-dlopen' is ignored for archives"
+      fi
+
+      case " $deplibs" in
+      *\ -l* | *\ -L*)
+	func_warning "'-l' and '-L' are ignored for archives" ;;
+      esac
+
+      test -n "$rpath" && \
+	func_warning "'-rpath' is ignored for archives"
+
+      test -n "$xrpath" && \
+	func_warning "'-R' is ignored for archives"
+
+      test -n "$vinfo" && \
+	func_warning "'-version-info/-version-number' is ignored for archives"
+
+      test -n "$release" && \
+	func_warning "'-release' is ignored for archives"
+
+      test -n "$export_symbols$export_symbols_regex" && \
+	func_warning "'-export-symbols' is ignored for archives"
+
+      # Now set the variables for building old libraries.
+      build_libtool_libs=no
+      oldlibs=$output
+      func_append objs "$old_deplibs"
+      ;;
+
+    lib)
+      # Make sure we only generate libraries of the form 'libNAME.la'.
+      case $outputname in
+      lib*)
+	func_stripname 'lib' '.la' "$outputname"
+	name=$func_stripname_result
+	eval shared_ext=\"$shrext_cmds\"
+	eval libname=\"$libname_spec\"
+	;;
+      *)
+	test no = "$module" \
+	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
+
+	if test no != "$need_lib_prefix"; then
+	  # Add the "lib" prefix for modules if required
+	  func_stripname '' '.la' "$outputname"
+	  name=$func_stripname_result
+	  eval shared_ext=\"$shrext_cmds\"
+	  eval libname=\"$libname_spec\"
+	else
+	  func_stripname '' '.la' "$outputname"
+	  libname=$func_stripname_result
+	fi
+	;;
+      esac
+
+      if test -n "$objs"; then
+	if test pass_all != "$deplibs_check_method"; then
+	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
+	else
+	  echo
+	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
+	  $ECHO "*** objects $objs is not portable!"
+	  func_append libobjs " $objs"
+	fi
+      fi
+
+      test no = "$dlself" \
+	|| func_warning "'-dlopen self' is ignored for libtool libraries"
+
+      set dummy $rpath
+      shift
+      test 1 -lt "$#" \
+	&& func_warning "ignoring multiple '-rpath's for a libtool library"
+
+      install_libdir=$1
+
+      oldlibs=
+      if test -z "$rpath"; then
+	if test yes = "$build_libtool_libs"; then
+	  # Building a libtool convenience library.
+	  # Some compilers have problems with a '.al' extension so
+	  # convenience libraries should have the same extension an
+	  # archive normally would.
+	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
+	  build_libtool_libs=convenience
+	  build_old_libs=yes
+	fi
+
+	test -n "$vinfo" && \
+	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
+
+	test -n "$release" && \
+	  func_warning "'-release' is ignored for convenience libraries"
+      else
+
+	# Parse the version information argument.
+	save_ifs=$IFS; IFS=:
+	set dummy $vinfo 0 0 0
+	shift
+	IFS=$save_ifs
+
+	test -n "$7" && \
+	  func_fatal_help "too many parameters to '-version-info'"
+
+	# convert absolute version numbers to libtool ages
+	# this retains compatibility with .la files and attempts
+	# to make the code below a bit more comprehensible
+
+	case $vinfo_number in
+	yes)
+	  number_major=$1
+	  number_minor=$2
+	  number_revision=$3
+	  #
+	  # There are really only two kinds -- those that
+	  # use the current revision as the major version
+	  # and those that subtract age and use age as
+	  # a minor version.  But, then there is irix
+	  # that has an extra 1 added just for fun
+	  #
+	  case $version_type in
+	  # correct linux to gnu/linux during the next big refactor
+	  darwin|freebsd-elf|linux|osf|windows|none)
+	    func_arith $number_major + $number_minor
+	    current=$func_arith_result
+	    age=$number_minor
+	    revision=$number_revision
+	    ;;
+	  freebsd-aout|qnx|sunos)
+	    current=$number_major
+	    revision=$number_minor
+	    age=0
+	    ;;
+	  irix|nonstopux)
+	    func_arith $number_major + $number_minor
+	    current=$func_arith_result
+	    age=$number_minor
+	    revision=$number_minor
+	    lt_irix_increment=no
+	    ;;
+	  esac
+	  ;;
+	no)
+	  current=$1
+	  revision=$2
+	  age=$3
+	  ;;
+	esac
+
+	# Check that each of the things are valid numbers.
+	case $current in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "CURRENT '$current' must be a nonnegative integer"
+	  func_fatal_error "'$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	case $revision in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "REVISION '$revision' must be a nonnegative integer"
+	  func_fatal_error "'$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	case $age in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "AGE '$age' must be a nonnegative integer"
+	  func_fatal_error "'$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	if test "$age" -gt "$current"; then
+	  func_error "AGE '$age' is greater than the current interface number '$current'"
+	  func_fatal_error "'$vinfo' is not valid version information"
+	fi
+
+	# Calculate the version variables.
+	major=
+	versuffix=
+	verstring=
+	case $version_type in
+	none) ;;
+
+	darwin)
+	  # Like Linux, but with the current version available in
+	  # verstring for coding it into the library header
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix=$major.$age.$revision
+	  # Darwin ld doesn't like 0 for these options...
+	  func_arith $current + 1
+	  minor_current=$func_arith_result
+	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
+	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
+          # On Darwin other compilers
+          case $CC in
+              nagfor*)
+                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
+                  ;;
+              *)
+                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
+                  ;;
+          esac
+	  ;;
+
+	freebsd-aout)
+	  major=.$current
+	  versuffix=.$current.$revision
+	  ;;
+
+	freebsd-elf)
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix=$major.$age.$revision
+	  ;;
+
+	irix | nonstopux)
+	  if test no = "$lt_irix_increment"; then
+	    func_arith $current - $age
+	  else
+	    func_arith $current - $age + 1
+	  fi
+	  major=$func_arith_result
+
+	  case $version_type in
+	    nonstopux) verstring_prefix=nonstopux ;;
+	    *)         verstring_prefix=sgi ;;
+	  esac
+	  verstring=$verstring_prefix$major.$revision
+
+	  # Add in all the interfaces that we are compatible with.
+	  loop=$revision
+	  while test 0 -ne "$loop"; do
+	    func_arith $revision - $loop
+	    iface=$func_arith_result
+	    func_arith $loop - 1
+	    loop=$func_arith_result
+	    verstring=$verstring_prefix$major.$iface:$verstring
+	  done
+
+	  # Before this point, $major must not contain '.'.
+	  major=.$major
+	  versuffix=$major.$revision
+	  ;;
+
+	linux) # correct to gnu/linux during the next big refactor
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix=$major.$age.$revision
+	  ;;
+
+	osf)
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix=.$current.$age.$revision
+	  verstring=$current.$age.$revision
+
+	  # Add in all the interfaces that we are compatible with.
+	  loop=$age
+	  while test 0 -ne "$loop"; do
+	    func_arith $current - $loop
+	    iface=$func_arith_result
+	    func_arith $loop - 1
+	    loop=$func_arith_result
+	    verstring=$verstring:$iface.0
+	  done
+
+	  # Make executables depend on our current version.
+	  func_append verstring ":$current.0"
+	  ;;
+
+	qnx)
+	  major=.$current
+	  versuffix=.$current
+	  ;;
+
+	sco)
+	  major=.$current
+	  versuffix=.$current
+	  ;;
+
+	sunos)
+	  major=.$current
+	  versuffix=.$current.$revision
+	  ;;
+
+	windows)
+	  # Use '-' rather than '.', since we only want one
+	  # extension on DOS 8.3 file systems.
+	  func_arith $current - $age
+	  major=$func_arith_result
+	  versuffix=-$major
+	  ;;
+
+	*)
+	  func_fatal_configuration "unknown library version type '$version_type'"
+	  ;;
+	esac
+
+	# Clear the version info if we defaulted, and they specified a release.
+	if test -z "$vinfo" && test -n "$release"; then
+	  major=
+	  case $version_type in
+	  darwin)
+	    # we can't check for "0.0" in archive_cmds due to quoting
+	    # problems, so we reset it completely
+	    verstring=
+	    ;;
+	  *)
+	    verstring=0.0
+	    ;;
+	  esac
+	  if test no = "$need_version"; then
+	    versuffix=
+	  else
+	    versuffix=.0.0
+	  fi
+	fi
+
+	# Remove version info from name if versioning should be avoided
+	if test yes,no = "$avoid_version,$need_version"; then
+	  major=
+	  versuffix=
+	  verstring=
+	fi
+
+	# Check to see if the archive will have undefined symbols.
+	if test yes = "$allow_undefined"; then
+	  if test unsupported = "$allow_undefined_flag"; then
+	    if test yes = "$build_old_libs"; then
+	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
+	      build_libtool_libs=no
+	    else
+	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
+	    fi
+	  fi
+	else
+	  # Don't allow undefined symbols.
+	  allow_undefined_flag=$no_undefined_flag
+	fi
+
+      fi
+
+      func_generate_dlsyms "$libname" "$libname" :
+      func_append libobjs " $symfileobj"
+      test " " = "$libobjs" && libobjs=
+
+      if test relink != "$opt_mode"; then
+	# Remove our outputs, but don't remove object files since they
+	# may have been created when compiling PIC objects.
+	removelist=
+	tempremovelist=`$ECHO "$output_objdir/*"`
+	for p in $tempremovelist; do
+	  case $p in
+	    *.$objext | *.gcno)
+	       ;;
+	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
+	       if test -n "$precious_files_regex"; then
+		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
+		 then
+		   continue
+		 fi
+	       fi
+	       func_append removelist " $p"
+	       ;;
+	    *) ;;
+	  esac
+	done
+	test -n "$removelist" && \
+	  func_show_eval "${RM}r \$removelist"
+      fi
+
+      # Now set the variables for building old libraries.
+      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
+	func_append oldlibs " $output_objdir/$libname.$libext"
+
+	# Transform .lo files to .o files.
+	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
+      fi
+
+      # Eliminate all temporary directories.
+      #for path in $notinst_path; do
+      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
+      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
+      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
+      #done
+
+      if test -n "$xrpath"; then
+	# If the user specified any rpath flags, then add them.
+	temp_xrpath=
+	for libdir in $xrpath; do
+	  func_replace_sysroot "$libdir"
+	  func_append temp_xrpath " -R$func_replace_sysroot_result"
+	  case "$finalize_rpath " in
+	  *" $libdir "*) ;;
+	  *) func_append finalize_rpath " $libdir" ;;
+	  esac
+	done
+	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
+	  dependency_libs="$temp_xrpath $dependency_libs"
+	fi
+      fi
+
+      # Make sure dlfiles contains only unique files that won't be dlpreopened
+      old_dlfiles=$dlfiles
+      dlfiles=
+      for lib in $old_dlfiles; do
+	case " $dlprefiles $dlfiles " in
+	*" $lib "*) ;;
+	*) func_append dlfiles " $lib" ;;
+	esac
+      done
+
+      # Make sure dlprefiles contains only unique files
+      old_dlprefiles=$dlprefiles
+      dlprefiles=
+      for lib in $old_dlprefiles; do
+	case "$dlprefiles " in
+	*" $lib "*) ;;
+	*) func_append dlprefiles " $lib" ;;
+	esac
+      done
+
+      if test yes = "$build_libtool_libs"; then
+	if test -n "$rpath"; then
+	  case $host in
+	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
+	    # these systems don't actually have a c library (as such)!
+	    ;;
+	  *-*-rhapsody* | *-*-darwin1.[012])
+	    # Rhapsody C library is in the System framework
+	    func_append deplibs " System.ltframework"
+	    ;;
+	  *-*-netbsd*)
+	    # Don't link with libc until the a.out ld.so is fixed.
+	    ;;
+	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	    # Do not include libc due to us having libc/libc_r.
+	    ;;
+	  *-*-sco3.2v5* | *-*-sco5v6*)
+	    # Causes problems with __ctype
+	    ;;
+	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+	    # Compiler inserts libc in the correct place for threads to work
+	    ;;
+	  *)
+	    # Add libc to deplibs on all other systems if necessary.
+	    if test yes = "$build_libtool_need_lc"; then
+	      func_append deplibs " -lc"
+	    fi
+	    ;;
+	  esac
+	fi
+
+	# Transform deplibs into only deplibs that can be linked in shared.
+	name_save=$name
+	libname_save=$libname
+	release_save=$release
+	versuffix_save=$versuffix
+	major_save=$major
+	# I'm not sure if I'm treating the release correctly.  I think
+	# release should show up in the -l (ie -lgmp5) so we don't want to
+	# add it in twice.  Is that correct?
+	release=
+	versuffix=
+	major=
+	newdeplibs=
+	droppeddeps=no
+	case $deplibs_check_method in
+	pass_all)
+	  # Don't check for shared/static.  Everything works.
+	  # This might be a little naive.  We might want to check
+	  # whether the library exists or not.  But this is on
+	  # osf3 & osf4 and I'm not really sure... Just
+	  # implementing what was already the behavior.
+	  newdeplibs=$deplibs
+	  ;;
+	test_compile)
+	  # This code stresses the "libraries are programs" paradigm to its
+	  # limits. Maybe even breaks it.  We compile a program, linking it
+	  # against the deplibs as a proxy for the library.  Then we can check
+	  # whether they linked in statically or dynamically with ldd.
+	  $opt_dry_run || $RM conftest.c
+	  cat > conftest.c <<EOF
+	  int main() { return 0; }
+EOF
+	  $opt_dry_run || $RM conftest
+	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
+	    ldd_output=`ldd conftest`
+	    for i in $deplibs; do
+	      case $i in
+	      -l*)
+		func_stripname -l '' "$i"
+		name=$func_stripname_result
+		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
+		  case " $predeps $postdeps " in
+		  *" $i "*)
+		    func_append newdeplibs " $i"
+		    i=
+		    ;;
+		  esac
+		fi
+		if test -n "$i"; then
+		  libname=`eval "\\$ECHO \"$libname_spec\""`
+		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
+		  set dummy $deplib_matches; shift
+		  deplib_match=$1
+		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
+		    func_append newdeplibs " $i"
+		  else
+		    droppeddeps=yes
+		    echo
+		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
+		    echo "*** I have the capability to make that library automatically link in when"
+		    echo "*** you link to this library.  But I can only do this if you have a"
+		    echo "*** shared version of the library, which I believe you do not have"
+		    echo "*** because a test_compile did reveal that the linker did not use it for"
+		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
+		  fi
+		fi
+		;;
+	      *)
+		func_append newdeplibs " $i"
+		;;
+	      esac
+	    done
+	  else
+	    # Error occurred in the first compile.  Let's try to salvage
+	    # the situation: Compile a separate program for each library.
+	    for i in $deplibs; do
+	      case $i in
+	      -l*)
+		func_stripname -l '' "$i"
+		name=$func_stripname_result
+		$opt_dry_run || $RM conftest
+		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
+		  ldd_output=`ldd conftest`
+		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
+		    case " $predeps $postdeps " in
+		    *" $i "*)
+		      func_append newdeplibs " $i"
+		      i=
+		      ;;
+		    esac
+		  fi
+		  if test -n "$i"; then
+		    libname=`eval "\\$ECHO \"$libname_spec\""`
+		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
+		    set dummy $deplib_matches; shift
+		    deplib_match=$1
+		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
+		      func_append newdeplibs " $i"
+		    else
+		      droppeddeps=yes
+		      echo
+		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
+		      echo "*** I have the capability to make that library automatically link in when"
+		      echo "*** you link to this library.  But I can only do this if you have a"
+		      echo "*** shared version of the library, which you do not appear to have"
+		      echo "*** because a test_compile did reveal that the linker did not use this one"
+		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
+		    fi
+		  fi
+		else
+		  droppeddeps=yes
+		  echo
+		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
+		  echo "*** make it link in!  You will probably need to install it or some"
+		  echo "*** library that it depends on before this library will be fully"
+		  echo "*** functional.  Installing it before continuing would be even better."
+		fi
+		;;
+	      *)
+		func_append newdeplibs " $i"
+		;;
+	      esac
+	    done
+	  fi
+	  ;;
+	file_magic*)
+	  set dummy $deplibs_check_method; shift
+	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+	  for a_deplib in $deplibs; do
+	    case $a_deplib in
+	    -l*)
+	      func_stripname -l '' "$a_deplib"
+	      name=$func_stripname_result
+	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
+		case " $predeps $postdeps " in
+		*" $a_deplib "*)
+		  func_append newdeplibs " $a_deplib"
+		  a_deplib=
+		  ;;
+		esac
+	      fi
+	      if test -n "$a_deplib"; then
+		libname=`eval "\\$ECHO \"$libname_spec\""`
+		if test -n "$file_magic_glob"; then
+		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
+		else
+		  libnameglob=$libname
+		fi
+		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
+		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+		  if test yes = "$want_nocaseglob"; then
+		    shopt -s nocaseglob
+		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
+		    $nocaseglob
+		  else
+		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
+		  fi
+		  for potent_lib in $potential_libs; do
+		      # Follow soft links.
+		      if ls -lLd "$potent_lib" 2>/dev/null |
+			 $GREP " -> " >/dev/null; then
+			continue
+		      fi
+		      # The statement above tries to avoid entering an
+		      # endless loop below, in case of cyclic links.
+		      # We might still enter an endless loop, since a link
+		      # loop can be closed while we follow links,
+		      # but so what?
+		      potlib=$potent_lib
+		      while test -h "$potlib" 2>/dev/null; do
+			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
+			case $potliblink in
+			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
+			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
+			esac
+		      done
+		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
+			 $SED -e 10q |
+			 $EGREP "$file_magic_regex" > /dev/null; then
+			func_append newdeplibs " $a_deplib"
+			a_deplib=
+			break 2
+		      fi
+		  done
+		done
+	      fi
+	      if test -n "$a_deplib"; then
+		droppeddeps=yes
+		echo
+		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
+		echo "*** I have the capability to make that library automatically link in when"
+		echo "*** you link to this library.  But I can only do this if you have a"
+		echo "*** shared version of the library, which you do not appear to have"
+		echo "*** because I did check the linker path looking for a file starting"
+		if test -z "$potlib"; then
+		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
+		else
+		  $ECHO "*** with $libname and none of the candidates passed a file format test"
+		  $ECHO "*** using a file magic. Last file checked: $potlib"
+		fi
+	      fi
+	      ;;
+	    *)
+	      # Add a -L argument.
+	      func_append newdeplibs " $a_deplib"
+	      ;;
+	    esac
+	  done # Gone through all deplibs.
+	  ;;
+	match_pattern*)
+	  set dummy $deplibs_check_method; shift
+	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+	  for a_deplib in $deplibs; do
+	    case $a_deplib in
+	    -l*)
+	      func_stripname -l '' "$a_deplib"
+	      name=$func_stripname_result
+	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
+		case " $predeps $postdeps " in
+		*" $a_deplib "*)
+		  func_append newdeplibs " $a_deplib"
+		  a_deplib=
+		  ;;
+		esac
+	      fi
+	      if test -n "$a_deplib"; then
+		libname=`eval "\\$ECHO \"$libname_spec\""`
+		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+		  for potent_lib in $potential_libs; do
+		    potlib=$potent_lib # see symlink-check above in file_magic test
+		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
+		       $EGREP "$match_pattern_regex" > /dev/null; then
+		      func_append newdeplibs " $a_deplib"
+		      a_deplib=
+		      break 2
+		    fi
+		  done
+		done
+	      fi
+	      if test -n "$a_deplib"; then
+		droppeddeps=yes
+		echo
+		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
+		echo "*** I have the capability to make that library automatically link in when"
+		echo "*** you link to this library.  But I can only do this if you have a"
+		echo "*** shared version of the library, which you do not appear to have"
+		echo "*** because I did check the linker path looking for a file starting"
+		if test -z "$potlib"; then
+		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
+		else
+		  $ECHO "*** with $libname and none of the candidates passed a file format test"
+		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
+		fi
+	      fi
+	      ;;
+	    *)
+	      # Add a -L argument.
+	      func_append newdeplibs " $a_deplib"
+	      ;;
+	    esac
+	  done # Gone through all deplibs.
+	  ;;
+	none | unknown | *)
+	  newdeplibs=
+	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
+	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
+	    for i in $predeps $postdeps; do
+	      # can't use Xsed below, because $i might contain '/'
+	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
+	    done
+	  fi
+	  case $tmp_deplibs in
+	  *[!\	\ ]*)
+	    echo
+	    if test none = "$deplibs_check_method"; then
+	      echo "*** Warning: inter-library dependencies are not supported in this platform."
+	    else
+	      echo "*** Warning: inter-library dependencies are not known to be supported."
+	    fi
+	    echo "*** All declared inter-library dependencies are being dropped."
+	    droppeddeps=yes
+	    ;;
+	  esac
+	  ;;
+	esac
+	versuffix=$versuffix_save
+	major=$major_save
+	release=$release_save
+	libname=$libname_save
+	name=$name_save
+
+	case $host in
+	*-*-rhapsody* | *-*-darwin1.[012])
+	  # On Rhapsody replace the C library with the System framework
+	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
+	  ;;
+	esac
+
+	if test yes = "$droppeddeps"; then
+	  if test yes = "$module"; then
+	    echo
+	    echo "*** Warning: libtool could not satisfy all declared inter-library"
+	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
+	    echo "*** a static module, that should work as long as the dlopening"
+	    echo "*** application is linked with the -dlopen flag."
+	    if test -z "$global_symbol_pipe"; then
+	      echo
+	      echo "*** However, this would only work if libtool was able to extract symbol"
+	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
+	      echo "*** not find such a program.  So, this module is probably useless."
+	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
+	    fi
+	    if test no = "$build_old_libs"; then
+	      oldlibs=$output_objdir/$libname.$libext
+	      build_libtool_libs=module
+	      build_old_libs=yes
+	    else
+	      build_libtool_libs=no
+	    fi
+	  else
+	    echo "*** The inter-library dependencies that have been dropped here will be"
+	    echo "*** automatically added whenever a program is linked with this library"
+	    echo "*** or is declared to -dlopen it."
+
+	    if test no = "$allow_undefined"; then
+	      echo
+	      echo "*** Since this library must not contain undefined symbols,"
+	      echo "*** because either the platform does not support them or"
+	      echo "*** it was explicitly requested with -no-undefined,"
+	      echo "*** libtool will only create a static version of it."
+	      if test no = "$build_old_libs"; then
+		oldlibs=$output_objdir/$libname.$libext
+		build_libtool_libs=module
+		build_old_libs=yes
+	      else
+		build_libtool_libs=no
+	      fi
+	    fi
+	  fi
+	fi
+	# Done checking deplibs!
+	deplibs=$newdeplibs
+      fi
+      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
+      case $host in
+	*-*-darwin*)
+	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  ;;
+      esac
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+	case " $new_libs " in
+	*" -L$path/$objdir "*) ;;
+	*)
+	  case " $deplibs " in
+	  *" -L$path/$objdir "*)
+	    func_append new_libs " -L$path/$objdir" ;;
+	  esac
+	  ;;
+	esac
+      done
+      for deplib in $deplibs; do
+	case $deplib in
+	-L*)
+	  case " $new_libs " in
+	  *" $deplib "*) ;;
+	  *) func_append new_libs " $deplib" ;;
+	  esac
+	  ;;
+	*) func_append new_libs " $deplib" ;;
+	esac
+      done
+      deplibs=$new_libs
+
+      # All the library-specific variables (install_libdir is set above).
+      library_names=
+      old_library=
+      dlname=
+
+      # Test again, we may have decided not to build it any more
+      if test yes = "$build_libtool_libs"; then
+	# Remove $wl instances when linking with ld.
+	# FIXME: should test the right _cmds variable.
+	case $archive_cmds in
+	  *\$LD\ *) wl= ;;
+        esac
+	if test yes = "$hardcode_into_libs"; then
+	  # Hardcode the library paths
+	  hardcode_libdirs=
+	  dep_rpath=
+	  rpath=$finalize_rpath
+	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
+	  for libdir in $rpath; do
+	    if test -n "$hardcode_libdir_flag_spec"; then
+	      if test -n "$hardcode_libdir_separator"; then
+		func_replace_sysroot "$libdir"
+		libdir=$func_replace_sysroot_result
+		if test -z "$hardcode_libdirs"; then
+		  hardcode_libdirs=$libdir
+		else
+		  # Just accumulate the unique libdirs.
+		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		    ;;
+		  *)
+		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
+		    ;;
+		  esac
+		fi
+	      else
+		eval flag=\"$hardcode_libdir_flag_spec\"
+		func_append dep_rpath " $flag"
+	      fi
+	    elif test -n "$runpath_var"; then
+	      case "$perm_rpath " in
+	      *" $libdir "*) ;;
+	      *) func_append perm_rpath " $libdir" ;;
+	      esac
+	    fi
+	  done
+	  # Substitute the hardcoded libdirs into the rpath.
+	  if test -n "$hardcode_libdir_separator" &&
+	     test -n "$hardcode_libdirs"; then
+	    libdir=$hardcode_libdirs
+	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
+	  fi
+	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
+	    # We should set the runpath_var.
+	    rpath=
+	    for dir in $perm_rpath; do
+	      func_append rpath "$dir:"
+	    done
+	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
+	  fi
+	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
+	fi
+
+	shlibpath=$finalize_shlibpath
+	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
+	if test -n "$shlibpath"; then
+	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
+	fi
+
+	# Get the real and link names of the library.
+	eval shared_ext=\"$shrext_cmds\"
+	eval library_names=\"$library_names_spec\"
+	set dummy $library_names
+	shift
+	realname=$1
+	shift
+
+	if test -n "$soname_spec"; then
+	  eval soname=\"$soname_spec\"
+	else
+	  soname=$realname
+	fi
+	if test -z "$dlname"; then
+	  dlname=$soname
+	fi
+
+	lib=$output_objdir/$realname
+	linknames=
+	for link
+	do
+	  func_append linknames " $link"
+	done
+
+	# Use standard objects if they are pic
+	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
+	test "X$libobjs" = "X " && libobjs=
+
+	delfiles=
+	if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
+	  export_symbols=$output_objdir/$libname.uexp
+	  func_append delfiles " $export_symbols"
+	fi
+
+	orig_export_symbols=
+	case $host_os in
+	cygwin* | mingw* | cegcc*)
+	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
+	    # exporting using user supplied symfile
+	    func_dll_def_p "$export_symbols" || {
+	      # and it's NOT already a .def file. Must figure out
+	      # which of the given symbols are data symbols and tag
+	      # them as such. So, trigger use of export_symbols_cmds.
+	      # export_symbols gets reassigned inside the "prepare
+	      # the list of exported symbols" if statement, so the
+	      # include_expsyms logic still works.
+	      orig_export_symbols=$export_symbols
+	      export_symbols=
+	      always_export_symbols=yes
+	    }
+	  fi
+	  ;;
+	esac
+
+	# Prepare the list of exported symbols
+	if test -z "$export_symbols"; then
+	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
+	    func_verbose "generating symbol list for '$libname.la'"
+	    export_symbols=$output_objdir/$libname.exp
+	    $opt_dry_run || $RM $export_symbols
+	    cmds=$export_symbols_cmds
+	    save_ifs=$IFS; IFS='~'
+	    for cmd1 in $cmds; do
+	      IFS=$save_ifs
+	      # Take the normal branch if the nm_file_list_spec branch
+	      # doesn't work or if tool conversion is not needed.
+	      case $nm_file_list_spec~$to_tool_file_cmd in
+		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
+		  try_normal_branch=yes
+		  eval cmd=\"$cmd1\"
+		  func_len " $cmd"
+		  len=$func_len_result
+		  ;;
+		*)
+		  try_normal_branch=no
+		  ;;
+	      esac
+	      if test yes = "$try_normal_branch" \
+		 && { test "$len" -lt "$max_cmd_len" \
+		      || test "$max_cmd_len" -le -1; }
+	      then
+		func_show_eval "$cmd" 'exit $?'
+		skipped_export=false
+	      elif test -n "$nm_file_list_spec"; then
+		func_basename "$output"
+		output_la=$func_basename_result
+		save_libobjs=$libobjs
+		save_output=$output
+		output=$output_objdir/$output_la.nm
+		func_to_tool_file "$output"
+		libobjs=$nm_file_list_spec$func_to_tool_file_result
+		func_append delfiles " $output"
+		func_verbose "creating $NM input file list: $output"
+		for obj in $save_libobjs; do
+		  func_to_tool_file "$obj"
+		  $ECHO "$func_to_tool_file_result"
+		done > "$output"
+		eval cmd=\"$cmd1\"
+		func_show_eval "$cmd" 'exit $?'
+		output=$save_output
+		libobjs=$save_libobjs
+		skipped_export=false
+	      else
+		# The command line is too long to execute in one step.
+		func_verbose "using reloadable object file for export list..."
+		skipped_export=:
+		# Break out early, otherwise skipped_export may be
+		# set to false by a later but shorter cmd.
+		break
+	      fi
+	    done
+	    IFS=$save_ifs
+	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
+	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
+	    fi
+	  fi
+	fi
+
+	if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	  tmp_export_symbols=$export_symbols
+	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
+	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
+	fi
+
+	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
+	  # The given exports_symbols file has to be filtered, so filter it.
+	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
+	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
+	  # 's' commands, which not all seds can handle. GNU sed should be fine
+	  # though. Also, the filter scales superlinearly with the number of
+	  # global variables. join(1) would be nice here, but unfortunately
+	  # isn't a blessed tool.
+	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
+	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
+	  export_symbols=$output_objdir/$libname.def
+	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
+	fi
+
+	tmp_deplibs=
+	for test_deplib in $deplibs; do
+	  case " $convenience " in
+	  *" $test_deplib "*) ;;
+	  *)
+	    func_append tmp_deplibs " $test_deplib"
+	    ;;
+	  esac
+	done
+	deplibs=$tmp_deplibs
+
+	if test -n "$convenience"; then
+	  if test -n "$whole_archive_flag_spec" &&
+	    test yes = "$compiler_needs_object" &&
+	    test -z "$libobjs"; then
+	    # extract the archives, so we have objects to list.
+	    # TODO: could optimize this to just extract one archive.
+	    whole_archive_flag_spec=
+	  fi
+	  if test -n "$whole_archive_flag_spec"; then
+	    save_libobjs=$libobjs
+	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
+	    test "X$libobjs" = "X " && libobjs=
+	  else
+	    gentop=$output_objdir/${outputname}x
+	    func_append generated " $gentop"
+
+	    func_extract_archives $gentop $convenience
+	    func_append libobjs " $func_extract_archives_result"
+	    test "X$libobjs" = "X " && libobjs=
+	  fi
+	fi
+
+	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
+	  eval flag=\"$thread_safe_flag_spec\"
+	  func_append linker_flags " $flag"
+	fi
+
+	# Make a backup of the uninstalled library when relinking
+	if test relink = "$opt_mode"; then
+	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
+	fi
+
+	# Do each of the archive commands.
+	if test yes = "$module" && test -n "$module_cmds"; then
+	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+	    eval test_cmds=\"$module_expsym_cmds\"
+	    cmds=$module_expsym_cmds
+	  else
+	    eval test_cmds=\"$module_cmds\"
+	    cmds=$module_cmds
+	  fi
+	else
+	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+	    eval test_cmds=\"$archive_expsym_cmds\"
+	    cmds=$archive_expsym_cmds
+	  else
+	    eval test_cmds=\"$archive_cmds\"
+	    cmds=$archive_cmds
+	  fi
+	fi
+
+	if test : != "$skipped_export" &&
+	   func_len " $test_cmds" &&
+	   len=$func_len_result &&
+	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	  :
+	else
+	  # The command line is too long to link in one step, link piecewise
+	  # or, if using GNU ld and skipped_export is not :, use a linker
+	  # script.
+
+	  # Save the value of $output and $libobjs because we want to
+	  # use them later.  If we have whole_archive_flag_spec, we
+	  # want to use save_libobjs as it was before
+	  # whole_archive_flag_spec was expanded, because we can't
+	  # assume the linker understands whole_archive_flag_spec.
+	  # This may have to be revisited, in case too many
+	  # convenience libraries get linked in and end up exceeding
+	  # the spec.
+	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
+	    save_libobjs=$libobjs
+	  fi
+	  save_output=$output
+	  func_basename "$output"
+	  output_la=$func_basename_result
+
+	  # Clear the reloadable object creation command queue and
+	  # initialize k to one.
+	  test_cmds=
+	  concat_cmds=
+	  objlist=
+	  last_robj=
+	  k=1
+
+	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
+	    output=$output_objdir/$output_la.lnkscript
+	    func_verbose "creating GNU ld script: $output"
+	    echo 'INPUT (' > $output
+	    for obj in $save_libobjs
+	    do
+	      func_to_tool_file "$obj"
+	      $ECHO "$func_to_tool_file_result" >> $output
+	    done
+	    echo ')' >> $output
+	    func_append delfiles " $output"
+	    func_to_tool_file "$output"
+	    output=$func_to_tool_file_result
+	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
+	    output=$output_objdir/$output_la.lnk
+	    func_verbose "creating linker input file list: $output"
+	    : > $output
+	    set x $save_libobjs
+	    shift
+	    firstobj=
+	    if test yes = "$compiler_needs_object"; then
+	      firstobj="$1 "
+	      shift
+	    fi
+	    for obj
+	    do
+	      func_to_tool_file "$obj"
+	      $ECHO "$func_to_tool_file_result" >> $output
+	    done
+	    func_append delfiles " $output"
+	    func_to_tool_file "$output"
+	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
+	  else
+	    if test -n "$save_libobjs"; then
+	      func_verbose "creating reloadable object files..."
+	      output=$output_objdir/$output_la-$k.$objext
+	      eval test_cmds=\"$reload_cmds\"
+	      func_len " $test_cmds"
+	      len0=$func_len_result
+	      len=$len0
+
+	      # Loop over the list of objects to be linked.
+	      for obj in $save_libobjs
+	      do
+		func_len " $obj"
+		func_arith $len + $func_len_result
+		len=$func_arith_result
+		if test -z "$objlist" ||
+		   test "$len" -lt "$max_cmd_len"; then
+		  func_append objlist " $obj"
+		else
+		  # The command $test_cmds is almost too long, add a
+		  # command to the queue.
+		  if test 1 -eq "$k"; then
+		    # The first file doesn't have a previous command to add.
+		    reload_objs=$objlist
+		    eval concat_cmds=\"$reload_cmds\"
+		  else
+		    # All subsequent reloadable object files will link in
+		    # the last one created.
+		    reload_objs="$objlist $last_robj"
+		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
+		  fi
+		  last_robj=$output_objdir/$output_la-$k.$objext
+		  func_arith $k + 1
+		  k=$func_arith_result
+		  output=$output_objdir/$output_la-$k.$objext
+		  objlist=" $obj"
+		  func_len " $last_robj"
+		  func_arith $len0 + $func_len_result
+		  len=$func_arith_result
+		fi
+	      done
+	      # Handle the remaining objects by creating one last
+	      # reloadable object file.  All subsequent reloadable object
+	      # files will link in the last one created.
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      reload_objs="$objlist $last_robj"
+	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
+	      if test -n "$last_robj"; then
+	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
+	      fi
+	      func_append delfiles " $output"
+
+	    else
+	      output=
+	    fi
+
+	    ${skipped_export-false} && {
+	      func_verbose "generating symbol list for '$libname.la'"
+	      export_symbols=$output_objdir/$libname.exp
+	      $opt_dry_run || $RM $export_symbols
+	      libobjs=$output
+	      # Append the command to create the export file.
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
+	      if test -n "$last_robj"; then
+		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
+	      fi
+	    }
+
+	    test -n "$save_libobjs" &&
+	      func_verbose "creating a temporary reloadable object file: $output"
+
+	    # Loop through the commands generated above and execute them.
+	    save_ifs=$IFS; IFS='~'
+	    for cmd in $concat_cmds; do
+	      IFS=$save_ifs
+	      $opt_quiet || {
+		  func_quote_for_expand "$cmd"
+		  eval "func_echo $func_quote_for_expand_result"
+	      }
+	      $opt_dry_run || eval "$cmd" || {
+		lt_exit=$?
+
+		# Restore the uninstalled library and exit
+		if test relink = "$opt_mode"; then
+		  ( cd "$output_objdir" && \
+		    $RM "${realname}T" && \
+		    $MV "${realname}U" "$realname" )
+		fi
+
+		exit $lt_exit
+	      }
+	    done
+	    IFS=$save_ifs
+
+	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
+	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
+	    fi
+	  fi
+
+          ${skipped_export-false} && {
+	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	      tmp_export_symbols=$export_symbols
+	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
+	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
+	    fi
+
+	    if test -n "$orig_export_symbols"; then
+	      # The given exports_symbols file has to be filtered, so filter it.
+	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
+	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
+	      # 's' commands, which not all seds can handle. GNU sed should be fine
+	      # though. Also, the filter scales superlinearly with the number of
+	      # global variables. join(1) would be nice here, but unfortunately
+	      # isn't a blessed tool.
+	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
+	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
+	      export_symbols=$output_objdir/$libname.def
+	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
+	    fi
+	  }
+
+	  libobjs=$output
+	  # Restore the value of output.
+	  output=$save_output
+
+	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
+	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
+	    test "X$libobjs" = "X " && libobjs=
+	  fi
+	  # Expand the library linking commands again to reset the
+	  # value of $libobjs for piecewise linking.
+
+	  # Do each of the archive commands.
+	  if test yes = "$module" && test -n "$module_cmds"; then
+	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+	      cmds=$module_expsym_cmds
+	    else
+	      cmds=$module_cmds
+	    fi
+	  else
+	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+	      cmds=$archive_expsym_cmds
+	    else
+	      cmds=$archive_cmds
+	    fi
+	  fi
+	fi
+
+	if test -n "$delfiles"; then
+	  # Append the command to remove temporary files to $cmds.
+	  eval cmds=\"\$cmds~\$RM $delfiles\"
+	fi
+
+	# Add any objects from preloaded convenience libraries
+	if test -n "$dlprefiles"; then
+	  gentop=$output_objdir/${outputname}x
+	  func_append generated " $gentop"
+
+	  func_extract_archives $gentop $dlprefiles
+	  func_append libobjs " $func_extract_archives_result"
+	  test "X$libobjs" = "X " && libobjs=
+	fi
+
+	save_ifs=$IFS; IFS='~'
+	for cmd in $cmds; do
+	  IFS=$sp$nl
+	  eval cmd=\"$cmd\"
+	  IFS=$save_ifs
+	  $opt_quiet || {
+	    func_quote_for_expand "$cmd"
+	    eval "func_echo $func_quote_for_expand_result"
+	  }
+	  $opt_dry_run || eval "$cmd" || {
+	    lt_exit=$?
+
+	    # Restore the uninstalled library and exit
+	    if test relink = "$opt_mode"; then
+	      ( cd "$output_objdir" && \
+	        $RM "${realname}T" && \
+		$MV "${realname}U" "$realname" )
+	    fi
+
+	    exit $lt_exit
+	  }
+	done
+	IFS=$save_ifs
+
+	# Restore the uninstalled library and exit
+	if test relink = "$opt_mode"; then
+	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
+
+	  if test -n "$convenience"; then
+	    if test -z "$whole_archive_flag_spec"; then
+	      func_show_eval '${RM}r "$gentop"'
+	    fi
+	  fi
+
+	  exit $EXIT_SUCCESS
+	fi
+
+	# Create links to the real library.
+	for linkname in $linknames; do
+	  if test "$realname" != "$linkname"; then
+	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
+	  fi
+	done
+
+	# If -module or -export-dynamic was specified, set the dlname.
+	if test yes = "$module" || test yes = "$export_dynamic"; then
+	  # On all known operating systems, these are identical.
+	  dlname=$soname
+	fi
+      fi
+      ;;
+
+    obj)
+      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
+	func_warning "'-dlopen' is ignored for objects"
+      fi
+
+      case " $deplibs" in
+      *\ -l* | *\ -L*)
+	func_warning "'-l' and '-L' are ignored for objects" ;;
+      esac
+
+      test -n "$rpath" && \
+	func_warning "'-rpath' is ignored for objects"
+
+      test -n "$xrpath" && \
+	func_warning "'-R' is ignored for objects"
+
+      test -n "$vinfo" && \
+	func_warning "'-version-info' is ignored for objects"
+
+      test -n "$release" && \
+	func_warning "'-release' is ignored for objects"
+
+      case $output in
+      *.lo)
+	test -n "$objs$old_deplibs" && \
+	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
+
+	libobj=$output
+	func_lo2o "$libobj"
+	obj=$func_lo2o_result
+	;;
+      *)
+	libobj=
+	obj=$output
+	;;
+      esac
+
+      # Delete the old objects.
+      $opt_dry_run || $RM $obj $libobj
+
+      # Objects from convenience libraries.  This assumes
+      # single-version convenience libraries.  Whenever we create
+      # different ones for PIC/non-PIC, this we'll have to duplicate
+      # the extraction.
+      reload_conv_objs=
+      gentop=
+      # if reload_cmds runs $LD directly, get rid of -Wl from
+      # whole_archive_flag_spec and hope we can get by with turning comma
+      # into space.
+      case $reload_cmds in
+        *\$LD[\ \$]*) wl= ;;
+      esac
+      if test -n "$convenience"; then
+	if test -n "$whole_archive_flag_spec"; then
+	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
+	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
+	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
+	else
+	  gentop=$output_objdir/${obj}x
+	  func_append generated " $gentop"
+
+	  func_extract_archives $gentop $convenience
+	  reload_conv_objs="$reload_objs $func_extract_archives_result"
+	fi
+      fi
+
+      # If we're not building shared, we need to use non_pic_objs
+      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
+
+      # Create the old-style object.
+      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
+
+      output=$obj
+      func_execute_cmds "$reload_cmds" 'exit $?'
+
+      # Exit if we aren't doing a library object file.
+      if test -z "$libobj"; then
+	if test -n "$gentop"; then
+	  func_show_eval '${RM}r "$gentop"'
+	fi
+
+	exit $EXIT_SUCCESS
+      fi
+
+      test yes = "$build_libtool_libs" || {
+	if test -n "$gentop"; then
+	  func_show_eval '${RM}r "$gentop"'
+	fi
+
+	# Create an invalid libtool object if no PIC, so that we don't
+	# accidentally link it into a program.
+	# $show "echo timestamp > $libobj"
+	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
+	exit $EXIT_SUCCESS
+      }
+
+      if test -n "$pic_flag" || test default != "$pic_mode"; then
+	# Only do commands if we really have different PIC objects.
+	reload_objs="$libobjs $reload_conv_objs"
+	output=$libobj
+	func_execute_cmds "$reload_cmds" 'exit $?'
+      fi
+
+      if test -n "$gentop"; then
+	func_show_eval '${RM}r "$gentop"'
+      fi
+
+      exit $EXIT_SUCCESS
+      ;;
+
+    prog)
+      case $host in
+	*cygwin*) func_stripname '' '.exe' "$output"
+	          output=$func_stripname_result.exe;;
+      esac
+      test -n "$vinfo" && \
+	func_warning "'-version-info' is ignored for programs"
+
+      test -n "$release" && \
+	func_warning "'-release' is ignored for programs"
+
+      $preload \
+	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
+	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
+
+      case $host in
+      *-*-rhapsody* | *-*-darwin1.[012])
+	# On Rhapsody replace the C library is the System framework
+	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
+	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
+	;;
+      esac
+
+      case $host in
+      *-*-darwin*)
+	# Don't allow lazy linking, it breaks C++ global constructors
+	# But is supposedly fixed on 10.4 or later (yay!).
+	if test CXX = "$tagname"; then
+	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
+	    10.[0123])
+	      func_append compile_command " $wl-bind_at_load"
+	      func_append finalize_command " $wl-bind_at_load"
+	    ;;
+	  esac
+	fi
+	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
+	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	;;
+      esac
+
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+	case " $new_libs " in
+	*" -L$path/$objdir "*) ;;
+	*)
+	  case " $compile_deplibs " in
+	  *" -L$path/$objdir "*)
+	    func_append new_libs " -L$path/$objdir" ;;
+	  esac
+	  ;;
+	esac
+      done
+      for deplib in $compile_deplibs; do
+	case $deplib in
+	-L*)
+	  case " $new_libs " in
+	  *" $deplib "*) ;;
+	  *) func_append new_libs " $deplib" ;;
+	  esac
+	  ;;
+	*) func_append new_libs " $deplib" ;;
+	esac
+      done
+      compile_deplibs=$new_libs
+
+
+      func_append compile_command " $compile_deplibs"
+      func_append finalize_command " $finalize_deplibs"
+
+      if test -n "$rpath$xrpath"; then
+	# If the user specified any rpath flags, then add them.
+	for libdir in $rpath $xrpath; do
+	  # This is the magic to use -rpath.
+	  case "$finalize_rpath " in
+	  *" $libdir "*) ;;
+	  *) func_append finalize_rpath " $libdir" ;;
+	  esac
+	done
+      fi
+
+      # Now hardcode the library paths
+      rpath=
+      hardcode_libdirs=
+      for libdir in $compile_rpath $finalize_rpath; do
+	if test -n "$hardcode_libdir_flag_spec"; then
+	  if test -n "$hardcode_libdir_separator"; then
+	    if test -z "$hardcode_libdirs"; then
+	      hardcode_libdirs=$libdir
+	    else
+	      # Just accumulate the unique libdirs.
+	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		;;
+	      *)
+		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
+		;;
+	      esac
+	    fi
+	  else
+	    eval flag=\"$hardcode_libdir_flag_spec\"
+	    func_append rpath " $flag"
+	  fi
+	elif test -n "$runpath_var"; then
+	  case "$perm_rpath " in
+	  *" $libdir "*) ;;
+	  *) func_append perm_rpath " $libdir" ;;
+	  esac
+	fi
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
+	  case :$dllsearchpath: in
+	  *":$libdir:"*) ;;
+	  ::) dllsearchpath=$libdir;;
+	  *) func_append dllsearchpath ":$libdir";;
+	  esac
+	  case :$dllsearchpath: in
+	  *":$testbindir:"*) ;;
+	  ::) dllsearchpath=$testbindir;;
+	  *) func_append dllsearchpath ":$testbindir";;
+	  esac
+	  ;;
+	esac
+      done
+      # Substitute the hardcoded libdirs into the rpath.
+      if test -n "$hardcode_libdir_separator" &&
+	 test -n "$hardcode_libdirs"; then
+	libdir=$hardcode_libdirs
+	eval rpath=\" $hardcode_libdir_flag_spec\"
+      fi
+      compile_rpath=$rpath
+
+      rpath=
+      hardcode_libdirs=
+      for libdir in $finalize_rpath; do
+	if test -n "$hardcode_libdir_flag_spec"; then
+	  if test -n "$hardcode_libdir_separator"; then
+	    if test -z "$hardcode_libdirs"; then
+	      hardcode_libdirs=$libdir
+	    else
+	      # Just accumulate the unique libdirs.
+	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		;;
+	      *)
+		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
+		;;
+	      esac
+	    fi
+	  else
+	    eval flag=\"$hardcode_libdir_flag_spec\"
+	    func_append rpath " $flag"
+	  fi
+	elif test -n "$runpath_var"; then
+	  case "$finalize_perm_rpath " in
+	  *" $libdir "*) ;;
+	  *) func_append finalize_perm_rpath " $libdir" ;;
+	  esac
+	fi
+      done
+      # Substitute the hardcoded libdirs into the rpath.
+      if test -n "$hardcode_libdir_separator" &&
+	 test -n "$hardcode_libdirs"; then
+	libdir=$hardcode_libdirs
+	eval rpath=\" $hardcode_libdir_flag_spec\"
+      fi
+      finalize_rpath=$rpath
+
+      if test -n "$libobjs" && test yes = "$build_old_libs"; then
+	# Transform all the library objects into standard objects.
+	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
+	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
+      fi
+
+      func_generate_dlsyms "$outputname" "@PROGRAM@" false
+
+      # template prelinking step
+      if test -n "$prelink_cmds"; then
+	func_execute_cmds "$prelink_cmds" 'exit $?'
+      fi
+
+      wrappers_required=:
+      case $host in
+      *cegcc* | *mingw32ce*)
+        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
+        wrappers_required=false
+        ;;
+      *cygwin* | *mingw* )
+        test yes = "$build_libtool_libs" || wrappers_required=false
+        ;;
+      *)
+        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
+          wrappers_required=false
+        fi
+        ;;
+      esac
+      $wrappers_required || {
+	# Replace the output file specification.
+	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
+	link_command=$compile_command$compile_rpath
+
+	# We have no uninstalled library dependencies, so finalize right now.
+	exit_status=0
+	func_show_eval "$link_command" 'exit_status=$?'
+
+	if test -n "$postlink_cmds"; then
+	  func_to_tool_file "$output"
+	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
+	  func_execute_cmds "$postlink_cmds" 'exit $?'
+	fi
+
+	# Delete the generated files.
+	if test -f "$output_objdir/${outputname}S.$objext"; then
+	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
+	fi
+
+	exit $exit_status
+      }
+
+      if test -n "$compile_shlibpath$finalize_shlibpath"; then
+	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
+      fi
+      if test -n "$finalize_shlibpath"; then
+	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
+      fi
+
+      compile_var=
+      finalize_var=
+      if test -n "$runpath_var"; then
+	if test -n "$perm_rpath"; then
+	  # We should set the runpath_var.
+	  rpath=
+	  for dir in $perm_rpath; do
+	    func_append rpath "$dir:"
+	  done
+	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
+	fi
+	if test -n "$finalize_perm_rpath"; then
+	  # We should set the runpath_var.
+	  rpath=
+	  for dir in $finalize_perm_rpath; do
+	    func_append rpath "$dir:"
+	  done
+	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
+	fi
+      fi
+
+      if test yes = "$no_install"; then
+	# We don't need to create a wrapper script.
+	link_command=$compile_var$compile_command$compile_rpath
+	# Replace the output file specification.
+	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
+	# Delete the old output file.
+	$opt_dry_run || $RM $output
+	# Link the executable and exit
+	func_show_eval "$link_command" 'exit $?'
+
+	if test -n "$postlink_cmds"; then
+	  func_to_tool_file "$output"
+	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
+	  func_execute_cmds "$postlink_cmds" 'exit $?'
+	fi
+
+	exit $EXIT_SUCCESS
+      fi
+
+      case $hardcode_action,$fast_install in
+        relink,*)
+	  # Fast installation is not supported
+	  link_command=$compile_var$compile_command$compile_rpath
+	  relink_command=$finalize_var$finalize_command$finalize_rpath
+
+	  func_warning "this platform does not like uninstalled shared libraries"
+	  func_warning "'$output' will be relinked during installation"
+	  ;;
+        *,yes)
+	  link_command=$finalize_var$compile_command$finalize_rpath
+	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
+          ;;
+	*,no)
+	  link_command=$compile_var$compile_command$compile_rpath
+	  relink_command=$finalize_var$finalize_command$finalize_rpath
+          ;;
+	*,needless)
+	  link_command=$finalize_var$compile_command$finalize_rpath
+	  relink_command=
+          ;;
+      esac
+
+      # Replace the output file specification.
+      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
+
+      # Delete the old output files.
+      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
+
+      func_show_eval "$link_command" 'exit $?'
+
+      if test -n "$postlink_cmds"; then
+	func_to_tool_file "$output_objdir/$outputname"
+	postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
+	func_execute_cmds "$postlink_cmds" 'exit $?'
+      fi
+
+      # Now create the wrapper script.
+      func_verbose "creating $output"
+
+      # Quote the relink command for shipping.
+      if test -n "$relink_command"; then
+	# Preserve any variables that may affect compiler behavior
+	for var in $variables_saved_for_relink; do
+	  if eval test -z \"\${$var+set}\"; then
+	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
+	  elif eval var_value=\$$var; test -z "$var_value"; then
+	    relink_command="$var=; export $var; $relink_command"
+	  else
+	    func_quote_for_eval "$var_value"
+	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
+	  fi
+	done
+	func_quote "(cd `pwd`; $relink_command)"
+	relink_command=$func_quote_result
+      fi
+
+      # Only actually do things if not in dry run mode.
+      $opt_dry_run || {
+	# win32 will think the script is a binary if it has
+	# a .exe suffix, so we strip it off here.
+	case $output in
+	  *.exe) func_stripname '' '.exe' "$output"
+	         output=$func_stripname_result ;;
+	esac
+	# test for cygwin because mv fails w/o .exe extensions
+	case $host in
+	  *cygwin*)
+	    exeext=.exe
+	    func_stripname '' '.exe' "$outputname"
+	    outputname=$func_stripname_result ;;
+	  *) exeext= ;;
+	esac
+	case $host in
+	  *cygwin* | *mingw* )
+	    func_dirname_and_basename "$output" "" "."
+	    output_name=$func_basename_result
+	    output_path=$func_dirname_result
+	    cwrappersource=$output_path/$objdir/lt-$output_name.c
+	    cwrapper=$output_path/$output_name.exe
+	    $RM $cwrappersource $cwrapper
+	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
+
+	    func_emit_cwrapperexe_src > $cwrappersource
+
+	    # The wrapper executable is built using the $host compiler,
+	    # because it contains $host paths and files. If cross-
+	    # compiling, it, like the target executable, must be
+	    # executed on the $host or under an emulation environment.
+	    $opt_dry_run || {
+	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
+	      $STRIP $cwrapper
+	    }
+
+	    # Now, create the wrapper script for func_source use:
+	    func_ltwrapper_scriptname $cwrapper
+	    $RM $func_ltwrapper_scriptname_result
+	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
+	    $opt_dry_run || {
+	      # note: this script will not be executed, so do not chmod.
+	      if test "x$build" = "x$host"; then
+		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
+	      else
+		func_emit_wrapper no > $func_ltwrapper_scriptname_result
+	      fi
+	    }
+	  ;;
+	  * )
+	    $RM $output
+	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
+
+	    func_emit_wrapper no > $output
+	    chmod +x $output
+	  ;;
+	esac
+      }
+      exit $EXIT_SUCCESS
+      ;;
+    esac
+
+    # See if we need to build an old-fashioned archive.
+    for oldlib in $oldlibs; do
+
+      case $build_libtool_libs in
+        convenience)
+	  oldobjs="$libobjs_save $symfileobj"
+	  addlibs=$convenience
+	  build_libtool_libs=no
+	  ;;
+	module)
+	  oldobjs=$libobjs_save
+	  addlibs=$old_convenience
+	  build_libtool_libs=no
+          ;;
+	*)
+	  oldobjs="$old_deplibs $non_pic_objects"
+	  $preload && test -f "$symfileobj" \
+	    && func_append oldobjs " $symfileobj"
+	  addlibs=$old_convenience
+	  ;;
+      esac
+
+      if test -n "$addlibs"; then
+	gentop=$output_objdir/${outputname}x
+	func_append generated " $gentop"
+
+	func_extract_archives $gentop $addlibs
+	func_append oldobjs " $func_extract_archives_result"
+      fi
+
+      # Do each command in the archive commands.
+      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
+	cmds=$old_archive_from_new_cmds
+      else
+
+	# Add any objects from preloaded convenience libraries
+	if test -n "$dlprefiles"; then
+	  gentop=$output_objdir/${outputname}x
+	  func_append generated " $gentop"
+
+	  func_extract_archives $gentop $dlprefiles
+	  func_append oldobjs " $func_extract_archives_result"
+	fi
+
+	# POSIX demands no paths to be encoded in archives.  We have
+	# to avoid creating archives with duplicate basenames if we
+	# might have to extract them afterwards, e.g., when creating a
+	# static archive out of a convenience library, or when linking
+	# the entirety of a libtool archive into another (currently
+	# not supported by libtool).
+	if (for obj in $oldobjs
+	    do
+	      func_basename "$obj"
+	      $ECHO "$func_basename_result"
+	    done | sort | sort -uc >/dev/null 2>&1); then
+	  :
+	else
+	  echo "copying selected object files to avoid basename conflicts..."
+	  gentop=$output_objdir/${outputname}x
+	  func_append generated " $gentop"
+	  func_mkdir_p "$gentop"
+	  save_oldobjs=$oldobjs
+	  oldobjs=
+	  counter=1
+	  for obj in $save_oldobjs
+	  do
+	    func_basename "$obj"
+	    objbase=$func_basename_result
+	    case " $oldobjs " in
+	    " ") oldobjs=$obj ;;
+	    *[\ /]"$objbase "*)
+	      while :; do
+		# Make sure we don't pick an alternate name that also
+		# overlaps.
+		newobj=lt$counter-$objbase
+		func_arith $counter + 1
+		counter=$func_arith_result
+		case " $oldobjs " in
+		*[\ /]"$newobj "*) ;;
+		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
+		esac
+	      done
+	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
+	      func_append oldobjs " $gentop/$newobj"
+	      ;;
+	    *) func_append oldobjs " $obj" ;;
+	    esac
+	  done
+	fi
+	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
+	tool_oldlib=$func_to_tool_file_result
+	eval cmds=\"$old_archive_cmds\"
+
+	func_len " $cmds"
+	len=$func_len_result
+	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	  cmds=$old_archive_cmds
+	elif test -n "$archiver_list_spec"; then
+	  func_verbose "using command file archive linking..."
+	  for obj in $oldobjs
+	  do
+	    func_to_tool_file "$obj"
+	    $ECHO "$func_to_tool_file_result"
+	  done > $output_objdir/$libname.libcmd
+	  func_to_tool_file "$output_objdir/$libname.libcmd"
+	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
+	  cmds=$old_archive_cmds
+	else
+	  # the command line is too long to link in one step, link in parts
+	  func_verbose "using piecewise archive linking..."
+	  save_RANLIB=$RANLIB
+	  RANLIB=:
+	  objlist=
+	  concat_cmds=
+	  save_oldobjs=$oldobjs
+	  oldobjs=
+	  # Is there a better way of finding the last object in the list?
+	  for obj in $save_oldobjs
+	  do
+	    last_oldobj=$obj
+	  done
+	  eval test_cmds=\"$old_archive_cmds\"
+	  func_len " $test_cmds"
+	  len0=$func_len_result
+	  len=$len0
+	  for obj in $save_oldobjs
+	  do
+	    func_len " $obj"
+	    func_arith $len + $func_len_result
+	    len=$func_arith_result
+	    func_append objlist " $obj"
+	    if test "$len" -lt "$max_cmd_len"; then
+	      :
+	    else
+	      # the above command should be used before it gets too long
+	      oldobjs=$objlist
+	      if test "$obj" = "$last_oldobj"; then
+		RANLIB=$save_RANLIB
+	      fi
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
+	      objlist=
+	      len=$len0
+	    fi
+	  done
+	  RANLIB=$save_RANLIB
+	  oldobjs=$objlist
+	  if test -z "$oldobjs"; then
+	    eval cmds=\"\$concat_cmds\"
+	  else
+	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
+	  fi
+	fi
+      fi
+      func_execute_cmds "$cmds" 'exit $?'
+    done
+
+    test -n "$generated" && \
+      func_show_eval "${RM}r$generated"
+
+    # Now create the libtool archive.
+    case $output in
+    *.la)
+      old_library=
+      test yes = "$build_old_libs" && old_library=$libname.$libext
+      func_verbose "creating $output"
+
+      # Preserve any variables that may affect compiler behavior
+      for var in $variables_saved_for_relink; do
+	if eval test -z \"\${$var+set}\"; then
+	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
+	elif eval var_value=\$$var; test -z "$var_value"; then
+	  relink_command="$var=; export $var; $relink_command"
+	else
+	  func_quote_for_eval "$var_value"
+	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
+	fi
+      done
+      # Quote the link command for shipping.
+      relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
+      func_quote "$relink_command"
+      relink_command=$func_quote_result
+      if test yes = "$hardcode_automatic"; then
+	relink_command=
+      fi
+
+      # Only create the output if not a dry run.
+      $opt_dry_run || {
+	for installed in no yes; do
+	  if test yes = "$installed"; then
+	    if test -z "$install_libdir"; then
+	      break
+	    fi
+	    output=$output_objdir/${outputname}i
+	    # Replace all uninstalled libtool libraries with the installed ones
+	    newdependency_libs=
+	    for deplib in $dependency_libs; do
+	      case $deplib in
+	      *.la)
+		func_basename "$deplib"
+		name=$func_basename_result
+		func_resolve_sysroot "$deplib"
+		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
+		test -z "$libdir" && \
+		  func_fatal_error "'$deplib' is not a valid libtool archive"
+		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
+		;;
+	      -L*)
+		func_stripname -L '' "$deplib"
+		func_replace_sysroot "$func_stripname_result"
+		func_append newdependency_libs " -L$func_replace_sysroot_result"
+		;;
+	      -R*)
+		func_stripname -R '' "$deplib"
+		func_replace_sysroot "$func_stripname_result"
+		func_append newdependency_libs " -R$func_replace_sysroot_result"
+		;;
+	      *) func_append newdependency_libs " $deplib" ;;
+	      esac
+	    done
+	    dependency_libs=$newdependency_libs
+	    newdlfiles=
+
+	    for lib in $dlfiles; do
+	      case $lib in
+	      *.la)
+	        func_basename "$lib"
+		name=$func_basename_result
+		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+		test -z "$libdir" && \
+		  func_fatal_error "'$lib' is not a valid libtool archive"
+		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
+		;;
+	      *) func_append newdlfiles " $lib" ;;
+	      esac
+	    done
+	    dlfiles=$newdlfiles
+	    newdlprefiles=
+	    for lib in $dlprefiles; do
+	      case $lib in
+	      *.la)
+		# Only pass preopened files to the pseudo-archive (for
+		# eventual linking with the app. that links it) if we
+		# didn't already link the preopened objects directly into
+		# the library:
+		func_basename "$lib"
+		name=$func_basename_result
+		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+		test -z "$libdir" && \
+		  func_fatal_error "'$lib' is not a valid libtool archive"
+		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
+		;;
+	      esac
+	    done
+	    dlprefiles=$newdlprefiles
+	  else
+	    newdlfiles=
+	    for lib in $dlfiles; do
+	      case $lib in
+		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
+		*) abs=`pwd`"/$lib" ;;
+	      esac
+	      func_append newdlfiles " $abs"
+	    done
+	    dlfiles=$newdlfiles
+	    newdlprefiles=
+	    for lib in $dlprefiles; do
+	      case $lib in
+		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
+		*) abs=`pwd`"/$lib" ;;
+	      esac
+	      func_append newdlprefiles " $abs"
+	    done
+	    dlprefiles=$newdlprefiles
+	  fi
+	  $RM $output
+	  # place dlname in correct position for cygwin
+	  # In fact, it would be nice if we could use this code for all target
+	  # systems that can't hard-code library paths into their executables
+	  # and that have no shared library path variable independent of PATH,
+	  # but it turns out we can't easily determine that from inspecting
+	  # libtool variables, so we have to hard-code the OSs to which it
+	  # applies here; at the moment, that means platforms that use the PE
+	  # object format with DLL files.  See the long comment at the top of
+	  # tests/bindir.at for full details.
+	  tdlname=$dlname
+	  case $host,$output,$installed,$module,$dlname in
+	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
+	      # If a -bindir argument was supplied, place the dll there.
+	      if test -n "$bindir"; then
+		func_relative_path "$install_libdir" "$bindir"
+		tdlname=$func_relative_path_result/$dlname
+	      else
+		# Otherwise fall back on heuristic.
+		tdlname=../bin/$dlname
+	      fi
+	      ;;
+	  esac
+	  $ECHO > $output "\
+# $outputname - a libtool library file
+# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# The name that we can dlopen(3).
+dlname='$tdlname'
+
+# Names of this library.
+library_names='$library_names'
+
+# The name of the static archive.
+old_library='$old_library'
+
+# Linker flags that cannot go in dependency_libs.
+inherited_linker_flags='$new_inherited_linker_flags'
+
+# Libraries that this one depends upon.
+dependency_libs='$dependency_libs'
+
+# Names of additional weak libraries provided by this library
+weak_library_names='$weak_libs'
+
+# Version information for $libname.
+current=$current
+age=$age
+revision=$revision
+
+# Is this an already installed library?
+installed=$installed
+
+# Should we warn about portability when linking against -modules?
+shouldnotlink=$module
+
+# Files to dlopen/dlpreopen
+dlopen='$dlfiles'
+dlpreopen='$dlprefiles'
+
+# Directory that this library needs to be installed in:
+libdir='$install_libdir'"
+	  if test no,yes = "$installed,$need_relink"; then
+	    $ECHO >> $output "\
+relink_command=\"$relink_command\""
+	  fi
+	done
+      }
+
+      # Do a symbolic link so that the libtool archive can be found in
+      # LD_LIBRARY_PATH before the program is installed.
+      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
+      ;;
+    esac
+    exit $EXIT_SUCCESS
+}
+
+if test link = "$opt_mode" || test relink = "$opt_mode"; then
+  func_mode_link ${1+"$@"}
+fi
+
+
+# func_mode_uninstall arg...
+func_mode_uninstall ()
+{
+    $debug_cmd
+
+    RM=$nonopt
+    files=
+    rmforce=false
+    exit_status=0
+
+    # This variable tells wrapper scripts just to set variables rather
+    # than running their programs.
+    libtool_install_magic=$magic
+
+    for arg
+    do
+      case $arg in
+      -f) func_append RM " $arg"; rmforce=: ;;
+      -*) func_append RM " $arg" ;;
+      *) func_append files " $arg" ;;
+      esac
+    done
+
+    test -z "$RM" && \
+      func_fatal_help "you must specify an RM program"
+
+    rmdirs=
+
+    for file in $files; do
+      func_dirname "$file" "" "."
+      dir=$func_dirname_result
+      if test . = "$dir"; then
+	odir=$objdir
+      else
+	odir=$dir/$objdir
+      fi
+      func_basename "$file"
+      name=$func_basename_result
+      test uninstall = "$opt_mode" && odir=$dir
+
+      # Remember odir for removal later, being careful to avoid duplicates
+      if test clean = "$opt_mode"; then
+	case " $rmdirs " in
+	  *" $odir "*) ;;
+	  *) func_append rmdirs " $odir" ;;
+	esac
+      fi
+
+      # Don't error if the file doesn't exist and rm -f was used.
+      if { test -L "$file"; } >/dev/null 2>&1 ||
+	 { test -h "$file"; } >/dev/null 2>&1 ||
+	 test -f "$file"; then
+	:
+      elif test -d "$file"; then
+	exit_status=1
+	continue
+      elif $rmforce; then
+	continue
+      fi
+
+      rmfiles=$file
+
+      case $name in
+      *.la)
+	# Possibly a libtool archive, so verify it.
+	if func_lalib_p "$file"; then
+	  func_source $dir/$name
+
+	  # Delete the libtool libraries and symlinks.
+	  for n in $library_names; do
+	    func_append rmfiles " $odir/$n"
+	  done
+	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
+
+	  case $opt_mode in
+	  clean)
+	    case " $library_names " in
+	    *" $dlname "*) ;;
+	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
+	    esac
+	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
+	    ;;
+	  uninstall)
+	    if test -n "$library_names"; then
+	      # Do each command in the postuninstall commands.
+	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
+	    fi
+
+	    if test -n "$old_library"; then
+	      # Do each command in the old_postuninstall commands.
+	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
+	    fi
+	    # FIXME: should reinstall the best remaining shared library.
+	    ;;
+	  esac
+	fi
+	;;
+
+      *.lo)
+	# Possibly a libtool object, so verify it.
+	if func_lalib_p "$file"; then
+
+	  # Read the .lo file
+	  func_source $dir/$name
+
+	  # Add PIC object to the list of files to remove.
+	  if test -n "$pic_object" && test none != "$pic_object"; then
+	    func_append rmfiles " $dir/$pic_object"
+	  fi
+
+	  # Add non-PIC object to the list of files to remove.
+	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
+	    func_append rmfiles " $dir/$non_pic_object"
+	  fi
+	fi
+	;;
+
+      *)
+	if test clean = "$opt_mode"; then
+	  noexename=$name
+	  case $file in
+	  *.exe)
+	    func_stripname '' '.exe' "$file"
+	    file=$func_stripname_result
+	    func_stripname '' '.exe' "$name"
+	    noexename=$func_stripname_result
+	    # $file with .exe has already been added to rmfiles,
+	    # add $file without .exe
+	    func_append rmfiles " $file"
+	    ;;
+	  esac
+	  # Do a test to see if this is a libtool program.
+	  if func_ltwrapper_p "$file"; then
+	    if func_ltwrapper_executable_p "$file"; then
+	      func_ltwrapper_scriptname "$file"
+	      relink_command=
+	      func_source $func_ltwrapper_scriptname_result
+	      func_append rmfiles " $func_ltwrapper_scriptname_result"
+	    else
+	      relink_command=
+	      func_source $dir/$noexename
+	    fi
+
+	    # note $name still contains .exe if it was in $file originally
+	    # as does the version of $file that was added into $rmfiles
+	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
+	    if test yes = "$fast_install" && test -n "$relink_command"; then
+	      func_append rmfiles " $odir/lt-$name"
+	    fi
+	    if test "X$noexename" != "X$name"; then
+	      func_append rmfiles " $odir/lt-$noexename.c"
+	    fi
+	  fi
+	fi
+	;;
+      esac
+      func_show_eval "$RM $rmfiles" 'exit_status=1'
+    done
+
+    # Try to remove the $objdir's in the directories where we deleted files
+    for dir in $rmdirs; do
+      if test -d "$dir"; then
+	func_show_eval "rmdir $dir >/dev/null 2>&1"
+      fi
+    done
+
+    exit $exit_status
+}
+
+if test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
+  func_mode_uninstall ${1+"$@"}
+fi
+
+test -z "$opt_mode" && {
+  help=$generic_help
+  func_fatal_help "you must specify a MODE"
+}
+
+test -z "$exec_cmd" && \
+  func_fatal_help "invalid operation mode '$opt_mode'"
+
+if test -n "$exec_cmd"; then
+  eval exec "$exec_cmd"
+  exit $EXIT_FAILURE
+fi
+
+exit $exit_status
+
+
+# The TAGs below are defined such that we never get into a situation
+# where we disable both kinds of libraries.  Given conflicting
+# choices, we go for a static library, that is the most portable,
+# since we can't tell whether shared libraries were disabled because
+# the user asked for that or because the platform doesn't support
+# them.  This is particularly important on AIX, because we don't
+# support having both static and shared libraries enabled at the same
+# time on that platform, so we default to a shared-only configuration.
+# If a disable-shared tag is given, we'll fallback to a static-only
+# configuration.  But we'll never go from static-only to shared-only.
+
+# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
+build_libtool_libs=no
+build_old_libs=yes
+# ### END LIBTOOL TAG CONFIG: disable-shared
+
+# ### BEGIN LIBTOOL TAG CONFIG: disable-static
+build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
+# ### END LIBTOOL TAG CONFIG: disable-static
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:2
+# End:

diff --git a/missing b/missing
new file mode 100755
index 0000000..c6e3795
--- /dev/null
+++ b/missing
@@ -0,0 +1,215 @@
+#! /bin/sh
+# Common wrapper for a few potentially missing GNU programs.
+
+scriptversion=2016-01-11.22; # UTC
+
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.
+# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+if test $# -eq 0; then
+  echo 1>&2 "Try '$0 --help' for more information"
+  exit 1
+fi
+
+case $1 in
+
+  --is-lightweight)
+    # Used by our autoconf macros to check whether the available missing
+    # script is modern enough.
+    exit 0
+    ;;
+
+  --run)
+    # Back-compat with the calling convention used by older automake.
+    shift
+    ;;
+
+  -h|--h|--he|--hel|--help)
+    echo "\
+$0 [OPTION]... PROGRAM [ARGUMENT]...
+
+Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
+to PROGRAM being missing or too old.
+
+Options:
+  -h, --help      display this help and exit
+  -v, --version   output version information and exit
+
+Supported PROGRAM values:
+  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
+  bison     yacc      flex         lex       help2man
+
+Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
+'g' are ignored when checking the name.
+
+Send bug reports to <bug-automake@gnu.org>."
+    exit $?
+    ;;
+
+  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+    echo "missing $scriptversion (GNU Automake)"
+    exit $?
+    ;;
+
+  -*)
+    echo 1>&2 "$0: unknown '$1' option"
+    echo 1>&2 "Try '$0 --help' for more information"
+    exit 1
+    ;;
+
+esac
+
+# Run the given program, remember its exit status.
+"$@"; st=$?
+
+# If it succeeded, we are done.
+test $st -eq 0 && exit 0
+
+# Also exit now if we it failed (or wasn't found), and '--version' was
+# passed; such an option is passed most likely to detect whether the
+# program is present and works.
+case $2 in --version|--help) exit $st;; esac
+
+# Exit code 63 means version mismatch.  This often happens when the user
+# tries to use an ancient version of a tool on a file that requires a
+# minimum version.
+if test $st -eq 63; then
+  msg="probably too old"
+elif test $st -eq 127; then
+  # Program was missing.
+  msg="missing on your system"
+else
+  # Program was found and executed, but failed.  Give up.
+  exit $st
+fi
+
+perl_URL=http://www.perl.org/
+flex_URL=http://flex.sourceforge.net/
+gnu_software_URL=http://www.gnu.org/software
+
+program_details ()
+{
+  case $1 in
+    aclocal|automake)
+      echo "The '$1' program is part of the GNU Automake package:"
+      echo "<$gnu_software_URL/automake>"
+      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
+      echo "<$gnu_software_URL/autoconf>"
+      echo "<$gnu_software_URL/m4/>"
+      echo "<$perl_URL>"
+      ;;
+    autoconf|autom4te|autoheader)
+      echo "The '$1' program is part of the GNU Autoconf package:"
+      echo "<$gnu_software_URL/autoconf/>"
+      echo "It also requires GNU m4 and Perl in order to run:"
+      echo "<$gnu_software_URL/m4/>"
+      echo "<$perl_URL>"
+      ;;
+  esac
+}
+
+give_advice ()
+{
+  # Normalize program name to check for.
+  normalized_program=`echo "$1" | sed '
+    s/^gnu-//; t
+    s/^gnu//; t
+    s/^g//; t'`
+
+  printf '%s\n' "'$1' is $msg."
+
+  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
+  case $normalized_program in
+    autoconf*)
+      echo "You should only need it if you modified 'configure.ac',"
+      echo "or m4 files included by it."
+      program_details 'autoconf'
+      ;;
+    autoheader*)
+      echo "You should only need it if you modified 'acconfig.h' or"
+      echo "$configure_deps."
+      program_details 'autoheader'
+      ;;
+    automake*)
+      echo "You should only need it if you modified 'Makefile.am' or"
+      echo "$configure_deps."
+      program_details 'automake'
+      ;;
+    aclocal*)
+      echo "You should only need it if you modified 'acinclude.m4' or"
+      echo "$configure_deps."
+      program_details 'aclocal'
+      ;;
+   autom4te*)
+      echo "You might have modified some maintainer files that require"
+      echo "the 'autom4te' program to be rebuilt."
+      program_details 'autom4te'
+      ;;
+    bison*|yacc*)
+      echo "You should only need it if you modified a '.y' file."
+      echo "You may want to install the GNU Bison package:"
+      echo "<$gnu_software_URL/bison/>"
+      ;;
+    lex*|flex*)
+      echo "You should only need it if you modified a '.l' file."
+      echo "You may want to install the Fast Lexical Analyzer package:"
+      echo "<$flex_URL>"
+      ;;
+    help2man*)
+      echo "You should only need it if you modified a dependency" \
+           "of a man page."
+      echo "You may want to install the GNU Help2man package:"
+      echo "<$gnu_software_URL/help2man/>"
+    ;;
+    makeinfo*)
+      echo "You should only need it if you modified a '.texi' file, or"
+      echo "any other file indirectly affecting the aspect of the manual."
+      echo "You might want to install the Texinfo package:"
+      echo "<$gnu_software_URL/texinfo/>"
+      echo "The spurious makeinfo call might also be the consequence of"
+      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
+      echo "want to install GNU make:"
+      echo "<$gnu_software_URL/make/>"
+      ;;
+    *)
+      echo "You might have modified some files without having the proper"
+      echo "tools for further handling them.  Check the 'README' file, it"
+      echo "often tells you about the needed prerequisites for installing"
+      echo "this package.  You may also peek at any GNU archive site, in"
+      echo "case some other package contains this missing '$1' program."
+      ;;
+  esac
+}
+
+give_advice "$1" | sed -e '1s/^/WARNING: /' \
+                       -e '2,$s/^/         /' >&2
+
+# Propagate the correct exit status (expected to be 127 for a program
+# not found, 63 for a program that failed due to version mismatch).
+exit $st
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC0"
+# time-stamp-end: "; # UTC"
+# End:


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-03-19 20:32 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-03-19 20:32 UTC (permalink / raw
  To: gentoo-commits

commit:     741684c0be529d9cb7ea91a48b801ca6859d2e9d
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 19 19:49:50 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Mar 19 19:49:50 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=741684c0

build: fix misc issues found on Linux

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 configure      | 36 ++++++++++++++++++++++++++++++++++++
 configure.ac   |  1 +
 libq/atom.c    |  1 +
 libq/prelink.c |  1 +
 libq/safe_io.c |  1 +
 libq/xchdir.c  |  1 +
 libq/xmkdir.c  |  2 ++
 main.c         |  1 +
 qmerge.c       |  2 ++
 9 files changed, 46 insertions(+)

diff --git a/configure b/configure
index ad96730..ce1fbde 100755
--- a/configure
+++ b/configure
@@ -35001,6 +35001,42 @@ else
 fi
 
 
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -Wno-expansion-to-defined" >&5
+$as_echo_n "checking whether C compiler accepts -Wno-expansion-to-defined... " >&6; }
+if ${ax_cv_check_cflags___Wno_expansion_to_defined+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+  ax_check_save_flags=$CFLAGS
+  CFLAGS="$CFLAGS  -Wno-expansion-to-defined"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ax_cv_check_cflags___Wno_expansion_to_defined=yes
+else
+  ax_cv_check_cflags___Wno_expansion_to_defined=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  CFLAGS=$ax_check_save_flags
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___Wno_expansion_to_defined" >&5
+$as_echo "$ax_cv_check_cflags___Wno_expansion_to_defined" >&6; }
+if test "x$ax_cv_check_cflags___Wno_expansion_to_defined" = xyes; then :
+  as_fn_append CFLAGS " -Wno-expansion-to-defined"
+else
+  :
+fi
+
+
 
 ac_config_files="$ac_config_files Makefile libq/Makefile autotools/gnulib/Makefile tests/atom_explode/Makefile tests/copy_file/Makefile tests/mkdir/Makefile tests/rmspace/Makefile"
 

diff --git a/configure.ac b/configure.ac
index 870a059..55346a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,6 +48,7 @@ m4_foreach_w([flag], [
 	-Wsequence-point
 	-Wold-style-definition
 	-Wextra
+	-Wno-expansion-to-defined
 ], [
 	AX_CHECK_COMPILE_FLAG(flag, AS_VAR_APPEND([CFLAGS], " flag"))
 ])

diff --git a/libq/atom.c b/libq/atom.c
index e5c3dc1..60a37ce 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -11,6 +11,7 @@
 #include "atom.h"
 
 #include <unistd.h>
+#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include <xalloc.h>

diff --git a/libq/prelink.c b/libq/prelink.c
index 0d1ce83..0cda2c5 100644
--- a/libq/prelink.c
+++ b/libq/prelink.c
@@ -11,6 +11,7 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <stdlib.h>
 
 #include "xasprintf.h"
 #include "prelink.h"

diff --git a/libq/safe_io.c b/libq/safe_io.c
index e209c87..a1c7687 100644
--- a/libq/safe_io.c
+++ b/libq/safe_io.c
@@ -8,6 +8,7 @@
 #include "main.h"
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <errno.h>
 
 #define _IN_SAFE_IO 1

diff --git a/libq/xchdir.c b/libq/xchdir.c
index 2d649ad..a208fbc 100644
--- a/libq/xchdir.c
+++ b/libq/xchdir.c
@@ -8,6 +8,7 @@
 #include "main.h"
 
 #include <unistd.h>
+#include <stdlib.h>
 
 #include "xchdir.h"
 

diff --git a/libq/xmkdir.c b/libq/xmkdir.c
index 2e60b08..8a5aab9 100644
--- a/libq/xmkdir.c
+++ b/libq/xmkdir.c
@@ -8,6 +8,8 @@
 
 #include "main.h"
 
+#include <stdlib.h>
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>

diff --git a/main.c b/main.c
index 1749114..6b4153a 100644
--- a/main.c
+++ b/main.c
@@ -36,6 +36,7 @@
 #include <assert.h>
 #include <ctype.h>
 #include <sys/time.h>
+#include <limits.h>
 
 #if defined(__sun) && defined(__SVR4)
 /* workaround non-const defined name in option struct, such that we

diff --git a/qmerge.c b/qmerge.c
index 3388ed3..5ebb55e 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -10,6 +10,8 @@
 #ifdef APPLET_qmerge
 
 #include <fnmatch.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include "stat-time.h"
 
 #ifndef GLOB_BRACE


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-03-22  9:57 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-03-22  9:57 UTC (permalink / raw
  To: gentoo-commits

commit:     ad69607fe21bde3192f230b926facdc1b7a57cbd
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Mar 22 09:57:05 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Mar 22 09:57:05 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ad69607f

remove_extra_space: move to libq/rmspace

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/rmspace.c | 34 ++++++++++++++++++++++++++++++++++
 libq/rmspace.h |  1 +
 main.c         | 31 +++----------------------------
 3 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/libq/rmspace.c b/libq/rmspace.c
index a43354d..f3b8e37 100644
--- a/libq/rmspace.c
+++ b/libq/rmspace.c
@@ -7,9 +7,12 @@
  * Copyright 2019-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
+#include "main.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <xalloc.h>
 
 #include "rmspace.h"
 
@@ -35,3 +38,34 @@ char *rmspace(char *s)
 {
 	return rmspace_len(s, strlen(s));
 }
+
+/* removes adjacent extraneous white space */
+char *
+remove_extra_space(char *str)
+{
+	char *p, c = ' ';
+	size_t len, pos = 0;
+	char *buf;
+
+	if (str == NULL)
+		return NULL;
+	len = strlen(str);
+	buf = xmalloc(len+1);
+	for (p = str; *p != 0; ++p) {
+		if (!isspace(*p)) {
+			c = *p;
+		} else {
+			if (c == ' ')
+				continue;
+			c = ' ';
+		}
+		buf[pos] = c;
+		pos++;
+	}
+	buf[pos] = '\0';
+	if (pos > 0 && buf[pos-1] == ' ')
+		buf[pos-1] = '\0';
+	strcpy(str, buf);
+	free(buf);
+	return str;
+}

diff --git a/libq/rmspace.h b/libq/rmspace.h
index f70d732..e37d121 100644
--- a/libq/rmspace.h
+++ b/libq/rmspace.h
@@ -10,5 +10,6 @@
 
 char *rmspace_len(char *s, size_t len);
 char *rmspace(char *s);
+char *remove_extra_space(char *s);
 
 #endif

diff --git a/main.c b/main.c
index 6b4153a..01d358a 100644
--- a/main.c
+++ b/main.c
@@ -4,6 +4,7 @@
  *
  * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
+ * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
 #include "main.h"
@@ -112,8 +113,8 @@ static DECLARE_ARRAY(overlays);
 static void
 no_colors(void)
 {
-	/* echo $(awk '{print $4,"="}' libq/colors.c  | grep ^* |cut -c 2-| grep ^[A-Z] |tr '\n' ' ') = \"\"\;  */
-	BOLD = NORM = BLUE = DKBLUE = CYAN = GREEN = DKGREEN = MAGENTA = RED = YELLOW = BRYELLOW = WHITE = "";
+	BOLD = NORM = BLUE = DKBLUE = CYAN = GREEN = DKGREEN = \
+		   MAGENTA = RED = YELLOW = BRYELLOW = WHITE = "";
 	setenv("NOCOLOR", "true", 1);
 }
 
@@ -281,32 +282,6 @@ rematch(const char *re, const char *match, int cflags)
 	return ret;
 }
 
-/* removes adjacent extraneous white space */
-static char *
-remove_extra_space(char *str)
-{
-	char *p, c = ' ';
-	size_t len, pos = 0;
-	char *buf;
-
-	if (str == NULL)
-		return NULL;
-	len = strlen(str);
-	buf = xzalloc(len+1);
-	for (p = str; *p != 0; ++p) {
-		if (!isspace(*p)) c = *p; else {
-			if (c == ' ') continue;
-			c = ' ';
-		}
-		buf[pos] = c;
-		pos++;
-	}
-	if (pos > 0 && buf[pos-1] == ' ') buf[pos-1] = '\0';
-	strcpy(str, buf);
-	free(buf);
-	return str;
-}
-
 static void
 freeargv(int argc, char **argv)
 {


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-03-27 10:55 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-03-27 10:55 UTC (permalink / raw
  To: gentoo-commits

commit:     d0a8d231167adddb80a73849d3bc70edbfda3507
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 27 10:53:58 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Mar 27 10:53:58 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=d0a8d231

build: compile applets as separate objects

Instead of including everything from a single file, compile each applet
separately.  This standardises things somewhat, and allows for parallel
compilation.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 Makefile.am            |  20 +-
 Makefile.in            | 283 ++++++++++++++++++++++-
 TODO.md                |   5 +
 applets.h              |  90 +++++++-
 configure              | 108 ---------
 configure.ac           |   3 -
 libq/Makefile.am       |   2 +
 libq/Makefile.in       |  31 ++-
 libq/cache.h           |   2 +
 libq/contents.c        |  92 ++++++++
 libq/contents.h        |  29 +++
 libq/copy_file.c       |  18 ++
 libq/copy_file.h       |   3 +
 libq/human_readable.c  |  15 +-
 libq/md5_sha1_sum.h    |   3 +
 libq/scandirat.c       |   8 +
 libq/scandirat.h       |   1 +
 libq/vdb.c             |  77 +++++++
 libq/vdb.h             |   5 +
 libq/xarray.h          |   1 +
 qxpak.c => libq/xpak.c | 237 +++++++------------
 libq/xpak.h            |  31 +++
 libq/xregex.c          |  17 ++
 libq/xregex.h          |   1 +
 main.c                 | 604 +++----------------------------------------------
 main.h                 |  12 +-
 q.c                    |  43 +++-
 qatom.c                |  14 +-
 qcache.c               |  56 +++--
 qcheck.c               |  20 +-
 qdepends.c             |  18 +-
 qfile.c                |  20 +-
 qgrep.c                |  91 +++++---
 qlist.c                |  42 +++-
 qlop.c                 |  18 +-
 qmerge.c               |  54 ++++-
 qpkg.c                 |  94 +++++---
 qsearch.c              |  83 +++++--
 qsize.c                |  28 ++-
 qtbz2.c                |  89 +++-----
 qtegrity.c             |  16 +-
 quse.c                 |  66 +++---
 qxpak.c                | 374 ++++--------------------------
 43 files changed, 1383 insertions(+), 1441 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index bb1015c..a9eba56 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,7 +8,25 @@ postsyncddir = $(portagedir)/repo.postsync.d
 dist_postsyncd_SCRIPTS = repo.postsync/q-reinit
 
 bin_PROGRAMS = q
-q_SOURCES = main.c
+q_SOURCES = \
+	main.c \
+	q.c \
+	qatom.c \
+	qcache.c \
+	qcheck.c \
+	qdepends.c \
+	qfile.c \
+	qgrep.c \
+	qlist.c \
+	qlop.c \
+	qmerge.c \
+	qpkg.c \
+	qsearch.c \
+	qsize.c \
+	qtbz2.c \
+	qtegrity.c \
+	quse.c \
+	qxpak.c
 q_CPPFLAGS = \
 	-I$(top_srcdir)/libq \
 	-I$(top_builddir)/autotools/gnulib \

diff --git a/Makefile.in b/Makefile.in
index ee65a5d..a014d25 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -248,7 +248,12 @@ CONFIG_CLEAN_VPATH_FILES =
 am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(postsyncddir)" \
 	"$(DESTDIR)$(man1dir)"
 PROGRAMS = $(bin_PROGRAMS)
-am_q_OBJECTS = q-main.$(OBJEXT)
+am_q_OBJECTS = q-main.$(OBJEXT) q-q.$(OBJEXT) q-qatom.$(OBJEXT) \
+	q-qcache.$(OBJEXT) q-qcheck.$(OBJEXT) q-qdepends.$(OBJEXT) \
+	q-qfile.$(OBJEXT) q-qgrep.$(OBJEXT) q-qlist.$(OBJEXT) \
+	q-qlop.$(OBJEXT) q-qmerge.$(OBJEXT) q-qpkg.$(OBJEXT) \
+	q-qsearch.$(OBJEXT) q-qsize.$(OBJEXT) q-qtbz2.$(OBJEXT) \
+	q-qtegrity.$(OBJEXT) q-quse.$(OBJEXT) q-qxpak.$(OBJEXT)
 q_OBJECTS = $(am_q_OBJECTS)
 am__DEPENDENCIES_1 =
 q_DEPENDENCIES = $(top_builddir)/libq/libq.la \
@@ -1542,7 +1547,26 @@ SUBDIRS = autotools/gnulib libq
 portagedir = $(sysconfdir)/portage
 postsyncddir = $(portagedir)/repo.postsync.d
 dist_postsyncd_SCRIPTS = repo.postsync/q-reinit
-q_SOURCES = main.c
+q_SOURCES = \
+	main.c \
+	q.c \
+	qatom.c \
+	qcache.c \
+	qcheck.c \
+	qdepends.c \
+	qfile.c \
+	qgrep.c \
+	qlist.c \
+	qlop.c \
+	qmerge.c \
+	qpkg.c \
+	qsearch.c \
+	qsize.c \
+	qtbz2.c \
+	qtegrity.c \
+	quse.c \
+	qxpak.c
+
 
 # @@@ GEN START @@@ #
 q_CPPFLAGS = -I$(top_srcdir)/libq -I$(top_builddir)/autotools/gnulib \
@@ -1831,6 +1855,23 @@ distclean-compile:
 	-rm -f *.tab.c
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-q.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qatom.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qcache.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qcheck.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qdepends.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qfile.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qgrep.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qlist.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qlop.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qmerge.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qpkg.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qsearch.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qsize.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qtbz2.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qtegrity.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-quse.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/q-qxpak.Po@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -1867,6 +1908,244 @@ q-main.obj: main.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi`
 
+q-q.o: q.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-q.o -MD -MP -MF $(DEPDIR)/q-q.Tpo -c -o q-q.o `test -f 'q.c' || echo '$(srcdir)/'`q.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-q.Tpo $(DEPDIR)/q-q.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='q.c' object='q-q.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-q.o `test -f 'q.c' || echo '$(srcdir)/'`q.c
+
+q-q.obj: q.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-q.obj -MD -MP -MF $(DEPDIR)/q-q.Tpo -c -o q-q.obj `if test -f 'q.c'; then $(CYGPATH_W) 'q.c'; else $(CYGPATH_W) '$(srcdir)/q.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-q.Tpo $(DEPDIR)/q-q.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='q.c' object='q-q.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-q.obj `if test -f 'q.c'; then $(CYGPATH_W) 'q.c'; else $(CYGPATH_W) '$(srcdir)/q.c'; fi`
+
+q-qatom.o: qatom.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qatom.o -MD -MP -MF $(DEPDIR)/q-qatom.Tpo -c -o q-qatom.o `test -f 'qatom.c' || echo '$(srcdir)/'`qatom.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qatom.Tpo $(DEPDIR)/q-qatom.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qatom.c' object='q-qatom.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qatom.o `test -f 'qatom.c' || echo '$(srcdir)/'`qatom.c
+
+q-qatom.obj: qatom.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qatom.obj -MD -MP -MF $(DEPDIR)/q-qatom.Tpo -c -o q-qatom.obj `if test -f 'qatom.c'; then $(CYGPATH_W) 'qatom.c'; else $(CYGPATH_W) '$(srcdir)/qatom.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qatom.Tpo $(DEPDIR)/q-qatom.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qatom.c' object='q-qatom.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qatom.obj `if test -f 'qatom.c'; then $(CYGPATH_W) 'qatom.c'; else $(CYGPATH_W) '$(srcdir)/qatom.c'; fi`
+
+q-qcache.o: qcache.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qcache.o -MD -MP -MF $(DEPDIR)/q-qcache.Tpo -c -o q-qcache.o `test -f 'qcache.c' || echo '$(srcdir)/'`qcache.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qcache.Tpo $(DEPDIR)/q-qcache.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qcache.c' object='q-qcache.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qcache.o `test -f 'qcache.c' || echo '$(srcdir)/'`qcache.c
+
+q-qcache.obj: qcache.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qcache.obj -MD -MP -MF $(DEPDIR)/q-qcache.Tpo -c -o q-qcache.obj `if test -f 'qcache.c'; then $(CYGPATH_W) 'qcache.c'; else $(CYGPATH_W) '$(srcdir)/qcache.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qcache.Tpo $(DEPDIR)/q-qcache.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qcache.c' object='q-qcache.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qcache.obj `if test -f 'qcache.c'; then $(CYGPATH_W) 'qcache.c'; else $(CYGPATH_W) '$(srcdir)/qcache.c'; fi`
+
+q-qcheck.o: qcheck.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qcheck.o -MD -MP -MF $(DEPDIR)/q-qcheck.Tpo -c -o q-qcheck.o `test -f 'qcheck.c' || echo '$(srcdir)/'`qcheck.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qcheck.Tpo $(DEPDIR)/q-qcheck.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qcheck.c' object='q-qcheck.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qcheck.o `test -f 'qcheck.c' || echo '$(srcdir)/'`qcheck.c
+
+q-qcheck.obj: qcheck.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qcheck.obj -MD -MP -MF $(DEPDIR)/q-qcheck.Tpo -c -o q-qcheck.obj `if test -f 'qcheck.c'; then $(CYGPATH_W) 'qcheck.c'; else $(CYGPATH_W) '$(srcdir)/qcheck.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qcheck.Tpo $(DEPDIR)/q-qcheck.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qcheck.c' object='q-qcheck.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qcheck.obj `if test -f 'qcheck.c'; then $(CYGPATH_W) 'qcheck.c'; else $(CYGPATH_W) '$(srcdir)/qcheck.c'; fi`
+
+q-qdepends.o: qdepends.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qdepends.o -MD -MP -MF $(DEPDIR)/q-qdepends.Tpo -c -o q-qdepends.o `test -f 'qdepends.c' || echo '$(srcdir)/'`qdepends.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qdepends.Tpo $(DEPDIR)/q-qdepends.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qdepends.c' object='q-qdepends.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qdepends.o `test -f 'qdepends.c' || echo '$(srcdir)/'`qdepends.c
+
+q-qdepends.obj: qdepends.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qdepends.obj -MD -MP -MF $(DEPDIR)/q-qdepends.Tpo -c -o q-qdepends.obj `if test -f 'qdepends.c'; then $(CYGPATH_W) 'qdepends.c'; else $(CYGPATH_W) '$(srcdir)/qdepends.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qdepends.Tpo $(DEPDIR)/q-qdepends.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qdepends.c' object='q-qdepends.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qdepends.obj `if test -f 'qdepends.c'; then $(CYGPATH_W) 'qdepends.c'; else $(CYGPATH_W) '$(srcdir)/qdepends.c'; fi`
+
+q-qfile.o: qfile.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qfile.o -MD -MP -MF $(DEPDIR)/q-qfile.Tpo -c -o q-qfile.o `test -f 'qfile.c' || echo '$(srcdir)/'`qfile.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qfile.Tpo $(DEPDIR)/q-qfile.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qfile.c' object='q-qfile.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qfile.o `test -f 'qfile.c' || echo '$(srcdir)/'`qfile.c
+
+q-qfile.obj: qfile.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qfile.obj -MD -MP -MF $(DEPDIR)/q-qfile.Tpo -c -o q-qfile.obj `if test -f 'qfile.c'; then $(CYGPATH_W) 'qfile.c'; else $(CYGPATH_W) '$(srcdir)/qfile.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qfile.Tpo $(DEPDIR)/q-qfile.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qfile.c' object='q-qfile.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qfile.obj `if test -f 'qfile.c'; then $(CYGPATH_W) 'qfile.c'; else $(CYGPATH_W) '$(srcdir)/qfile.c'; fi`
+
+q-qgrep.o: qgrep.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qgrep.o -MD -MP -MF $(DEPDIR)/q-qgrep.Tpo -c -o q-qgrep.o `test -f 'qgrep.c' || echo '$(srcdir)/'`qgrep.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qgrep.Tpo $(DEPDIR)/q-qgrep.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qgrep.c' object='q-qgrep.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qgrep.o `test -f 'qgrep.c' || echo '$(srcdir)/'`qgrep.c
+
+q-qgrep.obj: qgrep.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qgrep.obj -MD -MP -MF $(DEPDIR)/q-qgrep.Tpo -c -o q-qgrep.obj `if test -f 'qgrep.c'; then $(CYGPATH_W) 'qgrep.c'; else $(CYGPATH_W) '$(srcdir)/qgrep.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qgrep.Tpo $(DEPDIR)/q-qgrep.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qgrep.c' object='q-qgrep.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qgrep.obj `if test -f 'qgrep.c'; then $(CYGPATH_W) 'qgrep.c'; else $(CYGPATH_W) '$(srcdir)/qgrep.c'; fi`
+
+q-qlist.o: qlist.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qlist.o -MD -MP -MF $(DEPDIR)/q-qlist.Tpo -c -o q-qlist.o `test -f 'qlist.c' || echo '$(srcdir)/'`qlist.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qlist.Tpo $(DEPDIR)/q-qlist.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qlist.c' object='q-qlist.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qlist.o `test -f 'qlist.c' || echo '$(srcdir)/'`qlist.c
+
+q-qlist.obj: qlist.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qlist.obj -MD -MP -MF $(DEPDIR)/q-qlist.Tpo -c -o q-qlist.obj `if test -f 'qlist.c'; then $(CYGPATH_W) 'qlist.c'; else $(CYGPATH_W) '$(srcdir)/qlist.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qlist.Tpo $(DEPDIR)/q-qlist.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qlist.c' object='q-qlist.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qlist.obj `if test -f 'qlist.c'; then $(CYGPATH_W) 'qlist.c'; else $(CYGPATH_W) '$(srcdir)/qlist.c'; fi`
+
+q-qlop.o: qlop.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qlop.o -MD -MP -MF $(DEPDIR)/q-qlop.Tpo -c -o q-qlop.o `test -f 'qlop.c' || echo '$(srcdir)/'`qlop.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qlop.Tpo $(DEPDIR)/q-qlop.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qlop.c' object='q-qlop.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qlop.o `test -f 'qlop.c' || echo '$(srcdir)/'`qlop.c
+
+q-qlop.obj: qlop.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qlop.obj -MD -MP -MF $(DEPDIR)/q-qlop.Tpo -c -o q-qlop.obj `if test -f 'qlop.c'; then $(CYGPATH_W) 'qlop.c'; else $(CYGPATH_W) '$(srcdir)/qlop.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qlop.Tpo $(DEPDIR)/q-qlop.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qlop.c' object='q-qlop.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qlop.obj `if test -f 'qlop.c'; then $(CYGPATH_W) 'qlop.c'; else $(CYGPATH_W) '$(srcdir)/qlop.c'; fi`
+
+q-qmerge.o: qmerge.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qmerge.o -MD -MP -MF $(DEPDIR)/q-qmerge.Tpo -c -o q-qmerge.o `test -f 'qmerge.c' || echo '$(srcdir)/'`qmerge.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qmerge.Tpo $(DEPDIR)/q-qmerge.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qmerge.c' object='q-qmerge.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qmerge.o `test -f 'qmerge.c' || echo '$(srcdir)/'`qmerge.c
+
+q-qmerge.obj: qmerge.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qmerge.obj -MD -MP -MF $(DEPDIR)/q-qmerge.Tpo -c -o q-qmerge.obj `if test -f 'qmerge.c'; then $(CYGPATH_W) 'qmerge.c'; else $(CYGPATH_W) '$(srcdir)/qmerge.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qmerge.Tpo $(DEPDIR)/q-qmerge.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qmerge.c' object='q-qmerge.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qmerge.obj `if test -f 'qmerge.c'; then $(CYGPATH_W) 'qmerge.c'; else $(CYGPATH_W) '$(srcdir)/qmerge.c'; fi`
+
+q-qpkg.o: qpkg.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qpkg.o -MD -MP -MF $(DEPDIR)/q-qpkg.Tpo -c -o q-qpkg.o `test -f 'qpkg.c' || echo '$(srcdir)/'`qpkg.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qpkg.Tpo $(DEPDIR)/q-qpkg.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qpkg.c' object='q-qpkg.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qpkg.o `test -f 'qpkg.c' || echo '$(srcdir)/'`qpkg.c
+
+q-qpkg.obj: qpkg.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qpkg.obj -MD -MP -MF $(DEPDIR)/q-qpkg.Tpo -c -o q-qpkg.obj `if test -f 'qpkg.c'; then $(CYGPATH_W) 'qpkg.c'; else $(CYGPATH_W) '$(srcdir)/qpkg.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qpkg.Tpo $(DEPDIR)/q-qpkg.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qpkg.c' object='q-qpkg.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qpkg.obj `if test -f 'qpkg.c'; then $(CYGPATH_W) 'qpkg.c'; else $(CYGPATH_W) '$(srcdir)/qpkg.c'; fi`
+
+q-qsearch.o: qsearch.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qsearch.o -MD -MP -MF $(DEPDIR)/q-qsearch.Tpo -c -o q-qsearch.o `test -f 'qsearch.c' || echo '$(srcdir)/'`qsearch.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qsearch.Tpo $(DEPDIR)/q-qsearch.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qsearch.c' object='q-qsearch.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qsearch.o `test -f 'qsearch.c' || echo '$(srcdir)/'`qsearch.c
+
+q-qsearch.obj: qsearch.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qsearch.obj -MD -MP -MF $(DEPDIR)/q-qsearch.Tpo -c -o q-qsearch.obj `if test -f 'qsearch.c'; then $(CYGPATH_W) 'qsearch.c'; else $(CYGPATH_W) '$(srcdir)/qsearch.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qsearch.Tpo $(DEPDIR)/q-qsearch.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qsearch.c' object='q-qsearch.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qsearch.obj `if test -f 'qsearch.c'; then $(CYGPATH_W) 'qsearch.c'; else $(CYGPATH_W) '$(srcdir)/qsearch.c'; fi`
+
+q-qsize.o: qsize.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qsize.o -MD -MP -MF $(DEPDIR)/q-qsize.Tpo -c -o q-qsize.o `test -f 'qsize.c' || echo '$(srcdir)/'`qsize.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qsize.Tpo $(DEPDIR)/q-qsize.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qsize.c' object='q-qsize.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qsize.o `test -f 'qsize.c' || echo '$(srcdir)/'`qsize.c
+
+q-qsize.obj: qsize.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qsize.obj -MD -MP -MF $(DEPDIR)/q-qsize.Tpo -c -o q-qsize.obj `if test -f 'qsize.c'; then $(CYGPATH_W) 'qsize.c'; else $(CYGPATH_W) '$(srcdir)/qsize.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qsize.Tpo $(DEPDIR)/q-qsize.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qsize.c' object='q-qsize.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qsize.obj `if test -f 'qsize.c'; then $(CYGPATH_W) 'qsize.c'; else $(CYGPATH_W) '$(srcdir)/qsize.c'; fi`
+
+q-qtbz2.o: qtbz2.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qtbz2.o -MD -MP -MF $(DEPDIR)/q-qtbz2.Tpo -c -o q-qtbz2.o `test -f 'qtbz2.c' || echo '$(srcdir)/'`qtbz2.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qtbz2.Tpo $(DEPDIR)/q-qtbz2.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qtbz2.c' object='q-qtbz2.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qtbz2.o `test -f 'qtbz2.c' || echo '$(srcdir)/'`qtbz2.c
+
+q-qtbz2.obj: qtbz2.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qtbz2.obj -MD -MP -MF $(DEPDIR)/q-qtbz2.Tpo -c -o q-qtbz2.obj `if test -f 'qtbz2.c'; then $(CYGPATH_W) 'qtbz2.c'; else $(CYGPATH_W) '$(srcdir)/qtbz2.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qtbz2.Tpo $(DEPDIR)/q-qtbz2.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qtbz2.c' object='q-qtbz2.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qtbz2.obj `if test -f 'qtbz2.c'; then $(CYGPATH_W) 'qtbz2.c'; else $(CYGPATH_W) '$(srcdir)/qtbz2.c'; fi`
+
+q-qtegrity.o: qtegrity.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qtegrity.o -MD -MP -MF $(DEPDIR)/q-qtegrity.Tpo -c -o q-qtegrity.o `test -f 'qtegrity.c' || echo '$(srcdir)/'`qtegrity.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qtegrity.Tpo $(DEPDIR)/q-qtegrity.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qtegrity.c' object='q-qtegrity.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qtegrity.o `test -f 'qtegrity.c' || echo '$(srcdir)/'`qtegrity.c
+
+q-qtegrity.obj: qtegrity.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qtegrity.obj -MD -MP -MF $(DEPDIR)/q-qtegrity.Tpo -c -o q-qtegrity.obj `if test -f 'qtegrity.c'; then $(CYGPATH_W) 'qtegrity.c'; else $(CYGPATH_W) '$(srcdir)/qtegrity.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qtegrity.Tpo $(DEPDIR)/q-qtegrity.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qtegrity.c' object='q-qtegrity.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qtegrity.obj `if test -f 'qtegrity.c'; then $(CYGPATH_W) 'qtegrity.c'; else $(CYGPATH_W) '$(srcdir)/qtegrity.c'; fi`
+
+q-quse.o: quse.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-quse.o -MD -MP -MF $(DEPDIR)/q-quse.Tpo -c -o q-quse.o `test -f 'quse.c' || echo '$(srcdir)/'`quse.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-quse.Tpo $(DEPDIR)/q-quse.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='quse.c' object='q-quse.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-quse.o `test -f 'quse.c' || echo '$(srcdir)/'`quse.c
+
+q-quse.obj: quse.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-quse.obj -MD -MP -MF $(DEPDIR)/q-quse.Tpo -c -o q-quse.obj `if test -f 'quse.c'; then $(CYGPATH_W) 'quse.c'; else $(CYGPATH_W) '$(srcdir)/quse.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-quse.Tpo $(DEPDIR)/q-quse.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='quse.c' object='q-quse.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-quse.obj `if test -f 'quse.c'; then $(CYGPATH_W) 'quse.c'; else $(CYGPATH_W) '$(srcdir)/quse.c'; fi`
+
+q-qxpak.o: qxpak.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qxpak.o -MD -MP -MF $(DEPDIR)/q-qxpak.Tpo -c -o q-qxpak.o `test -f 'qxpak.c' || echo '$(srcdir)/'`qxpak.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qxpak.Tpo $(DEPDIR)/q-qxpak.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qxpak.c' object='q-qxpak.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qxpak.o `test -f 'qxpak.c' || echo '$(srcdir)/'`qxpak.c
+
+q-qxpak.obj: qxpak.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT q-qxpak.obj -MD -MP -MF $(DEPDIR)/q-qxpak.Tpo -c -o q-qxpak.obj `if test -f 'qxpak.c'; then $(CYGPATH_W) 'qxpak.c'; else $(CYGPATH_W) '$(srcdir)/qxpak.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/q-qxpak.Tpo $(DEPDIR)/q-qxpak.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='qxpak.c' object='q-qxpak.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(q_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o q-qxpak.obj `if test -f 'qxpak.c'; then $(CYGPATH_W) 'qxpak.c'; else $(CYGPATH_W) '$(srcdir)/qxpak.c'; fi`
+
 mostlyclean-libtool:
 	-rm -f *.lo
 

diff --git a/TODO.md b/TODO.md
index 6e813b8..5ebd9ea 100644
--- a/TODO.md
+++ b/TODO.md
@@ -49,6 +49,7 @@
 - support TTL field in binpkgs file
 - merge duplicate atoms on the CLI (`qmerge -Uq nano nano nano`)
 - unmerging should clean out @world set
+- test should work on local vdb (so TRAVIS can test it too)
 
 # qdepends
 
@@ -66,3 +67,7 @@
 # qsync
 
 - rewrite to use new repos.conf standard
+
+# qgrep
+
+- make it use standard xarray instead of its own buf\_list

diff --git a/applets.h b/applets.h
index 14b0154..e2d487c 100644
--- a/applets.h
+++ b/applets.h
@@ -1,13 +1,36 @@
 /*
- * Copyright 2005-2018 Gentoo Foundation
+ * Copyright 2005-2019 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
  */
 
-#ifndef _QAPPLETS_H_
-#define _QAPPLETS_H_
+#ifndef _APPLETS_H_
+#define _APPLETS_H_ 1
+
+#if defined(__sun) && defined(__SVR4)
+/* workaround non-const defined name in option struct, such that we
+ * don't get a zillion of warnings */
+#define	no_argument		0
+#define	required_argument	1
+#define	optional_argument	2
+struct option {
+	const char *name;
+	int has_arg;
+	int *flag;
+	int val;
+};
+extern int	getopt_long(int, char * const *, const char *,
+		    const struct option *, int *);
+#else
+# include <getopt.h>
+#endif
+
+#include <stdbool.h>
+#include <dirent.h>
+
+#include "xarray.h"
 
 /* applet prototypes */
 typedef int (*APPLET)(int, char **);
@@ -34,11 +57,6 @@ DECLARE_APPLET(qcache)
 DECLARE_APPLET(qtegrity)
 #undef DECLARE_APPLET
 
-#define DEFINE_APPLET_STUB(applet) \
-	int applet##_main(_q_unused_ int argc, _q_unused_ char **argv) { \
-		err("Sorry, this applet has been disabled"); \
-	}
-
 static const struct applet_t {
 	const char *name;
 	APPLET func;
@@ -92,4 +110,60 @@ static const struct applet_t {
 	{NULL, NULL, NULL, NULL}
 };
 
+/* Common usage for all applets */
+#define COMMON_FLAGS "vqChV"
+#define COMMON_LONG_OPTS \
+	{"root",       a_argument, NULL, 0x1}, \
+	{"verbose",   no_argument, NULL, 'v'}, \
+	{"quiet",     no_argument, NULL, 'q'}, \
+	{"nocolor",   no_argument, NULL, 'C'}, \
+	{"help",      no_argument, NULL, 'h'}, \
+	{"version",   no_argument, NULL, 'V'}, \
+	{NULL,        no_argument, NULL, 0x0}
+#define COMMON_OPTS_HELP \
+	"Set the ROOT env var", \
+	"Make a lot of noise", \
+	"Tighter output; suppress warnings", \
+	"Don't output color", \
+	"Print this help and exit", \
+	"Print version and exit", \
+	NULL
+#define COMMON_GETOPTS_CASES(applet) \
+	case 0x1: portroot = optarg; break; \
+	case 'v': ++verbose; break; \
+	case 'q': setup_quiet(); break; \
+	case 'V': version_barf(); break; \
+	case 'h': applet ## _usage(EXIT_SUCCESS); break; \
+	case 'C': no_colors(); break; \
+	default: applet ## _usage(EXIT_FAILURE); break;
+
+extern char *modpath;
+extern char *portroot;
+extern int verbose;
+extern int quiet;
+extern char pretend;
+extern char *config_protect;
+extern char *config_protect_mask;
+extern char *portvdb;
+extern char *portlogdir;
+extern int portcachedir_type;
+extern char *pkg_install_mask;
+extern char *binhost;
+extern char *pkgdir;
+extern char *port_tmpdir;
+extern char *features;
+extern char *install_mask;
+extern DEFINE_ARRAY(overlays);
+
+void no_colors(void);
+void setup_quiet(void);
+void version_barf(void);
+void usage(int status, const char *flags, struct option const opts[],
+      const char * const help[], const char *desc, int blabber);
+int lookup_applet_idx(const char *);
+APPLET lookup_applet(const char *applet);
+const char *initialize_flat(const char *overlay, int cache_type, bool force);
+void freeargv(int argc, char **argv);
+void makeargv(const char *string, int *argc, char ***argv);
+
 #endif

diff --git a/configure b/configure
index ce1fbde..e538b3e 100755
--- a/configure
+++ b/configure
@@ -34569,42 +34569,6 @@ else
 fi
 
 
-	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -Wno-missing-prototypes" >&5
-$as_echo_n "checking whether C compiler accepts -Wno-missing-prototypes... " >&6; }
-if ${ax_cv_check_cflags___Wno_missing_prototypes+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-
-  ax_check_save_flags=$CFLAGS
-  CFLAGS="$CFLAGS  -Wno-missing-prototypes"
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  ax_cv_check_cflags___Wno_missing_prototypes=yes
-else
-  ax_cv_check_cflags___Wno_missing_prototypes=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-  CFLAGS=$ax_check_save_flags
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___Wno_missing_prototypes" >&5
-$as_echo "$ax_cv_check_cflags___Wno_missing_prototypes" >&6; }
-if test "x$ax_cv_check_cflags___Wno_missing_prototypes" = xyes; then :
-  as_fn_append CFLAGS " -Wno-missing-prototypes"
-else
-  :
-fi
-
-
 	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -Wwrite-strings" >&5
 $as_echo_n "checking whether C compiler accepts -Wwrite-strings... " >&6; }
 if ${ax_cv_check_cflags___Wwrite_strings+:} false; then :
@@ -34857,42 +34821,6 @@ else
 fi
 
 
-	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -Wno-format-nonliteral" >&5
-$as_echo_n "checking whether C compiler accepts -Wno-format-nonliteral... " >&6; }
-if ${ax_cv_check_cflags___Wno_format_nonliteral+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-
-  ax_check_save_flags=$CFLAGS
-  CFLAGS="$CFLAGS  -Wno-format-nonliteral"
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  ax_cv_check_cflags___Wno_format_nonliteral=yes
-else
-  ax_cv_check_cflags___Wno_format_nonliteral=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-  CFLAGS=$ax_check_save_flags
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___Wno_format_nonliteral" >&5
-$as_echo "$ax_cv_check_cflags___Wno_format_nonliteral" >&6; }
-if test "x$ax_cv_check_cflags___Wno_format_nonliteral" = xyes; then :
-  as_fn_append CFLAGS " -Wno-format-nonliteral"
-else
-  :
-fi
-
-
 	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -Wsequence-point" >&5
 $as_echo_n "checking whether C compiler accepts -Wsequence-point... " >&6; }
 if ${ax_cv_check_cflags___Wsequence_point+:} false; then :
@@ -35001,42 +34929,6 @@ else
 fi
 
 
-	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -Wno-expansion-to-defined" >&5
-$as_echo_n "checking whether C compiler accepts -Wno-expansion-to-defined... " >&6; }
-if ${ax_cv_check_cflags___Wno_expansion_to_defined+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-
-  ax_check_save_flags=$CFLAGS
-  CFLAGS="$CFLAGS  -Wno-expansion-to-defined"
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  ax_cv_check_cflags___Wno_expansion_to_defined=yes
-else
-  ax_cv_check_cflags___Wno_expansion_to_defined=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-  CFLAGS=$ax_check_save_flags
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___Wno_expansion_to_defined" >&5
-$as_echo "$ax_cv_check_cflags___Wno_expansion_to_defined" >&6; }
-if test "x$ax_cv_check_cflags___Wno_expansion_to_defined" = xyes; then :
-  as_fn_append CFLAGS " -Wno-expansion-to-defined"
-else
-  :
-fi
-
-
 
 ac_config_files="$ac_config_files Makefile libq/Makefile autotools/gnulib/Makefile tests/atom_explode/Makefile tests/copy_file/Makefile tests/mkdir/Makefile tests/rmspace/Makefile"
 

diff --git a/configure.ac b/configure.ac
index 55346a8..c7f6e69 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,7 +36,6 @@ m4_foreach_w([flag], [
 	-Wshadow
 	-Wformat=2
 	-Wmissing-declarations
-	-Wno-missing-prototypes
 	-Wwrite-strings
 	-Wbad-function-cast
 	-Wnested-externs
@@ -44,11 +43,9 @@ m4_foreach_w([flag], [
 	-Winline
 	-Wchar-subscripts
 	-Wcast-align
-	-Wno-format-nonliteral
 	-Wsequence-point
 	-Wold-style-definition
 	-Wextra
-	-Wno-expansion-to-defined
 ], [
 	AX_CHECK_COMPILE_FLAG(flag, AS_VAR_APPEND([CFLAGS], " flag"))
 ])

diff --git a/libq/Makefile.am b/libq/Makefile.am
index 26647ee..734a78f 100644
--- a/libq/Makefile.am
+++ b/libq/Makefile.am
@@ -5,6 +5,7 @@ QFILES = \
 	busybox.h \
 	cache.c cache.h \
 	colors.c colors.h \
+	contents.c contents.h \
 	copy_file.c copy_file.h \
 	eat_file.c eat_file.h \
 	hash_fd.c hash_fd.h \
@@ -22,6 +23,7 @@ QFILES = \
 	xasprintf.h \
 	xchdir.c xchdir.h \
 	xmkdir.c xmkdir.h \
+	xpak.c xpak.h \
 	xregex.c xregex.h \
 	xsystem.c xsystem.h \
 	$(NULL)

diff --git a/libq/Makefile.in b/libq/Makefile.in
index 6c529c2..ab7012f 100644
--- a/libq/Makefile.in
+++ b/libq/Makefile.in
@@ -242,12 +242,13 @@ CONFIG_CLEAN_VPATH_FILES =
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 libq_la_LIBADD =
 am__objects_1 = libq_la-atom.lo libq_la-basename.lo libq_la-cache.lo \
-	libq_la-colors.lo libq_la-copy_file.lo libq_la-eat_file.lo \
-	libq_la-hash_fd.lo libq_la-human_readable.lo \
-	libq_la-md5_sha1_sum.lo libq_la-prelink.lo libq_la-profile.lo \
-	libq_la-rmspace.lo libq_la-safe_io.lo libq_la-scandirat.lo \
-	libq_la-set.lo libq_la-vdb.lo libq_la-xarray.lo \
-	libq_la-xchdir.lo libq_la-xmkdir.lo libq_la-xregex.lo \
+	libq_la-colors.lo libq_la-contents.lo libq_la-copy_file.lo \
+	libq_la-eat_file.lo libq_la-hash_fd.lo \
+	libq_la-human_readable.lo libq_la-md5_sha1_sum.lo \
+	libq_la-prelink.lo libq_la-profile.lo libq_la-rmspace.lo \
+	libq_la-safe_io.lo libq_la-scandirat.lo libq_la-set.lo \
+	libq_la-vdb.lo libq_la-xarray.lo libq_la-xchdir.lo \
+	libq_la-xmkdir.lo libq_la-xpak.lo libq_la-xregex.lo \
 	libq_la-xsystem.lo
 am_libq_la_OBJECTS = $(am__objects_1)
 libq_la_OBJECTS = $(am_libq_la_OBJECTS)
@@ -1447,6 +1448,7 @@ QFILES = \
 	busybox.h \
 	cache.c cache.h \
 	colors.c colors.h \
+	contents.c contents.h \
 	copy_file.c copy_file.h \
 	eat_file.c eat_file.h \
 	hash_fd.c hash_fd.h \
@@ -1464,6 +1466,7 @@ QFILES = \
 	xasprintf.h \
 	xchdir.c xchdir.h \
 	xmkdir.c xmkdir.h \
+	xpak.c xpak.h \
 	xregex.c xregex.h \
 	xsystem.c xsystem.h \
 	$(NULL)
@@ -1532,6 +1535,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-basename.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-cache.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-colors.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-contents.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-copy_file.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-eat_file.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-hash_fd.Plo@am__quote@
@@ -1547,6 +1551,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-xarray.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-xchdir.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-xmkdir.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-xpak.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-xregex.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-xsystem.Plo@am__quote@
 
@@ -1599,6 +1604,13 @@ libq_la-colors.lo: colors.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-colors.lo `test -f 'colors.c' || echo '$(srcdir)/'`colors.c
 
+libq_la-contents.lo: contents.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-contents.lo -MD -MP -MF $(DEPDIR)/libq_la-contents.Tpo -c -o libq_la-contents.lo `test -f 'contents.c' || echo '$(srcdir)/'`contents.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-contents.Tpo $(DEPDIR)/libq_la-contents.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='contents.c' object='libq_la-contents.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-contents.lo `test -f 'contents.c' || echo '$(srcdir)/'`contents.c
+
 libq_la-copy_file.lo: copy_file.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-copy_file.lo -MD -MP -MF $(DEPDIR)/libq_la-copy_file.Tpo -c -o libq_la-copy_file.lo `test -f 'copy_file.c' || echo '$(srcdir)/'`copy_file.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-copy_file.Tpo $(DEPDIR)/libq_la-copy_file.Plo
@@ -1704,6 +1716,13 @@ libq_la-xmkdir.lo: xmkdir.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-xmkdir.lo `test -f 'xmkdir.c' || echo '$(srcdir)/'`xmkdir.c
 
+libq_la-xpak.lo: xpak.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-xpak.lo -MD -MP -MF $(DEPDIR)/libq_la-xpak.Tpo -c -o libq_la-xpak.lo `test -f 'xpak.c' || echo '$(srcdir)/'`xpak.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-xpak.Tpo $(DEPDIR)/libq_la-xpak.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='xpak.c' object='libq_la-xpak.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-xpak.lo `test -f 'xpak.c' || echo '$(srcdir)/'`xpak.c
+
 libq_la-xregex.lo: xregex.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-xregex.lo -MD -MP -MF $(DEPDIR)/libq_la-xregex.Tpo -c -o libq_la-xregex.lo `test -f 'xregex.c' || echo '$(srcdir)/'`xregex.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-xregex.Tpo $(DEPDIR)/libq_la-xregex.Plo

diff --git a/libq/cache.h b/libq/cache.h
index 971417c..93421df 100644
--- a/libq/cache.h
+++ b/libq/cache.h
@@ -10,6 +10,8 @@
 #ifndef _CACHE_H
 #define _CACHE_H 1
 
+#include "atom.h"
+
 typedef struct {
 	char *_data;
 	char *DEPEND;        /* line 1 */

diff --git a/libq/contents.c b/libq/contents.c
new file mode 100644
index 0000000..41929d0
--- /dev/null
+++ b/libq/contents.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2005-2019 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ *
+ * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
+ * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
+ * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
+ */
+
+#include "main.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "contents.h"
+
+/*
+ * Parse a line of CONTENTS file and provide access to the individual fields
+ */
+contents_entry *
+contents_parse_line(char *line)
+{
+	static contents_entry e;
+	char *p;
+
+	if (!line || !*line || *line == '\n')
+		return NULL;
+
+	/* chop trailing newline */
+	if ((p = strrchr(line, '\n')) != NULL)
+		*p = '\0';
+
+	/* ferringb wants to break portage/vdb by using tabs vs spaces
+	 * so filenames can have lame ass spaces in them..
+	 * (I smell Windows near by)
+	 * Anyway we just convert that crap to a space so we can still
+	 * parse quickly */
+	p = line;
+	while ((p = strchr(p, '\t')) != NULL)
+		*p = ' ';
+
+	memset(&e, 0x00, sizeof(e));
+	e._data = line;
+
+	if (!strncmp(e._data, "obj ", 4))
+		e.type = CONTENTS_OBJ;
+	else if (!strncmp(e._data, "dir ", 4))
+		e.type = CONTENTS_DIR;
+	else if (!strncmp(e._data, "sym ", 4))
+		e.type = CONTENTS_SYM;
+	else
+		return NULL;
+
+	e.name = e._data + 4;
+
+	switch (e.type) {
+		/* dir /bin */
+		case CONTENTS_DIR:
+			break;
+
+		/* obj /bin/bash 62ed51c8b23866777552643ec57614b0 1120707577 */
+		case CONTENTS_OBJ:
+			if ((e.mtime_str = strrchr(e.name, ' ')) == NULL)
+				return NULL;
+			*e.mtime_str++ = '\0';
+			if ((e.digest = strrchr(e.name, ' ')) == NULL)
+				return NULL;
+			*e.digest++ = '\0';
+			break;
+
+		/* sym /bin/sh -> bash 1120707577 */
+		case CONTENTS_SYM:
+			if ((e.mtime_str = strrchr(e.name, ' ')) == NULL)
+				return NULL;
+			*e.mtime_str++ = '\0';
+			if ((e.sym_target = strstr(e.name, " -> ")) == NULL)
+				return NULL;
+			*e.sym_target = '\0';
+			e.sym_target += 4;
+			break;
+	}
+
+	if (e.mtime_str) {
+		e.mtime = strtol(e.mtime_str, NULL, 10);
+		if (e.mtime == LONG_MAX) {
+			e.mtime = 0;
+			e.mtime_str = NULL;
+		}
+	}
+
+	return &e;
+}

diff --git a/libq/contents.h b/libq/contents.h
new file mode 100644
index 0000000..c766827
--- /dev/null
+++ b/libq/contents.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2005-2019 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ *
+ * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
+ * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
+ * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
+ */
+
+#ifndef _CONTENTS_H
+#define _CONTENTS_H 1
+
+typedef enum {
+	CONTENTS_DIR, CONTENTS_OBJ, CONTENTS_SYM
+} contents_type;
+
+typedef struct {
+	contents_type type;
+	char *_data;
+	char *name;
+	char *sym_target;
+	char *digest;
+	char *mtime_str;
+	long mtime;
+} contents_entry;
+
+contents_entry *contents_parse_line(char *line);
+
+#endif

diff --git a/libq/copy_file.c b/libq/copy_file.c
index e013442..e4619ce 100644
--- a/libq/copy_file.c
+++ b/libq/copy_file.c
@@ -26,3 +26,21 @@ int copy_file_fd(int fd_src, int fd_dst)
 			return -1;
 	}
 }
+
+int copy_file(FILE *src, FILE *dst)
+{
+	ssize_t rcnt, wcnt;
+	char buf[64 * 1024];
+
+	while (1) {
+		rcnt = fread(buf, 1, sizeof(buf), src);
+		if (rcnt < 0)
+			return -1;
+		else if (rcnt == 0)
+			return 0;
+
+		wcnt = fwrite(buf, 1, rcnt, dst);
+		if (wcnt == -1 || wcnt != rcnt)
+			return -1;
+	}
+}

diff --git a/libq/copy_file.h b/libq/copy_file.h
index 41da823..080c99e 100644
--- a/libq/copy_file.h
+++ b/libq/copy_file.h
@@ -8,6 +8,9 @@
 #ifndef _COPY_FILE_H
 #define _COPY_FILE_H 1
 
+#include <stdio.h>
+
 int copy_file_fd(int fd_src, int fd_dst);
+int copy_file(FILE *src, FILE *dst);
 
 #endif

diff --git a/libq/human_readable.c b/libq/human_readable.c
index 855ecef..5b8f7a3 100644
--- a/libq/human_readable.c
+++ b/libq/human_readable.c
@@ -38,14 +38,12 @@ make_human_readable_str(unsigned long long val,
 
 	unsigned frac; /* 0..9 - the fractional digit */
 	const char *u;
-	const char *fmt;
 
 	static char str[21];		/* Sufficient for 64 bit unsigned integers. */
 
 	if (val == 0)
 		return "0";
 
-	fmt = "%llu";
 	if (block_size > 1)
 		val *= block_size;
 	frac = 0;
@@ -55,11 +53,11 @@ make_human_readable_str(unsigned long long val,
 		val += display_unit/2;  /* Deal with rounding */
 		val /= display_unit;    /* Don't combine with the line above! */
 		/* will just print it as ulonglong (below) */
+		snprintf(str, sizeof(str), "%llu", val);
 	} else {
 		while ((val >= 1024)
 		 /* && (u < unit_chars + sizeof(unit_chars) - 1) - always true */
 		) {
-			fmt = "%llu.%u%c";
 			u++;
 			frac = (((unsigned)val % 1024) * 10 + 1024/2) / 1024;
 			val /= 1024;
@@ -68,19 +66,18 @@ make_human_readable_str(unsigned long long val,
 			++val;
 			frac = 0;
 		}
-#if 1
 		/* If block_size is 0, dont print fractional part */
 		if (block_size == 0) {
 			if (frac >= 5) {
 				++val;
 			}
-			fmt = "%llu%*c";
-			frac = 1;
+			snprintf(str, sizeof(str), "%llu%c", val, *u);
+		} else if (u == unit_chars) {
+			snprintf(str, sizeof(str), "%llu", val);
+		} else {
+			snprintf(str, sizeof(str), "%llu.%u%c", val, frac, *u);
 		}
-#endif
 	}
 
-	snprintf(str, sizeof(str), fmt, val, frac, *u);
-
 	return str;
 }

diff --git a/libq/md5_sha1_sum.h b/libq/md5_sha1_sum.h
index a4d7b1e..3c682a4 100644
--- a/libq/md5_sha1_sum.h
+++ b/libq/md5_sha1_sum.h
@@ -6,6 +6,9 @@
 #ifndef _MD5_SHA1_SUM_H
 #define _MD5_SHA1_SUM_H 1
 
+/* for HASH_MD5/HASH_SHA1 */
+#include "busybox.h"
+
 /* pass in a fd and get back a fd; filename is for display only */
 typedef int (*hash_cb_t) (int, const char *);
 

diff --git a/libq/scandirat.c b/libq/scandirat.c
index c98ce59..b3d0cfe 100644
--- a/libq/scandirat.c
+++ b/libq/scandirat.c
@@ -84,3 +84,11 @@ scandir_free(struct dirent **de, int cnt)
 		free(de[cnt]);
 	free(de);
 }
+
+int
+filter_hidden(const struct dirent *dentry)
+{
+	if (dentry->d_name[0] == '.')
+		return 0;
+	return 1;
+}

diff --git a/libq/scandirat.h b/libq/scandirat.h
index 10ff256..950cbb1 100644
--- a/libq/scandirat.h
+++ b/libq/scandirat.h
@@ -19,5 +19,6 @@ int scandirat(
 #endif
 
 void scandir_free(struct dirent **de, int cnt);
+int filter_hidden(const struct dirent *dentry);
 
 #endif

diff --git a/libq/vdb.c b/libq/vdb.c
index 9bf6d1d..974986c 100644
--- a/libq/vdb.c
+++ b/libq/vdb.c
@@ -10,6 +10,8 @@
 #include "rmspace.h"
 #include "scandirat.h"
 #include "eat_file.h"
+#include "set.h"
+#include "atom.h"
 #include "vdb.h"
 
 #include <ctype.h>
@@ -345,3 +347,78 @@ next_entry:
 
 	return ret;
 }
+
+set *
+get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv)
+{
+	q_vdb_ctx *ctx;
+
+	int cfd, j;
+	int dfd, i;
+
+	char buf[_Q_PATH_MAX];
+	char slot[_Q_PATH_MAX];
+	char *slotp = slot;
+	size_t slot_len;
+
+	struct dirent **cat;
+	struct dirent **pf;
+
+	depend_atom *atom = NULL;
+	set *cpf = NULL;
+
+	ctx = q_vdb_open(sroot, svdb);
+	if (!ctx)
+		return NULL;
+
+	/* scan the cat first */
+	cfd = scandirat(ctx->vdb_fd, ".", &cat, q_vdb_filter_cat, alphasort);
+	if (cfd < 0)
+		goto fuckit;
+
+	for (j = 0; j < cfd; j++) {
+		dfd = scandirat(ctx->vdb_fd, cat[j]->d_name,
+				&pf, q_vdb_filter_pkg, alphasort);
+		if (dfd < 0)
+			continue;
+		for (i = 0; i < dfd; i++) {
+			int blen = snprintf(buf, sizeof(buf), "%s/%s/SLOT",
+					cat[j]->d_name, pf[i]->d_name);
+			if (blen < 0 || (size_t)blen >= sizeof(buf)) {
+				warnf("unable to parse long package: %s/%s",
+						cat[j]->d_name, pf[i]->d_name);
+				continue;
+			}
+
+			/* Chop the SLOT for the atom parsing. */
+			buf[blen - 5] = '\0';
+			if ((atom = atom_explode(buf)) == NULL)
+				continue;
+			/* Restore the SLOT. */
+			buf[blen - 5] = '/';
+
+			slot_len = sizeof(slot);
+			eat_file_at(ctx->vdb_fd, buf, &slotp, &slot_len);
+			rmspace(slot);
+
+			if (fullcpv) {
+				if (atom->PR_int)
+					snprintf(buf, sizeof(buf), "%s/%s-%s-r%i",
+							atom->CATEGORY, atom->PN, atom->PV, atom->PR_int);
+				else
+					snprintf(buf, sizeof(buf), "%s/%s-%s",
+							atom->CATEGORY, atom->PN, atom->PV);
+			} else {
+				snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN);
+			}
+			atom_implode(atom);
+			cpf = add_set(buf, cpf);
+		}
+		scandir_free(pf, dfd);
+	}
+	scandir_free(cat, cfd);
+
+ fuckit:
+	q_vdb_close(ctx);
+	return cpf;
+}

diff --git a/libq/vdb.h b/libq/vdb.h
index b91d1d1..80c318c 100644
--- a/libq/vdb.h
+++ b/libq/vdb.h
@@ -6,6 +6,10 @@
 #ifndef _VDB_H
 #define _VDB_H 1
 
+#include <dirent.h>
+
+#include "set.h"
+
 /* VDB context */
 typedef struct {
 	int portroot_fd, vdb_fd;
@@ -56,5 +60,6 @@ int q_vdb_foreach_pkg(const char *sroot, const char *svdb,
 int q_vdb_foreach_pkg_sorted(const char *sroot, const char *svdb,
 		q_vdb_pkg_cb callback, void *priv);
 struct dirent *q_vdb_get_next_dir(DIR *dir);
+set *get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv);
 
 #endif

diff --git a/libq/xarray.h b/libq/xarray.h
index 46cd772..22ee47a 100644
--- a/libq/xarray.h
+++ b/libq/xarray.h
@@ -33,6 +33,7 @@ typedef struct {
 #define array_init_decl { .eles = NULL, .num = 0, }
 #define array_cnt(arr) (arr)->num
 #define DECLARE_ARRAY(arr) array_t _##arr = array_init_decl, *arr = &_##arr
+#define DEFINE_ARRAY(arr) array_t *arr;
 #define xarraypush_str(arr, ele) xarraypush(arr, ele, strlen(ele) + 1 /*NUL*/)
 #define xarraypush_struct(arr, ele) xarraypush(arr, ele, sizeof(*(ele)))
 

diff --git a/qxpak.c b/libq/xpak.c
similarity index 57%
copy from qxpak.c
copy to libq/xpak.c
index bdd5294..09b58bd 100644
--- a/qxpak.c
+++ b/libq/xpak.c
@@ -1,12 +1,23 @@
 /*
- * Copyright 2005-2018 Gentoo Foundation
+ * Copyright 2005-2019 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
  */
 
-#ifdef APPLET_qxpak
+#include "main.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <xalloc.h>
+#include <assert.h>
+
+#include "basename.h"
+#include "copy_file.h"
+#include "safe_io.h"
+#include "scandirat.h"
+#include "xpak.h"
 
 /*
 # The format for a tbz2/xpak:
@@ -28,25 +39,6 @@
 #define XPAK_END_MSG         "XPAKSTOP"
 #define XPAK_END_MSG_LEN     8
 
-#define QXPAK_FLAGS "lxcd:O" COMMON_FLAGS
-static struct option const qxpak_long_opts[] = {
-	{"list",      no_argument, NULL, 'l'},
-	{"extract",   no_argument, NULL, 'x'},
-	{"create",    no_argument, NULL, 'c'},
-	{"dir",        a_argument, NULL, 'd'},
-	{"stdout",    no_argument, NULL, 'O'},
-	COMMON_LONG_OPTS
-};
-static const char * const qxpak_opts_help[] = {
-	"List the contents of an archive",
-	"Extract the contents of an archive",
-	"Create an archive of a directory/files",
-	"Change to specified directory",
-	"Write files to stdout",
-	COMMON_OPTS_HELP
-};
-#define qxpak_usage(ret) usage(ret, QXPAK_FLAGS, qxpak_long_opts, qxpak_opts_help, NULL, lookup_applet_idx("qxpak"))
-
 typedef struct {
 	int dir_fd;
 	FILE *fp;
@@ -55,18 +47,20 @@ typedef struct {
 	char *index, *data;
 } _xpak_archive;
 
-static char xpak_stdout;
-
 typedef void (*xpak_callback_t)(int,char*,int,int,int,char*);
 
-static void _xpak_walk_index(_xpak_archive *x, int argc, char **argv, xpak_callback_t func)
+static void _xpak_walk_index(
+		_xpak_archive *x,
+		int argc,
+		char **argv,
+		xpak_callback_t func)
 {
 	int i, pathname_len, data_offset, data_len;
 	char *p, pathname[100];
 
 	p = x->index;
 	while ((p - x->index) < x->index_len) {
-		pathname_len = tbz2_decode_int((unsigned char*)p);
+		pathname_len = READ_BE_INT32((unsigned char*)p);
 		assert((size_t)pathname_len < sizeof(pathname));
 		p += 4;
 		memcpy(pathname, p, pathname_len);
@@ -74,20 +68,22 @@ static void _xpak_walk_index(_xpak_archive *x, int argc, char **argv, xpak_callb
 		if (strchr(pathname, '/') != NULL || strchr(pathname, '\\') != NULL)
 			err("Index contains a file with a path: '%s'", pathname);
 		p += pathname_len;
-		data_offset = tbz2_decode_int((unsigned char*)p);
+		data_offset = READ_BE_INT32((unsigned char*)p);
 		p += 4;
-		data_len = tbz2_decode_int((unsigned char*)p);
+		data_len = READ_BE_INT32((unsigned char*)p);
 		p += 4;
 		if (argc) {
-			for (i = 0; i < argc; ++i)
+			for (i = 0; i < argc; ++i) {
 				if (argv[i] && !strcmp(pathname, argv[i])) {
 					argv[i] = NULL;
 					break;
 				}
+			}
 			if (i == argc)
 				continue;
 		}
-		(*func)(x->dir_fd, pathname, pathname_len, data_offset, data_len, x->data);
+		(*func)(x->dir_fd, pathname, pathname_len,
+				data_offset, data_len, x->data);
 	}
 
 	if (argc)
@@ -117,8 +113,8 @@ static _xpak_archive *_xpak_open(const char *file)
 	}
 
 	/* calc index and data sizes */
-	ret.index_len = tbz2_decode_int((unsigned char*)buf+XPAK_START_MSG_LEN);
-	ret.data_len = tbz2_decode_int((unsigned char*)buf+XPAK_START_MSG_LEN+4);
+	ret.index_len = READ_BE_INT32((unsigned char*)buf+XPAK_START_MSG_LEN);
+	ret.data_len = READ_BE_INT32((unsigned char*)buf+XPAK_START_MSG_LEN+4);
 	if (!ret.index_len || !ret.data_len) {
 		warn("Skipping empty archive '%s'", file);
 		goto close_and_ret;
@@ -137,20 +133,13 @@ static void _xpak_close(_xpak_archive *x)
 	fclose(x->fp);
 }
 
-static void
-_xpak_list_callback(_q_unused_ int dir_fd, char *pathname, _q_unused_ int pathname_len,
-                    int data_offset, int data_len, _q_unused_ char *data)
-{
-	if (!verbose)
-		puts(pathname);
-	else if (verbose == 1)
-		printf("%s: %i byte%c\n", pathname, data_len, (data_len>1?'s':' '));
-	else
-		printf("%s: %i byte%c @ offset byte %i\n",
-			pathname, data_len, (data_len>1?'s':' '), data_offset);
-}
-static int
-xpak_list(int dir_fd, const char *file, int argc, char **argv)
+int
+xpak_list(
+		int dir_fd,
+		const char *file,
+		int argc,
+		char **argv,
+		xpak_callback_t func)
 {
 	_xpak_archive *x;
 	char buf[BUFSIZE];
@@ -165,41 +154,20 @@ xpak_list(int dir_fd, const char *file, int argc, char **argv)
 	assert((size_t)x->index_len < sizeof(buf));
 	ret = fread(x->index, 1, x->index_len, x->fp);
 	assert(ret == (size_t)x->index_len);
-	_xpak_walk_index(x, argc, argv, &_xpak_list_callback);
+	_xpak_walk_index(x, argc, argv, func);
 
 	_xpak_close(x);
 
 	return 0;
 }
 
-static void
-_xpak_extract_callback(int dir_fd, char *pathname, _q_unused_ int pathname_len,
-                       int data_offset, int data_len, char *data)
-{
-	FILE *out;
-
-	if (verbose == 1)
-		puts(pathname);
-	else if (verbose > 1)
-		printf("%s: %i byte%c\n", pathname, data_len, (data_len>1?'s':' '));
-
-	if (!xpak_stdout) {
-		int fd = openat(dir_fd, pathname, O_WRONLY|O_CLOEXEC|O_CREAT|O_TRUNC, 0644);
-		if (fd < 0)
-			return;
-		out = fdopen(fd, "w");
-		if (!out)
-			return;
-	} else
-		out = stdout;
-
-	fwrite(data + data_offset, 1, data_len, out);
-
-	if (!xpak_stdout)
-		fclose(out);
-}
-static int
-xpak_extract(int dir_fd, const char *file, int argc, char **argv)
+int
+xpak_extract(
+	int dir_fd,
+	const char *file,
+	int argc,
+	char **argv,
+	xpak_callback_t func)
 {
 	_xpak_archive *x;
 	char buf[BUFSIZE], ext[BUFSIZE*32];
@@ -215,7 +183,8 @@ xpak_extract(int dir_fd, const char *file, int argc, char **argv)
 	assert((size_t)x->index_len < sizeof(buf));
 	in = fread(x->index, 1, x->index_len, x->fp);
 	if ((int)in != x->index_len)
-		err("index chunk: read %i bytes, wanted %i bytes", (int)in, x->index_len);
+		err("index chunk: read %i bytes, wanted %i bytes",
+				(int)in, x->index_len);
 
 	/* the xpak may be large (like when it has CONTENTS) #300744 */
 	x->data = (size_t)x->data_len < sizeof(ext) ? ext : xmalloc(x->data_len);
@@ -223,7 +192,7 @@ xpak_extract(int dir_fd, const char *file, int argc, char **argv)
 	if ((int)in != x->data_len)
 		err("data chunk: read %i bytes, wanted %i bytes", (int)in, x->data_len);
 
-	_xpak_walk_index(x, argc, argv, &_xpak_extract_callback);
+	_xpak_walk_index(x, argc, argv, func);
 
 	_xpak_close(x);
 
@@ -234,20 +203,23 @@ xpak_extract(int dir_fd, const char *file, int argc, char **argv)
 }
 
 static void
-_xpak_add_file(int dir_fd, const char *filename, struct stat *st, FILE *findex,
-               int *index_len, FILE *fdata, int *data_len)
+_xpak_add_file(
+		int dir_fd,
+		const char *filename,
+		struct stat *st,
+		FILE *findex,
+		int *index_len,
+		FILE *fdata,
+		int *data_len,
+		int verbose)
 {
 	FILE *fin;
-	unsigned char *p;
+	unsigned char intbuf[4];
+	unsigned char *p = intbuf;
 	const char *basefile;
 	int fd, in_len;
 
-	if ((basefile = strrchr(filename, '/')) == NULL) {
-		basefile = filename;
-	} else {
-		++basefile;
-		assert(*basefile);
-	}
+	basefile = basename(filename);
 
 	if (verbose == 1)
 		printf("%s\n", basefile);
@@ -256,23 +228,24 @@ _xpak_add_file(int dir_fd, const char *filename, struct stat *st, FILE *findex,
 
 	/* write out the (pathname_len) */
 	in_len = strlen(basefile);
-	p = tbz2_encode_int(in_len);
+	WRITE_BE_INT32(p, in_len);
 	fwrite(p, 1, 4, findex);
 	/* write out the pathname */
 	fwrite(basefile, 1, in_len, findex);
 	/* write out the (data_offset) */
-	p = tbz2_encode_int(*data_len);
+	WRITE_BE_INT32(p, *data_len);
 	fwrite(p, 1, 4, findex);
 
 	*index_len += 4 + in_len + 4 + 4;
 
-	/* now open the file, get (data_len), and append the file to the data file */
+	/* now open the file, get (data_len),
+	 * and append the file to the data file */
 	fd = openat(dir_fd, filename, O_RDONLY|O_CLOEXEC);
 	if (fd < 0) {
  open_fail:
 		warnp("could not open for reading: %s", filename);
  fake_data_len:
-		p = tbz2_encode_int(0);
+		WRITE_BE_INT32(p, 0);
 		fwrite(p, 1, 4, findex);
 		return;
 	}
@@ -289,21 +262,29 @@ _xpak_add_file(int dir_fd, const char *filename, struct stat *st, FILE *findex,
 		fclose(fin);
 		goto fake_data_len;
 	}
-	p = tbz2_encode_int(in_len);
+	WRITE_BE_INT32(p, in_len);
 	fwrite(p, 1, 4, findex);
-	_tbz2_copy_file(fin, fdata);
+	copy_file(fin, fdata);
 	fclose(fin);
 
 	*data_len += in_len;
 }
-static int
-xpak_create(int dir_fd, const char *file, int argc, char **argv)
+
+int
+xpak_create(
+		int dir_fd,
+		const char *file,
+		int argc,
+		char **argv,
+		char append,
+		int verbose)
 {
 	FILE *findex, *fdata, *fout;
 	struct dirent **dir;
 	int i, fidx, numfiles;
 	struct stat st;
 	char path[_Q_PATH_MAX];
+	unsigned char intbuf[4];
 	unsigned char *p;
 	int index_len, data_len;
 
@@ -313,7 +294,7 @@ xpak_create(int dir_fd, const char *file, int argc, char **argv)
 	if (strlen(file) >= sizeof(path)-6)
 		err("Pathname is too long: %s", file);
 
-	if ((fout = fopen(file, "w")) == NULL) {
+	if ((fout = fopen(file, append ? "a" : "w")) == NULL) {
 		warnp("could not open output: %s", file);
 		return 1;
 	}
@@ -338,7 +319,8 @@ xpak_create(int dir_fd, const char *file, int argc, char **argv)
 			continue;
 		}
 		if (S_ISDIR(st.st_mode)) {
-			if ((numfiles = scandir(argv[i], &dir, filter_hidden, alphasort)) < 0)
+			if ((numfiles =
+						scandir(argv[i], &dir, filter_hidden, alphasort)) < 0)
 				warn("Directory '%s' is empty; skipping", argv[i]);
 			for (fidx = 0; fidx < numfiles; ++fidx) {
 				int ret = snprintf(path, sizeof(path), "%s/%s",
@@ -352,11 +334,13 @@ xpak_create(int dir_fd, const char *file, int argc, char **argv)
 					warnp("could not read %s", path);
 					continue;
 				}
-				_xpak_add_file(dir_fd, path, &st, findex, &index_len, fdata, &data_len);
+				_xpak_add_file(dir_fd, path, &st,
+						findex, &index_len, fdata, &data_len, verbose);
 			}
 			scandir_free(dir, numfiles);
 		} else if (S_ISREG(st.st_mode)) {
-			_xpak_add_file(dir_fd, argv[i], &st, findex, &index_len, fdata, &data_len);
+			_xpak_add_file(dir_fd, argv[i], &st,
+					findex, &index_len, fdata, &data_len, verbose);
 		} else
 			warn("Skipping non file/directory '%s'", argv[i]);
 	}
@@ -366,12 +350,13 @@ xpak_create(int dir_fd, const char *file, int argc, char **argv)
 
 	/* "XPAKPACK" + (index_len) + (data_len) + index + data + "XPAKSTOP" */
 	fwrite(XPAK_START_MSG, 1, XPAK_START_MSG_LEN, fout); /* "XPAKPACK" */
-	p = tbz2_encode_int(index_len);
+	p = intbuf;
+	WRITE_BE_INT32(p, index_len);
 	fwrite(p, 1, 4, fout);                               /* (index_len) */
-	p = tbz2_encode_int(data_len);
+	WRITE_BE_INT32(p, data_len);
 	fwrite(p, 1, 4, fout);                               /* (data_len) */
-	_tbz2_copy_file(findex, fout);                       /* index */
-	_tbz2_copy_file(fdata, fout);                        /* data */
+	copy_file(findex, fout);                       /* index */
+	copy_file(fdata, fout);                        /* data */
 	fwrite(XPAK_END_MSG, 1, XPAK_END_MSG_LEN, fout);     /* "XPAKSTOP" */
 
 	strcpy(path, file); strcat(path, ".index"); unlink(path);
@@ -382,53 +367,3 @@ xpak_create(int dir_fd, const char *file, int argc, char **argv)
 
 	return 0;
 }
-
-int qxpak_main(int argc, char **argv)
-{
-	enum { XPAK_ACT_NONE, XPAK_ACT_LIST, XPAK_ACT_EXTRACT, XPAK_ACT_CREATE };
-	int i, ret, dir_fd;
-	char *xpak;
-	char action = XPAK_ACT_NONE;
-
-	dir_fd = AT_FDCWD;
-	xpak_stdout = 0;
-
-	while ((i = GETOPT_LONG(QXPAK, qxpak, "")) != -1) {
-		switch (i) {
-		COMMON_GETOPTS_CASES(qxpak)
-		case 'l': action = XPAK_ACT_LIST; break;
-		case 'x': action = XPAK_ACT_EXTRACT; break;
-		case 'c': action = XPAK_ACT_CREATE; break;
-		case 'O': xpak_stdout = 1; break;
-		case 'd':
-			if (dir_fd != AT_FDCWD)
-				err("Only use -d once");
-			dir_fd = open(optarg, O_RDONLY|O_CLOEXEC|O_PATH);
-			if (dir_fd < 0)
-				errp("Could not open directory %s", optarg);
-			break;
-		}
-	}
-	if (optind == argc || action == XPAK_ACT_NONE)
-		qxpak_usage(EXIT_FAILURE);
-
-	xpak = argv[optind++];
-	argc -= optind;
-	argv += optind;
-
-	switch (action) {
-	case XPAK_ACT_LIST:    ret = xpak_list(dir_fd, xpak, argc, argv); break;
-	case XPAK_ACT_EXTRACT: ret = xpak_extract(dir_fd, xpak, argc, argv); break;
-	case XPAK_ACT_CREATE:  ret = xpak_create(dir_fd, xpak, argc, argv); break;
-	default: ret = EXIT_FAILURE;
-	}
-
-	if (dir_fd != AT_FDCWD)
-		close(dir_fd);
-
-	return ret;
-}
-
-#else
-DEFINE_APPLET_STUB(qxpak)
-#endif

diff --git a/libq/xpak.h b/libq/xpak.h
new file mode 100644
index 0000000..0b318b2
--- /dev/null
+++ b/libq/xpak.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2005-2019 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ */
+
+#ifndef _XPAK_H
+#define _XPAK_H 1
+
+typedef void (*xpak_callback_t)(int,char*,int,int,int,char*);
+
+int xpak_list(
+		int dir_fd,
+		const char *file,
+		int argc,
+		char **argv,
+		xpak_callback_t func);
+int xpak_extract(
+	int dir_fd,
+	const char *file,
+	int argc,
+	char **argv,
+	xpak_callback_t func);
+int xpak_create(
+		int dir_fd,
+		const char *file,
+		int argc,
+		char **argv,
+		char append,
+		int v);
+
+#endif

diff --git a/libq/xregex.c b/libq/xregex.c
index d299edd..3151254 100644
--- a/libq/xregex.c
+++ b/libq/xregex.c
@@ -26,3 +26,20 @@ void xregcomp(regex_t *preg, const char *regex, int cflags)
 	if (unlikely(wregcomp(preg, regex, cflags)))
 		exit(EXIT_FAILURE);
 }
+
+int
+rematch(const char *re, const char *match, int cflags)
+{
+	regex_t preg;
+	int ret;
+
+	if ((match == NULL) || (re == NULL))
+		return EXIT_FAILURE;
+
+	if (wregcomp(&preg, re, cflags))
+		return EXIT_FAILURE;
+	ret = regexec(&preg, match, 0, NULL, 0);
+	regfree(&preg);
+
+	return ret;
+}

diff --git a/libq/xregex.h b/libq/xregex.h
index fd75030..59fc51b 100644
--- a/libq/xregex.h
+++ b/libq/xregex.h
@@ -12,5 +12,6 @@
 
 int wregcomp(regex_t *preg, const char *regex, int cflags);
 void xregcomp(regex_t *preg, const char *regex, int cflags);
+int rematch(const char *, const char *, int);
 
 #endif

diff --git a/main.c b/main.c
index 01d358a..1da04fe 100644
--- a/main.c
+++ b/main.c
@@ -8,9 +8,19 @@
  */
 
 #include "main.h"
+#include "applets.h"
+
+#include <iniparser.h>
+#include <xalloc.h>
+#include <assert.h>
+#include <ctype.h>
+#include <sys/time.h>
+#include <limits.h>
+
 #include "atom.h"
 #include "basename.h"
 #include "busybox.h"
+#include "cache.h"
 #include "colors.h"
 #include "copy_file.h"
 #include "eat_file.h"
@@ -32,34 +42,6 @@
 #include "xregex.h"
 #include "xsystem.h"
 
-#include <iniparser.h>
-#include <xalloc.h>
-#include <assert.h>
-#include <ctype.h>
-#include <sys/time.h>
-#include <limits.h>
-
-#if defined(__sun) && defined(__SVR4)
-/* workaround non-const defined name in option struct, such that we
- * don't get a zillion of warnings */
-#define	no_argument		0
-#define	required_argument	1
-#define	optional_argument	2
-struct option {
-	const char *name;
-	int has_arg;
-	int *flag;
-	int val;
-};
-extern int	getopt_long(int, char * const *, const char *,
-		    const struct option *, int *);
-#else
-# include <getopt.h>
-#endif
-
-/* prototypes and such */
-static int lookup_applet_idx(const char *);
-
 /* variables to control runtime behavior */
 char *module_name = NULL;
 char *modpath = NULL;
@@ -67,29 +49,26 @@ int verbose = 0;
 int quiet = 0;
 int portcachedir_type = 0;
 char pretend = 0;
-static int reinitialize = 0;
-static int reinitialize_metacache = 0;
-static char *portlogdir;
+char *portroot;
+char *config_protect;
+char *config_protect_mask;
+char *portvdb;
+char *portlogdir;
+char *pkg_install_mask;
+char *binhost;
+char *pkgdir;
+char *port_tmpdir;
+char *features;
+char *install_mask;
+DECLARE_ARRAY(overlays);
+
 static char *main_overlay;
 static char *portarch;
-static char *portvdb;
 static char *portedb;
 const char portcachedir_pms[] = "metadata/cache";
 const char portcachedir_md5[] = "metadata/md5-cache";
-static char *portroot;
 static char *eprefix;
-static char *config_protect, *config_protect_mask;
-
-static char *pkgdir;
-static char *port_tmpdir;
-
-static char *binhost;
-static char *features;
 static char *accept_license;
-static char *install_mask;
-static char *pkg_install_mask;
-
-const char err_noapplet[] = "Sorry this applet was disabled at compile time";
 
 /* helper functions for showing errors */
 const char *argv0;
@@ -108,9 +87,7 @@ init_coredumps(void)
 }
 #endif
 
-static DECLARE_ARRAY(overlays);
-
-static void
+void
 no_colors(void)
 {
 	BOLD = NORM = BLUE = DKBLUE = CYAN = GREEN = DKGREEN = \
@@ -118,7 +95,7 @@ no_colors(void)
 	setenv("NOCOLOR", "true", 1);
 }
 
-static void
+void
 setup_quiet(void)
 {
 	/* "e" for FD_CLOEXEC */
@@ -127,38 +104,8 @@ setup_quiet(void)
 	++quiet;
 }
 
-/* include common applet defs */
-#include "applets.h"
-
-/* Common usage for all applets */
-#define COMMON_FLAGS "vqChV"
-#define COMMON_LONG_OPTS \
-	{"root",       a_argument, NULL, 0x1}, \
-	{"verbose",   no_argument, NULL, 'v'}, \
-	{"quiet",     no_argument, NULL, 'q'}, \
-	{"nocolor",   no_argument, NULL, 'C'}, \
-	{"help",      no_argument, NULL, 'h'}, \
-	{"version",   no_argument, NULL, 'V'}, \
-	{NULL,        no_argument, NULL, 0x0}
-#define COMMON_OPTS_HELP \
-	"Set the ROOT env var", \
-	"Make a lot of noise", \
-	"Tighter output; suppress warnings", \
-	"Don't output color", \
-	"Print this help and exit", \
-	"Print version and exit", \
-	NULL
-#define COMMON_GETOPTS_CASES(applet) \
-	case 0x1: portroot = optarg; break; \
-	case 'v': ++verbose; break; \
-	case 'q': setup_quiet(); break; \
-	case 'V': version_barf(); break; \
-	case 'h': applet ## _usage(EXIT_SUCCESS); break; \
-	case 'C': no_colors(); break; \
-	default: applet ## _usage(EXIT_FAILURE); break;
-
 /* display usage and exit */
-static void
+void
 usage(int status, const char *flags, struct option const opts[],
       const char * const help[], const char *desc, int blabber)
 {
@@ -226,7 +173,7 @@ usage(int status, const char *flags, struct option const opts[],
 	exit(status);
 }
 
-static void
+void
 version_barf(void)
 {
 	const char *vcsid = "";
@@ -250,39 +197,7 @@ version_barf(void)
 	exit(EXIT_SUCCESS);
 }
 
-static bool
-prompt(const char *p)
-{
-	printf("%s? [Y/n] ", p);
-	fflush(stdout);
-	switch (getc(stdin)) {
-	case '\n':
-	case 'y':
-	case 'Y':
-		return true;
-	default:
-		return false;
-	}
-}
-
-int
-rematch(const char *re, const char *match, int cflags)
-{
-	regex_t preg;
-	int ret;
-
-	if ((match == NULL) || (re == NULL))
-		return EXIT_FAILURE;
-
-	if (wregcomp(&preg, re, cflags))
-		return EXIT_FAILURE;
-	ret = regexec(&preg, match, 0, NULL, 0);
-	regfree(&preg);
-
-	return ret;
-}
-
-static void
+void
 freeargv(int argc, char **argv)
 {
 	while (argc--)
@@ -290,7 +205,7 @@ freeargv(int argc, char **argv)
 	free(argv);
 }
 
-static void
+void
 makeargv(const char *string, int *argc, char ***argv)
 {
 	int curc = 2;
@@ -320,96 +235,6 @@ makeargv(const char *string, int *argc, char ***argv)
 	free(q);
 }
 
-/*
- * Parse a line of CONTENTS file and provide access to the individual fields
- */
-typedef enum {
-	CONTENTS_DIR, CONTENTS_OBJ, CONTENTS_SYM
-} contents_type;
-typedef struct {
-	contents_type type;
-	char *_data;
-	char *name;
-	char *sym_target;
-	char *digest;
-	char *mtime_str;
-	long mtime;
-} contents_entry;
-
-static contents_entry *
-contents_parse_line(char *line)
-{
-	static contents_entry e;
-	char *p;
-
-	if (!line || !*line || *line == '\n')
-		return NULL;
-
-	/* chop trailing newline */
-	if ((p = strrchr(line, '\n')) != NULL)
-		*p = '\0';
-
-	/* ferringb wants to break portage/vdb by using tabs vs spaces
-	 * so filenames can have lame ass spaces in them..
-	 * (I smell Windows near by)
-	 * Anyway we just convert that crap to a space so we can still
-	 * parse quickly */
-	p = line;
-	while ((p = strchr(p, '\t')) != NULL)
-		*p = ' ';
-
-	memset(&e, 0x00, sizeof(e));
-	e._data = line;
-
-	if (!strncmp(e._data, "obj ", 4))
-		e.type = CONTENTS_OBJ;
-	else if (!strncmp(e._data, "dir ", 4))
-		e.type = CONTENTS_DIR;
-	else if (!strncmp(e._data, "sym ", 4))
-		e.type = CONTENTS_SYM;
-	else
-		return NULL;
-
-	e.name = e._data + 4;
-
-	switch (e.type) {
-		/* dir /bin */
-		case CONTENTS_DIR:
-			break;
-
-		/* obj /bin/bash 62ed51c8b23866777552643ec57614b0 1120707577 */
-		case CONTENTS_OBJ:
-			if ((e.mtime_str = strrchr(e.name, ' ')) == NULL)
-				return NULL;
-			*e.mtime_str++ = '\0';
-			if ((e.digest = strrchr(e.name, ' ')) == NULL)
-				return NULL;
-			*e.digest++ = '\0';
-			break;
-
-		/* sym /bin/sh -> bash 1120707577 */
-		case CONTENTS_SYM:
-			if ((e.mtime_str = strrchr(e.name, ' ')) == NULL)
-				return NULL;
-			*e.mtime_str++ = '\0';
-			if ((e.sym_target = strstr(e.name, " -> ")) == NULL)
-				return NULL;
-			*e.sym_target = '\0';
-			e.sym_target += 4;
-			break;
-	}
-
-	if (e.mtime_str) {
-		e.mtime = strtol(e.mtime_str, NULL, 10);
-		if (e.mtime == LONG_MAX) {
-			e.mtime = 0;
-			e.mtime_str = NULL;
-		}
-	}
-
-	return &e;
-}
-
 /* Handle a single file in the repos.conf format. */
 static void
 read_one_repos_conf(const char *repos_conf)
@@ -958,22 +783,7 @@ initialize_portage_env(void)
 		color_remap();
 }
 
-enum {
-	CACHE_EBUILD = 1,
-	CACHE_METADATA = 2,
-	CACHE_METADATA_PMS = 10,
-	CACHE_METADATA_MD5 = 11,
-};
-
-static int
-filter_hidden(const struct dirent *dentry)
-{
-	if (dentry->d_name[0] == '.')
-		return 0;
-	return 1;
-}
-
-static const char *
+const char *
 initialize_flat(const char *overlay, int cache_type, bool force)
 {
 	struct dirent **category, **pn, **eb;
@@ -1109,357 +919,6 @@ ret:
 	return cache_file;
 }
 
-static void
-reinitialize_as_needed(void)
-{
-	size_t n;
-	const char *overlay, *ret = ret;
-
-	if (reinitialize)
-		array_for_each(overlays, n, overlay) {
-			ret = initialize_flat(overlay, CACHE_EBUILD, true);
-			if (USE_CLEANUP)
-				free((void *)ret);
-		}
-
-	if (reinitialize_metacache)
-		array_for_each(overlays, n, overlay) {
-			ret = initialize_flat(overlay, CACHE_METADATA, true);
-			if (USE_CLEANUP)
-				free((void *)ret);
-		}
-}
-
-typedef struct {
-	char *_data;
-	char *DEPEND;        /* line 1 */
-	char *RDEPEND;
-	char *SLOT;
-	char *SRC_URI;
-	char *RESTRICT;      /* line 5 */
-	char *HOMEPAGE;
-	char *LICENSE;
-	char *DESCRIPTION;
-	char *KEYWORDS;
-	char *INHERITED;     /* line 10 */
-	char *IUSE;
-	char *CDEPEND;
-	char *PDEPEND;
-	char *PROVIDE;       /* line 14 */
-	char *EAPI;
-	char *PROPERTIES;
-	depend_atom *atom;
-	/* These are MD5-Cache only */
-	char *DEFINED_PHASES;
-	char *REQUIRED_USE;
-	char *_eclasses_;
-	char *_md5_;
-} portage_cache;
-
-static void cache_free(portage_cache *cache);
-static portage_cache *cache_read_file_pms(const char *file);
-static portage_cache *cache_read_file_md5(const char *file);
-
-static portage_cache *
-cache_read_file(const char *file)
-{
-	if (portcachedir_type == CACHE_METADATA_MD5)
-		return(cache_read_file_md5(file));
-	else if (portcachedir_type == CACHE_METADATA_PMS)
-		return(cache_read_file_pms(file));
-	warn("Unknown metadata cache type!");
-	return NULL;
-}
-
-static portage_cache *
-cache_read_file_pms(const char *file)
-{
-	struct stat s;
-	char *ptr;
-	FILE *f;
-	portage_cache *ret = NULL;
-	size_t len;
-
-	if ((f = fopen(file, "r")) == NULL)
-		goto err;
-
-	if (fstat(fileno(f), &s) != 0)
-		goto err;
-	len = sizeof(*ret) + s.st_size + 1;
-	ret = xzalloc(len);
-	ptr = (char*)ret;
-	ret->_data = ptr + sizeof(*ret);
-	if ((off_t)fread(ret->_data, 1, s.st_size, f) != s.st_size)
-		goto err;
-
-	ret->atom = atom_explode(file);
-	ret->DEPEND = ret->_data;
-#define next_line(curr, next) \
-	if ((ptr = strchr(ret->curr, '\n')) == NULL) { \
-		warn("Invalid cache file '%s'", file); \
-		goto err; \
-	} \
-	ret->next = ptr+1; \
-	*ptr = '\0';
-	next_line(DEPEND, RDEPEND)
-	next_line(RDEPEND, SLOT)
-	next_line(SLOT, SRC_URI)
-	next_line(SRC_URI, RESTRICT)
-	next_line(RESTRICT, HOMEPAGE)
-	next_line(HOMEPAGE, LICENSE)
-	next_line(LICENSE, DESCRIPTION)
-	next_line(DESCRIPTION, KEYWORDS)
-	next_line(KEYWORDS, INHERITED)
-	next_line(INHERITED, IUSE)
-	next_line(IUSE, CDEPEND)
-	next_line(CDEPEND, PDEPEND)
-	next_line(PDEPEND, PROVIDE)
-	next_line(PROVIDE, EAPI)
-	next_line(EAPI, PROPERTIES)
-#undef next_line
-	ptr = strchr(ptr+1, '\n');
-	if (ptr == NULL) {
-		warn("Invalid cache file '%s' - could not find end of cache data", file);
-		goto err;
-	}
-	*ptr = '\0';
-
-	fclose(f);
-
-	return ret;
-
-err:
-	if (f) fclose(f);
-	if (ret) cache_free(ret);
-	return NULL;
-}
-
-static portage_cache *
-cache_read_file_md5(const char *file)
-{
-	struct stat s;
-	char *ptr, *endptr;
-	FILE *f;
-	portage_cache *ret = NULL;
-	size_t len;
-
-	if ((f = fopen(file, "r")) == NULL)
-		goto err;
-
-	if (fstat(fileno(f), &s) != 0)
-		goto err;
-	len = sizeof(*ret) + s.st_size + 1;
-	ret = xzalloc(len);
-	ptr = (char*)ret;
-	ret->_data = ptr + sizeof(*ret);
-	if ((off_t)fread(ret->_data, 1, s.st_size, f) != s.st_size)
-		goto err;
-
-	ret->atom = atom_explode(file);
-
-	/* We have a block of key=value\n data.
-	 * KEY=VALUE\n
-	 * Where KEY does NOT contain:
-	 * \0 \n =
-	 * And VALUE does NOT contain:
-	 * \0 \n
-	 * */
-#define assign_var_cmp(keyname, cmpkey) \
-	if (strncmp(keyptr, cmpkey, strlen(cmpkey)) == 0) { \
-		ret->keyname = valptr; \
-		continue; \
-	}
-#define assign_var(keyname) \
-	assign_var_cmp(keyname, #keyname);
-
-	ptr = ret->_data;
-	endptr = strchr(ptr, '\0');
-	if (endptr == NULL) {
-			warn("Invalid cache file '%s' - could not find end of cache data", file);
-			goto err;
-	}
-
-	while (ptr != NULL && ptr != endptr) {
-		char *keyptr;
-		char *valptr;
-		keyptr = ptr;
-		valptr = strchr(ptr, '=');
-		if (valptr == NULL) {
-			warn("Invalid cache file '%s' val", file);
-			goto err;
-		}
-		*valptr = '\0';
-		valptr++;
-		ptr = strchr(valptr, '\n');
-		if (ptr == NULL) {
-			warn("Invalid cache file '%s' key", file);
-			goto err;
-		}
-		*ptr = '\0';
-		ptr++;
-
-		assign_var(CDEPEND);
-		assign_var(DEPEND);
-		assign_var(DESCRIPTION);
-		assign_var(EAPI);
-		assign_var(HOMEPAGE);
-		assign_var(INHERITED);
-		assign_var(IUSE);
-		assign_var(KEYWORDS);
-		assign_var(LICENSE);
-		assign_var(PDEPEND);
-		assign_var(PROPERTIES);
-		assign_var(PROVIDE);
-		assign_var(RDEPEND);
-		assign_var(RESTRICT);
-		assign_var(SLOT);
-		assign_var(SRC_URI);
-		assign_var(DEFINED_PHASES);
-		assign_var(REQUIRED_USE);
-		assign_var(_eclasses_);
-		assign_var(_md5_);
-		warn("Cache file '%s' with unknown key %s", file, keyptr);
-	}
-#undef assign_var
-#undef assign_var_cmp
-
-	fclose(f);
-
-	return ret;
-
-err:
-	if (f) fclose(f);
-	if (ret) cache_free(ret);
-	return NULL;
-}
-
-#ifdef EBUG
-static void
-cache_dump(portage_cache *cache)
-{
-	if (!cache)
-		errf("Cache is empty !");
-
-	printf("DEPEND     : %s\n", cache->DEPEND);
-	printf("RDEPEND    : %s\n", cache->RDEPEND);
-	printf("SLOT       : %s\n", cache->SLOT);
-	printf("SRC_URI    : %s\n", cache->SRC_URI);
-	printf("RESTRICT   : %s\n", cache->RESTRICT);
-	printf("HOMEPAGE   : %s\n", cache->HOMEPAGE);
-	printf("LICENSE    : %s\n", cache->LICENSE);
-	printf("DESCRIPTION: %s\n", cache->DESCRIPTION);
-	printf("KEYWORDS   : %s\n", cache->KEYWORDS);
-	printf("INHERITED  : %s\n", cache->INHERITED);
-	printf("IUSE       : %s\n", cache->IUSE);
-	printf("CDEPEND    : %s\n", cache->CDEPEND);
-	printf("PDEPEND    : %s\n", cache->PDEPEND);
-	printf("PROVIDE    : %s\n", cache->PROVIDE);
-	printf("EAPI       : %s\n", cache->EAPI);
-	printf("PROPERTIES : %s\n", cache->PROPERTIES);
-	if (!cache->atom) return;
-	printf("CATEGORY   : %s\n", cache->atom->CATEGORY);
-	printf("PN         : %s\n", cache->atom->PN);
-	printf("PV         : %s\n", cache->atom->PV);
-	printf("PVR        : %s\n", cache->atom->PVR);
-}
-#endif
-
-static void
-cache_free(portage_cache *cache)
-{
-	if (!cache)
-		errf("Cache is empty !");
-	atom_implode(cache->atom);
-	free(cache);
-}
-
-static char *
-atom_to_pvr(depend_atom *atom) {
-	return (atom->PR_int == 0 ? atom->P : atom->PVR );
-}
-
-/* TODO: Merge this into libq/vdb.c somehow. */
-static set *
-get_vdb_atoms(int fullcpv)
-{
-	q_vdb_ctx *ctx;
-
-	int cfd, j;
-	int dfd, i;
-
-	char buf[_Q_PATH_MAX];
-	char slot[_Q_PATH_MAX];
-	char *slotp = slot;
-	size_t slot_len;
-
-	struct dirent **cat;
-	struct dirent **pf;
-
-	depend_atom *atom = NULL;
-	set *cpf = NULL;
-
-	ctx = q_vdb_open(portroot, portvdb);
-	if (!ctx)
-		return NULL;
-
-	/* scan the cat first */
-	cfd = scandirat(ctx->vdb_fd, ".", &cat, q_vdb_filter_cat, alphasort);
-	if (cfd < 0)
-		goto fuckit;
-
-	for (j = 0; j < cfd; j++) {
-		dfd = scandirat(ctx->vdb_fd, cat[j]->d_name,
-				&pf, q_vdb_filter_pkg, alphasort);
-		if (dfd < 0)
-			continue;
-		for (i = 0; i < dfd; i++) {
-			int blen = snprintf(buf, sizeof(buf), "%s/%s/SLOT",
-					cat[j]->d_name, pf[i]->d_name);
-			if (blen < 0 || (size_t)blen >= sizeof(buf)) {
-				warnf("unable to parse long package: %s/%s",
-						cat[j]->d_name, pf[i]->d_name);
-				continue;
-			}
-
-			/* Chop the SLOT for the atom parsing. */
-			buf[blen - 5] = '\0';
-			if ((atom = atom_explode(buf)) == NULL)
-				continue;
-			/* Restore the SLOT. */
-			buf[blen - 5] = '/';
-
-			slot_len = sizeof(slot);
-			eat_file_at(ctx->vdb_fd, buf, &slotp, &slot_len);
-			rmspace(slot);
-
-			if (fullcpv) {
-				if (atom->PR_int)
-					snprintf(buf, sizeof(buf), "%s/%s-%s-r%i",
-							atom->CATEGORY, atom->PN, atom->PV, atom->PR_int);
-				else
-					snprintf(buf, sizeof(buf), "%s/%s-%s",
-							atom->CATEGORY, atom->PN, atom->PV);
-			} else {
-				snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN);
-			}
-			atom_implode(atom);
-			cpf = add_set(buf, cpf);
-		}
-		scandir_free(pf, dfd);
-	}
-	scandir_free(cat, cfd);
-
- fuckit:
-	q_vdb_close(ctx);
-	return cpf;
-}
-
-static void
-cleanup(void)
-{
-	reinitialize_as_needed();
-}
-
 int main(int argc, char **argv)
 {
 	struct stat st;
@@ -1478,9 +937,6 @@ int main(int argc, char **argv)
 		no_colors();
 
 	initialize_portage_env();
-	atexit(cleanup);
 	optind = 0;
 	return q_main(argc, argv);
 }
-
-#include "include_applets.h"

diff --git a/main.h b/main.h
index ef98c5d..958efa6 100644
--- a/main.h
+++ b/main.h
@@ -52,6 +52,16 @@ extern const char *argv0;
 # define MAX(x, y) ((x) < (y) ? (y) : (x))
 #endif
 
+#define READ_BE_INT32(P) \
+	(((P)[0] << 24) | ((P)[1] << 16) | ((P)[2] << 8 ) | (P)[3])
+#define WRITE_BE_INT32(P,I) \
+{ \
+	(P)[0] = (I & 0xff000000) >> 24; \
+	(P)[1] = (I & 0x00ff0000) >> 16; \
+	(P)[2] = (I & 0x0000ff00) >> 8; \
+	(P)[3] = (I & 0x000000ff); \
+}
+
 /* Easy enough to glue to older versions */
 #ifndef O_CLOEXEC
 # define O_CLOEXEC 0
@@ -122,6 +132,4 @@ extern FILE *warnout;
 #define errp(fmt, args...) _err(warnp, fmt , ## args)
 #define errfp(fmt, args...) _err(warnfp, fmt, ## args)
 
-int rematch(const char *, const char *, int);
-
 #endif

diff --git a/q.c b/q.c
index e5cc369..a4a943e 100644
--- a/q.c
+++ b/q.c
@@ -7,6 +7,17 @@
  * Copyright 2017-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
+#include "main.h"
+#include "applets.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "atom.h"
+#include "basename.h"
+#include "cache.h"
+
 #define Q_FLAGS "irmM:" COMMON_FLAGS
 static struct option const q_long_opts[] = {
 	{"install",       no_argument, NULL, 'i'},
@@ -24,7 +35,7 @@ static const char * const q_opts_help[] = {
 };
 #define q_usage(ret) usage(ret, Q_FLAGS, q_long_opts, q_opts_help, NULL, lookup_applet_idx("q"))
 
-static APPLET lookup_applet(const char *applet)
+APPLET lookup_applet(const char *applet)
 {
 	unsigned int i;
 
@@ -34,7 +45,8 @@ static APPLET lookup_applet(const char *applet)
 	for (i = 0; applets[i].name; ++i) {
 		if (strcmp(applets[i].name, applet) == 0) {
 			argv0 = applets[i].name;
-			if (i && applets[i].desc != NULL) ++argv0; /* chop the leading 'q' */
+			if (i && applets[i].desc != NULL)
+				++argv0; /* chop the leading 'q' */
 			return applets[i].func;
 		}
 	}
@@ -60,11 +72,34 @@ int lookup_applet_idx(const char *applet)
 	return 0;
 }
 
+static void
+reinitialize_as_needed(int reinitialize, int reinitialize_metacache)
+{
+	size_t n;
+	const char *overlay, *ret = ret;
+
+	if (reinitialize)
+		array_for_each(overlays, n, overlay) {
+			ret = initialize_flat(overlay, CACHE_EBUILD, true);
+			if (USE_CLEANUP)
+				free((void *)ret);
+		}
+
+	if (reinitialize_metacache)
+		array_for_each(overlays, n, overlay) {
+			ret = initialize_flat(overlay, CACHE_METADATA, true);
+			if (USE_CLEANUP)
+				free((void *)ret);
+		}
+}
+
 int q_main(int argc, char **argv)
 {
 	int i, install;
 	const char *p;
 	APPLET func;
+	int reinitialize_metacache = 0;
+	int reinitialize = 0;
 
 	if (argc == 0)
 		return 1;
@@ -161,8 +196,10 @@ int q_main(int argc, char **argv)
 		return ret;
 	}
 
-	if (reinitialize > 0 || reinitialize_metacache > 0)
+	if (reinitialize > 0 || reinitialize_metacache > 0) {
+		reinitialize_as_needed(reinitialize, reinitialize_metacache);
 		return 0;
+	}
 	if (reinitialize < 0 || reinitialize_metacache < 0) {
 		reinitialize = reinitialize_metacache = 0;
 		return 0;

diff --git a/qatom.c b/qatom.c
index d7782ea..c1af10d 100644
--- a/qatom.c
+++ b/qatom.c
@@ -1,12 +1,18 @@
 /*
- * Copyright 2005-2018 Gentoo Foundation
+ * Copyright 2005-2019 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
  */
 
-#ifdef APPLET_qatom
+#include "main.h"
+
+#include <stdlib.h>
+#include <stdbool.h>
+
+#include "atom.h"
+#include "applets.h"
 
 #define QATOM_FORMAT "%{CATEGORY} %{PN} %{PV} %[PR] %[SLOT] %[pfx] %[sfx]"
 
@@ -148,7 +154,3 @@ int qatom_main(int argc, char **argv)
 
 	return EXIT_SUCCESS;
 }
-
-#else
-DEFINE_APPLET_STUB(qatom)
-#endif

diff --git a/qcache.c b/qcache.c
index e4b6a7e..29b10af 100644
--- a/qcache.c
+++ b/qcache.c
@@ -5,7 +5,23 @@
  * Copyright 2006 Thomas A. Cort - <tcort@gentoo.org>
  */
 
-#ifdef APPLET_qcache
+#include "main.h"
+#include "applets.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <xalloc.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "atom.h"
+#include "cache.h"
+#include "scandirat.h"
+#include "rmspace.h"
+#include "set.h"
+#include "xasprintf.h"
 
 /********************************************************************/
 /* Required portage-utils stuff                                     */
@@ -358,7 +374,9 @@ qcache_vercmp(const struct dirent **x, const struct dirent **y)
 static int
 qcache_file_select(const struct dirent *entry)
 {
-	return !(entry->d_name[0] == '.' || (strcmp(entry->d_name, "metadata.xml") == 0) || (strstr(entry->d_name, ".cpickle") != 0));
+	return !(entry->d_name[0] == '.' ||
+			(strcmp(entry->d_name, "metadata.xml") == 0) ||
+			(strstr(entry->d_name, ".cpickle") != 0));
 }
 
 /*
@@ -374,7 +392,8 @@ qcache_file_select(const struct dirent *entry)
 static int
 qcache_ebuild_select(const struct dirent *entry)
 {
-	return ((strlen(entry->d_name) > 7) && !strcmp(entry->d_name+strlen(entry->d_name)-7, ".ebuild"));
+	return ((strlen(entry->d_name) > 7) &&
+			!strcmp(entry->d_name+strlen(entry->d_name)-7, ".ebuild"));
 }
 
 /********************************************************************/
@@ -594,10 +613,13 @@ qcache_not(qcache_data *data)
 		return;
 	}
 
-	if (keywords[qcache_test_arch] == testing || keywords[qcache_test_arch] == stable) {
+	if (keywords[qcache_test_arch] == testing ||
+			keywords[qcache_test_arch] == stable)
+	{
 		qcache_skip = 1;
 	} else if (data->cur == data->num) {
-		printf("%s%s/%s%s%s\n", BOLD, data->category, BLUE, data->package, NORM);
+		printf("%s%s/%s%s%s\n", BOLD, data->category, BLUE,
+				data->package, NORM);
 	}
 
 	free(keywords);
@@ -621,9 +643,12 @@ qcache_all(qcache_data *data)
 		return;
 	}
 
-	if (keywords[qcache_test_arch] == stable || keywords[qcache_test_arch] == testing) {
+	if (keywords[qcache_test_arch] == stable ||
+			keywords[qcache_test_arch] == testing)
+	{
 		qcache_skip = 1;
-		printf("%s%s/%s%s%s\n", BOLD, data->category, BLUE, data->package, NORM);
+		printf("%s%s/%s%s%s\n", BOLD, data->category, BLUE,
+				data->package, NORM);
 	}
 
 	free(keywords);
@@ -651,11 +676,14 @@ qcache_dropped(qcache_data *data)
 		return;
 	}
 
-	if (keywords[qcache_test_arch] == testing || keywords[qcache_test_arch] == stable) {
+	if (keywords[qcache_test_arch] == testing ||
+			keywords[qcache_test_arch] == stable)
+	{
 		qcache_skip = 1;
 
 		if (possible) {
-			printf("%s%s/%s%s%s\n", BOLD, data->category, BLUE, data->package, NORM);
+			printf("%s%s/%s%s%s\n", BOLD, data->category, BLUE,
+					data->package, NORM);
 		}
 
 		free(keywords);
@@ -889,7 +917,8 @@ qcache_testing_only(qcache_data *data)
 		possible = 1;
 
 	if (data->cur == data->num && possible) {
-		printf("%s%s/%s%s%s\n", BOLD, data->category, BLUE, data->package, NORM);
+		printf("%s%s/%s%s%s\n", BOLD, data->category, BLUE,
+				data->package, NORM);
 	}
 
 	free(keywords);
@@ -972,7 +1001,8 @@ int qcache_main(int argc, char **argv)
 			case 'a':
 			case 'n':
 				if (action)
-					qcache_usage(EXIT_FAILURE); /* trying to use more than 1 action */
+					qcache_usage(EXIT_FAILURE);
+					/* trying to use more than 1 action */
 				action = i;
 				break;
 
@@ -999,7 +1029,3 @@ int qcache_main(int argc, char **argv)
 	qcache_usage(EXIT_FAILURE);
 	return EXIT_FAILURE;
 }
-
-#else
-DEFINE_APPLET_STUB(qcache)
-#endif

diff --git a/qcheck.c b/qcheck.c
index b500dd5..0585396 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -7,9 +7,23 @@
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-#ifdef APPLET_qcheck
+#include "main.h"
+#include "applets.h"
 
+#include <sys/types.h>
 #include <inttypes.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "atom.h"
+#include "contents.h"
+#include "md5_sha1_sum.h"
+#include "prelink.h"
+#include "set.h"
+#include "vdb.h"
+#include "xarray.h"
+#include "xasprintf.h"
+#include "xregex.h"
 
 #define QCHECK_FLAGS "s:uABHTPp" COMMON_FLAGS
 static struct option const qcheck_long_opts[] = {
@@ -437,7 +451,3 @@ int qcheck_main(int argc, char **argv)
 	xarrayfree_int(atoms);
 	return ret;
 }
-
-#else
-DEFINE_APPLET_STUB(qcheck)
-#endif

diff --git a/qdepends.c b/qdepends.c
index e19718c..ca82f08 100644
--- a/qdepends.c
+++ b/qdepends.c
@@ -7,7 +7,19 @@
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-#ifdef APPLET_qdepends
+#include "main.h"
+#include "applets.h"
+
+#include <ctype.h>
+#include <xalloc.h>
+#include <assert.h>
+
+#include "atom.h"
+#include "set.h"
+#include "vdb.h"
+#include "xarray.h"
+#include "xasprintf.h"
+#include "xregex.h"
 
 #define QDEPENDS_FLAGS "drpbafNk:Q:" COMMON_FLAGS
 static struct option const qdepends_long_opts[] = {
@@ -714,7 +726,3 @@ int qdepends_main(int argc, char **argv)
 		warn("no matches found for your query");
 	return ret ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-
-#else
-DEFINE_APPLET_STUB(qdepends)
-#endif

diff --git a/qfile.c b/qfile.c
index 71a3236..19b156e 100644
--- a/qfile.c
+++ b/qfile.c
@@ -1,12 +1,24 @@
 /*
- * Copyright 2005-2018 Gentoo Foundation
+ * Copyright 2005-2019 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
+ * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-#ifdef APPLET_qfile
+#include "main.h"
+#include "applets.h"
+
+#include <xalloc.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "atom.h"
+#include "basename.h"
+#include "contents.h"
+#include "rmspace.h"
+#include "vdb.h"
 
 #define QFILE_FLAGS "boRx:S" COMMON_FLAGS
 static struct option const qfile_long_opts[] = {
@@ -499,7 +511,3 @@ int qfile_main(int argc, char **argv)
 
 	return (found ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-
-#else
-DEFINE_APPLET_STUB(qfile)
-#endif

diff --git a/qgrep.c b/qgrep.c
index f018821..da38f40 100644
--- a/qgrep.c
+++ b/qgrep.c
@@ -8,7 +8,22 @@
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-#ifdef APPLET_qgrep
+#include "main.h"
+#include "applets.h"
+
+#include <stdio.h>
+#include <xalloc.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "atom.h"
+#include "cache.h"
+#include "vdb.h"
+#include "xarray.h"
+#include "xchdir.h"
+#include "xregex.h"
 
 #define QGREP_FLAGS "IiHNclLexJEsS:B:A:" COMMON_FLAGS
 static struct option const qgrep_long_opts[] = {
@@ -314,7 +329,8 @@ int qgrep_main(int argc, char **argv)
 	}
 
 	if (show_name && show_filename) {
-		warn("--with-name and --with-filename are incompatible options. The former wins.");
+		warn("--with-name and --with-filename are incompatible options. "
+				"The former wins.");
 		show_filename = 0;
 	}
 
@@ -341,14 +357,16 @@ int qgrep_main(int argc, char **argv)
 	}
 
 	if (do_installed && do_eclass) {
-		warn("--installed and --eclass are incompatible options. The former wins.");
+		warn("--installed and --eclass are incompatible options. "
+				"The former wins.");
 		do_eclass = 0;
 	}
 
 	/* do we report results once per file or per line ? */
 	per_file_output = do_count || (do_list && (!verbose || invert_list));
 	/* label for prefixing matching lines or listing matching files */
-	label = (show_name ? name : ((verbose || show_filename || do_list) ? ebuild : NULL));
+	label = (show_name ? name :
+			((verbose || show_filename || do_list) ? ebuild : NULL));
 
 	if (argc > (optind + 1)) {
 		include_atoms = xcalloc(sizeof(depend_atom*), (argc - optind - 1));
@@ -392,16 +410,20 @@ int qgrep_main(int argc, char **argv)
 			snprintf(buf, sizeof(buf), "%s/%s", portroot, portvdb);
 			xchdir(buf);
 			if ((vdb_dir = opendir(".")) == NULL)
-				errp("could not opendir(%s/%s) for ROOT/VDB", portroot, portvdb);
+				errp("could not opendir(%s/%s) for ROOT/VDB",
+						portroot, portvdb);
 		}
 
 		/* iteration is either over ebuilds or eclasses */
 		while (do_eclass
 				? ((dentry = readdir(eclass_dir))
-					&& snprintf(ebuild, sizeof(ebuild), "eclass/%s", dentry->d_name))
+					&& snprintf(ebuild, sizeof(ebuild),
+						"eclass/%s", dentry->d_name))
 				: (do_installed
-					? (get_next_installed_ebuild(ebuild, vdb_dir, &dentry, &cat_dir) != NULL)
-					: (fgets(ebuild, sizeof(ebuild), fp) != NULL))) {
+					? (get_next_installed_ebuild(ebuild, vdb_dir,
+							&dentry, &cat_dir) != NULL)
+					: (fgets(ebuild, sizeof(ebuild), fp) != NULL)))
+		{
 			FILE *newfp;
 
 			/* filter badly named files, prepare eclass or package name, etc. */
@@ -451,14 +473,19 @@ int qgrep_main(int argc, char **argv)
 				int lineno = 0;
 				char remaining_after_context = 0;
 				count = 0;
-				/* if there have been some matches already, then a separator will be needed */
-				need_separator = (!status) && (num_lines_before || num_lines_after);
-				/* whatever is in the circular buffers list is no more a valid context */
+				/* if there have been some matches already, then a
+				 * separator will be needed */
+				need_separator =
+					!status && (num_lines_before || num_lines_after);
+				/* whatever is in the circular buffers list is no more a
+				 * valid context */
 				qgrep_buf_list_invalidate(buf_list);
 
-				/* reading a new line always happen in the next buffer of the list */
-				while ((buf_list = buf_list->next)
-						&& (fgets(buf_list->buf, sizeof(buf_list->buf), newfp)) != NULL) {
+				/* reading a new line always happen in the next buffer
+				 * of the list */
+				while ((buf_list = buf_list->next) &&
+						fgets(buf_list->buf, sizeof(buf_list->buf), newfp))
+				{
 					lineno++;
 					buf_list->valid = 1;
 
@@ -477,17 +504,20 @@ int qgrep_main(int argc, char **argv)
 					}
 
 					if (skip_pattern) {
-						/* reject some other lines which match an optional pattern */
+						/* reject some other lines which match an
+						 * optional pattern */
 						if (!do_regex) {
 							if (strfunc(buf_list->buf, skip_pattern) != NULL)
 								goto print_after_context;
 						} else {
-							if (regexec(&skip_preg, buf_list->buf, 0, NULL, 0) == 0)
+							if (regexec(&skip_preg, buf_list->buf,
+										0, NULL, 0) == 0)
 								goto print_after_context;
 						}
 					}
 
-					/* four ways to match a line (with/without inversion and regexp) */
+					/* four ways to match a line (with/without inversion
+					 * and regexp) */
 					if (!invert_match) {
 						if (do_regex == 0) {
 							if (strfunc(buf_list->buf, argv[optind]) == NULL)
@@ -509,7 +539,8 @@ int qgrep_main(int argc, char **argv)
 					count++;
 					status = 0; /* got a match, exit status should be 0 */
 					if (per_file_output)
-						continue; /* matching files are listed out of this loop */
+						continue;
+						/* matching files are listed out of this loop */
 
 					if ((need_separator > 0)
 							&& (num_lines_before || num_lines_after))
@@ -519,7 +550,8 @@ int qgrep_main(int argc, char **argv)
 					need_separator = 0 - num_lines_before;
 					if (!do_list) {
 						/* print the leading context */
-						qgrep_print_before_context(buf_list, num_lines_before, label,
+						qgrep_print_before_context(buf_list,
+								num_lines_before, label,
 								((verbose > 1) ? lineno : -1));
 						/* print matching line */
 						if (invert_match || *RED == '\0')
@@ -530,9 +562,11 @@ int qgrep_main(int argc, char **argv)
 								((verbose > 1) ? lineno : -1), &preg);
 						else
 							qgrep_print_matching_line_strcolor(buf_list, label,
-								((verbose > 1) ? lineno : -1), strfunc, argv[optind]);
+								((verbose > 1) ? lineno : -1), strfunc,
+								argv[optind]);
 					} else {
-						/* in verbose do_list mode, list the file once per match */
+						/* in verbose do_list mode, list the file once
+						 * per match */
 						printf("%s", label);
 						if (verbose > 1)
 							printf(":%d", lineno);
@@ -546,8 +580,9 @@ int qgrep_main(int argc, char **argv)
 					/* print some trailing context lines when needed */
 					if (!remaining_after_context) {
 						if (!status)
-							/* we're getting closer to the need of a separator between
-							 * current match block and the next one */
+							/* we're getting closer to the need of a
+							 * separator between current match block and
+							 * the next one */
 							++need_separator;
 					} else {
 						qgrep_print_context_line(buf_list, label,
@@ -557,7 +592,8 @@ int qgrep_main(int argc, char **argv)
 				}
 				fclose(newfp);
 				if (!per_file_output)
-					continue; /* matches were already displayed, line per line */
+					continue;
+					/* matches were already displayed, line per line */
 				if (do_count && count) {
 					if (label != NULL)
 						/* -c without -v/-N/-H only outputs
@@ -565,7 +601,8 @@ int qgrep_main(int argc, char **argv)
 						printf("%s:", label);
 					printf("%d\n", count);
 				} else if ((count && !invert_list) || (!count && invert_list))
-					printf("%s\n", label); /* do_list == 1, or we wouldn't be here */
+					printf("%s\n", label);
+					/* do_list == 1, or we wouldn't be here */
 			}
 		}
 		if (do_eclass)
@@ -591,7 +628,3 @@ int qgrep_main(int argc, char **argv)
 
 	return status;
 }
-
-#else
-DEFINE_APPLET_STUB(qgrep)
-#endif

diff --git a/qlist.c b/qlist.c
index d98b30e..d46e0a6 100644
--- a/qlist.c
+++ b/qlist.c
@@ -8,7 +8,18 @@
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-#ifdef APPLET_qlist
+#include "main.h"
+#include "applets.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <xalloc.h>
+
+#include "atom.h"
+#include "contents.h"
+#include "vdb.h"
+#include "xregex.h"
 
 #define QLIST_FLAGS "ISRUcDeados" COMMON_FLAGS
 static struct option const qlist_long_opts[] = {
@@ -163,8 +174,19 @@ umapstr(char display, q_vdb_pkg_ctx *pkg_ctx)
 	return _umapstr_buf;
 }
 
-static bool
-qlist_match(q_vdb_pkg_ctx *pkg_ctx, const char *name, depend_atom **name_atom, bool exact)
+/* forward declaration necessary for misuse from qmerge.c, see HACK there */
+bool
+qlist_match(
+		q_vdb_pkg_ctx *pkg_ctx,
+		const char *name,
+		depend_atom **name_atom,
+		bool exact);
+bool
+qlist_match(
+		q_vdb_pkg_ctx *pkg_ctx,
+		const char *name,
+		depend_atom **name_atom,
+		bool exact)
 {
 	const char *catname = pkg_ctx->cat_ctx->name;
 	const char *pkgname = pkg_ctx->name;
@@ -182,7 +204,8 @@ qlist_match(q_vdb_pkg_ctx *pkg_ctx, const char *name, depend_atom **name_atom, b
 			uslot = NULL;
 		else {
 			if (!pkg_ctx->slot)
-				q_vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot, &pkg_ctx->slot_len);
+				q_vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot,
+						&pkg_ctx->slot_len);
 			uslot_len = strlen(uslot);
 		}
 	}
@@ -190,7 +213,8 @@ qlist_match(q_vdb_pkg_ctx *pkg_ctx, const char *name, depend_atom **name_atom, b
 	urepo = strstr(name, "::");
 	if (urepo) {
 		if (!pkg_ctx->repo)
-			q_vdb_pkg_eat(pkg_ctx, "repository", &pkg_ctx->repo, &pkg_ctx->repo_len);
+			q_vdb_pkg_eat(pkg_ctx, "repository", &pkg_ctx->repo,
+					&pkg_ctx->repo_len);
 		urepo += 2;
 		urepo_len = strlen(urepo);
 
@@ -229,8 +253,8 @@ qlist_match(q_vdb_pkg_ctx *pkg_ctx, const char *name, depend_atom **name_atom, b
 	}
 
 	if (uslot) {
-		/* Require exact match on SLOTs.  If the user didn't include a subslot,
-		 * then ignore it when checking the package's value. */
+		/* Require exact match on SLOTs.  If the user didn't include a
+		 * subslot, then ignore it when checking the package's value. */
 		if (strncmp(pkg_ctx->slot, uslot, uslot_len) != 0 ||
 		    (pkg_ctx->slot[uslot_len] != '\0' &&
 		     pkg_ctx->slot[uslot_len] != '/'))
@@ -474,7 +498,3 @@ int qlist_main(int argc, char **argv)
 	/* The return value is whether we matched anything. */
 	return ret ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-
-#else
-DEFINE_APPLET_STUB(qlist)
-#endif

diff --git a/qlop.c b/qlop.c
index d5c2548..b8038b4 100644
--- a/qlop.c
+++ b/qlop.c
@@ -7,7 +7,19 @@
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-#ifdef APPLET_qlop
+#include "main.h"
+#include "applets.h"
+
+#include <string.h>
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "atom.h"
+#include "eat_file.h"
+#include "xarray.h"
+#include "xasprintf.h"
 
 #define QLOP_DEFAULT_LOGFILE "emerge.log"
 
@@ -1009,7 +1021,3 @@ int qlop_main(int argc, char **argv)
 
 	return EXIT_SUCCESS;
 }
-
-#else
-DEFINE_APPLET_STUB(qlop)
-#endif

diff --git a/qmerge.c b/qmerge.c
index 5ebb55e..81da0b1 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -7,13 +7,35 @@
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-#ifdef APPLET_qmerge
+#include "main.h"
+#include "applets.h"
 
+#include <stdio.h>
+#include <xalloc.h>
 #include <fnmatch.h>
+#include <dirent.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <assert.h>
 #include "stat-time.h"
 
+#include "atom.h"
+#include "copy_file.h"
+#include "contents.h"
+#include "eat_file.h"
+#include "human_readable.h"
+#include "md5_sha1_sum.h"
+#include "profile.h"
+#include "rmspace.h"
+#include "scandirat.h"
+#include "set.h"
+#include "vdb.h"
+#include "xasprintf.h"
+#include "xchdir.h"
+#include "xmkdir.h"
+#include "xsystem.h"
+
 #ifndef GLOB_BRACE
 # define GLOB_BRACE     (1 << 10)	/* Expand "{a,b}" to "a" "b".  */
 #endif
@@ -100,6 +122,21 @@ static int pkg_unmerge(q_vdb_pkg_ctx *, set *, int, char **, int, char **);
 static struct pkg_t *grab_binpkg_info(const char *);
 static char *find_binpkg(const char *);
 
+static bool
+prompt(const char *p)
+{
+	printf("%s? [Y/n] ", p);
+	fflush(stdout);
+	switch (getc(stdin)) {
+	case '\n':
+	case 'y':
+	case 'Y':
+		return true;
+	default:
+		return false;
+	}
+}
+
 static int run_applet_l(const char *arg, ...)
 {
 	int (*applet)(int, char **);
@@ -251,6 +288,15 @@ qmerge_filter_cat(q_vdb_cat_ctx *cat_ctx, void *priv)
 	return !state->catname || strcmp(cat_ctx->name, state->catname) == 0;
 }
 
+/* HACK: pull this in, knowing that qlist will be in the final link, we
+ * should however figure out how to do what match does here from e.g.
+ * atom */
+extern bool qlist_match(
+		q_vdb_pkg_ctx *pkg_ctx,
+		const char *name,
+		depend_atom **name_atom,
+		bool exact);
+
 static int
 qmerge_best_version_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 {
@@ -2269,7 +2315,7 @@ qmerge_add_set(char *buf, set *q)
 	if (strcmp(buf, "world") == 0)
 		return qmerge_add_set_file("/var/lib/portage", "world", q);
 	else if (strcmp(buf, "all") == 0)
-		return get_vdb_atoms(0);
+		return get_vdb_atoms(portroot, portvdb, 0);
 	else if (strcmp(buf, "system") == 0)
 		return q_profile_walk("packages", qmerge_add_set_system, q);
 	else if (buf[0] == '@')
@@ -2362,7 +2408,3 @@ int qmerge_main(int argc, char **argv)
 	free_set(todo);
 	return ret;
 }
-
-#else
-DEFINE_APPLET_STUB(qmerge)
-#endif

diff --git a/qpkg.c b/qpkg.c
index 4de856a..3ff4507 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -7,9 +7,30 @@
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-#ifdef APPLET_qpkg
+#include "main.h"
+#include "applets.h"
 
+#include <stdio.h>
+#include <string.h>
 #include <fnmatch.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "atom.h"
+#include "basename.h"
+#include "cache.h"
+#include "contents.h"
+#include "human_readable.h"
+#include "md5_sha1_sum.h"
+#include "scandirat.h"
+#include "set.h"
+#include "vdb.h"
+#include "xarray.h"
+#include "xasprintf.h"
+#include "xchdir.h"
+#include "xpak.h"
 
 #define QPKG_FLAGS "cEpP:" COMMON_FLAGS
 static struct option const qpkg_long_opts[] = {
@@ -33,6 +54,11 @@ extern char pretend;
 static char *qpkg_bindir = NULL;
 static int eclean = 0;
 
+static char *
+atom_to_pvr(depend_atom *atom) {
+	return (atom->PR_int == 0 ? atom->P : atom->PVR );
+}
+
 /* checks to make sure this is a .tbz2 file. used by scandir() */
 static int
 filter_tbz2(const struct dirent *dentry)
@@ -114,7 +140,7 @@ qpkg_clean(char *dirp)
 	if ((count = scandir(".", &dnames, filter_hidden, alphasort)) < 0)
 		return 1;
 
-	vdb = get_vdb_atoms(1);
+	vdb = get_vdb_atoms(portroot, portvdb, 1);
 
 	if (eclean) {
 		size_t n;
@@ -222,7 +248,6 @@ qpkg_make(depend_atom *atom)
 	FILE *fp, *out;
 	char tmpdir[BUFSIZE];
 	char filelist[BUFSIZE + 32];
-	char xpak[BUFSIZE + 32];
 	char tbz2[BUFSIZE + 32];
 	size_t buflen;
 	char *buf;
@@ -231,7 +256,8 @@ qpkg_make(depend_atom *atom)
 	struct stat st;
 
 	if (pretend) {
-		printf(" %s-%s %s/%s:\n", GREEN, NORM, atom->CATEGORY, atom_to_pvr(atom));
+		printf(" %s-%s %s/%s:\n",
+				GREEN, NORM, atom->CATEGORY, atom_to_pvr(atom));
 		return 0;
 	}
 
@@ -240,20 +266,28 @@ qpkg_make(depend_atom *atom)
 
 	snprintf(buf, buflen, "%s/%s/%s/CONTENTS",
 			portvdb, atom->CATEGORY, atom_to_pvr(atom));
-	if ((fp = fopen(buf, "r")) == NULL)
+	if ((fp = fopen(buf, "r")) == NULL) {
+		free(buf);
 		return -1;
+	}
 
 	snprintf(tmpdir, sizeof(tmpdir), "%s/qpkg.XXXXXX", qpkg_get_bindir());
-	if ((i = mkstemp(tmpdir)) == -1)
+	if ((i = mkstemp(tmpdir)) == -1) {
+		free(buf);
 		return -2;
+	}
 	close(i);
 	unlink(tmpdir);
-	if (mkdir(tmpdir, 0750))
+	if (mkdir(tmpdir, 0750)) {
+		free(buf);
 		return -3;
+	}
 
 	snprintf(filelist, sizeof(filelist), "%s/filelist", tmpdir);
-	if ((out = fopen(filelist, "w")) == NULL)
+	if ((out = fopen(filelist, "w")) == NULL) {
+		free(buf);
 		return -4;
+	}
 
 	while (getline(&buf, &buflen, fp) != -1) {
 		contents_entry *e;
@@ -280,41 +314,38 @@ qpkg_make(depend_atom *atom)
 	printf(" %s-%s %s/%s: ", GREEN, NORM, atom->CATEGORY, atom_to_pvr(atom));
 	fflush(stdout);
 
-	snprintf(tbz2, sizeof(tbz2), "%s/bin.tar.bz2", tmpdir);
+	snprintf(tbz2, sizeof(tbz2), "%s/bin.tbz2", tmpdir);
 	if (snprintf(buf, buflen, "tar jcf '%s' --files-from='%s' "
-			"--no-recursion >/dev/null 2>&1", tbz2, filelist) > (int)buflen)
-		return 2;
-	if ((fp = popen(buf, "r")) == NULL)
+			"--no-recursion >/dev/null 2>&1", tbz2, filelist) > (int)buflen ||
+			(fp = popen(buf, "r")) == NULL)
+	{
+		free(buf);
 		return 2;
+	}
 	pclose(fp);
 
-	snprintf(xpak, sizeof(xpak), "%s/inf.xpak", tmpdir);
 	snprintf(buf, buflen, "%s/%s/%s",
 			portvdb, atom->CATEGORY, atom_to_pvr(atom));
 	xpak_argv[0] = buf;
 	xpak_argv[1] = NULL;
-	xpak_create(AT_FDCWD, xpak, 1, xpak_argv);
-
-	snprintf(buf, buflen, "%s/binpkg.tbz2", tmpdir);
-	tbz2_compose(AT_FDCWD, tbz2, xpak, buf);
+	xpak_create(AT_FDCWD, tbz2, 1, xpak_argv, 1, verbose);
 
 	unlink(filelist);
-	unlink(xpak);
-	unlink(tbz2);
 
-	snprintf(tbz2, sizeof(tbz2), "%s/%s.tbz2",
-			qpkg_get_bindir(), atom_to_pvr(atom));
-	if (rename(buf, tbz2)) {
-		warnp("could not move '%s' to '%s'", buf, tbz2);
+	snprintf(buf, buflen, "%s/%s.tbz2", qpkg_get_bindir(), atom_to_pvr(atom));
+	if (rename(tbz2, buf)) {
+		warnp("could not move '%s' to '%s'", tbz2, buf);
+		free(buf);
 		return 1;
 	}
 
 	rmdir(tmpdir);
 
-	stat(tbz2, &st);
+	stat(buf, &st);
 	printf("%s%s%s kB\n",
 			RED, make_human_readable_str(st.st_size, 1, KILOBYTE), NORM);
 
+	free(buf);
 	return 0;
 }
 
@@ -425,8 +456,12 @@ retry_mkdir:
 			for (i = optind; i < argc; ++i) {
 				if (!argv[i]) continue;
 
-				if (!strcmp(argv[i], atom->PN) || !strcmp(argv[i], atom->P) || !strcmp(argv[i], buf) || !strcmp(argv[i], "world"))
-					if (!qpkg_make(atom)) ++pkgs_made;
+				if (!strcmp(argv[i], atom->PN) ||
+						!strcmp(argv[i], atom->P) ||
+						!strcmp(argv[i], buf) ||
+						!strcmp(argv[i], "world"))
+					if (!qpkg_make(atom))
+						++pkgs_made;
 			}
 			atom_implode(atom);
 
@@ -437,13 +472,10 @@ retry_mkdir:
 
 	s = (argc - optind) - pkgs_made;
 	if (s && !pretend)
-		printf(" %s*%s %i package%s could not be matched :/\n", RED, NORM, (int)s, (s > 1 ? "s" : ""));
+		printf(" %s*%s %i package%s could not be matched :/\n",
+				RED, NORM, (int)s, (s > 1 ? "s" : ""));
 	if (pkgs_made)
 		qprintf(" %s*%s Packages can be found in %s\n", GREEN, NORM, bindir);
 
 	return (pkgs_made ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-
-#else
-DEFINE_APPLET_STUB(qpkg)
-#endif

diff --git a/qsearch.c b/qsearch.c
index b75a4f7..5ae68bc 100644
--- a/qsearch.c
+++ b/qsearch.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2018 Gentoo Authors
+ * Copyright 2005-2019 Gentoo Authors
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -7,7 +7,22 @@
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org
  */
 
-#ifdef APPLET_qsearch
+#include "main.h"
+#include "applets.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <xalloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "atom.h"
+#include "basename.h"
+#include "cache.h"
+#include "rmspace.h"
+#include "xarray.h"
+#include "xregex.h"
 
 #define QSEARCH_FLAGS "acesSNH" COMMON_FLAGS
 static struct option const qsearch_long_opts[] = {
@@ -36,21 +51,32 @@ static const char * const qsearch_opts_help[] = {
 
 /* Search an ebuild's details via the metadata cache. */
 static void
-qsearch_ebuild_metadata(_q_unused_ int overlay_fd, const char *ebuild, const char *search_me, char *last,
-                        bool search_desc, bool search_all, _q_unused_ bool search_name, bool show_name_only, bool show_homepage)
+qsearch_ebuild_metadata(
+		int overlay_fd,
+		const char *ebuild,
+		const char *search_me,
+		char *last,
+		bool search_desc,
+		bool search_all,
+		bool search_name,
+		bool show_name_only,
+		bool show_homepage)
 {
-	portage_cache *pcache = cache_read_file(ebuild);
+	(void)overlay_fd;
+	(void)search_name;
+
+	portage_cache *pcache = cache_read_file(portcachedir_type, ebuild);
 
 	if (pcache == NULL) {
-		if (!reinitialize)
-			warnf("(cache update pending) %s", ebuild);
-		reinitialize = 1;
+		warnf("missing cache, please (re)generate");
 		return;
 	}
 
 	if (strcmp(pcache->atom->PN, last) != 0) {
 		strncpy(last, pcache->atom->PN, LAST_BUF_SIZE);
-		if (search_all || rematch(search_me, (search_desc ? pcache->DESCRIPTION : ebuild), REG_EXTENDED | REG_ICASE) == 0)
+		if (search_all || rematch(search_me,
+					(search_desc ? pcache->DESCRIPTION : ebuild),
+					REG_EXTENDED | REG_ICASE) == 0)
 			printf("%s%s/%s%s%s%s%s\n", BOLD, pcache->atom->CATEGORY, BLUE,
 			       pcache->atom->PN, NORM,
 				   (show_name_only ? "" : " "),
@@ -62,22 +88,37 @@ qsearch_ebuild_metadata(_q_unused_ int overlay_fd, const char *ebuild, const cha
 
 /* Search an ebuild's details via the ebuild cache. */
 static void
-qsearch_ebuild_ebuild(int overlay_fd, const char *ebuild, const char *search_me, char *last,
-                      _q_unused_ bool search_desc, bool search_all, bool search_name, bool show_name_only, _q_unused_ bool show_homepage)
+qsearch_ebuild_ebuild(
+		int overlay_fd,
+		const char *ebuild,
+		const char *search_me,
+		char *last,
+		bool search_desc,
+		bool search_all,
+		bool search_name,
+		bool show_name_only,
+		bool show_homepage)
 {
 	const char * const search_vars[] = { "DESCRIPTION=", "HOMEPAGE=" };
 	const char *search_var = search_vars[show_homepage ? 1 : 0];
 	size_t search_len = strlen(search_var);
 	char *p, *q, *str;
-
+	char *buf = NULL;
+	int linelen;
+	size_t buflen;
+	bool show_it = false;
 	FILE *ebuildfp;
+	int fd;
+
 	str = xstrdup(ebuild);
 	p = dirname(str);
 
+	(void)search_desc;
+	(void)show_homepage;
+
 	if (strcmp(p, last) == 0)
 		goto no_cache_ebuild_match;
 
-	bool show_it = false;
 	strncpy(last, p, LAST_BUF_SIZE);
 	if (search_name) {
 		if (rematch(search_me, basename(last), REG_EXTENDED | REG_ICASE) != 0) {
@@ -88,7 +129,7 @@ qsearch_ebuild_ebuild(int overlay_fd, const char *ebuild, const char *search_me,
 		}
 	}
 
-	int fd = openat(overlay_fd, ebuild, O_RDONLY|O_CLOEXEC);
+	fd = openat(overlay_fd, ebuild, O_RDONLY|O_CLOEXEC);
 	if (fd != -1) {
 		ebuildfp = fdopen(fd, "r");
 		if (ebuildfp == NULL) {
@@ -96,15 +137,10 @@ qsearch_ebuild_ebuild(int overlay_fd, const char *ebuild, const char *search_me,
 			goto no_cache_ebuild_match;
 		}
 	} else {
-		if (!reinitialize)
-			warnfp("(cache update pending) %s", ebuild);
-		reinitialize = 1;
+		warnf("missing cache, please (re)generate");
 		goto no_cache_ebuild_match;
 	}
 
-	char *buf = NULL;
-	int linelen;
-	size_t buflen;
 	while ((linelen = getline(&buf, &buflen, ebuildfp)) >= 0) {
 		if ((size_t)linelen <= search_len)
 			continue;
@@ -115,7 +151,8 @@ qsearch_ebuild_ebuild(int overlay_fd, const char *ebuild, const char *search_me,
 		if (strlen(buf) <= search_len)
 			break;
 		q = buf + search_len + 1;
-		if (!search_all && !search_name && rematch(search_me, q, REG_EXTENDED | REG_ICASE) != 0)
+		if (!search_all && !search_name &&
+				rematch(search_me, q, REG_EXTENDED | REG_ICASE) != 0)
 			break;
 		show_it = true;
 		break;
@@ -216,7 +253,3 @@ int qsearch_main(int argc, char **argv)
 
 	return ret;
 }
-
-#else
-DEFINE_APPLET_STUB(qsearch)
-#endif

diff --git a/qsize.c b/qsize.c
index 3566429..80d496c 100644
--- a/qsize.c
+++ b/qsize.c
@@ -1,12 +1,14 @@
 /*
- * Copyright 2005-2018 Gentoo Foundation
+ * Copyright 2005-2019 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
+ * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-#ifdef APPLET_qsize
+#include "main.h"
+#include "applets.h"
 
 /* Solaris */
 #if defined(__sun) && defined(__SVR4)
@@ -41,6 +43,18 @@
 # define S_BLKSIZE 512
 #endif
 
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "atom.h"
+#include "contents.h"
+#include "human_readable.h"
+#include "vdb.h"
+#include "xarray.h"
+#include "xregex.h"
+
 #define QSIZE_FLAGS "fsSmkbi:" COMMON_FLAGS
 static struct option const qsize_long_opts[] = {
 	{"filesystem", no_argument, NULL, 'f'},
@@ -136,8 +150,10 @@ qsize_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
 		if (e->type == CONTENTS_OBJ || e->type == CONTENTS_SYM) {
 			struct stat st;
 			++num_files;
-			if (!fstatat(pkg_ctx->cat_ctx->ctx->portroot_fd, e->name + 1, &st, AT_SYMLINK_NOFOLLOW))
-				num_bytes += (state->fs_size ? st.st_blocks * S_BLKSIZE : st.st_size);
+			if (!fstatat(pkg_ctx->cat_ctx->ctx->portroot_fd,
+						e->name + 1, &st, AT_SYMLINK_NOFOLLOW))
+				num_bytes +=
+					state->fs_size ? st.st_blocks * S_BLKSIZE : st.st_size;
 		} else
 			++num_nonfiles;
 	}
@@ -235,7 +251,3 @@ int qsize_main(int argc, char **argv)
 
 	return ret;
 }
-
-#else
-DEFINE_APPLET_STUB(qsize)
-#endif

diff --git a/qtbz2.c b/qtbz2.c
index ee8e161..314eecd 100644
--- a/qtbz2.c
+++ b/qtbz2.c
@@ -1,12 +1,25 @@
 /*
- * Copyright 2005-2018 Gentoo Foundation
+ * Copyright 2005-2019 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
  */
 
-#ifdef APPLET_qtbz2
+#include "main.h"
+#include "applets.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include "basename.h"
+#include "copy_file.h"
+#include "human_readable.h"
+#include "safe_io.h"
 
 /*
 # The format for a tbz2/xpak:
@@ -49,40 +62,6 @@ static const char * const qtbz2_opts_help[] = {
 
 static char tbz2_stdout = 0;
 
-static unsigned char *
-tbz2_encode_int(int enc)
-{
-	static unsigned char ret[4];
-	ret[0] = (enc & 0xff000000) >> 24;
-	ret[1] = (enc & 0x00ff0000) >> 16;
-	ret[2] = (enc & 0x0000ff00) >> 8;
-	ret[3] = (enc & 0x000000ff);
-	return ret;
-}
-static int
-tbz2_decode_int(unsigned char *buf)
-{
-	int ret;
-	ret = 0;
-	ret += (buf[0] << 24);
-	ret += (buf[1] << 16);
-	ret += (buf[2] << 8);
-	ret += (buf[3]);
-	return ret;
-}
-
-static void
-_tbz2_copy_file(FILE *src, FILE *dst)
-{
-	int count = 1;
-	unsigned char buffer[BUFSIZE*32];
-	while (count) {
-		count = fread(buffer, 1, sizeof(buffer), src);
-		if (!count) return;
-		fwrite(buffer, 1, count, dst);
-	}
-}
-
 static int
 tbz2_compose(int dir_fd, const char *tarbz2, const char *xpak, const char *tbz2)
 {
@@ -136,14 +115,15 @@ tbz2_compose(int dir_fd, const char *tarbz2, const char *xpak, const char *tbz2)
 	}
 
 	/* save [tarball] */
-	_tbz2_copy_file(in_tarbz2, out);
+	copy_file(in_tarbz2, out);
 	fclose(in_tarbz2);
 	/* save [xpak] */
-	_tbz2_copy_file(in_xpak, out);
+	copy_file(in_xpak, out);
 	fclose(in_xpak);
 
 	/* save tbz2 tail: OOOOSTOP */
-	fwrite(tbz2_encode_int(st.st_size), 1, 4, out);
+	WRITE_BE_INT32(buf, st.st_size);
+	fwrite(buf, 1, 4, out);
 	fwrite(TBZ2_END_MSG, 1, TBZ2_END_MSG_LEN, out);
 
 	fclose(out);
@@ -202,7 +182,8 @@ tbz2_decompose(int dir_fd, const char *tbz2, const char *tarbz2, const char *xpa
 		goto close_in_and_ret;
 
 	if (verbose)
-		printf("input tbz2: %s (%s)\n", tbz2, make_human_readable_str(st.st_size, 1, 0));
+		printf("input tbz2: %s (%s)\n", tbz2,
+				make_human_readable_str(st.st_size, 1, 0));
 
 	/* verify the tail signature */
 	if (fseek(in, -TBZ2_END_LEN, SEEK_END) != 0)
@@ -215,7 +196,7 @@ tbz2_decompose(int dir_fd, const char *tbz2, const char *tarbz2, const char *xpa
 	}
 
 	/* calculate xpak's size */
-	xpak_size = tbz2_decode_int(tbz2_tail);
+	xpak_size = READ_BE_INT32(tbz2_tail);
 	/* calculate tarbz2's size */
 	tarbz2_size = st.st_size - xpak_size - TBZ2_END_LEN;
 
@@ -223,11 +204,13 @@ tbz2_decompose(int dir_fd, const char *tbz2, const char *tarbz2, const char *xpa
 	rewind(in);
 	/* dump the tar.bz2 */
 	if (verbose)
-		printf("output tar.bz2: %s (%s)\n", tarbz2, make_human_readable_str(tarbz2_size, 1, 0));
+		printf("output tar.bz2: %s (%s)\n", tarbz2,
+				make_human_readable_str(tarbz2_size, 1, 0));
 	_tbz2_write_file(in, dir_fd, tarbz2, tarbz2_size);
 	/* dump the xpak */
 	if (verbose)
-		printf("output xpak: %s (%s)\n", xpak, make_human_readable_str(xpak_size, 1, 0));
+		printf("output xpak: %s (%s)\n", xpak,
+				make_human_readable_str(xpak_size, 1, 0));
 	_tbz2_write_file(in, dir_fd, xpak, xpak_size);
 
 	ret = 0;
@@ -266,9 +249,12 @@ int qtbz2_main(int argc, char **argv)
 	}
 	if (optind == argc) {
 		switch (action) {
-		case TBZ2_ACT_JOIN:  err("Join usage: <input tar.bz2> <input xpak> [<output tbz2>]");
-		case TBZ2_ACT_SPLIT: err("Split usage: <input tbz2> [<output tar.bz2> <output xpak>]");
-		default:             qtbz2_usage(EXIT_FAILURE);
+		case TBZ2_ACT_JOIN:
+			err("Join usage: <input tar.bz2> <input xpak> [<output tbz2>]");
+		case TBZ2_ACT_SPLIT:
+			err("Split usage: <input tbz2> [<output tar.bz2> <output xpak>]");
+		default:
+			qtbz2_usage(EXIT_FAILURE);
 		}
 	}
 
@@ -281,8 +267,8 @@ int qtbz2_main(int argc, char **argv)
 		else if (strstr(argv[optind], ".tbz2") != NULL)
 			action = TBZ2_ACT_SPLIT;
 		else
-			err("%s: need to use -j or -s, or file must end in .tar.bz2 or .tbz2 to autodetect",
-				argv[optind]);
+			err("%s: need to use -j or -s, or file must end "
+					"in .tar.bz2 or .tbz2 to autodetect", argv[optind]);
 	}
 
 	/* tbz2tool join .tar.bz2 .xpak .tbz2 */
@@ -357,8 +343,7 @@ int qtbz2_main(int argc, char **argv)
 	}
 
 	/* We have to cleanup all resources as we're used indirectly
-	 * (e.g. via qmerge).
-	 */
+	 * (e.g. via qmerge). */
 	free(heap_tbz2);
 	free(heap_xpak);
 	free(heap_tarbz2);
@@ -367,7 +352,3 @@ int qtbz2_main(int argc, char **argv)
 
 	return EXIT_SUCCESS;
 }
-
-#else
-DEFINE_APPLET_STUB(qtbz2)
-#endif

diff --git a/qtegrity.c b/qtegrity.c
index 7436aa2..2e3b859 100644
--- a/qtegrity.c
+++ b/qtegrity.c
@@ -7,10 +7,13 @@
  * Copyright 2017-2018 Sam Besselink
  */
 
-#ifdef APPLET_qtegrity
+#include "main.h"
+#include "applets.h"
 
+#include <string.h>
 #include <sys/types.h>
 #include <signal.h>
+#include <fcntl.h>
 
 #define QTEGRITY_FLAGS "a:is" COMMON_FLAGS
 static struct option const qtegrity_long_opts[] = {
@@ -56,6 +59,9 @@ struct qtegrity_opt_state {
 
 static void external_check_sha(char * ret_digest, char * filepath, char * algo) {
 	size_t size_digest = 1;
+	char cmd[11];
+	int pipefd[2];
+	pid_t pid;
 
 	if (strcmp(algo, "sha256") == 0) {
 		size_digest = 64;
@@ -67,12 +73,8 @@ static void external_check_sha(char * ret_digest, char * filepath, char * algo)
 		return;
 	}
 
-	char cmd[11];
 	snprintf(cmd, 10, "%ssum", algo);
 
-	int pipefd[2];
-	pid_t pid;
-
 	if (pipe(pipefd) == -1) {
 		perror("Couldn't create pipe to shasum\n");
 		exit(1);
@@ -504,7 +506,3 @@ int qtegrity_main(int argc, char **argv)
 
 	return EXIT_SUCCESS;
 }
-
-#else
-DEFINE_APPLET_STUB(qtegrity)
-#endif

diff --git a/quse.c b/quse.c
index 1fd4f3a..62ae166 100644
--- a/quse.c
+++ b/quse.c
@@ -7,7 +7,22 @@
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
-#ifdef APPLET_quse
+#include "main.h"
+#include "applets.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <xalloc.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <assert.h>
+
+#include "cache.h"
+#include "rmspace.h"
+#include "xarray.h"
+#include "xregex.h"
 
 /*
  quse -CKe -- '-*' {'~',-,}{alpha,amd64,hppa,ia64,ppc,ppc64,sparc,x86}
@@ -88,7 +103,11 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
 	char *buf, *p;
 	unsigned int i, f;
 	size_t s;
-	const char * const search_files[] = { "use.desc", "use.local.desc", "arch.list", };
+	const char * const search_files[] = {
+		"use.desc",
+		"use.local.desc",
+		"arch.list"
+	};
 	FILE *fp[NUM_SEARCH_FILES];
 	int dfd, fd;
 	DIR *d;
@@ -218,7 +237,8 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
 
 			for (i = ind; i < argc; i++)
 				if (!strcmp(argv[i], buf))
-					printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
+					printf(" %s%s%s:%s%s%s: %s\n",
+							BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
 		}
 		fclose(fp[0]);
 	}
@@ -243,7 +263,12 @@ int quse_main(int argc, char **argv)
 	char *ebuild;
 
 	const char *search_var = NULL;
-	const char *search_vars[] = { "IUSE=", "KEYWORDS=", "LICENSE=", search_var };
+	const char *search_vars[] = {
+		"IUSE=",
+		"KEYWORDS=",
+		"LICENSE=",
+		search_var
+	};
 	short quse_all = 0;
 	int regexp_matching = 1, i, idx = 0;
 	size_t search_len;
@@ -277,6 +302,8 @@ int quse_main(int argc, char **argv)
 	assert(search_len < sizeof(buf0));
 
 	array_for_each(overlays, n, overlay) {
+		int overlay_fd;
+
 		cache_file = initialize_flat(overlay, CACHE_EBUILD, false);
 
 		if ((fp = fopen(cache_file, "re")) == NULL) {
@@ -284,7 +311,7 @@ int quse_main(int argc, char **argv)
 			continue;
 		}
 
-		int overlay_fd = open(overlay, O_RDONLY|O_CLOEXEC|O_PATH);
+		overlay_fd = open(overlay, O_RDONLY|O_CLOEXEC|O_PATH);
 
 		ebuild = NULL;
 		while ((linelen = getline(&ebuild, &ebuildlen, fp)) >= 0) {
@@ -299,24 +326,12 @@ int quse_main(int argc, char **argv)
 			newfp = fdopen(fd, "r");
 			if (newfp != NULL) {
 				unsigned int lineno = 0;
-				char revision[sizeof(buf0)];
-				char date[sizeof(buf0)];
-				char user[sizeof(buf0)];
 
-				revision[0] = 0;
-				user[0] = 0;
-				date[0] = 0;
 				while (fgets(buf0, sizeof(buf0), newfp) != NULL) {
 					int ok = 0;
 					char warned = 0;
 					lineno++;
 
-					if (*buf0 == '#') {
-						if (strncmp(buf0, "# $Header: /", 12) == 0)
-							sscanf(buf0, "%*s %*s %*s %s %s %*s %s %*s %*s",
-								revision, date, user);
-						continue;
-					}
 					if (strncmp(buf0, search_vars[idx], search_len) != 0)
 						continue;
 
@@ -417,14 +432,9 @@ int quse_main(int argc, char **argv)
 						}
 					}
 					if (ok) {
-						if (verbose > 3)
-							printf("%s %s %s ",
-								*user ? user : "MISSING",
-								*revision ? revision : "MISSING",
-								*date ? date : "MISSING");
-
 						printf("%s%s%s ", CYAN, ebuild, NORM);
-						print_highlighted_use_flags(&buf0[search_len + 1], optind, argc, argv);
+						print_highlighted_use_flags(&buf0[search_len + 1],
+								optind, argc, argv);
 						puts(NORM);
 						if (verbose > 1) {
 							char **ARGV;
@@ -438,9 +448,7 @@ int quse_main(int argc, char **argv)
 				}
 				fclose(newfp);
 			} else {
-				if (!reinitialize)
-					warnfp("(cache update pending) %s", ebuild);
-				reinitialize = 1;
+				warnf("missing cache, please (re)generate");
 			}
 		}
 		fclose(fp);
@@ -449,7 +457,3 @@ int quse_main(int argc, char **argv)
 
 	return EXIT_SUCCESS;
 }
-
-#else
-DEFINE_APPLET_STUB(quse)
-#endif

diff --git a/qxpak.c b/qxpak.c
index bdd5294..eb19cae 100644
--- a/qxpak.c
+++ b/qxpak.c
@@ -1,32 +1,25 @@
 /*
- * Copyright 2005-2018 Gentoo Foundation
+ * Copyright 2005-2019 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
  */
 
-#ifdef APPLET_qxpak
+#include "main.h"
+#include "applets.h"
 
-/*
-# The format for a tbz2/xpak:
-#
-#  tbz2: tar.bz2 + xpak + (xpak_offset) + "STOP"
-#  xpak: "XPAKPACK" + (index_len) + (data_len) + index + data + "XPAKSTOP"
-# index: (pathname_len) + pathname + (data_offset) + (data_len)
-#        index entries are concatenated end-to-end.
-#  data: concatenated data chunks, end-to-end.
-#
-# [tarball]XPAKPACKIIIIDDDD[index][data]XPAKSTOPOOOOSTOP
-#
-# (integer) == encodeint(integer)  ===> 4 characters (big-endian copy)
-# '+' means concatenate the fields ===> All chunks are strings
-*/
-#define XPAK_START_MSG       "XPAKPACK"
-#define XPAK_START_MSG_LEN   8
-#define XPAK_START_LEN       (8 + 4 + 4)
-#define XPAK_END_MSG         "XPAKSTOP"
-#define XPAK_END_MSG_LEN     8
+#include <string.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "basename.h"
+#include "copy_file.h"
+#include "safe_io.h"
+#include "scandirat.h"
+#include "xpak.h"
 
 #define QXPAK_FLAGS "lxcd:O" COMMON_FLAGS
 static struct option const qxpak_long_opts[] = {
@@ -47,100 +40,21 @@ static const char * const qxpak_opts_help[] = {
 };
 #define qxpak_usage(ret) usage(ret, QXPAK_FLAGS, qxpak_long_opts, qxpak_opts_help, NULL, lookup_applet_idx("qxpak"))
 
-typedef struct {
-	int dir_fd;
-	FILE *fp;
-	int index_len;
-	int data_len;
-	char *index, *data;
-} _xpak_archive;
-
 static char xpak_stdout;
 
-typedef void (*xpak_callback_t)(int,char*,int,int,int,char*);
-
-static void _xpak_walk_index(_xpak_archive *x, int argc, char **argv, xpak_callback_t func)
-{
-	int i, pathname_len, data_offset, data_len;
-	char *p, pathname[100];
-
-	p = x->index;
-	while ((p - x->index) < x->index_len) {
-		pathname_len = tbz2_decode_int((unsigned char*)p);
-		assert((size_t)pathname_len < sizeof(pathname));
-		p += 4;
-		memcpy(pathname, p, pathname_len);
-		pathname[pathname_len] = '\0';
-		if (strchr(pathname, '/') != NULL || strchr(pathname, '\\') != NULL)
-			err("Index contains a file with a path: '%s'", pathname);
-		p += pathname_len;
-		data_offset = tbz2_decode_int((unsigned char*)p);
-		p += 4;
-		data_len = tbz2_decode_int((unsigned char*)p);
-		p += 4;
-		if (argc) {
-			for (i = 0; i < argc; ++i)
-				if (argv[i] && !strcmp(pathname, argv[i])) {
-					argv[i] = NULL;
-					break;
-				}
-			if (i == argc)
-				continue;
-		}
-		(*func)(x->dir_fd, pathname, pathname_len, data_offset, data_len, x->data);
-	}
-
-	if (argc)
-		for (i = 0; i < argc; ++i)
-			if (argv[i])
-				warn("Could not locate '%s' in archive", argv[i]);
-}
-
-static _xpak_archive *_xpak_open(const char *file)
-{
-	static _xpak_archive ret;
-	char buf[XPAK_START_LEN];
-
-	/* init the file */
-	memset(&ret, 0x00, sizeof(ret));
-	if (file[0] == '-' && file[1] == '\0')
-		ret.fp = stdin;
-	else if ((ret.fp = fopen(file, "r")) == NULL)
-		return NULL;
-
-	/* verify this xpak doesnt suck */
-	if (fread(buf, 1, XPAK_START_LEN, ret.fp) != XPAK_START_LEN)
-		goto close_and_ret;
-	if (memcmp(buf, XPAK_START_MSG, XPAK_START_MSG_LEN)) {
-		warn("%s: Invalid xpak", file);
-		goto close_and_ret;
-	}
-
-	/* calc index and data sizes */
-	ret.index_len = tbz2_decode_int((unsigned char*)buf+XPAK_START_MSG_LEN);
-	ret.data_len = tbz2_decode_int((unsigned char*)buf+XPAK_START_MSG_LEN+4);
-	if (!ret.index_len || !ret.data_len) {
-		warn("Skipping empty archive '%s'", file);
-		goto close_and_ret;
-	}
-
-	return &ret;
-
-close_and_ret:
-	if (ret.fp != stdin)
-		fclose(ret.fp);
-	return NULL;
-}
-
-static void _xpak_close(_xpak_archive *x)
-{
-	fclose(x->fp);
-}
-
 static void
-_xpak_list_callback(_q_unused_ int dir_fd, char *pathname, _q_unused_ int pathname_len,
-                    int data_offset, int data_len, _q_unused_ char *data)
+_xpak_list_callback(
+		int dir_fd,
+		char *pathname,
+		int pathname_len,
+		int data_offset,
+		int data_len,
+		char *data)
 {
+	(void)dir_fd;
+	(void)pathname_len;
+	(void)data;
+
 	if (!verbose)
 		puts(pathname);
 	else if (verbose == 1)
@@ -149,34 +63,18 @@ _xpak_list_callback(_q_unused_ int dir_fd, char *pathname, _q_unused_ int pathna
 		printf("%s: %i byte%c @ offset byte %i\n",
 			pathname, data_len, (data_len>1?'s':' '), data_offset);
 }
-static int
-xpak_list(int dir_fd, const char *file, int argc, char **argv)
-{
-	_xpak_archive *x;
-	char buf[BUFSIZE];
-	size_t ret;
-
-	x = _xpak_open(file);
-	if (!x)
-		return 1;
-
-	x->dir_fd = dir_fd;
-	x->index = buf;
-	assert((size_t)x->index_len < sizeof(buf));
-	ret = fread(x->index, 1, x->index_len, x->fp);
-	assert(ret == (size_t)x->index_len);
-	_xpak_walk_index(x, argc, argv, &_xpak_list_callback);
-
-	_xpak_close(x);
-
-	return 0;
-}
 
 static void
-_xpak_extract_callback(int dir_fd, char *pathname, _q_unused_ int pathname_len,
-                       int data_offset, int data_len, char *data)
+_xpak_extract_callback(
+	int dir_fd,
+	char *pathname,
+	int pathname_len,
+	int data_offset,
+	int data_len,
+	char *data)
 {
 	FILE *out;
+	(void)pathname_len;
 
 	if (verbose == 1)
 		puts(pathname);
@@ -184,7 +82,8 @@ _xpak_extract_callback(int dir_fd, char *pathname, _q_unused_ int pathname_len,
 		printf("%s: %i byte%c\n", pathname, data_len, (data_len>1?'s':' '));
 
 	if (!xpak_stdout) {
-		int fd = openat(dir_fd, pathname, O_WRONLY|O_CLOEXEC|O_CREAT|O_TRUNC, 0644);
+		int fd = openat(dir_fd, pathname,
+				O_WRONLY|O_CLOEXEC|O_CREAT|O_TRUNC, 0644);
 		if (fd < 0)
 			return;
 		out = fdopen(fd, "w");
@@ -198,190 +97,6 @@ _xpak_extract_callback(int dir_fd, char *pathname, _q_unused_ int pathname_len,
 	if (!xpak_stdout)
 		fclose(out);
 }
-static int
-xpak_extract(int dir_fd, const char *file, int argc, char **argv)
-{
-	_xpak_archive *x;
-	char buf[BUFSIZE], ext[BUFSIZE*32];
-	size_t in;
-
-	x = _xpak_open(file);
-	if (!x)
-		return 1;
-
-	x->dir_fd = dir_fd;
-	x->index = buf;
-
-	assert((size_t)x->index_len < sizeof(buf));
-	in = fread(x->index, 1, x->index_len, x->fp);
-	if ((int)in != x->index_len)
-		err("index chunk: read %i bytes, wanted %i bytes", (int)in, x->index_len);
-
-	/* the xpak may be large (like when it has CONTENTS) #300744 */
-	x->data = (size_t)x->data_len < sizeof(ext) ? ext : xmalloc(x->data_len);
-	in = fread(x->data, 1, x->data_len, x->fp);
-	if ((int)in != x->data_len)
-		err("data chunk: read %i bytes, wanted %i bytes", (int)in, x->data_len);
-
-	_xpak_walk_index(x, argc, argv, &_xpak_extract_callback);
-
-	_xpak_close(x);
-
-	if (x->data != ext)
-		free(x->data);
-
-	return 0;
-}
-
-static void
-_xpak_add_file(int dir_fd, const char *filename, struct stat *st, FILE *findex,
-               int *index_len, FILE *fdata, int *data_len)
-{
-	FILE *fin;
-	unsigned char *p;
-	const char *basefile;
-	int fd, in_len;
-
-	if ((basefile = strrchr(filename, '/')) == NULL) {
-		basefile = filename;
-	} else {
-		++basefile;
-		assert(*basefile);
-	}
-
-	if (verbose == 1)
-		printf("%s\n", basefile);
-	else if (verbose)
-		printf("%s @ offset byte %i\n", basefile, *data_len);
-
-	/* write out the (pathname_len) */
-	in_len = strlen(basefile);
-	p = tbz2_encode_int(in_len);
-	fwrite(p, 1, 4, findex);
-	/* write out the pathname */
-	fwrite(basefile, 1, in_len, findex);
-	/* write out the (data_offset) */
-	p = tbz2_encode_int(*data_len);
-	fwrite(p, 1, 4, findex);
-
-	*index_len += 4 + in_len + 4 + 4;
-
-	/* now open the file, get (data_len), and append the file to the data file */
-	fd = openat(dir_fd, filename, O_RDONLY|O_CLOEXEC);
-	if (fd < 0) {
- open_fail:
-		warnp("could not open for reading: %s", filename);
- fake_data_len:
-		p = tbz2_encode_int(0);
-		fwrite(p, 1, 4, findex);
-		return;
-	}
-	fin = fdopen(fd, "r");
-	if (!fin) {
-		close(fd);
-		goto open_fail;
-	}
-	in_len = st->st_size;
-	/* the xpak format can only store files whose size is a 32bit int
-	 * so we have to make sure we don't store a big file */
-	if (in_len != st->st_size) {
-		warnf("File is too big: %"PRIu64, (uint64_t)st->st_size);
-		fclose(fin);
-		goto fake_data_len;
-	}
-	p = tbz2_encode_int(in_len);
-	fwrite(p, 1, 4, findex);
-	_tbz2_copy_file(fin, fdata);
-	fclose(fin);
-
-	*data_len += in_len;
-}
-static int
-xpak_create(int dir_fd, const char *file, int argc, char **argv)
-{
-	FILE *findex, *fdata, *fout;
-	struct dirent **dir;
-	int i, fidx, numfiles;
-	struct stat st;
-	char path[_Q_PATH_MAX];
-	unsigned char *p;
-	int index_len, data_len;
-
-	if (argc == 0)
-		err("Create usage: <xpak output> <files/dirs to pack>");
-
-	if (strlen(file) >= sizeof(path)-6)
-		err("Pathname is too long: %s", file);
-
-	if ((fout = fopen(file, "w")) == NULL) {
-		warnp("could not open output: %s", file);
-		return 1;
-	}
-	strcpy(path, file); strcat(path, ".index");
-	if ((findex = fopen(path, "w+")) == NULL) {
-		warnp("could not open output: %s", path);
-		fclose(fout);
-		return 1;
-	}
-	strcpy(path, file); strcat(path, ".dat");
-	if ((fdata = fopen(path, "w+")) == NULL) {
-		warnp("could not open output: %s", path);
-		fclose(fout);
-		fclose(findex);
-		return 1;
-	}
-
-	index_len = data_len = 0;
-	for (i = 0; i < argc; ++i) {
-		if (fstatat(dir_fd, argv[i], &st, 0)) {
-			warnp("fstatat(%s) failed", argv[i]);
-			continue;
-		}
-		if (S_ISDIR(st.st_mode)) {
-			if ((numfiles = scandir(argv[i], &dir, filter_hidden, alphasort)) < 0)
-				warn("Directory '%s' is empty; skipping", argv[i]);
-			for (fidx = 0; fidx < numfiles; ++fidx) {
-				int ret = snprintf(path, sizeof(path), "%s/%s",
-						argv[i], dir[fidx]->d_name);
-				if (ret < 0 || (size_t)ret >= sizeof(path)) {
-					warn("skipping path too long: %s/%s",
-							argv[i], dir[fidx]->d_name);
-					continue;
-				}
-				if (stat(path, &st) < 0) {
-					warnp("could not read %s", path);
-					continue;
-				}
-				_xpak_add_file(dir_fd, path, &st, findex, &index_len, fdata, &data_len);
-			}
-			scandir_free(dir, numfiles);
-		} else if (S_ISREG(st.st_mode)) {
-			_xpak_add_file(dir_fd, argv[i], &st, findex, &index_len, fdata, &data_len);
-		} else
-			warn("Skipping non file/directory '%s'", argv[i]);
-	}
-
-	rewind(findex);
-	rewind(fdata);
-
-	/* "XPAKPACK" + (index_len) + (data_len) + index + data + "XPAKSTOP" */
-	fwrite(XPAK_START_MSG, 1, XPAK_START_MSG_LEN, fout); /* "XPAKPACK" */
-	p = tbz2_encode_int(index_len);
-	fwrite(p, 1, 4, fout);                               /* (index_len) */
-	p = tbz2_encode_int(data_len);
-	fwrite(p, 1, 4, fout);                               /* (data_len) */
-	_tbz2_copy_file(findex, fout);                       /* index */
-	_tbz2_copy_file(fdata, fout);                        /* data */
-	fwrite(XPAK_END_MSG, 1, XPAK_END_MSG_LEN, fout);     /* "XPAKSTOP" */
-
-	strcpy(path, file); strcat(path, ".index"); unlink(path);
-	strcpy(path, file); strcat(path, ".dat");   unlink(path);
-	fclose(findex);
-	fclose(fdata);
-	fclose(fout);
-
-	return 0;
-}
 
 int qxpak_main(int argc, char **argv)
 {
@@ -417,10 +132,17 @@ int qxpak_main(int argc, char **argv)
 	argv += optind;
 
 	switch (action) {
-	case XPAK_ACT_LIST:    ret = xpak_list(dir_fd, xpak, argc, argv); break;
-	case XPAK_ACT_EXTRACT: ret = xpak_extract(dir_fd, xpak, argc, argv); break;
-	case XPAK_ACT_CREATE:  ret = xpak_create(dir_fd, xpak, argc, argv); break;
-	default: ret = EXIT_FAILURE;
+	case XPAK_ACT_LIST:
+		ret = xpak_list(dir_fd, xpak, argc, argv, &_xpak_list_callback);
+		break;
+	case XPAK_ACT_EXTRACT:
+		ret = xpak_extract(dir_fd, xpak, argc, argv, &_xpak_extract_callback);
+		break;
+	case XPAK_ACT_CREATE:
+		ret = xpak_create(dir_fd, xpak, argc, argv, 0, verbose);
+		break;
+	default:
+		ret = EXIT_FAILURE;
 	}
 
 	if (dir_fd != AT_FDCWD)
@@ -428,7 +150,3 @@ int qxpak_main(int argc, char **argv)
 
 	return ret;
 }
-
-#else
-DEFINE_APPLET_STUB(qxpak)
-#endif


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-03-27 20:18 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-03-27 20:18 UTC (permalink / raw
  To: gentoo-commits

commit:     3cf77d19bd7f3abd323e4f148f73575cee8ac85b
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 27 20:18:20 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Mar 27 20:18:20 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=3cf77d19

q: fix various issues on Linux systems

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/contents.c |  1 +
 libq/xpak.c     |  2 +-
 libq/xsystem.c  |  7 +++++--
 main.c          |  4 ++--
 main.h          |  1 +
 q.c             |  1 +
 qcache.c        |  2 +-
 qgrep.c         | 15 ++++++++++-----
 qlop.c          |  1 +
 qmerge.c        | 10 +++++-----
 qpkg.c          |  4 ++--
 qsearch.c       |  1 +
 qtegrity.c      |  3 +++
 quse.c          |  1 +
 14 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/libq/contents.c b/libq/contents.c
index 41929d0..3e719a6 100644
--- a/libq/contents.c
+++ b/libq/contents.c
@@ -11,6 +11,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <limits.h>
 
 #include "contents.h"
 

diff --git a/libq/xpak.c b/libq/xpak.c
index 09b58bd..2785899 100644
--- a/libq/xpak.c
+++ b/libq/xpak.c
@@ -258,7 +258,7 @@ _xpak_add_file(
 	/* the xpak format can only store files whose size is a 32bit int
 	 * so we have to make sure we don't store a big file */
 	if (in_len != st->st_size) {
-		warnf("File is too big: %"PRIu64, (uint64_t)st->st_size);
+		warnf("File is too big: %zu", (size_t)st->st_size);
 		fclose(fin);
 		goto fake_data_len;
 	}

diff --git a/libq/xsystem.c b/libq/xsystem.c
index 1cc5cad..e11172e 100644
--- a/libq/xsystem.c
+++ b/libq/xsystem.c
@@ -6,12 +6,15 @@
  */
 
 #include "main.h"
-#include "xasprintf.h"
-#include "xsystem.h"
 
 #include <stdlib.h>
 #include <sys/wait.h>
 #include <fcntl.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "xasprintf.h"
+#include "xsystem.h"
 
 void xsystem(const char *command)
 {

diff --git a/main.c b/main.c
index 1da04fe..7e56101 100644
--- a/main.c
+++ b/main.c
@@ -448,7 +448,7 @@ read_portage_env_file(const char *configroot, const char *file, env_vars vars[])
 	if ((dentslen = scandir(buf, &dents, NULL, alphasort)) > 0) {
 		int di;
 		struct dirent *d;
-		char npath[_Q_PATH_MAX];
+		char npath[_Q_PATH_MAX * 2];
 
 		/* recurse through all files */
 		for (di = 0; di < dentslen; di++) {
@@ -858,7 +858,7 @@ initialize_flat(const char *overlay, int cache_type, bool force)
 		if (pkg_cnt < 0)
 			continue;
 		for (c = 0; c < pkg_cnt; c++) {
-			char de[_Q_PATH_MAX];
+			char de[_Q_PATH_MAX * 2];
 
 			snprintf(de, sizeof(de), "%s/%s",
 					category[i]->d_name, pn[c]->d_name);

diff --git a/main.h b/main.h
index 958efa6..32c995f 100644
--- a/main.h
+++ b/main.h
@@ -15,6 +15,7 @@
 #endif
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <stdint.h>

diff --git a/q.c b/q.c
index a4a943e..1e180de 100644
--- a/q.c
+++ b/q.c
@@ -10,6 +10,7 @@
 #include "main.h"
 #include "applets.h"
 
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>

diff --git a/qcache.c b/qcache.c
index 29b10af..f3252d7 100644
--- a/qcache.c
+++ b/qcache.c
@@ -805,7 +805,7 @@ qcache_stats(qcache_data *data)
 #endif
 			{
 				struct stat s;
-				char spath[_Q_PATH_MAX];
+				char spath[_Q_PATH_MAX * 2];
 				snprintf(spath, sizeof(spath), "%s/%s", catpath, de->d_name);
 				if (lstat(spath, &s) != 0)
 					continue;

diff --git a/qgrep.c b/qgrep.c
index da38f40..fdabf9c 100644
--- a/qgrep.c
+++ b/qgrep.c
@@ -223,7 +223,12 @@ qgrep_print_before_context(qgrep_buf_t *current, const char num_lines_before,
 
 /* Yield the path of one of the installed ebuilds (from VDB). */
 static char *
-get_next_installed_ebuild(char *ebuild_path, DIR *vdb_dir, struct dirent **cat_dirent_pt, DIR **cat_dir_pt)
+get_next_installed_ebuild(
+		char *ebuild_path,
+		size_t ebuild_path_len,
+		DIR *vdb_dir,
+		struct dirent **cat_dirent_pt,
+		DIR **cat_dir_pt)
 {
 	struct dirent *pkg_dirent = NULL;
 	if (*cat_dirent_pt == NULL || *cat_dir_pt == NULL)
@@ -233,7 +238,7 @@ get_next_ebuild_from_category:
 		goto get_next_category;
 	if (pkg_dirent->d_name[0] == '.')
 		goto get_next_ebuild_from_category;
-	snprintf(ebuild_path, _Q_PATH_MAX, "%s/%s/%s.ebuild",
+	snprintf(ebuild_path, ebuild_path_len, "%s/%s/%s.ebuild",
 			(*cat_dirent_pt)->d_name, pkg_dirent->d_name, pkg_dirent->d_name);
 	return ebuild_path;
 get_next_category:
@@ -260,7 +265,7 @@ int qgrep_main(int argc, char **argv)
 	DIR *vdb_dir = NULL;
 	DIR *cat_dir = NULL;
 	struct dirent *dentry = NULL;
-	char ebuild[_Q_PATH_MAX];
+	char ebuild[_Q_PATH_MAX * 4];
 	char name[_Q_PATH_MAX * 2];
 	char *label;
 	int reflags = 0;
@@ -420,8 +425,8 @@ int qgrep_main(int argc, char **argv)
 					&& snprintf(ebuild, sizeof(ebuild),
 						"eclass/%s", dentry->d_name))
 				: (do_installed
-					? (get_next_installed_ebuild(ebuild, vdb_dir,
-							&dentry, &cat_dir) != NULL)
+					? (get_next_installed_ebuild(ebuild, sizeof(ebuild),
+							vdb_dir, &dentry, &cat_dir) != NULL)
 					: (fgets(ebuild, sizeof(ebuild), fp) != NULL)))
 		{
 			FILE *newfp;

diff --git a/qlop.c b/qlop.c
index b8038b4..b6970d0 100644
--- a/qlop.c
+++ b/qlop.c
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
+#include <limits.h>
 
 #include "atom.h"
 #include "eat_file.h"

diff --git a/qmerge.c b/qmerge.c
index 81da0b1..97726db 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -850,13 +850,13 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
 			int fd_srcf, fd_dstf;
 			unsigned char *hash;
 			const char *tmpname, *dname;
-			char buf[_Q_PATH_MAX];
+			char buf[_Q_PATH_MAX * 2];
 
 			/* syntax: obj filename hash mtime */
 			hash = hash_file_at(subfd_src, name, HASH_MD5);
 			if (!pretend)
-				fprintf(contents, "obj %s %s %"PRIu64"\n",
-						cpath, hash, (uint64_t)st.st_mtime);
+				fprintf(contents, "obj %s %s %zu""\n",
+						cpath, hash, (size_t)st.st_mtime);
 			free(hash);
 
 			/* Check CONFIG_PROTECT */
@@ -954,8 +954,8 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
 
 			/* syntax: sym src -> dst mtime */
 			if (!pretend)
-				fprintf(contents, "sym %s -> %s %"PRIu64"\n",
-						cpath, sym, (uint64_t)st.st_mtime);
+				fprintf(contents, "sym %s -> %s %zu\n",
+						cpath, sym, (size_t)st.st_mtime);
 			qprintf("%s>>>%s %s%s -> %s%s\n", GREEN, NORM,
 					CYAN, cpath, sym, NORM);
 			*objs = add_set(cpath, *objs);

diff --git a/qpkg.c b/qpkg.c
index 3ff4507..37f1cb7 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -77,7 +77,7 @@ qpkg_clean_dir(char *dirp, set *vdb)
 	set *ll = NULL;
 	struct dirent **fnames;
 	int i, count;
-	char buf[_Q_PATH_MAX];
+	char buf[_Q_PATH_MAX * 2];
 	struct stat st;
 	uint64_t num_all_bytes = 0;
 	size_t disp_units = 0;
@@ -186,7 +186,7 @@ qpkg_clean(char *dirp)
 	num_all_bytes = qpkg_clean_dir(dirp, vdb);
 
 	for (i = 0; i < count; i++) {
-		char buf[_Q_PATH_MAX];
+		char buf[_Q_PATH_MAX * 2];
 		snprintf(buf, sizeof(buf), "%s/%s", dirp, dnames[i]->d_name);
 		num_all_bytes += qpkg_clean_dir(buf, vdb);
 	}

diff --git a/qsearch.c b/qsearch.c
index 5ae68bc..f543b8a 100644
--- a/qsearch.c
+++ b/qsearch.c
@@ -11,6 +11,7 @@
 #include "applets.h"
 
 #include <stdio.h>
+#include <unistd.h>
 #include <string.h>
 #include <xalloc.h>
 #include <sys/types.h>

diff --git a/qtegrity.c b/qtegrity.c
index 2e3b859..70a99d5 100644
--- a/qtegrity.c
+++ b/qtegrity.c
@@ -10,8 +10,11 @@
 #include "main.h"
 #include "applets.h"
 
+#include <stdio.h>
+#include <unistd.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <signal.h>
 #include <fcntl.h>
 

diff --git a/quse.c b/quse.c
index 62ae166..c93be87 100644
--- a/quse.c
+++ b/quse.c
@@ -11,6 +11,7 @@
 #include "applets.h"
 
 #include <stdio.h>
+#include <unistd.h>
 #include <string.h>
 #include <xalloc.h>
 #include <sys/types.h>


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-04-28 15:20 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-04-28 15:20 UTC (permalink / raw
  To: gentoo-commits

commit:     2fc9b2a308a7d72edede919956a0d290a72a7781
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Apr 28 15:19:07 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Apr 28 15:19:07 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=2fc9b2a3

libq/{vdb,cache}: unify sorted and unsorted traversal

Get vdb to know some bits for cache, such that cache can be a more
shallow wrapper around it.  Use the same code to traverse in sorted mode
by just keeping a temp list in the sorted case.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/cache.c | 137 ++++++++++++++++++-------------------------------
 libq/cache.h |  14 +----
 libq/vdb.c   | 164 ++++++++++++++++++++++++++++++++++-------------------------
 libq/vdb.h   |  46 +++++++++++++----
 qgrep.c      |   4 +-
 5 files changed, 186 insertions(+), 179 deletions(-)

diff --git a/libq/cache.c b/libq/cache.c
index 7724287..a00dd6b 100644
--- a/libq/cache.c
+++ b/libq/cache.c
@@ -53,46 +53,43 @@ static const char portrepo_name[]    = "profiles/repo_name";
 cache_ctx *
 cache_open(const char *sroot, const char *portdir)
 {
-	q_vdb_ctx *dir;
 	cache_ctx *ret;
 	char buf[_Q_PATH_MAX];
+	char *repo = NULL;
 	size_t repolen = 0;
 
-	ret = xzalloc(sizeof(cache_ctx));
-
 	snprintf(buf, sizeof(buf), "%s%s/%s", sroot, portdir, portrepo_name);
-	if (eat_file(buf, &ret->repo, &repolen)) {
-		(void)rmspace(ret->repo);
+	if (eat_file(buf, &repo, &repolen)) {
+		(void)rmspace(repo);
 	} else {
-		ret->repo = NULL;  /* ignore missing repo file */
+		repo = NULL;  /* ignore missing repo file */
 	}
 
 	snprintf(buf, sizeof(buf), "%s/%s", portdir, portcachedir_md5);
-	dir = q_vdb_open2(sroot, buf, true);
-	if (dir != NULL) {
-		ret->dir_ctx = dir;
+	ret = q_vdb_open2(sroot, buf, true);
+	if (ret != NULL) {
 		ret->cachetype = CACHE_METADATA_MD5;
+		ret->repo = repo;
 		return ret;
 	}
 
 	snprintf(buf, sizeof(buf), "%s/%s", portdir, portcachedir_pms);
-	dir = q_vdb_open2(sroot, buf, true);
-	if (dir != NULL) {
-		ret->dir_ctx = dir;
+	ret = q_vdb_open2(sroot, buf, true);
+	if (ret != NULL) {
 		ret->cachetype = CACHE_METADATA_PMS;
+		ret->repo = repo;
 		return ret;
 	}
 
-	dir = q_vdb_open2(sroot, portdir, true);
-	if (dir != NULL) {
-		ret->dir_ctx = dir;
+	ret = q_vdb_open2(sroot, portdir, true);
+	if (ret != NULL) {
 		ret->cachetype = CACHE_EBUILD;
+		ret->repo = repo;
 		return ret;
 	}
 
 	cache_close(ret);
-	warnf("could not open repository at %s (under root %s)",
-			portdir, sroot);
+	warnf("could not open repository at %s (under root %s)", portdir, sroot);
 
 	return NULL;
 }
@@ -100,49 +97,41 @@ cache_open(const char *sroot, const char *portdir)
 void
 cache_close(cache_ctx *ctx)
 {
-	if (ctx->dir_ctx != NULL)
-		q_vdb_close(ctx->dir_ctx);
 	if (ctx->repo != NULL)
 		free(ctx->repo);
-	free(ctx);
+	if (ctx->ebuilddir_ctx != NULL)
+		free(ctx->ebuilddir_ctx);
+	q_vdb_close(ctx);
 }
 
 cache_cat_ctx *
 cache_open_cat(cache_ctx *ctx, const char *name)
 {
-	cache_cat_ctx *ret = q_vdb_open_cat(ctx->dir_ctx, name);
-	if (ret != NULL)
-		ret->ctx = (q_vdb_ctx *)ctx;
-	return ret;
+	return q_vdb_open_cat(ctx, name);
 }
 
 cache_cat_ctx *
 cache_next_cat(cache_ctx *ctx)
 {
-	cache_cat_ctx *ret = q_vdb_next_cat(ctx->dir_ctx);
-	if (ret != NULL)
-		ret->ctx = (q_vdb_ctx *)ctx;
-	return ret;
+	return q_vdb_next_cat(ctx);
 }
 
 void
 cache_close_cat(cache_cat_ctx *cat_ctx)
 {
-	q_vdb_close_cat(cat_ctx);
+	return q_vdb_close_cat(cat_ctx);
 }
 
 cache_pkg_ctx *
 cache_open_pkg(cache_cat_ctx *cat_ctx, const char *name)
 {
-	cache_pkg_ctx *ret = q_vdb_open_pkg(cat_ctx, name);
-	ret->repo = ((cache_ctx *)cat_ctx->ctx)->repo;
-	return ret;
+	return q_vdb_open_pkg(cat_ctx, name);
 }
 
 cache_pkg_ctx *
 cache_next_pkg(cache_cat_ctx *cat_ctx)
 {
-	cache_ctx *ctx = (cache_ctx *)(cat_ctx->ctx);
+	cache_ctx *ctx = (cache_ctx *)cat_ctx->ctx;
 	cache_pkg_ctx *ret = NULL;
 
 	if (ctx->cachetype == CACHE_EBUILD) {
@@ -152,7 +141,10 @@ cache_next_pkg(cache_cat_ctx *cat_ctx)
 		 * to CAT/P like in VDB and metadata */
 		do {
 			if (ctx->ebuilddir_pkg_ctx == NULL) {
-				q_vdb_ctx *pkgdir = &ctx->ebuilddir_ctx;
+				q_vdb_ctx *pkgdir = ctx->ebuilddir_ctx;
+
+				if (pkgdir == NULL)
+					pkgdir = ctx->ebuilddir_ctx = xzalloc(sizeof(q_vdb_ctx));
 
 				if ((ctx->ebuilddir_pkg_ctx = q_vdb_next_pkg(cat_ctx)) == NULL)
 					return NULL;
@@ -492,14 +484,16 @@ void
 cache_close_pkg(cache_pkg_ctx *pkg_ctx)
 {
 	/* avoid free of cache_ctx' repo by q_vdb_close_pkg */
-	if (((cache_ctx *)pkg_ctx->cat_ctx->ctx)->repo == pkg_ctx->repo)
+	if (pkg_ctx->cat_ctx->ctx->repo == pkg_ctx->repo)
 		pkg_ctx->repo = NULL;
+
 	q_vdb_close_pkg(pkg_ctx);
 }
 
-int
-cache_foreach_pkg(const char *sroot, const char *portdir,
-		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter)
+static int
+cache_foreach_pkg_int(const char *sroot, const char *portdir,
+		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter,
+		bool sort, void *catsortfunc, void *pkgsortfunc)
 {
 	cache_ctx *ctx;
 	cache_cat_ctx *cat_ctx;
@@ -510,6 +504,12 @@ cache_foreach_pkg(const char *sroot, const char *portdir,
 	if (!ctx)
 		return EXIT_FAILURE;
 
+	ctx->do_sort = sort;
+	if (catsortfunc != NULL)
+		ctx->catsortfunc = catsortfunc;
+	if (pkgsortfunc != NULL)
+		ctx->pkgsortfunc = pkgsortfunc;
+
 	ret = 0;
 	while ((cat_ctx = cache_next_cat(ctx))) {
 		if (filter && !filter(cat_ctx, priv))
@@ -518,63 +518,26 @@ cache_foreach_pkg(const char *sroot, const char *portdir,
 			ret |= callback(pkg_ctx, priv);
 			cache_close_pkg(pkg_ctx);
 		}
+		cache_close_cat(cat_ctx);
 	}
+	cache_close(ctx);
 
 	return ret;
 }
 
+int
+cache_foreach_pkg(const char *sroot, const char *portdir,
+		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter)
+{
+	return cache_foreach_pkg_int(sroot, portdir, callback, priv,
+			filter, false, NULL, NULL);
+}
+
 int
 cache_foreach_pkg_sorted(const char *sroot, const char *portdir,
 		q_vdb_pkg_cb callback, void *priv,
 		void *catsortfunc, void *pkgsortfunc)
 {
-	cache_ctx *ctx;
-	cache_cat_ctx *cat_ctx;
-	cache_pkg_ctx *pkg_ctx;
-	int ret = 0;
-	int c;
-	int p;
-	int cat_cnt;
-	int pkg_cnt;
-	struct dirent **cat_de;
-	struct dirent **pkg_de;
-
-	ctx = cache_open(sroot, portdir);
-	if (!ctx)
-		return EXIT_FAILURE;
-
-	if (catsortfunc == NULL)
-		catsortfunc = alphasort;
-	if (pkgsortfunc == NULL)
-		pkgsortfunc = alphasort;
-
-	cat_cnt = scandirat(ctx->dir_ctx->vdb_fd,
-			".", &cat_de, q_vdb_filter_cat, catsortfunc);
-	for (c = 0; c < cat_cnt; c++) {
-		cat_ctx = cache_open_cat(ctx, cat_de[c]->d_name);
-		if (!cat_ctx)
-			continue;
-
-		pkg_cnt = scandirat(ctx->dir_ctx->vdb_fd,
-				cat_de[c]->d_name, &pkg_de, q_vdb_filter_pkg, pkgsortfunc);
-		for (p = 0; p < pkg_cnt; p++) {
-			if (pkg_de[p]->d_name[0] == '-')
-				continue;
-
-			pkg_ctx = cache_open_pkg(cat_ctx, pkg_de[p]->d_name);
-			if (!pkg_ctx)
-				continue;
-
-			ret |= callback(pkg_ctx, priv);
-
-			cache_close_pkg(pkg_ctx);
-		}
-		scandir_free(pkg_de, pkg_cnt);
-
-		cache_close_cat(cat_ctx);
-	}
-	scandir_free(cat_de, cat_cnt);
-
-	cache_close(ctx);
-	return ret;
+	return cache_foreach_pkg_int(sroot, portdir, callback, priv,
+			NULL, true, catsortfunc, pkgsortfunc);
 }

diff --git a/libq/cache.h b/libq/cache.h
index 0157824..f9b1d43 100644
--- a/libq/cache.h
+++ b/libq/cache.h
@@ -13,19 +13,7 @@
 #include "atom.h"
 #include "vdb.h"
 
-typedef struct cache_ctx {
-	q_vdb_ctx *dir_ctx;
-	enum {
-		CACHE_UNSET = 0,
-		CACHE_METADATA_MD5,
-		CACHE_METADATA_PMS,
-		CACHE_EBUILD,
-	} cachetype;
-	q_vdb_pkg_ctx *ebuilddir_pkg_ctx;
-	q_vdb_cat_ctx *ebuilddir_cat_ctx;
-	q_vdb_ctx ebuilddir_ctx;
-	char *repo;
-} cache_ctx;
+#define cache_ctx     q_vdb_ctx
 #define cache_cat_ctx q_vdb_cat_ctx
 #define cache_pkg_ctx q_vdb_pkg_ctx
 

diff --git a/libq/vdb.c b/libq/vdb.c
index a32ba53..9c53b5b 100644
--- a/libq/vdb.c
+++ b/libq/vdb.c
@@ -45,6 +45,13 @@ q_vdb_open2(const char *sroot, const char *svdb, bool quiet)
 	if (ctx->dir == NULL)
 		goto cv_error;
 
+	ctx->do_sort = false;
+	ctx->cat_de = NULL;
+	ctx->catsortfunc = alphasort;
+	ctx->pkgsortfunc = alphasort;
+	ctx->repo = NULL;
+	ctx->ebuilddir_ctx = NULL;
+	ctx->ebuilddir_pkg_ctx = NULL;
 	return ctx;
 
  cv_error:
@@ -69,6 +76,8 @@ q_vdb_close(q_vdb_ctx *ctx)
 	/* closedir() above does this for us: */
 	/* close(ctx->vdb_fd); */
 	close(ctx->portroot_fd);
+	if (ctx->do_sort)
+		scandir_free(ctx->cat_de, ctx->cat_cnt);
 	free(ctx);
 }
 
@@ -136,6 +145,7 @@ q_vdb_open_cat(q_vdb_ctx *ctx, const char *name)
 	cat_ctx->fd = fd;
 	cat_ctx->dir = dir;
 	cat_ctx->ctx = ctx;
+	cat_ctx->pkg_de = NULL;
 	return cat_ctx;
 }
 
@@ -143,22 +153,39 @@ q_vdb_cat_ctx *
 q_vdb_next_cat(q_vdb_ctx *ctx)
 {
 	/* search for a category directory */
-	q_vdb_cat_ctx *cat_ctx;
-	const struct dirent *de;
+	q_vdb_cat_ctx *cat_ctx = NULL;
 
- next_cat:
-	de = readdir(ctx->dir);
-	if (!de) {
-		q_vdb_close(ctx);
-		return NULL;
-	}
+	if (ctx->do_sort) {
+		if (ctx->cat_de == NULL) {
+			ctx->cat_cnt = scandirat(ctx->vdb_fd,
+					".", &ctx->cat_de, q_vdb_filter_cat, ctx->catsortfunc);
+			ctx->cat_cur = 0;
+		}
+
+		while (ctx->cat_cur < ctx->cat_cnt) {
+			cat_ctx = q_vdb_open_cat(ctx, ctx->cat_de[ctx->cat_cur++]->d_name);
+			if (!cat_ctx)
+				continue;
+			break;
+		}
+	} else {
+		/* cheaper "streaming" variant */
+		const struct dirent *de;
+		do {
+			de = readdir(ctx->dir);
+			if (!de)
+				break;
 
-	if (q_vdb_filter_cat(de) == 0)
-		goto next_cat;
+			if (q_vdb_filter_cat(de) == 0)
+				continue;
+
+			cat_ctx = q_vdb_open_cat(ctx, de->d_name);
+			if (!cat_ctx)
+				continue;
 
-	cat_ctx = q_vdb_open_cat(ctx, de->d_name);
-	if (!cat_ctx)
-		goto next_cat;
+			break;
+		} while (1);
+	}
 
 	return cat_ctx;
 }
@@ -169,6 +196,8 @@ q_vdb_close_cat(q_vdb_cat_ctx *cat_ctx)
 	closedir(cat_ctx->dir);
 	/* closedir() above does this for us: */
 	/* close(ctx->fd); */
+	if (cat_ctx->ctx->do_sort)
+		scandir_free(cat_ctx->pkg_de, cat_ctx->pkg_cnt);
 	free(cat_ctx);
 }
 
@@ -194,7 +223,7 @@ q_vdb_open_pkg(q_vdb_cat_ctx *cat_ctx, const char *name)
 	q_vdb_pkg_ctx *pkg_ctx = xmalloc(sizeof(*pkg_ctx));
 	pkg_ctx->name = name;
 	pkg_ctx->slot = NULL;
-	pkg_ctx->repo = NULL;
+	pkg_ctx->repo = cat_ctx->ctx->repo;
 	pkg_ctx->fd = -1;
 	pkg_ctx->cat_ctx = cat_ctx;
 	return pkg_ctx;
@@ -203,22 +232,40 @@ q_vdb_open_pkg(q_vdb_cat_ctx *cat_ctx, const char *name)
 q_vdb_pkg_ctx *
 q_vdb_next_pkg(q_vdb_cat_ctx *cat_ctx)
 {
-	q_vdb_pkg_ctx *pkg_ctx;
-	const struct dirent *de;
+	q_vdb_pkg_ctx *pkg_ctx = NULL;
 
- next_pkg:
-	de = readdir(cat_ctx->dir);
-	if (!de) {
-		q_vdb_close_cat(cat_ctx);
-		return NULL;
-	}
+	if (cat_ctx->ctx->do_sort) {
+		if (cat_ctx->pkg_de == NULL) {
+			cat_ctx->pkg_cnt = scandirat(cat_ctx->fd, ".", &cat_ctx->pkg_de,
+					q_vdb_filter_pkg, cat_ctx->ctx->pkgsortfunc);
+			cat_ctx->pkg_cur = 0;
+		}
+
+		while (cat_ctx->pkg_cur < cat_ctx->pkg_cnt) {
+			pkg_ctx =
+				q_vdb_open_pkg(cat_ctx,
+						cat_ctx->pkg_de[cat_ctx->pkg_cur++]->d_name);
+			if (!pkg_ctx)
+				continue;
+			break;
+		}
+	} else {
+		const struct dirent *de;
+		do {
+			de = readdir(cat_ctx->dir);
+			if (!de)
+				break;
+
+			if (q_vdb_filter_pkg(de) == 0)
+				continue;
 
-	if (q_vdb_filter_pkg(de) == 0)
-		goto next_pkg;
+			pkg_ctx = q_vdb_open_pkg(cat_ctx, de->d_name);
+			if (!pkg_ctx)
+				continue;
 
-	pkg_ctx = q_vdb_open_pkg(cat_ctx, de->d_name);
-	if (!pkg_ctx)
-		goto next_pkg;
+			break;
+		} while (1);
+	}
 
 	return pkg_ctx;
 }
@@ -275,9 +322,10 @@ q_vdb_close_pkg(q_vdb_pkg_ctx *pkg_ctx)
 	free(pkg_ctx);
 }
 
-int
-q_vdb_foreach_pkg(const char *sroot, const char *svdb,
-		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter)
+static int
+q_vdb_foreach_pkg_int(const char *sroot, const char *svdb,
+		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter,
+		bool sort, void *catsortfunc, void *pkgsortfunc)
 {
 	q_vdb_ctx *ctx;
 	q_vdb_cat_ctx *cat_ctx;
@@ -288,6 +336,12 @@ q_vdb_foreach_pkg(const char *sroot, const char *svdb,
 	if (!ctx)
 		return EXIT_FAILURE;
 
+	ctx->do_sort = sort;
+	if (catsortfunc != NULL)
+		ctx->catsortfunc = catsortfunc;
+	if (pkgsortfunc != NULL)
+		ctx->pkgsortfunc = pkgsortfunc;
+
 	ret = 0;
 	while ((cat_ctx = q_vdb_next_cat(ctx))) {
 		if (filter && !filter(cat_ctx, priv))
@@ -296,53 +350,27 @@ q_vdb_foreach_pkg(const char *sroot, const char *svdb,
 			ret |= callback(pkg_ctx, priv);
 			q_vdb_close_pkg(pkg_ctx);
 		}
+		q_vdb_close_cat(cat_ctx);
 	}
+	q_vdb_close(ctx);
 
 	return ret;
 }
 
+int
+q_vdb_foreach_pkg(const char *sroot, const char *svdb,
+		q_vdb_pkg_cb callback, void *priv, q_vdb_cat_filter filter)
+{
+	return q_vdb_foreach_pkg_int(sroot, svdb, callback, priv,
+			filter, false, NULL, NULL);
+}
+
 int
 q_vdb_foreach_pkg_sorted(const char *sroot, const char *svdb,
 		q_vdb_pkg_cb callback, void *priv)
 {
-	q_vdb_ctx *ctx;
-	q_vdb_cat_ctx *cat_ctx;
-	q_vdb_pkg_ctx *pkg_ctx;
-	int ret = 0;
-	int c, p, cat_cnt, pkg_cnt;
-	struct dirent **cat_de, **pkg_de;
-
-	ctx = q_vdb_open(sroot, svdb);
-	if (!ctx)
-		return EXIT_FAILURE;
-
-	cat_cnt = scandirat(ctx->vdb_fd, ".", &cat_de, q_vdb_filter_cat, alphasort);
-	for (c = 0; c < cat_cnt; ++c) {
-		cat_ctx = q_vdb_open_cat(ctx, cat_de[c]->d_name);
-		if (!cat_ctx)
-			continue;
-
-		pkg_cnt = scandirat(ctx->vdb_fd, cat_de[c]->d_name, &pkg_de, q_vdb_filter_pkg, alphasort);
-		for (p = 0; p < pkg_cnt; ++p) {
-			if (pkg_de[p]->d_name[0] == '-')
-				continue;
-
-			pkg_ctx = q_vdb_open_pkg(cat_ctx, pkg_de[p]->d_name);
-			if (!pkg_ctx)
-				continue;
-
-			ret |= callback(pkg_ctx, priv);
-
-			q_vdb_close_pkg(pkg_ctx);
-		}
-		scandir_free(pkg_de, pkg_cnt);
-
-		q_vdb_close_cat(cat_ctx);
-	}
-	scandir_free(cat_de, cat_cnt);
-
-	q_vdb_close(ctx);
-	return ret;
+	return q_vdb_foreach_pkg_int(sroot, svdb, callback, priv,
+			NULL, true, NULL, NULL);
 }
 
 struct dirent *

diff --git a/libq/vdb.h b/libq/vdb.h
index 102f5a9..ee2ee69 100644
--- a/libq/vdb.h
+++ b/libq/vdb.h
@@ -7,31 +7,59 @@
 #define _VDB_H 1
 
 #include <dirent.h>
+#include <stdbool.h>
 
 #include "set.h"
 
+typedef struct q_vdb_ctx q_vdb_ctx;
+typedef struct q_vdb_cat_ctx q_vdb_cat_ctx;
+typedef struct q_vdb_pkg_ctx q_vdb_pkg_ctx;
+
 /* VDB context */
-typedef struct {
-	int portroot_fd, vdb_fd;
+struct q_vdb_ctx {
+	int portroot_fd;
+	int vdb_fd;
 	DIR *dir;
-} q_vdb_ctx;
+	struct dirent **cat_de;
+	size_t cat_cnt;
+	size_t cat_cur;
+	void *catsortfunc;
+	void *pkgsortfunc;
+	bool do_sort:1;
+	enum {
+		CACHE_UNSET = 0,
+		CACHE_METADATA_MD5,
+		CACHE_METADATA_PMS,
+		CACHE_EBUILD,
+		CACHE_VDB,
+	} cachetype:3;
+	q_vdb_pkg_ctx *ebuilddir_pkg_ctx;
+	q_vdb_cat_ctx *ebuilddir_cat_ctx;
+	q_vdb_ctx *ebuilddir_ctx;
+	char *repo;
+};
 
 /* Category context */
-typedef struct {
+struct q_vdb_cat_ctx {
 	const char *name;
 	int fd;
 	DIR *dir;
 	const q_vdb_ctx *ctx;
-} q_vdb_cat_ctx;
+	struct dirent **pkg_de;
+	size_t pkg_cnt;
+	size_t pkg_cur;
+};
 
 /* Package context */
-typedef struct {
+struct q_vdb_pkg_ctx {
 	const char *name;
-	char *slot, *repo;
-	size_t slot_len, repo_len;
+	char *slot;
+	char *repo;
+	size_t slot_len;
+	size_t repo_len;
 	int fd;
 	q_vdb_cat_ctx *cat_ctx;
-} q_vdb_pkg_ctx;
+};
 
 /* Global helpers */
 typedef int (q_vdb_pkg_cb)(q_vdb_pkg_ctx *, void *priv);

diff --git a/qgrep.c b/qgrep.c
index 9d78c18..6cb5697 100644
--- a/qgrep.c
+++ b/qgrep.c
@@ -413,9 +413,9 @@ qgrep_cache_cb(cache_pkg_ctx *pkg_ctx, void *priv)
 	/* need to construct path in portdir to ebuild, pass it to grep */
 	cctx = (cache_ctx *)(pkg_ctx->cat_ctx->ctx);
 	if (cctx->cachetype == CACHE_EBUILD) {
-		pfd = cctx->dir_ctx->vdb_fd;
+		pfd = cctx->vdb_fd;
 	} else {
-		pfd = openat(cctx->dir_ctx->vdb_fd, "../..", O_RDONLY|O_CLOEXEC);
+		pfd = openat(cctx->vdb_fd, "../..", O_RDONLY|O_CLOEXEC);
 	}
 
 	/* cat/pkg/pkg-ver.ebuild */


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-05-05 18:13 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-05-05 18:13 UTC (permalink / raw
  To: gentoo-commits

commit:     70679e49ee7fadc209a87ae23860fedfd646dc10
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun May  5 18:12:27 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun May  5 18:12:27 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=70679e49

libq/atom: move atom_format here

move atom_print from qatom to libq/atom as atom_format so it can be
reused by multiple applets

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/atom.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 libq/atom.h |   4 ++
 qatom.c     |  94 +----------------------------------------
 3 files changed, 137 insertions(+), 97 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index 5f4b137..8eb9ac6 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -13,6 +13,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdbool.h>
 #include <ctype.h>
 #include <xalloc.h>
 
@@ -569,12 +570,9 @@ implode_a1_ret:
 /**
  * Reconstructs an atom exactly like it was originally given (exploded).
  */
-static char _atom_buf[BUFSIZ];
 char *
-atom_to_string(depend_atom *a)
+atom_to_string_r(char *buf, size_t buflen, depend_atom *a)
 {
-	char *buf = _atom_buf;
-	size_t buflen = sizeof(_atom_buf);
 	size_t off = 0;
 	atom_usedep *ud;
 
@@ -606,3 +604,133 @@ atom_to_string(depend_atom *a)
 
 	return buf;
 }
+
+/**
+ * Run printf on an atom.  The format field takes the form:
+ *  %{keyword}: Always display the field that matches "keyword" or <unset>
+ *  %[keyword]: Only display the field when it's set (or pverbose)
+ * The possible "keywords" are:
+ *  CATEGORY  P  PN  PV  PVR  PF  PR  SLOT
+ *    - these are all the standard portage variables (so see ebuild(5))
+ *  pfx - the version qualifier if set (e.g. > < = !)
+ *  sfx - the version qualifier if set (e.g. *)
+ */
+char *
+atom_format_r(
+		char *buf,
+		size_t buflen,
+		const char *format,
+		const depend_atom *atom,
+		int pverbose)
+{
+	char bracket;
+	const char *fmt;
+	const char *p;
+	size_t len;
+	bool showit;
+	char *ret;
+
+	if (!atom) {
+		snprintf(buf, buflen, "%s", "(NULL:atom)");
+		return buf;
+	}
+
+#define append_buf(B,L,FMT,...) \
+	{ \
+		len = snprintf(B, L, FMT, __VA_ARGS__); \
+		L -= len; \
+		B += len; \
+	}
+	ret = buf;
+	p = format;
+	while (*p != '\0') {
+		fmt = strchr(p, '%');
+		if (fmt == NULL) {
+			if (buflen > 0)
+				*buf = '\0';
+			return buf;
+		} else if (fmt != p) {
+			append_buf(buf, buflen, "%.*s", (int)(fmt - p), p);
+		}
+
+		bracket = fmt[1];
+		if (bracket == '{' || bracket == '[') {
+			fmt += 2;
+			p = strchr(fmt, bracket == '{' ? '}' : ']');
+			if (p) {
+				len = p - fmt;
+				showit = (bracket == '{') || pverbose;
+#define HN(X) (X ? X : "<unset>")
+				if (!strncmp("CATEGORY", fmt, len)) {
+					if (showit || atom->CATEGORY)
+						append_buf(buf, buflen, "%s", HN(atom->CATEGORY));
+				} else if (!strncmp("P", fmt, len)) {
+					if (showit || atom->P)
+						append_buf(buf, buflen, "%s", HN(atom->P));
+				} else if (!strncmp("PN", fmt, len)) {
+					if (showit || atom->PN)
+						append_buf(buf, buflen, "%s", HN(atom->PN));
+				} else if (!strncmp("PV", fmt, len)) {
+					if (showit || atom->PV)
+						append_buf(buf, buflen, "%s", HN(atom->PV));
+				} else if (!strncmp("PVR", fmt, len)) {
+					if (showit || atom->PVR)
+						append_buf(buf, buflen, "%s", HN(atom->PVR));
+				} else if (!strncmp("PF", fmt, len)) {
+					append_buf(buf, buflen, "%s", atom->PN);
+					if (atom->PV)
+						append_buf(buf, buflen, "-%s", atom->PV);
+					if (atom->PR_int)
+						append_buf(buf, buflen,"-r%i", atom->PR_int);
+				} else if (!strncmp("PR", fmt, len)) {
+					if (showit || atom->PR_int)
+						append_buf(buf, buflen, "r%i", atom->PR_int);
+				} else if (!strncmp("SLOT", fmt, len)) {
+					if (showit || atom->SLOT)
+						append_buf(buf, buflen, "%s%s%s%s%s",
+								atom->SLOT ? ":" : "<unset>",
+								atom->SLOT ? atom->SLOT : "",
+								atom->SUBSLOT ? "/" : "",
+								atom->SUBSLOT ? atom->SUBSLOT : "",
+								atom_slotdep_str[atom->slotdep]);
+				} else if (!strncmp("REPO", fmt, len)) {
+					if (showit || atom->REPO)
+						append_buf(buf, buflen, "::%s", HN(atom->REPO));
+				} else if (!strncmp("pfx", fmt, len)) {
+					if (showit || atom->pfx_op != ATOM_OP_NONE)
+						append_buf(buf, buflen, "%s",
+								atom->pfx_op == ATOM_OP_NONE ?
+								"<unset>" : atom_op_str[atom->pfx_op]);
+				} else if (!strncmp("sfx", fmt, len)) {
+					if (showit || atom->sfx_op != ATOM_OP_NONE)
+						append_buf(buf, buflen, "%s",
+								atom->sfx_op == ATOM_OP_NONE ?
+								"<unset>" : atom_op_str[atom->sfx_op]);
+				} else
+					append_buf(buf, buflen, "<BAD:%.*s>", (int)len, fmt);
+				++p;
+#undef HN
+			} else
+				p = fmt + 1;
+		} else
+			++p;
+	}
+#undef append_buf
+
+	return ret;
+}
+
+/* versions that use an internal buffer, which is suitable for most
+ * scenarios */
+static char _atom_buf[BUFSIZ];
+char *
+atom_to_string(depend_atom *a)
+{
+	return atom_to_string_r(_atom_buf, sizeof(_atom_buf), a);
+}
+
+char *
+atom_format(const char *format, const depend_atom *atom, int pverbose)
+{
+	return atom_format_r(_atom_buf, sizeof(_atom_buf), format, atom, pverbose);
+}

diff --git a/libq/atom.h b/libq/atom.h
index 291d637..51ea88e 100644
--- a/libq/atom.h
+++ b/libq/atom.h
@@ -92,6 +92,10 @@ depend_atom *atom_explode(const char *atom);
 void atom_implode(depend_atom *atom);
 int atom_compare(const depend_atom *a1, const depend_atom *a2);
 int atom_compare_str(const char * const s1, const char * const s2);
+char *atom_to_string_r(char *buf, size_t buflen, depend_atom *a);
+char *atom_format_r(char *buf, size_t buflen,
+		const char *format, const depend_atom *atom, int pverbose);
 char *atom_to_string(depend_atom *a);
+char *atom_format(const char *format, const depend_atom *atom, int pverbose);
 
 #endif

diff --git a/qatom.c b/qatom.c
index e3d2b0b..8825055 100644
--- a/qatom.c
+++ b/qatom.c
@@ -31,97 +31,6 @@ static const char * const qatom_opts_help[] = {
 };
 #define qatom_usage(ret) usage(ret, QATOM_FLAGS, qatom_long_opts, qatom_opts_help, NULL, lookup_applet_idx("qatom"))
 
-/* Run printf on an atom!  The format field takes the form:
- *  %{keyword}: Always display the field that matches "keyword"
- *  %[keyword]: Only display the field when it's valid (or pverbose)
- * The possible "keywords" are:
- *  CATEGORY  P  PN  PV  PVR  PF  PR  SLOT
- *    - these are all the standard portage variables (so see ebuild(5))
- *  pfx - the version qualifier if set (e.g. > < = !)
- *  sfx - the version qualifier if set (e.g. *)
- */
-static void
-qatom_printf(const char *format, const depend_atom *atom, int pverbose)
-{
-	char bracket;
-	const char *fmt, *p;
-
-	if (!atom) {
-		printf("(NULL:atom)");
-		return;
-	}
-
-	p = format;
-	while (*p != '\0') {
-		fmt = strchr(p, '%');
-		if (fmt == NULL) {
-			printf("%s", p);
-			return;
-		} else if (fmt != p)
-			printf("%.*s", (int)(fmt - p), p);
-
-		bracket = fmt[1];
-		if (bracket == '{' || bracket == '[') {
-			fmt += 2;
-			p = strchr(fmt, bracket == '{' ? '}' : ']');
-			if (p) {
-				size_t len = p - fmt;
-				bool showit = (bracket == '{') || pverbose;
-#define HN(X) (X ? X : "<unset>")
-				if (!strncmp("CATEGORY", fmt, len)) {
-					if (showit || atom->CATEGORY)
-						printf("%s", HN(atom->CATEGORY));
-				} else if (!strncmp("P", fmt, len)) {
-					if (showit || atom->P)
-						printf("%s", HN(atom->P));
-				} else if (!strncmp("PN", fmt, len)) {
-					if (showit || atom->PN)
-						printf("%s", HN(atom->PN));
-				} else if (!strncmp("PV", fmt, len)) {
-					if (showit || atom->PV)
-						printf("%s", HN(atom->PV));
-				} else if (!strncmp("PVR", fmt, len)) {
-					if (showit || atom->PVR)
-						printf("%s", HN(atom->PVR));
-				} else if (!strncmp("PF", fmt, len)) {
-					printf("%s", atom->PN);
-					if (atom->PV)
-						printf("-%s", atom->PV);
-					if (atom->PR_int)
-						printf("-r%i", atom->PR_int);
-				} else if (!strncmp("PR", fmt, len)) {
-					if (showit || atom->PR_int)
-						printf("r%i", atom->PR_int);
-				} else if (!strncmp("SLOT", fmt, len)) {
-					if (showit || atom->SLOT)
-						printf("%s%s%s%s%s",
-								atom->SLOT ? ":" : "<unset>",
-								atom->SLOT ? atom->SLOT : "",
-								atom->SUBSLOT ? "/" : "",
-								atom->SUBSLOT ? atom->SUBSLOT : "",
-								atom_slotdep_str[atom->slotdep]);
-				} else if (!strncmp("REPO", fmt, len)) {
-					if (showit || atom->REPO)
-						printf("::%s", HN(atom->REPO));
-				} else if (!strncmp("pfx", fmt, len)) {
-					if (showit || atom->pfx_op != ATOM_OP_NONE)
-						printf("%s", atom->pfx_op == ATOM_OP_NONE ?
-								"<unset>" : atom_op_str[atom->pfx_op]);
-				} else if (!strncmp("sfx", fmt, len)) {
-					if (showit || atom->sfx_op != ATOM_OP_NONE)
-						printf("%s", atom->sfx_op == ATOM_OP_NONE ?
-								"<unset>" : atom_op_str[atom->sfx_op]);
-				} else
-					printf("<BAD:%.*s>", (int)len, fmt);
-				++p;
-#undef HN
-			} else
-				p = fmt + 1;
-		} else
-			++p;
-	}
-}
-
 int qatom_main(int argc, char **argv)
 {
 	enum qatom_atom { _EXPLODE=0, _COMPARE, _PRINT } action = _EXPLODE;
@@ -168,8 +77,7 @@ int qatom_main(int argc, char **argv)
 			atom_implode(atomc);
 			break;
 		case _EXPLODE:
-			qatom_printf(format, atom, verbose);
-			putchar('\n');
+			printf("%s\n", atom_format(format, atom, verbose));
 			break;
 		case _PRINT:
 			printf("%s\n", atom_to_string(atom));


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-05-09 20:19 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-05-09 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     7cf702111a7350b17443f4d9d0d76138b503dac3
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu May  9 20:17:46 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu May  9 20:17:46 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7cf70211

libq/tree: merge vdb and cache

since cache was basically a shadow of vdb, and vdb grew too many
non-vdb-like behaviour, renamed to tree such that further features only
have to be implemented once

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md          |    7 +-
 libq/Makefile.am |    3 +-
 libq/Makefile.in |   31 +-
 libq/cache.c     |  687 -----------------------------------
 libq/cache.h     |   74 ----
 libq/tree.c      | 1066 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 libq/tree.h      |  141 ++++++++
 libq/vdb.c       |  515 --------------------------
 libq/vdb.h       |   96 -----
 main.c           |   20 -
 q.c              |    2 -
 qcheck.c         |   37 +-
 qdepends.c       |   22 +-
 qfile.c          |   19 +-
 qgrep.c          |   29 +-
 qkeyword.c       |   43 ++-
 qlist.c          |   35 +-
 qmerge.c         |   66 ++--
 qpkg.c           |   30 +-
 qsearch.c        |   20 +-
 qsize.c          |   13 +-
 quse.c           |   17 +-
 22 files changed, 1419 insertions(+), 1554 deletions(-)

diff --git a/TODO.md b/TODO.md
index 3333fd6..ec5f843 100644
--- a/TODO.md
+++ b/TODO.md
@@ -23,10 +23,11 @@
   we end up getting just:<br>
   `ACCEPT_LICENSE=" bar"`
 
-- vdb\_foreach\_pkg should have variant that takes an atom (or just
-  cat?) to reduce search space, same for cache\_foreach\_pkg
+- tree\_foreach\_pkg should have variant that takes an atom (or just
+  cat?) to reduce search space
 
-- vdb repo/slot think about when it is freed (see cache\_pkg\_close)
+- tree\_get\_atoms should return atoms iso string set, needs a rewrite
+  to use foreach\_pkg and get\_atom
 
 # Atoms
 

diff --git a/libq/Makefile.am b/libq/Makefile.am
index 765347f..62ffb83 100644
--- a/libq/Makefile.am
+++ b/libq/Makefile.am
@@ -3,7 +3,6 @@ QFILES = \
 	atom.c atom.h \
 	basename.c basename.h \
 	busybox.h \
-	cache.c cache.h \
 	colors.c colors.h \
 	contents.c contents.h \
 	copy_file.c copy_file.h \
@@ -19,7 +18,7 @@ QFILES = \
 	safe_io.c safe_io.h \
 	scandirat.c scandirat.h \
 	set.c set.h \
-	vdb.c vdb.h \
+	tree.c tree.h \
 	xarray.c xarray.h \
 	xasprintf.h \
 	xchdir.c xchdir.h \

diff --git a/libq/Makefile.in b/libq/Makefile.in
index 5f118fc..c359f4b 100644
--- a/libq/Makefile.in
+++ b/libq/Makefile.in
@@ -241,13 +241,13 @@ CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 libq_la_LIBADD =
-am__objects_1 = libq_la-atom.lo libq_la-basename.lo libq_la-cache.lo \
-	libq_la-colors.lo libq_la-contents.lo libq_la-copy_file.lo \
-	libq_la-dep.lo libq_la-eat_file.lo libq_la-hash_fd.lo \
+am__objects_1 = libq_la-atom.lo libq_la-basename.lo libq_la-colors.lo \
+	libq_la-contents.lo libq_la-copy_file.lo libq_la-dep.lo \
+	libq_la-eat_file.lo libq_la-hash_fd.lo \
 	libq_la-human_readable.lo libq_la-md5_sha1_sum.lo \
 	libq_la-prelink.lo libq_la-profile.lo libq_la-rmspace.lo \
 	libq_la-safe_io.lo libq_la-scandirat.lo libq_la-set.lo \
-	libq_la-vdb.lo libq_la-xarray.lo libq_la-xchdir.lo \
+	libq_la-tree.lo libq_la-xarray.lo libq_la-xchdir.lo \
 	libq_la-xmkdir.lo libq_la-xpak.lo libq_la-xregex.lo \
 	libq_la-xsystem.lo
 am_libq_la_OBJECTS = $(am__objects_1)
@@ -1447,7 +1447,6 @@ QFILES = \
 	atom.c atom.h \
 	basename.c basename.h \
 	busybox.h \
-	cache.c cache.h \
 	colors.c colors.h \
 	contents.c contents.h \
 	copy_file.c copy_file.h \
@@ -1463,7 +1462,7 @@ QFILES = \
 	safe_io.c safe_io.h \
 	scandirat.c scandirat.h \
 	set.c set.h \
-	vdb.c vdb.h \
+	tree.c tree.h \
 	xarray.c xarray.h \
 	xasprintf.h \
 	xchdir.c xchdir.h \
@@ -1535,7 +1534,6 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-atom.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-basename.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-cache.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-colors.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-contents.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-copy_file.Plo@am__quote@
@@ -1550,7 +1548,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-safe_io.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-scandirat.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-set.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-vdb.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-tree.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-xarray.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-xchdir.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-xmkdir.Plo@am__quote@
@@ -1593,13 +1591,6 @@ libq_la-basename.lo: basename.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-basename.lo `test -f 'basename.c' || echo '$(srcdir)/'`basename.c
 
-libq_la-cache.lo: cache.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-cache.lo -MD -MP -MF $(DEPDIR)/libq_la-cache.Tpo -c -o libq_la-cache.lo `test -f 'cache.c' || echo '$(srcdir)/'`cache.c
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-cache.Tpo $(DEPDIR)/libq_la-cache.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='cache.c' object='libq_la-cache.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-cache.lo `test -f 'cache.c' || echo '$(srcdir)/'`cache.c
-
 libq_la-colors.lo: colors.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-colors.lo -MD -MP -MF $(DEPDIR)/libq_la-colors.Tpo -c -o libq_la-colors.lo `test -f 'colors.c' || echo '$(srcdir)/'`colors.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-colors.Tpo $(DEPDIR)/libq_la-colors.Plo
@@ -1698,12 +1689,12 @@ libq_la-set.lo: set.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-set.lo `test -f 'set.c' || echo '$(srcdir)/'`set.c
 
-libq_la-vdb.lo: vdb.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-vdb.lo -MD -MP -MF $(DEPDIR)/libq_la-vdb.Tpo -c -o libq_la-vdb.lo `test -f 'vdb.c' || echo '$(srcdir)/'`vdb.c
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-vdb.Tpo $(DEPDIR)/libq_la-vdb.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vdb.c' object='libq_la-vdb.lo' libtool=yes @AMDEPBACKSLASH@
+libq_la-tree.lo: tree.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-tree.lo -MD -MP -MF $(DEPDIR)/libq_la-tree.Tpo -c -o libq_la-tree.lo `test -f 'tree.c' || echo '$(srcdir)/'`tree.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libq_la-tree.Tpo $(DEPDIR)/libq_la-tree.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='tree.c' object='libq_la-tree.lo' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-vdb.lo `test -f 'vdb.c' || echo '$(srcdir)/'`vdb.c
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libq_la-tree.lo `test -f 'tree.c' || echo '$(srcdir)/'`tree.c
 
 libq_la-xarray.lo: xarray.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libq_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libq_la-xarray.lo -MD -MP -MF $(DEPDIR)/libq_la-xarray.Tpo -c -o libq_la-xarray.lo `test -f 'xarray.c' || echo '$(srcdir)/'`xarray.c

diff --git a/libq/cache.c b/libq/cache.c
deleted file mode 100644
index 304cd34..0000000
--- a/libq/cache.c
+++ /dev/null
@@ -1,687 +0,0 @@
-/*
- * Copyright 2005-2019 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- *
- * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
- * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
- * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
- */
-
-#include "main.h"
-
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#include <xalloc.h>
-
-#include "cache.h"
-#include "eat_file.h"
-#include "rmspace.h"
-#include "scandirat.h"
-#include "vdb.h"
-
-#ifdef EBUG
-static void
-cache_dump(cache_pkg_meta *cache)
-{
-	if (!cache)
-		errf("Cache is empty !");
-
-	printf("DEPEND     : %s\n", cache->DEPEND);
-	printf("RDEPEND    : %s\n", cache->RDEPEND);
-	printf("SLOT       : %s\n", cache->SLOT);
-	printf("SRC_URI    : %s\n", cache->SRC_URI);
-	printf("RESTRICT   : %s\n", cache->RESTRICT);
-	printf("HOMEPAGE   : %s\n", cache->HOMEPAGE);
-	printf("LICENSE    : %s\n", cache->LICENSE);
-	printf("DESCRIPTION: %s\n", cache->DESCRIPTION);
-	printf("KEYWORDS   : %s\n", cache->KEYWORDS);
-	printf("INHERITED  : %s\n", cache->INHERITED);
-	printf("IUSE       : %s\n", cache->IUSE);
-	printf("CDEPEND    : %s\n", cache->CDEPEND);
-	printf("PDEPEND    : %s\n", cache->PDEPEND);
-	printf("PROVIDE    : %s\n", cache->PROVIDE);
-	printf("EAPI       : %s\n", cache->EAPI);
-	printf("PROPERTIES : %s\n", cache->PROPERTIES);
-}
-#endif
-
-static const char portcachedir_pms[] = "metadata/cache";
-static const char portcachedir_md5[] = "metadata/md5-cache";
-static const char portrepo_name[]    = "profiles/repo_name";
-cache_ctx *
-cache_open(const char *sroot, const char *portdir)
-{
-	cache_ctx *ret;
-	char buf[_Q_PATH_MAX];
-	char *repo = NULL;
-	size_t repolen = 0;
-
-	snprintf(buf, sizeof(buf), "%s%s/%s", sroot, portdir, portrepo_name);
-	if (eat_file(buf, &repo, &repolen)) {
-		(void)rmspace(repo);
-	} else {
-		repo = NULL;  /* ignore missing repo file */
-	}
-
-	snprintf(buf, sizeof(buf), "%s/%s", portdir, portcachedir_md5);
-	ret = vdb_open2(sroot, buf, true);
-	if (ret != NULL) {
-		ret->cachetype = CACHE_METADATA_MD5;
-		ret->repo = repo;
-		return ret;
-	}
-
-	snprintf(buf, sizeof(buf), "%s/%s", portdir, portcachedir_pms);
-	ret = vdb_open2(sroot, buf, true);
-	if (ret != NULL) {
-		ret->cachetype = CACHE_METADATA_PMS;
-		ret->repo = repo;
-		return ret;
-	}
-
-	ret = vdb_open2(sroot, portdir, true);
-	if (ret != NULL) {
-		ret->cachetype = CACHE_EBUILD;
-		ret->repo = repo;
-		return ret;
-	}
-
-	cache_close(ret);
-	warnf("could not open repository at %s (under root %s)", portdir, sroot);
-
-	return NULL;
-}
-
-void
-cache_close(cache_ctx *ctx)
-{
-	if (ctx->repo != NULL)
-		free(ctx->repo);
-	if (ctx->ebuilddir_ctx != NULL)
-		free(ctx->ebuilddir_ctx);
-	vdb_close(ctx);
-}
-
-cache_cat_ctx *
-cache_open_cat(cache_ctx *ctx, const char *name)
-{
-	return vdb_open_cat(ctx, name);
-}
-
-cache_cat_ctx *
-cache_next_cat(cache_ctx *ctx)
-{
-	return vdb_next_cat(ctx);
-}
-
-void
-cache_close_cat(cache_cat_ctx *cat_ctx)
-{
-	return vdb_close_cat(cat_ctx);
-}
-
-cache_pkg_ctx *
-cache_open_pkg(cache_cat_ctx *cat_ctx, const char *name)
-{
-	return vdb_open_pkg(cat_ctx, name);
-}
-
-cache_pkg_ctx *
-cache_next_pkg(cache_cat_ctx *cat_ctx)
-{
-	cache_ctx *ctx = (cache_ctx *)cat_ctx->ctx;
-	cache_pkg_ctx *ret = NULL;
-
-	if (ctx->cachetype == CACHE_EBUILD) {
-		char *p;
-
-		/* serve *.ebuild files each as separate pkg_ctx with name set
-		 * to CAT/P like in VDB and metadata */
-		do {
-			if (ctx->ebuilddir_pkg_ctx == NULL) {
-				vdb_ctx *pkgdir = ctx->ebuilddir_ctx;
-
-				if (pkgdir == NULL)
-					pkgdir = ctx->ebuilddir_ctx = xmalloc(sizeof(vdb_ctx));
-				memset(ctx->ebuilddir_ctx, '\0', sizeof(*ctx->ebuilddir_ctx));
-
-				if ((ctx->ebuilddir_pkg_ctx = vdb_next_pkg(cat_ctx)) == NULL)
-					return NULL;
-
-				pkgdir->portroot_fd = -1;
-				pkgdir->vdb_fd = cat_ctx->fd;
-				pkgdir->do_sort = ctx->do_sort;
-				pkgdir->catsortfunc = ctx->catsortfunc;
-				pkgdir->pkgsortfunc = ctx->pkgsortfunc;
-				pkgdir->repo = ctx->repo;
-				pkgdir->cachetype = ctx->cachetype;
-
-				ctx->ebuilddir_cat_ctx =
-					vdb_open_cat(pkgdir, ctx->ebuilddir_pkg_ctx->name);
-
-				/* opening might fail if what we found wasn't a
-				 * directory or something */
-				if (ctx->ebuilddir_cat_ctx == NULL) {
-					ctx->ebuilddir_pkg_ctx = NULL;
-					return NULL;
-				}
-
-				/* "zap" the pkg such that it looks like CAT/P */
-				ctx->ebuilddir_cat_ctx->name = cat_ctx->name;
-			}
-
-			ret = vdb_next_pkg(ctx->ebuilddir_cat_ctx);
-			if (ret == NULL) {
-				vdb_close_cat(ctx->ebuilddir_cat_ctx);
-				ctx->ebuilddir_pkg_ctx = NULL;
-			} else {
-				if ((p = strstr(ret->name, ".ebuild")) == NULL) {
-					cache_close_pkg(ret);
-					ret = NULL;
-				} else {
-					*p = '\0';
-				}
-			}
-		} while (ret == NULL);
-	} else {
-		ret = vdb_next_pkg(cat_ctx);
-	}
-
-	return ret;
-}
-
-static cache_pkg_meta *
-cache_read_file_pms(cache_pkg_ctx *pkg_ctx)
-{
-	struct stat s;
-	char *ptr;
-	FILE *f;
-	cache_pkg_meta *ret = NULL;
-	size_t len;
-	char buf[_Q_PATH_MAX];
-
-	if ((f = fdopen(pkg_ctx->fd, "r")) == NULL)
-		goto err;
-
-	if (fstat(pkg_ctx->fd, &s) != 0)
-		goto err;
-
-	len = sizeof(*ret) + s.st_size + 1;
-	ret = xzalloc(len);
-	ptr = (char*)ret;
-	ret->_data = ptr + sizeof(*ret);
-	if ((off_t)fread(ret->_data, 1, s.st_size, f) != s.st_size)
-		goto err;
-
-	ret->DEPEND = ret->_data;
-#define next_line(curr, next) \
-	if ((ptr = strchr(ret->curr, '\n')) == NULL) { \
-		warn("Invalid cache file for '%s'", buf); \
-		goto err; \
-	} \
-	ret->next = ptr+1; \
-	*ptr = '\0';
-	next_line(DEPEND, RDEPEND)
-	next_line(RDEPEND, SLOT)
-	next_line(SLOT, SRC_URI)
-	next_line(SRC_URI, RESTRICT)
-	next_line(RESTRICT, HOMEPAGE)
-	next_line(HOMEPAGE, LICENSE)
-	next_line(LICENSE, DESCRIPTION)
-	next_line(DESCRIPTION, KEYWORDS)
-	next_line(KEYWORDS, INHERITED)
-	next_line(INHERITED, IUSE)
-	next_line(IUSE, CDEPEND)
-	next_line(CDEPEND, PDEPEND)
-	next_line(PDEPEND, PROVIDE)
-	next_line(PROVIDE, EAPI)
-	next_line(EAPI, PROPERTIES)
-#undef next_line
-	ptr = strchr(ptr+1, '\n');
-	if (ptr == NULL) {
-		warn("Invalid cache file for '%s' - could not find end of cache data",
-				buf);
-		goto err;
-	}
-	*ptr = '\0';
-
-	fclose(f);
-	pkg_ctx->fd = -1;
-
-	return ret;
-
-err:
-	if (f)
-		fclose(f);
-	pkg_ctx->fd = -1;
-	if (ret)
-		cache_close_meta(ret);
-	return NULL;
-}
-
-static cache_pkg_meta *
-cache_read_file_md5(cache_pkg_ctx *pkg_ctx)
-{
-	struct stat s;
-	char *ptr, *endptr;
-	FILE *f;
-	cache_pkg_meta *ret = NULL;
-	size_t len;
-
-	if ((f = fdopen(pkg_ctx->fd, "r")) == NULL)
-		goto err;
-
-	if (fstat(pkg_ctx->fd, &s) != 0)
-		goto err;
-
-	len = sizeof(*ret) + s.st_size + 1;
-	ret = xzalloc(len);
-	ptr = (char*)ret;
-	ret->_data = ptr + sizeof(*ret);
-	if ((off_t)fread(ret->_data, 1, s.st_size, f) != s.st_size)
-		goto err;
-
-	/* We have a block of key=value\n data.
-	 * KEY=VALUE\n
-	 * Where KEY does NOT contain:
-	 * \0 \n =
-	 * And VALUE does NOT contain:
-	 * \0 \n
-	 * */
-#define assign_var_cmp(keyname, cmpkey) \
-	if (strncmp(keyptr, cmpkey, strlen(cmpkey)) == 0) { \
-		ret->keyname = valptr; \
-		continue; \
-	}
-#define assign_var(keyname) \
-	assign_var_cmp(keyname, #keyname);
-
-	ptr = ret->_data;
-	endptr = strchr(ptr, '\0');
-	if (endptr == NULL) {
-			warn("Invalid cache file for '%s/%s': "
-					"could not find end of cache data",
-					pkg_ctx->cat_ctx->name, pkg_ctx->name);
-			goto err;
-	}
-
-	while (ptr != NULL && ptr != endptr) {
-		char *keyptr;
-		char *valptr;
-		keyptr = ptr;
-		valptr = strchr(ptr, '=');
-		if (valptr == NULL) {
-			warn("Invalid cache file for '%s/%s': missing val",
-					pkg_ctx->cat_ctx->name, pkg_ctx->name);
-			goto err;
-		}
-		*valptr = '\0';
-		valptr++;
-		ptr = strchr(valptr, '\n');
-		if (ptr == NULL) {
-			warn("Invalid cache file for '%s/%s': missing key",
-					pkg_ctx->cat_ctx->name, pkg_ctx->name);
-			goto err;
-		}
-		*ptr = '\0';
-		ptr++;
-
-		assign_var(CDEPEND);
-		assign_var(DEPEND);
-		assign_var(DESCRIPTION);
-		assign_var(EAPI);
-		assign_var(HOMEPAGE);
-		assign_var(INHERITED);
-		assign_var(IUSE);
-		assign_var(KEYWORDS);
-		assign_var(LICENSE);
-		assign_var(PDEPEND);
-		assign_var(PROPERTIES);
-		assign_var(PROVIDE);
-		assign_var(RDEPEND);
-		assign_var(RESTRICT);
-		assign_var(SLOT);
-		assign_var(SRC_URI);
-		assign_var(DEFINED_PHASES);
-		assign_var(REQUIRED_USE);
-		assign_var(BDEPEND);
-		assign_var(_eclasses_);
-		assign_var(_md5_);
-		warn("Cache file for '%s/%s' has unknown key %s",
-				pkg_ctx->cat_ctx->name, pkg_ctx->name, keyptr);
-	}
-#undef assign_var
-#undef assign_var_cmp
-
-	fclose(f);
-	pkg_ctx->fd = -1;
-
-	return ret;
-
-err:
-	if (f)
-		fclose(f);
-	pkg_ctx->fd = -1;
-	if (ret)
-		cache_close_meta(ret);
-	return NULL;
-}
-
-static cache_pkg_meta *
-cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx)
-{
-	FILE *f;
-	struct stat s;
-	cache_pkg_meta *ret = NULL;
-	size_t len;
-	char *p;
-	char *q;
-	char *w;
-	char **key;
-	bool esc;
-	bool findnl;
-
-	if ((f = fdopen(pkg_ctx->fd, "r")) == NULL)
-		goto err;
-
-	if (fstat(pkg_ctx->fd, &s) != 0)
-		goto err;
-
-	len = sizeof(*ret) + s.st_size + 1;
-	ret = xzalloc(len);
-	p = (char *)ret;
-	ret->_data = p + sizeof(*ret);
-	if ((off_t)fread(ret->_data, 1, s.st_size, f) != s.st_size)
-		goto err;
-
-	p = ret->_data;
-	do {
-		q = p;
-		while (*p >= 'A' && *p <= 'Z')
-			p++;
-
-		key = NULL;
-		if (q < p && *p == '=') {
-			*p++ = '\0';
-			/* match variable against which ones we look for */
-#define match_key(X) else if (strcmp(q, #X) == 0) key = &ret->X
-			if (1 == 0); /* dummy for syntax */
-			match_key(DEPEND);
-			match_key(RDEPEND);
-			match_key(SLOT);
-			match_key(SRC_URI);
-			match_key(RESTRICT);
-			match_key(HOMEPAGE);
-			match_key(LICENSE);
-			match_key(DESCRIPTION);
-			match_key(KEYWORDS);
-			match_key(IUSE);
-			match_key(CDEPEND);
-			match_key(PDEPEND);
-			match_key(EAPI);
-			match_key(REQUIRED_USE);
-#undef match_key
-		}
-
-		findnl = true;
-		if (key != NULL) {
-			q = p;
-			if (*q == '"' || *q == '\'') {
-				/* find matching quote */
-				p++;
-				w = p;
-				esc = false;
-				do {
-					while (*p != '\0' && *p != *q) {
-						if (*p == '\\') {
-							esc = !esc;
-							if (esc) {
-								p++;
-								continue;
-							}
-						} else {
-							/* implement line continuation (\ before newline) */
-							if (esc && (*p == '\n' || *p == '\r'))
-								*p = ' ';
-							esc = false;
-						}
-
-						*w++ = *p++;
-					}
-					if (*p == *q && esc) {
-						/* escaped, move along */
-						esc = false;
-						*w++ = *p++;
-						continue;
-					}
-					break;
-				} while (1);
-				q++;
-				*w = '\0';
-			} else {
-				/* find first whitespace */
-				while (!isspace((int)*p))
-					p++;
-				if (*p == '\n')
-					findnl = false;
-			}
-			*p++ = '\0';
-			*key = q;
-		}
-
-		if (findnl && (p = strchr(p, '\n')) != NULL)
-			p++;
-	} while (p != NULL);
-
-	fclose(f);
-	pkg_ctx->fd = -1;
-
-	return ret;
-
-err:
-	if (f)
-		fclose(f);
-	pkg_ctx->fd = -1;
-	if (ret)
-		cache_close_meta(ret);
-	return NULL;
-}
-
-cache_pkg_meta *
-cache_pkg_read(cache_pkg_ctx *pkg_ctx)
-{
-	cache_ctx *ctx = (cache_ctx *)(pkg_ctx->cat_ctx->ctx);
-
-	if (pkg_ctx->fd == -1) {
-		if (ctx->cachetype != CACHE_EBUILD) {
-			pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name,
-					O_RDONLY|O_CLOEXEC);
-		} else {
-			char *p = (char *)pkg_ctx->name;
-			p += strlen(p);
-			*p = '.';
-			pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name,
-					O_RDONLY|O_CLOEXEC);
-			*p = '\0';
-		}
-		if (pkg_ctx->fd == -1)
-			return NULL;
-	}
-
-	if (ctx->cachetype == CACHE_METADATA_MD5) {
-		return cache_read_file_md5(pkg_ctx);
-	} else if (ctx->cachetype == CACHE_METADATA_PMS) {
-		return cache_read_file_pms(pkg_ctx);
-	} else if (ctx->cachetype == CACHE_EBUILD) {
-		return cache_read_file_ebuild(pkg_ctx);
-	}
-
-	warn("Unknown metadata cache type!");
-	return NULL;
-}
-
-void
-cache_close_meta(cache_pkg_meta *cache)
-{
-	if (!cache)
-		errf("Cache is empty !");
-	free(cache);
-}
-
-cache_metadata_xml *
-cache_read_metadata(cache_pkg_ctx *pkg_ctx)
-{
-	cache_ctx *ctx = (cache_ctx *)(pkg_ctx->cat_ctx->ctx);
-	int fd;
-	FILE *f;
-	struct stat s;
-	char *xbuf;
-	char *p;
-	char *q;
-	size_t len;
-	cache_metadata_xml *ret = NULL;
-	struct elist *emailw = NULL;
-	char buf[_Q_PATH_MAX];
-
-	/* lame @$$ XML parsing, I don't want to pull in a real parser
-	 * library because we only retrieve one element for now: email
-	 * technically speaking, email may occur only once in a maintainer
-	 * tag, but practically speaking we don't care at all, so we can
-	 * just extract everything between <email> and </email> */
-
-	if (ctx->cachetype == CACHE_EBUILD) {
-		fd = openat(pkg_ctx->cat_ctx->fd, "metadata", O_RDONLY | O_CLOEXEC);
-	} else {
-		depend_atom *atom;
-		snprintf(buf, sizeof(buf), "%s/%s",
-				pkg_ctx->cat_ctx->name, pkg_ctx->name);
-		atom = atom_explode(buf);
-		snprintf(buf, sizeof(buf), "../../%s/%s/metadata.xml",
-				atom->CATEGORY, atom->PN);
-		atom_implode(atom);
-		fd = openat(ctx->vdb_fd, buf, O_RDONLY | O_CLOEXEC);
-	}
-
-	if (fd == -1)
-		return NULL;
-
-	if ((f = fdopen(fd, "r")) == NULL) {
-		close(fd);
-		return NULL;
-	}
-
-	if (fstat(fd, &s) != 0) {
-		fclose(f);
-		return NULL;
-	}
-
-	len = sizeof(*ret) + s.st_size + 1;
-	p = xbuf = xzalloc(len);
-	if ((off_t)fread(p, 1, s.st_size, f) != s.st_size) {
-		free(p);
-		fclose(f);
-		pkg_ctx->fd = -1;
-		return NULL;
-	}
-
-	ret = xmalloc(sizeof(*ret));
-	ret->email = NULL;
-
-	while ((q = strstr(p, "<email>")) != NULL) {
-		p = q + sizeof("<email>") - 1;
-		if ((q = strstr(p, "</email>")) == NULL)
-			break;
-		*q = '\0';
-		rmspace(p);
-		if (emailw == NULL) {
-			emailw = ret->email = xmalloc(sizeof(*emailw));
-		} else {
-			emailw = emailw->next = xmalloc(sizeof(*emailw));
-		}
-		emailw->next = NULL;
-		emailw->addr = xstrdup(p);
-		p = q + 1;
-	}
-
-	free(xbuf);
-	fclose(f);
-	return ret;
-}
-
-void
-cache_close_metadata(cache_metadata_xml *meta_ctx)
-{
-	struct elist *e;
-	while (meta_ctx->email != NULL) {
-		e = meta_ctx->email;
-		free(e->addr);
-		e = e->next;
-		free(meta_ctx->email);
-		meta_ctx->email = e;
-	}
-	free(meta_ctx);
-}
-
-void
-cache_close_pkg(cache_pkg_ctx *pkg_ctx)
-{
-	/* avoid free of cache_ctx' repo by vdb_close_pkg */
-	if (pkg_ctx->cat_ctx->ctx->repo == pkg_ctx->repo)
-		pkg_ctx->repo = NULL;
-
-	vdb_close_pkg(pkg_ctx);
-}
-
-static int
-cache_foreach_pkg_int(const char *sroot, const char *portdir,
-		vdb_pkg_cb callback, void *priv, vdb_cat_filter filter,
-		bool sort, void *catsortfunc, void *pkgsortfunc)
-{
-	cache_ctx *ctx;
-	cache_cat_ctx *cat_ctx;
-	cache_pkg_ctx *pkg_ctx;
-	int ret;
-
-	ctx = cache_open(sroot, portdir);
-	if (!ctx)
-		return EXIT_FAILURE;
-
-	ctx->do_sort = sort;
-	if (catsortfunc != NULL)
-		ctx->catsortfunc = catsortfunc;
-	if (pkgsortfunc != NULL)
-		ctx->pkgsortfunc = pkgsortfunc;
-
-	ret = 0;
-	while ((cat_ctx = cache_next_cat(ctx))) {
-		if (filter && !filter(cat_ctx, priv))
-			continue;
-		while ((pkg_ctx = cache_next_pkg(cat_ctx))) {
-			ret |= callback(pkg_ctx, priv);
-			cache_close_pkg(pkg_ctx);
-		}
-		cache_close_cat(cat_ctx);
-	}
-	cache_close(ctx);
-
-	return ret;
-}
-
-int
-cache_foreach_pkg(const char *sroot, const char *portdir,
-		vdb_pkg_cb callback, void *priv, vdb_cat_filter filter)
-{
-	return cache_foreach_pkg_int(sroot, portdir, callback, priv,
-			filter, false, NULL, NULL);
-}
-
-int
-cache_foreach_pkg_sorted(const char *sroot, const char *portdir,
-		vdb_pkg_cb callback, void *priv,
-		void *catsortfunc, void *pkgsortfunc)
-{
-	return cache_foreach_pkg_int(sroot, portdir, callback, priv,
-			NULL, true, catsortfunc, pkgsortfunc);
-}

diff --git a/libq/cache.h b/libq/cache.h
deleted file mode 100644
index e863daf..0000000
--- a/libq/cache.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2005-2019 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- *
- * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
- * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
- * Copyright 2019-     Fabian Groffen  - <grobian@gentoo.org>
- */
-
-#ifndef _CACHE_H
-#define _CACHE_H 1
-
-#include "atom.h"
-#include "vdb.h"
-
-#define cache_ctx     vdb_ctx
-#define cache_cat_ctx vdb_cat_ctx
-#define cache_pkg_ctx vdb_pkg_ctx
-
-typedef struct {
-	char *_data;
-	char *DEPEND;        /* line 1 */
-	char *RDEPEND;
-	char *SLOT;
-	char *SRC_URI;
-	char *RESTRICT;      /* line 5 */
-	char *HOMEPAGE;
-	char *LICENSE;
-	char *DESCRIPTION;
-	char *KEYWORDS;
-	char *INHERITED;     /* line 10 */
-	char *IUSE;
-	char *CDEPEND;
-	char *PDEPEND;
-	char *PROVIDE;       /* line 14 */
-	char *EAPI;
-	char *PROPERTIES;
-	/* These are MD5-Cache only */
-	char *DEFINED_PHASES;
-	char *REQUIRED_USE;
-	char *BDEPEND;
-	char *_eclasses_;
-	char *_md5_;
-} cache_pkg_meta;
-
-typedef struct {
-	struct elist {
-		char *addr;
-		struct elist *next;
-	} *email;
-} cache_metadata_xml;
-
-typedef int (cache_pkg_cb)(cache_pkg_ctx *, void *priv);
-typedef int (cache_cat_filter)(cache_cat_ctx *, void *priv);
-
-cache_ctx *cache_open(const char *sroot, const char *portdir);
-void cache_close(cache_ctx *ctx);
-cache_cat_ctx *cache_open_cat(cache_ctx *ctx, const char *name);
-cache_cat_ctx *cache_next_cat(cache_ctx *ctx);
-void cache_close_cat(cache_cat_ctx *cat_ctx);
-cache_pkg_ctx *cache_open_pkg(cache_cat_ctx *cat_ctx, const char *name);
-cache_pkg_ctx *cache_next_pkg(cache_cat_ctx *cat_ctx);
-cache_pkg_meta *cache_pkg_read(cache_pkg_ctx *pkg_ctx);
-void cache_close_meta(cache_pkg_meta *cache);
-cache_metadata_xml *cache_read_metadata(cache_pkg_ctx *pkg_ctx);
-void cache_close_metadata(cache_metadata_xml *meta_ctx);
-void cache_close_pkg(cache_pkg_ctx *pkg_ctx);
-int cache_foreach_pkg(const char *sroot, const char *portdir,
-		cache_pkg_cb callback, void *priv, cache_cat_filter filter);
-int cache_foreach_pkg_sorted(const char *sroot, const char *portdir,
-		cache_pkg_cb callback, void *priv,
-		void *catsortfunc, void *pkgsortfunc);
-
-#endif

diff --git a/libq/tree.c b/libq/tree.c
new file mode 100644
index 0000000..bb7eefa
--- /dev/null
+++ b/libq/tree.c
@@ -0,0 +1,1066 @@
+/*
+ * Copyright 2005-2019 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ *
+ * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
+ * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
+ * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
+ */
+
+#include "main.h"
+
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ctype.h>
+#include <xalloc.h>
+
+#include "atom.h"
+#include "eat_file.h"
+#include "rmspace.h"
+#include "scandirat.h"
+#include "set.h"
+#include "tree.h"
+
+#include <ctype.h>
+#include <xalloc.h>
+
+static tree_ctx *
+tree_open_int(const char *sroot, const char *tdir, bool quiet)
+{
+	tree_ctx *ctx = xmalloc(sizeof(*ctx));
+
+	ctx->portroot_fd = open(sroot, O_RDONLY | O_CLOEXEC | O_PATH);
+	if (ctx->portroot_fd == -1) {
+		if (!quiet)
+			warnp("could not open root: %s", sroot);
+		goto f_error;
+	}
+
+	/* Skip the leading slash */
+	tdir++;
+	if (*tdir == '\0')
+		tdir = ".";
+	/* Cannot use O_PATH as we want to use fdopendir() */
+	ctx->tree_fd = openat(ctx->portroot_fd, tdir, O_RDONLY | O_CLOEXEC);
+	if (ctx->tree_fd == -1) {
+		if (!quiet)
+			warnp("could not open tree: %s (in root %s)", tdir, sroot);
+		goto cp_error;
+	}
+
+	ctx->dir = fdopendir(ctx->tree_fd);
+	if (ctx->dir == NULL)
+		goto cv_error;
+
+	ctx->do_sort = false;
+	ctx->cat_de = NULL;
+	ctx->catsortfunc = alphasort;
+	ctx->pkgsortfunc = alphasort;
+	ctx->repo = NULL;
+	ctx->ebuilddir_ctx = NULL;
+	ctx->ebuilddir_pkg_ctx = NULL;
+	return ctx;
+
+ cv_error:
+	close(ctx->tree_fd);
+ cp_error:
+	close(ctx->portroot_fd);
+ f_error:
+	free(ctx);
+	return NULL;
+}
+
+static const char portcachedir_pms[] = "metadata/cache";
+static const char portcachedir_md5[] = "metadata/md5-cache";
+static const char portrepo_name[]    = "profiles/repo_name";
+tree_ctx *
+tree_open(const char *sroot, const char *portdir)
+{
+	tree_ctx *ret;
+	char buf[_Q_PATH_MAX];
+	char *repo = NULL;
+	size_t repolen = 0;
+
+	snprintf(buf, sizeof(buf), "%s%s/%s", sroot, portdir, portrepo_name);
+	if (eat_file(buf, &repo, &repolen)) {
+		(void)rmspace(repo);
+	} else {
+		repo = NULL;  /* ignore missing repo file */
+	}
+
+	snprintf(buf, sizeof(buf), "%s/%s", portdir, portcachedir_md5);
+	ret = tree_open_int(sroot, buf, true);
+	if (ret != NULL) {
+		ret->cachetype = CACHE_METADATA_MD5;
+		ret->repo = repo;
+		return ret;
+	}
+
+	snprintf(buf, sizeof(buf), "%s/%s", portdir, portcachedir_pms);
+	ret = tree_open_int(sroot, buf, true);
+	if (ret != NULL) {
+		ret->cachetype = CACHE_METADATA_PMS;
+		ret->repo = repo;
+		return ret;
+	}
+
+	ret = tree_open_int(sroot, portdir, true);
+	if (ret != NULL) {
+		ret->cachetype = CACHE_EBUILD;
+		ret->repo = repo;
+		return ret;
+	}
+
+	tree_close(ret);
+	warnf("could not open repository at %s (under root %s)", portdir, sroot);
+
+	return NULL;
+}
+
+tree_ctx *
+tree_open_vdb(const char *sroot, const char *svdb)
+{
+	tree_ctx *ret = tree_open_int(sroot, svdb, false);
+	if (ret != NULL)
+		ret->cachetype = CACHE_VDB;
+	return ret;
+}
+
+void
+tree_close(tree_ctx *ctx)
+{
+	closedir(ctx->dir);
+	/* closedir() above does this for us: */
+	/* close(ctx->tree_fd); */
+	close(ctx->portroot_fd);
+	if (ctx->do_sort)
+		scandir_free(ctx->cat_de, ctx->cat_cnt);
+	if (ctx->repo != NULL)
+		free(ctx->repo);
+	if (ctx->ebuilddir_ctx != NULL)
+		free(ctx->ebuilddir_ctx);
+	free(ctx);
+}
+
+int
+tree_filter_cat(const struct dirent *de)
+{
+	int i;
+	bool founddash;
+
+#ifdef DT_UNKNOWN
+	/* cat must be a dir */
+	if (de->d_type != DT_UNKNOWN &&
+	    de->d_type != DT_DIR &&
+	    de->d_type != DT_LNK)
+		return 0;
+#endif
+
+	/* PMS 3.1.1 */
+	founddash = false;
+	for (i = 0; de->d_name[i] != '\0'; i++) {
+		switch (de->d_name[i]) {
+			case '_':
+				break;
+			case '-':
+				founddash = true;
+				/* fall through */
+			case '+':
+			case '.':
+				if (i)
+					break;
+				return 0;
+			default:
+				if ((de->d_name[i] >= 'A' && de->d_name[i] <= 'Z') ||
+						(de->d_name[i] >= 'a' && de->d_name[i] <= 'z') ||
+						(de->d_name[i] >= '0' && de->d_name[i] <= '9'))
+					break;
+				return 0;
+		}
+	}
+	if (!founddash && strcmp(de->d_name, "virtual") != 0)
+		return 0;
+
+	return i;
+}
+
+tree_cat_ctx *
+tree_open_cat(tree_ctx *ctx, const char *name)
+{
+	tree_cat_ctx *cat_ctx;
+	int fd;
+	DIR *dir;
+
+	/* Cannot use O_PATH as we want to use fdopendir() */
+	fd = openat(ctx->tree_fd, name, O_RDONLY | O_CLOEXEC);
+	if (fd == -1)
+		return NULL;
+
+	dir = fdopendir(fd);
+	if (!dir) {
+		close(fd);
+		return NULL;
+	}
+
+	cat_ctx = xmalloc(sizeof(*cat_ctx));
+	cat_ctx->name = name;
+	cat_ctx->fd = fd;
+	cat_ctx->dir = dir;
+	cat_ctx->ctx = ctx;
+	cat_ctx->pkg_de = NULL;
+	return cat_ctx;
+}
+
+tree_cat_ctx *
+tree_next_cat(tree_ctx *ctx)
+{
+	/* search for a category directory */
+	tree_cat_ctx *cat_ctx = NULL;
+
+	if (ctx->do_sort) {
+		if (ctx->cat_de == NULL) {
+			ctx->cat_cnt = scandirat(ctx->tree_fd,
+					".", &ctx->cat_de, tree_filter_cat, ctx->catsortfunc);
+			ctx->cat_cur = 0;
+		}
+
+		while (ctx->cat_cur < ctx->cat_cnt) {
+			cat_ctx = tree_open_cat(ctx, ctx->cat_de[ctx->cat_cur++]->d_name);
+			if (!cat_ctx)
+				continue;
+			break;
+		}
+	} else {
+		/* cheaper "streaming" variant */
+		const struct dirent *de;
+		do {
+			de = readdir(ctx->dir);
+			if (!de)
+				break;
+
+			if (tree_filter_cat(de) == 0)
+				continue;
+
+			cat_ctx = tree_open_cat(ctx, de->d_name);
+			if (!cat_ctx)
+				continue;
+
+			break;
+		} while (1);
+	}
+
+	return cat_ctx;
+}
+
+void
+tree_close_cat(tree_cat_ctx *cat_ctx)
+{
+	closedir(cat_ctx->dir);
+	/* closedir() above does this for us: */
+	/* close(ctx->fd); */
+	if (cat_ctx->ctx->do_sort)
+		scandir_free(cat_ctx->pkg_de, cat_ctx->pkg_cnt);
+	free(cat_ctx);
+}
+
+int
+tree_filter_pkg(const struct dirent *de)
+{
+	int i;
+	bool founddash = false;
+
+	/* PMS 3.1.2 */
+	for (i = 0; de->d_name[i] != '\0'; i++) {
+		switch (de->d_name[i]) {
+			case '_':
+				break;
+			case '-':
+				founddash = true;
+				/* fall through */
+			case '+':
+				if (i)
+					break;
+				return 0;
+			default:
+				if ((de->d_name[i] >= 'A' && de->d_name[i] <= 'Z') ||
+						(de->d_name[i] >= 'a' && de->d_name[i] <= 'z') ||
+						(de->d_name[i] >= '0' && de->d_name[i] <= '9'))
+					break;
+				if (founddash)
+					return 1;
+				return 0;
+		}
+	}
+
+	return i;
+}
+
+tree_pkg_ctx *
+tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name)
+{
+	tree_pkg_ctx *pkg_ctx = xmalloc(sizeof(*pkg_ctx));
+	pkg_ctx->name = name;
+	pkg_ctx->slot = NULL;
+	pkg_ctx->repo = cat_ctx->ctx->repo;
+	pkg_ctx->fd = -1;
+	pkg_ctx->cat_ctx = cat_ctx;
+	pkg_ctx->atom = NULL;
+	return pkg_ctx;
+}
+
+static tree_pkg_ctx *
+tree_next_pkg_int(tree_cat_ctx *cat_ctx);
+static tree_pkg_ctx *
+tree_next_pkg_int(tree_cat_ctx *cat_ctx)
+{
+	tree_pkg_ctx *pkg_ctx = NULL;
+
+	if (cat_ctx->ctx->do_sort) {
+		if (cat_ctx->pkg_de == NULL) {
+			cat_ctx->pkg_cnt = scandirat(cat_ctx->fd, ".", &cat_ctx->pkg_de,
+					tree_filter_pkg, cat_ctx->ctx->pkgsortfunc);
+			cat_ctx->pkg_cur = 0;
+		}
+
+		while (cat_ctx->pkg_cur < cat_ctx->pkg_cnt) {
+			pkg_ctx =
+				tree_open_pkg(cat_ctx,
+						cat_ctx->pkg_de[cat_ctx->pkg_cur++]->d_name);
+			if (!pkg_ctx)
+				continue;
+			break;
+		}
+	} else {
+		const struct dirent *de;
+		do {
+			de = readdir(cat_ctx->dir);
+			if (!de)
+				break;
+
+			if (tree_filter_pkg(de) == 0)
+				continue;
+
+			pkg_ctx = tree_open_pkg(cat_ctx, de->d_name);
+			if (!pkg_ctx)
+				continue;
+
+			break;
+		} while (1);
+	}
+
+	return pkg_ctx;
+}
+
+tree_pkg_ctx *
+tree_next_pkg(tree_cat_ctx *cat_ctx)
+{
+	tree_ctx *ctx = cat_ctx->ctx;
+	tree_pkg_ctx *ret = NULL;
+
+	if (ctx->cachetype == CACHE_EBUILD) {
+		char *p;
+
+		/* serve *.ebuild files each as separate pkg_ctx with name set
+		 * to CAT/P like in VDB and metadata */
+		do {
+			if (ctx->ebuilddir_pkg_ctx == NULL) {
+				tree_ctx *pkgdir = ctx->ebuilddir_ctx;
+
+				if (pkgdir == NULL)
+					pkgdir = ctx->ebuilddir_ctx = xmalloc(sizeof(tree_ctx));
+				memset(ctx->ebuilddir_ctx, '\0', sizeof(*ctx->ebuilddir_ctx));
+
+				ctx->ebuilddir_pkg_ctx = tree_next_pkg_int(cat_ctx);
+				if (ctx->ebuilddir_pkg_ctx == NULL)
+					return NULL;
+
+				pkgdir->portroot_fd = -1;
+				pkgdir->tree_fd = cat_ctx->fd;
+				pkgdir->do_sort = ctx->do_sort;
+				pkgdir->catsortfunc = ctx->catsortfunc;
+				pkgdir->pkgsortfunc = ctx->pkgsortfunc;
+				pkgdir->repo = ctx->repo;
+				pkgdir->cachetype = ctx->cachetype;
+
+				ctx->ebuilddir_cat_ctx =
+					tree_open_cat(pkgdir, ctx->ebuilddir_pkg_ctx->name);
+
+				/* opening might fail if what we found wasn't a
+				 * directory or something */
+				if (ctx->ebuilddir_cat_ctx == NULL) {
+					ctx->ebuilddir_pkg_ctx = NULL;
+					return NULL;
+				}
+
+				/* "zap" the pkg such that it looks like CAT/P */
+				ctx->ebuilddir_cat_ctx->name = cat_ctx->name;
+			}
+
+			ret = tree_next_pkg_int(ctx->ebuilddir_cat_ctx);
+			if (ret == NULL) {
+				tree_close_cat(ctx->ebuilddir_cat_ctx);
+				ctx->ebuilddir_pkg_ctx = NULL;
+			} else {
+				if ((p = strstr(ret->name, ".ebuild")) == NULL) {
+					tree_close_pkg(ret);
+					ret = NULL;
+				} else {
+					*p = '\0';
+				}
+			}
+		} while (ret == NULL);
+	} else {
+		ret = tree_next_pkg_int(cat_ctx);
+	}
+
+	return ret;
+}
+
+int
+tree_pkg_vdb_openat(
+		tree_pkg_ctx *pkg_ctx,
+		const char *file,
+		int flags, mode_t mode)
+{
+	if (pkg_ctx->fd == -1) {
+		pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name,
+				O_RDONLY | O_CLOEXEC | O_PATH);
+		if (pkg_ctx->fd == -1)
+			return -1;
+	}
+
+	return openat(pkg_ctx->fd, file, flags | O_CLOEXEC, mode);
+}
+
+FILE *
+tree_pkg_vdb_fopenat(
+		tree_pkg_ctx *pkg_ctx,
+		const char *file,
+		int flags,
+		mode_t mode,
+		const char *fmode)
+{
+	FILE *fp;
+	int fd;
+
+	fd = tree_pkg_vdb_openat(pkg_ctx, file, flags, mode);
+	if (fd == -1)
+		return NULL;
+
+	fp = fdopen(fd, fmode);
+	if (!fp)
+		close(fd);
+
+	return fp;
+}
+
+bool
+tree_pkg_vdb_eat(
+		tree_pkg_ctx *pkg_ctx,
+		const char *file,
+		char **bufptr,
+		size_t *buflen)
+{
+	int fd = tree_pkg_vdb_openat(pkg_ctx, file, O_RDONLY, 0);
+	bool ret = eat_file_fd(fd, bufptr, buflen);
+	rmspace(*bufptr);
+	if (fd != -1)
+		close(fd);
+	return ret;
+}
+
+static tree_pkg_meta *
+tree_read_file_pms(tree_pkg_ctx *pkg_ctx)
+{
+	struct stat s;
+	char *ptr;
+	FILE *f;
+	tree_pkg_meta *ret = NULL;
+	size_t len;
+	char buf[_Q_PATH_MAX];
+
+	if ((f = fdopen(pkg_ctx->fd, "r")) == NULL)
+		goto err;
+
+	if (fstat(pkg_ctx->fd, &s) != 0)
+		goto err;
+
+	len = sizeof(*ret) + s.st_size + 1;
+	ret = xzalloc(len);
+	ptr = (char*)ret;
+	ret->_data = ptr + sizeof(*ret);
+	if ((off_t)fread(ret->_data, 1, s.st_size, f) != s.st_size)
+		goto err;
+
+	ret->DEPEND = ret->_data;
+#define next_line(curr, next) \
+	if ((ptr = strchr(ret->curr, '\n')) == NULL) { \
+		warn("Invalid cache file for '%s'", buf); \
+		goto err; \
+	} \
+	ret->next = ptr+1; \
+	*ptr = '\0';
+	next_line(DEPEND, RDEPEND)
+	next_line(RDEPEND, SLOT)
+	next_line(SLOT, SRC_URI)
+	next_line(SRC_URI, RESTRICT)
+	next_line(RESTRICT, HOMEPAGE)
+	next_line(HOMEPAGE, LICENSE)
+	next_line(LICENSE, DESCRIPTION)
+	next_line(DESCRIPTION, KEYWORDS)
+	next_line(KEYWORDS, INHERITED)
+	next_line(INHERITED, IUSE)
+	next_line(IUSE, CDEPEND)
+	next_line(CDEPEND, PDEPEND)
+	next_line(PDEPEND, PROVIDE)
+	next_line(PROVIDE, EAPI)
+	next_line(EAPI, PROPERTIES)
+#undef next_line
+	ptr = strchr(ptr+1, '\n');
+	if (ptr == NULL) {
+		warn("Invalid cache file for '%s' - could not find end of cache data",
+				buf);
+		goto err;
+	}
+	*ptr = '\0';
+
+	fclose(f);
+	pkg_ctx->fd = -1;
+
+	return ret;
+
+err:
+	if (f)
+		fclose(f);
+	pkg_ctx->fd = -1;
+	if (ret)
+		tree_close_meta(ret);
+	return NULL;
+}
+
+static tree_pkg_meta *
+tree_read_file_md5(tree_pkg_ctx *pkg_ctx)
+{
+	struct stat s;
+	char *ptr, *endptr;
+	FILE *f;
+	tree_pkg_meta *ret = NULL;
+	size_t len;
+
+	if ((f = fdopen(pkg_ctx->fd, "r")) == NULL)
+		goto err;
+
+	if (fstat(pkg_ctx->fd, &s) != 0)
+		goto err;
+
+	len = sizeof(*ret) + s.st_size + 1;
+	ret = xzalloc(len);
+	ptr = (char*)ret;
+	ret->_data = ptr + sizeof(*ret);
+	if ((off_t)fread(ret->_data, 1, s.st_size, f) != s.st_size)
+		goto err;
+
+	/* We have a block of key=value\n data.
+	 * KEY=VALUE\n
+	 * Where KEY does NOT contain:
+	 * \0 \n =
+	 * And VALUE does NOT contain:
+	 * \0 \n
+	 * */
+#define assign_var_cmp(keyname, cmpkey) \
+	if (strncmp(keyptr, cmpkey, strlen(cmpkey)) == 0) { \
+		ret->keyname = valptr; \
+		continue; \
+	}
+#define assign_var(keyname) \
+	assign_var_cmp(keyname, #keyname);
+
+	ptr = ret->_data;
+	endptr = strchr(ptr, '\0');
+	if (endptr == NULL) {
+			warn("Invalid cache file for '%s/%s': "
+					"could not find end of cache data",
+					pkg_ctx->cat_ctx->name, pkg_ctx->name);
+			goto err;
+	}
+
+	while (ptr != NULL && ptr != endptr) {
+		char *keyptr;
+		char *valptr;
+		keyptr = ptr;
+		valptr = strchr(ptr, '=');
+		if (valptr == NULL) {
+			warn("Invalid cache file for '%s/%s': missing val",
+					pkg_ctx->cat_ctx->name, pkg_ctx->name);
+			goto err;
+		}
+		*valptr = '\0';
+		valptr++;
+		ptr = strchr(valptr, '\n');
+		if (ptr == NULL) {
+			warn("Invalid cache file for '%s/%s': missing key",
+					pkg_ctx->cat_ctx->name, pkg_ctx->name);
+			goto err;
+		}
+		*ptr = '\0';
+		ptr++;
+
+		assign_var(CDEPEND);
+		assign_var(DEPEND);
+		assign_var(DESCRIPTION);
+		assign_var(EAPI);
+		assign_var(HOMEPAGE);
+		assign_var(INHERITED);
+		assign_var(IUSE);
+		assign_var(KEYWORDS);
+		assign_var(LICENSE);
+		assign_var(PDEPEND);
+		assign_var(PROPERTIES);
+		assign_var(PROVIDE);
+		assign_var(RDEPEND);
+		assign_var(RESTRICT);
+		assign_var(SLOT);
+		assign_var(SRC_URI);
+		assign_var(DEFINED_PHASES);
+		assign_var(REQUIRED_USE);
+		assign_var(BDEPEND);
+		assign_var(_eclasses_);
+		assign_var(_md5_);
+		warn("Cache file for '%s/%s' has unknown key %s",
+				pkg_ctx->cat_ctx->name, pkg_ctx->name, keyptr);
+	}
+#undef assign_var
+#undef assign_var_cmp
+
+	fclose(f);
+	pkg_ctx->fd = -1;
+
+	return ret;
+
+err:
+	if (f)
+		fclose(f);
+	pkg_ctx->fd = -1;
+	if (ret)
+		tree_close_meta(ret);
+	return NULL;
+}
+
+static tree_pkg_meta *
+tree_read_file_ebuild(tree_pkg_ctx *pkg_ctx)
+{
+	FILE *f;
+	struct stat s;
+	tree_pkg_meta *ret = NULL;
+	size_t len;
+	char *p;
+	char *q;
+	char *w;
+	char **key;
+	bool esc;
+	bool findnl;
+
+	if ((f = fdopen(pkg_ctx->fd, "r")) == NULL)
+		goto err;
+
+	if (fstat(pkg_ctx->fd, &s) != 0)
+		goto err;
+
+	len = sizeof(*ret) + s.st_size + 1;
+	ret = xzalloc(len);
+	p = (char *)ret;
+	ret->_data = p + sizeof(*ret);
+	if ((off_t)fread(ret->_data, 1, s.st_size, f) != s.st_size)
+		goto err;
+
+	p = ret->_data;
+	do {
+		q = p;
+		while (*p >= 'A' && *p <= 'Z')
+			p++;
+
+		key = NULL;
+		if (q < p && *p == '=') {
+			*p++ = '\0';
+			/* match variable against which ones we look for */
+#define match_key(X) else if (strcmp(q, #X) == 0) key = &ret->X
+			if (1 == 0); /* dummy for syntax */
+			match_key(DEPEND);
+			match_key(RDEPEND);
+			match_key(SLOT);
+			match_key(SRC_URI);
+			match_key(RESTRICT);
+			match_key(HOMEPAGE);
+			match_key(LICENSE);
+			match_key(DESCRIPTION);
+			match_key(KEYWORDS);
+			match_key(IUSE);
+			match_key(CDEPEND);
+			match_key(PDEPEND);
+			match_key(EAPI);
+			match_key(REQUIRED_USE);
+#undef match_key
+		}
+
+		findnl = true;
+		if (key != NULL) {
+			q = p;
+			if (*q == '"' || *q == '\'') {
+				/* find matching quote */
+				p++;
+				w = p;
+				esc = false;
+				do {
+					while (*p != '\0' && *p != *q) {
+						if (*p == '\\') {
+							esc = !esc;
+							if (esc) {
+								p++;
+								continue;
+							}
+						} else {
+							/* implement line continuation (\ before newline) */
+							if (esc && (*p == '\n' || *p == '\r'))
+								*p = ' ';
+							esc = false;
+						}
+
+						*w++ = *p++;
+					}
+					if (*p == *q && esc) {
+						/* escaped, move along */
+						esc = false;
+						*w++ = *p++;
+						continue;
+					}
+					break;
+				} while (1);
+				q++;
+				*w = '\0';
+			} else {
+				/* find first whitespace */
+				while (!isspace((int)*p))
+					p++;
+				if (*p == '\n')
+					findnl = false;
+			}
+			*p++ = '\0';
+			*key = q;
+		}
+
+		if (findnl && (p = strchr(p, '\n')) != NULL)
+			p++;
+	} while (p != NULL);
+
+	fclose(f);
+	pkg_ctx->fd = -1;
+
+	return ret;
+
+err:
+	if (f)
+		fclose(f);
+	pkg_ctx->fd = -1;
+	if (ret)
+		tree_close_meta(ret);
+	return NULL;
+}
+
+tree_pkg_meta *
+tree_pkg_read(tree_pkg_ctx *pkg_ctx)
+{
+	tree_ctx *ctx = pkg_ctx->cat_ctx->ctx;
+
+	if (pkg_ctx->fd == -1) {
+		if (ctx->cachetype != CACHE_EBUILD) {
+			pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name,
+					O_RDONLY | O_CLOEXEC);
+		} else {
+			char *p = (char *)pkg_ctx->name;
+			p += strlen(p);
+			*p = '.';
+			pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name,
+					O_RDONLY | O_CLOEXEC);
+			*p = '\0';
+		}
+		if (pkg_ctx->fd == -1)
+			return NULL;
+	}
+
+	if (ctx->cachetype == CACHE_METADATA_MD5) {
+		return tree_read_file_md5(pkg_ctx);
+	} else if (ctx->cachetype == CACHE_METADATA_PMS) {
+		return tree_read_file_pms(pkg_ctx);
+	} else if (ctx->cachetype == CACHE_EBUILD) {
+		return tree_read_file_ebuild(pkg_ctx);
+	}
+
+	warn("Unknown metadata cache type!");
+	return NULL;
+}
+
+void
+tree_close_meta(tree_pkg_meta *cache)
+{
+	if (!cache)
+		errf("Cache is empty !");
+	free(cache);
+}
+
+tree_metadata_xml *
+tree_pkg_metadata(tree_pkg_ctx *pkg_ctx)
+{
+	tree_ctx *ctx = pkg_ctx->cat_ctx->ctx;
+	int fd;
+	FILE *f;
+	struct stat s;
+	char *xbuf;
+	char *p;
+	char *q;
+	size_t len;
+	tree_metadata_xml *ret = NULL;
+	struct elist *emailw = NULL;
+	char buf[_Q_PATH_MAX];
+
+	/* lame @$$ XML parsing, I don't want to pull in a real parser
+	 * library because we only retrieve one element for now: email
+	 * technically speaking, email may occur only once in a maintainer
+	 * tag, but practically speaking we don't care at all, so we can
+	 * just extract everything between <email> and </email> */
+
+	if (ctx->cachetype == CACHE_EBUILD) {
+		fd = openat(pkg_ctx->cat_ctx->fd, "metadata", O_RDONLY | O_CLOEXEC);
+	} else {
+		depend_atom *atom;
+		snprintf(buf, sizeof(buf), "%s/%s",
+				pkg_ctx->cat_ctx->name, pkg_ctx->name);
+		atom = atom_explode(buf);
+		snprintf(buf, sizeof(buf), "../../%s/%s/metadata.xml",
+				atom->CATEGORY, atom->PN);
+		atom_implode(atom);
+		fd = openat(ctx->tree_fd, buf, O_RDONLY | O_CLOEXEC);
+	}
+
+	if (fd == -1)
+		return NULL;
+
+	if ((f = fdopen(fd, "r")) == NULL) {
+		close(fd);
+		return NULL;
+	}
+
+	if (fstat(fd, &s) != 0) {
+		fclose(f);
+		return NULL;
+	}
+
+	len = sizeof(*ret) + s.st_size + 1;
+	p = xbuf = xzalloc(len);
+	if ((off_t)fread(p, 1, s.st_size, f) != s.st_size) {
+		free(p);
+		fclose(f);
+		pkg_ctx->fd = -1;
+		return NULL;
+	}
+
+	ret = xmalloc(sizeof(*ret));
+	ret->email = NULL;
+
+	while ((q = strstr(p, "<email>")) != NULL) {
+		p = q + sizeof("<email>") - 1;
+		if ((q = strstr(p, "</email>")) == NULL)
+			break;
+		*q = '\0';
+		rmspace(p);
+		if (emailw == NULL) {
+			emailw = ret->email = xmalloc(sizeof(*emailw));
+		} else {
+			emailw = emailw->next = xmalloc(sizeof(*emailw));
+		}
+		emailw->next = NULL;
+		emailw->addr = xstrdup(p);
+		p = q + 1;
+	}
+
+	free(xbuf);
+	fclose(f);
+	return ret;
+}
+
+void
+tree_close_metadata(tree_metadata_xml *meta_ctx)
+{
+	struct elist *e;
+	while (meta_ctx->email != NULL) {
+		e = meta_ctx->email;
+		free(e->addr);
+		e = e->next;
+		free(meta_ctx->email);
+		meta_ctx->email = e;
+	}
+	free(meta_ctx);
+}
+
+void
+tree_close_pkg(tree_pkg_ctx *pkg_ctx)
+{
+	if (pkg_ctx->fd != -1)
+		close(pkg_ctx->fd);
+	if (pkg_ctx->atom != NULL)
+		atom_implode(pkg_ctx->atom);
+	/* avoid freeing tree_ctx' repo */
+	if (pkg_ctx->cat_ctx->ctx->repo != pkg_ctx->repo)
+		free(pkg_ctx->repo);
+	free(pkg_ctx->slot);
+	free(pkg_ctx);
+}
+
+int
+tree_foreach_pkg(tree_ctx *ctx,
+		tree_pkg_cb callback, void *priv, tree_cat_filter filter,
+		bool sort, void *catsortfunc, void *pkgsortfunc)
+{
+	tree_cat_ctx *cat_ctx;
+	tree_pkg_ctx *pkg_ctx;
+	int ret;
+
+	if (ctx == NULL)
+		return EXIT_FAILURE;
+
+	ctx->do_sort = sort;
+	if (catsortfunc != NULL)
+		ctx->catsortfunc = catsortfunc;
+	if (pkgsortfunc != NULL)
+		ctx->pkgsortfunc = pkgsortfunc;
+
+	ret = 0;
+	while ((cat_ctx = tree_next_cat(ctx))) {
+		if (filter && !filter(cat_ctx, priv))
+			continue;
+		while ((pkg_ctx = tree_next_pkg(cat_ctx))) {
+			ret |= callback(pkg_ctx, priv);
+			tree_close_pkg(pkg_ctx);
+		}
+		tree_close_cat(cat_ctx);
+	}
+
+	return ret;
+}
+
+depend_atom *
+tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete)
+{
+	if (pkg_ctx->atom == NULL) {
+		pkg_ctx->atom = atom_explode(pkg_ctx->name);
+		if (pkg_ctx->atom == NULL)
+			return NULL;
+		pkg_ctx->atom->CATEGORY = (char *)pkg_ctx->cat_ctx->name;
+	}
+
+	if (complete) {
+		tree_ctx *ctx = pkg_ctx->cat_ctx->ctx;
+		if (ctx->cachetype == CACHE_VDB) {
+			if (pkg_ctx->atom->SLOT == NULL) {
+				tree_pkg_vdb_eat(pkg_ctx, "SLOT",
+						&pkg_ctx->slot, &pkg_ctx->slot_len);
+				pkg_ctx->atom->SLOT = pkg_ctx->slot;
+			}
+			if (pkg_ctx->atom->REPO == NULL) {
+				tree_pkg_vdb_eat(pkg_ctx, "repository",
+						&pkg_ctx->repo, &pkg_ctx->repo_len);
+				pkg_ctx->atom->REPO = pkg_ctx->repo;
+			}
+		} else { /* metadata or ebuild */
+			if (pkg_ctx->atom->SLOT == NULL) {
+				tree_pkg_meta *meta = tree_pkg_read(pkg_ctx);
+				if (meta != NULL) {
+					pkg_ctx->slot = xstrdup(meta->SLOT);
+					pkg_ctx->slot_len = strlen(pkg_ctx->slot);
+					pkg_ctx->atom->SLOT = pkg_ctx->slot;
+					tree_close_meta(meta);
+				}
+			}
+			/* repo is set from the tree, when found */
+			if (pkg_ctx->atom->REPO == NULL)
+				pkg_ctx->atom->REPO = pkg_ctx->repo;
+		}
+	}
+
+	return pkg_ctx->atom;
+}
+
+set *
+tree_get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv)
+{
+	tree_ctx *ctx;
+
+	int cfd, j;
+	int dfd, i;
+
+	char buf[_Q_PATH_MAX];
+	char slot[_Q_PATH_MAX];
+	char *slotp = slot;
+	size_t slot_len;
+
+	struct dirent **cat;
+	struct dirent **pf;
+
+	depend_atom *atom = NULL;
+	set *cpf = NULL;
+
+	ctx = tree_open_vdb(sroot, svdb);
+	if (!ctx)
+		return NULL;
+
+	/* scan the cat first */
+	cfd = scandirat(ctx->tree_fd, ".", &cat, tree_filter_cat, alphasort);
+	if (cfd < 0)
+		goto fuckit;
+
+	for (j = 0; j < cfd; j++) {
+		dfd = scandirat(ctx->tree_fd, cat[j]->d_name,
+				&pf, tree_filter_pkg, alphasort);
+		if (dfd < 0)
+			continue;
+		for (i = 0; i < dfd; i++) {
+			int blen = snprintf(buf, sizeof(buf), "%s/%s/SLOT",
+					cat[j]->d_name, pf[i]->d_name);
+			if (blen < 0 || (size_t)blen >= sizeof(buf)) {
+				warnf("unable to parse long package: %s/%s",
+						cat[j]->d_name, pf[i]->d_name);
+				continue;
+			}
+
+			/* Chop the SLOT for the atom parsing. */
+			buf[blen - 5] = '\0';
+			if ((atom = atom_explode(buf)) == NULL)
+				continue;
+			/* Restore the SLOT. */
+			buf[blen - 5] = '/';
+
+			slot_len = sizeof(slot);
+			eat_file_at(ctx->tree_fd, buf, &slotp, &slot_len);
+			rmspace(slot);
+
+			if (fullcpv) {
+				if (atom->PR_int)
+					snprintf(buf, sizeof(buf), "%s/%s-%s-r%i",
+							atom->CATEGORY, atom->PN, atom->PV, atom->PR_int);
+				else
+					snprintf(buf, sizeof(buf), "%s/%s-%s",
+							atom->CATEGORY, atom->PN, atom->PV);
+			} else {
+				snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN);
+			}
+			atom_implode(atom);
+			cpf = add_set(buf, cpf);
+		}
+		scandir_free(pf, dfd);
+	}
+	scandir_free(cat, cfd);
+
+ fuckit:
+	tree_close(ctx);
+	return cpf;
+}

diff --git a/libq/tree.h b/libq/tree.h
new file mode 100644
index 0000000..7f05819
--- /dev/null
+++ b/libq/tree.h
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2005-2019 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ */
+
+#ifndef _TREE_H
+#define _TREE_H 1
+
+#include <dirent.h>
+#include <stdbool.h>
+
+#include "atom.h"
+#include "set.h"
+
+typedef struct tree_ctx          tree_ctx;
+typedef struct tree_cat_ctx      tree_cat_ctx;
+typedef struct tree_pkg_ctx      tree_pkg_ctx;
+typedef struct tree_pkg_meta     tree_pkg_meta;
+typedef struct tree_metadata_xml tree_metadata_xml;
+
+/* VDB context */
+struct tree_ctx {
+	int portroot_fd;
+	int tree_fd;
+	DIR *dir;
+	struct dirent **cat_de;
+	size_t cat_cnt;
+	size_t cat_cur;
+	void *catsortfunc;
+	void *pkgsortfunc;
+	bool do_sort:1;
+	enum {
+		CACHE_UNSET = 0,
+		CACHE_METADATA_MD5,
+		CACHE_METADATA_PMS,
+		CACHE_EBUILD,
+		CACHE_VDB,
+	} cachetype:3;
+	tree_pkg_ctx *ebuilddir_pkg_ctx;
+	tree_cat_ctx *ebuilddir_cat_ctx;
+	tree_ctx *ebuilddir_ctx;
+	char *repo;
+};
+
+/* Category context */
+struct tree_cat_ctx {
+	const char *name;
+	int fd;
+	DIR *dir;
+	tree_ctx *ctx;
+	struct dirent **pkg_de;
+	size_t pkg_cnt;
+	size_t pkg_cur;
+};
+
+/* Package context */
+struct tree_pkg_ctx {
+	const char *name;
+	char *slot;
+	char *repo;
+	size_t slot_len;
+	size_t repo_len;
+	int fd;
+	tree_cat_ctx *cat_ctx;
+	depend_atom *atom;
+};
+
+/* Ebuild data */
+struct tree_pkg_meta {
+	char *_data;
+	char *DEPEND;        /* line 1 */
+	char *RDEPEND;
+	char *SLOT;
+	char *SRC_URI;
+	char *RESTRICT;      /* line 5 */
+	char *HOMEPAGE;
+	char *LICENSE;
+	char *DESCRIPTION;
+	char *KEYWORDS;
+	char *INHERITED;     /* line 10 */
+	char *IUSE;
+	char *CDEPEND;
+	char *PDEPEND;
+	char *PROVIDE;       /* line 14 */
+	char *EAPI;
+	char *PROPERTIES;
+	/* These are MD5-Cache only */
+	char *DEFINED_PHASES;
+	char *REQUIRED_USE;
+	char *BDEPEND;
+	char *_eclasses_;
+	char *_md5_;
+};
+
+/* Metadata.xml */
+struct tree_metadata_xml {
+	struct elist {
+		char *addr;
+		struct elist *next;
+	} *email;
+};
+
+/* Global helpers */
+typedef int (tree_pkg_cb)(tree_pkg_ctx *, void *priv);
+typedef int (tree_cat_filter)(tree_cat_ctx *, void *priv);
+
+tree_ctx *tree_open_vdb(const char *sroot, const char *svdb);
+tree_ctx *tree_open(const char *sroot, const char *portdir);
+void tree_close(tree_ctx *ctx);
+int tree_filter_cat(const struct dirent *de);
+tree_cat_ctx *tree_open_cat(tree_ctx *ctx, const char *name);
+tree_cat_ctx *tree_next_cat(tree_ctx *ctx);
+void tree_close_cat(tree_cat_ctx *cat_ctx);
+int tree_filter_pkg(const struct dirent *de);
+tree_pkg_ctx *tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name);
+tree_pkg_ctx *tree_next_pkg(tree_cat_ctx *cat_ctx);
+int tree_pkg_vdb_openat(tree_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode);
+FILE *tree_pkg_vdb_fopenat(tree_pkg_ctx *pkg_ctx, const char *file,
+	int flags, mode_t mode, const char *fmode);
+#define tree_pkg_vdb_fopenat_ro(pkg_ctx, file) \
+	tree_pkg_vdb_fopenat(pkg_ctx, file, O_RDONLY, 0, "r")
+#define tree_pkg_vdb_fopenat_rw(pkg_ctx, file) \
+	tree_pkg_vdb_fopenat(pkg_ctx, file, O_RDWR | O_CREAT | O_TRUNC, 0644, "w")
+bool tree_pkg_vdb_eat(tree_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *buflen);
+tree_pkg_meta *tree_pkg_read(tree_pkg_ctx *pkg_ctx);
+void tree_close_meta(tree_pkg_meta *cache);
+tree_metadata_xml *tree_pkg_metadata(tree_pkg_ctx *pkg_ctx);
+void tree_close_metadata(tree_metadata_xml *meta_ctx);
+void tree_close_pkg(tree_pkg_ctx *pkg_ctx);
+int tree_foreach_pkg(tree_ctx *ctx,
+		tree_pkg_cb callback, void *priv, tree_cat_filter filter,
+		bool sort, void *catsortfunc, void *pkgsortfunc);
+#define tree_foreach_pkg_fast(ctx, cb, priv, filter) \
+	tree_foreach_pkg(ctx, cb, priv, filter, false, NULL, NULL);
+#define tree_foreach_pkg_sorted(ctx, cb, priv) \
+	tree_foreach_pkg(ctx, cb, priv, NULL, true, NULL, NULL);
+struct dirent *tree_get_next_dir(DIR *dir);
+set *tree_get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv);
+depend_atom *tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete);
+
+#endif

diff --git a/libq/vdb.c b/libq/vdb.c
deleted file mode 100644
index 810a84c..0000000
--- a/libq/vdb.c
+++ /dev/null
@@ -1,515 +0,0 @@
-/*
- * Copyright 2005-2019 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- *
- * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
- * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
- * Copyright 2019-     Fabian Groffen  - <grobian@gentoo.org>
- */
-
-#include "main.h"
-#include "rmspace.h"
-#include "scandirat.h"
-#include "eat_file.h"
-#include "set.h"
-#include "atom.h"
-#include "vdb.h"
-
-#include <ctype.h>
-#include <xalloc.h>
-
-vdb_ctx *
-vdb_open2(const char *sroot, const char *svdb, bool quiet)
-{
-	vdb_ctx *ctx = xmalloc(sizeof(*ctx));
-
-	ctx->portroot_fd = open(sroot, O_RDONLY|O_CLOEXEC|O_PATH);
-	if (ctx->portroot_fd == -1) {
-		if (!quiet)
-			warnp("could not open root: %s", sroot);
-		goto f_error;
-	}
-
-	/* Skip the leading slash */
-	svdb++;
-	if (*svdb == '\0')
-		svdb = ".";
-	/* Cannot use O_PATH as we want to use fdopendir() */
-	ctx->vdb_fd = openat(ctx->portroot_fd, svdb, O_RDONLY|O_CLOEXEC);
-	if (ctx->vdb_fd == -1) {
-		if (!quiet)
-			warnp("could not open vdb: %s (in root %s)", svdb, sroot);
-		goto cp_error;
-	}
-
-	ctx->dir = fdopendir(ctx->vdb_fd);
-	if (ctx->dir == NULL)
-		goto cv_error;
-
-	ctx->do_sort = false;
-	ctx->cat_de = NULL;
-	ctx->catsortfunc = alphasort;
-	ctx->pkgsortfunc = alphasort;
-	ctx->repo = NULL;
-	ctx->ebuilddir_ctx = NULL;
-	ctx->ebuilddir_pkg_ctx = NULL;
-	return ctx;
-
- cv_error:
-	close(ctx->vdb_fd);
- cp_error:
-	close(ctx->portroot_fd);
- f_error:
-	free(ctx);
-	return NULL;
-}
-
-vdb_ctx *
-vdb_open(const char *sroot, const char *svdb)
-{
-	return vdb_open2(sroot, svdb, false);
-}
-
-void
-vdb_close(vdb_ctx *ctx)
-{
-	closedir(ctx->dir);
-	/* closedir() above does this for us: */
-	/* close(ctx->vdb_fd); */
-	close(ctx->portroot_fd);
-	if (ctx->do_sort)
-		scandir_free(ctx->cat_de, ctx->cat_cnt);
-	free(ctx);
-}
-
-int
-vdb_filter_cat(const struct dirent *de)
-{
-	int i;
-	bool founddash;
-
-#ifdef DT_UNKNOWN
-	/* cat must be a dir */
-	if (de->d_type != DT_UNKNOWN &&
-	    de->d_type != DT_DIR &&
-	    de->d_type != DT_LNK)
-		return 0;
-#endif
-
-	/* PMS 3.1.1 */
-	founddash = false;
-	for (i = 0; de->d_name[i] != '\0'; i++) {
-		switch (de->d_name[i]) {
-			case '_':
-				break;
-			case '-':
-				founddash = true;
-				/* fall through */
-			case '+':
-			case '.':
-				if (i)
-					break;
-				return 0;
-			default:
-				if ((de->d_name[i] >= 'A' && de->d_name[i] <= 'Z') ||
-						(de->d_name[i] >= 'a' && de->d_name[i] <= 'z') ||
-						(de->d_name[i] >= '0' && de->d_name[i] <= '9'))
-					break;
-				return 0;
-		}
-	}
-	if (!founddash && strcmp(de->d_name, "virtual") != 0)
-		return 0;
-
-	return i;
-}
-
-vdb_cat_ctx *
-vdb_open_cat(vdb_ctx *ctx, const char *name)
-{
-	vdb_cat_ctx *cat_ctx;
-	int fd;
-	DIR *dir;
-
-	/* Cannot use O_PATH as we want to use fdopendir() */
-	fd = openat(ctx->vdb_fd, name, O_RDONLY|O_CLOEXEC);
-	if (fd == -1)
-		return NULL;
-
-	dir = fdopendir(fd);
-	if (!dir) {
-		close(fd);
-		return NULL;
-	}
-
-	cat_ctx = xmalloc(sizeof(*cat_ctx));
-	cat_ctx->name = name;
-	cat_ctx->fd = fd;
-	cat_ctx->dir = dir;
-	cat_ctx->ctx = ctx;
-	cat_ctx->pkg_de = NULL;
-	return cat_ctx;
-}
-
-vdb_cat_ctx *
-vdb_next_cat(vdb_ctx *ctx)
-{
-	/* search for a category directory */
-	vdb_cat_ctx *cat_ctx = NULL;
-
-	if (ctx->do_sort) {
-		if (ctx->cat_de == NULL) {
-			ctx->cat_cnt = scandirat(ctx->vdb_fd,
-					".", &ctx->cat_de, vdb_filter_cat, ctx->catsortfunc);
-			ctx->cat_cur = 0;
-		}
-
-		while (ctx->cat_cur < ctx->cat_cnt) {
-			cat_ctx = vdb_open_cat(ctx, ctx->cat_de[ctx->cat_cur++]->d_name);
-			if (!cat_ctx)
-				continue;
-			break;
-		}
-	} else {
-		/* cheaper "streaming" variant */
-		const struct dirent *de;
-		do {
-			de = readdir(ctx->dir);
-			if (!de)
-				break;
-
-			if (vdb_filter_cat(de) == 0)
-				continue;
-
-			cat_ctx = vdb_open_cat(ctx, de->d_name);
-			if (!cat_ctx)
-				continue;
-
-			break;
-		} while (1);
-	}
-
-	return cat_ctx;
-}
-
-void
-vdb_close_cat(vdb_cat_ctx *cat_ctx)
-{
-	closedir(cat_ctx->dir);
-	/* closedir() above does this for us: */
-	/* close(ctx->fd); */
-	if (cat_ctx->ctx->do_sort)
-		scandir_free(cat_ctx->pkg_de, cat_ctx->pkg_cnt);
-	free(cat_ctx);
-}
-
-int
-vdb_filter_pkg(const struct dirent *de)
-{
-	int i;
-	bool founddash = false;
-
-	/* PMS 3.1.2 */
-	for (i = 0; de->d_name[i] != '\0'; i++) {
-		switch (de->d_name[i]) {
-			case '_':
-				break;
-			case '-':
-				founddash = true;
-				/* fall through */
-			case '+':
-				if (i)
-					break;
-				return 0;
-			default:
-				if ((de->d_name[i] >= 'A' && de->d_name[i] <= 'Z') ||
-						(de->d_name[i] >= 'a' && de->d_name[i] <= 'z') ||
-						(de->d_name[i] >= '0' && de->d_name[i] <= '9'))
-					break;
-				if (founddash)
-					return 1;
-				return 0;
-		}
-	}
-
-	return i;
-}
-
-vdb_pkg_ctx *
-vdb_open_pkg(vdb_cat_ctx *cat_ctx, const char *name)
-{
-	vdb_pkg_ctx *pkg_ctx = xmalloc(sizeof(*pkg_ctx));
-	pkg_ctx->name = name;
-	pkg_ctx->slot = NULL;
-	pkg_ctx->repo = cat_ctx->ctx->repo;
-	pkg_ctx->fd = -1;
-	pkg_ctx->cat_ctx = cat_ctx;
-	pkg_ctx->atom = NULL;
-	return pkg_ctx;
-}
-
-vdb_pkg_ctx *
-vdb_next_pkg(vdb_cat_ctx *cat_ctx)
-{
-	vdb_pkg_ctx *pkg_ctx = NULL;
-
-	if (cat_ctx->ctx->do_sort) {
-		if (cat_ctx->pkg_de == NULL) {
-			cat_ctx->pkg_cnt = scandirat(cat_ctx->fd, ".", &cat_ctx->pkg_de,
-					vdb_filter_pkg, cat_ctx->ctx->pkgsortfunc);
-			cat_ctx->pkg_cur = 0;
-		}
-
-		while (cat_ctx->pkg_cur < cat_ctx->pkg_cnt) {
-			pkg_ctx =
-				vdb_open_pkg(cat_ctx,
-						cat_ctx->pkg_de[cat_ctx->pkg_cur++]->d_name);
-			if (!pkg_ctx)
-				continue;
-			break;
-		}
-	} else {
-		const struct dirent *de;
-		do {
-			de = readdir(cat_ctx->dir);
-			if (!de)
-				break;
-
-			if (vdb_filter_pkg(de) == 0)
-				continue;
-
-			pkg_ctx = vdb_open_pkg(cat_ctx, de->d_name);
-			if (!pkg_ctx)
-				continue;
-
-			break;
-		} while (1);
-	}
-
-	return pkg_ctx;
-}
-
-int
-vdb_pkg_openat(vdb_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode)
-{
-	if (pkg_ctx->fd == -1) {
-		pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name,
-				O_RDONLY|O_CLOEXEC|O_PATH);
-		if (pkg_ctx->fd == -1)
-			return -1;
-	}
-
-	return openat(pkg_ctx->fd, file, flags|O_CLOEXEC, mode);
-}
-
-FILE *
-vdb_pkg_fopenat(vdb_pkg_ctx *pkg_ctx, const char *file,
-	int flags, mode_t mode, const char *fmode)
-{
-	FILE *fp;
-	int fd;
-
-	fd = vdb_pkg_openat(pkg_ctx, file, flags, mode);
-	if (fd == -1)
-		return NULL;
-
-	fp = fdopen(fd, fmode);
-	if (!fp)
-		close(fd);
-
-	return fp;
-}
-
-bool
-vdb_pkg_eat(vdb_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *buflen)
-{
-	int fd = vdb_pkg_openat(pkg_ctx, file, O_RDONLY, 0);
-	bool ret = eat_file_fd(fd, bufptr, buflen);
-	rmspace(*bufptr);
-	if (fd != -1)
-		close(fd);
-	return ret;
-}
-
-void
-vdb_close_pkg(vdb_pkg_ctx *pkg_ctx)
-{
-	if (pkg_ctx->fd != -1)
-		close(pkg_ctx->fd);
-	if (pkg_ctx->atom != NULL)
-		atom_implode(pkg_ctx->atom);
-	free(pkg_ctx->slot);
-	free(pkg_ctx->repo);
-	free(pkg_ctx);
-}
-
-static int
-vdb_foreach_pkg_int(const char *sroot, const char *svdb,
-		vdb_pkg_cb callback, void *priv, vdb_cat_filter filter,
-		bool sort, void *catsortfunc, void *pkgsortfunc)
-{
-	vdb_ctx *ctx;
-	vdb_cat_ctx *cat_ctx;
-	vdb_pkg_ctx *pkg_ctx;
-	int ret;
-
-	ctx = vdb_open(sroot, svdb);
-	if (!ctx)
-		return EXIT_FAILURE;
-
-	ctx->do_sort = sort;
-	if (catsortfunc != NULL)
-		ctx->catsortfunc = catsortfunc;
-	if (pkgsortfunc != NULL)
-		ctx->pkgsortfunc = pkgsortfunc;
-
-	ret = 0;
-	while ((cat_ctx = vdb_next_cat(ctx))) {
-		if (filter && !filter(cat_ctx, priv))
-			continue;
-		while ((pkg_ctx = vdb_next_pkg(cat_ctx))) {
-			ret |= callback(pkg_ctx, priv);
-			vdb_close_pkg(pkg_ctx);
-		}
-		vdb_close_cat(cat_ctx);
-	}
-	vdb_close(ctx);
-
-	return ret;
-}
-
-int
-vdb_foreach_pkg(const char *sroot, const char *svdb,
-		vdb_pkg_cb callback, void *priv, vdb_cat_filter filter)
-{
-	return vdb_foreach_pkg_int(sroot, svdb, callback, priv,
-			filter, false, NULL, NULL);
-}
-
-int
-vdb_foreach_pkg_sorted(const char *sroot, const char *svdb,
-		vdb_pkg_cb callback, void *priv)
-{
-	return vdb_foreach_pkg_int(sroot, svdb, callback, priv,
-			NULL, true, NULL, NULL);
-}
-
-struct dirent *
-vdb_get_next_dir(DIR *dir)
-{
-	/* search for a category directory */
-	struct dirent *ret;
-
-next_entry:
-	ret = readdir(dir);
-	if (ret == NULL) {
-		closedir(dir);
-		return NULL;
-	}
-
-	if (vdb_filter_cat(ret) == 0)
-		goto next_entry;
-
-	return ret;
-}
-
-depend_atom *
-vdb_get_atom(vdb_pkg_ctx *pkg_ctx, bool complete)
-{
-	if (pkg_ctx->atom == NULL) {
-		pkg_ctx->atom = atom_explode(pkg_ctx->name);
-		if (pkg_ctx->atom == NULL)
-			return NULL;
-		pkg_ctx->atom->CATEGORY = (char *)pkg_ctx->cat_ctx->name;
-	}
-
-	if (complete) {
-		if (pkg_ctx->atom->SLOT == NULL) {
-			vdb_pkg_eat(pkg_ctx, "SLOT",
-					&pkg_ctx->slot, &pkg_ctx->slot_len);
-			pkg_ctx->atom->SLOT = pkg_ctx->slot;
-		}
-		if (pkg_ctx->atom->REPO == NULL) {
-			vdb_pkg_eat(pkg_ctx, "repository",
-					&pkg_ctx->repo, &pkg_ctx->repo_len);
-			pkg_ctx->atom->REPO = pkg_ctx->repo;
-		}
-	}
-
-	return pkg_ctx->atom;
-}
-
-set *
-get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv)
-{
-	vdb_ctx *ctx;
-
-	int cfd, j;
-	int dfd, i;
-
-	char buf[_Q_PATH_MAX];
-	char slot[_Q_PATH_MAX];
-	char *slotp = slot;
-	size_t slot_len;
-
-	struct dirent **cat;
-	struct dirent **pf;
-
-	depend_atom *atom = NULL;
-	set *cpf = NULL;
-
-	ctx = vdb_open(sroot, svdb);
-	if (!ctx)
-		return NULL;
-
-	/* scan the cat first */
-	cfd = scandirat(ctx->vdb_fd, ".", &cat, vdb_filter_cat, alphasort);
-	if (cfd < 0)
-		goto fuckit;
-
-	for (j = 0; j < cfd; j++) {
-		dfd = scandirat(ctx->vdb_fd, cat[j]->d_name,
-				&pf, vdb_filter_pkg, alphasort);
-		if (dfd < 0)
-			continue;
-		for (i = 0; i < dfd; i++) {
-			int blen = snprintf(buf, sizeof(buf), "%s/%s/SLOT",
-					cat[j]->d_name, pf[i]->d_name);
-			if (blen < 0 || (size_t)blen >= sizeof(buf)) {
-				warnf("unable to parse long package: %s/%s",
-						cat[j]->d_name, pf[i]->d_name);
-				continue;
-			}
-
-			/* Chop the SLOT for the atom parsing. */
-			buf[blen - 5] = '\0';
-			if ((atom = atom_explode(buf)) == NULL)
-				continue;
-			/* Restore the SLOT. */
-			buf[blen - 5] = '/';
-
-			slot_len = sizeof(slot);
-			eat_file_at(ctx->vdb_fd, buf, &slotp, &slot_len);
-			rmspace(slot);
-
-			if (fullcpv) {
-				if (atom->PR_int)
-					snprintf(buf, sizeof(buf), "%s/%s-%s-r%i",
-							atom->CATEGORY, atom->PN, atom->PV, atom->PR_int);
-				else
-					snprintf(buf, sizeof(buf), "%s/%s-%s",
-							atom->CATEGORY, atom->PN, atom->PV);
-			} else {
-				snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN);
-			}
-			atom_implode(atom);
-			cpf = add_set(buf, cpf);
-		}
-		scandir_free(pf, dfd);
-	}
-	scandir_free(cat, cfd);
-
- fuckit:
-	vdb_close(ctx);
-	return cpf;
-}

diff --git a/libq/vdb.h b/libq/vdb.h
deleted file mode 100644
index 28ca040..0000000
--- a/libq/vdb.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2005-2019 Gentoo Foundation
- * Distributed under the terms of the GNU General Public License v2
- */
-
-#ifndef _VDB_H
-#define _VDB_H 1
-
-#include <dirent.h>
-#include <stdbool.h>
-
-#include "set.h"
-
-typedef struct vdb_ctx vdb_ctx;
-typedef struct vdb_cat_ctx vdb_cat_ctx;
-typedef struct vdb_pkg_ctx vdb_pkg_ctx;
-
-/* VDB context */
-struct vdb_ctx {
-	int portroot_fd;
-	int vdb_fd;
-	DIR *dir;
-	struct dirent **cat_de;
-	size_t cat_cnt;
-	size_t cat_cur;
-	void *catsortfunc;
-	void *pkgsortfunc;
-	bool do_sort:1;
-	enum {
-		CACHE_UNSET = 0,
-		CACHE_METADATA_MD5,
-		CACHE_METADATA_PMS,
-		CACHE_EBUILD,
-		CACHE_VDB,
-	} cachetype:3;
-	vdb_pkg_ctx *ebuilddir_pkg_ctx;
-	vdb_cat_ctx *ebuilddir_cat_ctx;
-	vdb_ctx *ebuilddir_ctx;
-	char *repo;
-};
-
-/* Category context */
-struct vdb_cat_ctx {
-	const char *name;
-	int fd;
-	DIR *dir;
-	const vdb_ctx *ctx;
-	struct dirent **pkg_de;
-	size_t pkg_cnt;
-	size_t pkg_cur;
-};
-
-/* Package context */
-struct vdb_pkg_ctx {
-	const char *name;
-	char *slot;
-	char *repo;
-	size_t slot_len;
-	size_t repo_len;
-	int fd;
-	vdb_cat_ctx *cat_ctx;
-	depend_atom *atom;
-};
-
-/* Global helpers */
-typedef int (vdb_pkg_cb)(vdb_pkg_ctx *, void *priv);
-typedef int (vdb_cat_filter)(vdb_cat_ctx *, void *priv);
-
-vdb_ctx *vdb_open(const char *sroot, const char *svdb);
-vdb_ctx *vdb_open2(const char *sroot, const char *svdb, bool quiet);
-void vdb_close(vdb_ctx *ctx);
-int vdb_filter_cat(const struct dirent *de);
-vdb_cat_ctx *vdb_open_cat(vdb_ctx *ctx, const char *name);
-vdb_cat_ctx *vdb_next_cat(vdb_ctx *ctx);
-void vdb_close_cat(vdb_cat_ctx *cat_ctx);
-int vdb_filter_pkg(const struct dirent *de);
-vdb_pkg_ctx *vdb_open_pkg(vdb_cat_ctx *cat_ctx, const char *name);
-vdb_pkg_ctx *vdb_next_pkg(vdb_cat_ctx *cat_ctx);
-int vdb_pkg_openat(vdb_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode);
-FILE *vdb_pkg_fopenat(vdb_pkg_ctx *pkg_ctx, const char *file,
-	int flags, mode_t mode, const char *fmode);
-#define vdb_pkg_fopenat_ro(pkg_ctx, file) \
-	vdb_pkg_fopenat(pkg_ctx, file, O_RDONLY, 0, "r")
-#define vdb_pkg_fopenat_rw(pkg_ctx, file) \
-	vdb_pkg_fopenat(pkg_ctx, file, O_RDWR|O_CREAT|O_TRUNC, 0644, "w")
-bool vdb_pkg_eat(vdb_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *buflen);
-void vdb_close_pkg(vdb_pkg_ctx *pkg_ctx);
-int vdb_foreach_pkg(const char *sroot, const char *svdb,
-		vdb_pkg_cb callback, void *priv, vdb_cat_filter filter);
-int vdb_foreach_pkg_sorted(const char *sroot, const char *svdb,
-		vdb_pkg_cb callback, void *priv);
-struct dirent *vdb_get_next_dir(DIR *dir);
-set *get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv);
-depend_atom *vdb_get_atom(vdb_pkg_ctx *pkg_ctx, bool complete);
-
-#endif

diff --git a/main.c b/main.c
index 159b262..944950e 100644
--- a/main.c
+++ b/main.c
@@ -17,30 +17,10 @@
 #include <sys/time.h>
 #include <limits.h>
 
-#include "atom.h"
-#include "basename.h"
-#include "busybox.h"
-#include "cache.h"
-#include "colors.h"
-#include "copy_file.h"
 #include "eat_file.h"
-#include "hash_fd.h"
-#include "human_readable.h"
-#include "i18n.h"
-#include "md5_sha1_sum.h"
-#include "prelink.h"
-#include "profile.h"
 #include "rmspace.h"
-#include "safe_io.h"
 #include "scandirat.h"
-#include "set.h"
-#include "vdb.h"
-#include "xarray.h"
 #include "xasprintf.h"
-#include "xchdir.h"
-#include "xmkdir.h"
-#include "xregex.h"
-#include "xsystem.h"
 
 /* variables to control runtime behavior */
 char *module_name = NULL;

diff --git a/q.c b/q.c
index a18c791..b6486ee 100644
--- a/q.c
+++ b/q.c
@@ -19,9 +19,7 @@
 #include <libproc.h>
 #endif
 
-#include "atom.h"
 #include "basename.h"
-#include "cache.h"
 
 #define Q_FLAGS "iM:" COMMON_FLAGS
 static struct option const q_long_opts[] = {

diff --git a/qcheck.c b/qcheck.c
index 68cdb30..a26b25d 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -20,7 +20,7 @@
 #include "md5_sha1_sum.h"
 #include "prelink.h"
 #include "set.h"
-#include "vdb.h"
+#include "tree.h"
 #include "xarray.h"
 #include "xasprintf.h"
 #include "xregex.h"
@@ -65,7 +65,7 @@ struct qcheck_opt_state {
 };
 
 static int
-qcheck_process_contents(vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
+qcheck_process_contents(tree_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 {
 	int fd_contents;
 	FILE *fp_contents, *fp_contents_update;
@@ -80,7 +80,8 @@ qcheck_process_contents(vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 	fp_contents_update = NULL;
 
 	/* Open contents */
-	fd_contents = vdb_pkg_openat(pkg_ctx, "CONTENTS", O_RDONLY|O_CLOEXEC, 0);
+	fd_contents = tree_pkg_vdb_openat(pkg_ctx, "CONTENTS",
+			O_RDONLY | O_CLOEXEC, 0);
 	if (fd_contents == -1)
 		return EXIT_SUCCESS;
 	if (fstat(fd_contents, &cst)) {
@@ -93,13 +94,13 @@ qcheck_process_contents(vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 	}
 
 	/* Open contents_update, if needed */
-	atom = vdb_get_atom(pkg_ctx, false);
+	atom = tree_get_atom(pkg_ctx, false);
 	num_files = num_files_ok = num_files_unknown = num_files_ignored = 0;
 	qcprintf("%sing %s ...\n",
 		(state->qc_update ? "Updat" : "Check"),
 		atom_format("%[CATEGORY]%[PF]", atom, 0));
 	if (state->qc_update) {
-		fp_contents_update = vdb_pkg_fopenat_rw(pkg_ctx, "CONTENTS~");
+		fp_contents_update = tree_pkg_vdb_fopenat_rw(pkg_ctx, "CONTENTS~");
 		if (fp_contents_update == NULL) {
 			fclose(fp_contents);
 			warnp("unable to fopen(%s/%s, w)", atom->P, "CONTENTS~");
@@ -355,7 +356,7 @@ qcheck_process_contents(vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 }
 
 static int
-qcheck_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
+qcheck_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qcheck_opt_state *state = priv;
 	bool showit = false;
@@ -366,7 +367,7 @@ qcheck_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 		depend_atom *qatom;
 		depend_atom *atom;
 
-		qatom = vdb_get_atom(pkg_ctx, false);
+		qatom = tree_get_atom(pkg_ctx, false);
 		array_for_each(state->atoms, i, atom) {
 			if (atom_compare(atom, qatom) == EQUAL) {
 				showit = true;
@@ -384,6 +385,7 @@ int qcheck_main(int argc, char **argv)
 {
 	size_t i;
 	int ret;
+	tree_ctx *vdb;
 	DECLARE_ARRAY(regex_arr);
 	depend_atom *atom;
 	DECLARE_ARRAY(atoms);
@@ -403,9 +405,9 @@ int qcheck_main(int argc, char **argv)
 		switch (ret) {
 		COMMON_GETOPTS_CASES(qcheck)
 		case 's': {
-			regex_t regex;
-			xregcomp(&regex, optarg, REG_EXTENDED|REG_NOSUB);
-			xarraypush(regex_arr, &regex, sizeof(regex));
+			regex_t preg;
+			xregcomp(&preg, optarg, REG_EXTENDED | REG_NOSUB);
+			xarraypush(regex_arr, &preg, sizeof(preg));
 			break;
 		}
 		case 'u': state.qc_update = true; break;
@@ -428,11 +430,16 @@ int qcheck_main(int argc, char **argv)
 			xarraypush_ptr(atoms, atom);
 	}
 
-	ret = vdb_foreach_pkg_sorted(portroot, portvdb, qcheck_cb, &state);
-	{
-		void *regex;
-		array_for_each(regex_arr, i, regex)
-			regfree(regex);
+	vdb = tree_open_vdb(portroot, portvdb);
+	ret = -1;
+	if (vdb != NULL) {
+		ret = tree_foreach_pkg_sorted(vdb, qcheck_cb, &state);
+		tree_close(vdb);
+	}
+	if (array_cnt(regex_arr) > 0) {
+		void *preg;
+		array_for_each(regex_arr, i, preg)
+			regfree(preg);
 	}
 	xarrayfree(regex_arr);
 	array_for_each(atoms, i, atom)

diff --git a/qdepends.c b/qdepends.c
index 64bf991..15d5253 100644
--- a/qdepends.c
+++ b/qdepends.c
@@ -17,7 +17,7 @@
 #include "atom.h"
 #include "dep.h"
 #include "set.h"
-#include "vdb.h"
+#include "tree.h"
 #include "xarray.h"
 #include "xasprintf.h"
 #include "xregex.h"
@@ -92,7 +92,7 @@ qdepends_print_depend(FILE *fp, const char *depend)
 }
 
 static int
-qdepends_results_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
+qdepends_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qdepends_opt_state *state = priv;
 	depend_atom *atom;
@@ -116,7 +116,7 @@ qdepends_results_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 	 * *DEPEND alters the search somewhat and affects results printing.
 	 */
 
-	datom = vdb_get_atom(pkg_ctx, false);
+	datom = tree_get_atom(pkg_ctx, false);
 	if (datom == NULL)
 		return ret;
 
@@ -135,7 +135,7 @@ qdepends_results_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 
 		ret = 1;
 
-		datom = vdb_get_atom(pkg_ctx, true);
+		datom = tree_get_atom(pkg_ctx, true);
 		printf("%s:", atom_format(state->format, datom, 0));
 	}
 
@@ -146,7 +146,7 @@ qdepends_results_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 	for (i = QMODE_DEPEND; i <= QMODE_BDEPEND; i <<= 1, dfile++) {
 		if (!(state->qmode & i))
 			continue;
-		if (!vdb_pkg_eat(pkg_ctx, *dfile,
+		if (!tree_pkg_vdb_eat(pkg_ctx, *dfile,
 					&state->depend, &state->depend_len))
 			continue;
 
@@ -174,7 +174,7 @@ qdepends_results_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 					ret = 1;
 
 					if (!firstmatch) {
-						datom = vdb_get_atom(pkg_ctx, true);
+						datom = tree_get_atom(pkg_ctx, true);
 						printf("%s:", atom_format(state->format, datom, 0));
 					}
 					firstmatch = true;
@@ -203,7 +203,7 @@ qdepends_results_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 						ret = 1;
 
 						if (!firstmatch) {
-							datom = vdb_get_atom(pkg_ctx, true);
+							datom = tree_get_atom(pkg_ctx, true);
 							printf("%s:", atom_format(state->format, datom, 0));
 						}
 						firstmatch = true;
@@ -243,6 +243,7 @@ qdepends_results_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 int qdepends_main(int argc, char **argv)
 {
 	depend_atom *atom;
+	tree_ctx *vdb;
 	DECLARE_ARRAY(atoms);
 	DECLARE_ARRAY(deps);
 	struct qdepends_opt_state state = {
@@ -307,8 +308,11 @@ int qdepends_main(int argc, char **argv)
 			xarraypush_ptr(atoms, atom);
 	}
 
-	ret = vdb_foreach_pkg(portroot, portvdb,
-			qdepends_results_cb, &state, NULL);
+	vdb = tree_open_vdb(portroot, portvdb);
+	if (vdb != NULL) {
+		ret = tree_foreach_pkg_fast(vdb, qdepends_results_cb, &state, NULL);
+		tree_close(vdb);
+	}
 
 	if (state.depend != NULL)
 		free(state.depend);

diff --git a/qfile.c b/qfile.c
index 3d1543e..c451ae4 100644
--- a/qfile.c
+++ b/qfile.c
@@ -18,7 +18,7 @@
 #include "basename.h"
 #include "contents.h"
 #include "rmspace.h"
-#include "vdb.h"
+#include "tree.h"
 
 #define QFILE_FLAGS "boRx:S" COMMON_FLAGS
 static struct option const qfile_long_opts[] = {
@@ -74,7 +74,7 @@ struct qfile_opt_state {
  * We assume the people calling us have chdir(/var/db/pkg) and so
  * we use relative paths throughout here.
  */
-static int qfile_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
+static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qfile_opt_state *state = priv;
 	const char *catname = pkg_ctx->cat_ctx->name;
@@ -115,14 +115,14 @@ static int qfile_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 		}
 		if (state->exclude_slot == NULL)
 			goto qlist_done; /* "(CAT/)?(PN|PF)" matches, and no SLOT specified */
-		vdb_pkg_eat(pkg_ctx, "SLOT", &state->buf, &state->buflen);
+		tree_pkg_vdb_eat(pkg_ctx, "SLOT", &state->buf, &state->buflen);
 		rmspace(state->buf);
 		if (strcmp(state->exclude_slot, state->buf) == 0)
 			goto qlist_done; /* "(CAT/)?(PN|PF):SLOT" matches */
 	}
  dont_skip_pkg: /* End of the package exclusion tests. */
 
-	fp = vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS");
+	fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS");
 	if (fp == NULL)
 		goto qlist_done;
 
@@ -227,7 +227,7 @@ static int qfile_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 					/* XXX: This assumes the buf is big enough. */
 					char *slot_hack = slot + 1;
 					size_t slot_len = sizeof(slot) - 1;
-					vdb_pkg_eat(pkg_ctx, "SLOT", &slot_hack, &slot_len);
+					tree_pkg_vdb_eat(pkg_ctx, "SLOT", &slot_hack, &slot_len);
 					rmspace(slot_hack);
 					slot[0] = ':';
 				} else
@@ -478,8 +478,13 @@ int qfile_main(int argc, char **argv)
 	/* Prepare the qfile(...) arguments structure */
 	nb_of_queries = prepare_qfile_args(argc, (const char **) argv, &state);
 	/* Now do the actual `qfile` checking */
-	if (nb_of_queries > 0)
-		found += vdb_foreach_pkg_sorted(portroot, portvdb, qfile_cb, &state);
+	if (nb_of_queries > 0) {
+		tree_ctx *vdb = tree_open_vdb(portroot, portvdb);
+		if (vdb != NULL) {
+			found += tree_foreach_pkg_sorted(vdb, qfile_cb, &state);
+			tree_close(vdb);
+		}
+	}
 
 	if (state.args.non_orphans) {
 		/* display orphan files */

diff --git a/qgrep.c b/qgrep.c
index f38f461..8e240f3 100644
--- a/qgrep.c
+++ b/qgrep.c
@@ -19,8 +19,7 @@
 #include <fcntl.h>
 
 #include "atom.h"
-#include "cache.h"
-#include "vdb.h"
+#include "tree.h"
 #include "xarray.h"
 #include "xchdir.h"
 #include "xregex.h"
@@ -381,14 +380,14 @@ print_after_context:
 }
 
 static int
-qgrep_cache_cb(cache_pkg_ctx *pkg_ctx, void *priv)
+qgrep_cache_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qgrep_grepargs *data = (struct qgrep_grepargs *)priv;
 	char buf[_Q_PATH_MAX];
 	char name[_Q_PATH_MAX];
 	char *label;
 	depend_atom *patom = NULL;
-	cache_ctx *cctx;
+	tree_ctx *cctx;
 	int ret;
 	int pfd;
 
@@ -411,11 +410,11 @@ qgrep_cache_cb(cache_pkg_ctx *pkg_ctx, void *priv)
 	}
 
 	/* need to construct path in portdir to ebuild, pass it to grep */
-	cctx = (cache_ctx *)(pkg_ctx->cat_ctx->ctx);
+	cctx = (tree_ctx *)(pkg_ctx->cat_ctx->ctx);
 	if (cctx->cachetype == CACHE_EBUILD) {
-		pfd = cctx->vdb_fd;
+		pfd = cctx->tree_fd;
 	} else {
-		pfd = openat(cctx->vdb_fd, "../..", O_RDONLY|O_CLOEXEC);
+		pfd = openat(cctx->tree_fd, "../..", O_RDONLY|O_CLOEXEC);
 	}
 
 	/* cat/pkg/pkg-ver.ebuild */
@@ -441,7 +440,7 @@ qgrep_cache_cb(cache_pkg_ctx *pkg_ctx, void *priv)
 }
 
 static int
-qgrep_vdb_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
+qgrep_vdb_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qgrep_grepargs *data = (struct qgrep_grepargs *)priv;
 	char buf[_Q_PATH_MAX];
@@ -687,11 +686,17 @@ int qgrep_main(int argc, char **argv)
 			}
 			closedir(eclass_dir);
 		} else if (do_installed) {
-			status = vdb_foreach_pkg(portroot, portvdb,
-					qgrep_vdb_cb, &args, NULL);
+			tree_ctx *t = tree_open_vdb(portroot, portvdb);
+			if (t != NULL) {
+				status = tree_foreach_pkg_fast(t, qgrep_vdb_cb, &args, NULL);
+				tree_close(t);
+			}
 		} else { /* do_ebuild */
-			status = cache_foreach_pkg(portroot, overlay,
-					qgrep_cache_cb, &args, NULL);
+			tree_ctx *t = tree_open(portroot, overlay);
+			if (t != NULL) {
+				status = tree_foreach_pkg_fast(t, qgrep_cache_cb, &args, NULL);
+				tree_close(t);
+			}
 		}
 	}
 

diff --git a/qkeyword.c b/qkeyword.c
index ef61fba..b9792af 100644
--- a/qkeyword.c
+++ b/qkeyword.c
@@ -18,10 +18,10 @@
 #include <sys/stat.h>
 
 #include "atom.h"
-#include "cache.h"
-#include "scandirat.h"
 #include "rmspace.h"
+#include "scandirat.h"
 #include "set.h"
+#include "tree.h"
 #include "xasprintf.h"
 
 /********************************************************************/
@@ -62,7 +62,7 @@ typedef struct {
 	int *keywordsbuf;
 	size_t keywordsbuflen;
 	const char *arch;
-	cache_pkg_cb *runfunc;
+	tree_pkg_cb *runfunc;
 } qkeyword_data;
 
 static set *archs = NULL;
@@ -214,7 +214,7 @@ qkeyword_vercmp(const struct dirent **x, const struct dirent **y)
 }
 
 static int
-qkeyword_imlate(cache_pkg_ctx *pkg_ctx, void *priv)
+qkeyword_imlate(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	size_t a;
 	qkeyword_data *data = (qkeyword_data *)priv;
@@ -241,7 +241,7 @@ qkeyword_imlate(cache_pkg_ctx *pkg_ctx, void *priv)
 }
 
 static int
-qkeyword_not(cache_pkg_ctx *pkg_ctx, void *priv)
+qkeyword_not(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	size_t a;
 	qkeyword_data *data = (qkeyword_data *)priv;
@@ -266,7 +266,7 @@ qkeyword_not(cache_pkg_ctx *pkg_ctx, void *priv)
 }
 
 static int
-qkeyword_all(cache_pkg_ctx *pkg_ctx, void *priv)
+qkeyword_all(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	qkeyword_data *data = (qkeyword_data *)priv;
 
@@ -282,7 +282,7 @@ qkeyword_all(cache_pkg_ctx *pkg_ctx, void *priv)
 }
 
 static int
-qkeyword_dropped(cache_pkg_ctx *pkg_ctx, void *priv)
+qkeyword_dropped(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	static bool candidate = false;
 	static char pkg1[_Q_PATH_MAX];
@@ -393,7 +393,7 @@ print_seconds_for_earthlings(const unsigned long t)
 }
 
 static int
-qkeyword_stats(cache_pkg_ctx *pkg_ctx, void *priv)
+qkeyword_stats(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	static time_t runtime;
 	static int numpkg  = 0;
@@ -536,7 +536,7 @@ qkeyword_stats(cache_pkg_ctx *pkg_ctx, void *priv)
 }
 
 static int
-qkeyword_testing_only(cache_pkg_ctx *pkg_ctx, void *priv)
+qkeyword_testing_only(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	static bool candidate = false;
 	static char pkg1[_Q_PATH_MAX];
@@ -606,14 +606,14 @@ qkeyword_testing_only(cache_pkg_ctx *pkg_ctx, void *priv)
 }
 
 static int
-qkeyword_results_cb(cache_pkg_ctx *pkg_ctx, void *priv)
+qkeyword_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	int *keywords;
 	qkeyword_data *data = (qkeyword_data *)priv;
 	char buf[_Q_PATH_MAX];
 	depend_atom *patom = NULL;
-	cache_pkg_meta *meta;
-	cache_metadata_xml *metadata;
+	tree_pkg_meta *meta;
+	tree_metadata_xml *metadata;
 	struct elist *emailw;
 	int ret;
 
@@ -638,7 +638,7 @@ qkeyword_results_cb(cache_pkg_ctx *pkg_ctx, void *priv)
 	}
 
 	if (data->qmaint != NULL) {
-		metadata = cache_read_metadata(pkg_ctx);
+		metadata = tree_pkg_metadata(pkg_ctx);
 		if (metadata == NULL)
 			return EXIT_SUCCESS;
 
@@ -650,13 +650,13 @@ qkeyword_results_cb(cache_pkg_ctx *pkg_ctx, void *priv)
 			/* arbitrary pointer to trigger exit below */
 			emailw = (struct elist *)buf;
 
-		cache_close_metadata(metadata);
+		tree_close_metadata(metadata);
 		if (emailw != NULL)
 			return EXIT_SUCCESS;
 	}
 
 	keywords = data->keywordsbuf;
-	meta = cache_pkg_read(pkg_ctx);
+	meta = tree_pkg_read(pkg_ctx);
 	if (meta == NULL) {
 		atom_implode(patom);
 		return EXIT_FAILURE;
@@ -731,7 +731,7 @@ qkeyword_load_arches(const char *overlay)
 }
 
 static int
-qkeyword_traverse(cache_pkg_cb func, void *priv)
+qkeyword_traverse(tree_pkg_cb func, void *priv)
 {
 	int ret;
 	size_t n;
@@ -756,9 +756,14 @@ qkeyword_traverse(cache_pkg_cb func, void *priv)
 
 	data->runfunc = func;
 	ret = 0;
-	array_for_each(overlays, n, overlay)
-		ret |= cache_foreach_pkg_sorted(portroot, overlay,
-				qkeyword_results_cb, priv, NULL, qkeyword_vercmp);
+	array_for_each(overlays, n, overlay) {
+		tree_ctx *t = tree_open(portroot, overlay);
+		if (t != NULL) {
+			ret |= tree_foreach_pkg(t, qkeyword_results_cb, priv,
+					NULL, true, NULL, qkeyword_vercmp);
+			tree_close(t);
+		}
+	}
 
 	return ret;
 }

diff --git a/qlist.c b/qlist.c
index 9314385..abefbcf 100644
--- a/qlist.c
+++ b/qlist.c
@@ -18,7 +18,7 @@
 
 #include "atom.h"
 #include "contents.h"
-#include "vdb.h"
+#include "tree.h"
 #include "xregex.h"
 
 #define QLIST_FLAGS "ISRUcDeados" COMMON_FLAGS
@@ -96,7 +96,7 @@ cmpstringp(const void *p1, const void *p2)
  */
 static char _umapstr_buf[BUFSIZ];
 static const char *
-umapstr(char display, vdb_pkg_ctx *pkg_ctx)
+umapstr(char display, tree_pkg_ctx *pkg_ctx)
 {
 	char *bufp = _umapstr_buf;
 	char *use = NULL;
@@ -115,10 +115,10 @@ umapstr(char display, vdb_pkg_ctx *pkg_ctx)
 	if (!display)
 		return bufp;
 
-	vdb_pkg_eat(pkg_ctx, "USE", &use, &use_len);
+	tree_pkg_vdb_eat(pkg_ctx, "USE", &use, &use_len);
 	if (!use[0])
 		return bufp;
-	vdb_pkg_eat(pkg_ctx, "IUSE", &iuse, &iuse_len);
+	tree_pkg_vdb_eat(pkg_ctx, "IUSE", &iuse, &iuse_len);
 	if (!iuse[0])
 		return bufp;
 
@@ -173,13 +173,13 @@ umapstr(char display, vdb_pkg_ctx *pkg_ctx)
 /* forward declaration necessary for misuse from qmerge.c, see HACK there */
 bool
 qlist_match(
-		vdb_pkg_ctx *pkg_ctx,
+		tree_pkg_ctx *pkg_ctx,
 		const char *name,
 		depend_atom **name_atom,
 		bool exact);
 bool
 qlist_match(
-		vdb_pkg_ctx *pkg_ctx,
+		tree_pkg_ctx *pkg_ctx,
 		const char *name,
 		depend_atom **name_atom,
 		bool exact)
@@ -200,7 +200,7 @@ qlist_match(
 			uslot = NULL;
 		else {
 			if (!pkg_ctx->slot)
-				vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot,
+				tree_pkg_vdb_eat(pkg_ctx, "SLOT", &pkg_ctx->slot,
 						&pkg_ctx->slot_len);
 			uslot_len = strlen(uslot);
 		}
@@ -209,7 +209,7 @@ qlist_match(
 	urepo = strstr(name, "::");
 	if (urepo) {
 		if (!pkg_ctx->repo)
-			vdb_pkg_eat(pkg_ctx, "repository", &pkg_ctx->repo,
+			tree_pkg_vdb_eat(pkg_ctx, "repository", &pkg_ctx->repo,
 					&pkg_ctx->repo_len);
 		urepo += 2;
 		urepo_len = strlen(urepo);
@@ -338,7 +338,7 @@ struct qlist_opt_state {
 };
 
 static int
-qlist_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
+qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qlist_opt_state *state = priv;
 	int i;
@@ -359,7 +359,7 @@ qlist_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 		atom = (verbose ? NULL : atom_explode(pkgname));
 		if ((state->all + state->just_pkgname) < 2) {
 			if (state->show_slots && !pkg_ctx->slot) {
-				vdb_pkg_eat(pkg_ctx, "SLOT",
+				tree_pkg_vdb_eat(pkg_ctx, "SLOT",
 						&pkg_ctx->slot, &pkg_ctx->slot_len);
 				/* chop off the subslot if desired */
 				if (state->show_slots == 1) {
@@ -369,7 +369,7 @@ qlist_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 				}
 			}
 			if (state->show_repo && !pkg_ctx->repo)
-				vdb_pkg_eat(pkg_ctx, "repository",
+				tree_pkg_vdb_eat(pkg_ctx, "repository",
 						&pkg_ctx->repo, &pkg_ctx->repo_len);
 			/* display it */
 			printf("%s%s/%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
@@ -398,7 +398,7 @@ qlist_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 		printf("%s%s/%s%s%s %sCONTENTS%s:\n",
 				BOLD, catname, BLUE, pkgname, NORM, DKBLUE, NORM);
 
-	fp = vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS");
+	fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS");
 	if (fp == NULL)
 		return 1;
 
@@ -444,6 +444,9 @@ qlist_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 
 int qlist_main(int argc, char **argv)
 {
+	int i;
+	int ret;
+	tree_ctx *vdb;
 	struct qlist_opt_state state = {
 		.argc = argc,
 		.argv = argv,
@@ -460,7 +463,6 @@ int qlist_main(int argc, char **argv)
 		.columns = false,
 		.buflen = _Q_PATH_MAX,
 	};
-	int i, ret;
 
 	while ((i = GETOPT_LONG(QLIST, qlist, "")) != -1) {
 		switch (i) {
@@ -489,7 +491,12 @@ int qlist_main(int argc, char **argv)
 
 	state.buf = xmalloc(state.buflen);
 	state.atoms = xcalloc(argc - optind, sizeof(*state.atoms));
-	ret = vdb_foreach_pkg_sorted(portroot, portvdb, qlist_cb, &state);
+	ret = 1;
+	vdb = tree_open_vdb(portroot, portvdb);
+	if (vdb != NULL) {
+		ret = tree_foreach_pkg_sorted(vdb, qlist_cb, &state);
+		tree_close(vdb);
+	}
 	free(state.buf);
 	for (i = optind; i < state.argc; ++i)
 		if (state.atoms[i - optind])

diff --git a/qmerge.c b/qmerge.c
index 41488fa..e6bbdb5 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -30,7 +30,7 @@
 #include "rmspace.h"
 #include "scandirat.h"
 #include "set.h"
-#include "vdb.h"
+#include "tree.h"
 #include "xasprintf.h"
 #include "xchdir.h"
 #include "xmkdir.h"
@@ -118,7 +118,7 @@ typedef struct llist_char_t llist_char;
 
 static void pkg_fetch(int, const depend_atom *, const struct pkg_t *);
 static void pkg_merge(int, const depend_atom *, const struct pkg_t *);
-static int pkg_unmerge(vdb_pkg_ctx *, set *, int, char **, int, char **);
+static int pkg_unmerge(tree_pkg_ctx *, set *, int, char **, int, char **);
 static struct pkg_t *grab_binpkg_info(const char *);
 static char *find_binpkg(const char *);
 
@@ -282,7 +282,7 @@ struct qmerge_bv_state {
 };
 
 static int
-qmerge_filter_cat(vdb_cat_ctx *cat_ctx, void *priv)
+qmerge_filter_cat(tree_cat_ctx *cat_ctx, void *priv)
 {
 	struct qmerge_bv_state *state = priv;
 	return !state->catname || strcmp(cat_ctx->name, state->catname) == 0;
@@ -292,13 +292,13 @@ qmerge_filter_cat(vdb_cat_ctx *cat_ctx, void *priv)
  * should however figure out how to do what match does here from e.g.
  * atom */
 extern bool qlist_match(
-		vdb_pkg_ctx *pkg_ctx,
+		tree_pkg_ctx *pkg_ctx,
 		const char *name,
 		depend_atom **name_atom,
 		bool exact);
 
 static int
-qmerge_best_version_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
+qmerge_best_version_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qmerge_bv_state *state = priv;
 	if (qlist_match(pkg_ctx, state->buf, NULL, true))
@@ -312,6 +312,8 @@ best_version(const char *catname, const char *pkgname, const char *slot)
 {
 	static int vdb_check = 1;
 	static char retbuf[4096];
+
+	tree_ctx *vdb;
 	struct qmerge_bv_state state = {
 		.catname = catname,
 		.pkgname = pkgname,
@@ -338,8 +340,12 @@ best_version(const char *catname, const char *pkgname, const char *slot)
 	retbuf[0] = '\0';
 	snprintf(state.buf, sizeof(state.buf), "%s%s%s:%s",
 		 catname ? : "", catname ? "/" : "", pkgname, slot);
-	vdb_foreach_pkg(portroot, portvdb,
-			qmerge_best_version_cb, &state, qmerge_filter_cat);
+	vdb = tree_open_vdb(portroot, portvdb);
+	if (vdb != NULL) {
+		tree_foreach_pkg_fast(vdb,
+				qmerge_best_version_cb, &state, qmerge_filter_cat);
+		tree_close(vdb);
+	}
 
  done:
 	return retbuf;
@@ -999,8 +1005,8 @@ static void
 pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 {
 	set *objs;
-	vdb_ctx *vdb;
-	vdb_cat_ctx *cat_ctx;
+	tree_ctx *vdb;
+	tree_cat_ctx *cat_ctx;
 	FILE *fp, *contents;
 	static char *phases;
 	static size_t phases_len;
@@ -1122,19 +1128,19 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 	}
 
 	/* Get a handle on the main vdb repo */
-	vdb = vdb_open(portroot, portvdb);
+	vdb = tree_open(portroot, portvdb);
 	if (!vdb)
 		return;
-	cat_ctx = vdb_open_cat(vdb, pkg->CATEGORY);
+	cat_ctx = tree_open_cat(vdb, pkg->CATEGORY);
 	if (!cat_ctx) {
 		if (errno != ENOENT) {
-			vdb_close(vdb);
+			tree_close(vdb);
 			return;
 		}
-		mkdirat(vdb->vdb_fd, pkg->CATEGORY, 0755);
-		cat_ctx = vdb_open_cat(vdb, pkg->CATEGORY);
+		mkdirat(vdb->tree_fd, pkg->CATEGORY, 0755);
+		cat_ctx = tree_open_cat(vdb, pkg->CATEGORY);
 		if (!cat_ctx) {
-			vdb_close(vdb);
+			tree_close(vdb);
 			return;
 		}
 	}
@@ -1345,10 +1351,10 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 	/* TODO: Should see about merging with unmerge_packages() */
 	while (1) {
 		int ret;
-		vdb_pkg_ctx *pkg_ctx;
+		tree_pkg_ctx *pkg_ctx;
 		depend_atom *old_atom;
 
-		pkg_ctx = vdb_next_pkg(cat_ctx);
+		pkg_ctx = tree_next_pkg(cat_ctx);
 		if (!pkg_ctx)
 			break;
 
@@ -1377,7 +1383,7 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 
 		pkg_unmerge(pkg_ctx, objs, cp_argc, cp_argv, cpm_argc, cpm_argv);
  next_pkg:
-		vdb_close_pkg(pkg_ctx);
+		tree_close_pkg(pkg_ctx);
 	}
 
 	freeargv(cp_argc, cp_argv);
@@ -1416,14 +1422,14 @@ pkg_merge(int level, const depend_atom *atom, const struct pkg_t *pkg)
 	printf("%s>>>%s %s%s%s/%s%s%s\n",
 			YELLOW, NORM, WHITE, atom->CATEGORY, NORM, CYAN, atom->PN, NORM);
 
-	vdb_close(vdb);
+	tree_close(vdb);
 }
 
 static int
-pkg_unmerge(vdb_pkg_ctx *pkg_ctx, set *keep,
+pkg_unmerge(tree_pkg_ctx *pkg_ctx, set *keep,
 		int cp_argc, char **cp_argv, int cpm_argc, char **cpm_argv)
 {
-	vdb_cat_ctx *cat_ctx = pkg_ctx->cat_ctx;
+	tree_cat_ctx *cat_ctx = pkg_ctx->cat_ctx;
 	const char *cat = cat_ctx->name;
 	const char *pkgname = pkg_ctx->name;
 	size_t buflen;
@@ -1447,7 +1453,7 @@ pkg_unmerge(vdb_pkg_ctx *pkg_ctx, set *keep,
 		return 0;
 
 	/* First get a handle on the things to clean up */
-	fp = vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS");
+	fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS");
 	if (fp == NULL)
 		return ret;
 
@@ -1455,7 +1461,7 @@ pkg_unmerge(vdb_pkg_ctx *pkg_ctx, set *keep,
 
 	/* Then execute the pkg_prerm step */
 	if (!pretend) {
-		vdb_pkg_eat(pkg_ctx, "DEFINED_PHASES", &phases, &phases_len);
+		tree_pkg_vdb_eat(pkg_ctx, "DEFINED_PHASES", &phases, &phases_len);
 		mkdirat(pkg_ctx->fd, "temp", 0755);
 		pkg_run_func_at(pkg_ctx->fd, ".", phases, "pkg_prerm", T, T);
 	}
@@ -1587,7 +1593,7 @@ pkg_unmerge(vdb_pkg_ctx *pkg_ctx, set *keep,
 		unlinkat(cat_ctx->fd, pkg_ctx->name, AT_REMOVEDIR);
 
 		/* And prune the category if it's empty */
-		unlinkat(cat_ctx->ctx->vdb_fd, cat_ctx->name, AT_REMOVEDIR);
+		unlinkat(cat_ctx->ctx->tree_fd, cat_ctx->name, AT_REMOVEDIR);
 	}
 
 	ret = 0;
@@ -1776,7 +1782,7 @@ print_Pkg(int full, const depend_atom *atom, const struct pkg_t *pkg)
 }
 
 static int
-qmerge_unmerge_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
+qmerge_unmerge_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	int cp_argc;
 	int cpm_argc;
@@ -1804,7 +1810,13 @@ qmerge_unmerge_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 static int
 unmerge_packages(set *todo)
 {
-	return vdb_foreach_pkg(portroot, portvdb, qmerge_unmerge_cb, todo, NULL);
+	tree_ctx *vdb = tree_open_vdb(portroot, portvdb);
+	int ret = 1;
+	if (vdb != NULL) {
+		ret = tree_foreach_pkg_fast(vdb, qmerge_unmerge_cb, todo, NULL);
+		tree_close(vdb);
+	}
+	return ret;
 }
 
 static FILE *
@@ -2315,7 +2327,7 @@ qmerge_add_set(char *buf, set *q)
 	if (strcmp(buf, "world") == 0)
 		return qmerge_add_set_file("/var/lib/portage", "world", q);
 	else if (strcmp(buf, "all") == 0)
-		return get_vdb_atoms(portroot, portvdb, 0);
+		return tree_get_vdb_atoms(portroot, portvdb, 0);
 	else if (strcmp(buf, "system") == 0)
 		return q_profile_walk("packages", qmerge_add_set_system, q);
 	else if (buf[0] == '@')

diff --git a/qpkg.c b/qpkg.c
index b93823b..26c14d1 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -20,13 +20,12 @@
 
 #include "atom.h"
 #include "basename.h"
-#include "cache.h"
 #include "contents.h"
 #include "human_readable.h"
 #include "md5_sha1_sum.h"
 #include "scandirat.h"
 #include "set.h"
-#include "vdb.h"
+#include "tree.h"
 #include "xarray.h"
 #include "xasprintf.h"
 #include "xchdir.h"
@@ -125,7 +124,7 @@ qpkg_clean_dir(char *dirp, set *vdb)
 }
 
 static int
-qpkg_cb(cache_pkg_ctx *pkg_ctx, void *priv)
+qpkg_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	set *vdb = (set *)priv;
 	depend_atom *atom;
@@ -156,14 +155,19 @@ qpkg_clean(char *dirp)
 	if ((count = scandir(".", &dnames, filter_hidden, alphasort)) < 0)
 		return 1;
 
-	vdb = get_vdb_atoms(portroot, portvdb, 1);
+	vdb = tree_get_vdb_atoms(portroot, portvdb, 1);
 
 	if (eclean) {
 		size_t n;
 		const char *overlay;
 
-		array_for_each(overlays, n, overlay)
-			cache_foreach_pkg(portroot, overlay, qpkg_cb, vdb, NULL);
+		array_for_each(overlays, n, overlay) {
+			tree_ctx *t = tree_open(portroot, overlay);
+			if (t != NULL) {
+				tree_foreach_pkg_fast(t, qpkg_cb, vdb, NULL);
+				tree_close(t);
+			}
+		}
 	}
 
 	num_all_bytes = qpkg_clean_dir(dirp, vdb);
@@ -334,9 +338,9 @@ qpkg_make(depend_atom *atom)
 
 int qpkg_main(int argc, char **argv)
 {
-	vdb_ctx *ctx;
-	vdb_cat_ctx *cat_ctx;
-	vdb_pkg_ctx *pkg_ctx;
+	tree_ctx *ctx;
+	tree_cat_ctx *cat_ctx;
+	tree_pkg_ctx *pkg_ctx;
 	size_t s, pkgs_made;
 	int i;
 	struct stat st;
@@ -417,15 +421,15 @@ retry_mkdir:
 	}
 
 	/* now try to run through vdb and locate matches for user inputs */
-	ctx = vdb_open(portroot, portvdb);
+	ctx = tree_open_vdb(portroot, portvdb);
 	if (!ctx)
 		return EXIT_FAILURE;
 
 	/* scan all the categories */
-	while ((cat_ctx = vdb_next_cat(ctx))) {
+	while ((cat_ctx = tree_next_cat(ctx))) {
 		/* scan all the packages in this category */
 		const char *catname = cat_ctx->name;
-		while ((pkg_ctx = vdb_next_pkg(cat_ctx))) {
+		while ((pkg_ctx = tree_next_pkg(cat_ctx))) {
 			const char *pkgname = pkg_ctx->name;
 
 			/* see if user wants any of these packages */
@@ -449,7 +453,7 @@ retry_mkdir:
 			atom_implode(atom);
 
  next_pkg:
-			vdb_close_pkg(pkg_ctx);
+			tree_close_pkg(pkg_ctx);
 		}
 	}
 

diff --git a/qsearch.c b/qsearch.c
index b6d7410..f52a5ff 100644
--- a/qsearch.c
+++ b/qsearch.c
@@ -20,8 +20,8 @@
 
 #include "atom.h"
 #include "basename.h"
-#include "cache.h"
 #include "rmspace.h"
+#include "tree.h"
 #include "xarray.h"
 #include "xregex.h"
 
@@ -57,14 +57,14 @@ struct qsearch_state {
 };
 
 static int
-qsearch_cb(cache_pkg_ctx *pkg_ctx, void *priv)
+qsearch_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	static depend_atom *last_atom;
 
 	struct qsearch_state *state = (struct qsearch_state *)priv;
 	depend_atom *atom;
 	char buf[_Q_PATH_MAX];
-	cache_pkg_meta *meta;
+	tree_pkg_meta *meta;
 	char *desc;
 	char *repo;
 	bool match;
@@ -90,7 +90,7 @@ qsearch_cb(cache_pkg_ctx *pkg_ctx, void *priv)
 	if ((match && (state->show_homepage || state->show_desc)) ||
 			(!match && state->search_desc))
 	{
-		meta = cache_pkg_read(pkg_ctx);
+		meta = tree_pkg_read(pkg_ctx);
 		if (meta != NULL) {
 			if (state->show_homepage)
 				desc = meta->HOMEPAGE;
@@ -115,7 +115,7 @@ qsearch_cb(cache_pkg_ctx *pkg_ctx, void *priv)
 	}
 
 	if (meta != NULL)
-		cache_close_meta(meta);
+		tree_close_meta(meta);
 
 	if (last_atom != NULL)
 		atom_implode(last_atom);
@@ -167,9 +167,13 @@ int qsearch_main(int argc, char **argv)
 	xregcomp(&state.search_expr, search_me, REG_EXTENDED | REG_ICASE);
 
 	/* use sorted order here so the duplicate reduction works reliably */
-	array_for_each(overlays, n, overlay)
-		ret |= cache_foreach_pkg_sorted(portroot, overlay, qsearch_cb,
-				&state, NULL, NULL);
+	array_for_each(overlays, n, overlay) {
+		tree_ctx *t = tree_open(portroot, overlay);
+		if (t != NULL) {
+			ret |= tree_foreach_pkg_sorted(t, qsearch_cb, &state);
+			tree_close(t);
+		}
+	}
 
 	return ret;
 }

diff --git a/qsize.c b/qsize.c
index 4fbbe47..1ae942d 100644
--- a/qsize.c
+++ b/qsize.c
@@ -51,7 +51,7 @@
 #include "atom.h"
 #include "contents.h"
 #include "human_readable.h"
-#include "vdb.h"
+#include "tree.h"
 #include "xarray.h"
 #include "xregex.h"
 
@@ -97,7 +97,7 @@ struct qsize_opt_state {
 };
 
 static int
-qsize_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
+qsize_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qsize_opt_state *state = priv;
 	const char *catname = pkg_ctx->cat_ctx->name;
@@ -126,7 +126,7 @@ qsize_cb(vdb_pkg_ctx *pkg_ctx, void *priv)
 	if (!showit)
 		return EXIT_SUCCESS;
 
-	if ((fp = vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS")) == NULL)
+	if ((fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS")) == NULL)
 		return EXIT_SUCCESS;
 
 	num_ignored = num_files = num_nonfiles = num_bytes = 0;
@@ -181,6 +181,7 @@ int qsize_main(int argc, char **argv)
 {
 	size_t i;
 	int ret;
+	tree_ctx *vdb;
 	DECLARE_ARRAY(ignore_regexp);
 	depend_atom *atom;
 	DECLARE_ARRAY(atoms);
@@ -230,7 +231,11 @@ int qsize_main(int argc, char **argv)
 	state.buflen = _Q_PATH_MAX;
 	state.buf = xmalloc(state.buflen);
 
-	ret = vdb_foreach_pkg(portroot, portvdb, qsize_cb, &state, NULL);
+	vdb = tree_open_vdb(portroot, portvdb);
+	if (vdb != NULL) {
+		ret = tree_foreach_pkg_fast(vdb, qsize_cb, &state, NULL);
+		tree_close(vdb);
+	}
 
 	if (state.summary) {
 		printf(" %sTotals%s: %'zu files, %'zu non-files, ", BOLD, NORM,

diff --git a/quse.c b/quse.c
index 604efdf..6def799 100644
--- a/quse.c
+++ b/quse.c
@@ -21,8 +21,8 @@
 #include <ctype.h>
 #include <assert.h>
 
-#include "cache.h"
 #include "rmspace.h"
+#include "tree.h"
 #include "xarray.h"
 #include "xregex.h"
 
@@ -401,12 +401,12 @@ quse_describe_flag(const char *root, const char *overlay,
 }
 
 static int
-quse_results_cb(cache_pkg_ctx *pkg_ctx, void *priv)
+quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct quse_state *state = (struct quse_state *)priv;
 	depend_atom *atom = NULL;  /* pacify compiler */
 	char buf[8192];
-	cache_pkg_meta *meta;
+	tree_pkg_meta *meta;
 	bool match;
 	char *p;
 	char *q;
@@ -436,7 +436,7 @@ quse_results_cb(cache_pkg_ctx *pkg_ctx, void *priv)
 		}
 	}
 
-	meta = cache_pkg_read(pkg_ctx);
+	meta = tree_pkg_read(pkg_ctx);
 	if (meta == NULL)
 		return 0;
 
@@ -591,7 +591,7 @@ quse_results_cb(cache_pkg_ctx *pkg_ctx, void *priv)
 		}
 	}
 
-	cache_close_meta(meta);
+	tree_close_meta(meta);
 	if (state->match && verbose)
 		atom_implode(atom);
 	if (verbose)
@@ -656,9 +656,12 @@ int quse_main(int argc, char **argv)
 			quse_describe_flag(portroot, overlay, &state);
 	} else {
 		array_for_each(overlays, n, overlay) {
+			tree_ctx *t = tree_open(portroot, overlay);
 			state.overlay = overlay;
-			cache_foreach_pkg_sorted(portroot, overlay,
-					quse_results_cb, &state, NULL, NULL);
+			if (t != NULL) {
+				tree_foreach_pkg_sorted(t, quse_results_cb, &state);
+				tree_close(t);
+			}
 		}
 	}
 


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-06-05  9:15 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-06-05  9:15 UTC (permalink / raw
  To: gentoo-commits

commit:     85c445dbc0d3526ff2df263f1d48dbc67433cd10
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  5 09:14:19 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Jun  5 09:14:19 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=85c445db

libq/atom: retain all input in atom_format_r

Copy the remainder, as well as data before and inbetween expandos.

Bug: https://bugs.gentoo.org/687416
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/atom.c | 3 +--
 qatom.c     | 5 +++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index 5627415..ae781a8 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -645,8 +645,7 @@ atom_format_r(
 	while (*p != '\0') {
 		fmt = strchr(p, '%');
 		if (fmt == NULL) {
-			if (buflen > 0)
-				*buf = '\0';
+			append_buf(buf, buflen, "%s", p);
 			return buf;
 		} else if (fmt != p) {
 			append_buf(buf, buflen, "%.*s", (int)(fmt - p), p);

diff --git a/qatom.c b/qatom.c
index 8825055..c7b6ccf 100644
--- a/qatom.c
+++ b/qatom.c
@@ -4,6 +4,7 @@
  *
  * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2014 Mike Frysinger  - <vapier@gentoo.org>
+ * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
  */
 
 #include "main.h"
@@ -41,9 +42,9 @@ int qatom_main(int argc, char **argv)
 
 	while ((i = GETOPT_LONG(QATOM, qatom, "")) != -1) {
 		switch (i) {
-		case 'F': format = optarg; break;
+		case 'F': format = optarg;   break;
 		case 'c': action = _COMPARE; break;
-		case 'p': action = _PRINT; break;
+		case 'p': action = _PRINT;   break;
 		COMMON_GETOPTS_CASES(qatom)
 		}
 	}


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-06-19 10:44 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-06-19 10:44 UTC (permalink / raw
  To: gentoo-commits

commit:     1089b8baedcd1d6d7aa41e8f5f81938660079e01
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 19 10:43:09 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Jun 19 10:43:09 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1089b8ba

libq/set: drop rmspace for all inputs

Most of the times, rmspace is unnecessary, and doing so, requires a
mutable copy of the data.  If the callers call rmspace when necessary,
set can be a bit more efficient.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md    |  3 ---
 libq/set.c | 17 ++++-------------
 qcheck.c   |  1 -
 qkeyword.c |  7 ++++---
 qmerge.c   | 14 +++++++++-----
 qpkg.c     |  6 ++----
 6 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/TODO.md b/TODO.md
index f9a713b..a319492 100644
--- a/TODO.md
+++ b/TODO.md
@@ -6,9 +6,6 @@
 	- -r (-R ?) regexp foo.\*
 - make default -e for apps like quse/qdepends?
 
-- remove odd rmspace for each string in libq/set.c (allows a lot less
-  malloc/frees)
-
 - make set.c to array (xarray) instead of C-array (list)
 
 - env vars only get expanded once, so this fails:<br>

diff --git a/libq/set.c b/libq/set.c
index de60410..f2c9394 100644
--- a/libq/set.c
+++ b/libq/set.c
@@ -15,7 +15,6 @@
 #include <string.h>
 #include <xalloc.h>
 
-#include "rmspace.h"
 #include "set.h"
 
 static unsigned int
@@ -47,7 +46,6 @@ add_set(const char *name, set *q)
 
 	ll->next = NULL;
 	ll->name = xstrdup(name);
-	rmspace(ll->name);
 	ll->hash = fnv1a32(ll->name);
 
 	pos = ll->hash % _SET_HASH_SIZE;
@@ -77,7 +75,6 @@ add_set_unique(const char *name, set *q, bool *unique)
 	if (q == NULL)
 		q = create_set();
 
-	rmspace(mname);
 	hash = fnv1a32(mname);
 	pos = hash % _SET_HASH_SIZE;
 
@@ -116,27 +113,24 @@ add_set_unique(const char *name, set *q, bool *unique)
 bool
 contains_set(char *s, set *q)
 {
-	char *mname = xstrdup(s);
 	unsigned int hash;
 	int pos;
 	elem *w;
 	bool found;
 
-	rmspace(mname);
-	hash = fnv1a32(mname);
+	hash = fnv1a32(s);
 	pos = hash % _SET_HASH_SIZE;
 
 	found = false;
 	if (q->buckets[pos] != NULL) {
 		for (w = q->buckets[pos]; w != NULL; w = w->next) {
-			if (w->hash == hash && strcmp(w->name, mname) == 0) {
+			if (w->hash == hash && strcmp(w->name, s) == 0) {
 				found = true;
 				break;
 			}
 		}
 	}
 
-	free(mname);
 	return found;
 }
 
@@ -144,22 +138,19 @@ contains_set(char *s, set *q)
 set *
 del_set(char *s, set *q, bool *removed)
 {
-	char *mname = xstrdup(s);
 	unsigned int hash;
 	int pos;
 	elem *ll;
 	elem *w;
 
-	rmspace(mname);
-	hash = fnv1a32(mname);
+	hash = fnv1a32(s);
 	pos = hash % _SET_HASH_SIZE;
 
 	*removed = false;
 	if (q->buckets[pos] != NULL) {
 		ll = NULL;
 		for (w = q->buckets[pos]; w != NULL; ll = w, w = w->next) {
-			if (w->hash == hash && strcmp(w->name, mname) == 0) {
-				free(mname);
+			if (w->hash == hash && strcmp(w->name, s) == 0) {
 				if (ll == NULL) {
 					q->buckets[pos] = w->next;
 				} else {

diff --git a/qcheck.c b/qcheck.c
index 8eb1f08..97070f2 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -19,7 +19,6 @@
 #include "contents.h"
 #include "md5_sha1_sum.h"
 #include "prelink.h"
-#include "set.h"
 #include "tree.h"
 #include "xarray.h"
 #include "xasprintf.h"

diff --git a/qkeyword.c b/qkeyword.c
index fda9b83..9c7187e 100644
--- a/qkeyword.c
+++ b/qkeyword.c
@@ -666,10 +666,11 @@ qkeyword_load_arches(const char *overlay)
 
 	buf = NULL;
 	while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
-		rmspace_len(buf, (size_t)linelen);
-
-		if ((s = strchr(buf, '#')) != NULL)
+		if ((s = strchr(buf, '#')) != NULL) {
 			*s = '\0';
+			linelen = s - buf;
+		}
+		rmspace_len(buf, (size_t)linelen);
 		if (buf[0] == '\0')
 			continue;
 

diff --git a/qmerge.c b/qmerge.c
index 47a6e9b..cb4342c 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -2289,7 +2289,7 @@ parse_packages(set *todo)
 }
 
 static set *
-qmerge_add_set_file(const char *dir, const char *file, set *q)
+qmerge_add_set_file(const char *pfx, const char *dir, const char *file, set *q)
 {
 	FILE *fp;
 	int linelen;
@@ -2297,7 +2297,7 @@ qmerge_add_set_file(const char *dir, const char *file, set *q)
 	char *buf, *fname;
 
 	/* Find the file to read */
-	xasprintf(&fname, "%s%s/%s", portroot, dir, file);
+	xasprintf(&fname, "%s%s%s/%s", portroot, pfx, dir, file);
 
 	if ((fp = fopen(fname, "r")) == NULL) {
 		warnp("unable to read set file %s", fname);
@@ -2348,15 +2348,19 @@ static set *
 qmerge_add_set(char *buf, set *q)
 {
 	if (strcmp(buf, "world") == 0)
-		return qmerge_add_set_file("/var/lib/portage", "world", q);
+		return qmerge_add_set_file(CONFIG_EPREFIX, "/var/lib/portage",
+				"world", q);
 	else if (strcmp(buf, "all") == 0)
 		return tree_get_vdb_atoms(portroot, portvdb, 0);
 	else if (strcmp(buf, "system") == 0)
 		return q_profile_walk("packages", qmerge_add_set_system, q);
 	else if (buf[0] == '@')
-		return qmerge_add_set_file("/etc/portage", buf+1, q);
-	else
+		/* TODO: use configroot */
+		return qmerge_add_set_file(CONFIG_EPREFIX, "/etc/portage", buf+1, q);
+	else {
+		rmspace(buf);
 		return add_set(buf, q);
+	}
 }
 
 static int

diff --git a/qpkg.c b/qpkg.c
index 26c14d1..4063af2 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -127,14 +127,12 @@ static int
 qpkg_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	set *vdb = (set *)priv;
-	depend_atom *atom;
 	char buf[_Q_PATH_MAX];
 
-	snprintf(buf, sizeof(buf), "%s/%s", pkg_ctx->cat_ctx->name, pkg_ctx->name);
-	atom = atom_explode(buf);
-	if (atom == NULL)
+	if (tree_get_atom(pkg_ctx, false) == NULL)
 		return 0;
 
+	snprintf(buf, sizeof(buf), "%s/%s", pkg_ctx->cat_ctx->name, pkg_ctx->name);
 	vdb = add_set(buf, vdb);
 
 	return 1;


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-07-13 10:04 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-07-13 10:04 UTC (permalink / raw
  To: gentoo-commits

commit:     264be8b792d2ddd131d1a52cc1773c60c52a1a51
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 13 10:03:47 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Jul 13 10:03:47 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=264be8b7

libq/tree: rename tree_get_vdb_atoms to tree_get_atoms

in qmerge take advantage of tree_get_atoms to fold the packages for all
trees (overlays) next to vdb contents into one using the same code that
builds the vdb list

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/tree.c | 20 ++++++++------------
 libq/tree.h |  2 +-
 qmerge.c    | 12 +++++++++---
 qpkg.c      | 28 +++++++++-------------------
 4 files changed, 27 insertions(+), 35 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index f4314d0..99e864b 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1042,14 +1042,14 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete)
 	return pkg_ctx->atom;
 }
 
-struct get_vdb_atoms_state {
+struct get_atoms_state {
 	set *cpf;
 	bool fullcpv;
 };
 
-static int tree_get_vdb_atoms_cb(tree_pkg_ctx *pkg_ctx, void *priv)
+static int tree_get_atoms_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
-	struct get_vdb_atoms_state *state = (struct get_vdb_atoms_state *)priv;
+	struct get_atoms_state *state = (struct get_atoms_state *)priv;
 	depend_atom *atom = tree_get_atom(pkg_ctx, false);
 
 	if (state->fullcpv) {
@@ -1063,18 +1063,14 @@ static int tree_get_vdb_atoms_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 }
 
 set *
-tree_get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv)
+tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms)
 {
-	tree_ctx *ctx;
-	struct get_vdb_atoms_state state = {
-		.cpf = NULL,
-		.fullcpv = fullcpv != 0
+	struct get_atoms_state state = {
+		.cpf = satoms,
+		.fullcpv = fullcpv
 	};
 
-	ctx = tree_open_vdb(sroot, svdb);
-	if (!ctx)
-		return NULL;
-	tree_foreach_pkg_fast(ctx, tree_get_vdb_atoms_cb, &state, NULL);
+	tree_foreach_pkg_fast(ctx, tree_get_atoms_cb, &state, NULL);
 	tree_close(ctx);
 
 	return state.cpf;

diff --git a/libq/tree.h b/libq/tree.h
index 36554be..c2a30f1 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -135,7 +135,7 @@ int tree_foreach_pkg(tree_ctx *ctx,
 #define tree_foreach_pkg_sorted(ctx, cb, priv) \
 	tree_foreach_pkg(ctx, cb, priv, NULL, true, NULL, NULL);
 struct dirent *tree_get_next_dir(DIR *dir);
-set *tree_get_vdb_atoms(const char *sroot, const char *svdb, int fullcpv);
+set *tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms);
 depend_atom *tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete);
 
 #endif

diff --git a/qmerge.c b/qmerge.c
index cb4342c..a3686ac 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -2350,9 +2350,15 @@ qmerge_add_set(char *buf, set *q)
 	if (strcmp(buf, "world") == 0)
 		return qmerge_add_set_file(CONFIG_EPREFIX, "/var/lib/portage",
 				"world", q);
-	else if (strcmp(buf, "all") == 0)
-		return tree_get_vdb_atoms(portroot, portvdb, 0);
-	else if (strcmp(buf, "system") == 0)
+	else if (strcmp(buf, "all") == 0) {
+		tree_ctx *ctx = tree_open_vdb(portroot, portvdb);
+		set *ret = NULL;
+		if (ctx != NULL) {
+			ret = tree_get_atoms(ctx, false, NULL);
+			tree_close(ctx);
+		}
+		return ret;
+	} else if (strcmp(buf, "system") == 0)
 		return q_profile_walk("packages", qmerge_add_set_system, q);
 	else if (buf[0] == '@')
 		/* TODO: use configroot */

diff --git a/qpkg.c b/qpkg.c
index 4063af2..2c5a6c3 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -123,21 +123,6 @@ qpkg_clean_dir(char *dirp, set *vdb)
 	return num_all_bytes;
 }
 
-static int
-qpkg_cb(tree_pkg_ctx *pkg_ctx, void *priv)
-{
-	set *vdb = (set *)priv;
-	char buf[_Q_PATH_MAX];
-
-	if (tree_get_atom(pkg_ctx, false) == NULL)
-		return 0;
-
-	snprintf(buf, sizeof(buf), "%s/%s", pkg_ctx->cat_ctx->name, pkg_ctx->name);
-	vdb = add_set(buf, vdb);
-
-	return 1;
-}
-
 /* figure out what dirs we want to process for cleaning and display results. */
 static int
 qpkg_clean(char *dirp)
@@ -146,23 +131,28 @@ qpkg_clean(char *dirp)
 	size_t disp_units = 0;
 	uint64_t num_all_bytes;
 	struct dirent **dnames;
-	set *vdb;
+	set *vdb = NULL;
+	tree_ctx *t;
 
 	if (chdir(dirp) != 0)
 		return 1;
 	if ((count = scandir(".", &dnames, filter_hidden, alphasort)) < 0)
 		return 1;
 
-	vdb = tree_get_vdb_atoms(portroot, portvdb, 1);
+	t = tree_open_vdb(portroot, portvdb);
+	if (t != NULL) {
+		vdb = tree_get_atoms(t, true, vdb);
+		tree_close(t);
+	}
 
 	if (eclean) {
 		size_t n;
 		const char *overlay;
 
 		array_for_each(overlays, n, overlay) {
-			tree_ctx *t = tree_open(portroot, overlay);
+			t = tree_open(portroot, overlay);
 			if (t != NULL) {
-				tree_foreach_pkg_fast(t, qpkg_cb, vdb, NULL);
+				vdb = tree_get_atoms(t, true, vdb);
 				tree_close(t);
 			}
 		}


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-12-27 16:57 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-12-27 16:57 UTC (permalink / raw
  To: gentoo-commits

commit:     deefb1d324ea8e7fc125c0b8b8271da3e3f3f0b3
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 15 14:16:08 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Dec 15 14:16:08 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=deefb1d3

libq/set: have del_set return the old value when set

Allow to easily free a set entry that has a value.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/set.c | 22 ++++++++++++++++------
 libq/set.h |  2 +-
 qmerge.c   |  2 +-
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/libq/set.c b/libq/set.c
index e0ea396..3b56f81 100644
--- a/libq/set.c
+++ b/libq/set.c
@@ -195,19 +195,26 @@ get_set(const char *name, set *q)
 	return NULL;
 }
 
-/* remove elem from a set. matches ->name and frees name,item */
-set *
+/* remove elem from a set. matches ->name and frees name,item, returns
+ * val if removed, NULL otherwise
+ * note that when val isn't set, NULL is returned, so the caller should
+ * use the removed argument to determine if something was removed from
+ * the set. */
+void *
 del_set(const char *s, set *q, bool *removed)
 {
 	unsigned int hash;
 	int pos;
 	elem *ll;
 	elem *w;
+	void *ret;
+	bool rmd;
 
 	hash = fnv1a32(s);
 	pos = hash % _SET_HASH_SIZE;
 
-	*removed = false;
+	ret = NULL;
+	rmd = false;
 	if (q->buckets[pos] != NULL) {
 		ll = NULL;
 		for (w = q->buckets[pos]; w != NULL; ll = w, w = w->next) {
@@ -217,17 +224,20 @@ del_set(const char *s, set *q, bool *removed)
 				} else {
 					ll->next = w->next;
 				}
+				ret = w->val;
 				free(w->name);
 				free(w);
-				*removed = true;
+				rmd = true;
 				break;
 			}
 		}
 	}
 
-	if (*removed)
+	if (rmd)
 		q->len--;
-	return q;
+	if (removed != NULL)
+		*removed = rmd;
+	return ret;
 }
 
 /* return the contents of a set as an array of strings

diff --git a/libq/set.h b/libq/set.h
index 638cc15..8546a90 100644
--- a/libq/set.h
+++ b/libq/set.h
@@ -34,7 +34,7 @@ set *add_set_unique(const char *name, set *q, bool *unique);
 void *add_set_value(const char *name, void *ptr, set *q);
 bool contains_set(const char *name, set *q);
 void *get_set(const char *name, set *q);
-set *del_set(const char *s, set *q, bool *removed);
+void *del_set(const char *s, set *q, bool *removed);
 size_t list_set(set *q, char ***l);
 size_t values_set(set *q, array_t *ret);
 size_t cnt_set(set *q);

diff --git a/qmerge.c b/qmerge.c
index 5b7a298..a2d06ab 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -2341,7 +2341,7 @@ qmerge_add_set_system(void *data, char *buf)
 		q = add_set(s + 1, q);
 	else if (s[0] == '-' && s[1] == '*') {
 		bool ok;
-		q = del_set(s + 2, q, &ok);
+		(void)del_set(s + 2, q, &ok);
 	}
 
 	return q;


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-12-29 13:26 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-12-29 13:26 UTC (permalink / raw
  To: gentoo-commits

commit:     2b91248cfb513dce06368c4485c55fd6746ee642
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 29 13:25:21 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Dec 29 13:25:21 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=2b91248c

libq/tree: remove tree_pkg_vdb_openat as public function

convert the only consumer of tree_pkg_vdb_openat to
tree_pkg_vdb_fopenat, such that we can transparently provide this
functionality for  binpkgs (via xpak).

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/tree.c |  2 +-
 libq/tree.h |  1 -
 qcheck.c    | 30 +++++++++++++-----------------
 3 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index cc8cf3e..f0c8ddb 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -474,7 +474,7 @@ tree_next_pkg(tree_cat_ctx *cat_ctx)
 	return ret;
 }
 
-int
+static int
 tree_pkg_vdb_openat(
 		tree_pkg_ctx *pkg_ctx,
 		const char *file,

diff --git a/libq/tree.h b/libq/tree.h
index d769b7b..aacfb14 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -123,7 +123,6 @@ void tree_close_cat(tree_cat_ctx *cat_ctx);
 int tree_filter_pkg(const struct dirent *de);
 tree_pkg_ctx *tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name);
 tree_pkg_ctx *tree_next_pkg(tree_cat_ctx *cat_ctx);
-int tree_pkg_vdb_openat(tree_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode);
 FILE *tree_pkg_vdb_fopenat(tree_pkg_ctx *pkg_ctx, const char *file,
 	int flags, mode_t mode, const char *fmode);
 #define tree_pkg_vdb_fopenat_ro(pkg_ctx, file) \

diff --git a/qcheck.c b/qcheck.c
index f77a501..ab4356b 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -72,7 +72,6 @@ struct qcheck_opt_state {
 static int
 qcheck_process_contents(tree_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 {
-	int fd_contents;
 	FILE *fp_contents, *fp_contents_update;
 	size_t num_files, num_files_ok, num_files_unknown, num_files_ignored;
 	char *buffer, *line;
@@ -85,18 +84,9 @@ qcheck_process_contents(tree_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 	fp_contents_update = NULL;
 
 	/* Open contents */
-	fd_contents = tree_pkg_vdb_openat(pkg_ctx, "CONTENTS",
-			O_RDONLY | O_CLOEXEC, 0);
-	if (fd_contents == -1)
+	fp_contents = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS");
+	if ((fp_contents = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS")) == NULL)
 		return EXIT_SUCCESS;
-	if (fstat(fd_contents, &cst)) {
-		close(fd_contents);
-		return EXIT_SUCCESS;
-	}
-	if ((fp_contents = fdopen(fd_contents, "r")) == NULL) {
-		close(fd_contents);
-		return EXIT_SUCCESS;
-	}
 
 	/* Open contents_update, if needed */
 	atom = tree_get_atom(pkg_ctx, false);
@@ -322,11 +312,17 @@ qcheck_process_contents(tree_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state)
 	}
 
 	if (state->qc_update) {
-		if (fchown(fd_contents, cst.st_uid, cst.st_gid)) {
-			/* meh */;
-		}
-		if (fchmod(fd_contents, cst.st_mode)) {
-			/* meh */;
+		int fd_contents = fileno(fp_contents);
+		int fd_update = fileno(fp_contents_update);
+
+		/* copy original ownership and mode */
+		if (fstat(fd_contents, &cst) == 0) {
+			if (fchown(fd_update, cst.st_uid, cst.st_gid)) {
+				/* meh */;
+			}
+			if (fchmod(fd_update, cst.st_mode)) {
+				/* meh */;
+			}
 		}
 		fclose(fp_contents_update);
 		if (renameat(pkg_ctx->fd, "CONTENTS~", pkg_ctx->fd, "CONTENTS"))


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-12-30 17:24 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-12-30 17:24 UTC (permalink / raw
  To: gentoo-commits

commit:     c9e89dfa7cc3ae22bc3c731a3d617e4912bd831a
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 17:21:21 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Dec 30 17:21:21 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c9e89dfa

libq/tree: introduce a wrapper for retrieving ebuild metadata

To further hide the difference between trees, add a wrapper around
tree_get_meta, which deals with the underlying storage format.  This is
most notably useful when dealing with vdb-based and binpkgs because they
have a specific or more expensive way of retrieval.  This can now
properly be hidden from the q applets.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/tree.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++++------------
 libq/tree.h |  55 +++++++++++---------
 qdepends.c  |  36 +++++--------
 qkeyword.c  |   6 +--
 qlist.c     |  71 +++-----------------------
 qsearch.c   |  16 ++----
 quse.c      |  71 +++++++++-----------------
 7 files changed, 213 insertions(+), 208 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index d9eec76..bac9d00 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -326,6 +326,7 @@ tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name)
 	pkg_ctx->fd = -1;
 	pkg_ctx->cat_ctx = cat_ctx;
 	pkg_ctx->atom = NULL;
+	pkg_ctx->meta = NULL;
 	return pkg_ctx;
 }
 
@@ -418,8 +419,7 @@ tree_next_pkg(tree_cat_ctx *cat_ctx)
 				tree_ctx *pkgdir = ctx->ebuilddir_ctx;
 
 				if (pkgdir == NULL)
-					pkgdir = ctx->ebuilddir_ctx = xmalloc(sizeof(tree_ctx));
-				memset(ctx->ebuilddir_ctx, '\0', sizeof(*ctx->ebuilddir_ctx));
+					pkgdir = ctx->ebuilddir_ctx = xzalloc(sizeof(tree_ctx));
 
 				ctx->ebuilddir_pkg_ctx = tree_next_pkg_int(cat_ctx);
 				if (ctx->ebuilddir_pkg_ctx == NULL)
@@ -554,13 +554,13 @@ tree_read_file_pms(tree_pkg_ctx *pkg_ctx)
 	if ((off_t)fread(ptr, 1, s.st_size, f) != s.st_size)
 		goto err;
 
-	ret->DEPEND = ptr;
+	ret->Q_DEPEND = ptr;
 #define next_line(curr, next) \
-	if ((ptr = strchr(ret->curr, '\n')) == NULL) { \
+	if ((ptr = strchr(ret->Q_##curr, '\n')) == NULL) { \
 		warn("Invalid cache file for '%s'", buf); \
 		goto err; \
 	} \
-	ret->next = ptr+1; \
+	ret->Q_##next = ptr+1; \
 	*ptr = '\0';
 	next_line(DEPEND, RDEPEND)
 	next_line(RDEPEND, SLOT)
@@ -630,7 +630,7 @@ tree_read_file_md5(tree_pkg_ctx *pkg_ctx)
 	 * */
 #define assign_var_cmp(keyname, cmpkey) \
 	if (strncmp(keyptr, cmpkey, strlen(cmpkey)) == 0) { \
-		ret->keyname = valptr; \
+		ret->Q_##keyname = valptr; \
 		continue; \
 	}
 #define assign_var(keyname) \
@@ -741,7 +741,7 @@ tree_read_file_ebuild(tree_pkg_ctx *pkg_ctx)
 		if (q < p && *p == '=') {
 			*p++ = '\0';
 			/* match variable against which ones we look for */
-#define match_key(X) else if (strcmp(q, #X) == 0) key = &ret->X
+#define match_key(X) else if (strcmp(q, #X) == 0) key = &ret->Q_##X
 			if (1 == 0); /* dummy for syntax */
 			match_key(DEPEND);
 			match_key(RDEPEND);
@@ -840,7 +840,7 @@ tree_read_file_binpkg_xpak_cb(
 
 #define match_path(K) \
 	else if (pathname_len == (sizeof(#K) - 1) && strcmp(pathname, #K) == 0) \
-		key = &m->K
+		key = &m->Q_##K
 	if (1 == 0); /* dummy for syntax */
 	match_path(DEPEND);
 	match_path(RDEPEND);
@@ -868,33 +868,33 @@ tree_read_file_binpkg_xpak_cb(
 #undef match_path
 
 	/* hijack unused members */
-	pos = (size_t)m->_eclasses_;
-	len = (size_t)m->_md5_;
+	pos = (size_t)m->Q__eclasses_;
+	len = (size_t)m->Q__md5_;
 
 	/* trim whitespace (mostly trailing newline) */
 	while (isspace((int)data[data_offset + data_len - 1]))
 		data_len--;
 
 	if (len - pos < (size_t)data_len) {
-		char *old_data = m->_data;
+		char *old_data = m->Q__data;
 		len += (((data_len + 1) / BUFSIZ) + 1) * BUFSIZ;
-		m->_data = xrealloc(m->_data, len);
-		m->_md5_ = (char *)len;
+		m->Q__data = xrealloc(m->Q__data, len);
+		m->Q__md5_ = (char *)len;
 
 		/* re-position existing keys */
-		if (old_data != NULL && m->_data != old_data) {
+		if (old_data != NULL && m->Q__data != old_data) {
 			char **newdata = (char **)m;
 			int elems = sizeof(tree_pkg_meta) / sizeof(char *);
 			while (elems-- > 0)
 				if (newdata[elems] != NULL)
-					newdata[elems] = m->_data + (newdata[elems] - old_data);
+					newdata[elems] = m->Q__data + (newdata[elems] - old_data);
 		}
 	}
 
-	*key = m->_data + pos;
+	*key = m->Q__data + pos;
 	snprintf(*key, len - pos, "%.*s", data_len, data + data_offset);
 	pos += data_len + 1;
-	m->_eclasses_ = (char *)pos;
+	m->Q__eclasses_ = (char *)pos;
 }
 
 static tree_pkg_meta *
@@ -941,7 +941,7 @@ tree_pkg_read(tree_pkg_ctx *pkg_ctx)
 		return (tree_pkg_meta *)pkg_ctx->cat_ctx->ctx->pkgs;
 	}
 
-	warn("Unknown metadata cache type!");
+	warn("Unknown/unsupported metadata cache type!");
 	return NULL;
 }
 
@@ -950,11 +950,101 @@ tree_close_meta(tree_pkg_meta *cache)
 {
 	if (cache == NULL)
 		errf("Cache is empty !");
-	if (cache->_data != NULL)
-		free(cache->_data);
+	if (cache->Q__data != NULL)
+		free(cache->Q__data);
 	free(cache);
 }
 
+char *
+tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char *keyn)
+{
+	tree_ctx *ctx = pkg_ctx->cat_ctx->ctx;
+	char **key;
+
+	/* offset is a byte offset in the tree_pkg_meta struct, pointing to
+	 * key, the tree_pkg_meta_get macro takes care of this */
+
+	if (ctx->cachetype == CACHE_VDB) {
+		if (pkg_ctx->meta == NULL)
+			pkg_ctx->meta = xzalloc(sizeof(tree_pkg_meta));
+
+		key = (char **)((char *)&pkg_ctx->meta->Q__data + offset);
+
+		/* just eat the file if we haven't yet */
+		if (*key == NULL) {
+			int fd = tree_pkg_vdb_openat(pkg_ctx, keyn, O_RDONLY, 0);
+			struct stat s;
+			size_t pos;
+			size_t len;
+			tree_pkg_meta *m = pkg_ctx->meta;
+
+			if (fd < 0)
+				return NULL;
+			if (fstat(fd, &s) != 0 || s.st_size == 0) {
+				close(fd);
+				return NULL;
+			}
+
+			/* hijack unused members */
+			pos = (size_t)m->Q__eclasses_;
+			len = (size_t)m->Q__md5_;
+
+			/* TODO: this is an exact copy from tree_read_file_binpkg_xpak_cb */
+			if (len - pos < (size_t)s.st_size) {
+				char *old_data = m->Q__data;
+				len += (((s.st_size + 1) / BUFSIZ) + 1) * BUFSIZ;
+				m->Q__data = xrealloc(m->Q__data, len);
+				m->Q__md5_ = (char *)len;
+
+				/* re-position existing keys */
+				if (old_data != NULL && m->Q__data != old_data) {
+					char **newdata = (char **)m;
+					int elems = sizeof(tree_pkg_meta) / sizeof(char *);
+					while (elems-- > 0)
+						if (newdata[elems] != NULL)
+							newdata[elems] =
+								m->Q__data + (newdata[elems] - old_data);
+				}
+			}
+
+			if (read(fd, &m->Q__data[pos], s.st_size) == (ssize_t)s.st_size) {
+				char *p = *key = m->Q__data + pos;
+				p[s.st_size] = '\0';
+				while (s.st_size > 0 && isspace((int)p[s.st_size - 1]))
+					p[s.st_size--] = '\0';
+				pos += s.st_size + 1;
+				m->Q__eclasses_ = (char *)pos;
+			}
+			close(fd);
+		}
+	} else {
+		if (pkg_ctx->meta == NULL)
+			pkg_ctx->meta = tree_pkg_read(pkg_ctx);
+		if (pkg_ctx->meta == NULL)
+			return NULL;
+
+		key = (char **)((char *)&pkg_ctx->meta->Q__data + offset);
+
+		/* Packages are nice, but also a bit daft, because they don't
+		 * contain everything available (for a semi-good reason though)
+		 * We cannot downgrade the tree execution to BINPKGS, because
+		 * we're running from tree_foreach_packages */
+		if (*key == NULL && ctx->cachetype == CACHE_PACKAGES) {
+			ctx->cachetype = CACHE_BINPKGS;
+			pkg_ctx->fd = -1;
+			pkg_ctx->meta = tree_pkg_read(pkg_ctx);
+			ctx->cachetype = CACHE_PACKAGES;
+			if (pkg_ctx->meta == NULL) {
+				/* hrmffff. */
+				pkg_ctx->fd = 0;
+				pkg_ctx->meta = tree_pkg_read(pkg_ctx);
+			}
+			key = (char **)((char *)&pkg_ctx->meta->Q__data + offset);
+		}
+	}
+	return *key;
+}
+
 tree_metadata_xml *
 tree_pkg_metadata(tree_pkg_ctx *pkg_ctx)
 {
@@ -1058,6 +1148,9 @@ tree_close_pkg(tree_pkg_ctx *pkg_ctx)
 	if (pkg_ctx->cat_ctx->ctx->do_sort)
 		free((char *)pkg_ctx->name);
 	free(pkg_ctx->slot);
+	if (pkg_ctx->meta != NULL &&
+			(void *)pkg_ctx->meta != (void *)pkg_ctx->cat_ctx->ctx->pkgs)
+		tree_close_meta(pkg_ctx->meta);
 	free(pkg_ctx);
 }
 
@@ -1067,18 +1160,16 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv)
 	char *p = ctx->pkgs;
 	char *q;
 	char *c;
+	char pkgname[_Q_PATH_MAX];
 	size_t len = ctx->pkgslen;
 	int ret = 0;
 
 	/* reused for every entry */
-	tree_cat_ctx *cat = xzalloc(sizeof(tree_cat_ctx));
+	tree_cat_ctx *cat = NULL;
 	tree_pkg_ctx *pkg = xzalloc(sizeof(tree_pkg_ctx));
 	tree_pkg_meta *meta = xzalloc(sizeof(tree_pkg_meta));
 	depend_atom *atom = NULL;
 
-	cat->ctx = ctx;
-	pkg->cat_ctx = cat;
-
 	do {
 		/* find next line */
 		c = NULL;
@@ -1093,15 +1184,26 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv)
 		if (p == q) {
 			/* make callback with populated atom */
 			if (atom != NULL) {
+				size_t pkgnamelen;
+
 				/* store meta ptr in repo->pkgs, such that get_pkg_meta
 				 * can grab it from there (for free) */
 				ctx->pkgs = (char *)meta;
 
-				cat->name = atom->CATEGORY;
-				pkg->name = atom->PN;
-				pkg->slot = meta->SLOT == NULL ? (char *)"0" : meta->SLOT;
+				if (cat == NULL || strcmp(cat->name, atom->CATEGORY) != 0)
+				{
+					if (cat != NULL)
+						tree_close_cat(cat);
+					pkg->cat_ctx = cat = tree_open_cat(ctx, atom->CATEGORY);
+				}
+				pkgnamelen = snprintf(pkgname, sizeof(pkgname), "%s-%s.tbz2",
+						atom->PN, atom->PR_int > 0 ? atom->PVR : atom->PV);
+				pkgname[pkgnamelen - (sizeof(".tbz2") - 1)] = '\0';
+				pkg->name = pkgname;
+				pkg->slot = meta->Q_SLOT == NULL ? (char *)"0" : meta->Q_SLOT;
 				pkg->repo = ctx->repo;
 				pkg->atom = atom;
+				pkg->fd = 0;  /* intentional, meta has already been read */
 
 				/* do call callback with pkg_atom (populate cat and pkg) */
 				ret |= callback(pkg, priv);
@@ -1140,7 +1242,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv)
 #define match_key(X) match_key2(X,X)
 #define match_key2(X,Y) \
 		} else if (strcmp(p, #X) == 0) { \
-			meta->Y = c
+			meta->Q_##Y = c
 		match_key(DEFINED_PHASES);
 		match_key(DEPEND);
 		match_key2(DESC, DESCRIPTION);
@@ -1234,8 +1336,8 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete)
 				if (pkg_ctx->slot == NULL) {
 					meta = tree_pkg_read(pkg_ctx);
 					if (meta != NULL) {
-						if (meta->SLOT != NULL) {
-							pkg_ctx->slot = xstrdup(meta->SLOT);
+						if (meta->Q_SLOT != NULL) {
+							pkg_ctx->slot = xstrdup(meta->Q_SLOT);
 							pkg_ctx->slot_len = strlen(pkg_ctx->slot);
 						}
 					}
@@ -1247,8 +1349,8 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete)
 				if (pkg_ctx->repo == NULL && ctx->cachetype == CACHE_BINPKGS) {
 					if (meta == NULL)
 						meta = tree_pkg_read(pkg_ctx);
-					if (meta != NULL && meta->repository != NULL) {
-						pkg_ctx->repo = xstrdup(meta->repository);
+					if (meta != NULL && meta->Q_repository != NULL) {
+						pkg_ctx->repo = xstrdup(meta->Q_repository);
 						pkg_ctx->repo_len = strlen(pkg_ctx->repo);
 					}
 				}

diff --git a/libq/tree.h b/libq/tree.h
index aacfb14..8a37cbb 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -8,6 +8,7 @@
 
 #include <dirent.h>
 #include <stdbool.h>
+#include <stddef.h>
 
 #include "atom.h"
 #include "set.h"
@@ -67,37 +68,38 @@ struct tree_pkg_ctx {
 	int fd;
 	tree_cat_ctx *cat_ctx;
 	depend_atom *atom;
+	tree_pkg_meta *meta;
 };
 
 /* Ebuild data */
 struct tree_pkg_meta {
-	char *_data;
-	char *DEPEND;        /* line 1 */
-	char *RDEPEND;
-	char *SLOT;
-	char *SRC_URI;
-	char *RESTRICT;      /* line 5 */
-	char *HOMEPAGE;
-	char *LICENSE;
-	char *DESCRIPTION;
-	char *KEYWORDS;
-	char *INHERITED;     /* line 10 */
-	char *IUSE;
-	char *CDEPEND;
-	char *PDEPEND;
-	char *PROVIDE;       /* line 14 */
-	char *EAPI;
-	char *PROPERTIES;
+	char *Q__data;
+	char *Q_DEPEND;        /* line 1 */
+	char *Q_RDEPEND;
+	char *Q_SLOT;
+	char *Q_SRC_URI;
+	char *Q_RESTRICT;      /* line 5 */
+	char *Q_HOMEPAGE;
+	char *Q_LICENSE;
+	char *Q_DESCRIPTION;
+	char *Q_KEYWORDS;
+	char *Q_INHERITED;     /* line 10 */
+	char *Q_IUSE;
+	char *Q_CDEPEND;
+	char *Q_PDEPEND;
+	char *Q_PROVIDE;       /* line 14 */
+	char *Q_EAPI;
+	char *Q_PROPERTIES;
 	/* These are MD5-Cache only */
-	char *DEFINED_PHASES;
-	char *REQUIRED_USE;
-	char *BDEPEND;
-	char *_eclasses_;
-	char *_md5_;
+	char *Q_DEFINED_PHASES;
+	char *Q_REQUIRED_USE;
+	char *Q_BDEPEND;
+	char *Q__eclasses_;
+	char *Q__md5_;
 	/* binpkgs/vdb */
-	char *CONTENTS;
-	char *USE;
-	char *repository;
+	char *Q_CONTENTS;
+	char *Q_USE;
+	char *Q_repository;
 };
 
 /* Metadata.xml */
@@ -132,6 +134,9 @@ FILE *tree_pkg_vdb_fopenat(tree_pkg_ctx *pkg_ctx, const char *file,
 bool tree_pkg_vdb_eat(tree_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *buflen);
 tree_pkg_meta *tree_pkg_read(tree_pkg_ctx *pkg_ctx);
 void tree_close_meta(tree_pkg_meta *cache);
+char *tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char *key);
+#define tree_pkg_meta_get(P,X) \
+	tree_pkg_meta_get_int(P, offsetof(tree_pkg_meta, Q_##X), #X)
 tree_metadata_xml *tree_pkg_metadata(tree_pkg_ctx *pkg_ctx);
 void tree_close_metadata(tree_metadata_xml *meta_ctx);
 void tree_close_pkg(tree_pkg_ctx *pkg_ctx);

diff --git a/qdepends.c b/qdepends.c
index 6f89835..9969d90 100644
--- a/qdepends.c
+++ b/qdepends.c
@@ -114,7 +114,6 @@ qdepends_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	int ret = 0;
 	dep_node *dep_tree;
 	char **d;
-	tree_pkg_meta *meta = NULL;
 	char *depstr;
 
 	/* matrix consists of:
@@ -155,27 +154,17 @@ qdepends_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	xarrayfree_int(state->deps);
 	clear_set(state->udeps);
 
-	if (state->qmode & QMODE_TREE)
-		if ((meta = tree_pkg_read(pkg_ctx)) == NULL)
-			return ret;
 	dfile = depend_files;
 	for (i = QMODE_DEPEND; i <= QMODE_BDEPEND; i <<= 1, dfile++) {
 		if (!(state->qmode & i))
 			continue;
 
-		if (state->qmode & QMODE_INSTALLED) {
-			if (!tree_pkg_vdb_eat(pkg_ctx, *dfile,
-						&state->depend, &state->depend_len))
-				continue;
-			depstr = state->depend;
-		} else {
-			depstr = i == 1<<0 ? meta->DEPEND :
-					 i == 1<<1 ? meta->RDEPEND :
-					 i == 1<<2 ? meta->PDEPEND :
-					 i == 1<<3 ? meta->BDEPEND : NULL;
-			if (depstr == NULL)
-				continue;
-		}
+		depstr = i == 1<<0 ? tree_pkg_meta_get(pkg_ctx, DEPEND) :
+				 i == 1<<1 ? tree_pkg_meta_get(pkg_ctx, RDEPEND) :
+				 i == 1<<2 ? tree_pkg_meta_get(pkg_ctx, PDEPEND) :
+				 i == 1<<3 ? tree_pkg_meta_get(pkg_ctx, BDEPEND) : NULL;
+		if (depstr == NULL)
+			continue;
 		dep_tree = dep_grow_tree(depstr);
 		if (dep_tree == NULL)
 			continue;
@@ -188,10 +177,13 @@ qdepends_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 				tree_pkg_ctx *vpkg =
 					tree_open_pkg(vcat, pkg_ctx->name);
 				if (vpkg != NULL) {
-					if (tree_pkg_vdb_eat(vpkg, *dfile,
-							&state->depend, &state->depend_len))
-					{
-						dep_node *dep_vdb = dep_grow_tree(state->depend);
+					depstr = i == 1<<0 ? tree_pkg_meta_get(vpkg, DEPEND) :
+							 i == 1<<1 ? tree_pkg_meta_get(vpkg, RDEPEND) :
+							 i == 1<<2 ? tree_pkg_meta_get(vpkg, PDEPEND) :
+							 i == 1<<3 ? tree_pkg_meta_get(vpkg, BDEPEND) :
+							 NULL;
+					if (depstr != NULL) {
+						dep_node *dep_vdb = dep_grow_tree(depstr);
 						if (dep_vdb != NULL)
 							dep_flatten_tree(dep_vdb, state->deps);
 					}
@@ -299,8 +291,6 @@ int qdepends_main(int argc, char **argv)
 		.deps = deps,
 		.udeps = create_set(),
 		.qmode = 0,
-		.depend = NULL,
-		.depend_len = 0,
 		.format = "%[CATEGORY]%[PF]",
 		.vdb = NULL,
 	};

diff --git a/qkeyword.c b/qkeyword.c
index 4e84ebd..70f75de 100644
--- a/qkeyword.c
+++ b/qkeyword.c
@@ -643,7 +643,6 @@ qkeyword_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	qkeyword_data *data = (qkeyword_data *)priv;
 	char buf[_Q_PATH_MAX];
 	depend_atom *patom = NULL;
-	tree_pkg_meta *meta;
 	tree_metadata_xml *metadata;
 	struct elist *emailw;
 	int ret;
@@ -679,11 +678,8 @@ qkeyword_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	}
 
 	keywords = data->keywordsbuf;
-	meta = tree_pkg_read(pkg_ctx);
-	if (meta == NULL)
-		return EXIT_FAILURE;
 
-	if (read_keywords(meta->KEYWORDS, keywords) < 0) {
+	if (read_keywords(tree_pkg_meta_get(pkg_ctx, KEYWORDS), keywords) < 0) {
 		if (verbose)
 			warn("Failed to read keywords for %s%s/%s%s%s",
 				BOLD, pkg_ctx->cat_ctx->name, BLUE, pkg_ctx->name, NORM);

diff --git a/qlist.c b/qlist.c
index 3f20ced..1d4862f 100644
--- a/qlist.c
+++ b/qlist.c
@@ -329,45 +329,14 @@ struct qlist_opt_state {
 	const char *fmt;
 };
 
-struct qlist_xpakcbctx {
-	const char *key;
-	char *retdata;
-	size_t retlen;
-};
-
-static void
-_qlist_xpakcb(
-	void *ctx,
-	char *pathname,
-	int pathname_len,
-	int data_offset,
-	int data_len,
-	char *data)
-{
-	struct qlist_xpakcbctx *xctx = ctx;
-	(void)pathname_len;
-
-	/* see if this path matches what we're looking for */
-	if (strcmp(pathname, xctx->key) != 0)
-		return;
-
-	xctx->retdata = xrealloc(xctx->retdata, data_len + 1);
-	memcpy(xctx->retdata, data + data_offset, data_len + 1);
-	xctx->retlen = data_len;
-}
-
 static int
 qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
 	struct qlist_opt_state *state = priv;
 	int i;
-	FILE *fp;
+	char *contents;
+	char *line;
 	depend_atom *atom;
-	struct qlist_xpakcbctx cbctx = {
-		.key = "CONTENTS",
-		.retdata = NULL,
-		.retlen = 0,
-	};
 
 	/* see if this cat/pkg is requested */
 	if (!state->all) {
@@ -392,38 +361,15 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 		printf("%s %sCONTENTS%s:\n",
 				atom_format(state->fmt, atom), DKBLUE, NORM);
 
-	if (state->do_binpkgs) {
-		char xpak[_Q_PATH_MAX];
-		int ret;
-		snprintf(xpak, sizeof(xpak), "%s/%s/%s/%s-%s.tbz2",
-				portroot, pkgdir, atom->CATEGORY, atom->PN,
-				atom->PR_int > 0 ? atom->PVR : atom->PV);
-		ret = xpak_extract(xpak, &cbctx, &_qlist_xpakcb);
-		if (ret != 0 || cbctx.retdata == NULL)
-			fp = NULL;
-		else
-#ifdef HAVE_FMEMOPEN
-			fp = fmemopen(cbctx.retdata, cbctx.retlen, "r");
-#else
-		{
-			/* resort to writing a file in tmpspace */
-			fp = tmpfile();
-			if (fp != NULL) {
-				fwrite(cbctx.retdata, 1, cbctx.retlen, fp);
-				fseek(fp, 0, SEEK_SET);
-			}
-		}
-#endif
-	} else {
-		fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS");
-	}
-	if (fp == NULL)
+	if ((contents = tree_pkg_meta_get(pkg_ctx, CONTENTS)) == NULL)
 		return 1;
 
-	while (getline(&state->buf, &state->buflen, fp) != -1) {
+	while ((line = strtok(contents, "\n")) != NULL) {
 		contents_entry *e;
 
-		e = contents_parse_line(state->buf);
+		contents = NULL;  /* for strtok */
+
+		e = contents_parse_line(line);
 		if (!e)
 			continue;
 
@@ -455,9 +401,6 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 				break;
 		}
 	}
-	fclose(fp);
-	if (state->do_binpkgs && cbctx.retdata != NULL)
-		free(cbctx.retdata);
 
 	return 1;
 }

diff --git a/qsearch.c b/qsearch.c
index d6470f6..a26e2d6 100644
--- a/qsearch.c
+++ b/qsearch.c
@@ -66,7 +66,6 @@ qsearch_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 
 	struct qsearch_state *state = (struct qsearch_state *)priv;
 	depend_atom *atom;
-	tree_pkg_meta *meta;
 	char *desc;
 	bool match;
 
@@ -84,17 +83,13 @@ qsearch_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 		match = true;
 
 	desc = NULL;
-	meta = NULL;
 	if ((match && (state->show_homepage || state->show_desc)) ||
 			(!match && state->search_desc))
 	{
-		meta = tree_pkg_read(pkg_ctx);
-		if (meta != NULL) {
-			if (state->show_homepage)
-				desc = meta->HOMEPAGE;
-			else if (state->show_desc)
-				desc = meta->DESCRIPTION;
-		}
+		if (state->show_homepage)
+			desc = tree_pkg_meta_get(pkg_ctx, HOMEPAGE);
+		else if (state->show_desc)
+			desc = tree_pkg_meta_get(pkg_ctx, DESCRIPTION);
 	}
 
 	if (!match && state->search_desc && desc != NULL &&
@@ -109,9 +104,6 @@ qsearch_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 				(state->show_name ? "" : desc ? desc : ""));
 	}
 
-	if (meta != NULL)
-		tree_close_meta(meta);
-
 	if (last_atom != NULL)
 		atom_implode(last_atom);
 	last_atom = atom;

diff --git a/quse.c b/quse.c
index df8626e..be34e48 100644
--- a/quse.c
+++ b/quse.c
@@ -412,7 +412,6 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 	struct quse_state *state = (struct quse_state *)priv;
 	depend_atom *atom = NULL;  /* pacify compiler */
 	char buf[8192];
-	tree_pkg_meta *meta;
 	set *use = NULL;
 	bool match;
 	char *p;
@@ -439,52 +438,38 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 		}
 	}
 
-	if (state->overlay != NULL) {
-		meta = tree_pkg_read(pkg_ctx);
-		if (meta == NULL)
+	if (!state->do_licence) {
+		if (tree_pkg_meta_get(pkg_ctx, IUSE) == NULL)
 			return 0;
-		if (meta->IUSE == NULL)
-			return 0;
-	} else {
-		size_t dummy;
-
-		meta = xzalloc(sizeof(*meta));
 
-		dummy = 0;
-		if (!tree_pkg_vdb_eat(pkg_ctx, "IUSE", &meta->IUSE, &dummy)) {
-			free(meta);
-			return 0;
+		if (state->do_describe) {
+			portdirfd = openat(pkg_ctx->cat_ctx->ctx->portroot_fd,
+					state->overlay == NULL ? main_overlay : state->overlay,
+					O_RDONLY | O_CLOEXEC | O_PATH);
+			if (portdirfd == -1)
+				return 0;
 		}
 
-		dummy = 0;
-		tree_pkg_vdb_eat(pkg_ctx, "LICENSE", &meta->LICENSE, &dummy);
-
-		s = NULL;
-		dummy = 0;
-		tree_pkg_vdb_eat(pkg_ctx, "USE", &s, &dummy);
-		p = s;
-		while ((q = strchr(p, (int)' ')) != NULL) {
-			*q++ = '\0';
-			use = add_set(p, use);
-			p = q;
+		/* available when dealing with VDB or binpkgs */
+		if ((p = tree_pkg_meta_get(pkg_ctx, USE)) != NULL) {
+			while ((q = strchr(p, (int)' ')) != NULL) {
+				*q++ = '\0';
+				use = add_set(p, use);
+				p = q;
+			}
+			if (*p != '\0')
+				use = add_set(p, use);
 		}
-		if (*p != '\0')
-			use = add_set(p, use);
-		free(s);
-	}
-
-	if (state->do_describe) {
-		portdirfd = openat(pkg_ctx->cat_ctx->ctx->portroot_fd,
-				state->overlay == NULL ? main_overlay : state->overlay,
-				O_RDONLY | O_CLOEXEC | O_PATH);
-		if (portdirfd == -1)
+	} else {
+		if (tree_pkg_meta_get(pkg_ctx, LICENSE) == NULL)
 			return 0;
 	}
 
 	maxlen = 0;
 	cnt = 0;
 	match = false;
-	q = p = state->do_licence ? meta->LICENSE : meta->IUSE;
+	q = p = state->do_licence ?
+		tree_pkg_meta_get(pkg_ctx, LICENSE) : tree_pkg_meta_get(pkg_ctx, IUSE);
 	buf[0] = '\0';
 	v = buf;
 	w = buf + sizeof(buf);
@@ -567,7 +552,7 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 
 			printf("%s\n", atom_format(state->fmt, atom));
 
-			q = p = meta->IUSE;
+			q = p = tree_pkg_meta_get(pkg_ctx, IUSE);
 			buf[0] = '\0';
 			v = buf;
 			w = buf + sizeof(buf);
@@ -652,16 +637,8 @@ quse_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 		}
 	}
 
-	if (state->overlay != NULL) {
-		tree_close_meta(meta);
-	} else {
-		free(meta->IUSE);
-		if (meta->LICENSE != NULL)
-			free(meta->LICENSE);
-		free(meta);
-		if (use != NULL)
-			free_set(use);
-	}
+	if (use != NULL)
+		free_set(use);
 	if (state->do_describe)
 		close(portdirfd);
 


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2019-12-31  9:05 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2019-12-31  9:05 UTC (permalink / raw
  To: gentoo-commits

commit:     acd6354c5f3b1e771bbba9cb4738c264f9e11af3
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 19:03:30 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Dec 30 19:03:30 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=acd6354c

libq/atom: slightly improve atom_explode

Use malloc iso zalloc and only clear the struct bit of the allocation.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md     | 5 -----
 libq/atom.c | 5 +++--
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/TODO.md b/TODO.md
index f4775eb..b0bac64 100644
--- a/TODO.md
+++ b/TODO.md
@@ -21,17 +21,12 @@
 
 - implement our own iniparser so we *can* be dep-free
 
-- add applet/functionality to view latest version of package in tree
-  (functionality necessary for upgrade in qmerge, easy printing would
-  also allow to use q instead of eix from Puppet provider)
-
 # Atoms
 
 - only 32bit values are supported for revision (-r#)
 - only 64bit values are supported in any individual version component
   foo-(1234)\_alpha(56789)
 - these limits should not be an issue for all practical purposes
-- remove zalloc from atom explode (just initialise what needs to)
 - make PVR match PMS https://dev.gentoo.org/~ulm/pms/head/pms.html#x1-10800011
 
 # qmerge

diff --git a/libq/atom.c b/libq/atom.c
index 6f65c8b..05b138c 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -54,8 +54,9 @@ atom_explode(const char *atom)
 	 * PVR needs 3 extra bytes for possible implicit '-r0'. */
 	slen = strlen(atom);
 	len = sizeof(*ret) + (slen + 1) * sizeof(*atom) * 3 + 3;
-	ret = xzalloc(len);
-	ptr = (char*)ret;
+	ret = xmalloc(len);
+	memset(ret, '\0', sizeof(*ret));
+	ptr = (char *)ret;
 	ret->P = ptr + sizeof(*ret);
 	ret->PVR = ret->P + slen + 1;
 	ret->CATEGORY = ret->PVR + slen + 1 + 3;


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2020-01-01 19:52 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2020-01-01 19:52 UTC (permalink / raw
  To: gentoo-commits

commit:     6d6c6c1c7c066ce642b58190c4d6df5a6e5e1a40
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Jan  1 19:52:01 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Jan  1 19:52:01 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=6d6c6c1c

libq/dep: fix parsing of USE-deps

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md    |  3 ---
 libq/dep.c | 14 +++++++++++---
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/TODO.md b/TODO.md
index cd4f2b2..191e91c 100644
--- a/TODO.md
+++ b/TODO.md
@@ -48,9 +48,6 @@
 
 # qdepends
 
-- add -S/-v/-R behavior like qlist #574934
-- bring back -k?  (but seems solved by using qlist -IF%{SLOT} pkg)
-- -Qt acts weird (if not, incorrect)
 - -v should lookup whether packages are installed for || cases/colouring
 
 # qpkg

diff --git a/libq/dep.c b/libq/dep.c
index 49edf10..0507326 100644
--- a/libq/dep.c
+++ b/libq/dep.c
@@ -110,7 +110,8 @@ dep_grow_tree(const char *depend)
 
 #define _maybe_consume_word(t) \
 	do { \
-		if (!word) break; \
+		if (word == NULL) \
+			break; \
 		new_node = _dep_grow_node(t, word, ptr-word); \
 		if (!ret) \
 			ret = curr_node = new_node; \
@@ -124,8 +125,8 @@ dep_grow_tree(const char *depend)
 	} while (0)
 
 	saw_whitespace = true;
-	for (ptr = depend; *ptr; ++ptr) {
-		if (isspace(*ptr)) {
+	for (ptr = depend; *ptr != '\0'; ptr++) {
+		if (isspace((int)*ptr)) {
 			saw_whitespace = true;
 			_maybe_consume_word(DEP_NORM);
 			continue;
@@ -185,6 +186,13 @@ dep_grow_tree(const char *depend)
 			curr_attach = _DEP_NEIGH;
 			break;
 		}
+		case '[': {
+			/* USE-dep, seek to matching ']', since they cannot be
+			 * nested, this is simple */
+			while (*ptr != '\0' && *ptr != ']')
+				ptr++;
+			break;
+		}
 		default:
 			if (!word)
 				word = ptr;


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2020-01-02 11:19 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2020-01-02 11:19 UTC (permalink / raw
  To: gentoo-commits

commit:     24e232b949803a0d650387c61eb32c95d7270647
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Jan  2 11:17:53 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Jan  2 11:17:53 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=24e232b9

libq/tree: have tree_foreach_pkg take a query atom

Allow to reduce the search by having a query atom.  This will skip
categories and packages not matching the atom, possibly avoiding lots of
work.

This needs to be exploited from applets where necessary.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md     |  2 --
 libq/tree.c | 79 +++++++++++++++++++++++++++++++++++++++++++++----------------
 libq/tree.h | 21 +++++++---------
 qcheck.c    |  4 ++--
 qdepends.c  |  4 ++--
 qfile.c     |  4 ++--
 qkeyword.c  |  4 ++--
 qlist.c     |  2 +-
 qmerge.c    | 65 +++++++++++++++++---------------------------------
 qsearch.c   |  4 ++--
 quse.c      |  6 ++---
 11 files changed, 103 insertions(+), 92 deletions(-)

diff --git a/TODO.md b/TODO.md
index d89dda1..71a0ce1 100644
--- a/TODO.md
+++ b/TODO.md
@@ -9,8 +9,6 @@
   `ACCEPT_LICENSE="${ACCEPT_LICENSE} bar"`<br>
   we end up getting just:<br>
   `ACCEPT_LICENSE=" bar"`
-- tree\_foreach\_pkg should have variant that takes an atom (or just
-  cat?) to reduce search space
 - tree\_get\_atoms should return atoms iso string set, needs a rewrite
   to use foreach\_pkg and get\_atom -- set is ready for storing objects
   now

diff --git a/libq/tree.c b/libq/tree.c
index 377af83..8996e55 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -57,8 +57,6 @@ tree_open_int(const char *sroot, const char *tdir, bool quiet)
 		goto cv_error;
 
 	ctx->do_sort = false;
-	ctx->catsortfunc = alphasort;
-	ctx->pkgsortfunc = tree_pkg_compar;
 	return ctx;
 
  cv_error:
@@ -237,23 +235,31 @@ tree_next_cat(tree_ctx *ctx)
 {
 	/* search for a category directory */
 	tree_cat_ctx *cat_ctx = NULL;
+	const struct dirent *de;
 
 	if (ctx->do_sort) {
 		if (ctx->cat_de == NULL) {
 			ctx->cat_cnt = scandirat(ctx->tree_fd,
-					".", &ctx->cat_de, tree_filter_cat, ctx->catsortfunc);
+					".", &ctx->cat_de, tree_filter_cat, alphasort);
 			ctx->cat_cur = 0;
 		}
 
 		while (ctx->cat_cur < ctx->cat_cnt) {
-			cat_ctx = tree_open_cat(ctx, ctx->cat_de[ctx->cat_cur++]->d_name);
+			de = ctx->cat_de[ctx->cat_cur++];
+
+			/* match if cat is requested */
+			if (ctx->query_atom != NULL && ctx->query_atom->CATEGORY != NULL &&
+					strcmp(ctx->query_atom->CATEGORY, de->d_name) != 0)
+				continue;
+
+			cat_ctx = tree_open_cat(ctx, de->d_name);
 			if (!cat_ctx)
 				continue;
+
 			break;
 		}
 	} else {
 		/* cheaper "streaming" variant */
-		const struct dirent *de;
 		do {
 			de = readdir(ctx->dir);
 			if (!de)
@@ -262,6 +268,11 @@ tree_next_cat(tree_ctx *ctx)
 			if (tree_filter_cat(de) == 0)
 				continue;
 
+			/* match if cat is requested */
+			if (ctx->query_atom != NULL && ctx->query_atom->CATEGORY != NULL &&
+					strcmp(ctx->query_atom->CATEGORY, de->d_name) != 0)
+				continue;
+
 			cat_ctx = tree_open_cat(ctx, de->d_name);
 			if (!cat_ctx)
 				continue;
@@ -327,6 +338,17 @@ tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name)
 	pkg_ctx->cat_ctx = cat_ctx;
 	pkg_ctx->atom = NULL;
 	pkg_ctx->meta = NULL;
+
+	/* see if this pkg matches the query, here we can finally check
+	 * version conditions like >=, etc. */
+	if (cat_ctx->ctx->query_atom != NULL) {
+		(void)tree_get_atom(pkg_ctx, false);
+		if (atom_compare(pkg_ctx->atom, cat_ctx->ctx->query_atom) != EQUAL) {
+			tree_close_pkg(pkg_ctx);
+			return NULL;
+		}
+	}
+
 	return pkg_ctx;
 }
 
@@ -348,6 +370,7 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx)
 {
 	tree_pkg_ctx *pkg_ctx = NULL;
 	const struct dirent *de;
+	depend_atom *qa = cat_ctx->ctx->query_atom;
 
 	if (cat_ctx->ctx->do_sort) {
 		if (cat_ctx->pkg_ctxs == NULL) {
@@ -360,11 +383,22 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx)
 				if (tree_filter_pkg(de) == 0)
 					continue;
 
+				/* perform package name check, for we don't have an atom
+				 * yet, and creating it is expensive, which we better
+				 * defer to pkg time, and filter most stuff out here
+				 * note that we might over-match, but that's easier than
+				 * trying to deal with end of string or '-' here (which
+				 * still wouldn't be 100% because name rules are complex) */
+				if (qa != NULL && qa->PN != NULL &&
+						strncmp(qa->PN, de->d_name, strlen(qa->PN)) != 0)
+					continue;
+
 				if (cat_ctx->pkg_cnt == pkg_size) {
 					pkg_size += 256;
 					cat_ctx->pkg_ctxs = xrealloc(cat_ctx->pkg_ctxs,
 								sizeof(*cat_ctx->pkg_ctxs) * pkg_size);
 				}
+
 				name = xstrdup(de->d_name);
 				pkg_ctx = cat_ctx->pkg_ctxs[cat_ctx->pkg_cnt++] =
 					tree_open_pkg(cat_ctx, name);
@@ -374,9 +408,9 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx)
 				}
 			}
 
-			if (cat_ctx->ctx->pkgsortfunc != NULL && cat_ctx->pkg_cnt > 1) {
+			if (cat_ctx->pkg_cnt > 1) {
 				qsort(cat_ctx->pkg_ctxs, cat_ctx->pkg_cnt,
-						sizeof(*cat_ctx->pkg_ctxs), cat_ctx->ctx->pkgsortfunc);
+						sizeof(*cat_ctx->pkg_ctxs), tree_pkg_compar);
 			}
 		}
 
@@ -392,6 +426,11 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx)
 			if (tree_filter_pkg(de) == 0)
 				continue;
 
+			/* perform package name check as for the sorted variant */
+			if (qa != NULL && qa->PN != NULL &&
+					strncmp(qa->PN, de->d_name, strlen(qa->PN)) != 0)
+				continue;
+
 			pkg_ctx = tree_open_pkg(cat_ctx, de->d_name);
 			if (!pkg_ctx)
 				continue;
@@ -428,8 +467,6 @@ tree_next_pkg(tree_cat_ctx *cat_ctx)
 				pkgdir->portroot_fd = -1;
 				pkgdir->tree_fd = cat_ctx->fd;
 				pkgdir->do_sort = ctx->do_sort;
-				pkgdir->catsortfunc = ctx->catsortfunc;
-				pkgdir->pkgsortfunc = ctx->pkgsortfunc;
 				pkgdir->repo = ctx->repo;
 				pkgdir->cachetype = ctx->cachetype;
 
@@ -440,7 +477,7 @@ tree_next_pkg(tree_cat_ctx *cat_ctx)
 				 * directory or something */
 				if (ctx->ebuilddir_cat_ctx == NULL) {
 					ctx->ebuilddir_pkg_ctx = NULL;
-					return NULL;
+					continue;
 				}
 
 				/* "zap" the pkg such that it looks like CAT/P */
@@ -1155,7 +1192,8 @@ tree_close_pkg(tree_pkg_ctx *pkg_ctx)
 }
 
 static int
-tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv)
+tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback,
+		void *priv, depend_atom *query)
 {
 	char *p = ctx->pkgs;
 	char *q;
@@ -1239,6 +1277,11 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv)
 			if (atom != NULL)
 				atom_implode(atom);
 			atom = atom_explode(c);
+			/* pretend this entry is bogus if it doesn't match query */
+			if (query != NULL && atom_compare(atom, query) != EQUAL) {
+				atom_implode(atom);
+				atom = NULL;
+			}
 #define match_key(X) match_key2(X,X)
 #define match_key2(X,Y) \
 		} else if (strcmp(p, #X) == 0) { \
@@ -1270,9 +1313,8 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv)
 }
 
 int
-tree_foreach_pkg(tree_ctx *ctx,
-		tree_pkg_cb callback, void *priv, tree_cat_filter filter,
-		bool sort, void *catsortfunc, void *pkgsortfunc)
+tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, void *priv,
+		bool sort, depend_atom *query)
 {
 	tree_cat_ctx *cat_ctx;
 	tree_pkg_ctx *pkg_ctx;
@@ -1283,18 +1325,12 @@ tree_foreach_pkg(tree_ctx *ctx,
 
 	/* handle Packages (binpkgs index) file separately */
 	if (ctx->cachetype == CACHE_PACKAGES)
-		return tree_foreach_packages(ctx, callback, priv);
+		return tree_foreach_packages(ctx, callback, priv, query);
 
 	ctx->do_sort = sort;
-	if (catsortfunc != NULL)
-		ctx->catsortfunc = catsortfunc;
-	if (pkgsortfunc != NULL)
-		ctx->pkgsortfunc = pkgsortfunc;
 
 	ret = 0;
 	while ((cat_ctx = tree_next_cat(ctx))) {
-		if (filter && !filter(cat_ctx, priv))
-			continue;
 		while ((pkg_ctx = tree_next_pkg(cat_ctx))) {
 			ret |= callback(pkg_ctx, priv);
 			tree_close_pkg(pkg_ctx);
@@ -1319,6 +1355,7 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete)
 		tree_ctx *ctx = pkg_ctx->cat_ctx->ctx;
 		if (ctx->cachetype == CACHE_VDB) {
 			if (pkg_ctx->atom->SLOT == NULL) {
+				/* FIXME: use tree_meta_get !!! */
 				if (pkg_ctx->slot == NULL)
 					tree_pkg_vdb_eat(pkg_ctx, "SLOT",
 							&pkg_ctx->slot, &pkg_ctx->slot_len);

diff --git a/libq/tree.h b/libq/tree.h
index 8a37cbb..eb60296 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  */
 
@@ -27,8 +27,6 @@ struct tree_ctx {
 	struct dirent **cat_de;
 	size_t cat_cnt;
 	size_t cat_cur;
-	void *catsortfunc;
-	void *pkgsortfunc;
 	bool do_sort:1;
 	enum {
 		CACHE_UNSET = 0,
@@ -45,6 +43,7 @@ struct tree_ctx {
 	char *repo;
 	char *pkgs;
 	size_t pkgslen;
+	depend_atom *query_atom;
 };
 
 /* Category context */
@@ -110,9 +109,8 @@ struct tree_metadata_xml {
 	} *email;
 };
 
-/* Global helpers */
+/* foreach pkg callback function signature */
 typedef int (tree_pkg_cb)(tree_pkg_ctx *, void *priv);
-typedef int (tree_cat_filter)(tree_cat_ctx *, void *priv);
 
 tree_ctx *tree_open(const char *sroot, const char *portdir);
 tree_ctx *tree_open_vdb(const char *sroot, const char *svdb);
@@ -140,13 +138,12 @@ char *tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char *ke
 tree_metadata_xml *tree_pkg_metadata(tree_pkg_ctx *pkg_ctx);
 void tree_close_metadata(tree_metadata_xml *meta_ctx);
 void tree_close_pkg(tree_pkg_ctx *pkg_ctx);
-int tree_foreach_pkg(tree_ctx *ctx,
-		tree_pkg_cb callback, void *priv, tree_cat_filter filter,
-		bool sort, void *catsortfunc, void *pkgsortfunc);
-#define tree_foreach_pkg_fast(ctx, cb, priv, filter) \
-	tree_foreach_pkg(ctx, cb, priv, filter, false, NULL, NULL);
-#define tree_foreach_pkg_sorted(ctx, cb, priv) \
-	tree_foreach_pkg(ctx, cb, priv, NULL, true, NULL, NULL);
+int tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, void *priv,
+		bool sort, depend_atom *query);
+#define tree_foreach_pkg_fast(ctx, cb, priv, query) \
+	tree_foreach_pkg(ctx, cb, priv, false, query);
+#define tree_foreach_pkg_sorted(ctx, cb, priv, query) \
+	tree_foreach_pkg(ctx, cb, priv, true, query);
 struct dirent *tree_get_next_dir(DIR *dir);
 set *tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms);
 depend_atom *tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete);

diff --git a/qcheck.c b/qcheck.c
index ab4356b..66a4ee7 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -434,7 +434,7 @@ int qcheck_main(int argc, char **argv)
 	vdb = tree_open_vdb(portroot, portvdb);
 	ret = -1;
 	if (vdb != NULL) {
-		ret = tree_foreach_pkg_sorted(vdb, qcheck_cb, &state);
+		ret = tree_foreach_pkg_sorted(vdb, qcheck_cb, &state, NULL);
 		tree_close(vdb);
 	}
 	if (array_cnt(regex_arr) > 0) {

diff --git a/qdepends.c b/qdepends.c
index 9969d90..44821b6 100644
--- a/qdepends.c
+++ b/qdepends.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Authors
+ * Copyright 2005-2020 Gentoo Authors
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -376,7 +376,7 @@ int qdepends_main(int argc, char **argv)
 			t = tree_open(portroot, overlay);
 			if (t != NULL) {
 				ret = tree_foreach_pkg_sorted(t,
-						qdepends_results_cb, &state);
+						qdepends_results_cb, &state, NULL);
 				tree_close(t);
 			}
 		}

diff --git a/qfile.c b/qfile.c
index b1aab8d..0b01061 100644
--- a/qfile.c
+++ b/qfile.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -569,7 +569,7 @@ int qfile_main(int argc, char **argv)
 	if (nb_of_queries > 0) {
 		tree_ctx *vdb = tree_open_vdb(portroot, portvdb);
 		if (vdb != NULL) {
-			found += tree_foreach_pkg_sorted(vdb, qfile_cb, &state);
+			found += tree_foreach_pkg_sorted(vdb, qfile_cb, &state, NULL);
 			tree_close(vdb);
 		}
 	}

diff --git a/qkeyword.c b/qkeyword.c
index 70f75de..f777960 100644
--- a/qkeyword.c
+++ b/qkeyword.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2006      Thomas A. Cort - <tcort@gentoo.org>
@@ -799,7 +799,7 @@ qkeyword_traverse(tree_pkg_cb func, void *priv)
 	array_for_each(overlays, n, overlay) {
 		tree_ctx *t = tree_open(portroot, overlay);
 		if (t != NULL) {
-			ret |= tree_foreach_pkg_sorted(t, qkeyword_results_cb, priv);
+			ret |= tree_foreach_pkg_sorted(t, qkeyword_results_cb, priv, NULL);
 			tree_close(t);
 		}
 	}

diff --git a/qlist.c b/qlist.c
index f77eaea..12d63f8 100644
--- a/qlist.c
+++ b/qlist.c
@@ -494,7 +494,7 @@ int qlist_main(int argc, char **argv)
 	else
 		vdb = tree_open_vdb(portroot, portvdb);
 	if (vdb != NULL) {
-		ret = tree_foreach_pkg_sorted(vdb, qlist_cb, &state);
+		ret = tree_foreach_pkg_sorted(vdb, qlist_cb, &state, NULL);
 		tree_close(vdb);
 	}
 	free(state.buf);

diff --git a/qmerge.c b/qmerge.c
index a2d06ab..6d9439f 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Authors
+ * Copyright 2005-2020 Gentoo Authors
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -272,37 +272,15 @@ qmerge_initialize(void)
 	free(buf);
 }
 
-struct qmerge_bv_state {
-	const char *catname;
-	const char *pkgname;
-	const char *slot;
-	char buf[4096];
-	char *retbuf;
-};
-
-static int
-qmerge_filter_cat(tree_cat_ctx *cat_ctx, void *priv)
-{
-	struct qmerge_bv_state *state = priv;
-	return !state->catname || strcmp(cat_ctx->name, state->catname) == 0;
-}
-
-/* HACK: pull this in, knowing that qlist will be in the final link, we
- * should however figure out how to do what match does here from e.g.
- * atom */
-extern bool qlist_match(
-		tree_pkg_ctx *pkg_ctx,
-		const char *name,
-		depend_atom **name_atom,
-		bool exact);
-
+static char _best_version_retbuf[4096];
 static int
 qmerge_best_version_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {
-	struct qmerge_bv_state *state = priv;
-	if (qlist_match(pkg_ctx, state->buf, NULL, true))
-		snprintf(state->retbuf, sizeof(state->buf), "%s/%s:%s",
-			 pkg_ctx->cat_ctx->name, pkg_ctx->name, state->slot);
+	depend_atom *sa = priv;
+	depend_atom *a = tree_get_atom(pkg_ctx, true);  /* need SLOT */
+	if (atom_compare(a, sa) == EQUAL)
+		snprintf(_best_version_retbuf, sizeof(_best_version_retbuf),
+				"%s/%s:%s", a->CATEGORY, a->PF, a->SLOT);
 	return 0;
 }
 
@@ -310,15 +288,7 @@ static char *
 best_version(const char *catname, const char *pkgname, const char *slot)
 {
 	static int vdb_check = 1;
-	static char retbuf[4096];
-
 	tree_ctx *vdb;
-	struct qmerge_bv_state state = {
-		.catname = catname,
-		.pkgname = pkgname,
-		.slot = slot,
-		.retbuf = retbuf,
-	};
 
 	/* Make sure these dirs exist before we try walking them */
 	switch (vdb_check) {
@@ -336,18 +306,18 @@ best_version(const char *catname, const char *pkgname, const char *slot)
 			goto done;
 	}
 
-	retbuf[0] = '\0';
-	snprintf(state.buf, sizeof(state.buf), "%s%s%s:%s",
-		 catname ? : "", catname ? "/" : "", pkgname, slot);
+	snprintf(_best_version_retbuf, sizeof(_best_version_retbuf),
+			"%s%s%s:%s", catname ? : "", catname ? "/" : "", pkgname, slot);
 	vdb = tree_open_vdb(portroot, portvdb);
 	if (vdb != NULL) {
-		tree_foreach_pkg_fast(vdb,
-				qmerge_best_version_cb, &state, qmerge_filter_cat);
+		depend_atom *sa = atom_explode(_best_version_retbuf);
+		tree_foreach_pkg_fast(vdb, qmerge_best_version_cb, sa, sa);
 		tree_close(vdb);
+		atom_implode(sa);
 	}
 
  done:
-	return retbuf;
+	return _best_version_retbuf;
 }
 
 static int
@@ -1810,6 +1780,15 @@ print_Pkg(int full, const depend_atom *atom, const struct pkg_t *pkg)
 	}
 }
 
+/* HACK: pull this in, knowing that qlist will be in the final link, we
+ * should however figure out how to do what match does here from e.g.
+ * atom */
+extern bool qlist_match(
+		tree_pkg_ctx *pkg_ctx,
+		const char *name,
+		depend_atom **name_atom,
+		bool exact);
+
 static int
 qmerge_unmerge_cb(tree_pkg_ctx *pkg_ctx, void *priv)
 {

diff --git a/qsearch.c b/qsearch.c
index a26e2d6..31b183c 100644
--- a/qsearch.c
+++ b/qsearch.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Authors
+ * Copyright 2005-2020 Gentoo Authors
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -174,7 +174,7 @@ int qsearch_main(int argc, char **argv)
 	array_for_each(overlays, n, overlay) {
 		tree_ctx *t = tree_open(portroot, overlay);
 		if (t != NULL) {
-			ret |= tree_foreach_pkg_sorted(t, qsearch_cb, &state);
+			ret |= tree_foreach_pkg_sorted(t, qsearch_cb, &state, NULL);
 			tree_close(t);
 		}
 	}

diff --git a/quse.c b/quse.c
index be34e48..a8585be 100644
--- a/quse.c
+++ b/quse.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -719,14 +719,14 @@ int quse_main(int argc, char **argv)
 	} else if (state.do_installed) {
 		tree_ctx *t = tree_open_vdb(portroot, portvdb);
 		state.overlay = NULL;
-		tree_foreach_pkg_sorted(t, quse_results_cb, &state);
+		tree_foreach_pkg_sorted(t, quse_results_cb, &state, NULL);
 		tree_close(t);
 	} else {
 		array_for_each(overlays, n, overlay) {
 			tree_ctx *t = tree_open(portroot, overlay);
 			state.overlay = overlay;
 			if (t != NULL) {
-				tree_foreach_pkg_sorted(t, quse_results_cb, &state);
+				tree_foreach_pkg_sorted(t, quse_results_cb, &state, NULL);
 				tree_close(t);
 			}
 		}


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2020-01-05 13:28 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2020-01-05 13:28 UTC (permalink / raw
  To: gentoo-commits

commit:     394c245a4ecbce18ab580228311f3f6023727727
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Jan  5 13:25:46 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Jan  5 13:27:50 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=394c245a

Revert "libq/tree: ignore Packages file when seemingly outdated"

A surprisingly bad idea.  Since Packages is a member of the dir we're
looking at to compare, it's never going to have newer or equal mtime.

This reverts commit 8b4086e7e32e3e548929fa532056a65188f8def8.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md     |  1 +
 libq/tree.c | 18 ++----------------
 2 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/TODO.md b/TODO.md
index f6326b8..fe74cab 100644
--- a/TODO.md
+++ b/TODO.md
@@ -15,6 +15,7 @@
 - parse package.accept\_keywords such that we can provide the latest
   "available" version like Portage
 - check timestamps in libq/tree for choosing which method to take:
+	- ignore Packages when it is older than the last directory change
 	- ignore metadata when ebuild is modified
 	- add some method to skip these checks and assume everything is right
 - add interface to retrieve a list/set of atoms from a tree

diff --git a/libq/tree.c b/libq/tree.c
index 976f166..49b2fa1 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -133,25 +133,11 @@ tree_open_binpkg(const char *sroot, const char *spkg)
 	char buf[_Q_PATH_MAX];
 
 	if (ret != NULL) {
-		struct stat st;
-		struct timespec pkgstim;
-
 		ret->cachetype = CACHE_BINPKGS;
 
 		snprintf(buf, sizeof(buf), "%s%s/%s", sroot, spkg, binpkg_packages);
-		if (eat_file(buf, &ret->pkgs, &ret->pkgslen)) {
-			if (stat(buf, &st) == 0)
-				memcpy(&pkgstim, &st.st_mtim, sizeof(st.st_mtim));
-			else
-				memset(&pkgstim, 0, sizeof(pkgstim));
-
-			/* if the Packages file seems outdated, don't trust/use it */
-			if (fstat(ret->tree_fd, &st) != 0 ||
-					st.st_mtim.tv_sec < pkgstim.tv_sec ||  /* impossible? */
-					(st.st_mtim.tv_sec == pkgstim.tv_sec &&
-					 st.st_mtim.tv_nsec <= pkgstim.tv_nsec))
-				ret->cachetype = CACHE_PACKAGES;
-		}
+		if (eat_file(buf, &ret->pkgs, &ret->pkgslen))
+			ret->cachetype = CACHE_PACKAGES;
 	}
 
 	return ret;


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2020-02-21  8:18 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2020-02-21  8:18 UTC (permalink / raw
  To: gentoo-commits

commit:     814f9ad4b3bfe41617e21f634b6facb84c2e1dfe
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Feb 21 08:17:09 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Feb 21 08:17:09 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=814f9ad4

libq/tree: respect SLOT in query atom for tree_open_pkg

Bug: https://bugs.gentoo.org/710372
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md     | 1 -
 libq/tree.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/TODO.md b/TODO.md
index 2cce64a..43c4d6a 100644
--- a/TODO.md
+++ b/TODO.md
@@ -46,7 +46,6 @@
 - support TTL field in binpkgs file
 - merge duplicate atoms on the CLI (`qmerge -Uq nano nano nano`)
 - unmerging should clean out @world set
-- test should work on local vdb (so TRAVIS can test it too)
 - fixup lame misnaming of force\_download (--fetch/--force) actually
   not-forcing things
 - use xpak.h instead of shelling out to qxpak binary

diff --git a/libq/tree.c b/libq/tree.c
index 1c2a54e..ebcc133 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -398,7 +398,7 @@ tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name)
 	/* see if this pkg matches the query, here we can finally check
 	 * version conditions like >=, etc. */
 	if (cat_ctx->ctx->query_atom != NULL) {
-		(void)tree_get_atom(pkg_ctx, false);
+		(void)tree_get_atom(pkg_ctx, cat_ctx->ctx->query_atom->SLOT != NULL);
 		if (atom_compare(pkg_ctx->atom, cat_ctx->ctx->query_atom) != EQUAL) {
 			tree_close_pkg(pkg_ctx);
 			return NULL;


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2021-08-16 13:23 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2021-08-16 13:23 UTC (permalink / raw
  To: gentoo-commits

commit:     18c65792094cb90b6876940b86a35e21e3da488c
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 16 13:21:57 2021 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Aug 16 13:21:57 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=18c65792

libq/atom: introduce atom_compare_flg

atom_compare_flg allows to give match behaviour flags, such that often
used exceptions can now be handled without having to modify the input
atoms.

atom_compare is now a macro calling atom_compare_flg with
flags=ATOM_COMP_DEFAULT.

Updated all callers that can use this feature.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/atom.c | 50 ++++++++++++++++++++++++++++----------------------
 libq/atom.h | 10 +++++++++-
 qlop.c      | 19 +++++++++----------
 qmerge.c    | 17 +++--------------
 quse.c      |  8 +++-----
 5 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index f4c7c1e..0959be5 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -514,7 +514,7 @@ _atom_compare_match(int ret, atom_operator op)
  * foo-1 <NOT_EQUAL> bar-1
  */
 atom_equality
-atom_compare(const depend_atom *data, const depend_atom *query)
+atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags)
 {
 	atom_operator pfx_op;
 	atom_operator sfx_op;
@@ -551,27 +551,32 @@ atom_compare(const depend_atom *data, const depend_atom *query)
 	 */
 	bl_op = query->blocker;
 	if (bl_op == ATOM_BL_ANTISLOT) {
-		/* ^perl -> match anything with a SLOT */
-		if (query->SLOT == NULL && data->SLOT == NULL)
-			return NOT_EQUAL;
-		if (query->SLOT != NULL) {
-			if (query->SUBSLOT == NULL) {
-				/* ^perl:0 -> match different SLOT */
-				if (data->SLOT == NULL ||
-						strcmp(query->SLOT, data->SLOT) == 0)
-					return NOT_EQUAL;
-			} else {
-				/* ^perl:0/5.28 -> match SLOT, but different SUBSLOT */
-				if (data->SLOT == NULL ||
-						strcmp(query->SLOT, data->SLOT) != 0)
-					return NOT_EQUAL;
-				if (data->SUBSLOT == NULL ||
-						strcmp(query->SUBSLOT, data->SUBSLOT) == 0)
-					return NOT_EQUAL;
+		/* just disable/ignore antislot op when SLOT is supposed to be
+		 * ignored */
+		if (!(flags & ATOM_COMP_NOSLOT)) {
+			/* ^perl -> match anything with a SLOT */
+			if (query->SLOT == NULL && data->SLOT == NULL)
+				return NOT_EQUAL;
+			if (query->SLOT != NULL) {
+				if (query->SUBSLOT == NULL || flags & ATOM_COMP_NOSUBSLOT) {
+					/* ^perl:0 -> match different SLOT */
+					if (data->SLOT == NULL ||
+							strcmp(query->SLOT, data->SLOT) == 0)
+						return NOT_EQUAL;
+				} else {
+					/* ^perl:0/5.28 -> match SLOT, but different SUBSLOT */
+					if (data->SLOT == NULL ||
+							strcmp(query->SLOT, data->SLOT) != 0)
+						return NOT_EQUAL;
+					if (!(flags & ATOM_COMP_NOSUBSLOT))
+						if (data->SUBSLOT == NULL ||
+								strcmp(query->SUBSLOT, data->SUBSLOT) == 0)
+							return NOT_EQUAL;
+				}
 			}
 		}
 		bl_op = ATOM_BL_NONE;  /* ease work below */
-	} else if (query->SLOT != NULL) {
+	} else if (query->SLOT != NULL && !(flags & ATOM_COMP_NOSLOT)) {
 		/* check SLOT only when query side has it */
 		if (data->SLOT == NULL) {
 			if (bl_op == ATOM_BL_NONE)
@@ -581,7 +586,7 @@ atom_compare(const depend_atom *data, const depend_atom *query)
 				/* slot has differs */
 				if (bl_op == ATOM_BL_NONE)
 					return NOT_EQUAL;
-			} else {
+			} else if (!(flags & ATOM_COMP_NOSUBSLOT)) {
 				if (query->SUBSLOT != NULL) {
 					if (data->SUBSLOT == NULL) {
 						if (bl_op == ATOM_BL_NONE)
@@ -623,7 +628,7 @@ atom_compare(const depend_atom *data, const depend_atom *query)
 	}
 
 	/* check REPO, if query has it, ignore blocker stuff for this one */
-	if (query->REPO != NULL) {
+	if (query->REPO != NULL && !(flags & ATOM_COMP_NOREPO)) {
 		if (data->REPO == NULL)
 			return NOT_EQUAL;
 		if (strcmp(query->REPO, data->REPO) != 0)
@@ -753,8 +758,9 @@ atom_compare(const depend_atom *data, const depend_atom *query)
 		return EQUAL;
 
 	/* Make sure the -r# is the same. */
-	if ((sfx_op == ATOM_OP_STAR && !query->PR_int) ||
+	if ((sfx_op == ATOM_OP_STAR && query->PR_int == 0) ||
 	    pfx_op == ATOM_OP_PV_EQUAL ||
+		flags & ATOM_COMP_NOREV ||
 	    data->PR_int == query->PR_int)
 		return _atom_compare_match(EQUAL, pfx_op);
 	else if (data->PR_int < query->PR_int)

diff --git a/libq/atom.h b/libq/atom.h
index ead9154..8291daf 100644
--- a/libq/atom.h
+++ b/libq/atom.h
@@ -96,11 +96,19 @@ typedef enum {
 	OLDER
 } atom_equality;
 
+/* bitflags to control compare behaviour */
+#define ATOM_COMP_DEFAULT    (0<<0)
+#define ATOM_COMP_NOREV      (1<<0)
+#define ATOM_COMP_NOSLOT     (1<<1)
+#define ATOM_COMP_NOSUBSLOT  (1<<2)
+#define ATOM_COMP_NOREPO     (1<<3)
+
 depend_atom *atom_explode_cat(const char *atom, const char *cat);
 #define atom_explode(A) atom_explode_cat(A, NULL)
 depend_atom *atom_clone(depend_atom *atom);
 void atom_implode(depend_atom *atom);
-atom_equality atom_compare(const depend_atom *a1, const depend_atom *a2);
+atom_equality atom_compare_flg(const depend_atom *a1, const depend_atom *a2, int flags);
+#define atom_compare(A,B) atom_compare_flg(A, B, ATOM_COMP_DEFAULT)
 atom_equality atom_compare_str(const char * const s1, const char * const s2);
 char *atom_to_string_r(char *buf, size_t buflen, depend_atom *a);
 char *atom_format_r(char *buf, size_t buflen,

diff --git a/qlop.c b/qlop.c
index 4783528..0e381bd 100644
--- a/qlop.c
+++ b/qlop.c
@@ -593,7 +593,7 @@ static int do_emerge_log(
 			continue;
 
 		/* are we interested in this line? */
-		if (flags->show_emerge && verbose && (strpfx(p, "  *** emerge ") == 0))
+		if (flags->show_emerge && verbose && p[7] == 'm' /* emerge */)
 		{
 			char shortopts[8];  /* must hold as many opts converted below */
 			int numopts = 0;
@@ -753,15 +753,17 @@ static int do_emerge_log(
 				/* see if we need this atom */
 				atomw = NULL;
 				if (atomset == NULL) {
-					int orev = atom->PR_int;
-					if (flags->do_predict)
-						atom->PR_int = 0;  /* allow matching a revision */
+					/* match without revisions when we try to predict,
+					 * such that our set remains rich enough to cover
+					 * various predictions */
 					array_for_each(atoms, i, atomw) {
-						if (atom_compare(atom, atomw) == EQUAL)
+						if (atom_compare_flg(atom, atomw,
+									flags->do_predict
+									? ATOM_COMP_NOREV
+									: ATOM_COMP_DEFAULT) == EQUAL)
 							break;
 						atomw = NULL;
 					}
-					atom->PR_int = orev;
 				} else {
 					snprintf(afmt, sizeof(afmt), "%s/%s",
 							atom->CATEGORY, atom->PN);
@@ -1229,11 +1231,8 @@ static int do_emerge_log(
 
 			array_for_each(avgs, j, pkg) {
 				if (pkgstate == P_INIT) {
-					int orev = pkg->atom->PR_int;
 					atom_equality eq;
-					pkg->atom->PR_int = 0;
-					eq = atom_compare(pkg->atom, atom);
-					pkg->atom->PR_int = orev;
+					eq = atom_compare_flg(pkg->atom, atom, ATOM_COMP_NOREV);
 					switch (eq) {
 						case EQUAL:
 							/* version-less atoms equal any versioned

diff --git a/qmerge.c b/qmerge.c
index a624b89..cf511ad 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1095,23 +1095,12 @@ pkg_merge(int level, const depend_atom *qatom, const tree_match_ctx *mpkg)
 
 	previnst = best_version(slotatom, BV_INSTALLED);
 	if (previnst != NULL) {
-		char *orepo;
-		char *osubslot;
-
 		/* drop REPO and SUBSLOT from query, we don't care about where
 		 * the replacement comes from here, SUBSLOT only affects rebuild
 		 * triggering */
-		orepo                   = previnst->atom->REPO;
-		osubslot                = previnst->atom->SUBSLOT;
-		previnst->atom->REPO    = NULL;
-		previnst->atom->SUBSLOT = NULL;
-
-		replacing               = atom_compare(mpkg->atom, previnst->atom);
-		replver                 = previnst->atom->PVR;
-
-		/* restore atom for later printing/handling */
-		previnst->atom->REPO    = orepo;
-		previnst->atom->SUBSLOT = osubslot;
+		replacing = atom_compare_flg(mpkg->atom, previnst->atom,
+				ATOM_COMP_NOSUBSLOT | ATOM_COMP_NOREPO);
+		replver   = previnst->atom->PVR;
 	}
 
 	(void)qprint_tree_node(level, mpkg, previnst, replacing);

diff --git a/quse.c b/quse.c
index 400339a..ad0d9a2 100644
--- a/quse.c
+++ b/quse.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2020 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -140,11 +140,9 @@ quse_search_use_local_desc(int portdirfd, struct quse_state *state)
 			if ((atom = atom_explode(buf)) == NULL)
 				continue;
 
-			atom->REPO = (char *)state->repo;
-			if (state->match != NULL)
-				atom->SLOT = state->match->SLOT;  /* fake match */
 			if (state->match == NULL ||
-					atom_compare(atom, state->match) == EQUAL)
+					atom_compare_flg(atom, state->match,
+						ATOM_COMP_NOSLOT | ATOM_COMP_NOREPO) == EQUAL)
 			{
 				if (state->do_list) {
 					state->retv[i] = xstrdup(q);


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2023-02-07  8:10 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2023-02-07  8:10 UTC (permalink / raw
  To: gentoo-commits

commit:     e2ebb44db31d4e0e9bfc0a9974d36eff63c8b2b1
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Feb  7 08:08:13 2023 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Feb  7 08:08:13 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e2ebb44d

set: ensure NULL is empty behaviour is retained throughout

Not all set functions respected NULL is empty behaviour, changed
add_set_value signature to return a set instead so it can conform.

Bug: https://bugs.gentoo.org/893424
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/set.c  | 47 +++++++++++++++++++++++++++++++++++++++--------
 libq/set.h  |  4 ++--
 libq/tree.c |  5 +++--
 main.c      |  6 ++++--
 qkeyword.c  |  6 +++---
 qlop.c      | 12 ++++++++----
 6 files changed, 59 insertions(+), 21 deletions(-)

diff --git a/libq/set.c b/libq/set.c
index 6c9fae0..fa485c7 100644
--- a/libq/set.c
+++ b/libq/set.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2023 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -112,17 +112,22 @@ add_set_unique(const char *name, set *q, bool *unique)
 
 /* add ptr to set with name as key, return existing value when key
  * already exists or NULL otherwise */
-void *
-add_set_value(const char *name, void *ptr, set *q)
+set *
+add_set_value(const char *name, void *ptr, void **prevptr, set *q)
 {
 	unsigned int hash;
 	int pos;
 	set_elem *ll;
 	set_elem *w;
 
+	if (q == NULL)
+		q = create_set();
+
 	hash = fnv1a32(name);
 	pos = hash % _SET_HASH_SIZE;
 
+	if (prevptr != NULL)
+		*prevptr = NULL;
 	if (q->buckets[pos] == NULL) {
 		q->buckets[pos] = ll = xmalloc(sizeof(*ll));
 		ll->next = NULL;
@@ -132,8 +137,11 @@ add_set_value(const char *name, void *ptr, set *q)
 	} else {
 		ll = NULL;
 		for (w = q->buckets[pos]; w != NULL; ll = w, w = w->next) {
-			if (w->hash == hash && strcmp(w->name, name) == 0)
-				return w->val;
+			if (w->hash == hash && strcmp(w->name, name) == 0) {
+				if (prevptr != NULL)
+					*prevptr = w->val;
+				return q;
+			}
 		}
 		if (w == NULL) {
 			ll = ll->next = xmalloc(sizeof(*ll));
@@ -145,7 +153,7 @@ add_set_value(const char *name, void *ptr, set *q)
 	}
 
 	q->len++;
-	return NULL;
+	return q;
 }
 
 /* returns whether name is in set, and if so, the set-internal key
@@ -158,6 +166,9 @@ contains_set(const char *name, set *q)
 	set_elem *w;
 	const char *found;
 
+	if (q == NULL)
+		return NULL;
+
 	hash = fnv1a32(name);
 	pos = hash % _SET_HASH_SIZE;
 
@@ -183,6 +194,9 @@ get_set(const char *name, set *q)
 	int pos;
 	set_elem *w;
 
+	if (q == NULL)
+		return NULL;
+
 	hash = fnv1a32(name);
 	pos = hash % _SET_HASH_SIZE;
 
@@ -211,6 +225,12 @@ del_set(const char *s, set *q, bool *removed)
 	void *ret;
 	bool rmd;
 
+	if (q == NULL) {
+		if (removed != NULL)
+			*removed = false;
+		return NULL;
+	}
+
 	hash = fnv1a32(s);
 	pos = hash % _SET_HASH_SIZE;
 
@@ -252,8 +272,8 @@ list_set(set *q, char ***l)
 	set_elem *w;
 	char **ret;
 
-	ret = *l = xmalloc(sizeof(char *) * (q->len + 1));
-	for (i = 0; i < _SET_HASH_SIZE; i++) {
+	ret = *l = xmalloc(sizeof(char *) * (cnt_set(q) + 1));
+	for (i = 0; q != NULL && i < _SET_HASH_SIZE; i++) {
 		for (w = q->buckets[i]; w != NULL; w = w->next) {
 			*ret = w->name;
 			ret++;
@@ -292,6 +312,11 @@ values_set(set *q, array_t *ret)
 	array_t blank = array_init_decl;
 
 	*ret = blank;
+
+	/* allow using empty set */
+	if (q == NULL)
+		return 0;
+
 	for (i = 0; i < _SET_HASH_SIZE; i++) {
 		for (w = q->buckets[i]; w != NULL; w = w->next)
 			xarraypush_ptr(ret, w->val);
@@ -314,6 +339,9 @@ clear_set(set *q)
 	set_elem *w;
 	set_elem *e;
 
+	if (q == NULL)
+		return;
+
 	for (i = 0; i < _SET_HASH_SIZE; i++) {
 		for (w = q->buckets[i]; w != NULL; w = e) {
 			e = w->next;
@@ -329,6 +357,9 @@ clear_set(set *q)
 void
 free_set(set *q)
 {
+	if (q == NULL)
+		return;
+
 	clear_set(q);
 	free(q);
 }

diff --git a/libq/set.h b/libq/set.h
index 5d53f95..219602e 100644
--- a/libq/set.h
+++ b/libq/set.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2023 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  */
 
@@ -30,7 +30,7 @@ struct set_t {
 set *create_set(void);
 set *add_set(const char *name, set *q);
 set *add_set_unique(const char *name, set *q, bool *unique);
-void *add_set_value(const char *name, void *ptr, set *q);
+set *add_set_value(const char *name, void *ptr, void **prevptr, set *q);
 const char *contains_set(const char *name, set *q);
 void *get_set(const char *name, set *q);
 void *del_set(const char *s, set *q, bool *removed);

diff --git a/libq/tree.c b/libq/tree.c
index 76190ed..a05a86e 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -297,7 +297,8 @@ tree_open_cat(tree_ctx *ctx, const char *name)
 	cat_ctx->pkg_cnt = 0;
 
 	if (ctx->cache.categories != NULL) {
-		add_set_value(name, cat_ctx, ctx->cache.categories);
+		ctx->cache.categories =
+			add_set_value(name, cat_ctx, NULL, ctx->cache.categories);
 		/* ensure name doesn't expire after this instantiation is closed */
 		cat_ctx->name = contains_set(name, ctx->cache.categories);
 	}
@@ -1708,7 +1709,7 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void *priv)
 	cat_ctx = get_set(atom->CATEGORY, cache);
 	if (cat_ctx == NULL) {
 		cat_ctx = tree_open_cat(tctx, ".");
-		add_set_value(atom->CATEGORY, cat_ctx, cache);
+		cache = add_set_value(atom->CATEGORY, cat_ctx, NULL, cache);
 		/* get a pointer from the set */
 		cat_ctx->name = contains_set(atom->CATEGORY, cache);
 	}

diff --git a/main.c b/main.c
index 347a50b..c5b27fe 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2022 Gentoo Foundation
+ * Copyright 2005-2023 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
@@ -581,10 +581,12 @@ read_portage_file(const char *file, enum portage_file_type type, void *data)
 				if ((p = del_set(buf + 1, masks, NULL)) != NULL)
 					free(p);
 			} else {
+				void *e;
 				snprintf(npath, sizeof(npath), "%s:%zu:%zu-%zu",
 						file, line, cbeg, cend);
 				p = xstrdup(npath);
-				if (add_set_value(buf, p, masks) != NULL)
+				masks = add_set_value(buf, p, &e, masks);
+				if (e != NULL)
 					free(p);
 			}
 		}

diff --git a/qkeyword.c b/qkeyword.c
index 5bc1010..4899d47 100644
--- a/qkeyword.c
+++ b/qkeyword.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2022 Gentoo Foundation
+ * Copyright 2005-2023 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2006      Thomas A. Cort - <tcort@gentoo.org>
@@ -913,8 +913,8 @@ int qkeyword_main(int argc, char **argv)
 				continue;
 			bucket = xzalloc(sizeof(array_t));
 			xarraypush_ptr(bucket, atom);
-			ebuck = add_set_value(atom_format("%[CAT]%[PN]", atom),
-					bucket, pmasks);
+			pmasks = add_set_value(atom_format("%[CAT]%[PN]", atom),
+								   bucket, (void **)&ebuck, pmasks);
 			if (ebuck != NULL) {
 				xarraypush_ptr(ebuck, atom);
 				xarrayfree_int(bucket);

diff --git a/qlop.c b/qlop.c
index 16bf69f..3e6db53 100644
--- a/qlop.c
+++ b/qlop.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2022 Gentoo Foundation
+ * Copyright 2005-2023 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -523,7 +523,7 @@ static int do_emerge_log(
 					last_merge = tstart_emerge;
 				}
 
-				atomw = add_set_value(afmt, atom, atomset);
+				atomset = add_set_value(afmt, atom, (void **)&atomw, atomset);
 				if (atomw != NULL)
 					atom_implode(atom);
 			}
@@ -807,7 +807,9 @@ static int do_emerge_log(
 									pkgw->atom->CATEGORY, pkgw->atom->PN);
 						}
 
-						pkg = add_set_value(afmt, pkgw, merge_averages);
+						merge_averages =
+							add_set_value(afmt, pkgw,
+										  (void **)&pkg, merge_averages);
 						if (pkg != NULL) {
 							pkg->cnt++;
 							pkg->time += elapsed;
@@ -952,7 +954,9 @@ static int do_emerge_log(
 									pkgw->atom->CATEGORY, pkgw->atom->PN);
 						}
 
-						pkg = add_set_value(afmt, pkgw, unmerge_averages);
+						unmerge_averages =
+							add_set_value(afmt, pkgw,
+										  (void **)&pkg, unmerge_averages);
 						if (pkg != NULL) {
 							pkg->cnt++;
 							pkg->time += elapsed;


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2023-02-07  8:25 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2023-02-07  8:25 UTC (permalink / raw
  To: gentoo-commits

commit:     067af6b9098858e786e71ef20cb91ad75c6e4ba4
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Feb  7 08:24:21 2023 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Feb  7 08:24:21 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=067af6b9

set: try to silence Coverity

Now add_set_value can allocate a new set, Coverity thinks this will
actually happen, despite in these cases the input set not being NULL.
Help Coverity by adding a redundant if.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/tree.c |  3 ++-
 main.c      | 12 +++++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index a05a86e..f308c8d 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1709,7 +1709,8 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void *priv)
 	cat_ctx = get_set(atom->CATEGORY, cache);
 	if (cat_ctx == NULL) {
 		cat_ctx = tree_open_cat(tctx, ".");
-		cache = add_set_value(atom->CATEGORY, cat_ctx, NULL, cache);
+		if (cache != NULL)  /* for static code analysers */
+			add_set_value(atom->CATEGORY, cat_ctx, NULL, cache);
 		/* get a pointer from the set */
 		cat_ctx->name = contains_set(atom->CATEGORY, cache);
 	}

diff --git a/main.c b/main.c
index c5b27fe..884d6da 100644
--- a/main.c
+++ b/main.c
@@ -585,9 +585,15 @@ read_portage_file(const char *file, enum portage_file_type type, void *data)
 				snprintf(npath, sizeof(npath), "%s:%zu:%zu-%zu",
 						file, line, cbeg, cend);
 				p = xstrdup(npath);
-				masks = add_set_value(buf, p, &e, masks);
-				if (e != NULL)
-					free(p);
+				/* if not necessary, but do it for static code analysers
+				 * which take into accound that add_set_value might
+				 * allocate a new set when masks would be NULL -- a case
+				 * which would never happen */
+				if (masks != NULL) {
+					add_set_value(buf, p, &e, masks);
+					if (e != NULL)
+						free(p);
+				}
 			}
 		}
 	}


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2024-01-02  7:57 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2024-01-02  7:57 UTC (permalink / raw
  To: gentoo-commits

commit:     92920dd0b9efed3e7467b4b18b68df86f9eee9d8
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Jan  1 13:17:56 2024 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Jan  1 13:17:56 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=92920dd0

*: remove WHIRLPOOL hash support

WHIRLPOOL has not been in use since mid 2017, and its support is bound
to be removed from OpenSSL.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/hash.c | 26 +++-----------------------
 libq/hash.h | 14 +++++++-------
 libq/tree.c |  2 +-
 qcheck.c    |  2 +-
 qmanifest.c | 31 +++++++++----------------------
 qmerge.c    |  4 ++--
 qpkg.c      |  2 +-
 qtegrity.c  |  4 ++--
 8 files changed, 26 insertions(+), 59 deletions(-)

diff --git a/libq/hash.c b/libq/hash.c
index b5aec46..4a1202a 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018-2020 Gentoo Foundation
+ * Copyright 2018-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
@@ -15,7 +15,6 @@
 #ifdef HAVE_SSL
 # include <openssl/md5.h>
 # include <openssl/sha.h>
-# include <openssl/whrlpool.h>
 #else
 # include "hash_md5_sha1.h"
 #endif
@@ -120,7 +119,6 @@ hash_multiple_file_fd(
 		char *sha1,
 		char *sha256,
 		char *sha512,
-		char *whrlpl,
 		char *blak2b,
 		size_t *flen,
 		int hashes)
@@ -133,13 +131,11 @@ hash_multiple_file_fd(
 	SHA_CTX s1;
 	SHA256_CTX s256;
 	SHA512_CTX s512;
-	WHIRLPOOL_CTX whrl;
 #else
 	struct md5_ctx_t m5;
 	struct sha1_ctx_t s1;
 	(void)sha256;
 	(void)sha512;
-	(void)whrlpl;
 #endif
 #ifdef HAVE_BLAKE2B
 	blake2b_state bl2b;
@@ -156,7 +152,6 @@ hash_multiple_file_fd(
 	SHA1_Init(&s1);
 	SHA256_Init(&s256);
 	SHA512_Init(&s512);
-	WHIRLPOOL_Init(&whrl);
 #else
 	md5_begin(&m5);
 	sha1_begin(&s1);
@@ -190,11 +185,6 @@ hash_multiple_file_fd(
 				if (hashes & HASH_SHA512)
 					SHA512_Update(&s512, data, len);
 			}
-#pragma omp section
-			{
-				if (hashes & HASH_WHIRLPOOL)
-					WHIRLPOOL_Update(&whrl, data, len);
-			}
 #else
 #pragma omp section
 			{
@@ -253,14 +243,6 @@ hash_multiple_file_fd(
 				hash_hex(sha512, sha512buf, SHA512_DIGEST_LENGTH);
 			}
 		}
-#pragma omp section
-		{
-			if (hashes & HASH_WHIRLPOOL) {
-				unsigned char whrlplbuf[WHIRLPOOL_DIGEST_LENGTH];
-				WHIRLPOOL_Final(whrlplbuf, &whrl);
-				hash_hex(whrlpl, whrlplbuf, WHIRLPOOL_DIGEST_LENGTH);
-			}
-		}
 #else
 #pragma omp section
 		{
@@ -303,7 +285,6 @@ hash_multiple_file_at_cb(
 		char *sha1,
 		char *sha256,
 		char *sha512,
-		char *whrlpl,
 		char *blak2b,
 		size_t *flen,
 		int hashes)
@@ -321,7 +302,7 @@ hash_multiple_file_at_cb(
 	}
 
 	ret = hash_multiple_file_fd(fd, md5, sha1, sha256, sha512,
-			whrlpl, blak2b, flen, hashes);
+			blak2b, flen, hashes);
 
 	if (ret != 0)
 		close(fd);
@@ -340,11 +321,10 @@ hash_file_at_cb(int pfd, const char *fname, int hash, hash_cb_t cb)
 		case HASH_SHA1:
 		case HASH_SHA256:
 		case HASH_SHA512:
-		case HASH_WHIRLPOOL:
 		case HASH_BLAKE2B:
 			if (hash_multiple_file_at_cb(pfd, fname, cb,
 					_hash_file_buf, _hash_file_buf, _hash_file_buf,
-					_hash_file_buf, _hash_file_buf, _hash_file_buf,
+					_hash_file_buf, _hash_file_buf,
 					&dummy, hash) != 0)
 				return NULL;
 			break;

diff --git a/libq/hash.h b/libq/hash.h
index f85080d..fb4ab5f 100644
--- a/libq/hash.h
+++ b/libq/hash.h
@@ -18,7 +18,7 @@ enum hash_impls {
 	HASH_SHA1      = 1<<1,
 	HASH_SHA256    = 1<<2,
 	HASH_SHA512    = 1<<3,
-	HASH_WHIRLPOOL = 1<<4,
+	HASH_WHIRLPOOL = 1<<4,  /* removed */
 	HASH_BLAKE2B   = 1<<5
 };
 
@@ -32,15 +32,15 @@ typedef int (*hash_cb_t) (int, const char *);
 void hash_hex(char *out, const unsigned char *buf, const int length);
 int hash_multiple_file_fd(
 		int fd, char *md5, char *sha1, char *sha256, char *sha512,
-		char *whrlpl, char *blak2b, size_t *flen, int hashes);
+		char *blak2b, size_t *flen, int hashes);
 int hash_multiple_file_at_cb(
 		int pfd, const char *fname, hash_cb_t cb, char *md5,
-		char *sha1, char *sha256, char *sha512, char *whrlpl,
+		char *sha1, char *sha256, char *sha512,
 		char *blak2b, size_t *flen, int hashes);
-#define hash_multiple_file(f, m, s1, s2, s5, w, b, l, h) \
-	hash_multiple_file_at_cb(AT_FDCWD, f, NULL, m, s1, s2, s5, w, b, l, h)
-#define hash_compute_file(f, s2, s5, w, b, l, h) \
-	hash_multiple_file_at_cb(AT_FDCWD, f, NULL, NULL, NULL, s2, s5, w, b, l, h)
+#define hash_multiple_file(f, m, s1, s2, s5, b, l, h) \
+	hash_multiple_file_at_cb(AT_FDCWD, f, NULL, m, s1, s2, s5, b, l, h)
+#define hash_compute_file(f, s2, s5, b, l, h) \
+	hash_multiple_file_at_cb(AT_FDCWD, f, NULL, NULL, NULL, s2, s5, b, l, h)
 char *hash_file_at_cb(int pfd, const char *filename, int hash_algo, hash_cb_t cb);
 #define hash_file(f, h) hash_file_at_cb(AT_FDCWD, f, h, NULL)
 #define hash_file_at(fd, f, h) hash_file_at_cb(fd, f, h, NULL)

diff --git a/libq/tree.c b/libq/tree.c
index 1922b7d..15d8267 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1075,7 +1075,7 @@ tree_read_file_binpkg(tree_pkg_ctx *pkg_ctx)
 
 		lseek(newfd, 0, SEEK_SET);  /* reposition at the whole file */
 		if (hash_multiple_file_fd(newfd, NULL, m->Q_SHA1, NULL, NULL,
-				NULL, NULL, &fsize, HASH_SHA1) == 0)
+				NULL, &fsize, HASH_SHA1) == 0)
 			snprintf(m->Q_SIZE, 19 + 1, "%zu", fsize);
 	}
 

diff --git a/qcheck.c b/qcheck.c
index 813c1f7..7c1fd0e 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2022 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>

diff --git a/qmanifest.c b/qmanifest.c
index 72d6362..2bb0f11 100644
--- a/qmanifest.c
+++ b/qmanifest.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018-2021 Gentoo Foundation
+ * Copyright 2018-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2018-     Fabian Groffen  - <grobian@gentoo.org>
@@ -30,7 +30,6 @@
 #include <sys/types.h>
 #include <sys/time.h>
 #include <openssl/sha.h>
-#include <openssl/whrlpool.h>
 #include <blake2.h>
 #include <zlib.h>
 #include <gpgme.h>
@@ -188,7 +187,6 @@ write_hashes(
 	size_t flen = 0;
 	char sha256[(SHA256_DIGEST_LENGTH * 2) + 1];
 	char sha512[(SHA512_DIGEST_LENGTH * 2) + 1];
-	char whrlpl[(WHIRLPOOL_DIGEST_LENGTH * 2) + 1];
 	char blak2b[(BLAKE2B_OUTBYTES * 2) + 1];
 	char data[8192];
 	char fname[8192];
@@ -202,7 +200,7 @@ write_hashes(
 
 	update_times(tv, &s);
 
-	hash_compute_file(fname, sha256, sha512, whrlpl, blak2b, &flen, hashes);
+	hash_compute_file(fname, sha256, sha512, blak2b, &flen, hashes);
 
 	len = snprintf(data, sizeof(data), "%s %s %zd", type, name, flen);
 	if (hashes & HASH_BLAKE2B)
@@ -214,9 +212,6 @@ write_hashes(
 	if (hashes & HASH_SHA512)
 		len += snprintf(data + len, sizeof(data) - len,
 				" SHA512 %s", sha512);
-	if (hashes & HASH_WHIRLPOOL)
-		len += snprintf(data + len, sizeof(data) - len,
-				" WHIRLPOOL %s", whrlpl);
 	len += snprintf(data + len, sizeof(data) - len, "\n");
 
 	if (m != NULL)
@@ -1034,7 +1029,6 @@ verify_file(const char *dir, char *mfline, const char *mfest, verify_msg **msgs)
 	size_t flen = 0;
 	char sha256[(SHA256_DIGEST_LENGTH * 2) + 1];
 	char sha512[(SHA512_DIGEST_LENGTH * 2) + 1];
-	char whrlpl[(WHIRLPOOL_DIGEST_LENGTH * 2) + 1];
 	char blak2b[(BLAKE2B_OUTBYTES * 2) + 1];
 	char ret = 0;
 
@@ -1065,9 +1059,9 @@ verify_file(const char *dir, char *mfline, const char *mfest, verify_msg **msgs)
 		return 1;
 	}
 
-	sha256[0] = sha512[0] = whrlpl[0] = blak2b[0] = '\0';
+	sha256[0] = sha512[0] = blak2b[0] = '\0';
 	snprintf(buf, sizeof(buf), "%s/%s", dir, path);
-	hash_compute_file(buf, sha256, sha512, whrlpl, blak2b, &flen, hashes);
+	hash_compute_file(buf, sha256, sha512, blak2b, &flen, hashes);
 
 	if (flen == 0) {
 		msgs_add(msgs, mfest, path, "cannot open file!");
@@ -1139,15 +1133,12 @@ verify_file(const char *dir, char *mfline, const char *mfest, verify_msg **msgs)
 					msgs_add(msgs, mfest, path,
 							"hash WHIRLPOOL is not "
 							"enabled for this repository");
-			} else if (strcmp(hash, whrlpl) != 0) {
-				msgs_add(msgs, mfest, path,
-						"WHIRLPOOL hash mismatch\n"
-						"computed: '%s'\n"
-						"Manifest: '%s'",
-						whrlpl, hash);
-				ret = 1;
+			} else {
+				if (strict)
+					msgs_add(msgs, mfest, path,
+							"hash WHIRLPOOL is not "
+							"supported by qmanifest");
 			}
-			whrlpl[0] = '\0';
 		} else if (strcmp(hashtype, "BLAKE2B") == 0) {
 			if (!(hashes & HASH_BLAKE2B)) {
 				if (strict)
@@ -1177,10 +1168,6 @@ verify_file(const char *dir, char *mfline, const char *mfest, verify_msg **msgs)
 		msgs_add(msgs, mfest, path, "missing hash: SHA512");
 		ret = 1;
 	}
-	if (whrlpl[0] != '\0') {
-		msgs_add(msgs, mfest, path, "missing hash: WHIRLPOOL");
-		ret = 1;
-	}
 	if (blak2b[0] != '\0') {
 		msgs_add(msgs, mfest, path, "missing hash: BLAKE2B");
 		ret = 1;

diff --git a/qmerge.c b/qmerge.c
index cbf94e6..b16b4b5 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2022 Gentoo Authors
+ * Copyright 2005-2024 Gentoo Authors
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -1806,7 +1806,7 @@ pkg_verify_checksums(
 	size_t flen;
 	int    mlen;
 
-	if (hash_multiple_file(pkg->path, md5, sha1, NULL, NULL, NULL, NULL,
+	if (hash_multiple_file(pkg->path, md5, sha1, NULL, NULL, NULL,
 			&flen, HASH_MD5 | HASH_SHA1) == -1)
 		errf("failed to compute hashes for %s: %s\n",
 				atom_to_string(pkg->atom), strerror(errno));

diff --git a/qpkg.c b/qpkg.c
index 7da0263..c165989 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2020 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd	       - <solar@gentoo.org>

diff --git a/qtegrity.c b/qtegrity.c
index 19fd509..0a8989b 100644
--- a/qtegrity.c
+++ b/qtegrity.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -77,7 +77,7 @@ check_sha(char *ret_digest, char *path, char *algo)
 		return;
 	}
 
-	hash_compute_file(path, ret_digest, ret_digest, NULL, NULL, &flen, hashes);
+	hash_compute_file(path, ret_digest, ret_digest, NULL, &flen, hashes);
 	(void)flen;  /* we don't use the file size */
 
 	return;


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2024-03-29 10:57 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2024-03-29 10:57 UTC (permalink / raw
  To: gentoo-commits

commit:     268c2076b5276fbce37df3f751619646c4b8d7a4
Author:     Boris Staletic <boris.staletic <AT> protonmail <DOT> com>
AuthorDate: Thu Mar 28 18:08:00 2024 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Mar 29 10:57:17 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=268c2076

qlop: Properly handle atom_compar_cb when called from qsort

`qsort` passes pointers to elements ("iterators" in C++ lingo) to the
callback, not elements directly.
Hence `l` and `r` in `atom_compar_cb` actually receives `depend_atom**`,
but only when called from `qsort`. The other two call sites
(`tree_pkg_compar` and `pkg_sort_cb`) actually apssed `depend_atom*`.

This leads to type casting confusion and undefined behaviour for any
invocation of `qlop -p`.

First discovered by SEGFAULT-ing with the following invocation:

    qlop -p `cat /var/lib/portage/world`

Valgrind and ASAN made triggering the SEGFAULT easier - any invocation
with two or more atoms triggered a NULL dereference.

This commit addresses the above problem:

1. Expect that `atom_compar_cb` is actually called with two
   `depend_atom**`.
2. Make `tree_pkg_compar` and `pkg_sort_cb` comply with the above
   change, by passing  `&al` and `&ar`, instead of `al` and `ar`.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/atom.c | 4 ++--
 libq/tree.c | 2 +-
 qlop.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index b1a150a..3cc2100 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -1242,8 +1242,8 @@ atom_format(const char *format, const depend_atom *atom)
 inline int
 atom_compar_cb(const void *l, const void *r)
 {
-	const depend_atom *al = l;
-	const depend_atom *ar = r;
+	const depend_atom *al = *(const depend_atom**)l;
+	const depend_atom *ar = *(const depend_atom**)r;
 
 	switch (atom_compare(al, ar)) {
 		case EQUAL:  return  0;

diff --git a/libq/tree.c b/libq/tree.c
index 4678634..335ac79 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -463,7 +463,7 @@ tree_pkg_compar(const void *l, const void *r)
 	depend_atom *al = tree_get_atom(pl, false);
 	depend_atom *ar = tree_get_atom(pr, false);
 
-	return atom_compar_cb(al, ar);
+	return atom_compar_cb(&al, &ar);
 }
 
 static tree_pkg_ctx *

diff --git a/qlop.c b/qlop.c
index 3e6db53..cfad246 100644
--- a/qlop.c
+++ b/qlop.c
@@ -309,7 +309,7 @@ pkg_sort_cb(const void *l, const void *r)
 	depend_atom *al = pl->atom;
 	depend_atom *ar = pr->atom;
 
-	return atom_compar_cb(al, ar);
+	return atom_compar_cb(&al, &ar);
 }
 
 /* The format of the sync log has changed over time.


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

* [gentoo-commits] proj/portage-utils:master commit in: libq/, /
@ 2024-06-27 19:19 Fabian Groffen
  0 siblings, 0 replies; 31+ messages in thread
From: Fabian Groffen @ 2024-06-27 19:19 UTC (permalink / raw
  To: gentoo-commits

commit:     092dbac3c93d4a5f6fc2e5d496e17a0405c950a7
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Jun 27 19:17:23 2024 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Jun 27 19:17:23 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=092dbac3

*: remove i18n/gettext support

This looked very rudimentary, and half, there were no translations, and
not all strings were covered.  It was never enabled, so dummy for many
releases.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/i18n.h | 17 -----------------
 main.c      | 14 +++++---------
 main.h      |  9 ++++-----
 qcheck.c    |  2 +-
 4 files changed, 10 insertions(+), 32 deletions(-)

diff --git a/libq/i18n.h b/libq/i18n.h
deleted file mode 100644
index 50f36ea..0000000
--- a/libq/i18n.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef _I18N_H
-#define _I18N_H
-
-#if ENABLE_NLS
-# include <locale.h>
-# include <libintl.h>
-# define _(String) gettext (String)
-# define decimal_point localeconv()->decimal_point
-#else
-# define _(String) (String)
-# define setlocale(x,y)
-# define bindtextdomain(x,y)
-# define textdomain(x)
-# define decimal_point "."
-#endif
-
-#endif

diff --git a/main.c b/main.c
index 7225eed..5d7c97d 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2023 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd        - <solar@gentoo.org>
@@ -106,13 +106,13 @@ usage(int status, const char *flags, struct option const opts[],
 				fprintf(fp, " %s%9s%s %s%-16s%s%s:%s %s\n",
 					YELLOW, applets[i].name, NORM,
 					DKBLUE, applets[i].opts, NORM,
-					RED, NORM, _(applets[i].desc));
+					RED, NORM, applets[i].desc);
 	} else if (blabber > 0) {
 		fprintf(fp, "%susage:%s %s%s%s [opts] %s%s%s %s:%s %s\n",
 			GREEN, NORM,
 			YELLOW, applets[blabber].name, NORM,
 			DKBLUE, applets[blabber].opts, NORM,
-			RED, NORM, _(applets[blabber].desc));
+			RED, NORM, applets[blabber].desc);
 		if (desc)
 			fprintf(fp, "\n%s\n", desc);
 	}
@@ -154,10 +154,10 @@ usage(int status, const char *flags, struct option const opts[],
 		/* then wrap the help text, if necessary */
 		prefixlen = 6 + 2 + optlen + 1 + 1 + 1;
 		if ((size_t)twidth < prefixlen + 10) {
-			fprintf(fp, "%s\n", _(help[i]));
+			fprintf(fp, "%s\n", help[i]);
 		} else {
 			const char *t;
-			hstr = _(help[i]);
+			hstr = help[i];
 			l = strlen(hstr);
 			while (twidth - prefixlen < l) {
 				/* search backwards for a space */
@@ -1240,10 +1240,6 @@ int main(int argc, char **argv)
 	IF_DEBUG(init_coredumps());
 	argv0 = argv[0];
 
-	setlocale(LC_ALL, "");
-	bindtextdomain(argv0, CONFIG_EPREFIX "usr/share/locale");
-	textdomain(argv0);
-
 	/* note: setting nocolor here is pointless, since
 	 * initialize_portage_env is going to re-init nocolor, so make
 	 * sure we modify the default instead. */

diff --git a/main.h b/main.h
index a1b2afc..c3139b0 100644
--- a/main.h
+++ b/main.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2021 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <solar@gentoo.org>
@@ -23,7 +23,6 @@
 #include <string.h>
 
 #include "colors.h"
-#include "i18n.h"
 #include "set.h"
 
 extern const char *argv0;
@@ -87,8 +86,8 @@ extern const char *argv0;
 #define likely(x) __builtin_expect((x), 1)
 #define unlikely(x) __builtin_expect((x), 0)
 
-#define qfprintf(stream, fmt, args...) do { if (!quiet) fprintf(stream, _( fmt ), ## args); } while (0)
-#define qprintf(fmt, args...) qfprintf(stdout, _( fmt ), ## args)
+#define qfprintf(stream, fmt, args...) do { if (!quiet) fprintf(stream, fmt, ## args); } while (0)
+#define qprintf(fmt, args...) qfprintf(stdout, fmt, ## args)
 
 #define _q_unused_ __attribute__((__unused__))
 
@@ -125,7 +124,7 @@ extern FILE *warnout;
 #define warn(fmt, args...)
 #else
 #define warn(fmt, args...) \
-	fprintf(warnout, _("%s%s%s: " fmt "\n"), RED, argv0, NORM , ## args)
+	fprintf(warnout, "%s%s%s: " fmt "\n", RED, argv0, NORM , ## args)
 #endif
 #define warnf(fmt, args...) warn("%s%s()%s: " fmt, YELLOW, __func__, NORM , ## args)
 #define warnl(fmt, args...) warn("%s%i()%s: " fmt, YELLOW, __LINE__, NORM , ## args)

diff --git a/qcheck.c b/qcheck.c
index 7c1fd0e..b6d5671 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -55,7 +55,7 @@ static const char * const qcheck_opts_help[] = {
 };
 #define qcheck_usage(ret) usage(ret, QCHECK_FLAGS, qcheck_long_opts, qcheck_opts_help, NULL, lookup_applet_idx("qcheck"))
 
-#define qcprintf(fmt, args...) do { if (!state->bad_only) printf(_(fmt), ## args); } while (0)
+#define qcprintf(fmt, args...) do { if (!state->bad_only) printf(fmt, ## args); } while (0)
 
 struct qcheck_opt_state {
 	array_t *atoms;


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

end of thread, other threads:[~2024-06-27 19:19 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-07  8:10 [gentoo-commits] proj/portage-utils:master commit in: libq/, / Fabian Groffen
  -- strict thread matches above, loose matches on Subject: below --
2024-06-27 19:19 Fabian Groffen
2024-03-29 10:57 Fabian Groffen
2024-01-02  7:57 Fabian Groffen
2023-02-07  8:25 Fabian Groffen
2021-08-16 13:23 Fabian Groffen
2020-02-21  8:18 Fabian Groffen
2020-01-05 13:28 Fabian Groffen
2020-01-02 11:19 Fabian Groffen
2020-01-01 19:52 Fabian Groffen
2019-12-31  9:05 Fabian Groffen
2019-12-30 17:24 Fabian Groffen
2019-12-29 13:26 Fabian Groffen
2019-12-27 16:57 Fabian Groffen
2019-07-13 10:04 Fabian Groffen
2019-06-19 10:44 Fabian Groffen
2019-06-05  9:15 Fabian Groffen
2019-05-09 20:19 Fabian Groffen
2019-05-05 18:13 Fabian Groffen
2019-04-28 15:20 Fabian Groffen
2019-03-27 20:18 Fabian Groffen
2019-03-27 10:55 Fabian Groffen
2019-03-22  9:57 Fabian Groffen
2019-03-19 20:32 Fabian Groffen
2019-03-19 20:32 Fabian Groffen
2019-03-09 18:58 Fabian Groffen
2018-03-23 11:56 Fabian Groffen
2016-12-29  2:25 Mike Frysinger
2016-11-26 23:17 Mike Frysinger
2015-11-28  2:44 Mike Frysinger
2015-02-24  1:26 Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox