]> git.ozlabs.org Git - ccan/blob - tools/tools.h
e78d13904c82b1c36c263ddb57a5fdb267779139
[ccan] / tools / tools.h
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
7 #ifndef CCAN_COMPILER
8 #define CCAN_COMPILER "cc"
9 #endif
10 #ifndef CCAN_CFLAGS
11 #define CCAN_CFLAGS "-g -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror"
12 #endif
13
14 #define IDENT_CHARS     "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
15                         "abcdefghijklmnopqrstuvwxyz" \
16                         "01234567889_"
17
18 #define SPACE_CHARS     " \f\n\r\t\v"
19
20 #define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
21
22 /* This compiles up the _info file into a temporary. */
23 char *compile_info(const void *ctx, const char *dir);
24
25 /* This actually compiles and runs the info file to get dependencies. */
26 char **get_deps(const void *ctx, const char *dir, bool recurse,
27                 char *(*get_info)(const void *ctx, const char *dir));
28
29 /* This is safer: just looks for ccan/ strings in info */
30 char **get_safe_ccan_deps(const void *ctx, const char *dir, bool recurse);
31
32 /* This also needs to compile the info file. */
33 char **get_libs(const void *ctx, const char *dir,
34                 unsigned int *num, char **infofile);
35
36 /* From tools.c */
37 /* If set, print all commands run, all output they give and exit status. */
38 extern bool tools_verbose;
39 char *talloc_basename(const void *ctx, const char *dir);
40 char *talloc_dirname(const void *ctx, const char *dir);
41 char *talloc_getcwd(const void *ctx);
42 bool PRINTF_FMT(4,5) run_command(const void *ctx,
43                                  unsigned int *time_ms,
44                                  char **output,
45                                  const char *fmt, ...);
46 char *run_with_timeout(const void *ctx, const char *cmd,
47                        bool *ok, unsigned *timeout_ms);
48 const char *temp_dir(const void *ctx);
49 bool move_file(const char *oldname, const char *newname);
50
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
72 /* Returns a file in temp_dir() */
73 char *temp_file(const void *ctx, const char *extension, const char *srcname);
74
75 /* Default wait for run_command.  Should never time out. */
76 extern const unsigned int default_timeout_ms;
77
78 /* Talloc destructor which unlinks file. */
79 int unlink_file_destructor(char *filename);
80
81 /* Get ccan/ top dir, given a directory within it. */
82 const char *find_ccan_dir(const char *base);
83 #endif /* CCAN_TOOLS_H */