ccan_depends.c 1.1 KB

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