tools.h 3.8 KB

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