]> git.ozlabs.org Git - ccan/blob - tools/tools.h
tools: use rbuf instead of grab_file.
[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 <stdlib.h>
7 #include <stdbool.h>
8
9 #ifndef CCAN_COMPILER
10 #define CCAN_COMPILER "cc"
11 #endif
12 #ifndef CCAN_CFLAGS
13 #define CCAN_CFLAGS "-g -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror"
14 #endif
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 /* This compiles up the _info file into a temporary. */
25 char *compile_info(const void *ctx, const char *dir);
26
27 /* This actually compiles and runs the info file to get dependencies. */
28 char **get_deps(const void *ctx, const char *dir, const char *style,
29                 bool recurse,
30                 char *(*get_info)(const void *ctx, const char *dir));
31
32 /* This is safer: just looks for ccan/ strings in info */
33 char **get_safe_ccan_deps(const void *ctx, const char *dir, const char *style,
34                           bool recurse);
35
36 /* This also needs to compile the info file:
37  * style == NULL: don't recurse.
38  * style == depends: recurse dependencies.
39  * style == testdepends: recurse testdepends and depends.
40  */
41 char **get_libs(const void *ctx, const char *dir, const char *style,
42                 char *(*get_info)(const void *ctx, const char *dir));
43
44 /* From tools.c */
45 /* If set, print all commands run, all output they give and exit status. */
46 extern bool tools_verbose;
47 char *talloc_basename(const void *ctx, const char *dir);
48 char *talloc_dirname(const void *ctx, const char *dir);
49 char *talloc_getcwd(const void *ctx);
50 bool PRINTF_FMT(4,5) run_command(const void *ctx,
51                                  unsigned int *time_ms,
52                                  char **output,
53                                  const char *fmt, ...);
54 char *run_with_timeout(const void *ctx, const char *cmd,
55                        bool *ok, unsigned *timeout_ms);
56 const char *temp_dir(const void *ctx);
57 bool move_file(const char *oldname, const char *newname);
58
59 void *do_talloc_realloc(void *p, size_t size);
60 void *talloc_grab_file(const void *ctx, const char *filename, size_t *size);
61
62 /* From compile.c.
63  *
64  * These all compile into a temporary dir, and return the filename.
65  * On failure they return NULL, and errmsg is set to compiler output.
66  */
67 /* If set, say what we're compiling to. */
68 extern bool compile_verbose;
69 /* Compile multiple object files into a single. */
70 char *link_objects(const void *ctx, const char *basename,
71                    const char *objs, char **errmsg);
72 /* Compile a single C file to an object file.  Returns false if fails. */
73 bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
74                     const char *compiler,
75                     const char *cflags,
76                     const char *outfile, char **output);
77 /* Compile and link single C file, with object files, libs, etc. */
78 bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
79                       const char *objs,
80                       const char *compiler, const char *cflags,
81                       const char *libs, const char *outfile, char **output);
82
83 /* Returns a file in temp_dir() */
84 char *temp_file(const void *ctx, const char *extension, const char *srcname);
85
86 /* Default wait for run_command.  Should never time out. */
87 extern const unsigned int default_timeout_ms;
88
89 /* Talloc destructor which unlinks file. */
90 int unlink_file_destructor(char *filename);
91
92 /* Get ccan/ top dir, given a directory within it. */
93 const char *find_ccan_dir(const char *base);
94 #endif /* CCAN_TOOLS_H */