Changeset 20762

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

Set SNX_BASE_DIR and the new environment variable SNX_DATA_DIR automatically
on all platforms. Bumped the version to 1.3.3.

Files:

Legend:

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

    r20493 r20762  
    11DATE        AUTHOR      CHANGE 
    22----------- ----------- ------------------------------------------------------- 
     3Sep-04-2007 patrick     Use new environment variable SNX_DATA_DIR as a way to 
     4                        look up files in SNX_BASE_DIR/share/sonix. 
     5                        NEW VERSION: 1.3.3 
     6Sep-04-2007 patrick     Set SNX_BASE_DIR automatically on all platforms. 
    37Jul-08-2007 patrick     Debug-enabled code linked against the release runtime 
    48                        on Windows is now named the same as optimized code. 
  • juggler/trunk/modules/sonix/VERSION

    r20493 r20762  
     11.3.3-0 @09/05/2007 03:00:00 UTC@ 
    121.3.2-0 @07/08/2007 21:15:00 UTC@ 
    231.3.1-0 @06/26/2007 23:10:00 UTC@ 
  • juggler/trunk/modules/sonix/snx/Makefile.in

    r19729 r20762  
    5151                SoundImplementation.cpp         \ 
    5252                StubSoundImplementation.cpp     \ 
     53                snxmain.cpp                     \ 
    5354                sonix.cpp 
    5455 
  • juggler/trunk/modules/sonix/snx/snxmain.cpp

    r20490 r20762  
    3434 *************** <auto-copyright.pl END do not edit this line> ***************/ 
    3535 
    36 #if defined(WIN32) || defined(WIN64) 
    37 #include <windows.h> 
     36#include <snx/snxConfig.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 
     51#include <vpr/vpr.h> 
     52 
    4553 
    4654namespace fs = boost::filesystem; 
    4755 
     56#if defined(WIN32) || defined(WIN64) 
    4857/** 
    4958 * Windows DLL entry point function. This ensures that the environment 
     
    6170      case DLL_PROCESS_ATTACH: 
    6271         { 
    63 #if defined(_MSC_VER) && _MSC_VER >= 1400 
    64             char* env_dir(NULL); 
    65             size_t len; 
    66             _dupenv_s(&env_dir, &len, "SNX_BASE_DIR"); 
    67 #else 
    68             const char* env_dir = std::getenv("SNX_BASE_DIR"); 
    69 #endif 
    70  
    71             if ( NULL == env_dir ) 
     72            try 
    7273            { 
    7374               char tmppath[1024]; 
     
    7576               GetModuleFileName(module, tmppath, sizeof(tmppath)); 
    7677 
    77                try 
    78                { 
    79                   fs::path dll_path(tmppath, fs::native); 
    80                   fs::path base_dir = dll_path.branch_path().branch_path(); 
     78               const fs::path dll_path(tmppath, fs::native); 
     79               fs::path base_dir = dll_path.branch_path().branch_path(); 
    8180#if (defined(JUGGLER_DEBUG) || defined(SNX_DEBUG)) && ! defined(_DEBUG) 
    82                   // The debug DLL linked against the release runtime is in 
    83                   // <base_dir>\lib\debug. 
    84                   base_dir = base_dir.branch_path(); 
    85 #endif 
     81               // The debug DLL linked against the release runtime is in 
     82               // <base_dir>\lib\debug. 
     83               base_dir = base_dir.branch_path(); 
     84#endif 
     85 
     86               char* env_dir(NULL); 
     87#if defined(_MSC_VER) && _MSC_VER >= 1400 
     88               size_t len; 
     89               _dupenv_s(&env_dir, &len, "SNX_BASE_DIR"); 
     90#else 
     91               env_dir = std::getenv("SNX_BASE_DIR"); 
     92#endif 
     93 
     94               if ( NULL == env_dir ) 
     95               { 
    8696                  const std::string base_dir_str = 
    8797                     base_dir.native_directory_string(); 
     98 
    8899#if defined(_MSC_VER) && _MSC_VER >= 1400 
    89100                  _putenv_s("SNX_BASE_DIR", base_dir_str.c_str()); 
     
    94105#endif 
    95106               } 
    96                catch (fs::filesystem_error& ex) 
    97                { 
    98                   std::cerr << "Automatic assignment of SNX_BASE_DIR failed:\n" 
    99                             << ex.what() << std::endl; 
    100                } 
    101             } 
    102 #if defined(_MSC_VER) && _MSC_VER >= 1400 
    103             else 
    104             { 
    105                std::free(env_dir); 
    106             } 
    107 #endif 
     107#if defined(_MSC_VER) && _MSC_VER >= 1400 
     108               else 
     109               { 
     110                  std::free(env_dir); 
     111               } 
     112#endif 
     113 
     114#if defined(_MSC_VER) && _MSC_VER >= 1400 
     115               _dupenv_s(&env_dir, &len, "SNX_DATA_DIR"); 
     116#else 
     117               env_dir = std::getenv("SNX_DATA_DIR"); 
     118#endif 
     119 
     120               if ( NULL == env_dir ) 
     121               { 
     122                  fs::path data_dir(base_dir / "share" / "sonix"); 
     123                  const std::string data_dir_str = 
     124                     data_dir.native_directory_string(); 
     125 
     126#if defined(_MSC_VER) && _MSC_VER >= 1400 
     127                  _putenv_s("SNX_DATA_DIR", data_dir_str.c_str()); 
     128#else 
     129                  std::ostringstream env_stream; 
     130                  env_stream << "SNX_DATA_DIR=" << data_dir_str; 
     131                  putenv(env_stream.str().c_str()); 
     132#endif 
     133               } 
     134#if defined(_MSC_VER) && _MSC_VER >= 1400 
     135               else 
     136               { 
     137                  std::free(env_dir); 
     138               } 
     139#endif 
     140            } 
     141            catch (fs::filesystem_error& ex) 
     142            { 
     143               std::cerr << "Automatic assignment of Sonix environment " 
     144                         << "variables failed:\n" << ex.what() << std::endl; 
     145            } 
    108146         } 
    109147         break; 
     
    114152   return TRUE; 
    115153} 
    116  
    117  
     154#else 
     155/** 
     156 * Non-Windows shared library constructor. This ensures that the environment 
     157 * variable \c SNX_BASE_DIR is set as soon as this shared library is loaded. 
     158 * If it is not set, then it sets it based on an assumption about the 
     159 * structure of a Sonix installation. More specifically, an assumption is made 
     160 * that this shared library lives in the \c lib subdirectory of the Sonix 
     161 * installation. Therefore, the root of the Sonix installation is the parent 
     162 * of the directory containing this shared library. 
     163 */ 
     164extern "C" void __attribute ((constructor)) snxLibraryInit() 
     165
     166   Dl_info info; 
     167   info.dli_fname = 0; 
     168   const int result = dladdr(reinterpret_cast<const void*>(&snxLibraryInit), 
     169                             &info); 
     170 
     171   // NOTE: dladdr(3) really does return a non-zero value on success. 
     172   if ( 0 != result ) 
     173   { 
     174      try 
     175      { 
     176         fs::path lib_file(info.dli_fname, fs::native); 
     177         lib_file = fs::system_complete(lib_file); 
     178 
     179#if defined(VPR_OS_IRIX) && defined(_ABIN32) 
     180         const std::string bit_suffix("32"); 
     181#elif defined(VPR_OS_IRIX) && defined(_ABI64) || \ 
     182      defined(VPR_OS_Linux) && defined(__x86_64__) 
     183         const std::string bit_suffix("64"); 
     184#else 
     185         const std::string bit_suffix(""); 
     186#endif 
     187 
     188         // Get the directory containing this shared library. 
     189         const fs::path lib_path = lib_file.branch_path(); 
     190 
     191         // Start the search for the root of the Sonix installation in the 
     192         // parent of the directory containing this shared library. 
     193         fs::path base_dir = lib_path.branch_path(); 
     194 
     195         // Use the lib subdirectory to figure out when we have found the root 
     196         // of the Sonix installation tree. 
     197         const fs::path lib_subdir(std::string("lib") + bit_suffix); 
     198 
     199         bool found(false); 
     200         while ( ! found ) 
     201         { 
     202            try 
     203            { 
     204               if ( ! fs::exists(base_dir / lib_subdir) ) 
     205               { 
     206                  base_dir = base_dir.branch_path(); 
     207               } 
     208               else 
     209               { 
     210                  found = true; 
     211               } 
     212            } 
     213            catch (fs::filesystem_error&) 
     214            { 
     215               base_dir = base_dir.branch_path(); 
     216            } 
     217         } 
     218 
     219         std::cout << base_dir.native_directory_string() << std::endl; 
     220         const fs::path data_dir = base_dir / SNX_SHARE_DIR; 
     221 
     222         // We use the overwrite value of 0 as a way around testing whether 
     223         // the environment variables are already set. 
     224         setenv("SNX_BASE_DIR", base_dir.native_directory_string().c_str(), 0); 
     225         setenv("SNX_DATA_DIR", data_dir.native_directory_string().c_str(), 0); 
     226      } 
     227      catch (fs::filesystem_error& ex) 
     228      { 
     229         std::cerr << "Automatic assignment of Sonix environment " 
     230                   << "variables failed:\n" << ex.what() << std::endl; 
     231      } 
     232   } 
     233
    118234#endif  /* defined(WIN32) || defined(WIN64) */