]> git.ozlabs.org Git - ccan/blob - tools/compile.c
ccanlint: remove redundant num_lines in struct ccan_file.
[ccan] / tools / compile.c
1 #include "tools.h"
2 #include <stdlib.h>
3
4 bool compile_verbose = false;
5
6 /* Compile multiple object files into a single.  Returns NULL if fails. */
7 char *link_objects(const void *ctx, const char *basename,
8                    const char *objs, char **errmsg)
9 {
10         char *file = temp_file(ctx, ".o", basename);
11
12         if (compile_verbose)
13                 printf("Linking objects into %s\n", file);
14
15         if (run_command(ctx, NULL, errmsg, "ld -r -o %s %s", file, objs))
16                 return file;
17
18         tal_free(file);
19         return NULL;
20 }
21
22 /* Compile a single C file to an object file. */
23 bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
24                     const char *compiler,
25                     const char *cflags,
26                     const char *outfile, char **output)
27 {
28         if (compile_verbose)
29                 printf("Compiling %s\n", outfile);
30         return run_command(ctx, NULL, output,
31                            "%s %s -I%s -c -o %s %s",
32                            compiler, cflags, ccandir, outfile, cfile);
33 }
34
35 /* Compile and link single C file, with object files.
36  * Returns false on failure. */
37 bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
38                       const char *objs, const char *compiler,
39                       const char *cflags,
40                       const char *libs, const char *outfile, char **output)
41 {
42         if (compile_verbose)
43                 printf("Compiling and linking %s\n", outfile);
44         return run_command(ctx, NULL, output,
45                            "%s %s -I%s -o %s %s %s %s",
46                            compiler, cflags,
47                            ccandir, outfile, cfile, objs, libs);
48 }