]> git.ipfire.org Git - thirdparty/curl.git/blame - acinclude.m4
Cludge fix for djgpp 2.03 or older; it doesn't have snprintf() etc.
[thirdparty/curl.git] / acinclude.m4
CommitLineData
d551412a
DS
1#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
2df622fd 8# Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
d551412a
DS
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###########################################################################
51581c03
YT
23
24dnl CURL_CHECK_HEADER_WINDOWS
25dnl -------------------------------------------------
b9f39c27 26dnl Check for compilable and valid windows.h header
51581c03
YT
27
28AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
29 AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [
30 AC_COMPILE_IFELSE([
31 AC_LANG_PROGRAM([
a6a5bba0 32#undef inline
74ed5b5e 33#ifndef WIN32_LEAN_AND_MEAN
51581c03 34#define WIN32_LEAN_AND_MEAN
74ed5b5e 35#endif
51581c03
YT
36#include <windows.h>
37 ],[
38 int dummy=2*WINVER;
39 ])
40 ],[
41 ac_cv_header_windows_h="yes"
42 ],[
43 ac_cv_header_windows_h="no"
44 ])
45 ])
46 if test "x$ac_cv_header_windows_h" = "xyes"; then
78febad7 47 AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
51581c03 48 [Define to 1 if you have the windows.h header file.])
b9f39c27
YT
49 AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
50 [Define to avoid automatic inclusion of winsock.h])
51581c03
YT
51 fi
52])
53
54
55dnl CURL_CHECK_HEADER_WINSOCK
56dnl -------------------------------------------------
b9f39c27 57dnl Check for compilable and valid winsock.h header
51581c03
YT
58
59AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
60 AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
61 AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
62 AC_COMPILE_IFELSE([
63 AC_LANG_PROGRAM([
a6a5bba0 64#undef inline
74ed5b5e 65#ifndef WIN32_LEAN_AND_MEAN
51581c03 66#define WIN32_LEAN_AND_MEAN
74ed5b5e 67#endif
51581c03
YT
68#include <windows.h>
69#include <winsock.h>
70 ],[
71 int dummy=WSACleanup();
72 ])
73 ],[
74 ac_cv_header_winsock_h="yes"
75 ],[
76 ac_cv_header_winsock_h="no"
77 ])
78 ])
79 if test "x$ac_cv_header_winsock_h" = "xyes"; then
78febad7 80 AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
51581c03
YT
81 [Define to 1 if you have the winsock.h header file.])
82 fi
83])
84
85
86dnl CURL_CHECK_HEADER_WINSOCK2
87dnl -------------------------------------------------
b9f39c27 88dnl Check for compilable and valid winsock2.h header
51581c03
YT
89
90AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
91 AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
92 AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
93 AC_COMPILE_IFELSE([
94 AC_LANG_PROGRAM([
a6a5bba0 95#undef inline
74ed5b5e 96#ifndef WIN32_LEAN_AND_MEAN
51581c03 97#define WIN32_LEAN_AND_MEAN
74ed5b5e 98#endif
51581c03
YT
99#include <windows.h>
100#include <winsock2.h>
101 ],[
102 int dummy=2*IPPROTO_ESP;
103 ])
104 ],[
105 ac_cv_header_winsock2_h="yes"
106 ],[
107 ac_cv_header_winsock2_h="no"
108 ])
109 ])
110 if test "x$ac_cv_header_winsock2_h" = "xyes"; then
78febad7 111 AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
51581c03
YT
112 [Define to 1 if you have the winsock2.h header file.])
113 fi
114])
115
116
117dnl CURL_CHECK_HEADER_WS2TCPIP
118dnl -------------------------------------------------
b9f39c27 119dnl Check for compilable and valid ws2tcpip.h header
51581c03
YT
120
121AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
122 AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
123 AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
124 AC_COMPILE_IFELSE([
125 AC_LANG_PROGRAM([
a6a5bba0 126#undef inline
74ed5b5e 127#ifndef WIN32_LEAN_AND_MEAN
51581c03 128#define WIN32_LEAN_AND_MEAN
74ed5b5e 129#endif
51581c03
YT
130#include <windows.h>
131#include <winsock2.h>
132#include <ws2tcpip.h>
133 ],[
134 int dummy=2*IP_PKTINFO;
135 ])
136 ],[
137 ac_cv_header_ws2tcpip_h="yes"
138 ],[
139 ac_cv_header_ws2tcpip_h="no"
140 ])
141 ])
142 if test "x$ac_cv_header_ws2tcpip_h" = "xyes"; then
78febad7 143 AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
51581c03
YT
144 [Define to 1 if you have the ws2tcpip.h header file.])
145 fi
146])
147
148
a6a5bba0
YT
149dnl CURL_CHECK_TYPE_SOCKLEN_T
150dnl -------------------------------------------------
b9f39c27
YT
151dnl Check for existing socklen_t type, and provide
152dnl an equivalent type if socklen_t not available
a6a5bba0
YT
153
154AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
155 AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
156 AC_CHECK_TYPE([socklen_t], ,[
5acac030
YT
157 AC_CACHE_CHECK([for socklen_t equivalent],
158 [curl_cv_socklen_t_equiv], [
b9f39c27 159 curl_cv_socklen_t_equiv="unknown"
fea5ddf5
YT
160 for arg2 in "struct sockaddr" void; do
161 for t in int size_t unsigned long "unsigned long"; do
a6a5bba0
YT
162 AC_COMPILE_IFELSE([
163 AC_LANG_PROGRAM([
164#undef inline
165#ifdef HAVE_WINDOWS_H
74ed5b5e 166#ifndef WIN32_LEAN_AND_MEAN
a6a5bba0 167#define WIN32_LEAN_AND_MEAN
74ed5b5e 168#endif
a6a5bba0
YT
169#include <windows.h>
170#ifdef HAVE_WINSOCK2_H
171#include <winsock2.h>
172#else
173#ifdef HAVE_WINSOCK_H
174#include <winsock.h>
175#endif
176#endif
177#else
178#ifdef HAVE_SYS_TYPES_H
179#include <sys/types.h>
180#endif
181#ifdef HAVE_SYS_SOCKET_H
182#include <sys/socket.h>
183#endif
184#endif
185 int getpeername (int, $arg2 *, $t *);
a6a5bba0 186 ],[
b9f39c27 187 $t len=0;
a6a5bba0 188 getpeername(0,0,&len);
a6a5bba0
YT
189 ])
190 ],[
5acac030 191 curl_cv_socklen_t_equiv="$t"
a6a5bba0
YT
192 break 2
193 ])
194 done
195 done
196 ])
b9f39c27 197 if test "$curl_cv_socklen_t_equiv" = "unknown"; then
5acac030 198 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
a6a5bba0 199 else
5acac030 200 AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
a6a5bba0
YT
201 [type to use in place of socklen_t if not defined])
202 fi
203 ],[
74ed5b5e 204#undef inline
a6a5bba0 205#ifdef HAVE_WINDOWS_H
74ed5b5e
YT
206#ifndef WIN32_LEAN_AND_MEAN
207#define WIN32_LEAN_AND_MEAN
208#endif
209#include <windows.h>
210#ifdef HAVE_WINSOCK2_H
211#include <winsock2.h>
a6a5bba0
YT
212#ifdef HAVE_WS2TCPIP_H
213#include <ws2tcpip.h>
214#endif
74ed5b5e 215#endif
a6a5bba0
YT
216#else
217#ifdef HAVE_SYS_TYPES_H
218#include <sys/types.h>
219#endif
220#ifdef HAVE_SYS_SOCKET_H
221#include <sys/socket.h>
222#endif
223#endif
224 ])
225])
226
227
e4388643 228dnl CURL_CHECK_FUNC_GETNAMEINFO
d6ffb4c1 229dnl -------------------------------------------------
e4388643
YT
230dnl Test if the getnameinfo function is available,
231dnl and check the types of five of its arguments.
232dnl If the function succeeds HAVE_GETNAMEINFO will be
233dnl defined, defining the types of the arguments in
d6ffb4c1 234dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
b1022ea4
YT
235dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7,
236dnl and also defining the type qualifier of first
237dnl argument in GETNAMEINFO_QUAL_ARG1.
d6ffb4c1 238
e4388643 239AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
d6ffb4c1
YT
240 AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
241 AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
242 AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
e4388643
YT
243 #
244 AC_MSG_CHECKING([for getnameinfo])
245 AC_LINK_IFELSE([
246 AC_LANG_FUNC_LINK_TRY([getnameinfo])
247 ],[
248 AC_MSG_RESULT([yes])
249 curl_cv_getnameinfo="yes"
250 ],[
251 AC_MSG_RESULT([no])
252 curl_cv_getnameinfo="no"
253 ])
254 #
255 if test "$curl_cv_getnameinfo" != "yes"; then
256 AC_MSG_CHECKING([deeper for getnameinfo])
257 AC_TRY_LINK([
258 ],[
259 getnameinfo();
260 ],[
261 AC_MSG_RESULT([yes])
262 curl_cv_getnameinfo="yes"
263 ],[
264 AC_MSG_RESULT([but still no])
265 curl_cv_getnameinfo="no"
266 ])
267 fi
268 #
269 if test "$curl_cv_getnameinfo" != "yes"; then
270 AC_MSG_CHECKING([deeper and deeper for getnameinfo])
271 AC_TRY_LINK([
272#undef inline
273#ifdef HAVE_WINDOWS_H
274#ifndef WIN32_LEAN_AND_MEAN
275#define WIN32_LEAN_AND_MEAN
276#endif
277#include <windows.h>
278#ifdef HAVE_WINSOCK2_H
279#include <winsock2.h>
280#ifdef HAVE_WS2TCPIP_H
281#include <ws2tcpip.h>
282#endif
283#endif
284#else
285#ifdef HAVE_SYS_TYPES_H
286#include <sys/types.h>
287#endif
288#ifdef HAVE_SYS_SOCKET_H
289#include <sys/socket.h>
290#endif
291#ifdef HAVE_NETDB_H
292#include <netdb.h>
293#endif
294#endif
295 ],[
296 getnameinfo(0, 0, 0, 0, 0, 0, 0);
297 ],[
298 AC_MSG_RESULT([yes])
299 curl_cv_getnameinfo="yes"
300 ],[
301 AC_MSG_RESULT([but still no])
302 curl_cv_getnameinfo="no"
303 ])
304 fi
305 #
306 if test "$curl_cv_getnameinfo" = "yes"; then
307 AC_CACHE_CHECK([types of arguments for getnameinfo],
308 [curl_cv_func_getnameinfo_args], [
309 curl_cv_func_getnameinfo_args="unknown"
310 for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
311 for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
312 for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
313 for gni_arg7 in 'int' 'unsigned int'; do
314 AC_COMPILE_IFELSE([
315 AC_LANG_PROGRAM([
e3657644 316#undef inline
d6ffb4c1 317#ifdef HAVE_WINDOWS_H
74ed5b5e 318#ifndef WIN32_LEAN_AND_MEAN
d6ffb4c1 319#define WIN32_LEAN_AND_MEAN
8a3280a2 320#endif
e3657644 321#if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
f4481685
YT
322#undef _WIN32_WINNT
323#define _WIN32_WINNT 0x0501
324#endif
d6ffb4c1
YT
325#include <windows.h>
326#ifdef HAVE_WINSOCK2_H
e3657644 327#include <winsock2.h>
d6ffb4c1
YT
328#ifdef HAVE_WS2TCPIP_H
329#include <ws2tcpip.h>
330#endif
74ed5b5e 331#endif
e3657644 332#define GNICALLCONV WSAAPI
d6ffb4c1
YT
333#else
334#ifdef HAVE_SYS_TYPES_H
335#include <sys/types.h>
336#endif
337#ifdef HAVE_SYS_SOCKET_H
338#include <sys/socket.h>
339#endif
340#ifdef HAVE_NETDB_H
341#include <netdb.h>
342#endif
e3657644 343#define GNICALLCONV
d6ffb4c1 344#endif
e4388643
YT
345 extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
346 char *, $gni_arg46,
347 char *, $gni_arg46,
348 $gni_arg7);
349 ],[
350 $gni_arg2 salen=0;
351 $gni_arg46 hostlen=0;
352 $gni_arg46 servlen=0;
353 $gni_arg7 flags=0;
354 int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
355 ])
d6ffb4c1 356 ],[
e4388643
YT
357 curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
358 break 4
d6ffb4c1 359 ])
e4388643 360 done
d6ffb4c1
YT
361 done
362 done
363 done
e4388643
YT
364 ]) # AC_CACHE_CHECK
365 if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
366 AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
367 AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
368 else
369 gni_prev_IFS=$IFS; IFS=','
370 set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
371 IFS=$gni_prev_IFS
372 shift
39745ac3
YT
373 #
374 gni_qual_type_arg1=$[1]
375 #
e4388643
YT
376 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
377 [Define to the type of arg 2 for getnameinfo.])
378 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
379 [Define to the type of args 4 and 6 for getnameinfo.])
380 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
381 [Define to the type of arg 7 for getnameinfo.])
b1022ea4 382 #
55329b56 383 prev_sh_opts=$-
39745ac3 384 #
55329b56 385 case $prev_sh_opts in
39745ac3
YT
386 *f*)
387 ;;
388 *)
389 set -f
390 ;;
391 esac
b1022ea4
YT
392 #
393 case "$gni_qual_type_arg1" in
394 const*)
395 gni_qual_arg1=const
39745ac3 396 gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
b1022ea4
YT
397 ;;
398 *)
399 gni_qual_arg1=
39745ac3 400 gni_type_arg1=$gni_qual_type_arg1
b1022ea4
YT
401 ;;
402 esac
403 #
7a6d7fca 404 AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
b1022ea4 405 [Define to the type qualifier of arg 1 for getnameinfo.])
7a6d7fca 406 AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
b1022ea4
YT
407 [Define to the type of arg 1 for getnameinfo.])
408 #
55329b56 409 case $prev_sh_opts in
39745ac3
YT
410 *f*)
411 ;;
412 *)
413 set +f
414 ;;
415 esac
416 #
e4388643
YT
417 AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
418 [Define to 1 if you have the getnameinfo function.])
419 ac_cv_func_getnameinfo="yes"
420 fi
d6ffb4c1 421 fi
e4388643 422]) # AC_DEFUN
d6ffb4c1
YT
423
424
bec19771
YT
425dnl TYPE_SOCKADDR_STORAGE
426dnl -------------------------------------------------
427dnl Check for struct sockaddr_storage. Most IPv6-enabled
428dnl hosts have it, but AIX 4.3 is one known exception.
429
430AC_DEFUN([TYPE_SOCKADDR_STORAGE],
431[
432 AC_CHECK_TYPE([struct sockaddr_storage],
433 AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
434 [if struct sockaddr_storage is defined]), ,
435 [
436#undef inline
437#ifdef HAVE_WINDOWS_H
438#ifndef WIN32_LEAN_AND_MEAN
439#define WIN32_LEAN_AND_MEAN
440#endif
441#include <windows.h>
442#ifdef HAVE_WINSOCK2_H
443#include <winsock2.h>
444#endif
445#else
446#ifdef HAVE_SYS_TYPES_H
447#include <sys/types.h>
448#endif
449#ifdef HAVE_SYS_SOCKET_H
450#include <sys/socket.h>
451#endif
452#ifdef HAVE_NETINET_IN_H
453#include <netinet/in.h>
454#endif
455#ifdef HAVE_ARPA_INET_H
456#include <arpa/inet.h>
457#endif
458#endif
459 ])
460])
461
462
4c08eb4b
YT
463dnl CURL_CHECK_NI_WITHSCOPEID
464dnl -------------------------------------------------
465dnl Check for working NI_WITHSCOPEID in getnameinfo()
466
467AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID], [
bec19771
YT
468 AC_REQUIRE([CURL_CHECK_FUNC_GETNAMEINFO])dnl
469 AC_REQUIRE([TYPE_SOCKADDR_STORAGE])dnl
470 AC_CHECK_HEADERS(stdio.h sys/types.h sys/socket.h \
471 netdb.h netinet/in.h arpa/inet.h)
472 #
4c08eb4b
YT
473 AC_CACHE_CHECK([for working NI_WITHSCOPEID],
474 [ac_cv_working_ni_withscopeid], [
475 AC_RUN_IFELSE([
476 AC_LANG_PROGRAM([
bec19771 477#ifdef HAVE_STDIO_H
4c08eb4b 478#include <stdio.h>
bec19771
YT
479#endif
480#ifdef HAVE_SYS_TYPES_H
4c08eb4b 481#include <sys/types.h>
bec19771
YT
482#endif
483#ifdef HAVE_SYS_SOCKET_H
4c08eb4b 484#include <sys/socket.h>
bec19771
YT
485#endif
486#ifdef HAVE_NETDB_H
4c08eb4b 487#include <netdb.h>
bec19771
YT
488#endif
489#ifdef HAVE_NETINET_IN_H
490#include <netinet/in.h>
491#endif
492#ifdef HAVE_ARPA_INET_H
493#include <arpa/inet.h>
494#endif
4c08eb4b 495 ],[
bec19771
YT
496#if defined(NI_WITHSCOPEID) && defined(HAVE_GETNAMEINFO)
497#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
498 struct sockaddr_storage sa;
499#else
500 unsigned char sa[256];
501#endif
502 char hostbuf[NI_MAXHOST];
4c08eb4b 503 int rc;
bec19771
YT
504 GETNAMEINFO_TYPE_ARG2 salen = (GETNAMEINFO_TYPE_ARG2)sizeof(sa);
505 GETNAMEINFO_TYPE_ARG46 hostlen = (GETNAMEINFO_TYPE_ARG46)sizeof(hostbuf);
506 GETNAMEINFO_TYPE_ARG7 flags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
4c08eb4b
YT
507 int fd = socket(AF_INET6, SOCK_STREAM, 0);
508 if(fd < 0) {
509 perror("socket()");
510 return 1; /* Error creating socket */
511 }
bec19771 512 rc = getsockname(fd, (GETNAMEINFO_TYPE_ARG1)&sa, &salen);
4c08eb4b
YT
513 if(rc) {
514 perror("getsockname()");
515 return 2; /* Error retrieving socket name */
516 }
bec19771 517 rc = getnameinfo((GETNAMEINFO_TYPE_ARG1)&sa, salen, hostbuf, hostlen, NULL, 0, flags);
4c08eb4b
YT
518 if(rc) {
519 printf("rc = %s\n", gai_strerror(rc));
520 return 3; /* Error translating socket address */
521 }
522 return 0; /* Ok, NI_WITHSCOPEID works */
523#else
bec19771 524 return 4; /* Error, NI_WITHSCOPEID not defined or no getnameinfo() */
4c08eb4b
YT
525#endif
526 ]) # AC_LANG_PROGRAM
527 ],[
528 # Exit code == 0. Program worked.
529 ac_cv_working_ni_withscopeid="yes"
530 ],[
531 # Exit code != 0. Program failed.
532 ac_cv_working_ni_withscopeid="no"
533 ],[
534 # Program is not run when cross-compiling. So we assume
535 # NI_WITHSCOPEID will work if we are able to compile it.
536 AC_COMPILE_IFELSE([
537 AC_LANG_PROGRAM([
4c08eb4b
YT
538#include <sys/types.h>
539#include <sys/socket.h>
540#include <netdb.h>
541 ],[
542 unsigned int dummy= NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
543 ])
544 ],[
545 ac_cv_working_ni_withscopeid="yes"
546 ],[
547 ac_cv_working_ni_withscopeid="no"
548 ]) # AC_COMPILE_IFELSE
549 ]) # AC_RUN_IFELSE
550 ]) # AC_CACHE_CHECK
551 if test "x$ac_cv_working_ni_withscopeid" = "xyes"; then
552 AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
553 [Define to 1 if NI_WITHSCOPEID exists and works.])
554 fi
555]) # AC_DEFUN
556
557
01fa02d0
YT
558dnl CURL_CHECK_FUNC_RECV
559dnl -------------------------------------------------
560dnl Test if the socket recv() function is available,
561dnl and check its return type and the types of its
562dnl arguments. If the function succeeds HAVE_RECV
563dnl will be defined, defining the types of the arguments
564dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3
565dnl and RECV_TYPE_ARG4, defining the type of the function
566dnl return value in RECV_TYPE_RETV.
567
568AC_DEFUN([CURL_CHECK_FUNC_RECV], [
569 AC_CHECK_HEADERS(sys/types.h sys/socket.h)
570 #
571 AC_MSG_CHECKING([for recv])
572 AC_TRY_LINK([
573#undef inline
574#ifdef HAVE_SYS_TYPES_H
575#include <sys/types.h>
576#endif
577#ifdef HAVE_SYS_SOCKET_H
578#include <sys/socket.h>
579#endif
580 ],[
581 recv(0, 0, 0, 0);
582 ],[
583 AC_MSG_RESULT([yes])
584 curl_cv_recv="yes"
585 ],[
586 AC_MSG_RESULT([no])
587 curl_cv_recv="no"
588 ])
589 #
590 if test "$curl_cv_recv" = "yes"; then
591 AC_CACHE_CHECK([types of arguments and return type for recv],
592 [curl_cv_func_recv_args], [
593 curl_cv_func_recv_args="unknown"
594 for recv_retv in 'int' 'ssize_t'; do
595 for recv_arg1 in 'int' 'ssize_t'; do
7e43d06b 596 for recv_arg2 in 'char *' 'void *'; do
01fa02d0
YT
597 for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
598 for recv_arg4 in 'int' 'unsigned int'; do
599 AC_COMPILE_IFELSE([
600 AC_LANG_PROGRAM([
601#undef inline
602#ifdef HAVE_SYS_TYPES_H
603#include <sys/types.h>
604#endif
605#ifdef HAVE_SYS_SOCKET_H
606#include <sys/socket.h>
607#endif
608 extern $recv_retv recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
609 ],[
610 $recv_arg1 s=0;
611 $recv_arg2 buf=0;
612 $recv_arg3 len=0;
613 $recv_arg4 flags=0;
614 $recv_retv res = recv(s, buf, len, flags);
615 ])
616 ],[
617 curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
618 break 5
619 ])
620 done
621 done
622 done
623 done
624 done
625 ]) # AC_CACHE_CHECK
626 if test "$curl_cv_func_recv_args" = "unknown"; then
627 AC_MSG_WARN([Cannot find proper types to use for recv args])
628 AC_MSG_WARN([HAVE_RECV will not be defined])
629 else
630 recv_prev_IFS=$IFS; IFS=','
631 set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
632 IFS=$recv_prev_IFS
633 shift
634 #
635 AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
636 [Define to the type of arg 1 for recv.])
637 AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
638 [Define to the type of arg 2 for recv.])
639 AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
640 [Define to the type of arg 3 for recv.])
641 AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
642 [Define to the type of arg 4 for recv.])
643 AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
644 [Define to the function return type for recv.])
645 #
646 AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
647 [Define to 1 if you have the recv function.])
648 ac_cv_func_recv="yes"
649 fi
650 fi
651]) # AC_DEFUN
652
653
654dnl CURL_CHECK_FUNC_SEND
655dnl -------------------------------------------------
656dnl Test if the socket send() function is available,
657dnl and check its return type and the types of its
658dnl arguments. If the function succeeds HAVE_SEND
659dnl will be defined, defining the types of the arguments
660dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3
661dnl and SEND_TYPE_ARG4, defining the type of the function
7e43d06b
YT
662dnl return value in SEND_TYPE_RETV, and also defining the
663dnl type qualifier of second argument in SEND_QUAL_ARG2.
01fa02d0
YT
664
665AC_DEFUN([CURL_CHECK_FUNC_SEND], [
666 AC_CHECK_HEADERS(sys/types.h sys/socket.h)
667 #
668 AC_MSG_CHECKING([for send])
669 AC_TRY_LINK([
670#undef inline
671#ifdef HAVE_SYS_TYPES_H
672#include <sys/types.h>
673#endif
674#ifdef HAVE_SYS_SOCKET_H
675#include <sys/socket.h>
676#endif
677 ],[
678 send(0, 0, 0, 0);
679 ],[
680 AC_MSG_RESULT([yes])
681 curl_cv_send="yes"
682 ],[
683 AC_MSG_RESULT([no])
684 curl_cv_send="no"
685 ])
686 #
687 if test "$curl_cv_send" = "yes"; then
688 AC_CACHE_CHECK([types of arguments and return type for send],
689 [curl_cv_func_send_args], [
690 curl_cv_func_send_args="unknown"
691 for send_retv in 'int' 'ssize_t'; do
692 for send_arg1 in 'int' 'ssize_t'; do
7e43d06b 693 for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
01fa02d0
YT
694 for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
695 for send_arg4 in 'int' 'unsigned int'; do
696 AC_COMPILE_IFELSE([
697 AC_LANG_PROGRAM([
698#undef inline
699#ifdef HAVE_SYS_TYPES_H
700#include <sys/types.h>
701#endif
702#ifdef HAVE_SYS_SOCKET_H
703#include <sys/socket.h>
704#endif
705 extern $send_retv send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
706 ],[
707 $send_arg1 s=0;
01fa02d0
YT
708 $send_arg3 len=0;
709 $send_arg4 flags=0;
7e43d06b 710 $send_retv res = send(s, 0, len, flags);
01fa02d0
YT
711 ])
712 ],[
713 curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
714 break 5
715 ])
716 done
717 done
718 done
719 done
720 done
721 ]) # AC_CACHE_CHECK
722 if test "$curl_cv_func_send_args" = "unknown"; then
723 AC_MSG_WARN([Cannot find proper types to use for send args])
724 AC_MSG_WARN([HAVE_SEND will not be defined])
725 else
726 send_prev_IFS=$IFS; IFS=','
727 set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
728 IFS=$send_prev_IFS
729 shift
730 #
7e43d06b
YT
731 send_qual_type_arg2=$[2]
732 #
01fa02d0
YT
733 AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
734 [Define to the type of arg 1 for send.])
01fa02d0
YT
735 AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
736 [Define to the type of arg 3 for send.])
737 AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
738 [Define to the type of arg 4 for send.])
739 AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
740 [Define to the function return type for send.])
741 #
55329b56 742 prev_sh_opts=$-
7e43d06b 743 #
55329b56 744 case $prev_sh_opts in
7e43d06b
YT
745 *f*)
746 ;;
747 *)
748 set -f
749 ;;
750 esac
751 #
752 case "$send_qual_type_arg2" in
753 const*)
754 send_qual_arg2=const
755 send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
756 ;;
757 *)
758 send_qual_arg2=
759 send_type_arg2=$send_qual_type_arg2
760 ;;
761 esac
762 #
763 AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
764 [Define to the type qualifier of arg 2 for send.])
765 AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
766 [Define to the type of arg 2 for send.])
767 #
55329b56 768 case $prev_sh_opts in
7e43d06b
YT
769 *f*)
770 ;;
771 *)
772 set +f
773 ;;
774 esac
775 #
01fa02d0
YT
776 AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
777 [Define to 1 if you have the send function.])
778 ac_cv_func_send="yes"
779 fi
780 fi
781]) # AC_DEFUN
782
783
74ed5b5e
YT
784dnl CURL_CHECK_NONBLOCKING_SOCKET
785dnl -------------------------------------------------
6ca45bea
DS
786dnl Check for how to set a socket to non-blocking state. There seems to exist
787dnl four known different ways, with the one used almost everywhere being POSIX
788dnl and XPG3, while the other different ways for different systems (old BSD,
789dnl Windows and Amiga).
790dnl
791dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
792dnl O_NONBLOCK define is found but does not work. This condition is attempted
793dnl to get caught in this script by using an excessive number of #ifdefs...
794dnl
4c70c3e8 795AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
6ca45bea
DS
796[
797 AC_MSG_CHECKING([non-blocking sockets style])
798
799 AC_TRY_COMPILE([
800/* headers for O_NONBLOCK test */
801#include <sys/types.h>
802#include <unistd.h>
803#include <fcntl.h>
804],[
805/* try to compile O_NONBLOCK */
806
807#if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
808# if defined(__SVR4) || defined(__srv4__)
809# define PLATFORM_SOLARIS
810# else
811# define PLATFORM_SUNOS4
812# endif
813#endif
814#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
815# define PLATFORM_AIX_V3
816#endif
817
bf20ed59 818#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
6ca45bea
DS
819#error "O_NONBLOCK does not work on this platform"
820#endif
821 int socket;
822 int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
823],[
824dnl the O_NONBLOCK test was fine
825nonblock="O_NONBLOCK"
b9c60df0 826AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
6ca45bea
DS
827],[
828dnl the code was bad, try a different program now, test 2
829
830 AC_TRY_COMPILE([
831/* headers for FIONBIO test */
832#include <unistd.h>
833#include <stropts.h>
834],[
0bbe184f
DS
835/* FIONBIO source test (old-style unix) */
836 int socket;
6ca45bea
DS
837 int flags = ioctl(socket, FIONBIO, &flags);
838],[
839dnl FIONBIO test was good
840nonblock="FIONBIO"
b9c60df0 841AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
6ca45bea
DS
842],[
843dnl FIONBIO test was also bad
844dnl the code was bad, try a different program now, test 3
845
846 AC_TRY_COMPILE([
74ed5b5e
YT
847/* headers for ioctlsocket test (Windows) */
848#undef inline
849#ifdef HAVE_WINDOWS_H
850#ifndef WIN32_LEAN_AND_MEAN
851#define WIN32_LEAN_AND_MEAN
852#endif
6ca45bea 853#include <windows.h>
74ed5b5e
YT
854#ifdef HAVE_WINSOCK2_H
855#include <winsock2.h>
856#else
857#ifdef HAVE_WINSOCK_H
858#include <winsock.h>
859#endif
860#endif
861#endif
6ca45bea
DS
862],[
863/* ioctlsocket source code */
df2b1251
YT
864 SOCKET sd;
865 unsigned long flags = 0;
866 sd = socket(0, 0, 0);
867 ioctlsocket(sd, FIONBIO, &flags);
6ca45bea
DS
868],[
869dnl ioctlsocket test was good
870nonblock="ioctlsocket"
b9c60df0 871AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
6ca45bea 872],[
0bbe184f 873dnl ioctlsocket didnt compile!, go to test 4
6ca45bea 874
0bbe184f 875 AC_TRY_LINK([
6ca45bea
DS
876/* headers for IoctlSocket test (Amiga?) */
877#include <sys/ioctl.h>
878],[
879/* IoctlSocket source code */
0bbe184f 880 int socket;
6ca45bea
DS
881 int flags = IoctlSocket(socket, FIONBIO, (long)1);
882],[
883dnl ioctlsocket test was good
884nonblock="IoctlSocket"
b9c60df0 885AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
6ca45bea 886],[
0bbe184f
DS
887dnl Ioctlsocket didnt compile, do test 5!
888 AC_TRY_COMPILE([
889/* headers for SO_NONBLOCK test (BeOS) */
58f4af79 890#include <socket.h>
0bbe184f
DS
891],[
892/* SO_NONBLOCK source code */
893 long b = 1;
894 int socket;
895 int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
896],[
897dnl the SO_NONBLOCK test was good
898nonblock="SO_NONBLOCK"
899AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
900],[
901dnl test 5 didnt compile!
6ca45bea 902nonblock="nada"
b9c60df0 903AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
0bbe184f
DS
904])
905dnl end of fifth test
906
6ca45bea
DS
907])
908dnl end of forth test
909
910])
911dnl end of third test
912
913])
914dnl end of second test
915
916])
917dnl end of non-blocking try-compile test
918 AC_MSG_RESULT($nonblock)
919
920 if test "$nonblock" = "nada"; then
921 AC_MSG_WARN([non-block sockets disabled])
922 fi
923])
924
74ed5b5e 925
74ed5b5e
YT
926dnl TYPE_IN_ADDR_T
927dnl -------------------------------------------------
d09b4369 928dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
ef355196 929dnl and a few other things.
d09b4369
DS
930AC_DEFUN([TYPE_IN_ADDR_T],
931[
932 AC_CHECK_TYPE([in_addr_t], ,[
933 AC_MSG_CHECKING([for in_addr_t equivalent])
934 AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
935 [
d09b4369 936 curl_cv_in_addr_t_equiv=
de9b76ce 937 for t in "unsigned long" int size_t unsigned long; do
820de919 938 AC_TRY_COMPILE([
74ed5b5e
YT
939#undef inline
940#ifdef HAVE_WINDOWS_H
941#ifndef WIN32_LEAN_AND_MEAN
942#define WIN32_LEAN_AND_MEAN
943#endif
944#include <windows.h>
945#ifdef HAVE_WINSOCK2_H
946#include <winsock2.h>
947#else
948#ifdef HAVE_WINSOCK_H
949#include <winsock.h>
950#endif
951#endif
952#else
953#ifdef HAVE_SYS_TYPES_H
954#include <sys/types.h>
955#endif
956#ifdef HAVE_SYS_SOCKET_H
957#include <sys/socket.h>
958#endif
959#ifdef HAVE_NETINET_IN_H
960#include <netinet/in.h>
961#endif
f4481685
YT
962#ifdef HAVE_ARPA_INET_H
963#include <arpa/inet.h>
964#endif
74ed5b5e 965#endif
820de919
DS
966 ],[
967 $t data = inet_addr ("1.2.3.4");
968 ],[
969 curl_cv_in_addr_t_equiv="$t"
970 break
971 ])
d09b4369
DS
972 done
973
974 if test "x$curl_cv_in_addr_t_equiv" = x; then
975 AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
976 fi
977 ])
978 AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
979 AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
980 [type to use in place of in_addr_t if not defined])],
74ed5b5e
YT
981 [
982#undef inline
983#ifdef HAVE_WINDOWS_H
984#ifndef WIN32_LEAN_AND_MEAN
985#define WIN32_LEAN_AND_MEAN
986#endif
987#include <windows.h>
988#ifdef HAVE_WINSOCK2_H
989#include <winsock2.h>
990#else
991#ifdef HAVE_WINSOCK_H
992#include <winsock.h>
993#endif
994#endif
995#else
996#ifdef HAVE_SYS_TYPES_H
997#include <sys/types.h>
998#endif
999#ifdef HAVE_SYS_SOCKET_H
d2203896 1000#include <sys/socket.h>
74ed5b5e
YT
1001#endif
1002#ifdef HAVE_NETINET_IN_H
1003#include <netinet/in.h>
1004#endif
f4481685
YT
1005#ifdef HAVE_ARPA_INET_H
1006#include <arpa/inet.h>
1007#endif
74ed5b5e 1008#endif
6de67a13
DS
1009 ]) dnl AC_CHECK_TYPE
1010]) dnl AC_DEFUN
d09b4369 1011
a1cec0e4
DS
1012dnl ************************************************************
1013dnl check for "localhost", if it doesn't exist, we can't do the
1014dnl gethostbyname_r tests!
1015dnl
1016
4c70c3e8 1017AC_DEFUN([CURL_CHECK_WORKING_RESOLVER],[
a1cec0e4
DS
1018AC_MSG_CHECKING([if "localhost" resolves])
1019AC_TRY_RUN([
1020#include <string.h>
1021#include <sys/types.h>
1022#include <netdb.h>
1023
1024int
1025main () {
1026struct hostent *h;
1027h = gethostbyname("localhost");
1028exit (h == NULL ? 1 : 0); }],[
1029 AC_MSG_RESULT(yes)],[
1030 AC_MSG_RESULT(no)
1031 AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
1032
1033 ]
1034)
1035])
1036
1037dnl ************************************************************
07e58aaa 1038dnl check for working getaddrinfo() that works with AI_NUMERICHOST
a1cec0e4 1039dnl
4c70c3e8 1040AC_DEFUN([CURL_CHECK_WORKING_GETADDRINFO],[
a1cec0e4
DS
1041 AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
1042 AC_TRY_RUN( [
1043#include <netdb.h>
1044#include <sys/types.h>
1045#include <sys/socket.h>
1046
a2ea0abf
DS
1047int main(void)
1048{
a1cec0e4
DS
1049 struct addrinfo hints, *ai;
1050 int error;
1051
1052 memset(&hints, 0, sizeof(hints));
07e58aaa 1053 hints.ai_flags = AI_NUMERICHOST;
a1cec0e4
DS
1054 hints.ai_family = AF_UNSPEC;
1055 hints.ai_socktype = SOCK_STREAM;
1056 error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
1057 if (error) {
a2ea0abf 1058 return 1;
a1cec0e4 1059 }
a2ea0abf 1060 return 0;
a1cec0e4
DS
1061}
1062],[
1063 ac_cv_working_getaddrinfo="yes"
1064],[
1065 ac_cv_working_getaddrinfo="no"
1066],[
1067 ac_cv_working_getaddrinfo="yes"
1068])])
1069if test "$ac_cv_working_getaddrinfo" = "yes"; then
1070 AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
1071 AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
1072
1073 IPV6_ENABLED=1
1074 AC_SUBST(IPV6_ENABLED)
1075fi
1076])
1077
1078
4c70c3e8 1079AC_DEFUN([CURL_CHECK_LOCALTIME_R],
a1cec0e4 1080[
242be557 1081 dnl check for localtime_r
a1cec0e4
DS
1082 AC_CHECK_FUNCS(localtime_r,[
1083 AC_MSG_CHECKING(whether localtime_r is declared)
1084 AC_EGREP_CPP(localtime_r,[
1085#include <time.h>],[
1086 AC_MSG_RESULT(yes)],[
1087 AC_MSG_RESULT(no)
1088 AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
1089 AC_EGREP_CPP(localtime_r,[
1090#define _REENTRANT
1091#include <time.h>],[
1092 AC_DEFINE(NEED_REENTRANT)
1093 AC_MSG_RESULT(yes)],
1094 AC_MSG_RESULT(no))])])
1095])
1096
7461592a
DS
1097dnl
1098dnl This function checks for strerror_r(). If it isn't found at first, it
1099dnl retries with _THREAD_SAFE defined, as that is what AIX seems to require
1100dnl in order to find this function.
1101dnl
1102dnl If the function is found, it will then proceed to check how the function
1103dnl actually works: glibc-style or POSIX-style.
1104dnl
1105dnl glibc:
1106dnl char *strerror_r(int errnum, char *buf, size_t n);
1107dnl
1108dnl What this one does is to return the error string (no surprises there),
1109dnl but it doesn't usually copy anything into buf! The 'buf' and 'n'
1110dnl parameters are only meant as an optional working area, in case strerror_r
1111dnl needs it. A quick test on a few systems shows that it's generally not
1112dnl touched at all.
1113dnl
1114dnl POSIX:
1115dnl int strerror_r(int errnum, char *buf, size_t n);
1116dnl
242be557
DS
1117AC_DEFUN([CURL_CHECK_STRERROR_R],
1118[
b9e5302f
DS
1119 AC_CHECK_FUNCS(strerror_r)
1120
1121 if test "x$ac_cv_func_strerror_r" = "xyes"; then
1122
242be557
DS
1123 AC_MSG_CHECKING(whether strerror_r is declared)
1124 AC_EGREP_CPP(strerror_r,[
1125#include <string.h>],[
1126 AC_MSG_RESULT(yes)],[
1127 AC_MSG_RESULT(no)
b9e5302f 1128 AC_MSG_CHECKING(whether strerror_r with -D_REENTRANT is declared)
242be557 1129 AC_EGREP_CPP(strerror_r,[
b9e5302f 1130#define _REENTRANT
242be557 1131#include <string.h>],[
b9e5302f 1132 CPPFLAGS="-D_REENTRANT $CPPFLAGS"
242be557 1133 AC_MSG_RESULT(yes)],
b9e5302f
DS
1134 AC_MSG_RESULT(no)
1135 AC_DEFINE(HAVE_NO_STRERROR_R_DECL, 1, [we have no strerror_r() proto])
1136 ) dnl with _THREAD_SAFE
1137 ]) dnl plain cpp for it
6f74820c 1138
7461592a
DS
1139 dnl determine if this strerror_r() is glibc or POSIX
1140 AC_MSG_CHECKING([for a glibc strerror_r API])
1141 AC_TRY_RUN([
1142#include <string.h>
1143#include <errno.h>
1144int
1145main () {
1146 char buffer[1024]; /* big enough to play with */
1147 char *string =
1148 strerror_r(EACCES, buffer, sizeof(buffer));
1149 /* this should've returned a string */
1150 if(!string || !string[0])
1151 return 99;
1152 return 0;
1153}
1154],
18dd8154 1155 GLIBC_STRERROR_R="1"
7461592a
DS
1156 AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
1157 AC_MSG_RESULT([yes]),
18dd8154 1158 AC_MSG_RESULT([no]),
b37a0b05
DF
1159
1160 dnl Use an inferior method of strerror_r detection while cross-compiling
1161 AC_EGREP_CPP(yes, [
1162#include <features.h>
1163#ifdef __GLIBC__
1164yes
1165#endif
1166],
1167 dnl looks like glibc, so assume a glibc-style strerror_r()
1168 GLIBC_STRERROR_R="1"
1169 AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
1170 AC_MSG_RESULT([yes]),
1171 AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
1172 ) dnl while cross-compiling
18dd8154 1173 )
7461592a 1174
18dd8154
DS
1175 if test -z "$GLIBC_STRERROR_R"; then
1176
1177 AC_MSG_CHECKING([for a POSIX strerror_r API])
1178 AC_TRY_RUN([
7461592a
DS
1179#include <string.h>
1180#include <errno.h>
1181int
1182main () {
1183 char buffer[1024]; /* big enough to play with */
1184 int error =
1185 strerror_r(EACCES, buffer, sizeof(buffer));
1186 /* This should've returned zero, and written an error string in the
1187 buffer.*/
1188 if(!buffer[0] || error)
1189 return 99;
1190 return 0;
1191}
1192],
18dd8154
DS
1193 AC_DEFINE(HAVE_POSIX_STRERROR_R, 1, [we have a POSIX-style strerror_r()])
1194 AC_MSG_RESULT([yes]),
1195 AC_MSG_RESULT([no]) ,
1196 dnl cross-compiling!
1197 AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
1198 )
7461592a 1199
18dd8154
DS
1200 fi dnl if not using glibc API
1201
1202 fi dnl we have a strerror_r
7461592a 1203
242be557
DS
1204])
1205
4c70c3e8 1206AC_DEFUN([CURL_CHECK_INET_NTOA_R],
a1cec0e4
DS
1207[
1208 dnl determine if function definition for inet_ntoa_r exists.
1209 AC_CHECK_FUNCS(inet_ntoa_r,[
1210 AC_MSG_CHECKING(whether inet_ntoa_r is declared)
1211 AC_EGREP_CPP(inet_ntoa_r,[
1212#include <arpa/inet.h>],[
b9c60df0 1213 AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
a1cec0e4
DS
1214 AC_MSG_RESULT(yes)],[
1215 AC_MSG_RESULT(no)
1216 AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
1217 AC_EGREP_CPP(inet_ntoa_r,[
1218#define _REENTRANT
1219#include <arpa/inet.h>],[
b9c60df0
DS
1220 AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
1221 AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
a1cec0e4
DS
1222 AC_MSG_RESULT(yes)],
1223 AC_MSG_RESULT(no))])])
a1cec0e4
DS
1224])
1225
4c70c3e8 1226AC_DEFUN([CURL_CHECK_GETHOSTBYADDR_R],
a1cec0e4
DS
1227[
1228 dnl check for number of arguments to gethostbyaddr_r. it might take
1229 dnl either 5, 7, or 8 arguments.
1230 AC_CHECK_FUNCS(gethostbyaddr_r,[
1231 AC_MSG_CHECKING(if gethostbyaddr_r takes 5 arguments)
1232 AC_TRY_COMPILE([
1233#include <sys/types.h>
1234#include <netdb.h>],[
1235char * address;
1236int length;
1237int type;
1238struct hostent h;
1239struct hostent_data hdata;
1240int rc;
1241rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
1242 AC_MSG_RESULT(yes)
b9c60df0 1243 AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
a1cec0e4
DS
1244 ac_cv_gethostbyaddr_args=5],[
1245 AC_MSG_RESULT(no)
1246 AC_MSG_CHECKING(if gethostbyaddr_r with -D_REENTRANT takes 5 arguments)
1247 AC_TRY_COMPILE([
1248#define _REENTRANT
1249#include <sys/types.h>
1250#include <netdb.h>],[
1251char * address;
1252int length;
1253int type;
1254struct hostent h;
1255struct hostent_data hdata;
1256int rc;
1257rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
1258 AC_MSG_RESULT(yes)
b9c60df0
DS
1259 AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
1260 AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
a1cec0e4
DS
1261 ac_cv_gethostbyaddr_args=5],[
1262 AC_MSG_RESULT(no)
1263 AC_MSG_CHECKING(if gethostbyaddr_r takes 7 arguments)
1264 AC_TRY_COMPILE([
1265#include <sys/types.h>
1266#include <netdb.h>],[
1267char * address;
1268int length;
1269int type;
1270struct hostent h;
1271char buffer[8192];
1272int h_errnop;
1273struct hostent * hp;
1274
1275hp = gethostbyaddr_r(address, length, type, &h,
1276 buffer, 8192, &h_errnop);],[
1277 AC_MSG_RESULT(yes)
b9c60df0 1278 AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args] )
a1cec0e4
DS
1279 ac_cv_gethostbyaddr_args=7],[
1280 AC_MSG_RESULT(no)
1281 AC_MSG_CHECKING(if gethostbyaddr_r takes 8 arguments)
1282 AC_TRY_COMPILE([
1283#include <sys/types.h>
1284#include <netdb.h>],[
1285char * address;
1286int length;
1287int type;
1288struct hostent h;
1289char buffer[8192];
1290int h_errnop;
1291struct hostent * hp;
1292int rc;
1293
1294rc = gethostbyaddr_r(address, length, type, &h,
1295 buffer, 8192, &hp, &h_errnop);],[
1296 AC_MSG_RESULT(yes)
b9c60df0 1297 AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
a1cec0e4
DS
1298 ac_cv_gethostbyaddr_args=8],[
1299 AC_MSG_RESULT(no)
1300 have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"])])])])])
a1cec0e4
DS
1301])
1302
4c70c3e8 1303AC_DEFUN([CURL_CHECK_GETHOSTBYNAME_R],
a1cec0e4
DS
1304[
1305 dnl check for number of arguments to gethostbyname_r. it might take
1306 dnl either 3, 5, or 6 arguments.
1307 AC_CHECK_FUNCS(gethostbyname_r,[
c3363f83
DS
1308 AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
1309 AC_TRY_COMPILE([
a1cec0e4
DS
1310#include <string.h>
1311#include <sys/types.h>
1312#include <netdb.h>
6ebac3dc
DS
1313#undef NULL
1314#define NULL (void *)0
a1cec0e4
DS
1315
1316int
c3363f83 1317gethostbyname_r(const char *, struct hostent *, struct hostent_data *);],[
325391ae 1318struct hostent_data data;
c3363f83 1319gethostbyname_r(NULL, NULL, NULL);],[
a1cec0e4 1320 AC_MSG_RESULT(yes)
b9c60df0 1321 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
a1cec0e4
DS
1322 ac_cv_gethostbyname_args=3],[
1323 AC_MSG_RESULT(no)
c3363f83
DS
1324 AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
1325 AC_TRY_COMPILE([
a1cec0e4
DS
1326#define _REENTRANT
1327
1328#include <string.h>
1329#include <sys/types.h>
1330#include <netdb.h>
6ebac3dc
DS
1331#undef NULL
1332#define NULL (void *)0
a1cec0e4
DS
1333
1334int
c3363f83 1335gethostbyname_r(const char *,struct hostent *, struct hostent_data *);],[
325391ae 1336struct hostent_data data;
c3363f83 1337gethostbyname_r(NULL, NULL, NULL);],[
a1cec0e4 1338 AC_MSG_RESULT(yes)
b9c60df0
DS
1339 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
1340 AC_DEFINE(NEED_REENTRANT, 1, [needs REENTRANT])
a1cec0e4
DS
1341 ac_cv_gethostbyname_args=3],[
1342 AC_MSG_RESULT(no)
c3363f83
DS
1343 AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
1344 AC_TRY_COMPILE([
a1cec0e4
DS
1345#include <sys/types.h>
1346#include <netdb.h>
6ebac3dc
DS
1347#undef NULL
1348#define NULL (void *)0
a1cec0e4 1349
c3363f83
DS
1350struct hostent *
1351gethostbyname_r(const char *, struct hostent *, char *, int, int *);],[
1352gethostbyname_r(NULL, NULL, NULL, 0, NULL);],[
a1cec0e4 1353 AC_MSG_RESULT(yes)
b9c60df0 1354 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
a1cec0e4
DS
1355 ac_cv_gethostbyname_args=5],[
1356 AC_MSG_RESULT(no)
c3363f83
DS
1357 AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
1358 AC_TRY_COMPILE([
a1cec0e4
DS
1359#include <sys/types.h>
1360#include <netdb.h>
6ebac3dc
DS
1361#undef NULL
1362#define NULL (void *)0
a1cec0e4
DS
1363
1364int
c3363f83
DS
1365gethostbyname_r(const char *, struct hostent *, char *, size_t,
1366struct hostent **, int *);],[
1367gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);],[
a1cec0e4 1368 AC_MSG_RESULT(yes)
b9c60df0 1369 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
a1cec0e4
DS
1370 ac_cv_gethostbyname_args=6],[
1371 AC_MSG_RESULT(no)
1372 have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"],
1373 [ac_cv_gethostbyname_args=0])],
1374 [ac_cv_gethostbyname_args=0])],
1375 [ac_cv_gethostbyname_args=0])],
1376 [ac_cv_gethostbyname_args=0])])
1377
1378if test "$ac_cv_func_gethostbyname_r" = "yes"; then
1379 if test "$ac_cv_gethostbyname_args" = "0"; then
1380 dnl there's a gethostbyname_r() function, but we don't know how
1381 dnl many arguments it wants!
1382 AC_MSG_ERROR([couldn't figure out how to use gethostbyname_r()])
1383 fi
1384fi
1385])
4fa58560 1386
2645782f 1387
2df622fd
DS
1388dnl **********************************************************************
1389dnl CURL_DETECT_ICC ([ACTION-IF-YES])
1390dnl
1391dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
1392dnl sets the $ICC variable to "yes" or "no"
1393dnl **********************************************************************
1394AC_DEFUN([CURL_DETECT_ICC],
1395[
1396 ICC="no"
1397 AC_MSG_CHECKING([for icc in use])
1398 if test "$GCC" = "yes"; then
1399 dnl check if this is icc acting as gcc in disguise
1400 AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
1401 dnl action if the text is found, this it has not been replaced by the
1402 dnl cpp
1403 ICC="no",
1404 dnl the text was not found, it was replaced by the cpp
1405 ICC="yes"
1406 AC_MSG_RESULT([yes])
1407 [$1]
1408 )
1409 fi
1410 if test "$ICC" = "no"; then
1411 # this is not ICC
1412 AC_MSG_RESULT([no])
1413 fi
1414])
1415
4fa58560
DS
1416dnl We create a function for detecting which compiler we use and then set as
1417dnl pendantic compiler options as possible for that particular compiler. The
1418dnl options are only used for debug-builds.
1419
1420AC_DEFUN([CURL_CC_DEBUG_OPTS],
1421[
2df622fd
DS
1422 if test "z$ICC" = "z"; then
1423 CURL_DETECT_ICC
1424 fi
1425
4fa58560
DS
1426 if test "$GCC" = "yes"; then
1427
1428 dnl figure out gcc version!
1429 AC_MSG_CHECKING([gcc version])
1430 gccver=`$CC -dumpversion`
1431 num1=`echo $gccver | cut -d . -f1`
1432 num2=`echo $gccver | cut -d . -f2`
1433 gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
1434 AC_MSG_RESULT($gccver)
1435
4fa58560
DS
1436 if test "$ICC" = "yes"; then
1437 dnl this is icc, not gcc.
6bd2de0c 1438
85af357d 1439 dnl ICC warnings we ignore:
85af357d
DS
1440 dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
1441 dnl "invalid format string conversion"
78e0ba82
DS
1442 dnl * 279 warns on static conditions in while expressions
1443 dnl * 981 warns on "operands are evaluated in unspecified order"
bde6c668 1444 dnl * 1418 "external definition with no prior declaration"
7e6043f0
DS
1445 dnl * 1419 warns on "external declaration in primary source file"
1446 dnl which we know and do on purpose.
6bd2de0c 1447
55c015c1 1448 WARN="-wd279,269,981,1418,1419"
6bd2de0c
DS
1449
1450 if test "$gccnum" -gt "600"; then
85af357d 1451 dnl icc 6.0 and older doesn't have the -Wall flag
6bd2de0c
DS
1452 WARN="-Wall $WARN"
1453 fi
4fa58560 1454 else dnl $ICC = yes
6789dfc5 1455 dnl this is a set of options we believe *ALL* gcc versions support:
38181fbc 1456 WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
4fa58560 1457
6789dfc5
DS
1458 dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
1459
38181fbc 1460 if test "$gccnum" -ge "207"; then
0e591829
DF
1461 dnl gcc 2.7 or later
1462 WARN="$WARN -Wmissing-declarations"
38181fbc
DF
1463 fi
1464
6789dfc5
DS
1465 if test "$gccnum" -gt "295"; then
1466 dnl only if the compiler is newer than 2.95 since we got lots of
1467 dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
1468 dnl gcc 2.95.4 on FreeBSD 4.9!
0e591829 1469 WARN="$WARN -Wundef -Wno-long-long -Wsign-compare"
6789dfc5 1470 fi
4fa58560
DS
1471
1472 if test "$gccnum" -ge "296"; then
1473 dnl gcc 2.96 or later
1474 WARN="$WARN -Wfloat-equal"
6789dfc5
DS
1475 fi
1476
1477 if test "$gccnum" -gt "296"; then
1478 dnl this option does not exist in 2.96
1479 WARN="$WARN -Wno-format-nonliteral"
1480 fi
4fa58560 1481
6789dfc5 1482 dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
c7b7bf32
DS
1483 dnl on i686-Linux as it gives us heaps with false positives.
1484 dnl Also, on gcc 4.0.X it is totally unbearable and complains all
1485 dnl over making it unusable for generic purposes. Let's not use it.
1486
6789dfc5
DS
1487 if test "$gccnum" -ge "303"; then
1488 dnl gcc 3.3 and later
1489 WARN="$WARN -Wendif-labels -Wstrict-prototypes"
4fa58560
DS
1490 fi
1491
aae521d0 1492 if test "$gccnum" -ge "304"; then
e81d4ac8 1493 # try these on gcc 3.4
c7b7bf32 1494 WARN="$WARN -Wdeclaration-after-statement"
aae521d0
DS
1495 fi
1496
4fa58560
DS
1497 for flag in $CPPFLAGS; do
1498 case "$flag" in
1499 -I*)
6789dfc5
DS
1500 dnl Include path, provide a -isystem option for the same dir
1501 dnl to prevent warnings in those dirs. The -isystem was not very
1502 dnl reliable on earlier gcc versions.
4fa58560 1503 add=`echo $flag | sed 's/^-I/-isystem /g'`
6bd2de0c 1504 WARN="$WARN $add"
4fa58560
DS
1505 ;;
1506 esac
1507 done
1508
4fa58560
DS
1509 fi dnl $ICC = no
1510
6bd2de0c
DS
1511 CFLAGS="$CFLAGS $WARN"
1512
193a652e
DS
1513 AC_MSG_NOTICE([Added this set of compiler options: $WARN])
1514
1515 else dnl $GCC = yes
1516
1517 AC_MSG_NOTICE([Added no extra compiler options])
1518
4fa58560
DS
1519 fi dnl $GCC = yes
1520
1521 dnl strip off optimizer flags
1522 NEWFLAGS=""
1523 for flag in $CFLAGS; do
1524 case "$flag" in
1525 -O*)
1526 dnl echo "cut off $flag"
1527 ;;
1528 *)
1529 NEWFLAGS="$NEWFLAGS $flag"
1530 ;;
1531 esac
1532 done
1533 CFLAGS=$NEWFLAGS
1534
1535]) dnl end of AC_DEFUN()
1536
205f8b26
DF
1537
1538dnl Determine the name of the library to pass to dlopen() based on the name
1539dnl that would normally be given to AC_CHECK_LIB. The preprocessor symbol
1540dnl given is set to the quoted library file name.
1541dnl The standard dynamic library file name is first generated, based on the
1542dnl current system type, then a search is performed for that file on the
1543dnl standard dynamic library path. If it is a symbolic link, the destination
1544dnl of the link is used as the file name, after stripping off any minor
1545dnl version numbers. If a library file can't be found, a guess is made.
1546dnl This macro assumes AC_PROG_LIBTOOL has been called and requires perl
228e6274 1547dnl to be available in the PATH, or $PERL to be set to its location.
205f8b26
DF
1548dnl
1549dnl CURL_DLLIB_NAME(VARIABLE, library_name)
1550dnl e.g. CURL_DLLIB_NAME(LDAP_NAME, ldap) on a Linux system might result
1551dnl in LDAP_NAME holding the string "libldap.so.2".
1552
1553AC_DEFUN([CURL_DLLIB_NAME],
1554[
1555AC_MSG_CHECKING([name of dynamic library $2])
1f68fa19
DF
1556dnl The shared library extension variable name changes from version to
1557dnl version of libtool. Try a few names then just set one statically.
b5112096 1558test -z "$shared_ext" && shared_ext="$shrext_cmds"
1f68fa19
DF
1559test -z "$shared_ext" && shared_ext="$shrext"
1560test -z "$shared_ext" && shared_ext=".so"
205f8b26 1561
1f68fa19 1562dnl Create the library link name of the correct form for this platform
228e6274 1563LIBNAME_LINK_SPEC=`echo "$library_names_spec" | $SED 's/^.* //'`
205f8b26 1564DLGUESSLIB=`name=$2 eval echo "$libname_spec"`
228e6274 1565DLGUESSFILE=`libname="$DLGUESSLIB" release="" major="" versuffix="" eval echo "$LIBNAME_LINK_SPEC"`
205f8b26 1566
1f68fa19
DF
1567dnl Synthesize a likely dynamic library name in case we can't find an actual one
1568SO_NAME_SPEC="$soname_spec"
1569dnl soname_spec undefined when identical to the 1st entry in library_names_spec
1570test -z "$SO_NAME_SPEC" && SO_NAME_SPEC=`echo "$library_names_spec" | $SED 's/ .*$//'`
1571DLGUESSSOFILE=`libname="$DLGUESSLIB" release="" major="" versuffix="" eval echo "$SO_NAME_SPEC"`
1572
205f8b26
DF
1573if test "$cross_compiling" = yes; then
1574 dnl Can't look at filesystem when cross-compiling
1f68fa19
DF
1575 AC_DEFINE_UNQUOTED($1, "$DLGUESSSOFILE", [$2 dynamic library file])
1576 AC_MSG_RESULT([$DLGUESSSOFILE (guess while cross-compiling)])
205f8b26
DF
1577else
1578
1579 DLFOUNDFILE=""
1580 if test "$sys_lib_dlsearch_path_spec" ; then
228e6274 1581 dnl Search for the link library name and see what it points to.
205f8b26
DF
1582 for direc in $sys_lib_dlsearch_path_spec ; do
1583 DLTRYFILE="$direc/$DLGUESSFILE"
1584 dnl Find where the symbolic link for this name points
1585 changequote(<<, >>)dnl
1586 <<
228e6274 1587 DLFOUNDFILE=`${PERL:-perl} -e 'use File::Basename; (basename(readlink($ARGV[0])) =~ /^(.*[^\d]\.\d+)[\d\.]*$/ && print ${1}) || exit 1;' "$DLTRYFILE" 2>&5`
205f8b26
DF
1588 >>
1589 changequote([, ])dnl
1590 if test "$?" -eq "0"; then
1591 dnl Found the file link
1592 break
1593 fi
1594 done
1595 fi
1596
1597 if test -z "$DLFOUNDFILE" ; then
1f68fa19
DF
1598 dnl Couldn't find a link library, so guess at a name.
1599 DLFOUNDFILE="$DLGUESSSOFILE"
205f8b26
DF
1600 fi
1601
1602 AC_DEFINE_UNQUOTED($1, "$DLFOUNDFILE", [$2 dynamic library file])
1603 AC_MSG_RESULT($DLFOUNDFILE)
1604fi
1605])
65afc576
DS
1606
1607# This is only a temporary fix. This macro is here to replace the broken one
1608# delivered by the automake project (including the 1.9.6 release). As soon as
1609# they ship a working version we SHOULD remove this work-around.
1610
1611AC_DEFUN([AM_MISSING_HAS_RUN],
1612[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
1613test x"${MISSING+set}" = xset || MISSING="\${SHELL} \"$am_aux_dir/missing\""
1614# Use eval to expand $SHELL
1615if eval "$MISSING --run true"; then
1616 am_missing_run="$MISSING --run "
1617else
1618 am_missing_run=
1619 AC_MSG_WARN([`missing' script is too old or missing])
1620fi
1621])