tools.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. char *tal_basename(const void *ctx, const char *dir);
  41. char *tal_dirname(const void *ctx, const char *dir);
  42. char *tal_getcwd(const void *ctx);
  43. bool PRINTF_FMT(4,5) run_command(const void *ctx,
  44. unsigned int *time_ms,
  45. char **output,
  46. const char *fmt, ...);
  47. char *run_with_timeout(const void *ctx, const char *cmd,
  48. bool *ok, unsigned *timeout_ms);
  49. const char *temp_dir(void);
  50. void keep_temp_dir(void);
  51. bool move_file(const char *oldname, const char *newname);
  52. void *do_tal_realloc(void *p, size_t size);
  53. void *tal_grab_file(const void *ctx, const char *filename, size_t *size);
  54. /* Freed on exit: a good parent for auto cleanup. */
  55. tal_t *autofree(void);
  56. /* From compile.c.
  57. *
  58. * These all compile into a temporary dir, and return the filename.
  59. * On failure they return NULL, and errmsg is set to compiler output.
  60. */
  61. /* If set, say what we're compiling to. */
  62. extern bool compile_verbose;
  63. /* Compile multiple object files into a single. */
  64. char *link_objects(const void *ctx, const char *basename,
  65. const char *objs, char **errmsg);
  66. /* Compile a single C file to an object file. Returns false if fails. */
  67. bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
  68. const char *compiler,
  69. const char *cflags,
  70. const char *outfile, char **output);
  71. /* Compile and link single C file, with object files, libs, etc. */
  72. bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
  73. const char *objs,
  74. const char *compiler, const char *cflags,
  75. const char *libs, const char *outfile, char **output);
  76. /* Returns a file in temp_dir() */
  77. char *temp_file(const void *ctx, const char *extension, const char *srcname);
  78. /* Default wait for run_command. Should never time out. */
  79. extern const unsigned int default_timeout_ms;
  80. /* Get ccan/ top dir, given a directory within it. */
  81. const char *find_ccan_dir(const char *base);
  82. #endif /* CCAN_TOOLS_H */