]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/curl/acinclude.m4
hello world
[icculus/iodoom3.git] / neo / curl / acinclude.m4
1 dnl Check for how to set a socket to non-blocking state. There seems to exist
2 dnl four known different ways, with the one used almost everywhere being POSIX
3 dnl and XPG3, while the other different ways for different systems (old BSD,
4 dnl Windows and Amiga).
5 dnl
6 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
7 dnl O_NONBLOCK define is found but does not work. This condition is attempted
8 dnl to get caught in this script by using an excessive number of #ifdefs...
9 dnl
10 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
11 [
12   AC_MSG_CHECKING([non-blocking sockets style])
13
14   AC_TRY_COMPILE([
15 /* headers for O_NONBLOCK test */
16 #include <sys/types.h>
17 #include <unistd.h>
18 #include <fcntl.h>
19 ],[
20 /* try to compile O_NONBLOCK */
21
22 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
23 # if defined(__SVR4) || defined(__srv4__)
24 #  define PLATFORM_SOLARIS
25 # else
26 #  define PLATFORM_SUNOS4
27 # endif
28 #endif
29 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
30 # define PLATFORM_AIX_V3
31 #endif
32
33 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
34 #error "O_NONBLOCK does not work on this platform"
35 #endif
36   int socket;
37   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
38 ],[
39 dnl the O_NONBLOCK test was fine
40 nonblock="O_NONBLOCK"
41 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
42 ],[
43 dnl the code was bad, try a different program now, test 2
44
45   AC_TRY_COMPILE([
46 /* headers for FIONBIO test */
47 #include <unistd.h>
48 #include <stropts.h>
49 ],[
50 /* FIONBIO source test (old-style unix) */
51  int socket;
52  int flags = ioctl(socket, FIONBIO, &flags);
53 ],[
54 dnl FIONBIO test was good
55 nonblock="FIONBIO"
56 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
57 ],[
58 dnl FIONBIO test was also bad
59 dnl the code was bad, try a different program now, test 3
60
61   AC_TRY_COMPILE([
62 /* headers for ioctlsocket test (cygwin?) */
63 #include <windows.h>
64 ],[
65 /* ioctlsocket source code */
66  int socket;
67  int flags = ioctlsocket(socket, FIONBIO, &flags);
68 ],[
69 dnl ioctlsocket test was good
70 nonblock="ioctlsocket"
71 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
72 ],[
73 dnl ioctlsocket didnt compile!, go to test 4
74
75   AC_TRY_LINK([
76 /* headers for IoctlSocket test (Amiga?) */
77 #include <sys/ioctl.h>
78 ],[
79 /* IoctlSocket source code */
80  int socket;
81  int flags = IoctlSocket(socket, FIONBIO, (long)1);
82 ],[
83 dnl ioctlsocket test was good
84 nonblock="IoctlSocket"
85 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
86 ],[
87 dnl Ioctlsocket didnt compile, do test 5!
88   AC_TRY_COMPILE([
89 /* headers for SO_NONBLOCK test (BeOS) */
90 #include <sys/types.h>
91 #include <unistd.h>
92 #include <fcntl.h>
93 ],[
94 /* SO_NONBLOCK source code */
95  long b = 1;
96  int socket;
97  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
98 ],[
99 dnl the SO_NONBLOCK test was good
100 nonblock="SO_NONBLOCK"
101 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
102 ],[
103 dnl test 5 didnt compile!
104 nonblock="nada"
105 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
106 ])
107 dnl end of fifth test
108
109 ])
110 dnl end of forth test
111
112 ])
113 dnl end of third test
114
115 ])
116 dnl end of second test
117
118 ])
119 dnl end of non-blocking try-compile test
120   AC_MSG_RESULT($nonblock)
121
122   if test "$nonblock" = "nada"; then
123     AC_MSG_WARN([non-block sockets disabled])
124   fi
125 ])
126
127 dnl Check for socklen_t: historically on BSD it is an int, and in
128 dnl POSIX 1g it is a type of its own, but some platforms use different
129 dnl types for the argument to getsockopt, getpeername, etc.  So we
130 dnl have to test to find something that will work.
131 AC_DEFUN([TYPE_SOCKLEN_T],
132 [
133    AC_CHECK_TYPE([socklen_t], ,[
134       AC_MSG_CHECKING([for socklen_t equivalent])
135       AC_CACHE_VAL([curl_cv_socklen_t_equiv],
136       [
137          # Systems have either "struct sockaddr *" or
138          # "void *" as the second argument to getpeername
139          curl_cv_socklen_t_equiv=
140          for arg2 in "struct sockaddr" void; do
141             for t in int size_t unsigned long "unsigned long"; do
142                AC_TRY_COMPILE([
143                   #ifdef HAVE_SYS_TYPES_H
144                   #include <sys/types.h>
145                   #endif
146                   #ifdef HAVE_SYS_SOCKET_H
147                   #include <sys/socket.h>
148                   #endif
149
150                   int getpeername (int, $arg2 *, $t *);
151                ],[
152                   $t len;
153                   getpeername(0,0,&len);
154                ],[
155                   curl_cv_socklen_t_equiv="$t"
156                   break
157                ])
158             done
159          done
160
161          if test "x$curl_cv_socklen_t_equiv" = x; then
162             AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
163          fi
164       ])
165       AC_MSG_RESULT($curl_cv_socklen_t_equiv)
166       AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
167                         [type to use in place of socklen_t if not defined])],
168       [#include <sys/types.h>
169 #include <sys/socket.h>])
170 ])
171
172 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
173 dnl and a few other things. If not found, we set it to unsigned int, as even
174 dnl 64-bit implementations use to set it to a 32-bit type.
175 AC_DEFUN([TYPE_IN_ADDR_T],
176 [
177    AC_CHECK_TYPE([in_addr_t], ,[
178       AC_MSG_CHECKING([for in_addr_t equivalent])
179       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
180       [
181          curl_cv_in_addr_t_equiv=
182          for t in "unsigned long" int size_t unsigned long; do
183             AC_TRY_COMPILE([
184                #ifdef HAVE_SYS_TYPES_H
185                #include <sys/types.h>
186                #endif
187                #ifdef HAVE_SYS_SOCKET_H
188                #include <sys/socket.h>
189                #endif
190                #ifdef HAVE_ARPA_INET_H
191                #include <arpa/inet.h>
192                #endif
193             ],[
194                $t data = inet_addr ("1.2.3.4");
195             ],[
196                curl_cv_in_addr_t_equiv="$t"
197                break
198             ])
199          done
200
201          if test "x$curl_cv_in_addr_t_equiv" = x; then
202             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
203          fi
204       ])
205       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
206       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
207                         [type to use in place of in_addr_t if not defined])],
208       [#include <sys/types.h>
209 #include <sys/socket.h>
210 #include <arpa/inet.h>])
211 ])
212
213 dnl ************************************************************
214 dnl check for "localhost", if it doesn't exist, we can't do the
215 dnl gethostbyname_r tests!
216 dnl 
217
218 AC_DEFUN([CURL_CHECK_WORKING_RESOLVER],[
219 AC_MSG_CHECKING([if "localhost" resolves])
220 AC_TRY_RUN([
221 #include <string.h>
222 #include <sys/types.h>
223 #include <netdb.h>
224
225 int
226 main () {
227 struct hostent *h;
228 h = gethostbyname("localhost");
229 exit (h == NULL ? 1 : 0); }],[
230       AC_MSG_RESULT(yes)],[
231       AC_MSG_RESULT(no)
232       AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
233
234       ]
235 )
236 ])
237
238 dnl ************************************************************
239 dnl check for working getaddrinfo()
240 dnl
241 AC_DEFUN([CURL_CHECK_WORKING_GETADDRINFO],[
242   AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
243   AC_TRY_RUN( [
244 #include <netdb.h>
245 #include <sys/types.h>
246 #include <sys/socket.h>
247
248 void main(void) {
249     struct addrinfo hints, *ai;
250     int error;
251
252     memset(&hints, 0, sizeof(hints));
253     hints.ai_family = AF_UNSPEC;
254     hints.ai_socktype = SOCK_STREAM;
255     error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
256     if (error) {
257         exit(1);
258     }
259     else {
260         exit(0);
261     }
262 }
263 ],[
264   ac_cv_working_getaddrinfo="yes"
265 ],[
266   ac_cv_working_getaddrinfo="no"
267 ],[
268   ac_cv_working_getaddrinfo="yes"
269 ])])
270 if test "$ac_cv_working_getaddrinfo" = "yes"; then
271   AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
272   AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
273
274   IPV6_ENABLED=1
275   AC_SUBST(IPV6_ENABLED)
276 fi
277 ])
278
279
280 AC_DEFUN([CURL_CHECK_LOCALTIME_R],
281 [
282   dnl check for a few thread-safe functions
283   AC_CHECK_FUNCS(localtime_r,[
284     AC_MSG_CHECKING(whether localtime_r is declared)
285     AC_EGREP_CPP(localtime_r,[
286 #include <time.h>],[
287       AC_MSG_RESULT(yes)],[
288       AC_MSG_RESULT(no)
289       AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
290       AC_EGREP_CPP(localtime_r,[
291 #define _REENTRANT
292 #include <time.h>],[
293         AC_DEFINE(NEED_REENTRANT)
294         AC_MSG_RESULT(yes)],
295         AC_MSG_RESULT(no))])])
296 ])
297
298 AC_DEFUN([CURL_CHECK_INET_NTOA_R],
299 [
300   dnl determine if function definition for inet_ntoa_r exists.
301   AC_CHECK_FUNCS(inet_ntoa_r,[
302     AC_MSG_CHECKING(whether inet_ntoa_r is declared)
303     AC_EGREP_CPP(inet_ntoa_r,[
304 #include <arpa/inet.h>],[
305       AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
306       AC_MSG_RESULT(yes)],[
307       AC_MSG_RESULT(no)
308       AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
309       AC_EGREP_CPP(inet_ntoa_r,[
310 #define _REENTRANT
311 #include <arpa/inet.h>],[
312         AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
313         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
314         AC_MSG_RESULT(yes)],
315         AC_MSG_RESULT(no))])])
316 ])
317
318 AC_DEFUN([CURL_CHECK_GETHOSTBYADDR_R],
319 [
320   dnl check for number of arguments to gethostbyaddr_r. it might take
321   dnl either 5, 7, or 8 arguments.
322   AC_CHECK_FUNCS(gethostbyaddr_r,[
323     AC_MSG_CHECKING(if gethostbyaddr_r takes 5 arguments)
324     AC_TRY_COMPILE([
325 #include <sys/types.h>
326 #include <netdb.h>],[
327 char * address;
328 int length;
329 int type;
330 struct hostent h;
331 struct hostent_data hdata;
332 int rc;
333 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
334       AC_MSG_RESULT(yes)
335       AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
336       ac_cv_gethostbyaddr_args=5],[
337       AC_MSG_RESULT(no)
338       AC_MSG_CHECKING(if gethostbyaddr_r with -D_REENTRANT takes 5 arguments)
339       AC_TRY_COMPILE([
340 #define _REENTRANT
341 #include <sys/types.h>
342 #include <netdb.h>],[
343 char * address;
344 int length;
345 int type;
346 struct hostent h;
347 struct hostent_data hdata;
348 int rc;
349 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
350         AC_MSG_RESULT(yes)
351         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
352         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
353         ac_cv_gethostbyaddr_args=5],[
354         AC_MSG_RESULT(no)
355         AC_MSG_CHECKING(if gethostbyaddr_r takes 7 arguments)
356         AC_TRY_COMPILE([
357 #include <sys/types.h>
358 #include <netdb.h>],[
359 char * address;
360 int length;
361 int type;
362 struct hostent h;
363 char buffer[8192];
364 int h_errnop;
365 struct hostent * hp;
366
367 hp = gethostbyaddr_r(address, length, type, &h,
368                      buffer, 8192, &h_errnop);],[
369           AC_MSG_RESULT(yes)
370           AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args] )
371           ac_cv_gethostbyaddr_args=7],[
372           AC_MSG_RESULT(no)
373           AC_MSG_CHECKING(if gethostbyaddr_r takes 8 arguments)
374           AC_TRY_COMPILE([
375 #include <sys/types.h>
376 #include <netdb.h>],[
377 char * address;
378 int length;
379 int type;
380 struct hostent h;
381 char buffer[8192];
382 int h_errnop;
383 struct hostent * hp;
384 int rc;
385
386 rc = gethostbyaddr_r(address, length, type, &h,
387                      buffer, 8192, &hp, &h_errnop);],[
388             AC_MSG_RESULT(yes)
389             AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
390             ac_cv_gethostbyaddr_args=8],[
391             AC_MSG_RESULT(no)
392             have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"])])])])])
393 ])
394
395 AC_DEFUN([CURL_CHECK_GETHOSTBYNAME_R],
396 [
397   dnl check for number of arguments to gethostbyname_r. it might take
398   dnl either 3, 5, or 6 arguments.
399   AC_CHECK_FUNCS(gethostbyname_r,[
400     AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
401     AC_TRY_COMPILE([
402 #include <string.h>
403 #include <sys/types.h>
404 #include <netdb.h>
405 #undef NULL
406 #define NULL (void *)0
407
408 int
409 gethostbyname_r(const char *, struct hostent *, struct hostent_data *);],[
410 struct hostent_data data;
411 gethostbyname_r(NULL, NULL, NULL);],[
412       AC_MSG_RESULT(yes)
413       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
414       ac_cv_gethostbyname_args=3],[
415       AC_MSG_RESULT(no)
416       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
417       AC_TRY_COMPILE([
418 #define _REENTRANT
419
420 #include <string.h>
421 #include <sys/types.h>
422 #include <netdb.h>
423 #undef NULL
424 #define NULL (void *)0
425
426 int
427 gethostbyname_r(const char *,struct hostent *, struct hostent_data *);],[
428 struct hostent_data data;
429 gethostbyname_r(NULL, NULL, NULL);],[
430         AC_MSG_RESULT(yes)
431         AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
432         AC_DEFINE(NEED_REENTRANT, 1, [needs REENTRANT])
433         ac_cv_gethostbyname_args=3],[
434         AC_MSG_RESULT(no)
435         AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
436         AC_TRY_COMPILE([
437 #include <sys/types.h>
438 #include <netdb.h>
439 #undef NULL
440 #define NULL (void *)0
441
442 struct hostent *
443 gethostbyname_r(const char *, struct hostent *, char *, int, int *);],[
444 gethostbyname_r(NULL, NULL, NULL, 0, NULL);],[
445           AC_MSG_RESULT(yes)
446           AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
447           ac_cv_gethostbyname_args=5],[
448           AC_MSG_RESULT(no)
449           AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
450           AC_TRY_COMPILE([
451 #include <sys/types.h>
452 #include <netdb.h>
453 #undef NULL
454 #define NULL (void *)0
455
456 int
457 gethostbyname_r(const char *, struct hostent *, char *, size_t,
458 struct hostent **, int *);],[
459 gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);],[
460             AC_MSG_RESULT(yes)
461             AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
462             ac_cv_gethostbyname_args=6],[
463             AC_MSG_RESULT(no)
464             have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"],
465             [ac_cv_gethostbyname_args=0])],
466           [ac_cv_gethostbyname_args=0])],
467         [ac_cv_gethostbyname_args=0])],
468       [ac_cv_gethostbyname_args=0])])
469
470 if test "$ac_cv_func_gethostbyname_r" = "yes"; then
471   if test "$ac_cv_gethostbyname_args" = "0"; then
472     dnl there's a gethostbyname_r() function, but we don't know how
473     dnl many arguments it wants!
474     AC_MSG_ERROR([couldn't figure out how to use gethostbyname_r()])
475   fi
476 fi
477 ])
478
479 dnl We create a function for detecting which compiler we use and then set as
480 dnl pendantic compiler options as possible for that particular compiler. The
481 dnl options are only used for debug-builds.
482
483 AC_DEFUN([CURL_CC_DEBUG_OPTS],
484 [
485     if test "$GCC" = "yes"; then
486
487        dnl figure out gcc version!
488        AC_MSG_CHECKING([gcc version])
489        gccver=`$CC -dumpversion`
490        num1=`echo $gccver | cut -d . -f1`
491        num2=`echo $gccver | cut -d . -f2`
492        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
493        AC_MSG_RESULT($gccver)
494
495        AC_MSG_CHECKING([if this is icc in disguise])
496        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
497          dnl action if the text is found, this it has not been replaced by the
498          dnl cpp
499          ICC="no"
500          AC_MSG_RESULT([no]),
501          dnl the text was not found, it was replaced by the cpp
502          ICC="yes"
503          AC_MSG_RESULT([yes])
504        )
505
506        if test "$ICC" = "yes"; then
507          dnl this is icc, not gcc.
508
509          dnl ICC warnings we ignore:
510          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
511          dnl   "invalid format string conversion"
512          dnl * 279 warns on static conditions in while expressions
513          dnl * 981 warns on "operands are evaluated in unspecified order"
514          dnl * 1419 warns on "external declaration in primary source file"
515          dnl   which we know and do on purpose.
516
517          WARN="-wd279,269,1419,981"
518
519          if test "$gccnum" -gt "600"; then
520             dnl icc 6.0 and older doesn't have the -Wall flag
521             WARN="-Wall $WARN"
522          fi
523        else dnl $ICC = yes
524          dnl this is a set of options we believe *ALL* gcc versions support:
525          WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"
526
527          dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
528
529          if test "$gccnum" -gt "295"; then
530            dnl only if the compiler is newer than 2.95 since we got lots of
531            dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
532            dnl gcc 2.95.4 on FreeBSD 4.9!
533            WARN="$WARN -Wundef"
534          fi
535
536          if test "$gccnum" -ge "296"; then
537            dnl gcc 2.96 or later
538            WARN="$WARN -Wfloat-equal"
539          fi
540
541          if test "$gccnum" -gt "296"; then
542            dnl this option does not exist in 2.96
543            WARN="$WARN -Wno-format-nonliteral"
544          fi
545
546          dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
547          dnl on i686-Linux as it gives us heaps with false positives
548          if test "$gccnum" -ge "303"; then
549            dnl gcc 3.3 and later
550            WARN="$WARN -Wendif-labels -Wstrict-prototypes"
551          fi
552
553          for flag in $CPPFLAGS; do
554            case "$flag" in
555             -I*)
556               dnl Include path, provide a -isystem option for the same dir
557               dnl to prevent warnings in those dirs. The -isystem was not very
558               dnl reliable on earlier gcc versions.
559               add=`echo $flag | sed 's/^-I/-isystem /g'`
560               WARN="$WARN $add"
561               ;;
562            esac
563          done
564
565        fi dnl $ICC = no
566
567        CFLAGS="$CFLAGS $WARN"
568
569       AC_MSG_NOTICE([Added this set of compiler options: $WARN])
570
571     else dnl $GCC = yes
572
573       AC_MSG_NOTICE([Added no extra compiler options])
574
575     fi dnl $GCC = yes
576
577     dnl strip off optimizer flags
578     NEWFLAGS=""
579     for flag in $CFLAGS; do
580       case "$flag" in
581       -O*)
582         dnl echo "cut off $flag"
583         ;;
584       *)
585         NEWFLAGS="$NEWFLAGS $flag"
586         ;;
587       esac
588     done
589     CFLAGS=$NEWFLAGS
590
591 ]) dnl end of AC_DEFUN()
592