Add check for winldap and winber header files
[platform/upstream/curl.git] / acinclude.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
9 #
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at http://curl.haxx.se/docs/copyright.html.
13 #
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
17 #
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
20 #
21 # $Id$
22 ###########################################################################
23
24
25 dnl CURL_CHECK_HEADER_WINDOWS
26 dnl -------------------------------------------------
27 dnl Check for compilable and valid windows.h header 
28
29 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
30   AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [
31     AC_COMPILE_IFELSE([
32       AC_LANG_PROGRAM([
33 #undef inline
34 #ifndef WIN32_LEAN_AND_MEAN
35 #define WIN32_LEAN_AND_MEAN
36 #endif
37 #include <windows.h>
38       ],[
39 #ifdef __CYGWIN__
40         HAVE_WINDOWS_H shall not be defined.
41 #else
42         int dummy=2*WINVER;
43 #endif
44       ])
45     ],[
46       ac_cv_header_windows_h="yes"
47     ],[
48       ac_cv_header_windows_h="no"
49     ])
50   ])
51   case "$ac_cv_header_windows_h" in
52     yes)
53       AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
54         [Define to 1 if you have the windows.h header file.])
55       AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
56         [Define to avoid automatic inclusion of winsock.h])
57       ;;
58   esac
59 ])
60
61
62 dnl CURL_CHECK_HEADER_WINSOCK
63 dnl -------------------------------------------------
64 dnl Check for compilable and valid winsock.h header 
65
66 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
67   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
68   AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
69     AC_COMPILE_IFELSE([
70       AC_LANG_PROGRAM([
71 #undef inline
72 #ifndef WIN32_LEAN_AND_MEAN
73 #define WIN32_LEAN_AND_MEAN
74 #endif
75 #include <windows.h>
76 #include <winsock.h>
77       ],[
78 #ifdef __CYGWIN__
79         HAVE_WINSOCK_H shall not be defined.
80 #else
81         int dummy=WSACleanup();
82 #endif
83       ])
84     ],[
85       ac_cv_header_winsock_h="yes"
86     ],[
87       ac_cv_header_winsock_h="no"
88     ])
89   ])
90   case "$ac_cv_header_winsock_h" in
91     yes)
92       AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
93         [Define to 1 if you have the winsock.h header file.])
94       ;;
95   esac
96 ])
97
98
99 dnl CURL_CHECK_HEADER_WINSOCK2
100 dnl -------------------------------------------------
101 dnl Check for compilable and valid winsock2.h header 
102
103 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
104   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
105   AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
106     AC_COMPILE_IFELSE([
107       AC_LANG_PROGRAM([
108 #undef inline
109 #ifndef WIN32_LEAN_AND_MEAN
110 #define WIN32_LEAN_AND_MEAN
111 #endif
112 #include <windows.h>
113 #include <winsock2.h>
114       ],[
115 #ifdef __CYGWIN__
116         HAVE_WINSOCK2_H shall not be defined.
117 #else
118         int dummy=2*IPPROTO_ESP;
119 #endif
120       ])
121     ],[
122       ac_cv_header_winsock2_h="yes"
123     ],[
124       ac_cv_header_winsock2_h="no"
125     ])
126   ])
127   case "$ac_cv_header_winsock2_h" in
128     yes)
129       AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
130         [Define to 1 if you have the winsock2.h header file.])
131       ;;
132   esac
133 ])
134
135
136 dnl CURL_CHECK_HEADER_WS2TCPIP
137 dnl -------------------------------------------------
138 dnl Check for compilable and valid ws2tcpip.h header
139
140 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
141   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
142   AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
143     AC_COMPILE_IFELSE([
144       AC_LANG_PROGRAM([
145 #undef inline
146 #ifndef WIN32_LEAN_AND_MEAN
147 #define WIN32_LEAN_AND_MEAN
148 #endif
149 #include <windows.h>
150 #include <winsock2.h>
151 #include <ws2tcpip.h>
152       ],[
153 #ifdef __CYGWIN__
154         HAVE_WS2TCPIP_H shall not be defined.
155 #else
156         int dummy=2*IP_PKTINFO;
157 #endif
158       ])
159     ],[
160       ac_cv_header_ws2tcpip_h="yes"
161     ],[
162       ac_cv_header_ws2tcpip_h="no"
163     ])
164   ])
165   case "$ac_cv_header_ws2tcpip_h" in
166     yes)
167       AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
168         [Define to 1 if you have the ws2tcpip.h header file.])
169       ;;
170   esac
171 ])
172
173
174 dnl CURL_CHECK_HEADER_WINLDAP
175 dnl -------------------------------------------------
176 dnl Check for compilable and valid winldap.h header
177
178 AC_DEFUN([CURL_CHECK_HEADER_WINLDAP], [
179   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
180   AC_CACHE_CHECK([for winldap.h], [ac_cv_header_winldap_h], [
181     AC_COMPILE_IFELSE([
182       AC_LANG_PROGRAM([
183 #undef inline
184 #ifndef WIN32_LEAN_AND_MEAN
185 #define WIN32_LEAN_AND_MEAN
186 #endif
187 #include <windows.h>
188 #include <winldap.h>
189       ],[
190 #ifdef __CYGWIN__
191         HAVE_WINLDAP_H shall not be defined.
192 #else
193         LDAP *ldp = ldap_init("dummy", LDAP_PORT);
194         ULONG res = ldap_unbind(ldp);
195 #endif
196       ])
197     ],[
198       ac_cv_header_winldap_h="yes"
199     ],[
200       ac_cv_header_winldap_h="no"
201     ])
202   ])
203   case "$ac_cv_header_winldap_h" in
204     yes)
205       AC_DEFINE_UNQUOTED(HAVE_WINLDAP_H, 1,
206         [Define to 1 if you have the winldap.h header file.])
207       ;;
208   esac
209 ])
210
211
212 dnl CURL_CHECK_HEADER_WINBER
213 dnl -------------------------------------------------
214 dnl Check for compilable and valid winber.h header
215
216 AC_DEFUN([CURL_CHECK_HEADER_WINBER], [
217   AC_REQUIRE([CURL_CHECK_HEADER_WINLDAP])dnl
218   AC_CACHE_CHECK([for winber.h], [ac_cv_header_winber_h], [
219     AC_COMPILE_IFELSE([
220       AC_LANG_PROGRAM([
221 #undef inline
222 #ifndef WIN32_LEAN_AND_MEAN
223 #define WIN32_LEAN_AND_MEAN
224 #endif
225 #include <windows.h>
226 #include <winldap.h>
227 #include <winber.h>
228       ],[
229 #ifdef __CYGWIN__
230         HAVE_WINBER_H shall not be defined.
231 #else
232         BERVAL *bvp = NULL;
233         BerElement *bep = ber_init(bvp);
234         ber_free(bep, 1);
235 #endif
236       ])
237     ],[
238       ac_cv_header_winber_h="yes"
239     ],[
240       ac_cv_header_winber_h="no"
241     ])
242   ])
243   case "$ac_cv_header_winber_h" in
244     yes)
245       AC_DEFINE_UNQUOTED(HAVE_WINBER_H, 1,
246         [Define to 1 if you have the winber.h header file.])
247       ;;
248   esac
249 ])
250
251
252 dnl CURL_CHECK_HEADER_MALLOC
253 dnl -------------------------------------------------
254 dnl Check for compilable and valid malloc.h header,
255 dnl and check if it is needed even with stdlib.h
256
257 AC_DEFUN([CURL_CHECK_HEADER_MALLOC], [
258   AC_CACHE_CHECK([for malloc.h], [ac_cv_header_malloc_h], [
259     AC_COMPILE_IFELSE([
260       AC_LANG_PROGRAM([
261 #include <malloc.h>
262       ],[
263         void *p = malloc(10);
264         void *q = calloc(10,10);
265         free(p);
266         free(q);
267       ])
268     ],[
269       ac_cv_header_malloc_h="yes"
270     ],[
271       ac_cv_header_malloc_h="no"
272     ])
273   ])
274   if test "$ac_cv_header_malloc_h" = "yes"; then
275     AC_DEFINE_UNQUOTED(HAVE_MALLOC_H, 1,
276       [Define to 1 if you have the malloc.h header file.])
277     #
278     AC_COMPILE_IFELSE([
279       AC_LANG_PROGRAM([
280 #include <stdlib.h>
281       ],[
282         void *p = malloc(10);
283         void *q = calloc(10,10);
284         free(p);
285         free(q);
286       ])
287     ],[
288       curl_cv_need_header_malloc_h="no"
289     ],[
290       curl_cv_need_header_malloc_h="yes"
291     ])
292     #
293     case "$curl_cv_need_header_malloc_h" in
294       yes)
295         AC_DEFINE_UNQUOTED(NEED_MALLOC_H, 1,
296           [Define to 1 if you need the malloc.h header file even with stdlib.h])
297         ;;
298     esac
299   fi
300 ])
301
302
303 dnl CURL_CHECK_TYPE_SOCKLEN_T
304 dnl -------------------------------------------------
305 dnl Check for existing socklen_t type, and provide
306 dnl an equivalent type if socklen_t not available
307
308 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
309   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
310   AC_CHECK_TYPE([socklen_t], ,[
311     AC_CACHE_CHECK([for socklen_t equivalent], 
312       [curl_cv_socklen_t_equiv], [
313       curl_cv_socklen_t_equiv="unknown"
314       for arg2 in "struct sockaddr" void; do
315         for t in int size_t unsigned long "unsigned long"; do
316           AC_COMPILE_IFELSE([
317             AC_LANG_PROGRAM([
318 #undef inline
319 #ifdef HAVE_WINDOWS_H
320 #ifndef WIN32_LEAN_AND_MEAN
321 #define WIN32_LEAN_AND_MEAN
322 #endif
323 #include <windows.h>
324 #ifdef HAVE_WINSOCK2_H
325 #include <winsock2.h>
326 #else
327 #ifdef HAVE_WINSOCK_H
328 #include <winsock.h>
329 #endif
330 #endif
331 #else
332 #ifdef HAVE_SYS_TYPES_H
333 #include <sys/types.h>
334 #endif
335 #ifdef HAVE_SYS_SOCKET_H
336 #include <sys/socket.h>
337 #endif
338 #endif
339               int getpeername (int, $arg2 *, $t *);
340             ],[
341               $t len=0;
342               getpeername(0,0,&len);
343             ])
344           ],[
345              curl_cv_socklen_t_equiv="$t"
346              break 2
347           ])
348         done
349       done
350     ])
351     case "$curl_cv_socklen_t_equiv" in
352       unknown)
353         AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
354         ;;
355       *)
356         AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
357           [type to use in place of socklen_t if not defined])
358         ;;
359     esac
360   ],[
361 #undef inline
362 #ifdef HAVE_WINDOWS_H
363 #ifndef WIN32_LEAN_AND_MEAN
364 #define WIN32_LEAN_AND_MEAN
365 #endif
366 #include <windows.h>
367 #ifdef HAVE_WINSOCK2_H
368 #include <winsock2.h>
369 #ifdef HAVE_WS2TCPIP_H
370 #include <ws2tcpip.h>
371 #endif
372 #endif
373 #else
374 #ifdef HAVE_SYS_TYPES_H
375 #include <sys/types.h>
376 #endif
377 #ifdef HAVE_SYS_SOCKET_H
378 #include <sys/socket.h>
379 #endif
380 #endif
381   ])
382 ])
383
384
385 dnl CURL_CHECK_FUNC_GETNAMEINFO
386 dnl -------------------------------------------------
387 dnl Test if the getnameinfo function is available, 
388 dnl and check the types of five of its arguments.
389 dnl If the function succeeds HAVE_GETNAMEINFO will be
390 dnl defined, defining the types of the arguments in
391 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
392 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7,
393 dnl and also defining the type qualifier of first 
394 dnl argument in GETNAMEINFO_QUAL_ARG1.
395
396 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
397   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
398   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
399   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
400   #
401   AC_MSG_CHECKING([for getnameinfo])
402   AC_LINK_IFELSE([
403       AC_LANG_FUNC_LINK_TRY([getnameinfo])
404     ],[
405       AC_MSG_RESULT([yes])
406       curl_cv_getnameinfo="yes"
407     ],[
408       AC_MSG_RESULT([no])
409       curl_cv_getnameinfo="no"
410   ])
411   #
412   if test "$curl_cv_getnameinfo" != "yes"; then
413     AC_MSG_CHECKING([deeper for getnameinfo])
414     AC_TRY_LINK([
415       ],[
416         getnameinfo();
417       ],[
418         AC_MSG_RESULT([yes])
419         curl_cv_getnameinfo="yes"
420       ],[
421         AC_MSG_RESULT([but still no])
422         curl_cv_getnameinfo="no"
423     ])
424   fi
425   #
426   if test "$curl_cv_getnameinfo" != "yes"; then
427     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
428     AC_TRY_LINK([
429 #undef inline
430 #ifdef HAVE_WINDOWS_H
431 #ifndef WIN32_LEAN_AND_MEAN
432 #define WIN32_LEAN_AND_MEAN
433 #endif
434 #include <windows.h>
435 #ifdef HAVE_WINSOCK2_H
436 #include <winsock2.h>
437 #ifdef HAVE_WS2TCPIP_H
438 #include <ws2tcpip.h>
439 #endif
440 #endif
441 #else
442 #ifdef HAVE_SYS_TYPES_H
443 #include <sys/types.h>
444 #endif
445 #ifdef HAVE_SYS_SOCKET_H
446 #include <sys/socket.h>
447 #endif
448 #ifdef HAVE_NETDB_H
449 #include <netdb.h>
450 #endif
451 #endif
452       ],[
453         getnameinfo(0, 0, 0, 0, 0, 0, 0);
454       ],[ 
455         AC_MSG_RESULT([yes])
456         curl_cv_getnameinfo="yes"
457       ],[
458         AC_MSG_RESULT([but still no])
459         curl_cv_getnameinfo="no"
460     ])
461   fi
462   #
463   if test "$curl_cv_getnameinfo" = "yes"; then
464     AC_CACHE_CHECK([types of arguments for getnameinfo],
465       [curl_cv_func_getnameinfo_args], [
466       curl_cv_func_getnameinfo_args="unknown"
467       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
468         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
469           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
470             for gni_arg7 in 'int' 'unsigned int'; do
471               AC_COMPILE_IFELSE([
472                 AC_LANG_PROGRAM([
473 #undef inline 
474 #ifdef HAVE_WINDOWS_H
475 #ifndef WIN32_LEAN_AND_MEAN
476 #define WIN32_LEAN_AND_MEAN
477 #endif
478 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
479 #undef _WIN32_WINNT
480 #define _WIN32_WINNT 0x0501
481 #endif
482 #include <windows.h>
483 #ifdef HAVE_WINSOCK2_H
484 #include <winsock2.h> 
485 #ifdef HAVE_WS2TCPIP_H
486 #include <ws2tcpip.h>
487 #endif
488 #endif
489 #define GNICALLCONV WSAAPI
490 #else
491 #ifdef HAVE_SYS_TYPES_H
492 #include <sys/types.h>
493 #endif
494 #ifdef HAVE_SYS_SOCKET_H
495 #include <sys/socket.h>
496 #endif
497 #ifdef HAVE_NETDB_H
498 #include <netdb.h>
499 #endif
500 #define GNICALLCONV
501 #endif
502                   extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
503                                          char *, $gni_arg46,
504                                          char *, $gni_arg46,
505                                          $gni_arg7);
506                 ],[
507                   $gni_arg2 salen=0;
508                   $gni_arg46 hostlen=0;
509                   $gni_arg46 servlen=0;
510                   $gni_arg7 flags=0;
511                   int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
512                 ])
513               ],[
514                  curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
515                  break 4
516               ])
517             done
518           done
519         done
520       done
521     ]) # AC_CACHE_CHECK
522     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
523       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
524       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
525     else
526       gni_prev_IFS=$IFS; IFS=','
527       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
528       IFS=$gni_prev_IFS
529       shift
530       #
531       gni_qual_type_arg1=$[1]
532       #
533       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
534         [Define to the type of arg 2 for getnameinfo.])
535       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
536         [Define to the type of args 4 and 6 for getnameinfo.])
537       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
538         [Define to the type of arg 7 for getnameinfo.])
539       #
540       prev_sh_opts=$-
541       #
542       case $prev_sh_opts in
543         *f*)
544           ;;
545         *)
546           set -f
547           ;;
548       esac
549       #
550       case "$gni_qual_type_arg1" in
551         const*)
552           gni_qual_arg1=const
553           gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
554         ;;
555         *)
556           gni_qual_arg1=
557           gni_type_arg1=$gni_qual_type_arg1
558         ;;
559       esac
560       #
561       AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
562         [Define to the type qualifier of arg 1 for getnameinfo.])
563       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
564         [Define to the type of arg 1 for getnameinfo.])
565       #
566       case $prev_sh_opts in
567         *f*)
568           ;;
569         *)
570           set +f
571           ;;
572       esac
573       #
574       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
575         [Define to 1 if you have the getnameinfo function.])
576       ac_cv_func_getnameinfo="yes"
577     fi
578   fi
579 ]) # AC_DEFUN
580
581
582 dnl TYPE_SOCKADDR_STORAGE
583 dnl -------------------------------------------------
584 dnl Check for struct sockaddr_storage. Most IPv6-enabled 
585 dnl hosts have it, but AIX 4.3 is one known exception.
586
587 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
588 [
589    AC_CHECK_TYPE([struct sockaddr_storage],
590         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
591                   [if struct sockaddr_storage is defined]), ,
592    [
593 #undef inline
594 #ifdef HAVE_WINDOWS_H
595 #ifndef WIN32_LEAN_AND_MEAN
596 #define WIN32_LEAN_AND_MEAN
597 #endif
598 #include <windows.h>
599 #ifdef HAVE_WINSOCK2_H
600 #include <winsock2.h>
601 #endif
602 #else
603 #ifdef HAVE_SYS_TYPES_H
604 #include <sys/types.h>
605 #endif
606 #ifdef HAVE_SYS_SOCKET_H
607 #include <sys/socket.h>
608 #endif
609 #ifdef HAVE_NETINET_IN_H
610 #include <netinet/in.h>
611 #endif
612 #ifdef HAVE_ARPA_INET_H
613 #include <arpa/inet.h>
614 #endif
615 #endif
616    ])
617 ])
618
619
620 dnl CURL_CHECK_NI_WITHSCOPEID
621 dnl -------------------------------------------------
622 dnl Check for working NI_WITHSCOPEID in getnameinfo()
623
624 AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID], [
625   AC_REQUIRE([CURL_CHECK_FUNC_GETNAMEINFO])dnl
626   AC_REQUIRE([TYPE_SOCKADDR_STORAGE])dnl
627   AC_CHECK_HEADERS(stdio.h sys/types.h sys/socket.h \
628                    netdb.h netinet/in.h arpa/inet.h)
629   #
630   AC_CACHE_CHECK([for working NI_WITHSCOPEID], 
631     [ac_cv_working_ni_withscopeid], [
632     AC_RUN_IFELSE([
633       AC_LANG_PROGRAM([
634 #ifdef HAVE_STDIO_H
635 #include <stdio.h>
636 #endif
637 #ifdef HAVE_SYS_TYPES_H
638 #include <sys/types.h>
639 #endif
640 #ifdef HAVE_SYS_SOCKET_H
641 #include <sys/socket.h>
642 #endif
643 #ifdef HAVE_NETDB_H
644 #include <netdb.h>
645 #endif
646 #ifdef HAVE_NETINET_IN_H
647 #include <netinet/in.h>
648 #endif
649 #ifdef HAVE_ARPA_INET_H
650 #include <arpa/inet.h>
651 #endif
652       ],[
653 #if defined(NI_WITHSCOPEID) && defined(HAVE_GETNAMEINFO)
654 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
655         struct sockaddr_storage sa;
656 #else
657         unsigned char sa[256];
658 #endif
659         char hostbuf[NI_MAXHOST];
660         int rc;
661         GETNAMEINFO_TYPE_ARG2 salen = (GETNAMEINFO_TYPE_ARG2)sizeof(sa);
662         GETNAMEINFO_TYPE_ARG46 hostlen = (GETNAMEINFO_TYPE_ARG46)sizeof(hostbuf);
663         GETNAMEINFO_TYPE_ARG7 flags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
664         int fd = socket(AF_INET6, SOCK_STREAM, 0);
665         if(fd < 0) {
666           perror("socket()");
667           return 1; /* Error creating socket */
668         }
669         rc = getsockname(fd, (GETNAMEINFO_TYPE_ARG1)&sa, &salen);
670         if(rc) {
671           perror("getsockname()");
672           return 2; /* Error retrieving socket name */
673         }
674         rc = getnameinfo((GETNAMEINFO_TYPE_ARG1)&sa, salen, hostbuf, hostlen, NULL, 0, flags);
675         if(rc) {
676           printf("rc = %s\n", gai_strerror(rc));
677           return 3; /* Error translating socket address */
678         }
679         return 0; /* Ok, NI_WITHSCOPEID works */
680 #else
681         return 4; /* Error, NI_WITHSCOPEID not defined or no getnameinfo() */
682 #endif
683       ]) # AC_LANG_PROGRAM
684     ],[
685       # Exit code == 0. Program worked.
686       ac_cv_working_ni_withscopeid="yes"
687     ],[
688       # Exit code != 0. Program failed.
689       ac_cv_working_ni_withscopeid="no"
690     ],[
691       # Program is not run when cross-compiling. So we assume
692       # NI_WITHSCOPEID will work if we are able to compile it.
693       AC_COMPILE_IFELSE([
694         AC_LANG_PROGRAM([
695 #include <sys/types.h>
696 #include <sys/socket.h>
697 #include <netdb.h>
698         ],[
699           unsigned int dummy= NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
700         ])
701       ],[
702         ac_cv_working_ni_withscopeid="yes"
703       ],[
704         ac_cv_working_ni_withscopeid="no"
705       ]) # AC_COMPILE_IFELSE
706     ]) # AC_RUN_IFELSE
707   ]) # AC_CACHE_CHECK
708   case "$ac_cv_working_ni_withscopeid" in
709     yes)
710       AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
711         [Define to 1 if NI_WITHSCOPEID exists and works.])
712       ;;
713   esac
714 ]) # AC_DEFUN
715
716
717 dnl CURL_CHECK_FUNC_RECV
718 dnl -------------------------------------------------
719 dnl Test if the socket recv() function is available, 
720 dnl and check its return type and the types of its 
721 dnl arguments. If the function succeeds HAVE_RECV 
722 dnl will be defined, defining the types of the arguments 
723 dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3 
724 dnl and RECV_TYPE_ARG4, defining the type of the function
725 dnl return value in RECV_TYPE_RETV.
726
727 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
728   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
729   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
730   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
731   #
732   AC_MSG_CHECKING([for recv])
733   AC_TRY_LINK([
734 #undef inline 
735 #ifdef HAVE_WINDOWS_H
736 #ifndef WIN32_LEAN_AND_MEAN
737 #define WIN32_LEAN_AND_MEAN
738 #endif
739 #include <windows.h>
740 #ifdef HAVE_WINSOCK2_H
741 #include <winsock2.h>
742 #else
743 #ifdef HAVE_WINSOCK_H
744 #include <winsock.h>
745 #endif
746 #endif
747 #else
748 #ifdef HAVE_SYS_TYPES_H
749 #include <sys/types.h>
750 #endif
751 #ifdef HAVE_SYS_SOCKET_H
752 #include <sys/socket.h>
753 #endif
754 #endif
755     ],[
756       recv(0, 0, 0, 0);
757     ],[ 
758       AC_MSG_RESULT([yes])
759       curl_cv_recv="yes"
760     ],[
761       AC_MSG_RESULT([no])
762       curl_cv_recv="no"
763   ])
764   #
765   if test "$curl_cv_recv" = "yes"; then
766     AC_CACHE_CHECK([types of args and return type for recv],
767       [curl_cv_func_recv_args], [
768       curl_cv_func_recv_args="unknown"
769       for recv_retv in 'int' 'ssize_t'; do
770         for recv_arg1 in 'int' 'ssize_t' 'SOCKET'; do
771           for recv_arg2 in 'char *' 'void *'; do
772             for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
773               for recv_arg4 in 'int' 'unsigned int'; do
774                 AC_COMPILE_IFELSE([
775                   AC_LANG_PROGRAM([
776 #undef inline 
777 #ifdef HAVE_WINDOWS_H
778 #ifndef WIN32_LEAN_AND_MEAN
779 #define WIN32_LEAN_AND_MEAN
780 #endif
781 #include <windows.h>
782 #ifdef HAVE_WINSOCK2_H
783 #include <winsock2.h>
784 #else
785 #ifdef HAVE_WINSOCK_H
786 #include <winsock.h>
787 #endif
788 #endif
789 #define RECVCALLCONV PASCAL
790 #else
791 #ifdef HAVE_SYS_TYPES_H
792 #include <sys/types.h>
793 #endif
794 #ifdef HAVE_SYS_SOCKET_H
795 #include <sys/socket.h>
796 #endif
797 #define RECVCALLCONV
798 #endif
799                     extern $recv_retv RECVCALLCONV recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
800                   ],[
801                     $recv_arg1 s=0;
802                     $recv_arg2 buf=0;
803                     $recv_arg3 len=0;
804                     $recv_arg4 flags=0;
805                     $recv_retv res = recv(s, buf, len, flags);
806                   ])
807                 ],[
808                    curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
809                    break 5
810                 ])
811               done
812             done
813           done
814         done
815       done
816     ]) # AC_CACHE_CHECK
817     if test "$curl_cv_func_recv_args" = "unknown"; then
818       AC_MSG_ERROR([Cannot find proper types to use for recv args])
819     else
820       recv_prev_IFS=$IFS; IFS=','
821       set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
822       IFS=$recv_prev_IFS
823       shift
824       #
825       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
826         [Define to the type of arg 1 for recv.])
827       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
828         [Define to the type of arg 2 for recv.])
829       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
830         [Define to the type of arg 3 for recv.])
831       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
832         [Define to the type of arg 4 for recv.])
833       AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
834         [Define to the function return type for recv.])
835       #
836       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
837         [Define to 1 if you have the recv function.])
838       ac_cv_func_recv="yes"
839     fi
840   else
841     AC_MSG_ERROR([Unable to link function recv])
842   fi
843 ]) # AC_DEFUN
844
845
846 dnl CURL_CHECK_FUNC_SEND
847 dnl -------------------------------------------------
848 dnl Test if the socket send() function is available, 
849 dnl and check its return type and the types of its 
850 dnl arguments. If the function succeeds HAVE_SEND 
851 dnl will be defined, defining the types of the arguments 
852 dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3 
853 dnl and SEND_TYPE_ARG4, defining the type of the function
854 dnl return value in SEND_TYPE_RETV, and also defining the 
855 dnl type qualifier of second argument in SEND_QUAL_ARG2.
856
857 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
858   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
859   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
860   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
861   #
862   AC_MSG_CHECKING([for send])
863   AC_TRY_LINK([
864 #undef inline 
865 #ifdef HAVE_WINDOWS_H
866 #ifndef WIN32_LEAN_AND_MEAN
867 #define WIN32_LEAN_AND_MEAN
868 #endif
869 #include <windows.h>
870 #ifdef HAVE_WINSOCK2_H
871 #include <winsock2.h>
872 #else
873 #ifdef HAVE_WINSOCK_H
874 #include <winsock.h>
875 #endif
876 #endif
877 #else
878 #ifdef HAVE_SYS_TYPES_H
879 #include <sys/types.h>
880 #endif
881 #ifdef HAVE_SYS_SOCKET_H
882 #include <sys/socket.h>
883 #endif
884 #endif
885     ],[
886       send(0, 0, 0, 0);
887     ],[ 
888       AC_MSG_RESULT([yes])
889       curl_cv_send="yes"
890     ],[
891       AC_MSG_RESULT([no])
892       curl_cv_send="no"
893   ])
894   #
895   if test "$curl_cv_send" = "yes"; then
896     AC_CACHE_CHECK([types of args and return type for send],
897       [curl_cv_func_send_args], [
898       curl_cv_func_send_args="unknown"
899       for send_retv in 'int' 'ssize_t'; do
900         for send_arg1 in 'int' 'ssize_t' 'SOCKET'; do
901           for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
902             for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
903               for send_arg4 in 'int' 'unsigned int'; do
904                 AC_COMPILE_IFELSE([
905                   AC_LANG_PROGRAM([
906 #undef inline 
907 #ifdef HAVE_WINDOWS_H
908 #ifndef WIN32_LEAN_AND_MEAN
909 #define WIN32_LEAN_AND_MEAN
910 #endif
911 #include <windows.h>
912 #ifdef HAVE_WINSOCK2_H
913 #include <winsock2.h>
914 #else
915 #ifdef HAVE_WINSOCK_H
916 #include <winsock.h>
917 #endif
918 #endif
919 #define SENDCALLCONV PASCAL
920 #else
921 #ifdef HAVE_SYS_TYPES_H
922 #include <sys/types.h>
923 #endif
924 #ifdef HAVE_SYS_SOCKET_H
925 #include <sys/socket.h>
926 #endif
927 #define SENDCALLCONV
928 #endif
929                     extern $send_retv SENDCALLCONV send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
930                   ],[
931                     $send_arg1 s=0;
932                     $send_arg3 len=0;
933                     $send_arg4 flags=0;
934                     $send_retv res = send(s, 0, len, flags);
935                   ])
936                 ],[
937                    curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
938                    break 5
939                 ])
940               done
941             done
942           done
943         done
944       done
945     ]) # AC_CACHE_CHECK
946     if test "$curl_cv_func_send_args" = "unknown"; then
947       AC_MSG_ERROR([Cannot find proper types to use for send args])
948     else
949       send_prev_IFS=$IFS; IFS=','
950       set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
951       IFS=$send_prev_IFS
952       shift
953       #
954       send_qual_type_arg2=$[2]
955       #
956       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
957         [Define to the type of arg 1 for send.])
958       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
959         [Define to the type of arg 3 for send.])
960       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
961         [Define to the type of arg 4 for send.])
962       AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
963         [Define to the function return type for send.])
964       #
965       prev_sh_opts=$-
966       #
967       case $prev_sh_opts in
968         *f*)
969           ;;
970         *)
971           set -f
972           ;;
973       esac
974       #
975       case "$send_qual_type_arg2" in
976         const*)
977           send_qual_arg2=const
978           send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
979         ;;
980         *)
981           send_qual_arg2=
982           send_type_arg2=$send_qual_type_arg2
983         ;;
984       esac
985       #
986       AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
987         [Define to the type qualifier of arg 2 for send.])
988       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
989         [Define to the type of arg 2 for send.])
990       #
991       case $prev_sh_opts in
992         *f*)
993           ;;
994         *)
995           set +f
996           ;;
997       esac
998       #
999       AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
1000         [Define to 1 if you have the send function.])
1001       ac_cv_func_send="yes"
1002     fi
1003   else
1004     AC_MSG_ERROR([Unable to link function send])
1005   fi
1006 ]) # AC_DEFUN
1007
1008
1009 dnl CURL_CHECK_MSG_NOSIGNAL
1010 dnl -------------------------------------------------
1011 dnl Check for MSG_NOSIGNAL
1012
1013 AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
1014   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1015   AC_CACHE_CHECK([for MSG_NOSIGNAL], [ac_cv_msg_nosignal], [
1016     AC_COMPILE_IFELSE([
1017       AC_LANG_PROGRAM([
1018 #undef inline 
1019 #ifdef HAVE_WINDOWS_H
1020 #ifndef WIN32_LEAN_AND_MEAN
1021 #define WIN32_LEAN_AND_MEAN
1022 #endif
1023 #include <windows.h>
1024 #ifdef HAVE_WINSOCK2_H
1025 #include <winsock2.h>
1026 #else
1027 #ifdef HAVE_WINSOCK_H
1028 #include <winsock.h>
1029 #endif
1030 #endif
1031 #else
1032 #ifdef HAVE_SYS_TYPES_H
1033 #include <sys/types.h>
1034 #endif
1035 #ifdef HAVE_SYS_SOCKET_H
1036 #include <sys/socket.h>
1037 #endif
1038 #endif
1039       ],[
1040         int flag=MSG_NOSIGNAL;
1041       ])
1042     ],[
1043       ac_cv_msg_nosignal="yes"
1044     ],[
1045       ac_cv_msg_nosignal="no"
1046     ])
1047   ])
1048   case "$ac_cv_msg_nosignal" in
1049     yes)
1050       AC_DEFINE_UNQUOTED(HAVE_MSG_NOSIGNAL, 1,
1051         [Define to 1 if you have the MSG_NOSIGNAL flag.])
1052       ;;
1053   esac
1054 ]) # AC_DEFUN
1055
1056
1057 dnl CURL_CHECK_STRUCT_TIMEVAL
1058 dnl -------------------------------------------------
1059 dnl Check for timeval struct
1060
1061 AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [
1062   AC_REQUIRE([AC_HEADER_TIME])dnl
1063   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1064   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1065   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
1066   AC_CACHE_CHECK([for struct timeval], [ac_cv_struct_timeval], [
1067     AC_COMPILE_IFELSE([
1068       AC_LANG_PROGRAM([
1069 #undef inline 
1070 #ifdef HAVE_WINDOWS_H
1071 #ifndef WIN32_LEAN_AND_MEAN
1072 #define WIN32_LEAN_AND_MEAN
1073 #endif
1074 #include <windows.h>
1075 #ifdef HAVE_WINSOCK2_H
1076 #include <winsock2.h>
1077 #else
1078 #ifdef HAVE_WINSOCK_H
1079 #include <winsock.h>
1080 #endif
1081 #endif
1082 #endif
1083 #ifdef HAVE_SYS_TYPES_H
1084 #include <sys/types.h>
1085 #endif
1086 #ifdef HAVE_SYS_TIME_H
1087 #include <sys/time.h>
1088 #ifdef TIME_WITH_SYS_TIME
1089 #include <time.h>
1090 #endif
1091 #else
1092 #ifdef HAVE_TIME_H
1093 #include <time.h>
1094 #endif
1095 #endif
1096       ],[
1097         struct timeval ts;
1098         ts.tv_sec  = 0;
1099         ts.tv_usec = 0;
1100       ])
1101     ],[
1102       ac_cv_struct_timeval="yes"
1103     ],[
1104       ac_cv_struct_timeval="no"
1105     ])
1106   ])
1107   case "$ac_cv_struct_timeval" in
1108     yes)
1109       AC_DEFINE_UNQUOTED(HAVE_STRUCT_TIMEVAL, 1,
1110         [Define to 1 if you have the timeval struct.])
1111       ;;
1112   esac
1113 ]) # AC_DEFUN
1114
1115
1116 dnl TYPE_SIG_ATOMIC_T
1117 dnl -------------------------------------------------
1118 dnl Check if the sig_atomic_t type is available, and
1119 dnl verify if it is already defined as volatile.
1120
1121 AC_DEFUN([TYPE_SIG_ATOMIC_T], [
1122   AC_CHECK_HEADERS(signal.h)
1123   AC_CHECK_TYPE([sig_atomic_t],[
1124     AC_DEFINE(HAVE_SIG_ATOMIC_T, 1,
1125       [Define to 1 if sig_atomic_t is an available typedef.])
1126   ], ,[
1127 #ifdef HAVE_SIGNAL_H
1128 #include <signal.h>
1129 #endif
1130   ])
1131   case "$ac_cv_type_sig_atomic_t" in
1132     yes)
1133       #
1134       AC_MSG_CHECKING([if sig_atomic_t is already defined as volatile])
1135       AC_TRY_LINK([
1136 #ifdef HAVE_SIGNAL_H
1137 #include <signal.h>
1138 #endif
1139         ],[
1140           static volatile sig_atomic_t dummy = 0;
1141         ],[ 
1142           AC_MSG_RESULT([no])
1143           ac_cv_sig_atomic_t_volatile="no"
1144         ],[
1145           AC_MSG_RESULT([yes])
1146           ac_cv_sig_atomic_t_volatile="yes"
1147       ])
1148       #
1149       if test "$ac_cv_sig_atomic_t_volatile" = "yes"; then
1150         AC_DEFINE(HAVE_SIG_ATOMIC_T_VOLATILE, 1,
1151           [Define to 1 if sig_atomic_t is already defined as volatile.])
1152       fi
1153       ;;
1154   esac
1155 ]) # AC_DEFUN
1156
1157
1158 dnl CURL_CHECK_NONBLOCKING_SOCKET
1159 dnl -------------------------------------------------
1160 dnl Check for how to set a socket to non-blocking state. There seems to exist
1161 dnl four known different ways, with the one used almost everywhere being POSIX
1162 dnl and XPG3, while the other different ways for different systems (old BSD,
1163 dnl Windows and Amiga).
1164 dnl
1165 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
1166 dnl O_NONBLOCK define is found but does not work. This condition is attempted
1167 dnl to get caught in this script by using an excessive number of #ifdefs...
1168 dnl
1169 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
1170 [
1171   AC_MSG_CHECKING([non-blocking sockets style])
1172
1173   AC_TRY_COMPILE([
1174 /* headers for O_NONBLOCK test */
1175 #include <sys/types.h>
1176 #include <unistd.h>
1177 #include <fcntl.h>
1178 ],[
1179 /* try to compile O_NONBLOCK */
1180
1181 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
1182 # if defined(__SVR4) || defined(__srv4__)
1183 #  define PLATFORM_SOLARIS
1184 # else
1185 #  define PLATFORM_SUNOS4
1186 # endif
1187 #endif
1188 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
1189 # define PLATFORM_AIX_V3
1190 #endif
1191
1192 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
1193 #error "O_NONBLOCK does not work on this platform"
1194 #endif
1195   int socket;
1196   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
1197 ],[
1198 dnl the O_NONBLOCK test was fine
1199 nonblock="O_NONBLOCK"
1200 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
1201 ],[
1202 dnl the code was bad, try a different program now, test 2
1203
1204   AC_TRY_COMPILE([
1205 /* headers for FIONBIO test */
1206 #include <unistd.h>
1207 #include <stropts.h>
1208 ],[
1209 /* FIONBIO source test (old-style unix) */
1210  int socket;
1211  int flags = ioctl(socket, FIONBIO, &flags);
1212 ],[
1213 dnl FIONBIO test was good
1214 nonblock="FIONBIO"
1215 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
1216 ],[
1217 dnl FIONBIO test was also bad
1218 dnl the code was bad, try a different program now, test 3
1219
1220   AC_TRY_COMPILE([
1221 /* headers for ioctlsocket test (Windows) */
1222 #undef inline
1223 #ifdef HAVE_WINDOWS_H
1224 #ifndef WIN32_LEAN_AND_MEAN
1225 #define WIN32_LEAN_AND_MEAN
1226 #endif
1227 #include <windows.h>
1228 #ifdef HAVE_WINSOCK2_H
1229 #include <winsock2.h>
1230 #else
1231 #ifdef HAVE_WINSOCK_H
1232 #include <winsock.h>
1233 #endif
1234 #endif
1235 #endif
1236 ],[
1237 /* ioctlsocket source code */
1238  SOCKET sd;
1239  unsigned long flags = 0;
1240  sd = socket(0, 0, 0);
1241  ioctlsocket(sd, FIONBIO, &flags);
1242 ],[
1243 dnl ioctlsocket test was good
1244 nonblock="ioctlsocket"
1245 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
1246 ],[
1247 dnl ioctlsocket didnt compile!, go to test 4
1248
1249   AC_TRY_LINK([
1250 /* headers for IoctlSocket test (Amiga?) */
1251 #include <sys/ioctl.h>
1252 ],[
1253 /* IoctlSocket source code */
1254  int socket;
1255  int flags = IoctlSocket(socket, FIONBIO, (long)1);
1256 ],[
1257 dnl ioctlsocket test was good
1258 nonblock="IoctlSocket"
1259 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
1260 ],[
1261 dnl Ioctlsocket didnt compile, do test 5!
1262   AC_TRY_COMPILE([
1263 /* headers for SO_NONBLOCK test (BeOS) */
1264 #include <socket.h>
1265 ],[
1266 /* SO_NONBLOCK source code */
1267  long b = 1;
1268  int socket;
1269  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
1270 ],[
1271 dnl the SO_NONBLOCK test was good
1272 nonblock="SO_NONBLOCK"
1273 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
1274 ],[
1275 dnl test 5 didnt compile!
1276 nonblock="nada"
1277 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
1278 ])
1279 dnl end of fifth test
1280
1281 ])
1282 dnl end of forth test
1283
1284 ])
1285 dnl end of third test
1286
1287 ])
1288 dnl end of second test
1289
1290 ])
1291 dnl end of non-blocking try-compile test
1292   AC_MSG_RESULT($nonblock)
1293
1294   if test "$nonblock" = "nada"; then
1295     AC_MSG_WARN([non-block sockets disabled])
1296   fi
1297 ])
1298
1299
1300 dnl TYPE_IN_ADDR_T
1301 dnl -------------------------------------------------
1302 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
1303 dnl and a few other things.
1304 AC_DEFUN([TYPE_IN_ADDR_T],
1305 [
1306    AC_CHECK_TYPE([in_addr_t], ,[
1307       AC_MSG_CHECKING([for in_addr_t equivalent])
1308       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
1309       [
1310          curl_cv_in_addr_t_equiv=
1311          for t in "unsigned long" int size_t unsigned long; do
1312             AC_TRY_COMPILE([
1313 #undef inline
1314 #ifdef HAVE_WINDOWS_H
1315 #ifndef WIN32_LEAN_AND_MEAN
1316 #define WIN32_LEAN_AND_MEAN
1317 #endif
1318 #include <windows.h>
1319 #ifdef HAVE_WINSOCK2_H
1320 #include <winsock2.h>
1321 #else
1322 #ifdef HAVE_WINSOCK_H
1323 #include <winsock.h>
1324 #endif
1325 #endif
1326 #else
1327 #ifdef HAVE_SYS_TYPES_H
1328 #include <sys/types.h>
1329 #endif
1330 #ifdef HAVE_SYS_SOCKET_H
1331 #include <sys/socket.h>
1332 #endif
1333 #ifdef HAVE_NETINET_IN_H
1334 #include <netinet/in.h>
1335 #endif
1336 #ifdef HAVE_ARPA_INET_H
1337 #include <arpa/inet.h>
1338 #endif
1339 #endif
1340             ],[
1341                $t data = inet_addr ("1.2.3.4");
1342             ],[
1343                curl_cv_in_addr_t_equiv="$t"
1344                break
1345             ])
1346          done
1347
1348          if test "x$curl_cv_in_addr_t_equiv" = x; then
1349             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
1350          fi
1351       ])
1352       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
1353       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
1354                         [type to use in place of in_addr_t if not defined])],
1355       [
1356 #undef inline
1357 #ifdef HAVE_WINDOWS_H
1358 #ifndef WIN32_LEAN_AND_MEAN
1359 #define WIN32_LEAN_AND_MEAN
1360 #endif
1361 #include <windows.h>
1362 #ifdef HAVE_WINSOCK2_H
1363 #include <winsock2.h>
1364 #else
1365 #ifdef HAVE_WINSOCK_H
1366 #include <winsock.h>
1367 #endif
1368 #endif
1369 #else
1370 #ifdef HAVE_SYS_TYPES_H
1371 #include <sys/types.h>
1372 #endif
1373 #ifdef HAVE_SYS_SOCKET_H
1374 #include <sys/socket.h>
1375 #endif
1376 #ifdef HAVE_NETINET_IN_H
1377 #include <netinet/in.h>
1378 #endif
1379 #ifdef HAVE_ARPA_INET_H
1380 #include <arpa/inet.h>
1381 #endif
1382 #endif
1383   ]) dnl AC_CHECK_TYPE
1384 ]) dnl AC_DEFUN
1385
1386 dnl ************************************************************
1387 dnl check for "localhost", if it doesn't exist, we can't do the
1388 dnl gethostbyname_r tests!
1389 dnl 
1390
1391 AC_DEFUN([CURL_CHECK_WORKING_RESOLVER],[
1392 AC_MSG_CHECKING([if "localhost" resolves])
1393 AC_TRY_RUN([
1394 #include <string.h>
1395 #include <sys/types.h>
1396 #include <netdb.h>
1397
1398 int
1399 main () {
1400 struct hostent *h;
1401 h = gethostbyname("localhost");
1402 exit (h == NULL ? 1 : 0); }],[
1403       AC_MSG_RESULT(yes)],[
1404       AC_MSG_RESULT(no)
1405       AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
1406
1407       ]
1408 )
1409 ])
1410
1411 dnl ************************************************************
1412 dnl check for working getaddrinfo() that works with AI_NUMERICHOST
1413 dnl
1414 AC_DEFUN([CURL_CHECK_WORKING_GETADDRINFO],[
1415   AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
1416   AC_TRY_RUN( [
1417 #include <netdb.h>
1418 #include <sys/types.h>
1419 #include <sys/socket.h>
1420
1421 int main(void)
1422 {
1423     struct addrinfo hints, *ai;
1424     int error;
1425
1426     memset(&hints, 0, sizeof(hints));
1427     hints.ai_flags = AI_NUMERICHOST;
1428     hints.ai_family = AF_UNSPEC;
1429     hints.ai_socktype = SOCK_STREAM;
1430     error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
1431     if (error) {
1432         return 1;
1433     }
1434     return 0;
1435 }
1436 ],[
1437   ac_cv_working_getaddrinfo="yes"
1438 ],[
1439   ac_cv_working_getaddrinfo="no"
1440 ],[
1441   ac_cv_working_getaddrinfo="yes"
1442 ])])
1443 if test "$ac_cv_working_getaddrinfo" = "yes"; then
1444   AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
1445   AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
1446
1447   IPV6_ENABLED=1
1448   AC_SUBST(IPV6_ENABLED)
1449 fi
1450 ])
1451
1452
1453 AC_DEFUN([CURL_CHECK_LOCALTIME_R],
1454 [
1455   dnl check for localtime_r
1456   AC_CHECK_FUNCS(localtime_r,[
1457     AC_MSG_CHECKING(whether localtime_r is declared)
1458     AC_EGREP_CPP(localtime_r,[
1459 #include <time.h>],[
1460       AC_MSG_RESULT(yes)],[
1461       AC_MSG_RESULT(no)
1462       AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
1463       AC_EGREP_CPP(localtime_r,[
1464 #define _REENTRANT
1465 #include <time.h>],[
1466         AC_DEFINE(NEED_REENTRANT)
1467         AC_MSG_RESULT(yes)],
1468         AC_MSG_RESULT(no))])])
1469 ])
1470
1471 dnl
1472 dnl This function checks for strerror_r(). If it isn't found at first, it
1473 dnl retries with _THREAD_SAFE defined, as that is what AIX seems to require
1474 dnl in order to find this function.
1475 dnl
1476 dnl If the function is found, it will then proceed to check how the function
1477 dnl actually works: glibc-style or POSIX-style.
1478 dnl
1479 dnl glibc:
1480 dnl      char *strerror_r(int errnum, char *buf, size_t n);
1481 dnl  
1482 dnl  What this one does is to return the error string (no surprises there),
1483 dnl  but it doesn't usually copy anything into buf!  The 'buf' and 'n'
1484 dnl  parameters are only meant as an optional working area, in case strerror_r
1485 dnl  needs it.  A quick test on a few systems shows that it's generally not
1486 dnl  touched at all.
1487 dnl
1488 dnl POSIX:
1489 dnl      int strerror_r(int errnum, char *buf, size_t n);
1490 dnl
1491 AC_DEFUN([CURL_CHECK_STRERROR_R],
1492 [
1493   AC_CHECK_FUNCS(strerror_r)
1494
1495   if test "x$ac_cv_func_strerror_r" = "xyes"; then
1496
1497     AC_MSG_CHECKING(whether strerror_r is declared)
1498     AC_EGREP_CPP(strerror_r,[
1499 #include <string.h>],[
1500       AC_MSG_RESULT(yes)],[
1501       AC_MSG_RESULT(no)
1502       AC_MSG_CHECKING(whether strerror_r with -D_REENTRANT is declared)
1503       AC_EGREP_CPP(strerror_r,[
1504 #define _REENTRANT
1505 #include <string.h>],[
1506         CPPFLAGS="-D_REENTRANT $CPPFLAGS"
1507         AC_MSG_RESULT(yes)],
1508         AC_MSG_RESULT(no)
1509         AC_DEFINE(HAVE_NO_STRERROR_R_DECL, 1, [we have no strerror_r() proto])
1510        ) dnl with _THREAD_SAFE
1511     ]) dnl plain cpp for it
1512
1513     dnl determine if this strerror_r() is glibc or POSIX
1514     AC_MSG_CHECKING([for a glibc strerror_r API])
1515     AC_TRY_RUN([
1516 #include <string.h>
1517 #include <errno.h>
1518 int
1519 main () {
1520   char buffer[1024]; /* big enough to play with */
1521   char *string =
1522     strerror_r(EACCES, buffer, sizeof(buffer));
1523     /* this should've returned a string */
1524     if(!string || !string[0])
1525       return 99;
1526     return 0;
1527 }
1528 ],
1529     GLIBC_STRERROR_R="1"
1530     AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
1531     AC_MSG_RESULT([yes]),
1532     AC_MSG_RESULT([no]),
1533
1534     dnl Use an inferior method of strerror_r detection while cross-compiling
1535     AC_EGREP_CPP(yes, [
1536 #include <features.h>
1537 #ifdef __GLIBC__
1538 yes
1539 #endif
1540 ], 
1541       dnl looks like glibc, so assume a glibc-style strerror_r()
1542       GLIBC_STRERROR_R="1"
1543       AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
1544       AC_MSG_RESULT([yes]),
1545       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
1546     ) dnl while cross-compiling
1547     )
1548
1549     if test -z "$GLIBC_STRERROR_R"; then
1550
1551       AC_MSG_CHECKING([for a POSIX strerror_r API])
1552       AC_TRY_RUN([
1553 #include <string.h>
1554 #include <errno.h>
1555 int
1556 main () {
1557   char buffer[1024]; /* big enough to play with */
1558   int error =
1559     strerror_r(EACCES, buffer, sizeof(buffer));
1560     /* This should've returned zero, and written an error string in the
1561        buffer.*/
1562     if(!buffer[0] || error)
1563       return 99;
1564     return 0;
1565 }
1566 ],
1567       AC_DEFINE(HAVE_POSIX_STRERROR_R, 1, [we have a POSIX-style strerror_r()])
1568       AC_MSG_RESULT([yes]),
1569       AC_MSG_RESULT([no]) ,
1570       dnl cross-compiling!
1571       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
1572     )
1573
1574     fi dnl if not using glibc API
1575
1576   fi dnl we have a strerror_r
1577
1578 ])
1579
1580 AC_DEFUN([CURL_CHECK_INET_NTOA_R],
1581 [
1582   dnl determine if function definition for inet_ntoa_r exists.
1583   AC_CHECK_FUNCS(inet_ntoa_r,[
1584     AC_MSG_CHECKING(whether inet_ntoa_r is declared)
1585     AC_EGREP_CPP(inet_ntoa_r,[
1586 #include <arpa/inet.h>],[
1587       AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
1588       AC_MSG_RESULT(yes)],[
1589       AC_MSG_RESULT(no)
1590       AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
1591       AC_EGREP_CPP(inet_ntoa_r,[
1592 #define _REENTRANT
1593 #include <arpa/inet.h>],[
1594         AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
1595         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
1596         AC_MSG_RESULT(yes)],
1597         AC_MSG_RESULT(no))])])
1598 ])
1599
1600 AC_DEFUN([CURL_CHECK_GETHOSTBYADDR_R],
1601 [
1602   dnl check for number of arguments to gethostbyaddr_r. it might take
1603   dnl either 5, 7, or 8 arguments.
1604   AC_CHECK_FUNCS(gethostbyaddr_r,[
1605     AC_MSG_CHECKING(if gethostbyaddr_r takes 5 arguments)
1606     AC_TRY_COMPILE([
1607 #include <sys/types.h>
1608 #include <netdb.h>],[
1609 char * address;
1610 int length;
1611 int type;
1612 struct hostent h;
1613 struct hostent_data hdata;
1614 int rc;
1615 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
1616       AC_MSG_RESULT(yes)
1617       AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
1618       ac_cv_gethostbyaddr_args=5],[
1619       AC_MSG_RESULT(no)
1620       AC_MSG_CHECKING(if gethostbyaddr_r with -D_REENTRANT takes 5 arguments)
1621       AC_TRY_COMPILE([
1622 #define _REENTRANT
1623 #include <sys/types.h>
1624 #include <netdb.h>],[
1625 char * address;
1626 int length;
1627 int type;
1628 struct hostent h;
1629 struct hostent_data hdata;
1630 int rc;
1631 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
1632         AC_MSG_RESULT(yes)
1633         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
1634         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
1635         ac_cv_gethostbyaddr_args=5],[
1636         AC_MSG_RESULT(no)
1637         AC_MSG_CHECKING(if gethostbyaddr_r takes 7 arguments)
1638         AC_TRY_COMPILE([
1639 #include <sys/types.h>
1640 #include <netdb.h>],[
1641 char * address;
1642 int length;
1643 int type;
1644 struct hostent h;
1645 char buffer[8192];
1646 int h_errnop;
1647 struct hostent * hp;
1648
1649 hp = gethostbyaddr_r(address, length, type, &h,
1650                      buffer, 8192, &h_errnop);],[
1651           AC_MSG_RESULT(yes)
1652           AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args] )
1653           ac_cv_gethostbyaddr_args=7],[
1654           AC_MSG_RESULT(no)
1655           AC_MSG_CHECKING(if gethostbyaddr_r takes 8 arguments)
1656           AC_TRY_COMPILE([
1657 #include <sys/types.h>
1658 #include <netdb.h>],[
1659 char * address;
1660 int length;
1661 int type;
1662 struct hostent h;
1663 char buffer[8192];
1664 int h_errnop;
1665 struct hostent * hp;
1666 int rc;
1667
1668 rc = gethostbyaddr_r(address, length, type, &h,
1669                      buffer, 8192, &hp, &h_errnop);],[
1670             AC_MSG_RESULT(yes)
1671             AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
1672             ac_cv_gethostbyaddr_args=8],[
1673             AC_MSG_RESULT(no)
1674             have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"])])])])])
1675 ])
1676
1677 AC_DEFUN([CURL_CHECK_GETHOSTBYNAME_R],
1678 [
1679   dnl check for number of arguments to gethostbyname_r. it might take
1680   dnl either 3, 5, or 6 arguments.
1681   AC_CHECK_FUNCS(gethostbyname_r,[
1682     AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
1683     AC_TRY_COMPILE([
1684 #include <string.h>
1685 #include <sys/types.h>
1686 #include <netdb.h>
1687 #undef NULL
1688 #define NULL (void *)0
1689
1690 int
1691 gethostbyname_r(const char *, struct hostent *, struct hostent_data *);],[
1692 struct hostent_data data;
1693 gethostbyname_r(NULL, NULL, NULL);],[
1694       AC_MSG_RESULT(yes)
1695       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
1696       ac_cv_gethostbyname_args=3],[
1697       AC_MSG_RESULT(no)
1698       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
1699       AC_TRY_COMPILE([
1700 #define _REENTRANT
1701
1702 #include <string.h>
1703 #include <sys/types.h>
1704 #include <netdb.h>
1705 #undef NULL
1706 #define NULL (void *)0
1707
1708 int
1709 gethostbyname_r(const char *,struct hostent *, struct hostent_data *);],[
1710 struct hostent_data data;
1711 gethostbyname_r(NULL, NULL, NULL);],[
1712         AC_MSG_RESULT(yes)
1713         AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
1714         AC_DEFINE(NEED_REENTRANT, 1, [needs REENTRANT])
1715         ac_cv_gethostbyname_args=3],[
1716         AC_MSG_RESULT(no)
1717         AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
1718         AC_TRY_COMPILE([
1719 #include <sys/types.h>
1720 #include <netdb.h>
1721 #undef NULL
1722 #define NULL (void *)0
1723
1724 struct hostent *
1725 gethostbyname_r(const char *, struct hostent *, char *, int, int *);],[
1726 gethostbyname_r(NULL, NULL, NULL, 0, NULL);],[
1727           AC_MSG_RESULT(yes)
1728           AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
1729           ac_cv_gethostbyname_args=5],[
1730           AC_MSG_RESULT(no)
1731           AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
1732           AC_TRY_COMPILE([
1733 #include <sys/types.h>
1734 #include <netdb.h>
1735 #undef NULL
1736 #define NULL (void *)0
1737
1738 int
1739 gethostbyname_r(const char *, struct hostent *, char *, size_t,
1740 struct hostent **, int *);],[
1741 gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);],[
1742             AC_MSG_RESULT(yes)
1743             AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
1744             ac_cv_gethostbyname_args=6],[
1745             AC_MSG_RESULT(no)
1746             have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"],
1747             [ac_cv_gethostbyname_args=0])],
1748           [ac_cv_gethostbyname_args=0])],
1749         [ac_cv_gethostbyname_args=0])],
1750       [ac_cv_gethostbyname_args=0])])
1751
1752 if test "$ac_cv_func_gethostbyname_r" = "yes"; then
1753   if test "$ac_cv_gethostbyname_args" = "0"; then
1754     dnl there's a gethostbyname_r() function, but we don't know how
1755     dnl many arguments it wants!
1756     AC_MSG_ERROR([couldn't figure out how to use gethostbyname_r()])
1757   fi
1758 fi
1759 ])
1760
1761
1762 dnl **********************************************************************
1763 dnl CURL_DETECT_ICC ([ACTION-IF-YES])
1764 dnl
1765 dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
1766 dnl sets the $ICC variable to "yes" or "no"
1767 dnl **********************************************************************
1768 AC_DEFUN([CURL_DETECT_ICC],
1769 [
1770     ICC="no"
1771     AC_MSG_CHECKING([for icc in use])
1772     if test "$GCC" = "yes"; then
1773        dnl check if this is icc acting as gcc in disguise
1774        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
1775          dnl action if the text is found, this it has not been replaced by the
1776          dnl cpp
1777          ICC="no",
1778          dnl the text was not found, it was replaced by the cpp
1779          ICC="yes"
1780          AC_MSG_RESULT([yes])
1781          [$1]
1782        )
1783     fi
1784     if test "$ICC" = "no"; then
1785         # this is not ICC
1786         AC_MSG_RESULT([no])
1787     fi
1788 ])
1789
1790 dnl We create a function for detecting which compiler we use and then set as
1791 dnl pendantic compiler options as possible for that particular compiler. The
1792 dnl options are only used for debug-builds.
1793
1794 AC_DEFUN([CURL_CC_DEBUG_OPTS],
1795 [
1796     if test "z$ICC" = "z"; then
1797       CURL_DETECT_ICC
1798     fi
1799
1800     if test "$GCC" = "yes"; then
1801
1802        dnl figure out gcc version!
1803        AC_MSG_CHECKING([gcc version])
1804        gccver=`$CC -dumpversion`
1805        num1=`echo $gccver | cut -d . -f1`
1806        num2=`echo $gccver | cut -d . -f2`
1807        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
1808        AC_MSG_RESULT($gccver)
1809
1810        if test "$ICC" = "yes"; then
1811          dnl this is icc, not gcc.
1812
1813          dnl ICC warnings we ignore:
1814          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
1815          dnl   "invalid format string conversion"
1816          dnl * 279 warns on static conditions in while expressions
1817          dnl * 981 warns on "operands are evaluated in unspecified order"
1818          dnl * 1418 "external definition with no prior declaration"
1819          dnl * 1419 warns on "external declaration in primary source file"
1820          dnl   which we know and do on purpose.
1821
1822          WARN="-wd279,269,981,1418,1419"
1823
1824          if test "$gccnum" -gt "600"; then
1825             dnl icc 6.0 and older doesn't have the -Wall flag
1826             WARN="-Wall $WARN"
1827          fi
1828        else dnl $ICC = yes
1829          dnl this is a set of options we believe *ALL* gcc versions support:
1830          WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
1831
1832          dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
1833
1834          if test "$gccnum" -ge "207"; then
1835            dnl gcc 2.7 or later
1836            WARN="$WARN -Wmissing-declarations"
1837          fi
1838
1839          if test "$gccnum" -gt "295"; then
1840            dnl only if the compiler is newer than 2.95 since we got lots of
1841            dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
1842            dnl gcc 2.95.4 on FreeBSD 4.9!
1843            WARN="$WARN -Wundef -Wno-long-long -Wsign-compare -Wshadow -Wno-multichar"
1844          fi
1845
1846          if test "$gccnum" -ge "296"; then
1847            dnl gcc 2.96 or later
1848            WARN="$WARN -Wfloat-equal"
1849          fi
1850
1851          if test "$gccnum" -gt "296"; then
1852            dnl this option does not exist in 2.96
1853            WARN="$WARN -Wno-format-nonliteral"
1854          fi
1855
1856          dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
1857          dnl on i686-Linux as it gives us heaps with false positives.
1858          dnl Also, on gcc 4.0.X it is totally unbearable and complains all
1859          dnl over making it unusable for generic purposes. Let's not use it.
1860
1861          if test "$gccnum" -ge "303"; then
1862            dnl gcc 3.3 and later
1863            WARN="$WARN -Wendif-labels -Wstrict-prototypes"
1864          fi
1865
1866          if test "$gccnum" -ge "304"; then
1867            # try these on gcc 3.4
1868            WARN="$WARN -Wdeclaration-after-statement"
1869          fi
1870
1871          for flag in $CPPFLAGS; do
1872            case "$flag" in
1873             -I*)
1874               dnl Include path, provide a -isystem option for the same dir
1875               dnl to prevent warnings in those dirs. The -isystem was not very
1876               dnl reliable on earlier gcc versions.
1877               add=`echo $flag | sed 's/^-I/-isystem /g'`
1878               WARN="$WARN $add"
1879               ;;
1880            esac
1881          done
1882
1883        fi dnl $ICC = no
1884
1885        CFLAGS="$CFLAGS $WARN"
1886
1887       AC_MSG_NOTICE([Added this set of compiler options: $WARN])
1888
1889     else dnl $GCC = yes
1890
1891       AC_MSG_NOTICE([Added no extra compiler options])
1892
1893     fi dnl $GCC = yes
1894
1895     dnl strip off optimizer flags
1896     NEWFLAGS=""
1897     for flag in $CFLAGS; do
1898       case "$flag" in
1899       -O*)
1900         dnl echo "cut off $flag"
1901         ;;
1902       *)
1903         NEWFLAGS="$NEWFLAGS $flag"
1904         ;;
1905       esac
1906     done
1907     CFLAGS=$NEWFLAGS
1908
1909 ]) dnl end of AC_DEFUN()
1910
1911 # This is only a temporary fix. This macro is here to replace the broken one
1912 # delivered by the automake project (including the 1.9.6 release). As soon as
1913 # they ship a working version we SHOULD remove this work-around.
1914
1915 AC_DEFUN([AM_MISSING_HAS_RUN],
1916 [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
1917 test x"${MISSING+set}" = xset || MISSING="\${SHELL} \"$am_aux_dir/missing\""
1918 # Use eval to expand $SHELL
1919 if eval "$MISSING --run true"; then
1920   am_missing_run="$MISSING --run "
1921 else
1922   am_missing_run=
1923   AC_MSG_WARN([`missing' script is too old or missing])
1924 fi
1925 ])
1926
1927
1928 dnl CURL_VERIFY_RUNTIMELIBS
1929 dnl -------------------------------------------------
1930 dnl Verify that the shared libs found so far can be used when running
1931 dnl programs, since otherwise the situation will create odd configure errors
1932 dnl that are misleading people.
1933 dnl
1934 dnl Make sure this test is run BEFORE the first test in the script that
1935 dnl runs anything, which at the time of this writing is the AC_CHECK_SIZEOF
1936 dnl macro. It must also run AFTER all lib-checking macros are complete.
1937
1938 AC_DEFUN([CURL_VERIFY_RUNTIMELIBS], [
1939
1940   dnl this test is of course not sensible if we are cross-compiling!
1941   if test "x$cross_compiling" != xyes; then
1942
1943     dnl just run a program to verify that the libs checked for previous to this
1944     dnl point also is available run-time!
1945     AC_MSG_CHECKING([run-time libs availability])
1946     AC_TRY_RUN([
1947 main()
1948 {
1949   return 0;
1950 }
1951 ],
1952     AC_MSG_RESULT([fine]),
1953     AC_MSG_RESULT([failed])
1954     AC_MSG_ERROR([one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS])
1955     )
1956
1957     dnl if this test fails, configure has already stopped
1958   fi
1959 ])
1960
1961
1962 dnl CURL_CHECK_VARIADIC_MACROS
1963 dnl -------------------------------------------------
1964 dnl Check compiler support of variadic macros
1965
1966 AC_DEFUN([CURL_CHECK_VARIADIC_MACROS], [
1967   AC_CACHE_CHECK([for compiler support of C99 variadic macro style],
1968     [curl_cv_variadic_macros_c99], [
1969     AC_COMPILE_IFELSE([
1970       AC_LANG_PROGRAM([
1971 #define c99_vmacro3(first, ...) fun3(first, __VA_ARGS__)
1972 #define c99_vmacro2(first, ...) fun2(first, __VA_ARGS__)
1973         int fun3(int arg1, int arg2, int arg3);
1974         int fun2(int arg1, int arg2);
1975         int fun3(int arg1, int arg2, int arg3)
1976         { return arg1 + arg2 + arg3; }
1977         int fun2(int arg1, int arg2)
1978         { return arg1 + arg2; }
1979       ],[
1980         int res3 = c99_vmacro3(1, 2, 3);
1981         int res2 = c99_vmacro2(1, 2);
1982       ])
1983     ],[
1984       curl_cv_variadic_macros_c99="yes"
1985     ],[
1986       curl_cv_variadic_macros_c99="no"
1987     ])
1988   ])
1989   case "$curl_cv_variadic_macros_c99" in
1990     yes)
1991       AC_DEFINE_UNQUOTED(HAVE_VARIADIC_MACROS_C99, 1,
1992         [Define to 1 if compiler supports C99 variadic macro style.])
1993       ;;
1994   esac
1995   AC_CACHE_CHECK([for compiler support of old gcc variadic macro style],
1996     [curl_cv_variadic_macros_gcc], [
1997     AC_COMPILE_IFELSE([
1998       AC_LANG_PROGRAM([
1999 #define gcc_vmacro3(first, args...) fun3(first, args)
2000 #define gcc_vmacro2(first, args...) fun2(first, args)
2001         int fun3(int arg1, int arg2, int arg3);
2002         int fun2(int arg1, int arg2);
2003         int fun3(int arg1, int arg2, int arg3)
2004         { return arg1 + arg2 + arg3; }
2005         int fun2(int arg1, int arg2)
2006         { return arg1 + arg2; }
2007       ],[
2008         int res3 = gcc_vmacro3(1, 2, 3);
2009         int res2 = gcc_vmacro2(1, 2);
2010       ])
2011     ],[
2012       curl_cv_variadic_macros_gcc="yes"
2013     ],[
2014       curl_cv_variadic_macros_gcc="no"
2015     ])
2016   ])
2017   case "$curl_cv_variadic_macros_gcc" in
2018     yes)
2019       AC_DEFINE_UNQUOTED(HAVE_VARIADIC_MACROS_GCC, 1,
2020         [Define to 1 if compiler supports old gcc variadic macro style.])
2021       ;;
2022   esac
2023 ])
2024
2025
2026 dnl CURL_CHECK_NATIVE_WINDOWS
2027 dnl -------------------------------------------------
2028 dnl Check if building a native Windows target
2029
2030 AC_DEFUN([CURL_CHECK_NATIVE_WINDOWS], [
2031   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
2032   AC_CACHE_CHECK([whether build target is a native Windows one], [ac_cv_native_windows], [
2033     if test "$ac_cv_header_windows_h" = "no"; then
2034       ac_cv_native_windows="no"
2035     else
2036       AC_COMPILE_IFELSE([
2037         AC_LANG_PROGRAM([
2038         ],[
2039 #ifdef __MINGW32__
2040           int dummy=1;
2041 #else
2042           Not a native Windows build target.
2043 #endif
2044         ])
2045       ],[
2046         ac_cv_native_windows="yes"
2047       ],[
2048         ac_cv_native_windows="no"
2049       ])
2050     fi
2051   ])
2052   case "$ac_cv_native_windows" in
2053     yes)
2054       AC_DEFINE_UNQUOTED(NATIVE_WINDOWS, 1,
2055         [Define to 1 if you are building a native Windows target.])
2056       ;;
2057   esac
2058 ])
2059