tools.h 3.0 KB

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