Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

ActiveSharedLib.cpp

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <sys/types.h>
00004 #include <sys/stat.h>
00005 #include <iostream>
00006 #include "ActiveSharedLib.h"
00007 
00008 #if defined(__sun) 
00009 #include <strings.h>
00010 #endif /* __sun */
00011 
00012 #ifdef AIDA_STD
00013 # undef AIDA_STD
00014 #endif
00015 
00016 #ifdef AIDA_NOT_USE_STD
00017 # define AIDA_STD
00018 #else
00019 # define AIDA_STD std
00020 #endif
00021 
00022 #ifdef _WIN32
00023   #define UNLINKCALL _unlink
00024 #else
00025 #include <sys/wait.h>
00026 #include <unistd.h>
00027  #define UNLINKCALL unlink
00028 #endif
00029 
00030 void ActiveSharedLib::remove() {
00031   unload();
00032   if (strlen(getPathName()) > 0) {
00033     if (UNLINKCALL(getPathName()) == -1) {
00034       AIDA_STD::cerr << "Can't unlink "<< unlink(getPathName()) ;
00035       AIDA_STD::cerr << AIDA_STD::endl;
00036     }
00037   }
00038 }
00039 
00040 int ActiveSharedLib::compile (char *libFileName, const char *gmakeFile, 
00041                               char *override) {
00042   char tmp [512];
00043   int retval = 0;
00044   int status;
00045   sprintf (tmp, "gmake -f %s %s %s",gmakeFile , libFileName, override);
00046   status = system(tmp);
00047 
00048 #ifdef _WIN32
00049   if (status >= 0) {
00050     if (status == 0) {
00051       retval = 1;
00052     } else {
00053       AIDA_STD::cerr << "gmake failed with code " << status << AIDA_STD::endl;
00054       AIDA_STD::cout << "Library " << getPathName() << AIDA_STD::endl;
00055     }
00056   } else {
00057     AIDA_STD::cerr <<"system call failed with code "<< errno<< AIDA_STD::endl;
00058   }
00059 #else
00060 
00061   if (status >= 0) {
00062     if (status != 127) {
00063       if ( WIFEXITED(status) ) {
00064         if (WEXITSTATUS(status) == 0) {
00065           retval = 1;
00066         } else {
00067           AIDA_STD::cerr<<"failed to make shared library"<<AIDA_STD::endl;
00068         }
00069       } else {
00070           AIDA_STD::cerr<<"make failed with code "<< status << AIDA_STD::endl;
00071       }
00072     } else {
00073       AIDA_STD::cerr << "Can't shell to make shared library" << AIDA_STD::endl;
00074     }
00075   } else {
00076     AIDA_STD::cerr <<"Can't system() to make shared library"<< AIDA_STD::endl;
00077   }
00078 
00079 #endif /* _WIN32 */
00080 return retval;
00081 }
00082 
00083 int ActiveSharedLib::makeLib (const char *baseFileName,const char *gmakeFile, 
00084                                char *override) {
00085   int retval = 0;
00086   char *libname = new char[(strlen(baseFileName)+5)];
00087   sprintf (libname,"%s.%s",baseFileName,shLibExt);
00088   retval = compile (libname, gmakeFile, override);
00089   if (retval) {
00090     setPathName(libname);
00091   }
00092   delete []libname;
00093   return retval;
00094 }
00095 
00096 

Generated on Tue May 20 14:50:25 2003 for HepUtilities by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002