Tools/udibuild - Cleanup (can find udibuild.ini if invoked relatively)
[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 "include/build.h"
11 #include "include/common.h"
12
13 #ifndef __GNUC__
14 # define __attribute__(...)
15 #endif
16
17 // === PROTOTYPES ===
18 char    *get_objfile(tIniFile *opts, const char *srcfile);
19
20 // === CODE ===
21 int Build_CompileFile(tIniFile *opts, const char *abi, tUdiprops *udiprops, tUdiprops_Srcfile *srcfile)
22 {
23         // Select compiler from opts [abi]
24         const char *cc_prog = IniFile_Get(opts, abi, "CC", NULL);
25         if( !cc_prog ) {
26                 fprintf(stderr, "No 'CC' defined for ABI %s\n", abi);
27                 return 1;
28         }
29         
30         // Build up compiler's command line
31         // - Include CFLAGS from .ini file
32         // - defines from udiprops
33         // - Object file is srcfile with .o appended
34         //  > Place in 'obj/' dir?
35         char *objfile = get_objfile(opts, srcfile->Filename);
36         char *cmd = mkstr("%s -DUDI_ABI_is_%s %s %s -c %s -o %s",
37                 cc_prog,
38                 abi,
39                 IniFile_Get(opts, abi, "CFLAGS", ""),
40                 srcfile->CompileOpts ? srcfile->CompileOpts : "",
41                 srcfile->Filename, objfile);
42         printf("--- Compiling: %s\n", srcfile->Filename);
43          int rv = system(cmd);
44         free(cmd);
45         free(objfile);
46         
47         return rv;
48 }
49
50 int Build_LinkObjects(tIniFile *opts, const char *abi, tUdiprops *udiprops)
51 {
52         return 0;
53 }
54
55 char *get_objfile(tIniFile *opts, const char *srcfile)
56 {
57         return mkstr("%s.o", srcfile);
58 }

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