fix ioctlsocket detection
[platform/upstream/c-ares.git] / acinclude.m4
1
2
3 dnl CURL_CHECK_HEADER_WINDOWS
4 dnl -------------------------------------------------
5 dnl Check for compilable and valid windows.h header 
6
7 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
8   AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [
9     AC_COMPILE_IFELSE([
10       AC_LANG_PROGRAM([
11 #undef inline
12 #ifndef WIN32_LEAN_AND_MEAN
13 #define WIN32_LEAN_AND_MEAN
14 #endif
15 #include <windows.h>
16       ],[
17         int dummy=2*WINVER;
18       ])
19     ],[
20       ac_cv_header_windows_h="yes"
21     ],[
22       ac_cv_header_windows_h="no"
23     ])
24   ])
25   if test "x$ac_cv_header_windows_h" = "xyes"; then
26     AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
27       [Define to 1 if you have the windows.h header file.])
28     AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
29       [Define to avoid automatic inclusion of winsock.h])
30   fi
31 ])
32
33
34 dnl CURL_CHECK_HEADER_WINSOCK
35 dnl -------------------------------------------------
36 dnl Check for compilable and valid winsock.h header 
37
38 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
39   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
40   AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
41     AC_COMPILE_IFELSE([
42       AC_LANG_PROGRAM([
43 #undef inline
44 #ifndef WIN32_LEAN_AND_MEAN
45 #define WIN32_LEAN_AND_MEAN
46 #endif
47 #include <windows.h>
48 #include <winsock.h>
49       ],[
50         int dummy=WSACleanup();
51       ])
52     ],[
53       ac_cv_header_winsock_h="yes"
54     ],[
55       ac_cv_header_winsock_h="no"
56     ])
57   ])
58   if test "x$ac_cv_header_winsock_h" = "xyes"; then
59     AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
60       [Define to 1 if you have the winsock.h header file.])
61   fi
62 ])
63
64
65 dnl CURL_CHECK_HEADER_WINSOCK2
66 dnl -------------------------------------------------
67 dnl Check for compilable and valid winsock2.h header 
68
69 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
70   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
71   AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
72     AC_COMPILE_IFELSE([
73       AC_LANG_PROGRAM([
74 #undef inline
75 #ifndef WIN32_LEAN_AND_MEAN
76 #define WIN32_LEAN_AND_MEAN
77 #endif
78 #include <windows.h>
79 #include <winsock2.h>
80       ],[
81         int dummy=2*IPPROTO_ESP;
82       ])
83     ],[
84       ac_cv_header_winsock2_h="yes"
85     ],[
86       ac_cv_header_winsock2_h="no"
87     ])
88   ])
89   if test "x$ac_cv_header_winsock2_h" = "xyes"; then
90     AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
91       [Define to 1 if you have the winsock2.h header file.])
92   fi
93 ])
94
95
96 dnl CURL_CHECK_HEADER_WS2TCPIP
97 dnl -------------------------------------------------
98 dnl Check for compilable and valid ws2tcpip.h header
99
100 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
101   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
102   AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
103     AC_COMPILE_IFELSE([
104       AC_LANG_PROGRAM([
105 #undef inline
106 #ifndef WIN32_LEAN_AND_MEAN
107 #define WIN32_LEAN_AND_MEAN
108 #endif
109 #include <windows.h>
110 #include <winsock2.h>
111 #include <ws2tcpip.h>
112       ],[
113         int dummy=2*IP_PKTINFO;
114       ])
115     ],[
116       ac_cv_header_ws2tcpip_h="yes"
117     ],[
118       ac_cv_header_ws2tcpip_h="no"
119     ])
120   ])
121   if test "x$ac_cv_header_ws2tcpip_h" = "xyes"; then
122     AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
123       [Define to 1 if you have the ws2tcpip.h header file.])
124   fi
125 ])
126
127
128 dnl CURL_CHECK_TYPE_SOCKLEN_T
129 dnl -------------------------------------------------
130 dnl Check for existing socklen_t type, and provide
131 dnl an equivalent type if socklen_t not available
132
133 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
134   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
135   AC_CHECK_TYPE([socklen_t], ,[
136     AC_CACHE_CHECK([for socklen_t equivalent], 
137       [curl_cv_socklen_t_equiv], [
138       curl_cv_socklen_t_equiv="unknown"
139       for arg2 in "struct sockaddr" void; do
140         for t in int size_t unsigned long "unsigned long"; do
141           AC_COMPILE_IFELSE([
142             AC_LANG_PROGRAM([
143 #undef inline
144 #ifdef HAVE_WINDOWS_H
145 #ifndef WIN32_LEAN_AND_MEAN
146 #define WIN32_LEAN_AND_MEAN
147 #endif
148 #include <windows.h>
149 #ifdef HAVE_WINSOCK2_H
150 #include <winsock2.h>
151 #else
152 #ifdef HAVE_WINSOCK_H
153 #include <winsock.h>
154 #endif
155 #endif
156 #else
157 #ifdef HAVE_SYS_TYPES_H
158 #include <sys/types.h>
159 #endif
160 #ifdef HAVE_SYS_SOCKET_H
161 #include <sys/socket.h>
162 #endif
163 #endif
164               int getpeername (int, $arg2 *, $t *);
165             ],[
166               $t len=0;
167               getpeername(0,0,&len);
168             ])
169           ],[
170              curl_cv_socklen_t_equiv="$t"
171              break 2
172           ])
173         done
174       done
175     ])
176     if test "$curl_cv_socklen_t_equiv" = "unknown"; then
177       AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
178     else
179       AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
180         [type to use in place of socklen_t if not defined])
181     fi
182   ],[
183 #undef inline
184 #ifdef HAVE_WINDOWS_H
185 #ifndef WIN32_LEAN_AND_MEAN
186 #define WIN32_LEAN_AND_MEAN
187 #endif
188 #include <windows.h>
189 #ifdef HAVE_WINSOCK2_H
190 #include <winsock2.h>
191 #ifdef HAVE_WS2TCPIP_H
192 #include <ws2tcpip.h>
193 #endif
194 #endif
195 #else
196 #ifdef HAVE_SYS_TYPES_H
197 #include <sys/types.h>
198 #endif
199 #ifdef HAVE_SYS_SOCKET_H
200 #include <sys/socket.h>
201 #endif
202 #endif
203   ])
204 ])
205
206
207 dnl CURL_FUNC_GETNAMEINFO_ARGTYPES
208 dnl -------------------------------------------------
209 dnl Check the type to be passed to five of the arguments
210 dnl of getnameinfo function, and define those types in  
211 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
212 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7.
213 dnl This function is experimental and its results shall
214 dnl not be trusted while this notice is in place ------
215
216 AC_DEFUN([CURL_FUNC_GETNAMEINFO_ARGTYPES], [
217   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
218   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
219   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
220   AC_CACHE_CHECK([types of arguments for getnameinfo],
221     [curl_cv_func_getnameinfo_args], [
222     curl_cv_func_getnameinfo_args="unknown"
223     for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
224       for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
225         for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
226           for gni_arg7 in 'int' 'unsigned int'; do
227             AC_COMPILE_IFELSE([
228               AC_LANG_PROGRAM([
229 #undef inline
230 #ifdef HAVE_WINDOWS_H
231 #ifndef WIN32_LEAN_AND_MEAN
232 #define WIN32_LEAN_AND_MEAN
233 #endif
234 #if defined(__MINGW32__) && ( (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501) )
235 #undef _WIN32_WINNT
236 #define _WIN32_WINNT 0x0501
237 #endif
238 #include <windows.h>
239 #ifdef HAVE_WINSOCK2_H
240 #include <winsock2.h>
241 #ifdef HAVE_WS2TCPIP_H
242 #include <ws2tcpip.h>
243 #endif
244 #endif
245 #else
246 #ifdef HAVE_SYS_TYPES_H
247 #include <sys/types.h>
248 #endif
249 #ifdef HAVE_SYS_SOCKET_H
250 #include <sys/socket.h>
251 #endif
252 #ifdef HAVE_NETDB_H
253 #include <netdb.h>
254 #endif
255 #endif
256                 extern int getnameinfo($gni_arg1, $gni_arg2,
257                                        char *, $gni_arg46,
258                                        char *, $gni_arg46,
259                                        $gni_arg7);
260               ],[
261                 $gni_arg2 salen=0;
262                 $gni_arg46 hostlen=0;
263                 $gni_arg46 servlen=0;
264                 $gni_arg7 flags=0;
265                 int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
266               ])
267             ],[
268                curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
269                break 4
270             ])
271           done
272         done
273       done
274     done
275   ])
276   if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
277     AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
278   else
279     gni_prev_IFS=$IFS; IFS=','
280     set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
281     IFS=$gni_prev_IFS
282     shift
283     AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $[1],
284       [Define to the type of arg 1 for getnameinfo.])
285     AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
286       [Define to the type of arg 2 for getnameinfo.])
287     AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
288       [Define to the type of args 4 and 6 for getnameinfo.])
289     AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
290       [Define to the type of arg 7 for getnameinfo.])
291   fi
292 ])
293
294
295 dnl CURL_CHECK_NONBLOCKING_SOCKET
296 dnl -------------------------------------------------
297 dnl Check for how to set a socket to non-blocking state. There seems to exist
298 dnl four known different ways, with the one used almost everywhere being POSIX
299 dnl and XPG3, while the other different ways for different systems (old BSD,
300 dnl Windows and Amiga).
301 dnl
302 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
303 dnl O_NONBLOCK define is found but does not work. This condition is attempted
304 dnl to get caught in this script by using an excessive number of #ifdefs...
305 dnl
306 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
307 [
308   AC_MSG_CHECKING([non-blocking sockets style])
309
310   AC_TRY_COMPILE([
311 /* headers for O_NONBLOCK test */
312 #include <sys/types.h>
313 #include <unistd.h>
314 #include <fcntl.h>
315 ],[
316 /* try to compile O_NONBLOCK */
317
318 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
319 # if defined(__SVR4) || defined(__srv4__)
320 #  define PLATFORM_SOLARIS
321 # else
322 #  define PLATFORM_SUNOS4
323 # endif
324 #endif
325 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
326 # define PLATFORM_AIX_V3
327 #endif
328
329 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
330 #error "O_NONBLOCK does not work on this platform"
331 #endif
332   int socket;
333   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
334 ],[
335 dnl the O_NONBLOCK test was fine
336 nonblock="O_NONBLOCK"
337 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
338 ],[
339 dnl the code was bad, try a different program now, test 2
340
341   AC_TRY_COMPILE([
342 /* headers for FIONBIO test */
343 #include <unistd.h>
344 #include <stropts.h>
345 ],[
346 /* FIONBIO source test (old-style unix) */
347  int socket;
348  int flags = ioctl(socket, FIONBIO, &flags);
349 ],[
350 dnl FIONBIO test was good
351 nonblock="FIONBIO"
352 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
353 ],[
354 dnl FIONBIO test was also bad
355 dnl the code was bad, try a different program now, test 3
356
357   AC_TRY_COMPILE([
358 /* headers for ioctlsocket test (Windows) */
359 #undef inline
360 #ifdef HAVE_WINDOWS_H
361 #ifndef WIN32_LEAN_AND_MEAN
362 #define WIN32_LEAN_AND_MEAN
363 #endif
364 #include <windows.h>
365 #ifdef HAVE_WINSOCK2_H
366 #include <winsock2.h>
367 #else
368 #ifdef HAVE_WINSOCK_H
369 #include <winsock.h>
370 #endif
371 #endif
372 #endif
373 ],[
374 /* ioctlsocket source code */
375  SOCKET sd;
376  unsigned long flags = 0;
377  sd = socket(0, 0, 0);
378  ioctlsocket(sd, FIONBIO, &flags);
379 ],[
380 dnl ioctlsocket test was good
381 nonblock="ioctlsocket"
382 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
383 ],[
384 dnl ioctlsocket didnt compile!, go to test 4
385
386   AC_TRY_LINK([
387 /* headers for IoctlSocket test (Amiga?) */
388 #include <sys/ioctl.h>
389 ],[
390 /* IoctlSocket source code */
391  int socket;
392  int flags = IoctlSocket(socket, FIONBIO, (long)1);
393 ],[
394 dnl ioctlsocket test was good
395 nonblock="IoctlSocket"
396 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
397 ],[
398 dnl Ioctlsocket didnt compile, do test 5!
399   AC_TRY_COMPILE([
400 /* headers for SO_NONBLOCK test (BeOS) */
401 #include <socket.h>
402 ],[
403 /* SO_NONBLOCK source code */
404  long b = 1;
405  int socket;
406  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
407 ],[
408 dnl the SO_NONBLOCK test was good
409 nonblock="SO_NONBLOCK"
410 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
411 ],[
412 dnl test 5 didnt compile!
413 nonblock="nada"
414 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
415 ])
416 dnl end of fifth test
417
418 ])
419 dnl end of forth test
420
421 ])
422 dnl end of third test
423
424 ])
425 dnl end of second test
426
427 ])
428 dnl end of non-blocking try-compile test
429   AC_MSG_RESULT($nonblock)
430
431   if test "$nonblock" = "nada"; then
432     AC_MSG_WARN([non-block sockets disabled])
433   fi
434 ])
435
436
437 dnl TYPE_SOCKADDR_STORAGE
438 dnl -------------------------------------------------
439 dnl Check for struct sockaddr_storage. Most IPv6-enabled hosts have it, but
440 dnl AIX 4.3 is one known exception.
441 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
442 [
443    AC_CHECK_TYPE([struct sockaddr_storage],
444         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
445                   [if struct sockaddr_storage is defined]), ,
446    [
447 #undef inline
448 #ifdef HAVE_WINDOWS_H
449 #ifndef WIN32_LEAN_AND_MEAN
450 #define WIN32_LEAN_AND_MEAN
451 #endif
452 #include <windows.h>
453 #ifdef HAVE_WINSOCK2_H
454 #include <winsock2.h>
455 #endif
456 #else
457 #ifdef HAVE_SYS_TYPES_H
458 #include <sys/types.h>
459 #endif
460 #ifdef HAVE_SYS_SOCKET_H
461 #include <sys/socket.h>
462 #endif
463 #ifdef HAVE_NETINET_IN_H
464 #include <netinet/in.h>
465 #endif
466 #ifdef HAVE_ARPA_INET_H
467 #include <arpa/inet.h>
468 #endif
469 #endif
470    ])
471 ])
472
473
474 dnl TYPE_IN_ADDR_T
475 dnl -------------------------------------------------
476 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
477 dnl and a few other things.
478 AC_DEFUN([TYPE_IN_ADDR_T],
479 [
480    AC_CHECK_TYPE([in_addr_t], ,[
481       AC_MSG_CHECKING([for in_addr_t equivalent])
482       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
483       [
484          curl_cv_in_addr_t_equiv=
485          for t in "unsigned long" int size_t unsigned long; do
486             AC_TRY_COMPILE([
487 #undef inline
488 #ifdef HAVE_WINDOWS_H
489 #ifndef WIN32_LEAN_AND_MEAN
490 #define WIN32_LEAN_AND_MEAN
491 #endif
492 #include <windows.h>
493 #ifdef HAVE_WINSOCK2_H
494 #include <winsock2.h>
495 #else
496 #ifdef HAVE_WINSOCK_H
497 #include <winsock.h>
498 #endif
499 #endif
500 #else
501 #ifdef HAVE_SYS_TYPES_H
502 #include <sys/types.h>
503 #endif
504 #ifdef HAVE_SYS_SOCKET_H
505 #include <sys/socket.h>
506 #endif
507 #ifdef HAVE_NETINET_IN_H
508 #include <netinet/in.h>
509 #endif
510 #ifdef HAVE_ARPA_INET_H
511 #include <arpa/inet.h>
512 #endif
513 #endif
514             ],[
515                $t data = inet_addr ("1.2.3.4");
516             ],[
517                curl_cv_in_addr_t_equiv="$t"
518                break
519             ])
520          done
521
522          if test "x$curl_cv_in_addr_t_equiv" = x; then
523             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
524          fi
525       ])
526       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
527       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
528                         [type to use in place of in_addr_t if not defined])],
529       [
530 #undef inline
531 #ifdef HAVE_WINDOWS_H
532 #ifndef WIN32_LEAN_AND_MEAN
533 #define WIN32_LEAN_AND_MEAN
534 #endif
535 #include <windows.h>
536 #ifdef HAVE_WINSOCK2_H
537 #include <winsock2.h>
538 #else
539 #ifdef HAVE_WINSOCK_H
540 #include <winsock.h>
541 #endif
542 #endif
543 #else
544 #ifdef HAVE_SYS_TYPES_H
545 #include <sys/types.h>
546 #endif
547 #ifdef HAVE_SYS_SOCKET_H
548 #include <sys/socket.h>
549 #endif
550 #ifdef HAVE_NETINET_IN_H
551 #include <netinet/in.h>
552 #endif
553 #ifdef HAVE_ARPA_INET_H
554 #include <arpa/inet.h>
555 #endif
556
557 #endif
558   ]) dnl AC_CHECK_TYPE
559 ]) dnl AC_DEFUN
560
561
562 dnl We create a function for detecting which compiler we use and then set as
563 dnl pendantic compiler options as possible for that particular compiler. The
564 dnl options are only used for debug-builds.
565
566 dnl This is a copy of the original found in curl's configure script. Don't
567 dnl modify this one, edit the one in curl and copy it back here when that one
568 dnl is changed.
569
570 AC_DEFUN([CURL_CC_DEBUG_OPTS],
571 [
572     if test "$GCC" = "yes"; then
573
574        dnl figure out gcc version!
575        AC_MSG_CHECKING([gcc version])
576        gccver=`$CC -dumpversion`
577        num1=`echo $gccver | cut -d . -f1`
578        num2=`echo $gccver | cut -d . -f2`
579        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
580        AC_MSG_RESULT($gccver)
581
582        AC_MSG_CHECKING([if this is icc in disguise])
583        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
584          dnl action if the text is found, this it has not been replaced by the
585          dnl cpp
586          ICC="no"
587          AC_MSG_RESULT([no]),
588          dnl the text was not found, it was replaced by the cpp
589          ICC="yes"
590          AC_MSG_RESULT([yes])
591        )
592
593        if test "$ICC" = "yes"; then
594          dnl this is icc, not gcc.
595
596          dnl ICC warnings we ignore:
597          dnl * 279 warns on static conditions in while expressions
598          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
599          dnl   "invalid format string conversion"
600
601          WARN="-wd279,269"
602
603          if test "$gccnum" -gt "600"; then
604             dnl icc 6.0 and older doesn't have the -Wall flag
605             WARN="-Wall $WARN"
606          fi
607        else dnl $ICC = yes
608          dnl 
609          WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
610
611          dnl -Wcast-align is a bit too annoying ;-)
612
613          if test "$gccnum" -ge "296"; then
614            dnl gcc 2.96 or later
615            WARN="$WARN -Wfloat-equal"
616
617            if test "$gccnum" -gt "296"; then
618              dnl this option does not exist in 2.96
619              WARN="$WARN -Wno-format-nonliteral"
620            fi
621
622            dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
623            dnl on i686-Linux as it gives us heaps with false positives
624            if test "$gccnum" -ge "303"; then
625              dnl gcc 3.3 and later
626              WARN="$WARN -Wendif-labels -Wstrict-prototypes"
627            fi
628          fi
629
630          for flag in $CPPFLAGS; do
631            case "$flag" in
632             -I*)
633               dnl include path
634               add=`echo $flag | sed 's/^-I/-isystem /g'`
635               WARN="$WARN $add"
636               ;;
637            esac
638          done
639
640        fi dnl $ICC = no
641
642        CFLAGS="$CFLAGS $WARN"
643
644     fi dnl $GCC = yes
645
646     dnl strip off optimizer flags
647     NEWFLAGS=""
648     for flag in $CFLAGS; do
649       case "$flag" in
650       -O*)
651         dnl echo "cut off $flag"
652         ;;
653       *)
654         NEWFLAGS="$NEWFLAGS $flag"
655         ;;
656       esac
657     done
658     CFLAGS=$NEWFLAGS
659
660 ]) dnl end of AC_DEFUN()
661
662
663 dnl This macro determines if the specified struct exists in the specified file
664 dnl Syntax:
665 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
666
667 AC_DEFUN([CARES_CHECK_STRUCT], [
668   AC_MSG_CHECKING([for struct $2])
669   AC_TRY_COMPILE([$1], 
670     [
671       struct $2 struct_instance;
672     ], ac_struct="yes", ac_found="no")
673   if test "$ac_struct" = "yes" ; then
674     AC_MSG_RESULT(yes)
675     $3
676   else
677     AC_MSG_RESULT(no)
678     $4
679   fi
680 ])
681
682 dnl This macro determines if the specified constant exists in the specified file
683 dnl Syntax:
684 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
685
686 AC_DEFUN([CARES_CHECK_CONSTANT], [
687   AC_MSG_CHECKING([for $2])
688   AC_EGREP_CPP(VARIABLEWASDEFINED,
689    [
690       $1
691
692       #ifdef $2
693         VARIABLEWASDEFINED
694       #else
695         NJET
696       #endif
697     ], ac_constant="yes", ac_constant="no"
698   )
699   if test "$ac_constant" = "yes" ; then
700     AC_MSG_RESULT(yes)
701     $3
702   else
703     AC_MSG_RESULT(no)
704     $4
705   fi
706 ])
707
708
709 dnl This macro determines how many parameters getservbyport_r takes
710 AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
711   AC_MSG_CHECKING([how many arguments getservbyport_r takes])
712   AC_TRY_COMPILE(
713     [#include <netdb.h>],
714     [
715       int p1, p5;
716       char *p2, p4[4096];
717       struct servent *p3, *p6;
718       getservbyport_r(p1, p2, p3, p4, p5, &p6);
719     ], ac_func_getservbyport_r=6,
720     [AC_TRY_COMPILE(
721       [#include <netdb.h>],
722       [
723         int p1, p5;
724         char *p2, p4[4096];
725         struct servent *p3;
726         getservbyport_r(p1, p2, p3, p4, p5);
727       ], ac_func_getservbyport_r=5,
728       [AC_TRY_COMPILE(
729         [#include <netdb.h>],
730         [
731           int p1;
732           char *p2;
733           struct servent *p3;
734           struct servent_data p4;
735           getservbyport_r(p1, p2, p3, &p4);
736         ], ac_func_getservbyport_r=4, ac_func_getservbyport_r=0
737       )]
738     )]
739   )
740 if test $ac_func_getservbyport_r != "0" ; then
741   AC_MSG_RESULT($ac_func_getservbyport_r)
742   AC_DEFINE(HAVE_GETSERVBYPORT_R, 1, [Specifies whether getservbyport_r is present])
743   AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r, [Specifies the number of arguments to 
744 getservbyport_r])
745   if test $ac_func_getservbyport_r = "4" ; then
746    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), [Specifies the size of the buffer to pass to 
747 getservbyport_r])
748   else
749    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, [Specifies the size of the buffer to pass to getservbyport_r])
750   fi
751 else
752   AC_MSG_RESULT([not found])
753 fi
754 ])
755