Alexander Lazic improved the getservbyport_r() configure check.
[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_CHECK_FUNC_GETNAMEINFO
208 dnl -------------------------------------------------
209 dnl Test if the getnameinfo function is available, 
210 dnl and check the types of five of its arguments.
211 dnl If the function succeeds HAVE_GETNAMEINFO will be
212 dnl defined, defining the types of the arguments in
213 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
214 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7.
215 dnl This function is experimental and its results shall
216 dnl not be trusted while this notice is in place ------
217
218 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
219   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
220   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
221   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
222   #
223   AC_MSG_CHECKING([for getnameinfo])
224   AC_LINK_IFELSE([
225       AC_LANG_FUNC_LINK_TRY([getnameinfo])
226     ],[
227       AC_MSG_RESULT([yes])
228       curl_cv_getnameinfo="yes"
229     ],[
230       AC_MSG_RESULT([no])
231       curl_cv_getnameinfo="no"
232   ])
233   #
234   if test "$curl_cv_getnameinfo" != "yes"; then
235     AC_MSG_CHECKING([deeper for getnameinfo])
236     AC_TRY_LINK([
237       ],[
238         getnameinfo();
239       ],[
240         AC_MSG_RESULT([yes])
241         curl_cv_getnameinfo="yes"
242       ],[
243         AC_MSG_RESULT([but still no])
244         curl_cv_getnameinfo="no"
245     ])
246   fi
247   #
248   if test "$curl_cv_getnameinfo" != "yes"; then
249     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
250     AC_TRY_LINK([
251 #undef inline
252 #ifdef HAVE_WINDOWS_H
253 #ifndef WIN32_LEAN_AND_MEAN
254 #define WIN32_LEAN_AND_MEAN
255 #endif
256 #include <windows.h>
257 #ifdef HAVE_WINSOCK2_H
258 #include <winsock2.h>
259 #ifdef HAVE_WS2TCPIP_H
260 #include <ws2tcpip.h>
261 #endif
262 #endif
263 #else
264 #ifdef HAVE_SYS_TYPES_H
265 #include <sys/types.h>
266 #endif
267 #ifdef HAVE_SYS_SOCKET_H
268 #include <sys/socket.h>
269 #endif
270 #ifdef HAVE_NETDB_H
271 #include <netdb.h>
272 #endif
273 #endif
274       ],[
275         getnameinfo(0, 0, 0, 0, 0, 0, 0);
276       ],[ 
277         AC_MSG_RESULT([yes])
278         curl_cv_getnameinfo="yes"
279       ],[
280         AC_MSG_RESULT([but still no])
281         curl_cv_getnameinfo="no"
282     ])
283   fi
284   #
285   if test "$curl_cv_getnameinfo" = "yes"; then
286     AC_CACHE_CHECK([types of arguments for getnameinfo],
287       [curl_cv_func_getnameinfo_args], [
288       curl_cv_func_getnameinfo_args="unknown"
289       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
290         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
291           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
292             for gni_arg7 in 'int' 'unsigned int'; do
293               AC_COMPILE_IFELSE([
294                 AC_LANG_PROGRAM([
295 #undef inline 
296 #ifdef HAVE_WINDOWS_H
297 #ifndef WIN32_LEAN_AND_MEAN
298 #define WIN32_LEAN_AND_MEAN
299 #endif
300 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
301 #undef _WIN32_WINNT
302 #define _WIN32_WINNT 0x0501
303 #endif
304 #include <windows.h>
305 #ifdef HAVE_WINSOCK2_H
306 #include <winsock2.h> 
307 #ifdef HAVE_WS2TCPIP_H
308 #include <ws2tcpip.h>
309 #endif
310 #endif
311 #define GNICALLCONV WSAAPI
312 #else
313 #ifdef HAVE_SYS_TYPES_H
314 #include <sys/types.h>
315 #endif
316 #ifdef HAVE_SYS_SOCKET_H
317 #include <sys/socket.h>
318 #endif
319 #ifdef HAVE_NETDB_H
320 #include <netdb.h>
321 #endif
322 #define GNICALLCONV
323 #endif
324                   extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
325                                          char *, $gni_arg46,
326                                          char *, $gni_arg46,
327                                          $gni_arg7);
328                 ],[
329                   $gni_arg2 salen=0;
330                   $gni_arg46 hostlen=0;
331                   $gni_arg46 servlen=0;
332                   $gni_arg7 flags=0;
333                   int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
334                 ])
335               ],[
336                  curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
337                  break 4
338               ])
339             done
340           done
341         done
342       done
343     ]) # AC_CACHE_CHECK
344     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
345       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
346       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
347     else
348       gni_prev_IFS=$IFS; IFS=','
349       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
350       IFS=$gni_prev_IFS
351       shift
352       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $[1],
353         [Define to the type of arg 1 for getnameinfo.])
354       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
355         [Define to the type of arg 2 for getnameinfo.])
356       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
357         [Define to the type of args 4 and 6 for getnameinfo.])
358       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
359         [Define to the type of arg 7 for getnameinfo.])
360       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
361         [Define to 1 if you have the getnameinfo function.])
362       ac_cv_func_getnameinfo="yes"
363     fi
364   fi
365 ]) # AC_DEFUN
366
367
368 dnl CURL_CHECK_NONBLOCKING_SOCKET
369 dnl -------------------------------------------------
370 dnl Check for how to set a socket to non-blocking state. There seems to exist
371 dnl four known different ways, with the one used almost everywhere being POSIX
372 dnl and XPG3, while the other different ways for different systems (old BSD,
373 dnl Windows and Amiga).
374 dnl
375 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
376 dnl O_NONBLOCK define is found but does not work. This condition is attempted
377 dnl to get caught in this script by using an excessive number of #ifdefs...
378 dnl
379 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
380 [
381   AC_MSG_CHECKING([non-blocking sockets style])
382
383   AC_TRY_COMPILE([
384 /* headers for O_NONBLOCK test */
385 #include <sys/types.h>
386 #include <unistd.h>
387 #include <fcntl.h>
388 ],[
389 /* try to compile O_NONBLOCK */
390
391 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
392 # if defined(__SVR4) || defined(__srv4__)
393 #  define PLATFORM_SOLARIS
394 # else
395 #  define PLATFORM_SUNOS4
396 # endif
397 #endif
398 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
399 # define PLATFORM_AIX_V3
400 #endif
401
402 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
403 #error "O_NONBLOCK does not work on this platform"
404 #endif
405   int socket;
406   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
407 ],[
408 dnl the O_NONBLOCK test was fine
409 nonblock="O_NONBLOCK"
410 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
411 ],[
412 dnl the code was bad, try a different program now, test 2
413
414   AC_TRY_COMPILE([
415 /* headers for FIONBIO test */
416 #include <unistd.h>
417 #include <stropts.h>
418 ],[
419 /* FIONBIO source test (old-style unix) */
420  int socket;
421  int flags = ioctl(socket, FIONBIO, &flags);
422 ],[
423 dnl FIONBIO test was good
424 nonblock="FIONBIO"
425 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
426 ],[
427 dnl FIONBIO test was also bad
428 dnl the code was bad, try a different program now, test 3
429
430   AC_TRY_COMPILE([
431 /* headers for ioctlsocket test (Windows) */
432 #undef inline
433 #ifdef HAVE_WINDOWS_H
434 #ifndef WIN32_LEAN_AND_MEAN
435 #define WIN32_LEAN_AND_MEAN
436 #endif
437 #include <windows.h>
438 #ifdef HAVE_WINSOCK2_H
439 #include <winsock2.h>
440 #else
441 #ifdef HAVE_WINSOCK_H
442 #include <winsock.h>
443 #endif
444 #endif
445 #endif
446 ],[
447 /* ioctlsocket source code */
448  SOCKET sd;
449  unsigned long flags = 0;
450  sd = socket(0, 0, 0);
451  ioctlsocket(sd, FIONBIO, &flags);
452 ],[
453 dnl ioctlsocket test was good
454 nonblock="ioctlsocket"
455 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
456 ],[
457 dnl ioctlsocket didnt compile!, go to test 4
458
459   AC_TRY_LINK([
460 /* headers for IoctlSocket test (Amiga?) */
461 #include <sys/ioctl.h>
462 ],[
463 /* IoctlSocket source code */
464  int socket;
465  int flags = IoctlSocket(socket, FIONBIO, (long)1);
466 ],[
467 dnl ioctlsocket test was good
468 nonblock="IoctlSocket"
469 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
470 ],[
471 dnl Ioctlsocket didnt compile, do test 5!
472   AC_TRY_COMPILE([
473 /* headers for SO_NONBLOCK test (BeOS) */
474 #include <socket.h>
475 ],[
476 /* SO_NONBLOCK source code */
477  long b = 1;
478  int socket;
479  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
480 ],[
481 dnl the SO_NONBLOCK test was good
482 nonblock="SO_NONBLOCK"
483 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
484 ],[
485 dnl test 5 didnt compile!
486 nonblock="nada"
487 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
488 ])
489 dnl end of fifth test
490
491 ])
492 dnl end of forth test
493
494 ])
495 dnl end of third test
496
497 ])
498 dnl end of second test
499
500 ])
501 dnl end of non-blocking try-compile test
502   AC_MSG_RESULT($nonblock)
503
504   if test "$nonblock" = "nada"; then
505     AC_MSG_WARN([non-block sockets disabled])
506   fi
507 ])
508
509
510 dnl TYPE_SOCKADDR_STORAGE
511 dnl -------------------------------------------------
512 dnl Check for struct sockaddr_storage. Most IPv6-enabled hosts have it, but
513 dnl AIX 4.3 is one known exception.
514 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
515 [
516    AC_CHECK_TYPE([struct sockaddr_storage],
517         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
518                   [if struct sockaddr_storage is defined]), ,
519    [
520 #undef inline
521 #ifdef HAVE_WINDOWS_H
522 #ifndef WIN32_LEAN_AND_MEAN
523 #define WIN32_LEAN_AND_MEAN
524 #endif
525 #include <windows.h>
526 #ifdef HAVE_WINSOCK2_H
527 #include <winsock2.h>
528 #endif
529 #else
530 #ifdef HAVE_SYS_TYPES_H
531 #include <sys/types.h>
532 #endif
533 #ifdef HAVE_SYS_SOCKET_H
534 #include <sys/socket.h>
535 #endif
536 #ifdef HAVE_NETINET_IN_H
537 #include <netinet/in.h>
538 #endif
539 #ifdef HAVE_ARPA_INET_H
540 #include <arpa/inet.h>
541 #endif
542 #endif
543    ])
544 ])
545
546
547 dnl TYPE_IN_ADDR_T
548 dnl -------------------------------------------------
549 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
550 dnl and a few other things.
551 AC_DEFUN([TYPE_IN_ADDR_T],
552 [
553    AC_CHECK_TYPE([in_addr_t], ,[
554       AC_MSG_CHECKING([for in_addr_t equivalent])
555       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
556       [
557          curl_cv_in_addr_t_equiv=
558          for t in "unsigned long" int size_t unsigned long; do
559             AC_TRY_COMPILE([
560 #undef inline
561 #ifdef HAVE_WINDOWS_H
562 #ifndef WIN32_LEAN_AND_MEAN
563 #define WIN32_LEAN_AND_MEAN
564 #endif
565 #include <windows.h>
566 #ifdef HAVE_WINSOCK2_H
567 #include <winsock2.h>
568 #else
569 #ifdef HAVE_WINSOCK_H
570 #include <winsock.h>
571 #endif
572 #endif
573 #else
574 #ifdef HAVE_SYS_TYPES_H
575 #include <sys/types.h>
576 #endif
577 #ifdef HAVE_SYS_SOCKET_H
578 #include <sys/socket.h>
579 #endif
580 #ifdef HAVE_NETINET_IN_H
581 #include <netinet/in.h>
582 #endif
583 #ifdef HAVE_ARPA_INET_H
584 #include <arpa/inet.h>
585 #endif
586 #endif
587             ],[
588                $t data = inet_addr ("1.2.3.4");
589             ],[
590                curl_cv_in_addr_t_equiv="$t"
591                break
592             ])
593          done
594
595          if test "x$curl_cv_in_addr_t_equiv" = x; then
596             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
597          fi
598       ])
599       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
600       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
601                         [type to use in place of in_addr_t if not defined])],
602       [
603 #undef inline
604 #ifdef HAVE_WINDOWS_H
605 #ifndef WIN32_LEAN_AND_MEAN
606 #define WIN32_LEAN_AND_MEAN
607 #endif
608 #include <windows.h>
609 #ifdef HAVE_WINSOCK2_H
610 #include <winsock2.h>
611 #else
612 #ifdef HAVE_WINSOCK_H
613 #include <winsock.h>
614 #endif
615 #endif
616 #else
617 #ifdef HAVE_SYS_TYPES_H
618 #include <sys/types.h>
619 #endif
620 #ifdef HAVE_SYS_SOCKET_H
621 #include <sys/socket.h>
622 #endif
623 #ifdef HAVE_NETINET_IN_H
624 #include <netinet/in.h>
625 #endif
626 #ifdef HAVE_ARPA_INET_H
627 #include <arpa/inet.h>
628 #endif
629
630 #endif
631   ]) dnl AC_CHECK_TYPE
632 ]) dnl AC_DEFUN
633
634
635 dnl We create a function for detecting which compiler we use and then set as
636 dnl pendantic compiler options as possible for that particular compiler. The
637 dnl options are only used for debug-builds.
638
639 dnl This is a copy of the original found in curl's configure script. Don't
640 dnl modify this one, edit the one in curl and copy it back here when that one
641 dnl is changed.
642
643 AC_DEFUN([CURL_CC_DEBUG_OPTS],
644 [
645     if test "$GCC" = "yes"; then
646
647        dnl figure out gcc version!
648        AC_MSG_CHECKING([gcc version])
649        gccver=`$CC -dumpversion`
650        num1=`echo $gccver | cut -d . -f1`
651        num2=`echo $gccver | cut -d . -f2`
652        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
653        AC_MSG_RESULT($gccver)
654
655        AC_MSG_CHECKING([if this is icc in disguise])
656        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
657          dnl action if the text is found, this it has not been replaced by the
658          dnl cpp
659          ICC="no"
660          AC_MSG_RESULT([no]),
661          dnl the text was not found, it was replaced by the cpp
662          ICC="yes"
663          AC_MSG_RESULT([yes])
664        )
665
666        if test "$ICC" = "yes"; then
667          dnl this is icc, not gcc.
668
669          dnl ICC warnings we ignore:
670          dnl * 279 warns on static conditions in while expressions
671          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
672          dnl   "invalid format string conversion"
673
674          WARN="-wd279,269"
675
676          if test "$gccnum" -gt "600"; then
677             dnl icc 6.0 and older doesn't have the -Wall flag
678             WARN="-Wall $WARN"
679          fi
680        else dnl $ICC = yes
681          dnl 
682          WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
683
684          dnl -Wcast-align is a bit too annoying ;-)
685
686          if test "$gccnum" -ge "296"; then
687            dnl gcc 2.96 or later
688            WARN="$WARN -Wfloat-equal"
689
690            if test "$gccnum" -gt "296"; then
691              dnl this option does not exist in 2.96
692              WARN="$WARN -Wno-format-nonliteral"
693            fi
694
695            dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
696            dnl on i686-Linux as it gives us heaps with false positives
697            if test "$gccnum" -ge "303"; then
698              dnl gcc 3.3 and later
699              WARN="$WARN -Wendif-labels -Wstrict-prototypes"
700            fi
701          fi
702
703          for flag in $CPPFLAGS; do
704            case "$flag" in
705             -I*)
706               dnl include path
707               add=`echo $flag | sed 's/^-I/-isystem /g'`
708               WARN="$WARN $add"
709               ;;
710            esac
711          done
712
713        fi dnl $ICC = no
714
715        CFLAGS="$CFLAGS $WARN"
716
717     fi dnl $GCC = yes
718
719     dnl strip off optimizer flags
720     NEWFLAGS=""
721     for flag in $CFLAGS; do
722       case "$flag" in
723       -O*)
724         dnl echo "cut off $flag"
725         ;;
726       *)
727         NEWFLAGS="$NEWFLAGS $flag"
728         ;;
729       esac
730     done
731     CFLAGS=$NEWFLAGS
732
733 ]) dnl end of AC_DEFUN()
734
735
736 dnl This macro determines if the specified struct exists in the specified file
737 dnl Syntax:
738 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
739
740 AC_DEFUN([CARES_CHECK_STRUCT], [
741   AC_MSG_CHECKING([for struct $2])
742   AC_TRY_COMPILE([$1], 
743     [
744       struct $2 struct_instance;
745     ], ac_struct="yes", ac_found="no")
746   if test "$ac_struct" = "yes" ; then
747     AC_MSG_RESULT(yes)
748     $3
749   else
750     AC_MSG_RESULT(no)
751     $4
752   fi
753 ])
754
755 dnl This macro determines if the specified constant exists in the specified file
756 dnl Syntax:
757 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
758
759 AC_DEFUN([CARES_CHECK_CONSTANT], [
760   AC_MSG_CHECKING([for $2])
761   AC_EGREP_CPP(VARIABLEWASDEFINED,
762    [
763       $1
764
765       #ifdef $2
766         VARIABLEWASDEFINED
767       #else
768         NJET
769       #endif
770     ], ac_constant="yes", ac_constant="no"
771   )
772   if test "$ac_constant" = "yes" ; then
773     AC_MSG_RESULT(yes)
774     $3
775   else
776     AC_MSG_RESULT(no)
777     $4
778   fi
779 ])
780
781
782 dnl This macro determines how many parameters getservbyport_r takes
783 AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
784   AC_MSG_CHECKING([how many arguments getservbyport_r takes])
785   AC_TRY_LINK(
786     [#include <netdb.h>],
787     [
788       int p1, p5;
789       char *p2, p4[4096];
790       struct servent *p3, *p6;
791       getservbyport_r(p1, p2, p3, p4, p5, &p6);
792     ], ac_func_getservbyport_r=6,
793     [AC_TRY_LINK(
794       [#include <netdb.h>],
795       [
796         int p1, p5;
797         char *p2, p4[4096];
798         struct servent *p3;
799         getservbyport_r(p1, p2, p3, p4, p5);
800       ], ac_func_getservbyport_r=5,
801       [AC_TRY_LINK(
802         [#include <netdb.h>],
803         [
804           int p1;
805           char *p2;
806           struct servent *p3;
807           struct servent_data p4;
808           getservbyport_r(p1, p2, p3, &p4);
809         ], ac_func_getservbyport_r=4, ac_func_getservbyport_r=0
810       )]
811     )]
812   )
813 if test $ac_func_getservbyport_r != "0" ; then
814   AC_MSG_RESULT($ac_func_getservbyport_r)
815   AC_DEFINE(HAVE_GETSERVBYPORT_R, 1, [Specifies whether getservbyport_r is present])
816   AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r, [Specifies the number of arguments to 
817 getservbyport_r])
818   if test $ac_func_getservbyport_r = "4" ; then
819    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), [Specifies the size of the buffer to pass to 
820 getservbyport_r])
821   else
822    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, [Specifies the size of the buffer to pass to getservbyport_r])
823   fi
824 else
825   AC_MSG_RESULT([not found])
826 fi
827 ])
828