From: Rainer M. <ra...@tb...> - 2008-07-10 15:24:00
|
Hi Eric, great, thanks! sorry for the still missing replies to your previous emails, we are quite in some stress here. Would you want a CVS developer access? You could directly submit such AIX-related changes. Rainer Eric Fernandez wrote: > Hi, > > As promised in my previous email, please find the patch for compiler.c > that adds compilation on AIX using xlc_r (the IBM compiler). > > Regards, > Eric > > > --- SBML_odeSolver.orig/src/compiler.c 2008-03-11 18:21:26.000000000 > +0000 > +++ SBML_odeSolver/src/compiler.c 2008-07-10 16:05:10.000000000 > +0100 > @@ -54,6 +54,8 @@ > > #endif /* end WIN32 */ > > +#define _DEBUG 1 > +#define AIX 1 > > #ifdef WIN32 > > @@ -172,6 +174,123 @@ > return (code); > } > > +#elif defined AIX /* AIX use xlc_r */ > + > +/** > + Returns a pointer to code that is compiled from the given source > code > +*/ > +compiled_code_t *Compiler_compile_with_xlc(const char *sourceCode) > +{ > + compiled_code_t *code = NULL; > + char gccFileName[MAX_PATH+1] = "xlc_r"; > + int result; > + char *tmpFileName = NULL; > + char *cFileName = NULL; > + char *dllFileName = NULL; > + char *oFileName = NULL; > + FILE *cFile; > + char command[4*MAX_PATH]; > + void *dllHandle; > + > + /* generate a unique temprorary filename template */ > + ASSIGN_NEW_MEMORY_BLOCK(tmpFileName, (MAX_PATH+1), char, NULL); > + tmpFileName = tmpnam(tmpFileName); > + > +#ifdef _DEBUG > + Warn(NULL,"Temporary File Name is %s\n", tmpFileName); > +#endif > + > + /* generate needed file names from the template*/ > + ASSIGN_NEW_MEMORY_BLOCK(cFileName, (strlen(tmpFileName)+3), char, > NULL); > + strcpy(cFileName, tmpFileName); > + strcat(cFileName, ".c"); > + ASSIGN_NEW_MEMORY_BLOCK(oFileName, (strlen(tmpFileName)+3), char, > NULL); > + strcpy(oFileName, tmpFileName); > + strcat(oFileName, ".o"); > + ASSIGN_NEW_MEMORY_BLOCK(dllFileName, > + (strlen(tmpFileName)+strlen(SHAREDLIBEXT)+1), > + char, NULL); > + strcpy(dllFileName, tmpFileName); > + strcat(dllFileName, SHAREDLIBEXT); > + > + /* open file and dump source code to it */ > + cFile = fopen(cFileName, "w"); > + > + if (!cFile) > + { > + SolverError_error(WARNING_ERROR_TYPE, SOLVER_ERROR_OPEN_FILE, > + "Could not open file %s - %s!", > + cFileName, strerror(errno)); > + return NULL; > + } > + > + fprintf(cFile, sourceCode); > + fclose(cFile); > + > + /* construct command for compiling */ > + sprintf(command, "%s -I%s -I%s -I../src -G -O1 -o %s %s -L../src -L%s > -lODES -lsbml -lm", > + gccFileName, > + SUNDIALS_CFLAGS, > + SOSLIB_CFLAGS, > + dllFileName, > + cFileName, > + SOSLIB_LDFLAGS); > + > +#ifdef _DEBUG > + Warn(NULL, "Command: %s\n", command); > + Warn(NULL, > + "%s -I%s -I%s -I../src -G -O1 -o %s %s -L../src -L%s -lODES > -lsbml -lm", > + gccFileName, > + SUNDIALS_CFLAGS, > + SOSLIB_CFLAGS, > + dllFileName, > + cFileName, > + SOSLIB_LDFLAGS); > +#endif > + > + /* compile source to shared library */ > + result = system(command); > + > + /* handle possible errors */ > + if (result == -1) > + { > + SolverError_error(WARNING_ERROR_TYPE, SOLVER_ERROR_GCC_FORK_FAILED, > + "forking gcc compiler subprocess failed!"); > + return (NULL); > + } > + else if (result != 0) > + { > + SolverError_error(WARNING_ERROR_TYPE, > SOLVER_ERROR_COMPILATION_FAILED, > + "compiling failed with errno %d - %s!", > + result, strerror(result)); > + return (NULL); > + } > + > + /* clean up compilation intermediates */ > + free(tmpFileName); > + remove(cFileName); > + free(cFileName); > + remove(oFileName); > + free(oFileName); > > + > + /* load shared library */ > + dllHandle = dlopen(dllFileName, RTLD_LAZY); > + if (dllHandle == NULL) > + { > + SolverError_error(WARNING_ERROR_TYPE, SOLVER_ERROR_DL_LOAD_FAILED, > + "loading shared library %s failed %d - %s!", > + dllFileName, errno, strerror(errno)); > + SolverError_dumpAndClearErrors(); > + return (NULL); > + } > + > + ASSIGN_NEW_MEMORY(code, compiled_code_t, NULL); > + code->dllHandle = dllHandle; > + code->dllFileName = dllFileName; > + > + return (code); > +} > + > #else /* default case is compile with gcc */ > > /** > @@ -237,7 +356,7 @@ > SBML_LDFLAGS, > SOSLIB_LDFLAGS); > #else > - sprintf(command, "%s -I%s -I%s -I../src -pipe -O -shared -fPIC -o %s > %s -L../src -L%s -lODES -lm", > + sprintf(command, "%s -I%s -I%s -I../src -pipe -O -shared -fPIC -o %s > %s -L../src -L%s -lODES -lsbml -lm -lstdc++", > gccFileName, > SUNDIALS_CFLAGS, > SOSLIB_CFLAGS, > @@ -261,7 +380,7 @@ > SOSLIB_LDFLAGS); > #else > Warn(NULL, > - "%s -I%s -I%s -I../src -pipe -O -shared -fPIC -o %s %s -L../src > -L%s -lODES -lm", > + "%s -I%s -I%s -I../src -pipe -O -shared -fPIC -o %s %s -L../src > -L%s -lODES -lsbml -lm -lstdc++", > gccFileName, > SUNDIALS_CFLAGS, > SOSLIB_CFLAGS, > @@ -314,6 +433,8 @@ > return (code); > } > > + > + > #endif /* end WIN32 */ > > /** > @@ -326,6 +447,10 @@ > #ifdef WIN32 > > code = Compiler_compile_with_tcc(sourceCode); > + > +#elif defined AIX > + > + code = Compiler_compile_with_xlc(sourceCode); > > #else > > ------------------------------------------------------------------------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source project, > along with a healthy diet, reduces your potential for chronic lameness > and boredom. Vote Now at http://www.sourceforge.net/community/cca08 > _______________________________________________ > sbmlsolver-discuss mailing list > sbm...@li... > https://lists.sourceforge.net/lists/listinfo/sbmlsolver-discuss |