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, bool recurse);
  22. /* This also needs to compile the info file. */
  23. char **get_libs(const void *ctx, const char *dir,
  24. unsigned int *num, char **infofile);
  25. /* From tools.c */
  26. /* If set, print all commands run, all output they give and exit status. */
  27. extern bool tools_verbose;
  28. char *talloc_basename(const void *ctx, const char *dir);
  29. char *talloc_dirname(const void *ctx, const char *dir);
  30. char *talloc_getcwd(const void *ctx);
  31. bool PRINTF_FMT(4,5) run_command(const void *ctx,
  32. unsigned int *time_ms,
  33. char **output,
  34. const char *fmt, ...);
  35. char *run_with_timeout(const void *ctx, const char *cmd,
  36. bool *ok, unsigned *timeout_ms);
  37. const char *temp_dir(const void *ctx);
  38. bool move_file(const char *oldname, const char *newname);
  39. /* From compile.c.
  40. *
  41. * These all compile into a temporary dir, and return the filename.
  42. * On failure they return NULL, and errmsg is set to compiler output.
  43. */
  44. /* If set, say what we're compiling to. */
  45. extern bool compile_verbose;
  46. /* Compile multiple object files into a single. */
  47. char *link_objects(const void *ctx, const char *basename,
  48. const char *objs, char **errmsg);
  49. /* Compile a single C file to an object file. Returns false if fails. */
  50. bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
  51. const char *compiler,
  52. const char *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,
  57. const char *compiler, const char *cflags,
  58. const char *libs, const char *outfile, char **output);
  59. /* Returns a file in temp_dir() */
  60. char *temp_file(const void *ctx, const char *extension, 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 */