Changeset 20758

Show
Ignore:
Timestamp:
09/04/07 21:33:19 (1 year ago)
Author:
patrick
Message:

Set VPR_BASE_DIR automatically on all platforms.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/vapor/ChangeLog

    r20733 r20758  
    11DATE       AUTHOR   CHANGE 
    22---------- -------- ----------------------------------------------------------- 
     32007-09-04 patrick  Set VPR_BASE_DIR automatically on all platforms. 
    342007-08-21 patrick  Removed support for SPROC. 
    45                    NEW VERSION: 2.1.5 
  • juggler/trunk/modules/vapor/vpr/Makefile.in

    r19729 r20758  
    6060                md 
    6161 
    62 SRCS=           SystemBase.cpp 
     62SRCS=           SystemBase.cpp  \ 
     63                vprmain.cpp 
    6364 
    6465include $(MKPATH)/dpp.obj-subdir.mk 
  • juggler/trunk/modules/vapor/vpr/vprmain.cpp

    r20490 r20758  
    3434 *************** <auto-copyright.pl END do not edit this line> ***************/ 
    3535 
    36 #if defined(WIN32) || defined(WIN64) 
    37 #include <windows.h> 
     36#include <vpr/vprConfig.h> 
     37 
    3838#include <iostream> 
    3939#include <sstream> 
    4040#include <cstdlib> 
    4141#include <string> 
     42 
     43#if ! defined(WIN32) && ! defined(WIN64) 
     44#  include <dlfcn.h> 
     45#endif 
     46 
    4247#include <boost/filesystem/path.hpp> 
     48#include <boost/filesystem/operations.hpp> 
    4349#include <boost/filesystem/exception.hpp> 
    4450 
     
    4652namespace fs = boost::filesystem; 
    4753 
     54#if defined(WIN32) || defined(WIN64) 
    4855/** 
    4956 * Windows DLL entry point function. This ensures that the environment 
     
    114121   return TRUE; 
    115122} 
     123#else 
     124/** 
     125 * Non-Windows shared library constructor. This ensures that the environment 
     126 * variable \c VPR_BASE_DIR is set as soon as this shared library is loaded. 
     127 * If it is not set, then it sets it based on an assumption about the 
     128 * structure of a VPR installation. More specifically, an assumption is made 
     129 * that this shared library lives in the \c lib subdirectory of the VPR 
     130 * installation. Therefore, the root of the VPR installation is the parent of 
     131 * the directory containing this shared library. 
     132 */ 
     133extern "C" void __attribute ((constructor)) vprLibraryInit() 
     134{ 
     135   Dl_info info; 
     136   info.dli_fname = 0; 
     137   const int result = dladdr(reinterpret_cast<const void*>(&vprLibraryInit), 
     138                             &info); 
    116139 
     140   // NOTE: dladdr(3) really does return a non-zero value on success. 
     141   if ( 0 != result ) 
     142   { 
     143      try 
     144      { 
     145         fs::path lib_file(info.dli_fname, fs::native); 
     146         lib_file = fs::system_complete(lib_file); 
    117147 
     148#if defined(VPR_OS_IRIX) && defined(_ABIN32) 
     149         const std::string bit_suffix("32"); 
     150#elif defined(VPR_OS_IRIX) && defined(_ABI64) || \ 
     151      defined(VPR_OS_Linux) && defined(__x86_64__) 
     152         const std::string bit_suffix("64"); 
     153#else 
     154         const std::string bit_suffix(""); 
     155#endif 
     156 
     157         // Get the directory containing this shared library. 
     158         const fs::path lib_path = lib_file.branch_path(); 
     159 
     160         // Start the search for the root of the VPR installation in the 
     161         // parent of the directory containing this shared library. 
     162         fs::path base_dir = lib_path.branch_path(); 
     163 
     164         // Use the lib subdirectory to figure out when we have found the root 
     165         // of the VPR installation tree. 
     166         const fs::path lib_subdir(std::string("lib") + bit_suffix); 
     167 
     168         bool found(false); 
     169         while ( ! found ) 
     170         { 
     171            try 
     172            { 
     173               if ( ! fs::exists(base_dir / lib_subdir) ) 
     174               { 
     175                  base_dir = base_dir.branch_path(); 
     176               } 
     177               else 
     178               { 
     179                  found = true; 
     180               } 
     181            } 
     182            catch (fs::filesystem_error&) 
     183            { 
     184               base_dir = base_dir.branch_path(); 
     185            } 
     186         } 
     187 
     188         // We use the overwrite value of 0 as a way around testing whether 
     189         // the environment variable is already set. 
     190         setenv("VPR_BASE_DIR", base_dir.native_directory_string().c_str(), 0); 
     191      } 
     192      catch (fs::filesystem_error& ex) 
     193      { 
     194         std::cerr << "Automatic assignment of VPR_BASE_DIR failed:\n" 
     195                   << ex.what() << std::endl; 
     196      } 
     197   } 
     198} 
    118199#endif  /* defined(WIN32) || defined(WIN64) */