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