Since there is no proof of the existence of a platform which would
[platform/upstream/c-ares.git] / acinclude.m4
1
2
3 dnl CURL_CHECK_HEADER_WINDOWS
4 dnl -------------------------------------------------
5 dnl Check for compilable and valid windows.h header 
6
7 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
8   AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [
9     AC_COMPILE_IFELSE([
10       AC_LANG_PROGRAM([
11 #undef inline
12 #define WIN32_LEAN_AND_MEAN
13 #include <windows.h>
14       ],[
15         int dummy=2*WINVER;
16       ])
17     ],[
18       ac_cv_header_windows_h="yes"
19     ],[
20       ac_cv_header_windows_h="no"
21     ])
22   ])
23   if test "x$ac_cv_header_windows_h" = "xyes"; then
24     AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
25       [Define to 1 if you have the windows.h header file.])
26     AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
27       [Define to avoid automatic inclusion of winsock.h])
28   fi
29 ])
30
31
32 dnl CURL_CHECK_HEADER_WINSOCK
33 dnl -------------------------------------------------
34 dnl Check for compilable and valid winsock.h header 
35
36 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
37   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
38   AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
39     AC_COMPILE_IFELSE([
40       AC_LANG_PROGRAM([
41 #undef inline
42 #define WIN32_LEAN_AND_MEAN
43 #include <windows.h>
44 #include <winsock.h>
45       ],[
46         int dummy=WSACleanup();
47       ])
48     ],[
49       ac_cv_header_winsock_h="yes"
50     ],[
51       ac_cv_header_winsock_h="no"
52     ])
53   ])
54   if test "x$ac_cv_header_winsock_h" = "xyes"; then
55     AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
56       [Define to 1 if you have the winsock.h header file.])
57   fi
58 ])
59
60
61 dnl CURL_CHECK_HEADER_WINSOCK2
62 dnl -------------------------------------------------
63 dnl Check for compilable and valid winsock2.h header 
64
65 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
66   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
67   AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
68     AC_COMPILE_IFELSE([
69       AC_LANG_PROGRAM([
70 #undef inline
71 #define WIN32_LEAN_AND_MEAN
72 #include <windows.h>
73 #include <winsock2.h>
74       ],[
75         int dummy=2*IPPROTO_ESP;
76       ])
77     ],[
78       ac_cv_header_winsock2_h="yes"
79     ],[
80       ac_cv_header_winsock2_h="no"
81     ])
82   ])
83   if test "x$ac_cv_header_winsock2_h" = "xyes"; then
84     AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
85       [Define to 1 if you have the winsock2.h header file.])
86   fi
87 ])
88
89
90 dnl CURL_CHECK_HEADER_WS2TCPIP
91 dnl -------------------------------------------------
92 dnl Check for compilable and valid ws2tcpip.h header
93
94 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
95   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
96   AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
97     AC_COMPILE_IFELSE([
98       AC_LANG_PROGRAM([
99 #undef inline
100 #define WIN32_LEAN_AND_MEAN
101 #include <windows.h>
102 #include <winsock2.h>
103 #include <ws2tcpip.h>
104       ],[
105         int dummy=2*IP_PKTINFO;
106       ])
107     ],[
108       ac_cv_header_ws2tcpip_h="yes"
109     ],[
110       ac_cv_header_ws2tcpip_h="no"
111     ])
112   ])
113   if test "x$ac_cv_header_ws2tcpip_h" = "xyes"; then
114     AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
115       [Define to 1 if you have the ws2tcpip.h header file.])
116   fi
117 ])
118
119
120 dnl CURL_CHECK_TYPE_SOCKLEN_T
121 dnl -------------------------------------------------
122 dnl Check for existing socklen_t type, and provide
123 dnl an equivalent type if socklen_t not available
124
125 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
126   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
127   AC_CHECK_TYPE([socklen_t], ,[
128     AC_CACHE_CHECK([for socklen_t equivalent], 
129       [curl_cv_socklen_t_equiv], [
130       curl_cv_socklen_t_equiv="unknown"
131       for arg2 in "struct sockaddr" void; do
132         for t in int size_t unsigned long "unsigned long"; do
133           AC_COMPILE_IFELSE([
134             AC_LANG_PROGRAM([
135 #undef inline
136 #ifdef HAVE_WINDOWS_H
137 #define WIN32_LEAN_AND_MEAN
138 #include <windows.h>
139 #ifdef HAVE_WINSOCK2_H
140 #include <winsock2.h>
141 #else
142 #ifdef HAVE_WINSOCK_H
143 #include <winsock.h>
144 #endif
145 #endif
146 #else
147 #ifdef HAVE_SYS_TYPES_H
148 #include <sys/types.h>
149 #endif
150 #ifdef HAVE_SYS_SOCKET_H
151 #include <sys/socket.h>
152 #endif
153 #endif
154               int getpeername (int, $arg2 *, $t *);
155             ],[
156               $t len=0;
157               getpeername(0,0,&len);
158             ])
159           ],[
160              curl_cv_socklen_t_equiv="$t"
161              break 2
162           ])
163         done
164       done
165     ])
166     if test "$curl_cv_socklen_t_equiv" = "unknown"; then
167       AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
168     else
169       AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
170         [type to use in place of socklen_t if not defined])
171     fi
172   ],[
173 #ifdef HAVE_WINDOWS_H
174 #ifdef HAVE_WS2TCPIP_H
175 #include <ws2tcpip.h>
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   ])
186 ])
187
188
189 dnl CURL_FUNC_GETNAMEINFO_ARGTYPES
190 dnl -------------------------------------------------
191 dnl Check the type to be passed to five of the arguments
192 dnl of getnameinfo function, and define those types in  
193 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
194 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7.
195 dnl This function is experimental and its results shall
196 dnl not be trusted while this notice is in place ------
197
198 AC_DEFUN([CURL_FUNC_GETNAMEINFO_ARGTYPES], [
199   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
200   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
201   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
202   AC_CACHE_CHECK([types of arguments for getnameinfo],
203     [curl_cv_func_getnameinfo_args], [
204     curl_cv_func_getnameinfo_args="unknown"
205     for gni_arg1 in 'struct sockaddr *' 'void *'; do
206       for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
207         for gni_arg46 in 'size_t' 'int' 'socklen_t'; do
208           for gni_arg7 in 'int' 'unsigned int'; do
209             AC_COMPILE_IFELSE([
210               AC_LANG_PROGRAM([
211 #undef inline
212 #ifdef HAVE_WINDOWS_H
213 #define WIN32_LEAN_AND_MEAN
214 #include <windows.h>
215 #ifdef HAVE_WINSOCK2_H
216 #include <winsock2.h>
217 #endif
218 #ifdef HAVE_WS2TCPIP_H
219 #include <ws2tcpip.h>
220 #endif
221 #else
222 #ifdef HAVE_SYS_TYPES_H
223 #include <sys/types.h>
224 #endif
225 #ifdef HAVE_SYS_SOCKET_H
226 #include <sys/socket.h>
227 #endif
228 #ifdef HAVE_NETDB_H
229 #include <netdb.h>
230 #endif
231 #endif
232                 extern int getnameinfo($gni_arg1, $gni_arg2,
233                                        char *, $gni_arg46,
234                                        char *, $gni_arg46,
235                                        $gni_arg7);
236               ],[
237                 $gni_arg1 sa=0;
238                 $gni_arg2 salen=0;
239                 char *host=0;
240                 $gni_arg46 hostlen=0;
241                 char *serv=0;
242                 $gni_arg46 servlen=0;
243                 $gni_arg7 flags=0;
244                 getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
245               ])
246             ],[
247                curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
248                break 4
249             ])
250           done
251         done
252       done
253     done
254   ])
255   if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
256     AC_MSG_ERROR([Cannot find proper types to use for getnameinfo args])
257   else
258     gni_prev_IFS=$IFS; IFS=','
259     set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
260     IFS=$gni_prev_IFS
261     shift
262     AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $[1],
263       [Define to the type of arg 1 for `getnameinfo'.])
264     AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
265       [Define to the type of arg 2 for `getnameinfo'.])
266     AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
267       [Define to the type of args 4 and 6 for `getnameinfo'.])
268     AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
269       [Define to the type of arg 7 for `getnameinfo'.])
270   fi
271 ])
272
273
274 dnl Check for how to set a socket to non-blocking state. There seems to exist
275 dnl four known different ways, with the one used almost everywhere being POSIX
276 dnl and XPG3, while the other different ways for different systems (old BSD,
277 dnl Windows and Amiga).
278 dnl
279 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
280 dnl O_NONBLOCK define is found but does not work. This condition is attempted
281 dnl to get caught in this script by using an excessive number of #ifdefs...
282 dnl
283 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
284 [
285   AC_MSG_CHECKING([non-blocking sockets style])
286
287   AC_TRY_COMPILE([
288 /* headers for O_NONBLOCK test */
289 #include <sys/types.h>
290 #include <unistd.h>
291 #include <fcntl.h>
292 ],[
293 /* try to compile O_NONBLOCK */
294
295 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
296 # if defined(__SVR4) || defined(__srv4__)
297 #  define PLATFORM_SOLARIS
298 # else
299 #  define PLATFORM_SUNOS4
300 # endif
301 #endif
302 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
303 # define PLATFORM_AIX_V3
304 #endif
305
306 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
307 #error "O_NONBLOCK does not work on this platform"
308 #endif
309   int socket;
310   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
311 ],[
312 dnl the O_NONBLOCK test was fine
313 nonblock="O_NONBLOCK"
314 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
315 ],[
316 dnl the code was bad, try a different program now, test 2
317
318   AC_TRY_COMPILE([
319 /* headers for FIONBIO test */
320 #include <unistd.h>
321 #include <stropts.h>
322 ],[
323 /* FIONBIO source test (old-style unix) */
324  int socket;
325  int flags = ioctl(socket, FIONBIO, &flags);
326 ],[
327 dnl FIONBIO test was good
328 nonblock="FIONBIO"
329 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
330 ],[
331 dnl FIONBIO test was also bad
332 dnl the code was bad, try a different program now, test 3
333
334   AC_TRY_COMPILE([
335 /* headers for ioctlsocket test (cygwin?) */
336 #include <windows.h>
337 ],[
338 /* ioctlsocket source code */
339  int socket;
340  unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
341 ],[
342 dnl ioctlsocket test was good
343 nonblock="ioctlsocket"
344 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
345 ],[
346 dnl ioctlsocket didnt compile!, go to test 4
347
348   AC_TRY_LINK([
349 /* headers for IoctlSocket test (Amiga?) */
350 #include <sys/ioctl.h>
351 ],[
352 /* IoctlSocket source code */
353  int socket;
354  int flags = IoctlSocket(socket, FIONBIO, (long)1);
355 ],[
356 dnl ioctlsocket test was good
357 nonblock="IoctlSocket"
358 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
359 ],[
360 dnl Ioctlsocket didnt compile, do test 5!
361   AC_TRY_COMPILE([
362 /* headers for SO_NONBLOCK test (BeOS) */
363 #include <socket.h>
364 ],[
365 /* SO_NONBLOCK source code */
366  long b = 1;
367  int socket;
368  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
369 ],[
370 dnl the SO_NONBLOCK test was good
371 nonblock="SO_NONBLOCK"
372 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
373 ],[
374 dnl test 5 didnt compile!
375 nonblock="nada"
376 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
377 ])
378 dnl end of fifth test
379
380 ])
381 dnl end of forth test
382
383 ])
384 dnl end of third test
385
386 ])
387 dnl end of second test
388
389 ])
390 dnl end of non-blocking try-compile test
391   AC_MSG_RESULT($nonblock)
392
393   if test "$nonblock" = "nada"; then
394     AC_MSG_WARN([non-block sockets disabled])
395   fi
396 ])
397
398 dnl We create a function for detecting which compiler we use and then set as
399 dnl pendantic compiler options as possible for that particular compiler. The
400 dnl options are only used for debug-builds.
401
402 dnl This is a copy of the original found in curl's configure script. Don't
403 dnl modify this one, edit the one in curl and copy it back here when that one
404 dnl is changed.
405
406 AC_DEFUN([CURL_CC_DEBUG_OPTS],
407 [
408     if test "$GCC" = "yes"; then
409
410        dnl figure out gcc version!
411        AC_MSG_CHECKING([gcc version])
412        gccver=`$CC -dumpversion`
413        num1=`echo $gccver | cut -d . -f1`
414        num2=`echo $gccver | cut -d . -f2`
415        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
416        AC_MSG_RESULT($gccver)
417
418        AC_MSG_CHECKING([if this is icc in disguise])
419        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
420          dnl action if the text is found, this it has not been replaced by the
421          dnl cpp
422          ICC="no"
423          AC_MSG_RESULT([no]),
424          dnl the text was not found, it was replaced by the cpp
425          ICC="yes"
426          AC_MSG_RESULT([yes])
427        )
428
429        if test "$ICC" = "yes"; then
430          dnl this is icc, not gcc.
431
432          dnl ICC warnings we ignore:
433          dnl * 279 warns on static conditions in while expressions
434          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
435          dnl   "invalid format string conversion"
436
437          WARN="-wd279,269"
438
439          if test "$gccnum" -gt "600"; then
440             dnl icc 6.0 and older doesn't have the -Wall flag
441             WARN="-Wall $WARN"
442          fi
443        else dnl $ICC = yes
444          dnl 
445          WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
446
447          dnl -Wcast-align is a bit too annoying ;-)
448
449          if test "$gccnum" -ge "296"; then
450            dnl gcc 2.96 or later
451            WARN="$WARN -Wfloat-equal"
452
453            if test "$gccnum" -gt "296"; then
454              dnl this option does not exist in 2.96
455              WARN="$WARN -Wno-format-nonliteral"
456            fi
457
458            dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
459            dnl on i686-Linux as it gives us heaps with false positives
460            if test "$gccnum" -ge "303"; then
461              dnl gcc 3.3 and later
462              WARN="$WARN -Wendif-labels -Wstrict-prototypes"
463            fi
464          fi
465
466          for flag in $CPPFLAGS; do
467            case "$flag" in
468             -I*)
469               dnl include path
470               add=`echo $flag | sed 's/^-I/-isystem /g'`
471               WARN="$WARN $add"
472               ;;
473            esac
474          done
475
476        fi dnl $ICC = no
477
478        CFLAGS="$CFLAGS $WARN"
479
480     fi dnl $GCC = yes
481
482     dnl strip off optimizer flags
483     NEWFLAGS=""
484     for flag in $CFLAGS; do
485       case "$flag" in
486       -O*)
487         dnl echo "cut off $flag"
488         ;;
489       *)
490         NEWFLAGS="$NEWFLAGS $flag"
491         ;;
492       esac
493     done
494     CFLAGS=$NEWFLAGS
495
496 ]) dnl end of AC_DEFUN()
497
498
499 dnl This macro determines if the specified struct exists in the specified file
500 dnl Syntax:
501 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
502
503 AC_DEFUN([CARES_CHECK_STRUCT], [
504   AC_MSG_CHECKING([for struct $2])
505   AC_TRY_COMPILE([$1], 
506     [
507       struct $2 struct_instance;
508     ], ac_struct="yes", ac_found="no")
509   if test "$ac_struct" = "yes" ; then
510     AC_MSG_RESULT(yes)
511     $3
512   else
513     AC_MSG_RESULT(no)
514     $4
515   fi
516 ])
517
518 dnl This macro determines if the specified constant exists in the specified file
519 dnl Syntax:
520 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])
521
522 AC_DEFUN([CARES_CHECK_CONSTANT], [
523   AC_MSG_CHECKING([for $2])
524   AC_EGREP_CPP(VARIABLEWASDEFINED,
525    [
526       $1
527
528       #ifdef $2
529         VARIABLEWASDEFINED
530       #else
531         NJET
532       #endif
533     ], ac_constant="yes", ac_constant="no"
534   )
535   if test "$ac_constant" = "yes" ; then
536     AC_MSG_RESULT(yes)
537     $3
538   else
539     AC_MSG_RESULT(no)
540     $4
541   fi
542 ])
543
544
545 dnl This macro determines how many parameters getservbyport_r takes
546 AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
547   AC_MSG_CHECKING([how many arguments getservbyport_r takes])
548   AC_TRY_COMPILE(
549     [#include <netdb.h>],
550     [
551       int p1, p5;
552       char *p2, p4[4096];
553       struct servent *p3, *p6;
554       getservbyport_r(p1, p2, p3, p4, p5, &p6);
555     ], ac_func_getservbyport_r=6,
556     [AC_TRY_COMPILE(
557       [#include <netdb.h>],
558       [
559         int p1, p5;
560         char *p2, p4[4096];
561         struct servent *p3;
562         getservbyport_r(p1, p2, p3, p4, p5);
563       ], ac_func_getservbyport_r=5,
564       [AC_TRY_COMPILE(
565         [#include <netdb.h>],
566         [
567           int p1;
568           char *p2;
569           struct servent *p3;
570           struct servent_data p4;
571           getservbyport_r(p1, p2, p3, &p4);
572         ], ac_func_getservbyport_r=4, ac_func_getservbyport_r=0
573       )]
574     )]
575   )
576 if test $ac_func_getservbyport_r != "0" ; then
577   AC_MSG_RESULT($ac_func_getservbyport_r)
578   AC_DEFINE(HAVE_GETSERVBYPORT_R, 1, [Specifies whether getservbyport_r is present])
579   AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $ac_func_getservbyport_r, [Specifies the number of arguments to 
580 getservbyport_r])
581   if test $ac_func_getservbyport_r = "4" ; then
582    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), [Specifies the size of the buffer to pass to 
583 getservbyport_r])
584   else
585    AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, [Specifies the size of the buffer to pass to getservbyport_r])
586   fi
587 else
588   AC_MSG_RESULT([not found])
589 fi
590 ])
591