From cc73a97dda62b913acc4cb0e98e77e6cbc81e09e Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 1 Nov 2024 22:23:35 +0800 Subject: [PATCH] build,fwd: Fix building issues on MSYS2 --- mcfgthread/fwd.h | 21 ++++++++++++++++++++- meson.build | 17 +++++++++++------ setup_meson.sh | 2 +- test/self_oom.c | 2 ++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/mcfgthread/fwd.h b/mcfgthread/fwd.h index dc2663cd24..ad9cbe13f4 100644 --- a/mcfgthread/fwd.h +++ b/mcfgthread/fwd.h @@ -374,7 +374,26 @@ __MCF_CXX(extern "C" {) #define __MCF_0_INIT { __MCF_C(0) } #define __MCF_SET_IF(x, ...) ((void) ((x) && (*(x) = (__VA_ARGS__)))) -/* These are necessary when the header is compiled as C89 or C++98. */ +/* These are necessary when the header is compiled as C89 or C++98. The check + * for `_LP64` is for Cygwin and MSYS2. */ +#ifdef _LP64 +# define __MCF_INT64 long +# define __MCF_INTPTR long +#else +# define __MCF_INT64 long long +# define __MCF_INTPTR __MCF_64_32(long long, int) +#endif + +#if !defined LLONG_MAX +typedef __MCF_INT64 int64_t; +typedef __MCF_INTPTR intptr_t; +typedef unsigned __MCF_INT64 uint64_t; +typedef unsigned __MCF_INTPTR uintptr_t; +# define LLONG_MAX 0x7FFFFFFFFFFFFFFFL +# define LLONG_MIN (-0x7FFFFFFFFFFFFFFFL-1) +# define ULLONG_MAX 0xFFFFFFFFFFFFFFFFUL +#endif + #define __MCF_PTR_BITS __MCF_64_32(64, 32) #define __MCF_IPTR_MIN __MCF_64_32(LLONG_MIN, INT_MIN) #define __MCF_IPTR_0 __MCF_64_32(0LL, 0) diff --git a/meson.build b/meson.build index 62995fcc8c..d00e6b5488 100644 --- a/meson.build +++ b/meson.build @@ -349,12 +349,17 @@ lib_mcfgthread_dll = shared_library('mcfgthread', version: '.'.join([ ver.get('abi_major'), ver.get('abi_minor'), '0' ]), install: true) -lib_mcfgthread_a = static_library('mcfgthread', - c_pch: 'mcfgthread/xprecompiled.h', - c_args: [ '-ffreestanding', '-fasynchronous-unwind-tables' ], - sources: [ mcfgthread_src_min, mcfgthread_src_ex, ], - dependencies: [ dep_kernel32, dep_ntdll ], - install: true) +if host_machine.system() == 'cygwin' + warning('Static linking is not supported on Cygwin or MSYS2.') + lib_mcfgthread_a = lib_mcfgthread_dll +else + lib_mcfgthread_a = static_library('mcfgthread', + c_pch: 'mcfgthread/xprecompiled.h', + c_args: [ '-ffreestanding', '-fasynchronous-unwind-tables' ], + sources: [ mcfgthread_src_min, mcfgthread_src_ex, ], + dependencies: [ dep_kernel32, dep_ntdll ], + install: true) +endif import('pkgconfig').generate(lib_mcfgthread_dll, name: 'mcfgthread', diff --git a/setup_meson.sh b/setup_meson.sh index 10af6824cc..ecbb53d492 100755 --- a/setup_meson.sh +++ b/setup_meson.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -if ! grep -Eoi '^mingw' /proc/version &>/dev/null +if ! grep -Eoi '^(mingw|msys|cygwin)' /proc/version &>/dev/null then _cross_file='--cross-file meson.cross.x86_64-w64-mingw32' fi diff --git a/test/self_oom.c b/test/self_oom.c index 0888599fda..57d6478838 100644 --- a/test/self_oom.c +++ b/test/self_oom.c @@ -13,6 +13,7 @@ #define NTHREADS 64U static HANDLE threads[NTHREADS]; +#if !defined __CYGWIN__ static DWORD __stdcall @@ -25,6 +26,7 @@ thread_proc(void* arg) fprintf(stderr, "thread %d quitting\n", _MCF_thread_self_tid()); return 0; } +#endif int main(void)