tools.h 3.4 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 <stdlib.h>
  7. #include <stdbool.h>
  8. #ifndef CCAN_COMPILER
  9. #define CCAN_COMPILER "cc"
  10. #endif
  11. #ifndef CCAN_CFLAGS
  12. #define CCAN_CFLAGS "-g -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror"
  13. #endif
  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. /* This compiles up the _info file into a temporary. */
  20. char *compile_info(const void *ctx, const char *dir);
  21. /* This actually compiles and runs the info file to get dependencies. */
  22. char **get_deps(const void *ctx, const char *dir, const char *style,
  23. bool recurse,
  24. char *(*get_info)(const void *ctx, const char *dir));
  25. /* This is safer: just looks for ccan/ strings in info */
  26. char **get_safe_ccan_deps(const void *ctx, const char *dir, const char *style,
  27. bool recurse);
  28. /* This also needs to compile the info file:
  29. * style == NULL: don't recurse.
  30. * style == depends: recurse dependencies.
  31. * style == testdepends: recurse testdepends and depends.
  32. */
  33. char **get_libs(const void *ctx, const char *dir, const char *style,
  34. char *(*get_info)(const void *ctx, const char *dir));
  35. /* From tools.c */
  36. /* If set, print all commands run, all output they give and exit status. */
  37. extern bool tools_verbose;
  38. char *talloc_basename(const void *ctx, const char *dir);
  39. char *talloc_dirname(const void *ctx, const char *dir);
  40. char *talloc_getcwd(const void *ctx);
  41. bool PRINTF_FMT(4,5) run_command(const void *ctx,
  42. unsigned int *time_ms,
  43. char **output,
  44. const char *fmt, ...);
  45. char *run_with_timeout(const void *ctx, const char *cmd,
  46. bool *ok, unsigned *timeout_ms);
  47. const char *temp_dir(const void *ctx);
  48. bool move_file(const char *oldname, const char *newname);
  49. void *do_talloc_realloc(void *p, size_t size);
  50. void *talloc_grab_file(const void *ctx, const char *filename, size_t *size);
  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. /* Talloc destructor which unlinks file. */
  76. int unlink_file_destructor(char *filename);
  77. /* Get ccan/ top dir, given a directory within it. */
  78. const char *find_ccan_dir(const char *base);
  79. #endif /* CCAN_TOOLS_H */