diff options
| author | ruki <[email protected]> | 2024-08-22 22:59:07 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-08-22 22:59:07 +0800 |
| commit | 01d4ef480fdb495b13fcd9f4529b30e5ccd5d1c7 (patch) | |
| tree | a8d46039b020301fddb445823a84e1cfec12ccdd /core/src | |
| parent | 6e8697ed326e5dc8424812681754e341152cf635 (diff) | |
detect host and arch for windows/cosmocc
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/engine.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 69307a46f..ae41a4d6e 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -49,6 +49,9 @@ #ifdef TB_CONFIG_OS_HAIKU # include <image.h> #endif +#ifdef __COSMOPOLITAN__ +# include <sys/utsname.h> +#endif // for uid #ifndef TB_CONFIG_OS_WINDOWS @@ -958,7 +961,18 @@ static tb_void_t xm_engine_init_host(xm_engine_t* engine) // init system host tb_char_t const* syshost = tb_null; -#if defined(TB_CONFIG_OS_WINDOWS) +#if defined(__COSMOPOLITAN__) + struct utsname buffer; + if (uname(&buffer) == 0) + { + if (tb_strstr(buffer.sysname, "Darwin")) + syshost = "macosx"; + else if (tb_strstr(buffer.sysname, "Linux")) + syshost = "linux"; + else if (tb_strstr(buffer.sysname, "Windows")) + syshost = "windows"; + } +#elif defined(TB_CONFIG_OS_WINDOWS) syshost = "windows"; #elif defined(TB_CONFIG_OS_MACOSX) syshost = "macosx"; @@ -1039,7 +1053,22 @@ static tb_void_t xm_engine_init_arch(xm_engine_t* engine) // init system architecture tb_char_t const* sysarch = tb_null; -#if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) +#if defined(__COSMOPOLITAN__) + struct utsname buffer; + if (uname(&buffer) == 0) + { + sysarch = buffer.machine; + if (tb_strstr(buffer.sysname, "Windows")) + { + if (!tb_strcmp(buffer.machine, "x86_64")) + sysarch = "x64"; + else if (!tb_strcmp(buffer.machine, "i686") || !tb_strcmp(buffer.machine, "i386")) + sysarch = "x86"; + } + else if (!tb_strcmp(buffer.machine, "aarch64")) + sysarch = "arm64"; + } +#elif defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) // the GetNativeSystemInfo function type typedef void (WINAPI *GetNativeSystemInfo_t)(LPSYSTEM_INFO); |
