From 1223593a8b27f62893b71d66b0fba97aa683f42b Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 23 May 2024 00:15:21 +0800 Subject: [PATCH 1/5] improve to build for clang --- src/tbox/prefix/compiler.h | 82 ++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/src/tbox/prefix/compiler.h b/src/tbox/prefix/compiler.h index 1fbc200d5..3f6e5cf82 100644 --- a/src/tbox/prefix/compiler.h +++ b/src/tbox/prefix/compiler.h @@ -126,9 +126,9 @@ # error Unknown borland c++ Compiler Version # endif -// gnu c/c++ -#elif defined(__GNUC__) -# define TB_COMPILER_IS_GCC +// gcc or clang +#elif defined(__GNUC__) || defined(__clang__) + # if defined(__MINGW32__) || defined(__MINGW64__) # define TB_COMPILER_IS_MINGW # endif @@ -142,43 +142,23 @@ defined(TB_COMPILER_ON_MSYS) || defined(TB_COMPILER_ON_CYGWIN) # define TB_COMPILER_LIKE_UNIX # endif -# define TB_COMPILER_VERSION_BT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) > ((major) * 100 + (minor))) -# define TB_COMPILER_VERSION_BE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) >= ((major) * 100 + (minor))) -# define TB_COMPILER_VERSION_EQ(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) == ((major) * 100 + (minor))) -# define TB_COMPILER_VERSION_LT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) < ((major) * 100 + (minor))) -# define TB_COMPILER_VERSION_LE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) <= ((major) * 100 + (minor))) -# define TB_COMPILER_STRING "gnu c/c++" -# if __GNUC__ == 2 -# if __GNUC_MINOR__ < 95 -# define TB_COMPILER_VERSION_STRING "gnu c/c++ <2.95" -# elif __GNUC_MINOR__ == 95 -# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.95" -# elif __GNUC_MINOR__ == 96 -# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.96" -# else -# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 2.96 && < 3.0" -# endif -# elif __GNUC__ == 3 -# if __GNUC_MINOR__ == 2 -# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.2" -# elif __GNUC_MINOR__ == 3 -# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.3" -# elif __GNUC_MINOR__ == 4 -# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.4" -# else -# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 3.4 && < 4.0" -# endif -# elif __GNUC__ >= 4 && defined(__GNUC_MINOR__) -# define TB_COMPILER_VERSION_STRING __tb_mstrcat4__("gnu c/c++ ", __tb_mstring_ex__(__GNUC__), ".", __tb_mstring_ex__(__GNUC_MINOR__)) -# else -# error Unknown gnu c/c++ Compiler Version + +# if defined(__clang__) +# define TB_COMPILER_IS_CLANG +# endif +# if defined(__GNUC__) +# define TB_COMPILER_IS_GCC # endif // clang # if defined(__clang__) -# define TB_COMPILER_IS_CLANG # undef TB_COMPILER_STRING # define TB_COMPILER_STRING "clang c/c++" +# define TB_COMPILER_VERSION_BT(major, minor) ((__clang_major__ * 100 + __clang_minor__) > ((major) * 100 + (minor))) +# define TB_COMPILER_VERSION_BE(major, minor) ((__clang_major__ * 100 + __clang_minor__) >= ((major) * 100 + (minor))) +# define TB_COMPILER_VERSION_EQ(major, minor) ((__clang_major__ * 100 + __clang_minor__) == ((major) * 100 + (minor))) +# define TB_COMPILER_VERSION_LT(major, minor) ((__clang_major__ * 100 + __clang_minor__) < ((major) * 100 + (minor))) +# define TB_COMPILER_VERSION_LE(major, minor) ((__clang_major__ * 100 + __clang_minor__) <= ((major) * 100 + (minor))) # if defined(__VERSION__) # undef TB_COMPILER_VERSION_STRING # define TB_COMPILER_VERSION_STRING __VERSION__ @@ -204,6 +184,40 @@ * pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) */ # pragma clang diagnostic ignored "-Wnullability-completeness" + + // gcc +# elif defined(__GNUC__) +# define TB_COMPILER_VERSION_BT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) > ((major) * 100 + (minor))) +# define TB_COMPILER_VERSION_BE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) >= ((major) * 100 + (minor))) +# define TB_COMPILER_VERSION_EQ(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) == ((major) * 100 + (minor))) +# define TB_COMPILER_VERSION_LT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) < ((major) * 100 + (minor))) +# define TB_COMPILER_VERSION_LE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) <= ((major) * 100 + (minor))) +# define TB_COMPILER_STRING "gnu c/c++" +# if __GNUC__ == 2 +# if __GNUC_MINOR__ < 95 +# define TB_COMPILER_VERSION_STRING "gnu c/c++ <2.95" +# elif __GNUC_MINOR__ == 95 +# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.95" +# elif __GNUC_MINOR__ == 96 +# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.96" +# else +# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 2.96 && < 3.0" +# endif +# elif __GNUC__ == 3 +# if __GNUC_MINOR__ == 2 +# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.2" +# elif __GNUC_MINOR__ == 3 +# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.3" +# elif __GNUC_MINOR__ == 4 +# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.4" +# else +# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 3.4 && < 4.0" +# endif +# elif __GNUC__ >= 4 && defined(__GNUC_MINOR__) +# define TB_COMPILER_VERSION_STRING __tb_mstrcat4__("gnu c/c++ ", __tb_mstring_ex__(__GNUC__), ".", __tb_mstring_ex__(__GNUC_MINOR__)) +# else +# error Unknown gnu c/c++ Compiler Version +# endif # endif // watcom c/c++ From e7321a92f2d87083a146a8273f41da56262cba01 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 23 May 2024 00:16:04 +0800 Subject: [PATCH 2/5] fix gcc detect --- src/tbox/prefix/compiler.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tbox/prefix/compiler.h b/src/tbox/prefix/compiler.h index 3f6e5cf82..8c140add7 100644 --- a/src/tbox/prefix/compiler.h +++ b/src/tbox/prefix/compiler.h @@ -146,9 +146,7 @@ # if defined(__clang__) # define TB_COMPILER_IS_CLANG # endif -# if defined(__GNUC__) -# define TB_COMPILER_IS_GCC -# endif +# define TB_COMPILER_IS_GCC // clang # if defined(__clang__) From 7bdc2c9c362ff5565ed70edc729be8e047b165f5 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 23 May 2024 00:16:19 +0800 Subject: [PATCH 3/5] add comment --- src/tbox/prefix/compiler.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tbox/prefix/compiler.h b/src/tbox/prefix/compiler.h index 8c140add7..c427e512a 100644 --- a/src/tbox/prefix/compiler.h +++ b/src/tbox/prefix/compiler.h @@ -146,6 +146,8 @@ # if defined(__clang__) # define TB_COMPILER_IS_CLANG # endif + + // we always need to be compatible with gcc style code if the current compiler is clang # define TB_COMPILER_IS_GCC // clang From a410f073cb6626de9e84c2164d78c62fd836d13e Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 23 May 2024 00:16:27 +0800 Subject: [PATCH 4/5] remove unused code --- src/tbox/platform/windows/dns.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/tbox/platform/windows/dns.c b/src/tbox/platform/windows/dns.c index 80c141f0e..9590c77d0 100644 --- a/src/tbox/platform/windows/dns.c +++ b/src/tbox/platform/windows/dns.c @@ -33,10 +33,8 @@ */ tb_bool_t tb_dns_init_env() { - // done - FIXED_INFO* info = tb_null; - ULONG size = 0; - tb_size_t count = 0; + FIXED_INFO* info = tb_null; + ULONG size = 0; do { // init func @@ -66,7 +64,6 @@ tb_bool_t tb_dns_init_env() // add the first dns address tb_dns_server_add(info->DnsServerList.IpAddress.String); - count++; // walk dns address IP_ADDR_STRING* addr = info->DnsServerList.Next; @@ -77,7 +74,6 @@ tb_bool_t tb_dns_init_env() // add the dns address tb_dns_server_add(addr->IpAddress.String); - count++; } } while (0); From 02c11a470a81c8da6fa124859597e75263e30fc9 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 23 May 2024 00:20:29 +0800 Subject: [PATCH 5/5] fix cross build --- src/xmake.sh | 2 +- xmake/check_interfaces.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xmake.sh b/src/xmake.sh index 6d72c1270..4234925d9 100755 --- a/src/xmake.sh +++ b/src/xmake.sh @@ -248,7 +248,7 @@ check_interfaces() { check_module_cfuncs "posix" "dlfcn.h" "dlopen" check_module_cfuncs "posix" "sys/stat.h fcntl.h" "open" "stat64" "lstat64" check_module_cfuncs "posix" "unistd.h" "gethostname" - check_module_cfuncs "posix" "ifaddrs.h" "getifaddrs" + check_module_cfuncs "posix" "ifaddrs.h net/if_dl.h" "getifaddrs" check_module_cfuncs "posix" "semaphore.h" "sem_init" check_module_cfuncs "posix" "unistd.h" "getpagesize" "sysconf" check_module_cfuncs "posix" "sched.h" "sched_yield" "sched_setaffinity" # need _GNU_SOURCE diff --git a/xmake/check_interfaces.lua b/xmake/check_interfaces.lua index c906e234d..ee4c4c51d 100644 --- a/xmake/check_interfaces.lua +++ b/xmake/check_interfaces.lua @@ -183,7 +183,7 @@ function _check_interfaces(target) _check_module_cfuncs(target, "posix", "dlfcn.h", "dlopen") _check_module_cfuncs(target, "posix", {"sys/stat.h", "fcntl.h"}, "open", "stat64", "lstat64") _check_module_cfuncs(target, "posix", "unistd.h", "gethostname") - _check_module_cfuncs(target, "posix", "ifaddrs.h", "getifaddrs") + _check_module_cfuncs(target, "posix", {"ifaddrs.h", "net/if_dl.h"}, "getifaddrs") _check_module_cfuncs(target, "posix", "unistd.h", "getpagesize", "sysconf") _check_module_cfuncs(target, "posix", "sched.h", "sched_yield", "sched_setaffinity") -- need _GNU_SOURCE _check_module_cfuncs(target, "posix", "regex.h", "regcomp", "regexec")