tools.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef CCAN_TOOLS_H
  2. #define CCAN_TOOLS_H
  3. #include "config.h"
  4. #include <ccan/compiler/compiler.h>
  5. #include <ccan/rbuf/rbuf.h>
  6. #include <ccan/tal/tal.h>
  7. #include <ccan/tal/str/str.h>
  8. #include <stdlib.h>
  9. #include <stdbool.h>
  10. /* These are the defaults. */
  11. #define DEFAULT_CCAN_COMPILER "cc"
  12. #define DEFAULT_CCAN_CFLAGS "-g"
  13. #define IDENT_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
  14. "abcdefghijklmnopqrstuvwxyz" \
  15. "01234567889_"
  16. #define SPACE_CHARS " \f\n\r\t\v"
  17. #define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
  18. /* Actual compiler and cflags (defaults to CCAN_COMPILER and CCAN_CFLAGS). */
  19. extern const char *compiler, *cflags;
  20. /* This compiles up the _info file into a temporary. */
  21. char *compile_info(const void *ctx, const char *dir);
  22. /* This actually compiles and runs the info file to get dependencies. */
  23. char **get_deps(const void *ctx, const char *dir, const char *style,
  24. bool recurse,
  25. char *(*get_info)(const void *ctx, const char *dir));
  26. /* This is safer: just looks for ccan/ strings in info */
  27. char **get_safe_ccan_deps(const void *ctx, const char *dir, const char *style,
  28. bool recurse);
  29. /* This also needs to compile the info file:
  30. * style == NULL: don't recurse.
  31. * style == depends: recurse dependencies.
  32. * style == testdepends: recurse testdepends and depends.
  33. */
  34. char **get_libs(const void *ctx, const char *dir, const char *style,
  35. char *(*get_info)(const void *ctx, const char *dir));
  36. /* From tools.c */
  37. /* If set, print all commands run, all output they give and exit status. */
  38. extern bool tools_verbose;
  39. bool PRINTF_FMT(4,5) run_command(const void *ctx,
  40. unsigned int *time_ms,
  41. char **output,
  42. const char *fmt, ...);
  43. char *run_with_timeout(const void *ctx, const char *cmd,
  44. bool *ok, unsigned *timeout_ms);
  45. const char *temp_dir(void);
  46. void keep_temp_dir(void);
  47. bool move_file(const char *oldname, const char *newname);
  48. void *do_tal_realloc(void *p, size_t size);
  49. /* Freed on exit: a good parent for auto cleanup. */
  50. tal_t *autofree(void);
  51. /* From compile.c.
  52. *
  53. * These all compile into a temporary dir, and return the filename.
  54. * On failure they return NULL, and errmsg is set to compiler output.
  55. */
  56. /* If set, say what we're compiling to. */
  57. extern bool compile_verbose;
  58. /* Compile multiple object files into a single. */
  59. char *link_objects(const void *ctx, const char *basename,
  60. const char *objs, char **errmsg);
  61. /* Compile a single C file to an object file. Returns false if fails. */
  62. bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
  63. const char *compiler,
  64. const char *cflags,
  65. const char *outfile, char **output);
  66. /* Compile and link single C file, with object files, libs, etc. */
  67. bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
  68. const char *objs,
  69. const char *compiler, const char *cflags,
  70. const char *libs, const char *outfile, char **output);
  71. /* Returns a file in temp_dir() */
  72. char *temp_file(const void *ctx, const char *extension, const char *srcname);
  73. /* Default wait for run_command. Should never time out. */
  74. extern const unsigned int default_timeout_ms;
  75. /* Get ccan/ top dir, given a directory within it. */
  76. const char *find_ccan_dir(const char *base);
  77. #endif /* CCAN_TOOLS_H */