ccan_depends: Fix up after tools changes.
[ccan] / tools / ccan_depends.c
1 #include "tools.h"
2 #include <err.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <ccan/str/str.h>
6 #include <ccan/talloc/talloc.h>
7
8 int main(int argc, char *argv[])
9 {
10         char **deps;
11         unsigned int i;
12         bool compile = false;
13         bool recurse = true;
14         bool ccan = true;
15         char *dirname, *basename;
16
17         if (argv[1] && streq(argv[1], "--direct")) {
18                 argv++;
19                 argc--;
20                 recurse = false;
21         }
22         if (argv[1] && streq(argv[1], "--compile")) {
23                 argv++;
24                 argc--;
25                 compile = true;
26         }
27         if (argv[1] && streq(argv[1], "--non-ccan")) {
28                 argv++;
29                 argc--;
30                 ccan = false;
31         }
32         if (argc != 2)
33                 errx(1, "Usage: ccan_depends [--direct] [--compile] [--non-ccan] <dir>\n"
34                         "Spits out all the ccan dependencies (recursively unless --direct)");
35
36         /* We find depends without compiling by looking for ccan/ */
37         if (!ccan && !compile)
38                 errx(1, "--non-ccan needs --compile");
39
40         dirname = talloc_dirname(NULL, argv[1]);
41         basename = talloc_basename(NULL, argv[1]);
42
43         if (compile)
44                 deps = get_deps(talloc_autofree_context(),
45                                 dirname, basename, recurse, NULL);
46         else
47                 deps = get_safe_ccan_deps(talloc_autofree_context(),
48                                           dirname, basename, recurse, NULL);
49
50         for (i = 0; deps[i]; i++)
51                 if (strstarts(deps[i], "ccan/") == ccan)
52                         printf("%s\n", deps[i]);
53         return 0;
54 }