42 #include <sys/utsname.h>
47#define CASE_TO_STRING(U,V) case U::V: return #V;
49#define OSTYPE_ENUM(X) \
51 X(os_type_t,Windows) \
53 X(os_type_t,Android) \
54 X(os_type_t,FreeBSD) \
57 X(os_type_t,GenWasm) \
58 X(os_type_t,Emscripten)
72 if( 0 == ::uname(&uinfo) ) {
73 info.sysname = std::string(uinfo.sysname);
74 info.nodename = std::string(uinfo.nodename);
75 info.release = std::string(uinfo.release);
76 info.version = std::string(uinfo.version);
77 info.machine = std::string(uinfo.machine);
78 #if defined(_GNU_SOURCE)
79 info.domainname = std::string(uinfo.domainname);
87#define ABITYPE_ENUM(X) \
88 X(abi_type_t,generic) \
89 X(abi_type_t,gnu_armel) \
90 X(abi_type_t,gnu_armhf) \
91 X(abi_type_t,aarch64) \
92 X(abi_type_t,wasm32_gen) \
93 X(abi_type_t,wasm32_ems) \
94 X(abi_type_t,wasm64_gen) \
95 X(abi_type_t,wasm64_ems)
107 std::string _and_arch_tmp, _and_arch_final;
111 if( abi_type_t::gnu_armhf == abi ) {
112 _and_arch_tmp =
"armv6hf";
114 _and_arch_tmp =
"armv6";
118 _and_arch_tmp =
"i586";
121 _and_arch_tmp =
"ppc";
127 _and_arch_tmp =
"sparc";
130 _and_arch_tmp =
"superh";
134 _and_arch_tmp =
"aarch64";
137 _and_arch_tmp =
"amd64";
143 _and_arch_tmp =
"mips64";
146 _and_arch_tmp =
"ia64";
149 _and_arch_tmp =
"sparcv9";
152 _and_arch_tmp =
"superh64";
155 _and_arch_tmp =
"wasm32";
158 _and_arch_tmp =
"wasm64";
161 _and_arch_tmp =
"undef_arch";
166 case os_type_t::Android:
168 _and_arch_final = _and_arch_tmp;
170 case os_type_t::Darwin:
172 _and_arch_final =
"universal";
174 case os_type_t::Windows:
176 _and_arch_final = _and_arch_tmp;
178 case os_type_t::Linux:
180 _and_arch_final = _and_arch_tmp;
182 case os_type_t::FreeBSD:
184 _and_arch_final = _and_arch_tmp;
186 case os_type_t::QnxNTO:
188 _and_arch_final = _and_arch_tmp;
190 case os_type_t::GenWasm:
192 _and_arch_final = _and_arch_tmp;
194 case os_type_t::Emscripten:
196 _and_arch_final = _and_arch_tmp;
200 _and_arch_final = _and_arch_tmp;
203 return os_ +
"-" + _and_arch_final;
216 ( rti_ok ? rti.
release.c_str() :
""),
222 sb.append(
", runtime: ").append(rti.
to_string()).append(
"\n");
228std::pair<std::string, bool>
234 const std::string libBaseName = isBasename ? filename :
jau::fs::basename(filename);
235 const std::string libBaseNameLC = caseInsensitive ?
jau::toLower(libBaseName) : libBaseName;
236 const size_t pre_idx = libBaseNameLC.find(prefix);
238 const size_t sfx_idx = libBaseNameLC.rfind(suffix);
239 if( std::string::npos != sfx_idx ) {
242 for (
size_t i = sfx_idx + suffix.length(); i < libBaseName.size(); i++) {
243 const char c = libBaseName[i];
244 if (!(c ==
'.' || (c >=
'0' && c <=
'9'))) {
252 const size_t sfx_len = libBaseName.size() - sfx_idx;
253 res = libBaseName.substr(prefix.size(), libBaseName.size() - prefix.size() - sfx_len);
255 return std::make_pair(res,
true);
259 return std::make_pair(std::string(),
false);
271 std::vector<std::string> res;
276 res.push_back(libName);
283 res.push_back(libBaseName);
288static void DynamicLinker_addBasenames(
const std::string& cause,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
289 for (
const std::string& baseName : baseNames) {
290 DBG_PRINT(
"NativeLibrary.enumerateLibraryPaths: %s: '%s'", cause.c_str(), baseName.c_str());
291 paths.push_back(baseName);
294static void DynamicLinker_addAbsPaths(
const std::string& cause,
const std::string& abs_path,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
295 for (
const std::string& baseName : baseNames) {
296 std::string p(abs_path); p.append(
"/").append(baseName);
297 DBG_PRINT(
"NativeLibrary.enumerateLibraryPaths: %s: '%s', from path '%s'", cause.c_str(), p.c_str(), abs_path.c_str());
301static void DynamicLinker_addSysPaths(
const std::string& cause,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
307 for(
const std::string& p : lib_paths) {
312static void DynamicLinker_addRelPaths(
const std::string& cause,
const std::string& path,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
313 std::string abs_path;
315 if( path_stats.exists() ) {
322 bool searchSystemPath,
323 bool searchSystemPathFirst)
noexcept {
324 DBG_PRINT(
"DynamicLibrary.enumerateLibraryPaths: libName '%s'", libName.c_str());
325 std::vector<std::string> paths;
326 if ( 0 == libName.size() ) {
332 paths.push_back(libName);
333 DBG_PRINT(
"NativeLibrary.enumerateLibraryPaths: done, absolute path found '%s'", libName.c_str());
340 if( searchSystemPath && searchSystemPathFirst ) {
348 DynamicLinker_addAbsPaths(
"add.ssp_1st_macos_cur",
"/System/Library/Frameworks/" + libName +
".framework", baseNames, paths);
380 if( searchSystemPath && !searchSystemPathFirst ) {
388 DynamicLinker_addAbsPaths(
"add.ssp_lst_macos_cur",
"/System/Library/Frameworks/" + libName +
".framework", baseNames, paths);
Singleton CpuInfo caching all jau::cpu information.
static const CpuInfo & get() noexcept
Returns reference to const singleton instance.
cpu_family_t family
cpu_family_t derived from Architectures predefined compiler macros.
std::string toString(std::string &sb, bool details_only=false) const noexcept
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
constexpr bool exists() const noexcept
Returns true if entity does not exist, exclusive bit.
static std::string getBaseName(const std::string &filename, const bool isBasename=false, const bool caseInsensitive=jau::os::is_windows()) noexcept
Returns the library basename, i.e.
static std::vector< std::string > enumerateLibraryPaths(const std::string &libName, bool searchSystemPath=false, bool searchSystemPathFirst=false) noexcept
Returns list of potential absolute library filenames.
static constexpr_cxx20 std::string getDefaultPrefix() noexcept
Returns the native library prefix, e.g.
static constexpr_cxx20 std::string getDefaultSuffix() noexcept
Returns the native library suffix including the dot, e.g.
static constexpr_cxx20 std::string getCanonicalName(const std::string &basename, const bool checkIsCanonical=true) noexcept
Returns canonical library name for this system from given library-basename, e.g.
static bool isCanonicalName(const std::string &filename, const bool isBasename=false, const bool caseInsensitive=jau::os::is_windows()) noexcept
Returns true if the given filename contains the canonical prefix and suffix, otherwise returns false.
static std::vector< std::string > getSystemEnvLibraryPaths()
Returns a list of system paths, from the getSystemEnvLibraryPathVarname() variable.
User account information of the underlying OS.
const std::string & homedir() const noexcept
bool isValid() const noexcept
#define DBG_PRINT(...)
Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] De...
endian_t
Endian identifier, indicating endianess of all scalar types.
std::string to_string(const endian_t v) noexcept
Return std::string representation of the given endian.
constexpr bool is_little_endian(const endian_t byte_order) noexcept
Returns true if given byte_order equals endian::little, otherwise false.
std::string basename(const std::string_view &path) noexcept
Return stripped leading directory components from given path separated by /.
std::string get_cwd() noexcept
Return the current working directory or empty on failure.
bool isAbsolute(const std::string_view &path) noexcept
Returns true if first character is / or - in case of Windows - \\.
bool get_rt_os_info(RuntimeOSInfo &info) noexcept
constexpr bool is_darwin() noexcept
Evaluates true if platform os_type::native contains os_type::Darwin.
os_type_t
OS type bits and unique IDs.
constexpr abi_type_t get_abi_type(const jau::cpu::cpu_family_t cpu) noexcept
std::string get_os_and_arch(const os_type_t os, const jau::cpu::cpu_family_t cpu, const abi_type_t abi, const endian_t e) noexcept
Returns the common name for the given os_type, jau::cpu::cpu_family, abi_type and endian.
constexpr bool is_windows() noexcept
Evaluates true if platform os_type::native contains os_type::Windows.
std::string to_string(const os_type_t mask) noexcept
Return the string representation of os_type.
std::string get_platform_info(std::string &sb) noexcept
@ native
Identifier for native OS type, one of the above.
std::string format_string(const char *format,...) noexcept
Returns a string according to printf() formatting rules and variable number of arguments following th...
std::string toLower(const std::string &s) noexcept
std::string to_string(const cpu_family_t v) noexcept
@ x86_64
AMD/Intel 64-bit.
@ x86_32
AMD/Intel 32-bit.
@ wasm64
WebAssembly 64-bit.
@ superh32
Hitachi SuperH 32bit.
@ superh64
Hitachi SuperH 64bit.
@ wasm32
WebAssembly 32-bit.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
static std::vector< std::string > DynamicLinker_buildNames(const std::string &libName) noexcept
static void DynamicLinker_addAbsPaths(const std::string &cause, const std::string &abs_path, const std::vector< std::string > &baseNames, std::vector< std::string > &paths) noexcept
#define CASE_TO_STRING(U, V)
static void DynamicLinker_addBasenames(const std::string &cause, const std::vector< std::string > &baseNames, std::vector< std::string > &paths) noexcept
static void DynamicLinker_addSysPaths(const std::string &cause, const std::vector< std::string > &baseNames, std::vector< std::string > &paths) noexcept
static std::pair< std::string, bool > DynamicLinker_processCanonicalNameImpl(bool strip, const std::string &filename, const bool isBasename, const bool caseInsensitive=jau::os::is_windows()) noexcept
std::string to_string() noexcept