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