]> git.ozlabs.org Git - ccan/blob - tools/tools.h
tools: use tal instead of talloc.
[ccan] / tools / tools.h
1 #ifndef CCAN_TOOLS_H
2 #define CCAN_TOOLS_H
3 #include "config.h"
4 #include <ccan/compiler/compiler.h>
5 #include <ccan/rbuf/rbuf.h>
6 #include <ccan/tal/tal.h>
7 #include <ccan/tal/str/str.h>
8 #include <stdlib.h>
9 #include <stdbool.h>
10
11 #ifndef CCAN_COMPILER
12 #define CCAN_COMPILER "cc"
13 #endif
14 #ifndef CCAN_CFLAGS
15 #define CCAN_CFLAGS "-g -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror"
16 #endif
17
18 #define IDENT_CHARS     "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
19                         "abcdefghijklmnopqrstuvwxyz" \
20                         "01234567889_"
21
22 #define SPACE_CHARS     " \f\n\r\t\v"
23
24 #define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
25
26 /* This compiles up the _info file into a temporary. */
27 char *compile_info(const void *ctx, const char *dir);
28
29 /* This actually compiles and runs the info file to get dependencies. */
30 char **get_deps(const void *ctx, const char *dir, const char *style,
31                 bool recurse,
32                 char *(*get_info)(const void *ctx, const char *dir));
33
34 /* This is safer: just looks for ccan/ strings in info */
35 char **get_safe_ccan_deps(const void *ctx, const char *dir, const char *style,
36                           bool recurse);
37
38 /* This also needs to compile the info file:
39  * style == NULL: don't recurse.
40  * style == depends: recurse dependencies.
41  * style == testdepends: recurse testdepends and depends.
42  */
43 char **get_libs(const void *ctx, const char *dir, const char *style,
44                 char *(*get_info)(const void *ctx, const char *dir));
45
46 /* From tools.c */
47 /* If set, print all commands run, all output they give and exit status. */
48 extern bool tools_verbose;
49 char *tal_basename(const void *ctx, const char *dir);
50 char *tal_dirname(const void *ctx, const char *dir);
51 char *tal_getcwd(const void *ctx);
52 bool PRINTF_FMT(4,5) run_command(const void *ctx,
53                                  unsigned int *time_ms,
54                                  char **output,
55                                  const char *fmt, ...);
56 char *run_with_timeout(const void *ctx, const char *cmd,
57                        bool *ok, unsigned *timeout_ms);
58 const char *temp_dir(void);
59 void keep_temp_dir(void);
60 bool move_file(const char *oldname, const char *newname);
61
62 void *do_tal_realloc(void *p, size_t size);
63 void *tal_grab_file(const void *ctx, const char *filename, size_t *size);
64
65 /* Freed on exit: a good parent for auto cleanup. */
66 tal_t *autofree(void);
67
68 /* From compile.c.
69  *
70  * These all compile into a temporary dir, and return the filename.
71  * On failure they return NULL, and errmsg is set to compiler output.
72  */
73 /* If set, say what we're compiling to. */
74 extern bool compile_verbose;
75 /* Compile multiple object files into a single. */
76 char *link_objects(const void *ctx, const char *basename,
77                    const char *objs, char **errmsg);
78 /* Compile a single C file to an object file.  Returns false if fails. */
79 bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
80                     const char *compiler,
81                     const char *cflags,
82                     const char *outfile, char **output);
83 /* Compile and link single C file, with object files, libs, etc. */
84 bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
85                       const char *objs,
86                       const char *compiler, const char *cflags,
87                       const char *libs, const char *outfile, char **output);
88
89 /* Returns a file in temp_dir() */
90 char *temp_file(const void *ctx, const char *extension, const char *srcname);
91
92 /* Default wait for run_command.  Should never time out. */
93 extern const unsigned int default_timeout_ms;
94
95 /* Get ccan/ top dir, given a directory within it. */
96 const char *find_ccan_dir(const char *base);
97 #endif /* CCAN_TOOLS_H */