tools.h 2.8 KB

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