Remove experimental notice from CURL_CHECK_FUNC_GETNAMEINFO
[platform/upstream/curl.git] / acinclude.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2006, 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 dnl CURL_CHECK_HEADER_WINDOWS
25 dnl -------------------------------------------------
26 dnl Check for compilable and valid windows.h header 
27
28 AC_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([
32 #undef inline
33 #ifndef WIN32_LEAN_AND_MEAN
34 #define WIN32_LEAN_AND_MEAN
35 #endif
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
47     AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
48       [Define to 1 if you have the windows.h header file.])
49     AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
50       [Define to avoid automatic inclusion of winsock.h])
51   fi
52 ])
53
54
55 dnl CURL_CHECK_HEADER_WINSOCK
56 dnl -------------------------------------------------
57 dnl Check for compilable and valid winsock.h header 
58
59 AC_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([
64 #undef inline
65 #ifndef WIN32_LEAN_AND_MEAN
66 #define WIN32_LEAN_AND_MEAN
67 #endif
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
80     AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
81       [Define to 1 if you have the winsock.h header file.])
82   fi
83 ])
84
85
86 dnl CURL_CHECK_HEADER_WINSOCK2
87 dnl -------------------------------------------------
88 dnl Check for compilable and valid winsock2.h header 
89
90 AC_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([
95 #undef inline
96 #ifndef WIN32_LEAN_AND_MEAN
97 #define WIN32_LEAN_AND_MEAN
98 #endif
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
111     AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
112       [Define to 1 if you have the winsock2.h header file.])
113   fi
114 ])
115
116
117 dnl CURL_CHECK_HEADER_WS2TCPIP
118 dnl -------------------------------------------------
119 dnl Check for compilable and valid ws2tcpip.h header
120
121 AC_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([
126 #undef inline
127 #ifndef WIN32_LEAN_AND_MEAN
128 #define WIN32_LEAN_AND_MEAN
129 #endif
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
143     AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
144       [Define to 1 if you have the ws2tcpip.h header file.])
145   fi
146 ])
147
148
149 dnl CURL_CHECK_TYPE_SOCKLEN_T
150 dnl -------------------------------------------------
151 dnl Check for existing socklen_t type, and provide
152 dnl an equivalent type if socklen_t not available
153
154 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
155   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
156   AC_CHECK_TYPE([socklen_t], ,[
157     AC_CACHE_CHECK([for socklen_t equivalent], 
158       [curl_cv_socklen_t_equiv], [
159       curl_cv_socklen_t_equiv="unknown"
160       for arg2 in "struct sockaddr" void; do
161         for t in int size_t unsigned long "unsigned long"; do
162           AC_COMPILE_IFELSE([
163             AC_LANG_PROGRAM([
164 #undef inline
165 #ifdef HAVE_WINDOWS_H
166 #ifndef WIN32_LEAN_AND_MEAN
167 #define WIN32_LEAN_AND_MEAN
168 #endif
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 *);
186             ],[
187               $t len=0;
188               getpeername(0,0,&len);
189             ])
190           ],[
191              curl_cv_socklen_t_equiv="$t"
192              break 2
193           ])
194         done
195       done
196     ])
197     if test "$curl_cv_socklen_t_equiv" = "unknown"; then
198       AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
199     else
200       AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
201         [type to use in place of socklen_t if not defined])
202     fi
203   ],[
204 #undef inline
205 #ifdef HAVE_WINDOWS_H
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>
212 #ifdef HAVE_WS2TCPIP_H
213 #include <ws2tcpip.h>
214 #endif
215 #endif
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
228 dnl CURL_CHECK_FUNC_GETNAMEINFO
229 dnl -------------------------------------------------
230 dnl Test if the getnameinfo function is available, 
231 dnl and check the types of five of its arguments.
232 dnl If the function succeeds HAVE_GETNAMEINFO will be
233 dnl defined, defining the types of the arguments in
234 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
235 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7.
236
237 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
238   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
239   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
240   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
241   #
242   AC_MSG_CHECKING([for getnameinfo])
243   AC_LINK_IFELSE([
244       AC_LANG_FUNC_LINK_TRY([getnameinfo])
245     ],[
246       AC_MSG_RESULT([yes])
247       curl_cv_getnameinfo="yes"
248     ],[
249       AC_MSG_RESULT([no])
250       curl_cv_getnameinfo="no"
251   ])
252   #
253   if test "$curl_cv_getnameinfo" != "yes"; then
254     AC_MSG_CHECKING([deeper for getnameinfo])
255     AC_TRY_LINK([
256       ],[
257         getnameinfo();
258       ],[
259         AC_MSG_RESULT([yes])
260         curl_cv_getnameinfo="yes"
261       ],[
262         AC_MSG_RESULT([but still no])
263         curl_cv_getnameinfo="no"
264     ])
265   fi
266   #
267   if test "$curl_cv_getnameinfo" != "yes"; then
268     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
269     AC_TRY_LINK([
270 #undef inline
271 #ifdef HAVE_WINDOWS_H
272 #ifndef WIN32_LEAN_AND_MEAN
273 #define WIN32_LEAN_AND_MEAN
274 #endif
275 #include <windows.h>
276 #ifdef HAVE_WINSOCK2_H
277 #include <winsock2.h>
278 #ifdef HAVE_WS2TCPIP_H
279 #include <ws2tcpip.h>
280 #endif
281 #endif
282 #else
283 #ifdef HAVE_SYS_TYPES_H
284 #include <sys/types.h>
285 #endif
286 #ifdef HAVE_SYS_SOCKET_H
287 #include <sys/socket.h>
288 #endif
289 #ifdef HAVE_NETDB_H
290 #include <netdb.h>
291 #endif
292 #endif
293       ],[
294         getnameinfo(0, 0, 0, 0, 0, 0, 0);
295       ],[ 
296         AC_MSG_RESULT([yes])
297         curl_cv_getnameinfo="yes"
298       ],[
299         AC_MSG_RESULT([but still no])
300         curl_cv_getnameinfo="no"
301     ])
302   fi
303   #
304   if test "$curl_cv_getnameinfo" = "yes"; then
305     AC_CACHE_CHECK([types of arguments for getnameinfo],
306       [curl_cv_func_getnameinfo_args], [
307       curl_cv_func_getnameinfo_args="unknown"
308       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
309         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
310           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
311             for gni_arg7 in 'int' 'unsigned int'; do
312               AC_COMPILE_IFELSE([
313                 AC_LANG_PROGRAM([
314 #undef inline 
315 #ifdef HAVE_WINDOWS_H
316 #ifndef WIN32_LEAN_AND_MEAN
317 #define WIN32_LEAN_AND_MEAN
318 #endif
319 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
320 #undef _WIN32_WINNT
321 #define _WIN32_WINNT 0x0501
322 #endif
323 #include <windows.h>
324 #ifdef HAVE_WINSOCK2_H
325 #include <winsock2.h> 
326 #ifdef HAVE_WS2TCPIP_H
327 #include <ws2tcpip.h>
328 #endif
329 #endif
330 #define GNICALLCONV WSAAPI
331 #else
332 #ifdef HAVE_SYS_TYPES_H
333 #include <sys/types.h>
334 #endif
335 #ifdef HAVE_SYS_SOCKET_H
336 #include <sys/socket.h>
337 #endif
338 #ifdef HAVE_NETDB_H
339 #include <netdb.h>
340 #endif
341 #define GNICALLCONV
342 #endif
343                   extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
344                                          char *, $gni_arg46,
345                                          char *, $gni_arg46,
346                                          $gni_arg7);
347                 ],[
348                   $gni_arg2 salen=0;
349                   $gni_arg46 hostlen=0;
350                   $gni_arg46 servlen=0;
351                   $gni_arg7 flags=0;
352                   int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
353                 ])
354               ],[
355                  curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
356                  break 4
357               ])
358             done
359           done
360         done
361       done
362     ]) # AC_CACHE_CHECK
363     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
364       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
365       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
366     else
367       gni_prev_IFS=$IFS; IFS=','
368       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
369       IFS=$gni_prev_IFS
370       shift
371       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $[1],
372         [Define to the type of arg 1 for getnameinfo.])
373       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
374         [Define to the type of arg 2 for getnameinfo.])
375       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
376         [Define to the type of args 4 and 6 for getnameinfo.])
377       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
378         [Define to the type of arg 7 for getnameinfo.])
379       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
380         [Define to 1 if you have the getnameinfo function.])
381       ac_cv_func_getnameinfo="yes"
382     fi
383   fi
384 ]) # AC_DEFUN
385
386
387 dnl CURL_CHECK_NONBLOCKING_SOCKET
388 dnl -------------------------------------------------
389 dnl Check for how to set a socket to non-blocking state. There seems to exist
390 dnl four known different ways, with the one used almost everywhere being POSIX
391 dnl and XPG3, while the other different ways for different systems (old BSD,
392 dnl Windows and Amiga).
393 dnl
394 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
395 dnl O_NONBLOCK define is found but does not work. This condition is attempted
396 dnl to get caught in this script by using an excessive number of #ifdefs...
397 dnl
398 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
399 [
400   AC_MSG_CHECKING([non-blocking sockets style])
401
402   AC_TRY_COMPILE([
403 /* headers for O_NONBLOCK test */
404 #include <sys/types.h>
405 #include <unistd.h>
406 #include <fcntl.h>
407 ],[
408 /* try to compile O_NONBLOCK */
409
410 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
411 # if defined(__SVR4) || defined(__srv4__)
412 #  define PLATFORM_SOLARIS
413 # else
414 #  define PLATFORM_SUNOS4
415 # endif
416 #endif
417 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
418 # define PLATFORM_AIX_V3
419 #endif
420
421 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
422 #error "O_NONBLOCK does not work on this platform"
423 #endif
424   int socket;
425   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
426 ],[
427 dnl the O_NONBLOCK test was fine
428 nonblock="O_NONBLOCK"
429 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
430 ],[
431 dnl the code was bad, try a different program now, test 2
432
433   AC_TRY_COMPILE([
434 /* headers for FIONBIO test */
435 #include <unistd.h>
436 #include <stropts.h>
437 ],[
438 /* FIONBIO source test (old-style unix) */
439  int socket;
440  int flags = ioctl(socket, FIONBIO, &flags);
441 ],[
442 dnl FIONBIO test was good
443 nonblock="FIONBIO"
444 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
445 ],[
446 dnl FIONBIO test was also bad
447 dnl the code was bad, try a different program now, test 3
448
449   AC_TRY_COMPILE([
450 /* headers for ioctlsocket test (Windows) */
451 #undef inline
452 #ifdef HAVE_WINDOWS_H
453 #ifndef WIN32_LEAN_AND_MEAN
454 #define WIN32_LEAN_AND_MEAN
455 #endif
456 #include <windows.h>
457 #ifdef HAVE_WINSOCK2_H
458 #include <winsock2.h>
459 #else
460 #ifdef HAVE_WINSOCK_H
461 #include <winsock.h>
462 #endif
463 #endif
464 #endif
465 ],[
466 /* ioctlsocket source code */
467  SOCKET sd;
468  unsigned long flags = 0;
469  sd = socket(0, 0, 0);
470  ioctlsocket(sd, FIONBIO, &flags);
471 ],[
472 dnl ioctlsocket test was good
473 nonblock="ioctlsocket"
474 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
475 ],[
476 dnl ioctlsocket didnt compile!, go to test 4
477
478   AC_TRY_LINK([
479 /* headers for IoctlSocket test (Amiga?) */
480 #include <sys/ioctl.h>
481 ],[
482 /* IoctlSocket source code */
483  int socket;
484  int flags = IoctlSocket(socket, FIONBIO, (long)1);
485 ],[
486 dnl ioctlsocket test was good
487 nonblock="IoctlSocket"
488 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
489 ],[
490 dnl Ioctlsocket didnt compile, do test 5!
491   AC_TRY_COMPILE([
492 /* headers for SO_NONBLOCK test (BeOS) */
493 #include <socket.h>
494 ],[
495 /* SO_NONBLOCK source code */
496  long b = 1;
497  int socket;
498  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
499 ],[
500 dnl the SO_NONBLOCK test was good
501 nonblock="SO_NONBLOCK"
502 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
503 ],[
504 dnl test 5 didnt compile!
505 nonblock="nada"
506 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
507 ])
508 dnl end of fifth test
509
510 ])
511 dnl end of forth test
512
513 ])
514 dnl end of third test
515
516 ])
517 dnl end of second test
518
519 ])
520 dnl end of non-blocking try-compile test
521   AC_MSG_RESULT($nonblock)
522
523   if test "$nonblock" = "nada"; then
524     AC_MSG_WARN([non-block sockets disabled])
525   fi
526 ])
527
528
529 dnl TYPE_SOCKADDR_STORAGE
530 dnl -------------------------------------------------
531 dnl Check for struct sockaddr_storage. Most IPv6-enabled hosts have it, but
532 dnl AIX 4.3 is one known exception.
533 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
534 [
535    AC_CHECK_TYPE([struct sockaddr_storage],
536         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
537                   [if struct sockaddr_storage is defined]), ,
538    [
539 #undef inline
540 #ifdef HAVE_WINDOWS_H
541 #ifndef WIN32_LEAN_AND_MEAN
542 #define WIN32_LEAN_AND_MEAN
543 #endif
544 #include <windows.h>
545 #ifdef HAVE_WINSOCK2_H
546 #include <winsock2.h>
547 #endif
548 #else
549 #ifdef HAVE_SYS_TYPES_H
550 #include <sys/types.h>
551 #endif
552 #ifdef HAVE_SYS_SOCKET_H
553 #include <sys/socket.h>
554 #endif
555 #ifdef HAVE_NETINET_IN_H
556 #include <netinet/in.h>
557 #endif
558 #ifdef HAVE_ARPA_INET_H
559 #include <arpa/inet.h>
560 #endif
561 #endif
562    ])
563 ])
564
565
566 dnl TYPE_IN_ADDR_T
567 dnl -------------------------------------------------
568 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
569 dnl and a few other things.
570 AC_DEFUN([TYPE_IN_ADDR_T],
571 [
572    AC_CHECK_TYPE([in_addr_t], ,[
573       AC_MSG_CHECKING([for in_addr_t equivalent])
574       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
575       [
576          curl_cv_in_addr_t_equiv=
577          for t in "unsigned long" int size_t unsigned long; do
578             AC_TRY_COMPILE([
579 #undef inline
580 #ifdef HAVE_WINDOWS_H
581 #ifndef WIN32_LEAN_AND_MEAN
582 #define WIN32_LEAN_AND_MEAN
583 #endif
584 #include <windows.h>
585 #ifdef HAVE_WINSOCK2_H
586 #include <winsock2.h>
587 #else
588 #ifdef HAVE_WINSOCK_H
589 #include <winsock.h>
590 #endif
591 #endif
592 #else
593 #ifdef HAVE_SYS_TYPES_H
594 #include <sys/types.h>
595 #endif
596 #ifdef HAVE_SYS_SOCKET_H
597 #include <sys/socket.h>
598 #endif
599 #ifdef HAVE_NETINET_IN_H
600 #include <netinet/in.h>
601 #endif
602 #ifdef HAVE_ARPA_INET_H
603 #include <arpa/inet.h>
604 #endif
605 #endif
606             ],[
607                $t data = inet_addr ("1.2.3.4");
608             ],[
609                curl_cv_in_addr_t_equiv="$t"
610                break
611             ])
612          done
613
614          if test "x$curl_cv_in_addr_t_equiv" = x; then
615             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
616          fi
617       ])
618       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
619       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
620                         [type to use in place of in_addr_t if not defined])],
621       [
622 #undef inline
623 #ifdef HAVE_WINDOWS_H
624 #ifndef WIN32_LEAN_AND_MEAN
625 #define WIN32_LEAN_AND_MEAN
626 #endif
627 #include <windows.h>
628 #ifdef HAVE_WINSOCK2_H
629 #include <winsock2.h>
630 #else
631 #ifdef HAVE_WINSOCK_H
632 #include <winsock.h>
633 #endif
634 #endif
635 #else
636 #ifdef HAVE_SYS_TYPES_H
637 #include <sys/types.h>
638 #endif
639 #ifdef HAVE_SYS_SOCKET_H
640 #include <sys/socket.h>
641 #endif
642 #ifdef HAVE_NETINET_IN_H
643 #include <netinet/in.h>
644 #endif
645 #ifdef HAVE_ARPA_INET_H
646 #include <arpa/inet.h>
647 #endif
648 #endif
649   ]) dnl AC_CHECK_TYPE
650 ]) dnl AC_DEFUN
651
652 dnl ************************************************************
653 dnl check for "localhost", if it doesn't exist, we can't do the
654 dnl gethostbyname_r tests!
655 dnl 
656
657 AC_DEFUN([CURL_CHECK_WORKING_RESOLVER],[
658 AC_MSG_CHECKING([if "localhost" resolves])
659 AC_TRY_RUN([
660 #include <string.h>
661 #include <sys/types.h>
662 #include <netdb.h>
663
664 int
665 main () {
666 struct hostent *h;
667 h = gethostbyname("localhost");
668 exit (h == NULL ? 1 : 0); }],[
669       AC_MSG_RESULT(yes)],[
670       AC_MSG_RESULT(no)
671       AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
672
673       ]
674 )
675 ])
676
677 dnl ************************************************************
678 dnl check for working getaddrinfo() that works with AI_NUMERICHOST
679 dnl
680 AC_DEFUN([CURL_CHECK_WORKING_GETADDRINFO],[
681   AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
682   AC_TRY_RUN( [
683 #include <netdb.h>
684 #include <sys/types.h>
685 #include <sys/socket.h>
686
687 int main(void)
688 {
689     struct addrinfo hints, *ai;
690     int error;
691
692     memset(&hints, 0, sizeof(hints));
693     hints.ai_flags = AI_NUMERICHOST;
694     hints.ai_family = AF_UNSPEC;
695     hints.ai_socktype = SOCK_STREAM;
696     error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
697     if (error) {
698         return 1;
699     }
700     return 0;
701 }
702 ],[
703   ac_cv_working_getaddrinfo="yes"
704 ],[
705   ac_cv_working_getaddrinfo="no"
706 ],[
707   ac_cv_working_getaddrinfo="yes"
708 ])])
709 if test "$ac_cv_working_getaddrinfo" = "yes"; then
710   AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
711   AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
712
713   IPV6_ENABLED=1
714   AC_SUBST(IPV6_ENABLED)
715 fi
716 ])
717
718 dnl ************************************************************
719 dnl check for working NI_WITHSCOPEID in getnameinfo()
720 dnl
721 AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID],[
722   AC_CACHE_CHECK(for working NI_WITHSCOPEID, ac_cv_working_ni_withscopeid,[
723
724  AC_RUN_IFELSE([[
725 #include <stdio.h>
726 #include <sys/types.h>
727 #include <sys/socket.h>
728 #include <netdb.h>
729 int main()
730 {
731 #ifdef NI_WITHSCOPEID
732    struct sockaddr_storage ss;
733    int sslen = sizeof(ss);
734    int rc;
735    char hbuf[NI_MAXHOST];
736    int fd = socket(AF_INET6, SOCK_STREAM, 0);
737    if(fd < 0) {
738      perror("socket()");
739      return 1; /* couldn't create socket of either kind */
740    }
741
742    rc = getsockname(fd, (struct sockaddr *)&ss, &sslen);
743    if(rc) {
744      perror("getsockname()");
745      return 2;
746    }
747
748    rc = getnameinfo((struct sockaddr *)&ss, sslen, hbuf, sizeof(hbuf),
749                      NULL, 0,
750                      NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID);
751
752    if(rc) {
753      printf("rc = %s\n", gai_strerror(rc));
754      return 3;
755    }
756
757    return 0; /* everything works fine, use NI_WITHSCOPEID! */
758 #else
759    return 4; /* we don't seem to have the definition, don't use it */
760 #endif
761 }
762 ]],
763 dnl program worked:
764 [ ac_cv_working_ni_withscopeid="yes" ],
765 dnl program failed:
766 [ ac_cv_working_ni_withscopeid="no" ],
767 dnl we cross-compile, check the headers using the preprocessor
768 [
769
770  AC_EGREP_CPP(WORKS,
771 [
772 #include <stdio.h>
773 #include <sys/types.h>
774 #include <sys/socket.h>
775 #include <netdb.h>
776
777 #ifdef NI_WITHSCOPEID
778 WORKS
779 #endif
780 ],
781   ac_cv_working_ni_withscopeid="yes",
782   ac_cv_working_ni_withscopeid="no" )
783
784  ]
785 ) dnl end of AC_RUN_IFELSE
786
787 ]) dnl end of AC_CACHE_CHECK
788
789 if test "$ac_cv_working_ni_withscopeid" = "yes"; then
790   AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
791             [Define if NI_WITHSCOPEID exists and works])
792 fi
793
794 ]) dnl end of AC_DEFUN
795
796
797 AC_DEFUN([CURL_CHECK_LOCALTIME_R],
798 [
799   dnl check for localtime_r
800   AC_CHECK_FUNCS(localtime_r,[
801     AC_MSG_CHECKING(whether localtime_r is declared)
802     AC_EGREP_CPP(localtime_r,[
803 #include <time.h>],[
804       AC_MSG_RESULT(yes)],[
805       AC_MSG_RESULT(no)
806       AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
807       AC_EGREP_CPP(localtime_r,[
808 #define _REENTRANT
809 #include <time.h>],[
810         AC_DEFINE(NEED_REENTRANT)
811         AC_MSG_RESULT(yes)],
812         AC_MSG_RESULT(no))])])
813 ])
814
815 dnl
816 dnl This function checks for strerror_r(). If it isn't found at first, it
817 dnl retries with _THREAD_SAFE defined, as that is what AIX seems to require
818 dnl in order to find this function.
819 dnl
820 dnl If the function is found, it will then proceed to check how the function
821 dnl actually works: glibc-style or POSIX-style.
822 dnl
823 dnl glibc:
824 dnl      char *strerror_r(int errnum, char *buf, size_t n);
825 dnl  
826 dnl  What this one does is to return the error string (no surprises there),
827 dnl  but it doesn't usually copy anything into buf!  The 'buf' and 'n'
828 dnl  parameters are only meant as an optional working area, in case strerror_r
829 dnl  needs it.  A quick test on a few systems shows that it's generally not
830 dnl  touched at all.
831 dnl
832 dnl POSIX:
833 dnl      int strerror_r(int errnum, char *buf, size_t n);
834 dnl
835 AC_DEFUN([CURL_CHECK_STRERROR_R],
836 [
837   AC_CHECK_FUNCS(strerror_r)
838
839   if test "x$ac_cv_func_strerror_r" = "xyes"; then
840
841     AC_MSG_CHECKING(whether strerror_r is declared)
842     AC_EGREP_CPP(strerror_r,[
843 #include <string.h>],[
844       AC_MSG_RESULT(yes)],[
845       AC_MSG_RESULT(no)
846       AC_MSG_CHECKING(whether strerror_r with -D_REENTRANT is declared)
847       AC_EGREP_CPP(strerror_r,[
848 #define _REENTRANT
849 #include <string.h>],[
850         CPPFLAGS="-D_REENTRANT $CPPFLAGS"
851         AC_MSG_RESULT(yes)],
852         AC_MSG_RESULT(no)
853         AC_DEFINE(HAVE_NO_STRERROR_R_DECL, 1, [we have no strerror_r() proto])
854        ) dnl with _THREAD_SAFE
855     ]) dnl plain cpp for it
856
857     dnl determine if this strerror_r() is glibc or POSIX
858     AC_MSG_CHECKING([for a glibc strerror_r API])
859     AC_TRY_RUN([
860 #include <string.h>
861 #include <errno.h>
862 int
863 main () {
864   char buffer[1024]; /* big enough to play with */
865   char *string =
866     strerror_r(EACCES, buffer, sizeof(buffer));
867     /* this should've returned a string */
868     if(!string || !string[0])
869       return 99;
870     return 0;
871 }
872 ],
873     GLIBC_STRERROR_R="1"
874     AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
875     AC_MSG_RESULT([yes]),
876     AC_MSG_RESULT([no]),
877
878     dnl Use an inferior method of strerror_r detection while cross-compiling
879     AC_EGREP_CPP(yes, [
880 #include <features.h>
881 #ifdef __GLIBC__
882 yes
883 #endif
884 ], 
885       dnl looks like glibc, so assume a glibc-style strerror_r()
886       GLIBC_STRERROR_R="1"
887       AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
888       AC_MSG_RESULT([yes]),
889       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
890     ) dnl while cross-compiling
891     )
892
893     if test -z "$GLIBC_STRERROR_R"; then
894
895       AC_MSG_CHECKING([for a POSIX strerror_r API])
896       AC_TRY_RUN([
897 #include <string.h>
898 #include <errno.h>
899 int
900 main () {
901   char buffer[1024]; /* big enough to play with */
902   int error =
903     strerror_r(EACCES, buffer, sizeof(buffer));
904     /* This should've returned zero, and written an error string in the
905        buffer.*/
906     if(!buffer[0] || error)
907       return 99;
908     return 0;
909 }
910 ],
911       AC_DEFINE(HAVE_POSIX_STRERROR_R, 1, [we have a POSIX-style strerror_r()])
912       AC_MSG_RESULT([yes]),
913       AC_MSG_RESULT([no]) ,
914       dnl cross-compiling!
915       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
916     )
917
918     fi dnl if not using glibc API
919
920   fi dnl we have a strerror_r
921
922 ])
923
924 AC_DEFUN([CURL_CHECK_INET_NTOA_R],
925 [
926   dnl determine if function definition for inet_ntoa_r exists.
927   AC_CHECK_FUNCS(inet_ntoa_r,[
928     AC_MSG_CHECKING(whether inet_ntoa_r is declared)
929     AC_EGREP_CPP(inet_ntoa_r,[
930 #include <arpa/inet.h>],[
931       AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
932       AC_MSG_RESULT(yes)],[
933       AC_MSG_RESULT(no)
934       AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
935       AC_EGREP_CPP(inet_ntoa_r,[
936 #define _REENTRANT
937 #include <arpa/inet.h>],[
938         AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
939         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
940         AC_MSG_RESULT(yes)],
941         AC_MSG_RESULT(no))])])
942 ])
943
944 AC_DEFUN([CURL_CHECK_GETHOSTBYADDR_R],
945 [
946   dnl check for number of arguments to gethostbyaddr_r. it might take
947   dnl either 5, 7, or 8 arguments.
948   AC_CHECK_FUNCS(gethostbyaddr_r,[
949     AC_MSG_CHECKING(if gethostbyaddr_r takes 5 arguments)
950     AC_TRY_COMPILE([
951 #include <sys/types.h>
952 #include <netdb.h>],[
953 char * address;
954 int length;
955 int type;
956 struct hostent h;
957 struct hostent_data hdata;
958 int rc;
959 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
960       AC_MSG_RESULT(yes)
961       AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
962       ac_cv_gethostbyaddr_args=5],[
963       AC_MSG_RESULT(no)
964       AC_MSG_CHECKING(if gethostbyaddr_r with -D_REENTRANT takes 5 arguments)
965       AC_TRY_COMPILE([
966 #define _REENTRANT
967 #include <sys/types.h>
968 #include <netdb.h>],[
969 char * address;
970 int length;
971 int type;
972 struct hostent h;
973 struct hostent_data hdata;
974 int rc;
975 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
976         AC_MSG_RESULT(yes)
977         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
978         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
979         ac_cv_gethostbyaddr_args=5],[
980         AC_MSG_RESULT(no)
981         AC_MSG_CHECKING(if gethostbyaddr_r takes 7 arguments)
982         AC_TRY_COMPILE([
983 #include <sys/types.h>
984 #include <netdb.h>],[
985 char * address;
986 int length;
987 int type;
988 struct hostent h;
989 char buffer[8192];
990 int h_errnop;
991 struct hostent * hp;
992
993 hp = gethostbyaddr_r(address, length, type, &h,
994                      buffer, 8192, &h_errnop);],[
995           AC_MSG_RESULT(yes)
996           AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args] )
997           ac_cv_gethostbyaddr_args=7],[
998           AC_MSG_RESULT(no)
999           AC_MSG_CHECKING(if gethostbyaddr_r takes 8 arguments)
1000           AC_TRY_COMPILE([
1001 #include <sys/types.h>
1002 #include <netdb.h>],[
1003 char * address;
1004 int length;
1005 int type;
1006 struct hostent h;
1007 char buffer[8192];
1008 int h_errnop;
1009 struct hostent * hp;
1010 int rc;
1011
1012 rc = gethostbyaddr_r(address, length, type, &h,
1013                      buffer, 8192, &hp, &h_errnop);],[
1014             AC_MSG_RESULT(yes)
1015             AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
1016             ac_cv_gethostbyaddr_args=8],[
1017             AC_MSG_RESULT(no)
1018             have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"])])])])])
1019 ])
1020
1021 AC_DEFUN([CURL_CHECK_GETHOSTBYNAME_R],
1022 [
1023   dnl check for number of arguments to gethostbyname_r. it might take
1024   dnl either 3, 5, or 6 arguments.
1025   AC_CHECK_FUNCS(gethostbyname_r,[
1026     AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
1027     AC_TRY_COMPILE([
1028 #include <string.h>
1029 #include <sys/types.h>
1030 #include <netdb.h>
1031 #undef NULL
1032 #define NULL (void *)0
1033
1034 int
1035 gethostbyname_r(const char *, struct hostent *, struct hostent_data *);],[
1036 struct hostent_data data;
1037 gethostbyname_r(NULL, NULL, NULL);],[
1038       AC_MSG_RESULT(yes)
1039       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
1040       ac_cv_gethostbyname_args=3],[
1041       AC_MSG_RESULT(no)
1042       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
1043       AC_TRY_COMPILE([
1044 #define _REENTRANT
1045
1046 #include <string.h>
1047 #include <sys/types.h>
1048 #include <netdb.h>
1049 #undef NULL
1050 #define NULL (void *)0
1051
1052 int
1053 gethostbyname_r(const char *,struct hostent *, struct hostent_data *);],[
1054 struct hostent_data data;
1055 gethostbyname_r(NULL, NULL, NULL);],[
1056         AC_MSG_RESULT(yes)
1057         AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
1058         AC_DEFINE(NEED_REENTRANT, 1, [needs REENTRANT])
1059         ac_cv_gethostbyname_args=3],[
1060         AC_MSG_RESULT(no)
1061         AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
1062         AC_TRY_COMPILE([
1063 #include <sys/types.h>
1064 #include <netdb.h>
1065 #undef NULL
1066 #define NULL (void *)0
1067
1068 struct hostent *
1069 gethostbyname_r(const char *, struct hostent *, char *, int, int *);],[
1070 gethostbyname_r(NULL, NULL, NULL, 0, NULL);],[
1071           AC_MSG_RESULT(yes)
1072           AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
1073           ac_cv_gethostbyname_args=5],[
1074           AC_MSG_RESULT(no)
1075           AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
1076           AC_TRY_COMPILE([
1077 #include <sys/types.h>
1078 #include <netdb.h>
1079 #undef NULL
1080 #define NULL (void *)0
1081
1082 int
1083 gethostbyname_r(const char *, struct hostent *, char *, size_t,
1084 struct hostent **, int *);],[
1085 gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);],[
1086             AC_MSG_RESULT(yes)
1087             AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
1088             ac_cv_gethostbyname_args=6],[
1089             AC_MSG_RESULT(no)
1090             have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"],
1091             [ac_cv_gethostbyname_args=0])],
1092           [ac_cv_gethostbyname_args=0])],
1093         [ac_cv_gethostbyname_args=0])],
1094       [ac_cv_gethostbyname_args=0])])
1095
1096 if test "$ac_cv_func_gethostbyname_r" = "yes"; then
1097   if test "$ac_cv_gethostbyname_args" = "0"; then
1098     dnl there's a gethostbyname_r() function, but we don't know how
1099     dnl many arguments it wants!
1100     AC_MSG_ERROR([couldn't figure out how to use gethostbyname_r()])
1101   fi
1102 fi
1103 ])
1104
1105
1106 dnl **********************************************************************
1107 dnl CURL_DETECT_ICC ([ACTION-IF-YES])
1108 dnl
1109 dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
1110 dnl sets the $ICC variable to "yes" or "no"
1111 dnl **********************************************************************
1112 AC_DEFUN([CURL_DETECT_ICC],
1113 [
1114     ICC="no"
1115     AC_MSG_CHECKING([for icc in use])
1116     if test "$GCC" = "yes"; then
1117        dnl check if this is icc acting as gcc in disguise
1118        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
1119          dnl action if the text is found, this it has not been replaced by the
1120          dnl cpp
1121          ICC="no",
1122          dnl the text was not found, it was replaced by the cpp
1123          ICC="yes"
1124          AC_MSG_RESULT([yes])
1125          [$1]
1126        )
1127     fi
1128     if test "$ICC" = "no"; then
1129         # this is not ICC
1130         AC_MSG_RESULT([no])
1131     fi
1132 ])
1133
1134 dnl We create a function for detecting which compiler we use and then set as
1135 dnl pendantic compiler options as possible for that particular compiler. The
1136 dnl options are only used for debug-builds.
1137
1138 AC_DEFUN([CURL_CC_DEBUG_OPTS],
1139 [
1140     if test "z$ICC" = "z"; then
1141       CURL_DETECT_ICC
1142     fi
1143
1144     if test "$GCC" = "yes"; then
1145
1146        dnl figure out gcc version!
1147        AC_MSG_CHECKING([gcc version])
1148        gccver=`$CC -dumpversion`
1149        num1=`echo $gccver | cut -d . -f1`
1150        num2=`echo $gccver | cut -d . -f2`
1151        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
1152        AC_MSG_RESULT($gccver)
1153
1154        if test "$ICC" = "yes"; then
1155          dnl this is icc, not gcc.
1156
1157          dnl ICC warnings we ignore:
1158          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
1159          dnl   "invalid format string conversion"
1160          dnl * 279 warns on static conditions in while expressions
1161          dnl * 981 warns on "operands are evaluated in unspecified order"
1162          dnl * 1418 "external definition with no prior declaration"
1163          dnl * 1419 warns on "external declaration in primary source file"
1164          dnl   which we know and do on purpose.
1165
1166          WARN="-wd279,269,981,1418,1419"
1167
1168          if test "$gccnum" -gt "600"; then
1169             dnl icc 6.0 and older doesn't have the -Wall flag
1170             WARN="-Wall $WARN"
1171          fi
1172        else dnl $ICC = yes
1173          dnl this is a set of options we believe *ALL* gcc versions support:
1174          WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
1175
1176          dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
1177
1178          if test "$gccnum" -ge "207"; then
1179            dnl gcc 2.7 or later
1180            WARN="$WARN -Wmissing-declarations"
1181          fi
1182
1183          if test "$gccnum" -gt "295"; then
1184            dnl only if the compiler is newer than 2.95 since we got lots of
1185            dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
1186            dnl gcc 2.95.4 on FreeBSD 4.9!
1187            WARN="$WARN -Wundef -Wno-long-long -Wsign-compare"
1188          fi
1189
1190          if test "$gccnum" -ge "296"; then
1191            dnl gcc 2.96 or later
1192            WARN="$WARN -Wfloat-equal"
1193          fi
1194
1195          if test "$gccnum" -gt "296"; then
1196            dnl this option does not exist in 2.96
1197            WARN="$WARN -Wno-format-nonliteral"
1198          fi
1199
1200          dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
1201          dnl on i686-Linux as it gives us heaps with false positives.
1202          dnl Also, on gcc 4.0.X it is totally unbearable and complains all
1203          dnl over making it unusable for generic purposes. Let's not use it.
1204
1205          if test "$gccnum" -ge "303"; then
1206            dnl gcc 3.3 and later
1207            WARN="$WARN -Wendif-labels -Wstrict-prototypes"
1208          fi
1209
1210          if test "$gccnum" -ge "304"; then
1211            # try these on gcc 3.4
1212            WARN="$WARN -Wdeclaration-after-statement"
1213          fi
1214
1215          for flag in $CPPFLAGS; do
1216            case "$flag" in
1217             -I*)
1218               dnl Include path, provide a -isystem option for the same dir
1219               dnl to prevent warnings in those dirs. The -isystem was not very
1220               dnl reliable on earlier gcc versions.
1221               add=`echo $flag | sed 's/^-I/-isystem /g'`
1222               WARN="$WARN $add"
1223               ;;
1224            esac
1225          done
1226
1227        fi dnl $ICC = no
1228
1229        CFLAGS="$CFLAGS $WARN"
1230
1231       AC_MSG_NOTICE([Added this set of compiler options: $WARN])
1232
1233     else dnl $GCC = yes
1234
1235       AC_MSG_NOTICE([Added no extra compiler options])
1236
1237     fi dnl $GCC = yes
1238
1239     dnl strip off optimizer flags
1240     NEWFLAGS=""
1241     for flag in $CFLAGS; do
1242       case "$flag" in
1243       -O*)
1244         dnl echo "cut off $flag"
1245         ;;
1246       *)
1247         NEWFLAGS="$NEWFLAGS $flag"
1248         ;;
1249       esac
1250     done
1251     CFLAGS=$NEWFLAGS
1252
1253 ]) dnl end of AC_DEFUN()
1254
1255
1256 dnl Determine the name of the library to pass to dlopen() based on the name
1257 dnl that would normally be given to AC_CHECK_LIB.  The preprocessor symbol
1258 dnl given is set to the quoted library file name. 
1259 dnl The standard dynamic library file name is first generated, based on the
1260 dnl current system type, then a search is performed for that file on the
1261 dnl standard dynamic library path.  If it is a symbolic link, the destination
1262 dnl of the link is used as the file name, after stripping off any minor
1263 dnl version numbers. If a library file can't be found, a guess is made.
1264 dnl This macro assumes AC_PROG_LIBTOOL has been called and requires perl
1265 dnl to be available in the PATH, or $PERL to be set to its location.
1266 dnl
1267 dnl CURL_DLLIB_NAME(VARIABLE, library_name)
1268 dnl e.g. CURL_DLLIB_NAME(LDAP_NAME, ldap) on a Linux system might result
1269 dnl in LDAP_NAME holding the string "libldap.so.2".
1270
1271 AC_DEFUN([CURL_DLLIB_NAME],
1272 [
1273 AC_MSG_CHECKING([name of dynamic library $2])
1274 dnl The shared library extension variable name changes from version to
1275 dnl version of libtool.  Try a few names then just set one statically.
1276 test -z "$shared_ext" && shared_ext="$shrext_cmds"
1277 test -z "$shared_ext" && shared_ext="$shrext"
1278 test -z "$shared_ext" && shared_ext=".so"
1279
1280 dnl Create the library link name of the correct form for this platform
1281 LIBNAME_LINK_SPEC=`echo "$library_names_spec" | $SED 's/^.* //'`
1282 DLGUESSLIB=`name=$2 eval echo "$libname_spec"`
1283 DLGUESSFILE=`libname="$DLGUESSLIB" release="" major="" versuffix="" eval echo "$LIBNAME_LINK_SPEC"`
1284
1285 dnl Synthesize a likely dynamic library name in case we can't find an actual one
1286 SO_NAME_SPEC="$soname_spec"
1287 dnl soname_spec undefined when identical to the 1st entry in library_names_spec
1288 test -z "$SO_NAME_SPEC" && SO_NAME_SPEC=`echo "$library_names_spec" | $SED 's/ .*$//'`
1289 DLGUESSSOFILE=`libname="$DLGUESSLIB" release="" major="" versuffix="" eval echo "$SO_NAME_SPEC"`
1290
1291 if test "$cross_compiling" = yes; then
1292   dnl Can't look at filesystem when cross-compiling
1293   AC_DEFINE_UNQUOTED($1, "$DLGUESSSOFILE", [$2 dynamic library file])
1294   AC_MSG_RESULT([$DLGUESSSOFILE (guess while cross-compiling)])
1295 else
1296
1297   DLFOUNDFILE=""
1298   if test "$sys_lib_dlsearch_path_spec" ; then
1299     dnl Search for the link library name and see what it points to.
1300     for direc in $sys_lib_dlsearch_path_spec ; do
1301       DLTRYFILE="$direc/$DLGUESSFILE"
1302       dnl Find where the symbolic link for this name points
1303       changequote(<<, >>)dnl
1304       <<
1305       DLFOUNDFILE=`${PERL:-perl} -e 'use File::Basename; (basename(readlink($ARGV[0])) =~ /^(.*[^\d]\.\d+)[\d\.]*$/ && print ${1}) || exit 1;' "$DLTRYFILE" 2>&5`
1306       >>
1307       changequote([, ])dnl
1308       if test "$?" -eq "0"; then
1309         dnl Found the file link
1310         break
1311       fi
1312     done
1313   fi
1314
1315   if test -z "$DLFOUNDFILE" ; then
1316     dnl Couldn't find a link library, so guess at a name.
1317     DLFOUNDFILE="$DLGUESSSOFILE"
1318   fi
1319
1320   AC_DEFINE_UNQUOTED($1, "$DLFOUNDFILE", [$2 dynamic library file])
1321   AC_MSG_RESULT($DLFOUNDFILE)
1322 fi
1323 ])
1324
1325 # This is only a temporary fix. This macro is here to replace the broken one
1326 # delivered by the automake project (including the 1.9.6 release). As soon as
1327 # they ship a working version we SHOULD remove this work-around.
1328
1329 AC_DEFUN([AM_MISSING_HAS_RUN],
1330 [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
1331 test x"${MISSING+set}" = xset || MISSING="\${SHELL} \"$am_aux_dir/missing\""
1332 # Use eval to expand $SHELL
1333 if eval "$MISSING --run true"; then
1334   am_missing_run="$MISSING --run "
1335 else
1336   am_missing_run=
1337   AC_MSG_WARN([`missing' script is too old or missing])
1338 fi
1339 ])