+/* FIXME: We should build if it doesn't exist... */
+static bool expect_obj_file(const char *dir)
+{
+ struct manifest *dep_man;
+ bool has_c_files;
+
+ dep_man = get_manifest(dir, dir);
+
+ /* If it has C files, we expect an object file built from them. */
+ has_c_files = !list_empty(&dep_man->c_files);
+ talloc_free(dep_man);
+ return has_c_files;
+}
+
+static char *add_dep(const struct manifest *m, char *list, const char *mod)
+{
+ char **deps, *obj;
+ unsigned int i;
+
+ /* Not ourselves. */
+ if (streq(m->basename, mod))
+ return list;
+
+ /* Not if there's no object file for that module */
+ if (!expect_obj_file(talloc_asprintf(list, "%s/ccan/%s", ccan_dir,mod)))
+ return list;
+
+ obj = talloc_asprintf(list, "%s/ccan/%s.o", ccan_dir, mod);
+
+ /* Not anyone we've already included. */
+ if (strstr(list, obj))
+ return list;
+
+ list = talloc_asprintf_append(list, " %s", obj);
+
+ /* Get that modules depends as well... */
+ assert(!safe_mode);
+ deps = get_deps(m, talloc_asprintf(list, "%s/ccan/%s", ccan_dir, mod),
+ false, NULL);
+
+ for (i = 0; deps[i]; i++) {
+ if (strstarts(deps[i], "ccan/"))
+ list = add_dep(m, list, deps[i] + strlen("ccan/"));
+ }
+ return list;
+}
+
+static char *obj_list(const struct manifest *m, struct ccan_file *f)