]> git.ozlabs.org Git - ccan/blob - tools/tools.h
take: add labels when CCAN_TAKE_DEBUG set, return in taken_any().
[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 /* These are the defaults. */
12 #define DEFAULT_CCAN_COMPILER "cc"
13 #define DEFAULT_CCAN_CFLAGS "-g"
14 #define DEFAULT_CCAN_OUTPUT_EXE_CFLAG "-o"
15
16 #define IDENT_CHARS     "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
17                         "abcdefghijklmnopqrstuvwxyz" \
18                         "01234567889_"
19
20 #define SPACE_CHARS     " \f\n\r\t\v"
21
22 #define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
23
24 /* Actual compiler and cflags
25  * (defaults to CCAN_COMPILER, CCAN_CFLAGS, CCAN_OUTPUT_EXE_CFLAG). */
26 extern const char *compiler, *cflags, *outexecflag;
27
28 /* This compiles up the _info file into a temporary. */
29 char *compile_info(const void *ctx, const char *dir);
30
31 /* This actually compiles and runs the info file to get dependencies. */
32 char **get_deps(const void *ctx, const char *dir, const char *style,
33                 bool recurse,
34                 char *(*get_info)(const void *ctx, const char *dir));
35
36 /* This is safer: just looks for ccan/ strings in info */
37 char **get_safe_ccan_deps(const void *ctx, const char *dir, const char *style,
38                           bool recurse);
39
40 /* This also needs to compile the info file:
41  * style == NULL: don't recurse.
42  * style == depends: recurse dependencies.
43  * style == testdepends: recurse testdepends and depends.
44  */
45 char **get_libs(const void *ctx, const char *dir, const char *style,
46                 char *(*get_info)(const void *ctx, const char *dir));
47
48 char **get_cflags(const void *ctx, const char *dir,
49                 char *(*get_info)(const void *ctx, const char *dir));
50
51 char **get_ccanlint(const void *ctx, const char *dir,
52                     char *(*get_info)(const void *ctx, const char *dir));
53
54 char *get_ported(const void *ctx, const char *dir, bool recurse,
55                  char *(*get_info)(const void *ctx, const char *dir));
56
57 /* From tools.c */
58 /* If set, print all commands run, all output they give and exit status. */
59 extern bool tools_verbose;
60 bool PRINTF_FMT(4,5) run_command(const void *ctx,
61                                  unsigned int *time_ms,
62                                  char **output,
63                                  const char *fmt, ...);
64 char *run_with_timeout(const void *ctx, const char *cmd,
65                        bool *ok, unsigned *timeout_ms);
66 const char *temp_dir(void);
67 void keep_temp_dir(void);
68 bool move_file(const char *oldname, const char *newname);
69
70 void *do_tal_realloc(void *p, size_t size);
71
72 /* Freed on exit: a good parent for auto cleanup. */
73 tal_t *autofree(void);
74
75 /* From compile.c.
76  *
77  * These all compile into a temporary dir, and return the filename.
78  * On failure they return NULL, and errmsg is set to compiler output.
79  */
80 /* If set, say what we're compiling to. */
81 extern bool compile_verbose;
82 /* Compile multiple object files into a single. */
83 char *link_objects(const void *ctx, const char *basename,
84                    const char *objs, char **errmsg);
85 /* Compile a single C file to an object file.  Returns false if fails. */
86 bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
87                     const char *compiler,
88                     const char *cflags,
89                     const char *outfile, char **output);
90 /* Compile and link single C file, with object files, libs, etc. */
91 bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
92                       const char *objs,
93                       const char *compiler, const char *cflags,
94                       const char *libs, const char *outfile, char **output);
95
96 /* Returns a file in temp_dir() */
97 char *temp_file(const void *ctx, const char *extension, const char *srcname);
98
99 /* Default wait for run_command.  Should never time out. */
100 extern const unsigned int default_timeout_ms;
101
102 /* Get ccan/ top dir, given a directory within it. */
103 const char *find_ccan_dir(const char *base);
104
105 /* Run gcov coverage tool */
106 extern const char *gcov;
107 const char *gcov_unavailable(void *ctx);
108 bool run_gcov(const void *ctx, unsigned int *time_ms, char **output,
109               const char *fmt, ...);
110
111 #endif /* CCAN_TOOLS_H */