Changeset 20765
- Timestamp:
- 09/06/07 09:00:36 (1 year ago)
- Files:
-
- juggler/trunk/modules/vapor/vpr/vprmain.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
juggler/trunk/modules/vapor/vpr/vprmain.cpp
r20764 r20765 133 133 extern "C" void __attribute ((constructor)) vprLibraryInit() 134 134 { 135 Dl_info info; 136 info.dli_fname = 0; 137 const int result = dladdr(reinterpret_cast<const void*>(&vprLibraryInit), 138 &info); 139 140 // NOTE: dladdr(3) really does return a non-zero value on success. 141 if ( 0 != result ) 135 const char* env_dir = std::getenv("VPR_BASE_DIR"); 136 137 if ( NULL == env_dir ) 142 138 { 143 try 139 Dl_info info; 140 info.dli_fname = 0; 141 const int result = 142 dladdr(reinterpret_cast<const void*>(&vprLibraryInit), &info); 143 144 // NOTE: dladdr(3) really does return a non-zero value on success. 145 if ( 0 != result ) 144 146 { 145 fs::path lib_file(info.dli_fname, fs::native); 146 lib_file = fs::system_complete(lib_file); 147 try 148 { 149 fs::path lib_file(info.dli_fname, fs::native); 150 lib_file = fs::system_complete(lib_file); 147 151 148 152 #if defined(VPR_OS_IRIX) && defined(_ABIN32) 149 const std::string bit_suffix("32");153 const std::string bit_suffix("32"); 150 154 #elif defined(VPR_OS_IRIX) && defined(_ABI64) || \ 151 155 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 && ! base_dir.empty() ) 156 const std::string bit_suffix("64"); 157 #else 158 const std::string bit_suffix(""); 159 #endif 160 161 // Get the directory containing this shared library. 162 const fs::path lib_path = lib_file.branch_path(); 163 164 // Start the search for the root of the VPR installation in the 165 // parent of the directory containing this shared library. 166 fs::path base_dir = lib_path.branch_path(); 167 168 // Use the lib subdirectory to figure out when we have found the 169 // root of the VPR installation tree. 170 const fs::path lib_subdir(std::string("lib") + bit_suffix); 171 172 bool found(false); 173 while ( ! found && ! base_dir.empty() ) 174 { 175 try 176 { 177 if ( ! fs::exists(base_dir / lib_subdir) ) 178 { 179 base_dir = base_dir.branch_path(); 180 } 181 else 182 { 183 found = true; 184 } 185 } 186 catch (fs::filesystem_error&) 187 { 188 base_dir = base_dir.branch_path(); 189 } 190 } 191 192 if ( found ) 193 { 194 setenv("VPR_BASE_DIR", 195 base_dir.native_directory_string().c_str(), 1); 196 } 197 } 198 catch (fs::filesystem_error& ex) 170 199 { 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 } 200 std::cerr << "Automatic assignment of VPR_BASE_DIR failed:\n" 201 << ex.what() << std::endl; 186 202 } 187 188 if ( found )189 {190 // We use the overwrite value of 0 as a way around testing whether191 // the environment variable is already set.192 setenv("VPR_BASE_DIR", base_dir.native_directory_string().c_str(),193 0);194 }195 }196 catch (fs::filesystem_error& ex)197 {198 std::cerr << "Automatic assignment of VPR_BASE_DIR failed:\n"199 << ex.what() << std::endl;200 203 } 201 204 }
