Skip to content

Commit 36c7364

Browse files
authored
Merge pull request #259 from tboox/clang
Fix build for clang on windows
2 parents 99e9476 + 02c11a4 commit 36c7364

File tree

4 files changed

+52
-42
lines changed

4 files changed

+52
-42
lines changed

src/tbox/platform/windows/dns.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@
3333
*/
3434
tb_bool_t tb_dns_init_env()
3535
{
36-
// done
37-
FIXED_INFO* info = tb_null;
38-
ULONG size = 0;
39-
tb_size_t count = 0;
36+
FIXED_INFO* info = tb_null;
37+
ULONG size = 0;
4038
do
4139
{
4240
// init func
@@ -66,7 +64,6 @@ tb_bool_t tb_dns_init_env()
6664

6765
// add the first dns address
6866
tb_dns_server_add(info->DnsServerList.IpAddress.String);
69-
count++;
7067

7168
// walk dns address
7269
IP_ADDR_STRING* addr = info->DnsServerList.Next;
@@ -77,7 +74,6 @@ tb_bool_t tb_dns_init_env()
7774

7875
// add the dns address
7976
tb_dns_server_add(addr->IpAddress.String);
80-
count++;
8177
}
8278

8379
} while (0);

src/tbox/prefix/compiler.h

+48-34
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@
126126
# error Unknown borland c++ Compiler Version
127127
# endif
128128

129-
// gnu c/c++
130-
#elif defined(__GNUC__)
131-
# define TB_COMPILER_IS_GCC
129+
// gcc or clang
130+
#elif defined(__GNUC__) || defined(__clang__)
131+
132132
# if defined(__MINGW32__) || defined(__MINGW64__)
133133
# define TB_COMPILER_IS_MINGW
134134
# endif
@@ -142,43 +142,23 @@
142142
defined(TB_COMPILER_ON_MSYS) || defined(TB_COMPILER_ON_CYGWIN)
143143
# define TB_COMPILER_LIKE_UNIX
144144
# endif
145-
# define TB_COMPILER_VERSION_BT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) > ((major) * 100 + (minor)))
146-
# define TB_COMPILER_VERSION_BE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) >= ((major) * 100 + (minor)))
147-
# define TB_COMPILER_VERSION_EQ(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) == ((major) * 100 + (minor)))
148-
# define TB_COMPILER_VERSION_LT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) < ((major) * 100 + (minor)))
149-
# define TB_COMPILER_VERSION_LE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) <= ((major) * 100 + (minor)))
150-
# define TB_COMPILER_STRING "gnu c/c++"
151-
# if __GNUC__ == 2
152-
# if __GNUC_MINOR__ < 95
153-
# define TB_COMPILER_VERSION_STRING "gnu c/c++ <2.95"
154-
# elif __GNUC_MINOR__ == 95
155-
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.95"
156-
# elif __GNUC_MINOR__ == 96
157-
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.96"
158-
# else
159-
# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 2.96 && < 3.0"
160-
# endif
161-
# elif __GNUC__ == 3
162-
# if __GNUC_MINOR__ == 2
163-
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.2"
164-
# elif __GNUC_MINOR__ == 3
165-
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.3"
166-
# elif __GNUC_MINOR__ == 4
167-
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.4"
168-
# else
169-
# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 3.4 && < 4.0"
170-
# endif
171-
# elif __GNUC__ >= 4 && defined(__GNUC_MINOR__)
172-
# define TB_COMPILER_VERSION_STRING __tb_mstrcat4__("gnu c/c++ ", __tb_mstring_ex__(__GNUC__), ".", __tb_mstring_ex__(__GNUC_MINOR__))
173-
# else
174-
# error Unknown gnu c/c++ Compiler Version
145+
146+
# if defined(__clang__)
147+
# define TB_COMPILER_IS_CLANG
175148
# endif
176149

150+
// we always need to be compatible with gcc style code if the current compiler is clang
151+
# define TB_COMPILER_IS_GCC
152+
177153
// clang
178154
# if defined(__clang__)
179-
# define TB_COMPILER_IS_CLANG
180155
# undef TB_COMPILER_STRING
181156
# define TB_COMPILER_STRING "clang c/c++"
157+
# define TB_COMPILER_VERSION_BT(major, minor) ((__clang_major__ * 100 + __clang_minor__) > ((major) * 100 + (minor)))
158+
# define TB_COMPILER_VERSION_BE(major, minor) ((__clang_major__ * 100 + __clang_minor__) >= ((major) * 100 + (minor)))
159+
# define TB_COMPILER_VERSION_EQ(major, minor) ((__clang_major__ * 100 + __clang_minor__) == ((major) * 100 + (minor)))
160+
# define TB_COMPILER_VERSION_LT(major, minor) ((__clang_major__ * 100 + __clang_minor__) < ((major) * 100 + (minor)))
161+
# define TB_COMPILER_VERSION_LE(major, minor) ((__clang_major__ * 100 + __clang_minor__) <= ((major) * 100 + (minor)))
182162
# if defined(__VERSION__)
183163
# undef TB_COMPILER_VERSION_STRING
184164
# define TB_COMPILER_VERSION_STRING __VERSION__
@@ -204,6 +184,40 @@
204184
* pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)
205185
*/
206186
# pragma clang diagnostic ignored "-Wnullability-completeness"
187+
188+
// gcc
189+
# elif defined(__GNUC__)
190+
# define TB_COMPILER_VERSION_BT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) > ((major) * 100 + (minor)))
191+
# define TB_COMPILER_VERSION_BE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) >= ((major) * 100 + (minor)))
192+
# define TB_COMPILER_VERSION_EQ(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) == ((major) * 100 + (minor)))
193+
# define TB_COMPILER_VERSION_LT(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) < ((major) * 100 + (minor)))
194+
# define TB_COMPILER_VERSION_LE(major, minor) ((__GNUC__ * 100 + __GNUC_MINOR__) <= ((major) * 100 + (minor)))
195+
# define TB_COMPILER_STRING "gnu c/c++"
196+
# if __GNUC__ == 2
197+
# if __GNUC_MINOR__ < 95
198+
# define TB_COMPILER_VERSION_STRING "gnu c/c++ <2.95"
199+
# elif __GNUC_MINOR__ == 95
200+
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.95"
201+
# elif __GNUC_MINOR__ == 96
202+
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 2.96"
203+
# else
204+
# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 2.96 && < 3.0"
205+
# endif
206+
# elif __GNUC__ == 3
207+
# if __GNUC_MINOR__ == 2
208+
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.2"
209+
# elif __GNUC_MINOR__ == 3
210+
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.3"
211+
# elif __GNUC_MINOR__ == 4
212+
# define TB_COMPILER_VERSION_STRING "gnu c/c++ 3.4"
213+
# else
214+
# define TB_COMPILER_VERSION_STRING "gnu c/c++ > 3.4 && < 4.0"
215+
# endif
216+
# elif __GNUC__ >= 4 && defined(__GNUC_MINOR__)
217+
# define TB_COMPILER_VERSION_STRING __tb_mstrcat4__("gnu c/c++ ", __tb_mstring_ex__(__GNUC__), ".", __tb_mstring_ex__(__GNUC_MINOR__))
218+
# else
219+
# error Unknown gnu c/c++ Compiler Version
220+
# endif
207221
# endif
208222

209223
// watcom c/c++

src/xmake.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ check_interfaces() {
248248
check_module_cfuncs "posix" "dlfcn.h" "dlopen"
249249
check_module_cfuncs "posix" "sys/stat.h fcntl.h" "open" "stat64" "lstat64"
250250
check_module_cfuncs "posix" "unistd.h" "gethostname"
251-
check_module_cfuncs "posix" "ifaddrs.h" "getifaddrs"
251+
check_module_cfuncs "posix" "ifaddrs.h net/if_dl.h" "getifaddrs"
252252
check_module_cfuncs "posix" "semaphore.h" "sem_init"
253253
check_module_cfuncs "posix" "unistd.h" "getpagesize" "sysconf"
254254
check_module_cfuncs "posix" "sched.h" "sched_yield" "sched_setaffinity" # need _GNU_SOURCE

xmake/check_interfaces.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function _check_interfaces(target)
183183
_check_module_cfuncs(target, "posix", "dlfcn.h", "dlopen")
184184
_check_module_cfuncs(target, "posix", {"sys/stat.h", "fcntl.h"}, "open", "stat64", "lstat64")
185185
_check_module_cfuncs(target, "posix", "unistd.h", "gethostname")
186-
_check_module_cfuncs(target, "posix", "ifaddrs.h", "getifaddrs")
186+
_check_module_cfuncs(target, "posix", {"ifaddrs.h", "net/if_dl.h"}, "getifaddrs")
187187
_check_module_cfuncs(target, "posix", "unistd.h", "getpagesize", "sysconf")
188188
_check_module_cfuncs(target, "posix", "sched.h", "sched_yield", "sched_setaffinity") -- need _GNU_SOURCE
189189
_check_module_cfuncs(target, "posix", "regex.h", "regcomp", "regexec")

0 commit comments

Comments
 (0)