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