From: John Hodge Date: Wed, 2 Oct 2013 14:53:13 +0000 (+0800) Subject: Tools/udibuil - Added (unneeded) support for adding .udiprops X-Git-Tag: rel0.15~149 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=0dea0609daa090182b07dd2565567b53e59c507e;p=tpg%2Facess2.git Tools/udibuil - Added (unneeded) support for adding .udiprops - Actually belongs in udimkpkg --- diff --git a/Tools/udibuild/src/build.c b/Tools/udibuild/src/build.c index feeb3b78..4d0b2947 100644 --- a/Tools/udibuild/src/build.c +++ b/Tools/udibuild/src/build.c @@ -9,11 +9,13 @@ #include #include #include // mkdir +#include // unlink #include "include/build.h" #include "include/common.h" // === PROTOTYPES === char *get_objfile(tIniFile *opts, const char *abi, const char *srcfile); +char *get_udipropsfile(tIniFile *opts, const char *abi); // === CODE === int Build_CompileFile(tIniFile *opts, const char *abi, tUdiprops *udiprops, tUdiprops_Srcfile *srcfile) @@ -45,6 +47,32 @@ int Build_CompileFile(tIniFile *opts, const char *abi, tUdiprops *udiprops, tUdi return rv; } +int Build_CreateUdiprops(tIniFile *opts, const char *abi, tUdiprops *udiprops) +{ + const char *cc_prog = IniFile_Get(opts, abi, "CC", NULL); + + char *filename = get_udipropsfile(opts, abi); + FILE *fp = fopen(filename, "w"); + fprintf(fp, "char udiprops[] __attribute__((section(\".udiprops\"))) = \n"); + for( int i = 0; i < udiprops->nLines; i ++ ) { + // TODO: Escape " in string + fprintf(fp, " \"%s\"\n", udiprops->Lines[i]); + } + fprintf(fp, " ;\n"); + fclose(fp); + + char *cmd = mkstr("%s %s -c %s -o %s.o", + cc_prog, IniFile_Get(opts, abi, "CFLAGS", ""), + filename, filename); + + int rv = system(cmd); + free(cmd); + unlink(filename); + free(filename); + + return rv; +} + int Build_LinkObjects(tIniFile *opts, const char *abi, tUdiprops *udiprops) { const char *linker = IniFile_Get(opts, abi, "LD", NULL); @@ -76,14 +104,16 @@ int Build_LinkObjects(tIniFile *opts, const char *abi, tUdiprops *udiprops) mkdir(abidir, 0755); free(abidir); - char *cmd = mkstr("%s -r %s -o bin/%s/%s -s %s", + char *udiprops_c = get_udipropsfile(opts, abi); + char *cmd = mkstr("%s -r %s -o bin/%s/%s -s %s",// %s.o", linker, IniFile_Get(opts, abi, "LDFLAGS", ""), - abi, udiprops->ModuleName, objfiles_str + abi, udiprops->ModuleName, objfiles_str, udiprops_c ); printf("--- Linking: bin/%s/%s\n", abi, udiprops->ModuleName); printf("%s\n", cmd); int rv = system(cmd); free(cmd); + free(udiprops_c); free(objfiles_str); return rv; @@ -94,3 +124,8 @@ char *get_objfile(tIniFile *opts, const char *abi, const char *srcfile) return mkstr("%s.o", srcfile); } +char *get_udipropsfile(tIniFile *opts, const char *abi) +{ + return mkstr(".udiprops.c"); +} + diff --git a/Tools/udibuild/src/include/build.h b/Tools/udibuild/src/include/build.h index aaad075c..fe377ddf 100644 --- a/Tools/udibuild/src/include/build.h +++ b/Tools/udibuild/src/include/build.h @@ -12,6 +12,7 @@ #include "udiprops.h" extern int Build_CompileFile(tIniFile *opts, const char *abi, tUdiprops *udiprops, tUdiprops_Srcfile *srcfile); +extern int Build_CreateUdiprops(tIniFile *opts, const char *abi, tUdiprops *udiprops); extern int Build_LinkObjects(tIniFile *opts, const char *abi, tUdiprops *udiprops); #endif diff --git a/Tools/udibuild/src/include/udiprops.h b/Tools/udibuild/src/include/udiprops.h index fa22d66b..4bbc5d4e 100644 --- a/Tools/udibuild/src/include/udiprops.h +++ b/Tools/udibuild/src/include/udiprops.h @@ -23,6 +23,9 @@ struct sUdiprops const char *ModuleName; int nSourceFiles; tUdiprops_Srcfile **SourceFiles; + + int nLines; + char **Lines; }; extern tUdiprops *Udiprops_LoadBuild(const char *Filename); diff --git a/Tools/udibuild/src/main.c b/Tools/udibuild/src/main.c index ff6b8f43..b5b0042e 100644 --- a/Tools/udibuild/src/main.c +++ b/Tools/udibuild/src/main.c @@ -98,6 +98,10 @@ int main(int argc, char *argv[]) return rv; } } + // Create file with `.udiprops` section + // - udimkpkg's job + //Build_CreateUdiprops(gpOptions, gsOpt_ABIName, gpUdipropsBuild); + // Link Build_LinkObjects(gpOptions, gsOpt_ABIName, gpUdipropsBuild); return 0; diff --git a/Tools/udibuild/src/udiprops.c b/Tools/udibuild/src/udiprops.c index 6b158f74..f6a9bfca 100644 --- a/Tools/udibuild/src/udiprops.c +++ b/Tools/udibuild/src/udiprops.c @@ -82,6 +82,10 @@ tUdiprops *Udiprops_LoadBuild(const char *Filename) rtrim(str); if( !str[0] ) continue ; + ret->nLines ++; + ret->Lines = realloc(ret->Lines, ret->nLines*sizeof(void*)); + ret->Lines[ret->nLines-1] = my_strdup(str); + int sym = _get_token_sym(str, (const char**)&str, "source_files", "compile_options", "source_requires", "module",