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;
175 cpu.toString(sb,
true);
179 sb.append(
", runtime: ").append(rti.
to_string()).append(
"\n");
185std::pair<std::string, bool>
192 const std::string libBaseNameLC = caseInsensitive ?
jau::toLower(libBaseName) : libBaseName;
193 const size_t pre_idx = libBaseNameLC.find(
prefix);
195 const size_t sfx_idx = libBaseNameLC.rfind(suffix);
196 if( std::string::npos != sfx_idx ) {
199 for (
size_t i = sfx_idx + suffix.length(); i < libBaseName.size(); i++) {
200 const char c = libBaseName[i];
201 if (!(c ==
'.' || (c >=
'0' && c <=
'9'))) {
209 const size_t sfx_len = libBaseName.size() - sfx_idx;
210 res = libBaseName.substr(
prefix.size(), libBaseName.size() -
prefix.size() - sfx_len);
212 return std::make_pair(res,
true);
216 return std::make_pair(std::string(),
false);
228 std::vector<std::string> res;
233 res.push_back(libName);
240 res.push_back(libBaseName);
245static void DynamicLinker_addBasenames(
const std::string& cause,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
246 for (
const std::string& baseName : baseNames) {
247 jau_DBG_PRINT(
"NativeLibrary.enumerateLibraryPaths: %s: '%s'", cause, baseName);
248 paths.push_back(baseName);
251static void DynamicLinker_addAbsPaths(
const std::string& cause,
const std::string& abs_path,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
252 for (
const std::string& baseName : baseNames) {
253 std::string p(abs_path); p.append(
"/").append(baseName);
254 jau_DBG_PRINT(
"NativeLibrary.enumerateLibraryPaths: %s: '%s', from path '%s'", cause, p, abs_path);
258static void DynamicLinker_addSysPaths(
const std::string& cause,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
264 for(
const std::string& p : lib_paths) {
269static void DynamicLinker_addRelPaths(
const std::string& cause,
const std::string& path,
const std::vector<std::string>& baseNames, std::vector<std::string>& paths)
noexcept {
270 std::string abs_path;
271 jau::fs::file_stats path_stats(path);
272 if( path_stats.exists() ) {
279 bool searchSystemPath,
280 bool searchSystemPathFirst)
noexcept {
281 jau_DBG_PRINT(
"DynamicLibrary.enumerateLibraryPaths: libName '%s'", libName);
282 std::vector<std::string> paths;
283 if ( 0 == libName.size() ) {
289 paths.push_back(libName);
290 jau_DBG_PRINT(
"NativeLibrary.enumerateLibraryPaths: done, absolute path found '%s'", libName);
297 if( searchSystemPath && searchSystemPathFirst ) {
305 DynamicLinker_addAbsPaths(
"add.ssp_1st_macos_cur",
"/System/Library/Frameworks/" + libName +
".framework", baseNames, paths);
337 if( searchSystemPath && !searchSystemPathFirst ) {
345 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 jau_DBG_PRINT(fmt,...)
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.
std::string_view to_string(const endian_t v) noexcept
Return std::string representation of the given endian.
endian_t
Endian identifier, indicating endianess of all scalar types.
bool isAbsolute(std::string_view path) noexcept
Returns true if first character is / or - in case of Windows - \\.
std::string get_cwd() noexcept
Return the current working directory or empty on failure.
std::string basename(std::string_view path) noexcept
Return stripped leading directory components from given path separated by /.
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 toLower(const std::string &s)
@ 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.
std::string format_string(std::string_view fmt, const Args &...args) noexcept
Safely returns a (non-truncated) string according to snprintf() formatting rules using a reserved str...
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