tools.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. char **get_cflags(const void *ctx, const char *dir,
  37. char *(*get_info)(const void *ctx, const char *dir));
  38. bool get_ported(const void *ctx, const char *dir, bool recurse,
  39. char *(*get_info)(const void *ctx, const char *dir));
  40. /* From tools.c */
  41. /* If set, print all commands run, all output they give and exit status. */
  42. extern bool tools_verbose;
  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. /* Freed on exit: a good parent for auto cleanup. */
  54. tal_t *autofree(void);
  55. /* From compile.c.
  56. *
  57. * These all compile into a temporary dir, and return the filename.
  58. * On failure they return NULL, and errmsg is set to compiler output.
  59. */
  60. /* If set, say what we're compiling to. */
  61. extern bool compile_verbose;
  62. /* Compile multiple object files into a single. */
  63. char *link_objects(const void *ctx, const char *basename,
  64. const char *objs, char **errmsg);
  65. /* Compile a single C file to an object file. Returns false if fails. */
  66. bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
  67. const char *compiler,
  68. const char *cflags,
  69. const char *outfile, char **output);
  70. /* Compile and link single C file, with object files, libs, etc. */
  71. bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
  72. const char *objs,
  73. const char *compiler, const char *cflags,
  74. const char *libs, const char *outfile, char **output);
  75. /* Returns a file in temp_dir() */
  76. char *temp_file(const void *ctx, const char *extension, const char *srcname);
  77. /* Default wait for run_command. Should never time out. */
  78. extern const unsigned int default_timeout_ms;
  79. /* Get ccan/ top dir, given a directory within it. */
  80. const char *find_ccan_dir(const char *base);
  81. #endif /* CCAN_TOOLS_H */