]> git.ozlabs.org Git - ccan/blob - tools/compile.c
5ec41228f59e51de3d2b5819a34a0eede4fcfa22
[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 *outfile, const char *objs)
7 {
8         return run_command(ctx, "cc " CFLAGS " -c -o %s %s", outfile, objs);
9 }
10
11 /* Compile a single C file to an object file.  Returns errmsg if fails. */
12 char *compile_object(const void *ctx, const char *outfile, const char *cfile)
13 {
14         return run_command(ctx, "cc " CFLAGS " -c -o %s %s", outfile, cfile);
15 }
16
17 /* Compile and link single C file, with object files.
18  * Returns name of result, or NULL (and fills in errmsg). */
19 char *compile_and_link(const void *ctx, const char *cfile, const char *objs,
20                        const char *extra_cflags, const char *libs,
21                        char **errmsg)
22 {
23         char *file = temp_file(ctx, "");
24
25         *errmsg = run_command(ctx, "cc " CFLAGS " %s -o %s %s %s %s",
26                               extra_cflags, file, cfile, objs, libs);
27         if (*errmsg) {
28                 talloc_free(file);
29                 return NULL;
30         }
31         return file;
32 }