tools.h 3.3 KB

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