2 * udibuild - UDI Compilation Utility
3 * - By John Hodge (thePowersGang)
6 * - Compilation functions
11 #include <sys/stat.h> // mkdir
12 #include "include/build.h"
13 #include "include/common.h"
16 char *get_objfile(tIniFile *opts, const char *abi, const char *srcfile);
19 int Build_CompileFile(tIniFile *opts, const char *abi, tUdiprops *udiprops, tUdiprops_Srcfile *srcfile)
21 // Select compiler from opts [abi]
22 const char *cc_prog = IniFile_Get(opts, abi, "CC", NULL);
24 fprintf(stderr, "No 'CC' defined for ABI %s\n", abi);
28 // Build up compiler's command line
29 // - Include CFLAGS from .ini file
30 // - defines from udiprops
31 // - Object file is srcfile with .o appended
32 // > Place in 'obj/' dir?
33 char *objfile = get_objfile(opts, abi, srcfile->Filename);
34 char *cmd = mkstr("%s -DUDI_ABI_is_%s %s %s -c %s -o %s",
37 IniFile_Get(opts, abi, "CFLAGS", ""),
38 srcfile->CompileOpts ? srcfile->CompileOpts : "",
39 srcfile->Filename, objfile);
40 printf("--- Compiling: %s\n", srcfile->Filename);
48 int Build_LinkObjects(tIniFile *opts, const char *abi, tUdiprops *udiprops)
50 const char *linker = IniFile_Get(opts, abi, "LD", NULL);
52 fprintf(stderr, "No 'LD' defined for ABI %s\n", abi);
56 char *objfiles[udiprops->nSourceFiles];
57 size_t objfiles_len = 0;
58 for( int i = 0; i < udiprops->nSourceFiles; i ++ ) {
59 objfiles[i] = get_objfile(opts, abi, udiprops->SourceFiles[i]->Filename);
60 objfiles_len += strlen(objfiles[i])+1;
63 // Create command string
64 char *objfiles_str = malloc(objfiles_len);
66 for( int i = 0; i < udiprops->nSourceFiles; i ++ ) {
67 strcpy(objfiles_str + objfiles_len, objfiles[i]);
68 objfiles_len += strlen(objfiles[i])+1;
69 objfiles_str[objfiles_len-1] = ' ';
72 objfiles_str[objfiles_len-1] = '\0';
75 char *abidir = mkstr("bin/%s", abi);
79 char *cmd = mkstr("%s -r %s -o bin/%s/%s -s %s",
80 linker, IniFile_Get(opts, abi, "LDFLAGS", ""),
81 abi, udiprops->ModuleName, objfiles_str
83 printf("--- Linking: bin/%s/%s\n", abi, udiprops->ModuleName);
92 char *get_objfile(tIniFile *opts, const char *abi, const char *srcfile)
94 return mkstr("%s.o", srcfile);