+char **get_libs(const void *ctx, const char *dir,
+ unsigned int *num, char **infofile)
+{
+ char **libs, *cmd;
+
+ if (!*infofile) {
+ *infofile = compile_info(ctx, dir);
+ if (!*infofile)
+ errx(1, "Could not compile _info for '%s'", dir);
+ }
+
+ cmd = talloc_asprintf(ctx, "%s libs", *infofile);
+ libs = lines_from_cmd(cmd, "%s", cmd);
+ if (!libs)
+ err(1, "Could not run '%s'", cmd);
+ /* FIXME: Do we need num arg? */
+ *num = talloc_array_length(libs) - 1;
+ return libs;
+}
+
+/* FIXME: This is O(n^2), which is dumb. */
+static void uniquify_deps(char **deps)
+{
+ unsigned int i, j, num;
+
+ num = talloc_array_length(deps) - 1;
+ for (i = 0; i < num; i++) {
+ for (j = i + 1; j < num; j++) {
+ if (streq(deps[i], deps[j])) {
+ memmove(&deps[j], &deps[j+1],
+ (num - j - 1) * sizeof(char *));
+ num--;
+ }
+ }
+ }
+ deps[num] = NULL;
+ /* Make sure talloc_array_length() works */
+ deps = talloc_realloc(NULL, deps, char *, num + 1);
+}
+
+char **get_deps(const void *ctx, const char *dir,
+ bool recurse, char **infofile)