ccan_depends.c 1.2 KB

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