]> git.ozlabs.org Git - ccan/blob - tools/compile.c
tools: add build_verbose to show every command executed.
[ccan] / tools / compile.c
1 #include "tools.h"
2 #include <ccan/talloc/talloc.h>
3 #include <stdlib.h>
4
5 /* Compile multiple object files into a single.  Returns errmsg if fails. */
6 char *link_objects(const void *ctx, const char *objs, char **errmsg)
7 {
8         char *file = temp_file(ctx, ".o");
9
10         *errmsg = run_command(ctx, NULL, "ld -r -o %s %s", file, objs);
11         if (*errmsg) {
12                 talloc_free(file);
13                 return NULL;
14         }
15         return file;
16 }
17
18 /* Compile a single C file to an object file.  Returns errmsg if fails. */
19 char *compile_object(const void *ctx, const char *cfile, const char *ccandir,
20                      const char *extra_cflags,
21                      const char *outfile)
22 {
23         return run_command(ctx, NULL, "cc " CFLAGS " -I%s %s -c -o %s %s",
24                            ccandir, extra_cflags, outfile, cfile);
25 }
26
27 /* Compile and link single C file, with object files.
28  * Returns error message or NULL on success. */
29 char *compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
30                        const char *objs, const char *extra_cflags,
31                        const char *libs, const char *outfile)
32 {
33         return run_command(ctx, NULL, "cc " CFLAGS " -I%s %s -o %s %s %s %s",
34                            ccandir, extra_cflags, outfile, cfile, objs, libs);
35 }