ccan_depends.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const char *style = "depends";
  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 (argv[1] && streq(argv[1], "--tests")) {
  31. argv++;
  32. argc--;
  33. style = "testdepends";
  34. }
  35. if (argc != 2)
  36. errx(1, "Usage: ccan_depends [--direct] [--compile] [--non-ccan] [--tests] <dir>\n"
  37. "Spits out all the ccan dependencies (recursively unless --direct)");
  38. /* We find depends without compiling by looking for ccan/ */
  39. if (!ccan && !compile)
  40. errx(1, "--non-ccan needs --compile");
  41. if (compile)
  42. deps = get_deps(talloc_autofree_context(), argv[1],
  43. style, recurse, compile_info);
  44. else
  45. deps = get_safe_ccan_deps(talloc_autofree_context(),
  46. argv[1], style, recurse);
  47. for (i = 0; deps[i]; i++)
  48. if (strstarts(deps[i], "ccan/") == ccan)
  49. printf("%s\n", deps[i]);
  50. return 0;
  51. }