ed5d5287b7e1556e90eb5fa98c7e996d7a3e2cca
[tpg/acess2.git] / Tools / udibuild / src / build.c
1 /*
2  * udibuild - UDI Compilation Utility
3  * - By John Hodge (thePowersGang)
4  *
5  * build.c
6  * - Compilation functions
7  */
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <stdarg.h>
11 #include "include/build.h"
12
13 #ifndef __GNUC__
14 # define __attribute__(...)
15 #endif
16
17 // === PROTOTYPES ===
18 char    *get_objfile(tIniFile *opts, const char *srcfile);
19 char    *mkstr(const char *fmt, ...) __attribute__((format(printf,1,2)));
20
21 // === CODE ===
22 int Build_CompileFile(tIniFile *opts, const char *abi, tUdiprops *udiprops, tUdiprops_Srcfile *srcfile)
23 {
24         // Select compiler from opts [abi]
25         const char *cc_prog = IniFile_Get(opts, abi, "CC", NULL);
26         if( !cc_prog ) {
27                 fprintf(stderr, "No 'CC' defined for ABI %s\n", abi);
28                 return 1;
29         }
30         
31         // Build up compiler's command line
32         // - Include CFLAGS from .ini file
33         // - defines from udiprops
34         // - Object file is srcfile with .o appended
35         //  > Place in 'obj/' dir?
36         char *objfile = get_objfile(opts, srcfile->Filename);
37         char *cmd = mkstr("%s -DUDI_ABI_is_%s %s %s -c %s -o %s",
38                 cc_prog,
39                 abi,
40                 IniFile_Get(opts, abi, "CFLAGS", ""),
41                 srcfile->CompileOpts ? srcfile->CompileOpts : "",
42                 srcfile->Filename, objfile);
43         printf("--- Compiling: %s\n", srcfile->Filename);
44          int rv = system(cmd);
45         free(cmd);
46         free(objfile);
47         
48         return rv;
49 }
50
51 int Build_LinkObjects(tIniFile *opts, const char *abi, tUdiprops *udiprops)
52 {
53         return 0;
54 }
55
56 char *get_objfile(tIniFile *opts, const char *srcfile)
57 {
58         return mkstr("%s.o", srcfile);
59 }
60
61 char *mkstr(const char *fmt, ...)
62 {
63         va_list args;
64         va_start(args, fmt);
65         size_t len = vsnprintf(NULL, 0, fmt, args);
66         va_end(args);
67         va_start(args, fmt);
68         char *ret = malloc(len+1);
69         vsnprintf(ret, len+1, fmt, args);
70         va_end(args);
71         return ret;
72 }
73

UCC git Repository :: git.ucc.asn.au