tools.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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, const char *style,
  21. bool recurse,
  22. char *(*get_info)(const void *ctx, const char *dir));
  23. /* This is safer: just looks for ccan/ strings in info */
  24. char **get_safe_ccan_deps(const void *ctx, const char *dir, const char *style,
  25. bool recurse);
  26. /* This also needs to compile the info file:
  27. * style == NULL: don't recurse.
  28. * style == depends: recurse dependencies.
  29. * style == testdepends: recurse testdepends and depends.
  30. */
  31. char **get_libs(const void *ctx, const char *dir, const char *style,
  32. char *(*get_info)(const void *ctx, const char *dir));
  33. /* From tools.c */
  34. /* If set, print all commands run, all output they give and exit status. */
  35. extern bool tools_verbose;
  36. char *talloc_basename(const void *ctx, const char *dir);
  37. char *talloc_dirname(const void *ctx, const char *dir);
  38. char *talloc_getcwd(const void *ctx);
  39. bool PRINTF_FMT(4,5) run_command(const void *ctx,
  40. unsigned int *time_ms,
  41. char **output,
  42. const char *fmt, ...);
  43. char *run_with_timeout(const void *ctx, const char *cmd,
  44. bool *ok, unsigned *timeout_ms);
  45. const char *temp_dir(const void *ctx);
  46. bool move_file(const char *oldname, const char *newname);
  47. /* From compile.c.
  48. *
  49. * These all compile into a temporary dir, and return the filename.
  50. * On failure they return NULL, and errmsg is set to compiler output.
  51. */
  52. /* If set, say what we're compiling to. */
  53. extern bool compile_verbose;
  54. /* Compile multiple object files into a single. */
  55. char *link_objects(const void *ctx, const char *basename,
  56. const char *objs, char **errmsg);
  57. /* Compile a single C file to an object file. Returns false if fails. */
  58. bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
  59. const char *compiler,
  60. const char *cflags,
  61. const char *outfile, char **output);
  62. /* Compile and link single C file, with object files, libs, etc. */
  63. bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
  64. const char *objs,
  65. const char *compiler, const char *cflags,
  66. const char *libs, const char *outfile, char **output);
  67. /* Returns a file in temp_dir() */
  68. char *temp_file(const void *ctx, const char *extension, const char *srcname);
  69. /* Default wait for run_command. Should never time out. */
  70. extern const unsigned int default_timeout_ms;
  71. /* Talloc destructor which unlinks file. */
  72. int unlink_file_destructor(char *filename);
  73. /* Get ccan/ top dir, given a directory within it. */
  74. const char *find_ccan_dir(const char *base);
  75. #endif /* CCAN_TOOLS_H */