Changeset 20761

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

Set GADGET_BASE_DIR and the new environment variable GADGET_DATA_DIR
automatically on all platforms. Bumped the version to 1.3.14.

Files:

Legend:

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

    r20605 r20761  
    11DATE        AUTHOR      CHANGE 
    22----------- ----------- ------------------------------------------------------- 
     3Sep-04-2007 patrick     Use new environment variable GADGET_DATA_DIR as a way 
     4                        to look up files in GADGET_BASE_DIR/share/gadgeteer. 
     5                        NEW VERSION: 1.3.14 
     6Sep-04-2007 patrick     Set GADGET_BASE_DIR automatically on all platforms. 
    37Jul-28-2007 aronb       Fixed device sharing in cluster configurations. 
    48                        NEW VERSION: 1.3.13 
  • juggler/trunk/modules/gadgeteer/VERSION

    r20737 r20761  
     11.3.14-0 @09/05/2007 02:50:00 UTC@ 
    121.3.13-0 @07/30/2007 02:45:00 UTC@ 
    231.3.12-0 @07/08/2007 21:15:00 UTC@ 
  • juggler/trunk/modules/gadgeteer/gadget/Makefile.in

    r20136 r20761  
    5757                ProxyDepChecker.cpp             \ 
    5858                ProxyFactory.cpp                \ 
    59                 Reactor.cpp 
     59                Reactor.cpp                     \ 
     60                gadgetmain.cpp 
    6061 
    6162include $(MKPATH)/dpp.obj-subdir.mk 
  • juggler/trunk/modules/gadgeteer/gadget/gadgetmain.cpp

    r20490 r20761  
    2525 *************** <auto-copyright.pl END do not edit this line> ***************/ 
    2626 
    27 #if defined(WIN32) || defined(WIN64) 
    28 #include <windows.h> 
     27#include <gadget/gadgetConfig.h> 
     28 
    2929#include <iostream> 
    3030#include <sstream> 
    3131#include <cstdlib> 
    3232#include <string> 
     33 
     34#if ! defined(WIN32) && ! defined(WIN64) 
     35#  include <dlfcn.h> 
     36#endif 
     37 
    3338#include <boost/filesystem/path.hpp> 
     39#include <boost/filesystem/operations.hpp> 
    3440#include <boost/filesystem/exception.hpp> 
    3541 
     42#include <vpr/vpr.h> 
     43 
    3644 
    3745namespace fs = boost::filesystem; 
    3846 
     47#if defined(WIN32) || defined(WIN64) 
    3948/** 
    4049 * Windows DLL entry point function. This ensures that the environment 
     
    5261      case DLL_PROCESS_ATTACH: 
    5362         { 
    54 #if defined(_MSC_VER) && _MSC_VER >= 1400 
    55             char* env_dir(NULL); 
    56             size_t len; 
    57             _dupenv_s(&env_dir, &len, "GADGET_BASE_DIR"); 
    58 #else 
    59             const char* env_dir = std::getenv("GADGET_BASE_DIR"); 
    60 #endif 
    61  
    62             if ( NULL == env_dir ) 
     63            try 
    6364            { 
    6465               char tmppath[1024]; 
     
    6667               GetModuleFileName(module, tmppath, sizeof(tmppath)); 
    6768 
    68                try 
    69                { 
    70                   fs::path dll_path(tmppath, fs::native); 
    71                   fs::path base_dir = dll_path.branch_path().branch_path(); 
     69               const fs::path dll_path(tmppath, fs::native); 
     70               fs::path base_dir = dll_path.branch_path().branch_path(); 
    7271#if (defined(JUGGLER_DEBUG) || defined(GADGET_DEBUG)) && ! defined(_DEBUG) 
    73                   // The debug DLL linked against the release runtime is in 
    74                   // <base_dir>\lib\debug. 
    75                   base_dir = base_dir.branch_path(); 
    76 #endif 
     72               // The debug DLL linked against the release runtime is in 
     73               // <base_dir>\lib\debug. 
     74               base_dir = base_dir.branch_path(); 
     75#endif 
     76 
     77               char* env_dir(NULL); 
     78#if defined(_MSC_VER) && _MSC_VER >= 1400 
     79               size_t len; 
     80               _dupenv_s(&env_dir, &len, "GADGET_BASE_DIR"); 
     81#else 
     82               env_dir = std::getenv("GADGET_BASE_DIR"); 
     83#endif 
     84 
     85               if ( NULL == env_dir ) 
     86               { 
    7787                  const std::string base_dir_str = 
    7888                     base_dir.native_directory_string(); 
     89 
    7990#if defined(_MSC_VER) && _MSC_VER >= 1400 
    8091                  _putenv_s("GADGET_BASE_DIR", base_dir_str.c_str()); 
     
    8596#endif 
    8697               } 
    87                catch (fs::filesystem_error& ex) 
    88                { 
    89                   std::cerr << "Automatic assignment of GADGET_BASE_DIR failed:\n" 
    90                             << ex.what() << std::endl; 
    91                } 
    92             } 
    93 #if defined(_MSC_VER) && _MSC_VER >= 1400 
    94             else 
    95             { 
    96                std::free(env_dir); 
    97             } 
    98 #endif 
     98#if defined(_MSC_VER) && _MSC_VER >= 1400 
     99               else 
     100               { 
     101                  std::free(env_dir); 
     102               } 
     103#endif 
     104 
     105#if defined(_MSC_VER) && _MSC_VER >= 1400 
     106               _dupenv_s(&env_dir, &len, "GADGET_DATA_DIR"); 
     107#else 
     108               env_dir = std::getenv("GADGET_DATA_DIR"); 
     109#endif 
     110 
     111               if ( NULL == env_dir ) 
     112               { 
     113                  fs::path data_dir(base_dir / "share" / "gadgeteer"); 
     114                  const std::string data_dir_str = 
     115                     data_dir.native_directory_string(); 
     116 
     117#if defined(_MSC_VER) && _MSC_VER >= 1400 
     118                  _putenv_s("GADGET_DATA_DIR", data_dir_str.c_str()); 
     119#else 
     120                  std::ostringstream env_stream; 
     121                  env_stream << "GADGET_DATA_DIR=" << data_dir_str; 
     122                  putenv(env_stream.str().c_str()); 
     123#endif 
     124               } 
     125#if defined(_MSC_VER) && _MSC_VER >= 1400 
     126               else 
     127               { 
     128                  std::free(env_dir); 
     129               } 
     130#endif 
     131            } 
     132            catch (fs::filesystem_error& ex) 
     133            { 
     134               std::cerr << "Automatic assignment of Gadgeteer environment " 
     135                         << "variables failed:\n" << ex.what() << std::endl; 
     136            } 
    99137         } 
    100138         break; 
     
    105143   return TRUE; 
    106144} 
    107  
    108  
     145#else 
     146/** 
     147 * Non-Windows shared library constructor. This ensures that the environment 
     148 * variable \c GADGET_BASE_DIR is set as soon as this shared library is loaded. 
     149 * If it is not set, then it sets it based on an assumption about the 
     150 * structure of a Gadgeteer installation. More specifically, an assumption is 
     151 * made that this shared library lives in the \c lib subdirectory of the VR 
     152 * Juggler installation. Therefore, the root of the Gadgeteer installation is 
     153 * the parent of the directory containing this shared library. 
     154 */ 
     155extern "C" void __attribute ((constructor)) gadgetLibraryInit() 
     156
     157   Dl_info info; 
     158   info.dli_fname = 0; 
     159   const int result = dladdr(reinterpret_cast<const void*>(&gadgetLibraryInit), 
     160                             &info); 
     161 
     162   // NOTE: dladdr(3) really does return a non-zero value on success. 
     163   if ( 0 != result ) 
     164   { 
     165      try 
     166      { 
     167         fs::path lib_file(info.dli_fname, fs::native); 
     168         lib_file = fs::system_complete(lib_file); 
     169 
     170#if defined(VPR_OS_IRIX) && defined(_ABIN32) 
     171         const std::string bit_suffix("32"); 
     172#elif defined(VPR_OS_IRIX) && defined(_ABI64) || \ 
     173      defined(VPR_OS_Linux) && defined(__x86_64__) 
     174         const std::string bit_suffix("64"); 
     175#else 
     176         const std::string bit_suffix(""); 
     177#endif 
     178 
     179         // Get the directory containing this shared library. 
     180         const fs::path lib_path = lib_file.branch_path(); 
     181 
     182         // Start the search for the root of the Gadgeteer installation in the 
     183         // parent of the directory containing this shared library. 
     184         fs::path base_dir = lib_path.branch_path(); 
     185 
     186         // Use the lib subdirectory to figure out when we have found the root 
     187         // of the Gadgeteer installation tree. 
     188         const fs::path lib_subdir(std::string("lib") + bit_suffix); 
     189 
     190         bool found(false); 
     191         while ( ! found ) 
     192         { 
     193            try 
     194            { 
     195               if ( ! fs::exists(base_dir / lib_subdir) ) 
     196               { 
     197                  base_dir = base_dir.branch_path(); 
     198               } 
     199               else 
     200               { 
     201                  found = true; 
     202               } 
     203            } 
     204            catch (fs::filesystem_error&) 
     205            { 
     206               base_dir = base_dir.branch_path(); 
     207            } 
     208         } 
     209 
     210         std::cout << base_dir.native_directory_string() << std::endl; 
     211         const fs::path data_dir = base_dir / GADGET_SHARE_DIR; 
     212 
     213         // We use the overwrite value of 0 as a way around testing whether 
     214         // the environment variables are already set. 
     215         setenv("GADGET_BASE_DIR", base_dir.native_directory_string().c_str(), 
     216                0); 
     217         setenv("GADGET_DATA_DIR", data_dir.native_directory_string().c_str(), 
     218                0); 
     219      } 
     220      catch (fs::filesystem_error& ex) 
     221      { 
     222         std::cerr << "Automatic assignment of Gadgeteer environment " 
     223                   << "variables failed:\n" << ex.what() << std::endl; 
     224      } 
     225   } 
     226
    109227#endif  /* defined(WIN32) || defined(WIN64) */