39 #include <sys/utsname.h>
44#define CASE_TO_STRING(U,V) case U::V: return #V;
49 if( 0 == ::uname(&uinfo) ) {
50 info.sysname = std::string(uinfo.sysname);
51 info.nodename = std::string(uinfo.nodename);
52 info.release = std::string(uinfo.release);
53 info.version = std::string(uinfo.version);
54 info.machine = std::string(uinfo.machine);
55 #if defined(_GNU_SOURCE)
56 info.domainname = std::string(uinfo.domainname);
66 std::string _and_arch_tmp, _and_arch_final;
71 _and_arch_tmp =
"armv6hf";
73 _and_arch_tmp =
"armv6";
77 _and_arch_tmp =
"i586";
80 _and_arch_tmp =
"ppc";
86 _and_arch_tmp =
"sparc";
89 _and_arch_tmp =
"superh";
93 _and_arch_tmp =
"aarch64";
96 _and_arch_tmp =
"amd64";
102 _and_arch_tmp =
"mips64";
105 _and_arch_tmp =
"ia64";
108 _and_arch_tmp =
"sparcv9";
111 _and_arch_tmp =
"superh64";
114 _and_arch_tmp =
"wasm32";
117 _and_arch_tmp =
"wasm64";
120 _and_arch_tmp =
"undef_arch";
127 _and_arch_final = _and_arch_tmp;
131 _and_arch_final =
"universal";
135 _and_arch_final = _and_arch_tmp;
139 _and_arch_final = _and_arch_tmp;
143 _and_arch_final = _and_arch_tmp;
147 _and_arch_final = _and_arch_tmp;
151 _and_arch_final = _and_arch_tmp;
155 _and_arch_final = _and_arch_tmp;
159 _and_arch_final = _and_arch_tmp;
162 return os_ +
"-" + _and_arch_final;
174 jau::os::to_string(
os).c_str(),
175 ( rti_ok ? rti.
release.c_str() :
""),
176 jau::cpu::to_string(
cpu.family).c_str() ) );
177 cpu.toString(sb,
true);
181 sb.append(
", runtime: ").append(rti.
to_string()).append(
"\n");
187std::pair<std::string, bool>
193 const std::string libBaseName = isBasename ? filename :
jau::fs::basename(filename);
194 const std::string libBaseNameLC = caseInsensitive ?
jau::toLower(libBaseName) : libBaseName;
195 const size_t pre_idx = libBaseNameLC.find(prefix);
197 const size_t sfx_idx = libBaseNameLC.rfind(suffix);
198 if( std::string::npos != sfx_idx ) {
201 for (
size_t i = sfx_idx + suffix.length(); i < libBaseName.size(); i++) {
202 const char c = libBaseName[i];
203 if (!(c ==
'.' || (c >=
'0' && c <=
'9'))) {
211 const size_t sfx_len = libBaseName.size() - sfx_idx;
212 res = libBaseName.substr(prefix.size(), libBaseName.size() - prefix.size() - sfx_len);
214 return std::make_pair(res,
true);
218 return std::make_pair(std::string(),
false);
230 std::vector<std::string> res;
235 res.push_back(libName);
242 res.push_back(libBaseName);
247static void DynamicLinker_addBasenames(
const std::string& cause,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
248 for (
const std::string& baseName : baseNames) {
249 DBG_PRINT(
"NativeLibrary.enumerateLibraryPaths: %s: '%s'", cause.c_str(), baseName.c_str());
250 paths.push_back(baseName);
253static void DynamicLinker_addAbsPaths(
const std::string& cause,
const std::string& abs_path,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
254 for (
const std::string& baseName : baseNames) {
255 std::string p(abs_path); p.append(
"/").append(baseName);
256 DBG_PRINT(
"NativeLibrary.enumerateLibraryPaths: %s: '%s', from path '%s'", cause.c_str(), p.c_str(), abs_path.c_str());
260static void DynamicLinker_addSysPaths(
const std::string& cause,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
266 for(
const std::string& p : lib_paths) {
271static void DynamicLinker_addRelPaths(
const std::string& cause,
const std::string& path,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
272 std::string abs_path;
274 if( path_stats.exists() ) {
281 bool searchSystemPath,
282 bool searchSystemPathFirst)
noexcept {
283 DBG_PRINT(
"DynamicLibrary.enumerateLibraryPaths: libName '%s'", libName.c_str());
284 std::vector<std::string> paths;
285 if ( 0 == libName.size() ) {
291 paths.push_back(libName);
292 DBG_PRINT(
"NativeLibrary.enumerateLibraryPaths: done, absolute path found '%s'", libName.c_str());
299 if( searchSystemPath && searchSystemPathFirst ) {
307 DynamicLinker_addAbsPaths(
"add.ssp_1st_macos_cur",
"/System/Library/Frameworks/" + libName +
".framework", baseNames, paths);
339 if( searchSystemPath && !searchSystemPathFirst ) {
347 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.
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...
constexpr bool is_little_endian() noexcept
Evaluates true if platform is running in little endian mode, i.e.
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.
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 - \\.
std::string get_os_and_arch() noexcept
Returns this hosts's common name, see get_os_and_arch()
std::string get_platform_info() noexcept
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.
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.
abi_type_t get_abi_type() noexcept
@ Emscripten
WebAssembly with Unix/Posix suport bit (emscripten)
@ native
Identifier for native OS type, one of the above.
@ FreeBSD
FreeBSD bit, includes: unix.
@ Darwin
Darwin (Apple OSX and iOS) bit, includes: unix.
@ GenWasm
Generic WebAssembly bit.
@ QnxNTO
QNX NTO (>= 6) bit, includes: unix.
@ Android
Android bit, includes: linux and unix.
@ Linux
Linux bit, contained by: android; includes: unix.
@ gnu_armhf
ARM GNU-EABI ARMHF -mfloat-abi=hard.
std::string format_string(const char *format,...)
Returns a string according to printf() formatting rules and variable number of arguments following th...
std::string toLower(const std::string &s) 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.
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2024 Gothel Software e.K.
__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
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