]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/unbound/acx_nlnetlabs.m4
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / unbound / acx_nlnetlabs.m4
1 # acx_nlnetlabs.m4 - common macros for configure checks
2 # Copyright 2009, Wouter Wijngaards, NLnet Labs.   
3 # BSD licensed.
4 #
5 # Version 21
6 # 2012-02-09 Fix AHX_MEMCMP_BROKEN with undef in compat/memcmp.h.
7 # 2012-01-20 Fix COMPILER_FLAGS_UNBOUND for gcc 4.6.2 assigned-not-used-warns.
8 # 2011-12-05 Fix getaddrinfowithincludes on windows with fedora16 mingw32-gcc.
9 #            Fix ACX_MALLOC for redefined malloc error.
10 #            Fix GETADDRINFO_WITH_INCLUDES to add -lws2_32
11 # 2011-11-10 Fix FLTO test to not drop a.out in current directory.
12 # 2011-11-01 Fix FLTO test for llvm on Lion.
13 # 2011-08-01 Fix nonblock test (broken at v13).
14 # 2011-08-01 Fix autoconf 2.68 warnings
15 # 2011-06-23 Add ACX_CHECK_FLTO to check -flto.
16 # 2010-08-16 Fix FLAG_OMITTED for AS_TR_CPP changes in autoconf-2.66.
17 # 2010-07-02 Add check for ss_family (for minix).
18 # 2010-04-26 Fix to use CPPFLAGS for CHECK_COMPILER_FLAGS.
19 # 2010-03-01 Fix RPATH using CONFIG_COMMANDS to run at the very end.
20 # 2010-02-18 WITH_SSL outputs the LIBSSL_LDFLAGS, LIBS, CPPFLAGS seperate, -ldl
21 # 2010-02-01 added ACX_CHECK_MEMCMP_SIGNED, AHX_MEMCMP_BROKEN
22 # 2010-01-20 added AHX_COONFIG_STRLCAT
23 # 2009-07-14 U_CHAR detection improved for windows crosscompile.
24 #            added ACX_FUNC_MALLOC
25 #            fixup some #if to #ifdef
26 #            NONBLOCKING test for mingw crosscompile.
27 # 2009-07-13 added ACX_WITH_SSL_OPTIONAL
28 # 2009-07-03 fixup LDFLAGS for empty ssl dir.
29 #
30 # Automates some of the checking constructs.  Aims at portability for POSIX.
31 # Documentation for functions is below.
32 #
33 # the following macro's are provided in this file:
34 # (see below for details on each macro).
35 #
36 # ACX_ESCAPE_BACKSLASH          - escape backslashes in var for C-preproc.
37 # ACX_RSRC_VERSION              - create windows resource version number.
38 # ACX_CHECK_COMPILER_FLAG       - see if cc supports a flag.
39 # ACX_CHECK_ERROR_FLAGS         - see which flag is -werror (used below).
40 # ACX_CHECK_COMPILER_FLAG_NEEDED - see if flags make the code compile cleanly.
41 # ACX_DEPFLAG                   - find cc dependency flags.
42 # ACX_DETERMINE_EXT_FLAGS_UNBOUND - find out which flags enable BSD and POSIX.
43 # ACX_CHECK_FORMAT_ATTRIBUTE    - find cc printf format syntax.
44 # ACX_CHECK_UNUSED_ATTRIBUTE    - find cc variable unused syntax.
45 # ACX_CHECK_FLTO                - see if cc supports -flto and use it if so.
46 # ACX_LIBTOOL_C_ONLY            - create libtool for C only, improved.
47 # ACX_TYPE_U_CHAR               - u_char type.
48 # ACX_TYPE_RLIM_T               - rlim_t type.
49 # ACX_TYPE_SOCKLEN_T            - socklen_t type.
50 # ACX_TYPE_IN_ADDR_T            - in_addr_t type.
51 # ACX_TYPE_IN_PORT_T            - in_port_t type.
52 # ACX_ARG_RPATH                 - add --disable-rpath option.
53 # ACX_WITH_SSL                  - add --with-ssl option, link -lcrypto.
54 # ACX_WITH_SSL_OPTIONAL         - add --with-ssl option, link -lcrypto,
55 #                                 where --without-ssl is also accepted
56 # ACX_LIB_SSL                   - setup to link -lssl.
57 # ACX_SYS_LARGEFILE             - improved sys_largefile, fseeko, >2G files.
58 # ACX_CHECK_GETADDRINFO_WITH_INCLUDES - find getaddrinfo, portably.
59 # ACX_FUNC_DEPRECATED           - see if func is deprecated.
60 # ACX_CHECK_NONBLOCKING_BROKEN  - see if nonblocking sockets really work.
61 # ACX_MKDIR_ONE_ARG             - determine mkdir(2) number of arguments.
62 # ACX_FUNC_IOCTLSOCKET          - find ioctlsocket, portably.
63 # ACX_FUNC_MALLOC               - check malloc, define replacement .
64 # AHX_CONFIG_FORMAT_ATTRIBUTE   - config.h text for format.
65 # AHX_CONFIG_UNUSED_ATTRIBUTE   - config.h text for unused.
66 # AHX_CONFIG_FSEEKO             - define fseeko, ftello fallback.
67 # AHX_CONFIG_RAND_MAX           - define RAND_MAX if needed.
68 # AHX_CONFIG_MAXHOSTNAMELEN     - define MAXHOSTNAMELEN if needed.
69 # AHX_CONFIG_IPV6_MIN_MTU       - define IPV6_MIN_MTU if needed.
70 # AHX_CONFIG_SNPRINTF           - snprintf compat prototype
71 # AHX_CONFIG_INET_PTON          - inet_pton compat prototype
72 # AHX_CONFIG_INET_NTOP          - inet_ntop compat prototype
73 # AHX_CONFIG_INET_ATON          - inet_aton compat prototype
74 # AHX_CONFIG_MEMMOVE            - memmove compat prototype
75 # AHX_CONFIG_STRLCAT            - strlcat compat prototype
76 # AHX_CONFIG_STRLCPY            - strlcpy compat prototype
77 # AHX_CONFIG_GMTIME_R           - gmtime_r compat prototype
78 # AHX_CONFIG_W32_SLEEP          - w32 compat for sleep
79 # AHX_CONFIG_W32_USLEEP         - w32 compat for usleep
80 # AHX_CONFIG_W32_RANDOM         - w32 compat for random
81 # AHX_CONFIG_W32_SRANDOM        - w32 compat for srandom
82 # AHX_CONFIG_W32_FD_SET_T       - w32 detection of FD_SET_T.
83 # ACX_CFLAGS_STRIP              - strip one flag from CFLAGS
84 # ACX_STRIP_EXT_FLAGS           - strip extension flags from CFLAGS
85 # AHX_CONFIG_FLAG_OMITTED       - define omitted flag
86 # AHX_CONFIG_FLAG_EXT           - define omitted extension flag
87 # AHX_CONFIG_EXT_FLAGS          - define the stripped extension flags
88 # ACX_CHECK_MEMCMP_SIGNED       - check if memcmp uses signed characters.
89 # AHX_MEMCMP_BROKEN             - replace memcmp func for CHECK_MEMCMP_SIGNED.
90 # ACX_CHECK_SS_FAMILY           - check for sockaddr_storage.ss_family
91 #
92
93 dnl Escape backslashes as \\, for C:\ paths, for the C preprocessor defines.
94 dnl for example, ACX_ESCAPE_BACKSLASH($from_var, to_var)
95 dnl $1: the text to change. 
96 dnl $2: the result.
97 AC_DEFUN([ACX_ESCAPE_BACKSLASH], [$2="`echo $1 | sed -e 's/\\\\/\\\\\\\\/g'`"
98 ])
99
100 dnl Calculate comma separated windows-resource numbers from package version.
101 dnl Picks the first three(,0) or four numbers out of the name.
102 dnl $1: variable for the result
103 AC_DEFUN([ACX_RSRC_VERSION], 
104 [$1=[`echo $PACKAGE_VERSION | sed -e 's/^[^0-9]*\([0-9]\)[^0-9]*\([0-9]\)[^0-9]*\([0-9]\)[^0-9]*\([0-9]\).*$/\1,\2,\3,\4/' -e 's/^[^0-9]*\([0-9]\)[^0-9]*\([0-9]\)[^0-9]*\([0-9]\)[^0-9]*$/\1,\2,\3,0/' `]
105 ])
106
107 dnl Routine to help check for compiler flags.
108 dnl Checks if the compiler will accept the flag.
109 dnl $1: the flag without a - in front, so g to check -g.
110 dnl $2: executed if yes
111 dnl $3: executed if no
112 AC_DEFUN([ACX_CHECK_COMPILER_FLAG], 
113 [
114 AC_REQUIRE([AC_PROG_CC])
115 AC_MSG_CHECKING(whether $CC supports -$1)
116 cache=`echo $1 | sed 'y%.=/+-%___p_%'`
117 AC_CACHE_VAL(cv_prog_cc_flag_$cache,
118 [
119 echo 'void f(){}' >conftest.c
120 if test -z "`$CC $CPPFLAGS $CFLAGS -$1 -c conftest.c 2>&1`"; then
121 eval "cv_prog_cc_flag_$cache=yes"
122 else
123 eval "cv_prog_cc_flag_$cache=no"
124 fi
125 rm -f conftest conftest.o conftest.c
126 ])
127 if eval "test \"`echo '$cv_prog_cc_flag_'$cache`\" = yes"; then
128 AC_MSG_RESULT(yes)
129 :
130 $2
131 else
132 AC_MSG_RESULT(no)
133 :
134 $3
135 fi
136 ])
137
138 dnl setup flags for ACX_CHECK_COMPILER_FLAG_NEEDED
139 dnl ERRFLAG: result, compiler flag to turn warnings into errors
140 AC_DEFUN([ACX_CHECK_ERROR_FLAGS],
141 [
142 ACX_CHECK_COMPILER_FLAG(Werror, [ERRFLAG="-Werror"], [ERRFLAG="-errwarn"])
143 ACX_CHECK_COMPILER_FLAG(Wall, [ERRFLAG="$ERRFLAG -Wall"],
144                                 [ERRFLAG="$ERRFLAG -errfmt"])
145 ])
146
147 dnl Routine to help check for needed compiler flags.
148 dnl $1: flags for CC
149 dnl $2: the includes and code
150 dnl $3: if the given code only compiles with the flag, execute argument 3
151 dnl $4: if the given code compiles without the flag, execute argument 4
152 dnl $5: with and without flag the compile fails, execute argument 5.
153 AC_DEFUN([ACX_CHECK_COMPILER_FLAG_NEEDED],
154 [
155 AC_REQUIRE([AC_PROG_CC])
156 AC_REQUIRE([ACX_CHECK_ERROR_FLAGS])
157 AC_MSG_CHECKING(whether we need $1 as a flag for $CC)
158 cache=AS_TR_SH($1)
159 dnl cache=`echo $1 | sed 'y%.=/+- %___p__%'`
160 AC_CACHE_VAL(cv_prog_cc_flag_needed_$cache,
161 [
162 echo '$2' > conftest.c
163 echo 'void f(){}' >>conftest.c
164 if test -z "`$CC $CPPFLAGS $CFLAGS $ERRFLAG -c conftest.c 2>&1`"; then
165 eval "cv_prog_cc_flag_needed_$cache=no"
166 else
167 [
168 if test -z "`$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`"; then
169 eval "cv_prog_cc_flag_needed_$cache=yes"
170 else
171 eval "cv_prog_cc_flag_needed_$cache=fail"
172 #echo 'Test with flag fails too!'
173 #cat conftest.c
174 #echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1"
175 #echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`
176 #exit 1
177 fi
178 ]
179 fi
180 rm -f conftest conftest.c conftest.o
181 ])
182 if eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = yes"; then
183 AC_MSG_RESULT(yes)
184 :
185 $3
186 else
187 if eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = no"; then
188 AC_MSG_RESULT(no)
189 #echo 'Test with flag is no!'
190 #cat conftest.c
191 #echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1"
192 #echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`
193 #exit 1
194 :
195 $4
196 else
197 AC_MSG_RESULT(failed)
198 :
199 $5
200 fi
201 fi
202 ])
203
204 dnl Check for CC dependency flag
205 dnl DEPFLAG: set to flag that generates dependencies.
206 AC_DEFUN([ACX_DEPFLAG],
207 [
208 AC_MSG_CHECKING([$CC dependency flag])
209 echo 'void f(){}' >conftest.c
210 if test "`$CC -MM conftest.c 2>&1`" = "conftest.o: conftest.c"; then
211         DEPFLAG="-MM"
212 else 
213   if test "`$CC -xM1 conftest.c 2>&1`" = "conftest.o: conftest.c"; then
214         DEPFLAG="-xM1"
215   else
216         DEPFLAG="-MM"  # dunno do something
217   fi 
218 fi
219 AC_MSG_RESULT($DEPFLAG)
220 rm -f conftest.c
221 AC_SUBST(DEPFLAG)
222 ])
223
224 dnl Determine flags that gives POSIX and BSD functionality.
225 dnl CFLAGS is modified for the result.
226 AC_DEFUN([ACX_DETERMINE_EXT_FLAGS_UNBOUND],
227 [
228 ACX_CHECK_COMPILER_FLAG(std=c99, [C99FLAG="-std=c99"])
229 ACX_CHECK_COMPILER_FLAG(xc99, [C99FLAG="-xc99"])
230
231 AC_CHECK_HEADERS([getopt.h time.h],,, [AC_INCLUDES_DEFAULT])
232
233 ACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_ALL_SOURCE,
234 [
235 #include "confdefs.h"
236 #include <stdlib.h>
237 #include <ctype.h>
238 #include <sys/time.h>
239 #ifdef HAVE_TIME_H
240 #include <time.h>
241 #endif
242 #include <unistd.h>
243 #include <netdb.h>
244 #ifdef HAVE_GETOPT_H
245 #include <getopt.h>
246 #endif
247
248 int test() {
249         int a;
250         char **opts = NULL;
251         struct timeval tv;
252         char *t;
253         time_t time = 0;
254         char *buf = NULL;
255         const char* str = NULL;
256         struct msghdr msg;
257         msg.msg_control = 0;
258         t = ctime_r(&time, buf);
259         tv.tv_usec = 10;
260         srandom(32);
261         a = getopt(2, opts, "a");
262         a = isascii(32);
263         str = gai_strerror(0);
264         if(str && t && tv.tv_usec && msg.msg_control)
265                 a = 0;
266         return a;
267 }
268 ], [CFLAGS="$CFLAGS $C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_ALL_SOURCE"])
269
270 ACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE,
271 [
272 #include "confdefs.h"
273 #include <stdlib.h>
274 #include <ctype.h>
275 #include <sys/time.h>
276 #ifdef HAVE_TIME_H
277 #include <time.h>
278 #endif
279 #include <unistd.h>
280 #include <netdb.h>
281 #ifdef HAVE_GETOPT_H
282 #include <getopt.h>
283 #endif
284
285 int test() {
286         int a;
287         char **opts = NULL;
288         struct timeval tv;
289         char *t;
290         time_t time = 0;
291         char *buf = NULL;
292         const char* str = NULL;
293         struct msghdr msg;
294         msg.msg_control = 0;
295         t = ctime_r(&time, buf);
296         tv.tv_usec = 10;
297         srandom(32);
298         a = getopt(2, opts, "a");
299         a = isascii(32);
300         str = gai_strerror(0);
301         if(str && t && tv.tv_usec && msg.msg_control)
302                 a = 0;
303         return a;
304 }
305 ], [CFLAGS="$CFLAGS $C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE"])
306
307 ACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG,
308 [
309 #include <stdbool.h>
310 #include <ctype.h>
311 int test() {
312         int a = 0;
313         return a;
314 }
315 ], [CFLAGS="$CFLAGS $C99FLAG"])
316
317 ACX_CHECK_COMPILER_FLAG_NEEDED(-D_BSD_SOURCE,
318 [
319 #include <ctype.h>
320
321 int test() {
322         int a;
323         a = isascii(32);
324         return a;
325 }
326 ], [CFLAGS="$CFLAGS -D_BSD_SOURCE"])
327
328 ACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE,
329 [
330 #include <netinet/in.h>
331
332 int test() {
333         struct in6_pktinfo inf;
334         int a = (int)sizeof(inf);
335         return a;
336 }
337 ], [CFLAGS="$CFLAGS -D_GNU_SOURCE"])
338
339 # check again for GNU_SOURCE for setresgid. May fail if setresgid
340 # is not available at all. -D_FRSRESGID is to make this check unique.
341 # otherwise we would get the previous cached result.
342 ACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE -D_FRSRESGID,
343 [
344 #include <unistd.h>
345
346 int test() {
347         int a = setresgid(0,0,0);
348         a = setresuid(0,0,0);
349         return a;
350 }
351 ], [CFLAGS="$CFLAGS -D_GNU_SOURCE"])
352
353 ACX_CHECK_COMPILER_FLAG_NEEDED(-D_POSIX_C_SOURCE=200112,
354 [
355 #include "confdefs.h"
356 #ifdef HAVE_TIME_H
357 #include <time.h>
358 #endif
359 #include <netdb.h>
360
361 int test() {
362         int a = 0;
363         char *t;
364         time_t time = 0;
365         char *buf = NULL;
366         const char* str = NULL;
367         t = ctime_r(&time, buf);
368         str = gai_strerror(0);
369         if(t && str)
370                 a = 0;
371         return a;
372 }
373 ], [CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112"])
374
375 ACX_CHECK_COMPILER_FLAG_NEEDED(-D__EXTENSIONS__,
376 [
377 #include "confdefs.h"
378 #include <stdlib.h>
379 #include <ctype.h>
380 #include <sys/time.h>
381 #ifdef HAVE_TIME_H
382 #include <time.h>
383 #endif
384 #include <unistd.h>
385 #ifdef HAVE_GETOPT_H
386 #include <getopt.h>
387 #endif
388
389 int test() {
390         int a;
391         char **opts = NULL;
392         struct timeval tv;
393         tv.tv_usec = 10;
394         srandom(32);
395         a = getopt(2, opts, "a");
396         a = isascii(32);
397         if(tv.tv_usec)
398                 a = 0;
399         return a;
400 }
401 ], [CFLAGS="$CFLAGS -D__EXTENSIONS__"])
402
403 ])dnl End of ACX_DETERMINE_EXT_FLAGS_UNBOUND
404
405 dnl Check if CC supports -flto.
406 dnl in a way that supports clang and suncc (that flag does something else,
407 dnl but fails to link).  It sets it in CFLAGS if it works.
408 AC_DEFUN([ACX_CHECK_FLTO],
409 [AC_MSG_CHECKING([if $CC supports -flto])
410 BAKCFLAGS="$CFLAGS"
411 CFLAGS="$CFLAGS -flto"
412 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [
413     if $CC $CFLAGS -o conftest conftest.c 2>&1 | grep "warning: no debug symbols in executable" >/dev/null; then
414         CFLAGS="$BAKCFLAGS"
415         AC_MSG_RESULT(no)
416     else
417         AC_MSG_RESULT(yes)
418     fi
419     rm -f conftest conftest.c conftest.o
420 ], [CFLAGS="$BAKCFLAGS" ; AC_MSG_RESULT(no)])
421 ])
422
423 dnl Check the printf-format attribute (if any)
424 dnl result in HAVE_ATTR_FORMAT.  
425 dnl Make sure you also include the AHX_CONFIG_FORMAT_ATTRIBUTE.
426 AC_DEFUN([ACX_CHECK_FORMAT_ATTRIBUTE],
427 [AC_REQUIRE([AC_PROG_CC])
428 AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute)
429 AC_CACHE_VAL(ac_cv_c_format_attribute,
430 [ac_cv_c_format_attribute=no
431 AC_TRY_COMPILE(
432 [#include <stdio.h>
433 void f (char *format, ...) __attribute__ ((format (printf, 1, 2)));
434 void (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2)));
435 ], [
436    f ("%s", "str");
437 ],
438 [ac_cv_c_format_attribute="yes"],
439 [ac_cv_c_format_attribute="no"])
440 ])
441
442 AC_MSG_RESULT($ac_cv_c_format_attribute)
443 if test $ac_cv_c_format_attribute = yes; then
444   AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute])
445 fi
446 ])dnl End of ACX_CHECK_FORMAT_ATTRIBUTE
447
448 dnl Setup ATTR_FORMAT config.h parts.
449 dnl make sure you call ACX_CHECK_FORMAT_ATTRIBUTE also.
450 AC_DEFUN([AHX_CONFIG_FORMAT_ATTRIBUTE],
451
452 #ifdef HAVE_ATTR_FORMAT
453 #  define ATTR_FORMAT(archetype, string_index, first_to_check) \
454     __attribute__ ((format (archetype, string_index, first_to_check)))
455 #else /* !HAVE_ATTR_FORMAT */
456 #  define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */
457 #endif /* !HAVE_ATTR_FORMAT */
458 ])
459
460 dnl Check how to mark function arguments as unused.
461 dnl result in HAVE_ATTR_UNUSED.  
462 dnl Make sure you include AHX_CONFIG_UNUSED_ATTRIBUTE also.
463 AC_DEFUN([ACX_CHECK_UNUSED_ATTRIBUTE],
464 [AC_REQUIRE([AC_PROG_CC])
465 AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute)
466 AC_CACHE_VAL(ac_cv_c_unused_attribute,
467 [ac_cv_c_unused_attribute=no
468 AC_TRY_COMPILE(
469 [#include <stdio.h>
470 void f (char *u __attribute__((unused)));
471 ], [
472    f ("x");
473 ],
474 [ac_cv_c_unused_attribute="yes"],
475 [ac_cv_c_unused_attribute="no"])
476 ])
477
478 dnl Setup ATTR_UNUSED config.h parts.
479 dnl make sure you call ACX_CHECK_UNUSED_ATTRIBUTE also.
480 AC_DEFUN([AHX_CONFIG_UNUSED_ATTRIBUTE],
481 [
482 #if defined(DOXYGEN)
483 #  define ATTR_UNUSED(x)  x
484 #elif defined(__cplusplus)
485 #  define ATTR_UNUSED(x)
486 #elif defined(HAVE_ATTR_UNUSED)
487 #  define ATTR_UNUSED(x)  x __attribute__((unused))
488 #else /* !HAVE_ATTR_UNUSED */
489 #  define ATTR_UNUSED(x)  x
490 #endif /* !HAVE_ATTR_UNUSED */
491 ])
492
493 AC_MSG_RESULT($ac_cv_c_unused_attribute)
494 if test $ac_cv_c_unused_attribute = yes; then
495   AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute])
496 fi
497 ])dnl
498
499 dnl Pre-fun for ACX_LIBTOOL_C_ONLY
500 AC_DEFUN([ACX_LIBTOOL_C_PRE], [
501 # skip these tests, we do not need them.
502 AC_DEFUN([AC_PROG_F77], [:])
503 AC_DEFUN([AC_PROG_FC], [:])
504 AC_DEFUN([AC_PROG_CXX], [:])
505 AC_DEFUN([AC_PROG_CXXCPP], [:])
506 AC_DEFUN([AC_PROG_OBJC], [:])
507 AC_DEFUN([AC_PROG_OBJCCPP], [:])
508 AC_DEFUN([AC_LIBTOOL_CXX], [:])
509 AC_DEFUN([AC_LIBTOOL_F77], [:])
510 # always use ./libtool unless override from commandline (libtool=mylibtool)
511 if test -z "$libtool"; then
512         libtool="./libtool"
513 fi
514 AC_SUBST(libtool)
515 # avoid libtool max commandline length test on systems that fork slowly.
516 AC_CANONICAL_HOST
517 if echo "$host_os" | grep "sunos4" >/dev/null; then
518         lt_cv_sys_max_cmd_len=32750;
519 fi
520 AC_PATH_TOOL(AR, ar, [false])
521 if test $AR = false; then
522         AC_MSG_ERROR([Cannot find 'ar', please extend PATH to include it])
523 fi
524 ])
525
526 dnl Perform libtool check, portably, only for C
527 AC_DEFUN([ACX_LIBTOOL_C_ONLY], [
528 dnl as a requirement so that is gets called before LIBTOOL
529 dnl because libtools 'AC_REQUIRE' names are right after this one, before
530 dnl this function contents.
531 AC_REQUIRE([ACX_LIBTOOL_C_PRE])
532 AC_PROG_LIBTOOL
533 ])
534
535 dnl Detect if u_char type is defined, otherwise define it.
536 AC_DEFUN([ACX_TYPE_U_CHAR], 
537 [AC_CHECK_TYPE([u_char], ,
538         [AC_DEFINE([u_char], [unsigned char], [Define to 'unsigned char if not defined])], [
539 AC_INCLUDES_DEFAULT
540 #ifdef HAVE_WINSOCK2_H
541 #  include <winsock2.h>
542 #endif
543 ]) ])
544
545 dnl Detect if rlim_t type is defined, otherwise define it.
546 AC_DEFUN([ACX_TYPE_RLIM_T],
547 [AC_CHECK_TYPE(rlim_t, , 
548         [AC_DEFINE([rlim_t], [unsigned long], [Define to 'int' if not defined])], [
549 AC_INCLUDES_DEFAULT
550 #ifdef HAVE_SYS_RESOURCE_H
551 #  include <sys/resource.h>
552 #endif
553 ]) ])
554
555 dnl Detect if socklen_t type is defined, otherwise define it.
556 AC_DEFUN([ACX_TYPE_SOCKLEN_T],
557 [
558 AC_CHECK_TYPE(socklen_t, , 
559         [AC_DEFINE([socklen_t], [int], [Define to 'int' if not defined])], [
560 AC_INCLUDES_DEFAULT
561 #ifdef HAVE_SYS_SOCKET_H
562 #  include <sys/socket.h>
563 #endif
564 #ifdef HAVE_WS2TCPIP_H
565 #  include <ws2tcpip.h>
566 #endif
567 ]) ])
568
569 dnl Detect if in_addr_t type is defined, otherwise define it.
570 AC_DEFUN([ACX_TYPE_IN_ADDR_T],
571 [ AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [
572 AC_INCLUDES_DEFAULT
573 #ifdef HAVE_SYS_TYPES_H
574 # include <sys/types.h>
575 #endif
576 #ifdef HAVE_NETINET_IN_H
577 # include <netinet/in.h>
578 #endif
579 ]) ])
580
581 dnl Detect if in_port_t type is defined, otherwise define it.
582 AC_DEFUN([ACX_TYPE_IN_PORT_T],
583 [ AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])], [
584 AC_INCLUDES_DEFAULT
585 #ifdef HAVE_SYS_TYPES_H
586 # include <sys/types.h>
587 #endif
588 #ifdef HAVE_NETINET_IN_H
589 # include <netinet/in.h>
590 #endif
591 ]) ])
592
593 dnl Add option to disable the evil rpath. Check whether to use rpath or not.
594 dnl Adds the --disable-rpath option. Uses trick to edit the ./libtool.
595 AC_DEFUN([ACX_ARG_RPATH],
596 [
597 AC_ARG_ENABLE(rpath,
598         [  --disable-rpath         disable hardcoded rpath (default=enabled)],
599         enable_rpath=$enableval, enable_rpath=yes)
600 if test "x$enable_rpath" = xno; then
601         dnl AC_MSG_RESULT([Fixing libtool for -rpath problems.])
602         AC_CONFIG_COMMANDS([disable-rpath], [
603         sed < libtool > libtool-2 \
604         's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_RPATH_SED__ "/'
605         mv libtool-2 libtool
606         chmod 755 libtool
607         libtool="./libtool"
608         ])
609 fi
610 ])
611
612 dnl Add a -R to the RUNTIME_PATH.  Only if rpath is enabled and it is
613 dnl an absolute path.
614 dnl $1: the pathname to add.
615 AC_DEFUN([ACX_RUNTIME_PATH_ADD], [
616         if test "x$enable_rpath" = xyes; then
617                 if echo "$1" | grep "^/" >/dev/null; then
618                         RUNTIME_PATH="$RUNTIME_PATH -R$1"
619                 fi
620         fi
621 ])
622
623 dnl Common code for both ACX_WITH_SSL and ACX_WITH_SSL_OPTIONAL
624 dnl Takes one argument; the withval checked in those 2 functions
625 dnl sets up the environment for the given openssl path
626 AC_DEFUN([ACX_SSL_CHECKS], [
627     withval=$1
628     if test x_$withval != x_no; then
629         AC_MSG_CHECKING(for SSL)
630         if test x_$withval = x_ -o x_$withval = x_yes; then
631             withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr"
632         fi
633         for dir in $withval; do
634             ssldir="$dir"
635             if test -f "$dir/include/openssl/ssl.h"; then
636                 found_ssl="yes"
637                 AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.])
638                 dnl assume /usr/include is already in the include-path.
639                 if test "$ssldir" != "/usr"; then
640                         CPPFLAGS="$CPPFLAGS -I$ssldir/include"
641                         LIBSSL_CPPFLAGS="$LIBSSL_CPPFLAGS -I$ssldir/include"
642                 fi
643                 break;
644             fi
645         done
646         if test x_$found_ssl != x_yes; then
647             AC_MSG_ERROR(Cannot find the SSL libraries in $withval)
648         else
649             AC_MSG_RESULT(found in $ssldir)
650             HAVE_SSL=yes
651             dnl assume /usr is already in the lib and dynlib paths.
652             if test "$ssldir" != "/usr" -a "$ssldir" != ""; then
653                 LDFLAGS="$LDFLAGS -L$ssldir/lib"
654                 LIBSSL_LDFLAGS="$LIBSSL_LDFLAGS -L$ssldir/lib"
655                 ACX_RUNTIME_PATH_ADD([$ssldir/lib])
656             fi
657         
658             AC_MSG_CHECKING([for HMAC_CTX_init in -lcrypto])
659             LIBS="$LIBS -lcrypto"
660             LIBSSL_LIBS="$LIBSSL_LIBS -lcrypto"
661             AC_TRY_LINK(, [
662                 int HMAC_CTX_init(void);
663                 (void)HMAC_CTX_init();
664               ], [
665                 AC_MSG_RESULT(yes)
666                 AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 
667                           [If you have HMAC_CTX_init])
668               ], [
669                 AC_MSG_RESULT(no)
670                 # check if -lwsock32 or -lgdi32 are needed.     
671                 BAKLIBS="$LIBS"
672                 BAKSSLLIBS="$LIBSSL_LIBS"
673                 LIBS="$LIBS -lgdi32"
674                 LIBSSL_LIBS="$LIBSSL_LIBS -lgdi32"
675                 AC_MSG_CHECKING([if -lcrypto needs -lgdi32])
676                 AC_TRY_LINK([], [
677                     int HMAC_CTX_init(void);
678                     (void)HMAC_CTX_init();
679                   ],[
680                     AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 
681                         [If you have HMAC_CTX_init])
682                     AC_MSG_RESULT(yes) 
683                   ],[
684                     AC_MSG_RESULT(no)
685                     LIBS="$BAKLIBS"
686                     LIBSSL_LIBS="$BAKSSLLIBS"
687                     LIBS="$LIBS -ldl"
688                     LIBSSL_LIBS="$LIBSSL_LIBS -ldl"
689                     AC_MSG_CHECKING([if -lcrypto needs -ldl])
690                     AC_TRY_LINK([], [
691                         int HMAC_CTX_init(void);
692                         (void)HMAC_CTX_init();
693                       ],[
694                         AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 
695                             [If you have HMAC_CTX_init])
696                         AC_MSG_RESULT(yes) 
697                       ],[
698                         AC_MSG_RESULT(no)
699                     AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required])
700                     ])
701                 ])
702             ])
703         fi
704         AC_SUBST(HAVE_SSL)
705         AC_SUBST(RUNTIME_PATH)
706         # openssl engine functionality needs dlopen().
707         BAKLIBS="$LIBS"
708         AC_SEARCH_LIBS([dlopen], [dl])
709         if test "$LIBS" != "$BAKLIBS"; then
710                 LIBSSL_LIBS="$LIBSSL_LIBS -ldl"
711         fi
712     fi
713 AC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT])
714 AC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT])
715 AC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT])
716 ])dnl End of ACX_SSL_CHECKS
717
718 dnl Check for SSL, where SSL is mandatory
719 dnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found
720 dnl Setup of CPPFLAGS, CFLAGS.  Adds -lcrypto to LIBS. 
721 dnl Checks main header files of SSL.
722 dnl
723 AC_DEFUN([ACX_WITH_SSL],
724 [
725 AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname],
726                                     [enable SSL (will check /usr/local/ssl
727                             /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr)]),[
728         ],[
729             withval="yes"
730         ])
731     if test x_$withval = x_no; then
732         AC_MSG_ERROR([Need SSL library to do digital signature cryptography])
733     fi
734     ACX_SSL_CHECKS($withval)
735 ])dnl End of ACX_WITH_SSL
736
737 dnl Check for SSL, where ssl is optional (--without-ssl is allowed)
738 dnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found
739 dnl Setup of CPPFLAGS, CFLAGS.  Adds -lcrypto to LIBS. 
740 dnl Checks main header files of SSL.
741 dnl
742 AC_DEFUN([ACX_WITH_SSL_OPTIONAL],
743 [
744 AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname],
745                                 [enable SSL (will check /usr/local/ssl
746                                 /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr)]),[
747         ],[
748             withval="yes"
749         ])
750     ACX_SSL_CHECKS($withval)
751 ])dnl End of ACX_WITH_SSL_OPTIONAL
752
753 dnl Setup to use -lssl
754 dnl To use -lcrypto, use the ACX_WITH_SSL setup (before this one).
755 AC_DEFUN([ACX_LIB_SSL],
756 [
757 # check if libssl needs libdl
758 BAKLIBS="$LIBS"
759 LIBS="-lssl $LIBS"
760 AC_MSG_CHECKING([if libssl needs libdl])
761 AC_TRY_LINK_FUNC([SSL_CTX_new], [
762         AC_MSG_RESULT([no])
763         LIBS="$BAKLIBS"
764 ] , [
765         AC_MSG_RESULT([yes])
766         LIBS="$BAKLIBS"
767         AC_SEARCH_LIBS([dlopen], [dl])
768 ]) ])dnl End of ACX_LIB_SSL
769
770 dnl Setup to use very large files (>2Gb).
771 dnl setups fseeko and its own
772 AC_DEFUN([ACX_SYS_LARGEFILE],
773 [
774 AC_SYS_LARGEFILE
775 dnl try to see if an additional _LARGEFILE_SOURCE 1 is needed to get fseeko
776 ACX_CHECK_COMPILER_FLAG_NEEDED(-D_LARGEFILE_SOURCE=1,
777 [
778 #include <stdio.h>
779 int test() {
780         int a = fseeko(stdin, 0, 0);
781         return a;
782 }
783 ], [CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE=1"])
784 ])
785
786 dnl Check getaddrinfo.
787 dnl Works on linux, solaris, bsd and windows(links winsock).
788 dnl defines HAVE_GETADDRINFO, USE_WINSOCK.
789 AC_DEFUN([ACX_CHECK_GETADDRINFO_WITH_INCLUDES],
790 [AC_REQUIRE([AC_PROG_CC])
791 AC_MSG_CHECKING(for getaddrinfo)
792 ac_cv_func_getaddrinfo=no
793 AC_LINK_IFELSE(
794 [AC_LANG_SOURCE([[
795 #ifdef __cplusplus
796 extern "C"
797 {
798 #endif
799 char* getaddrinfo();
800 char* (*f) () = getaddrinfo;
801 #ifdef __cplusplus
802 }
803 #endif
804 int main() {
805         ;
806         return 0;
807 }
808 ]])],
809 dnl this case on linux, solaris, bsd
810 [ac_cv_func_getaddrinfo="yes"
811 dnl see if on windows
812 if test "$ac_cv_header_windows_h" = "yes"; then
813         AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used])
814         USE_WINSOCK="1"
815         LIBS="$LIBS -lws2_32"
816 fi
817 ],
818 dnl no quick getaddrinfo, try mingw32 and winsock2 library.
819 ORIGLIBS="$LIBS"
820 LIBS="$LIBS -lws2_32"
821 AC_LINK_IFELSE(
822 [AC_LANG_PROGRAM(
823 [
824 #ifdef HAVE_WS2TCPIP_H
825 #include <ws2tcpip.h>
826 #endif
827 ],
828 [
829         (void)getaddrinfo(NULL, NULL, NULL, NULL);
830 ]
831 )],
832 [
833 ac_cv_func_getaddrinfo="yes"
834 dnl already: LIBS="$LIBS -lws2_32"
835 AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used])
836 USE_WINSOCK="1"
837 ],
838 [
839 ac_cv_func_getaddrinfo="no"
840 LIBS="$ORIGLIBS"
841 ])
842 )
843
844 AC_MSG_RESULT($ac_cv_func_getaddrinfo)
845 if test $ac_cv_func_getaddrinfo = yes; then
846   AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether getaddrinfo is available])
847 fi
848 ])dnl Endof AC_CHECK_GETADDRINFO_WITH_INCLUDES
849
850 dnl check if a function is deprecated. defines DEPRECATED_func in config.h.
851 dnl $1: function name
852 dnl $2: C-statement that calls the function.
853 dnl $3: includes for the program.
854 dnl $4: executes if yes
855 dnl $5: executes if no
856 AC_DEFUN([ACX_FUNC_DEPRECATED],
857 [
858 AC_REQUIRE([AC_PROG_CC])
859 AC_MSG_CHECKING(if $1 is deprecated)
860 cache=`echo $1 | sed 'y%.=/+-%___p_%'`
861 AC_CACHE_VAL(cv_cc_deprecated_$cache,
862 [
863 echo '$3' >conftest.c
864 echo 'void f(){ $2 }' >>conftest.c
865 if test -z "`$CC -c conftest.c 2>&1 | grep deprecated`"; then
866 eval "cv_cc_deprecated_$cache=no"
867 else
868 eval "cv_cc_deprecated_$cache=yes"
869 fi
870 rm -f conftest conftest.o conftest.c
871 ])
872 if eval "test \"`echo '$cv_cc_deprecated_'$cache`\" = yes"; then
873 AC_MSG_RESULT(yes)
874 AC_DEFINE_UNQUOTED(AS_TR_CPP([DEPRECATED_$1]), 1, [Whether $1 is deprecated])
875 :
876 $4
877 else
878 AC_MSG_RESULT(no)
879 :
880 $5
881 fi
882 ])dnl end of ACX_FUNC_DEPRECATED
883
884 dnl check if select and nonblocking sockets actually work.
885 dnl Needs fork(2) and select(2).
886 dnl defines NONBLOCKING_IS_BROKEN, and if that is true multiple reads from
887 dnl a nonblocking socket do not work, a new call to select is necessary.
888 AC_DEFUN([ACX_CHECK_NONBLOCKING_BROKEN],
889 [
890 AC_MSG_CHECKING([if nonblocking sockets work])
891 if echo $target | grep mingw32 >/dev/null; then 
892         AC_MSG_RESULT([no (windows)])
893         AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).])
894 else
895 AC_RUN_IFELSE([
896 AC_LANG_SOURCE([[
897 #include <stdio.h>
898 #include <string.h>
899 #include <stdlib.h>
900 #include <fcntl.h>
901 #include <errno.h>
902 #ifdef HAVE_SYS_TYPES_H
903 #include <sys/types.h>
904 #endif
905 #ifdef HAVE_SYS_SOCKET_H
906 #include <sys/socket.h>
907 #endif
908 #ifdef HAVE_NETINET_IN_H
909 #include <netinet/in.h>
910 #endif
911 #ifdef HAVE_ARPA_INET_H
912 #include <arpa/inet.h>
913 #endif
914 #ifdef HAVE_UNISTD_H
915 #include <unistd.h>
916 #endif
917 #ifdef HAVE_TIME_H
918 #include <time.h>
919 #endif
920
921 int main(void)
922 {
923         int port;
924         int sfd, cfd;
925         int num = 10;
926         int i, p;
927         struct sockaddr_in a;
928         /* test if select and nonblocking reads work well together */
929         /* open port.
930            fork child to send 10 messages.
931            select to read.
932            then try to nonblocking read the 10 messages
933            then, nonblocking read must give EAGAIN
934         */
935
936         port = 12345 + (time(0)%32);
937         sfd = socket(PF_INET, SOCK_DGRAM, 0);
938         if(sfd == -1) {
939                 perror("socket");
940                 return 1;
941         }
942         memset(&a, 0, sizeof(a));
943         a.sin_family = AF_INET;
944         a.sin_port = htons(port);
945         a.sin_addr.s_addr = inet_addr("127.0.0.1");
946         if(bind(sfd, (struct sockaddr*)&a, sizeof(a)) < 0) {
947                 perror("bind");
948                 return 1;
949         }
950         if(fcntl(sfd, F_SETFL, O_NONBLOCK) == -1) {
951                 perror("fcntl");
952                 return 1;
953         }
954
955         cfd = socket(PF_INET, SOCK_DGRAM, 0);
956         if(cfd == -1) {
957                 perror("client socket");
958                 return 1;
959         }
960         a.sin_port = 0;
961         if(bind(cfd, (struct sockaddr*)&a, sizeof(a)) < 0) {
962                 perror("client bind");
963                 return 1;
964         }
965         a.sin_port = htons(port);
966
967         /* no handler, causes exit in 10 seconds */
968         alarm(10);
969
970         /* send and receive on the socket */
971         if((p=fork()) == 0) {
972                 for(i=0; i<num; i++) {
973                         if(sendto(cfd, &i, sizeof(i), 0, 
974                                 (struct sockaddr*)&a, sizeof(a)) < 0) {
975                                 perror("sendto");
976                                 return 1;
977                         }
978                 }
979         } else {
980                 /* parent */
981                 fd_set rset;
982                 int x;
983                 if(p == -1) {
984                         perror("fork");
985                         return 1;
986                 }
987                 FD_ZERO(&rset);
988                 FD_SET(sfd, &rset);
989                 if(select(sfd+1, &rset, NULL, NULL, NULL) < 1) {
990                         perror("select");
991                         return 1;
992                 }
993                 i = 0;
994                 while(i < num) {
995                         if(recv(sfd, &x, sizeof(x), 0) != sizeof(x)) {
996                                 if(errno == EAGAIN)
997                                         continue;
998                                 perror("recv");
999                                 return 1;
1000                         }
1001                         i++;
1002                 }
1003                 /* now we want to get EAGAIN: nonblocking goodness */
1004                 errno = 0;
1005                 recv(sfd, &x, sizeof(x), 0);
1006                 if(errno != EAGAIN) {
1007                         perror("trying to recv again");
1008                         return 1;
1009                 }
1010                 /* EAGAIN encountered */
1011         }
1012
1013         close(sfd);
1014         close(cfd);
1015         return 0;
1016 }
1017 ]])], [
1018         AC_MSG_RESULT([yes])
1019 ], [
1020         AC_MSG_RESULT([no])
1021         AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).])
1022 ], [
1023         AC_MSG_RESULT([crosscompile(yes)])
1024 ])
1025 fi
1026 ])dnl End of ACX_CHECK_NONBLOCKING_BROKEN
1027
1028 dnl Check if mkdir has one or two arguments.
1029 dnl defines MKDIR_HAS_ONE_ARG
1030 AC_DEFUN([ACX_MKDIR_ONE_ARG],
1031 [
1032 AC_MSG_CHECKING([whether mkdir has one arg])
1033 AC_TRY_COMPILE([
1034 #include <stdio.h>
1035 #include <unistd.h>
1036 #ifdef HAVE_WINSOCK2_H
1037 #include <winsock2.h>
1038 #endif
1039 #ifdef HAVE_SYS_STAT_H
1040 #include <sys/stat.h>
1041 #endif
1042 ], [
1043         (void)mkdir("directory");
1044 ],
1045 AC_MSG_RESULT(yes)
1046 AC_DEFINE(MKDIR_HAS_ONE_ARG, 1, [Define if mkdir has one argument.])
1047 ,
1048 AC_MSG_RESULT(no)
1049 )
1050 ])dnl end of ACX_MKDIR_ONE_ARG
1051
1052 dnl Check for ioctlsocket function. works on mingw32 too.
1053 AC_DEFUN([ACX_FUNC_IOCTLSOCKET],
1054 [
1055 # check ioctlsocket
1056 AC_MSG_CHECKING(for ioctlsocket)
1057 AC_LINK_IFELSE([AC_LANG_PROGRAM([
1058 #ifdef HAVE_WINSOCK2_H
1059 #include <winsock2.h>
1060 #endif
1061 ], [
1062         (void)ioctlsocket(0, 0, NULL);
1063 ])], [
1064 AC_MSG_RESULT(yes)
1065 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [if the function 'ioctlsocket' is available])
1066 ],[AC_MSG_RESULT(no)])
1067 ])dnl end of ACX_FUNC_IOCTLSOCKET
1068
1069 dnl detect malloc and provide malloc compat prototype.
1070 dnl $1: unique name for compat code
1071 AC_DEFUN([ACX_FUNC_MALLOC],
1072 [
1073         AC_MSG_CHECKING([for GNU libc compatible malloc])
1074         AC_RUN_IFELSE([AC_LANG_PROGRAM(
1075 [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
1076 #include <stdlib.h>
1077 #else
1078 char *malloc ();
1079 #endif
1080 ]], [ if(malloc(0) != 0) return 1;])
1081 ],
1082         [AC_MSG_RESULT([no])
1083         AC_LIBOBJ(malloc)
1084         AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if  replacement function should be used.])] ,
1085         [AC_MSG_RESULT([yes])
1086         AC_DEFINE([HAVE_MALLOC], 1, [If have GNU libc compatible malloc])],
1087         [AC_MSG_RESULT([no (crosscompile)])
1088         AC_LIBOBJ(malloc)
1089         AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if  replacement function should be used.])] )
1090 ])
1091
1092 dnl Define fallback for fseeko and ftello if needed.
1093 AC_DEFUN([AHX_CONFIG_FSEEKO],
1094 [
1095 #ifndef HAVE_FSEEKO
1096 #define fseeko fseek
1097 #define ftello ftell
1098 #endif /* HAVE_FSEEKO */
1099 ])
1100
1101 dnl Define RAND_MAX if not defined
1102 AC_DEFUN([AHX_CONFIG_RAND_MAX],
1103 [
1104 #ifndef RAND_MAX
1105 #define RAND_MAX        2147483647
1106 #endif
1107 ])
1108
1109 dnl Define MAXHOSTNAMELEN if not defined
1110 AC_DEFUN([AHX_CONFIG_MAXHOSTNAMELEN],
1111 [
1112 #ifndef MAXHOSTNAMELEN
1113 #define MAXHOSTNAMELEN 256
1114 #endif
1115 ])
1116
1117 dnl Define IPV6_MIN_MTU if not defined
1118 AC_DEFUN([AHX_CONFIG_IPV6_MIN_MTU],
1119 [
1120 #ifndef IPV6_MIN_MTU
1121 #define IPV6_MIN_MTU 1280
1122 #endif /* IPV6_MIN_MTU */
1123 ])
1124
1125 dnl provide snprintf, vsnprintf compat prototype
1126 dnl $1: unique name for compat code
1127 AC_DEFUN([AHX_CONFIG_SNPRINTF],
1128 [
1129 #ifndef HAVE_SNPRINTF
1130 #define snprintf snprintf_$1
1131 #define vsnprintf vsnprintf_$1
1132 #include <stdarg.h>
1133 int snprintf (char *str, size_t count, const char *fmt, ...);
1134 int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
1135 #endif /* HAVE_SNPRINTF */
1136 ])
1137
1138 dnl provide inet_pton compat prototype.
1139 dnl $1: unique name for compat code
1140 AC_DEFUN([AHX_CONFIG_INET_PTON],
1141 [
1142 #ifndef HAVE_INET_PTON
1143 #define inet_pton inet_pton_$1
1144 int inet_pton(int af, const char* src, void* dst);
1145 #endif /* HAVE_INET_PTON */
1146 ])
1147
1148 dnl provide inet_ntop compat prototype.
1149 dnl $1: unique name for compat code
1150 AC_DEFUN([AHX_CONFIG_INET_NTOP],
1151 [
1152 #ifndef HAVE_INET_NTOP
1153 #define inet_ntop inet_ntop_$1
1154 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
1155 #endif
1156 ])
1157
1158 dnl provide inet_aton compat prototype.
1159 dnl $1: unique name for compat code
1160 AC_DEFUN([AHX_CONFIG_INET_ATON],
1161 [
1162 #ifndef HAVE_INET_ATON
1163 #define inet_aton inet_aton_$1
1164 int inet_aton(const char *cp, struct in_addr *addr);
1165 #endif
1166 ])
1167
1168 dnl provide memmove compat prototype.
1169 dnl $1: unique name for compat code
1170 AC_DEFUN([AHX_CONFIG_MEMMOVE],
1171 [
1172 #ifndef HAVE_MEMMOVE
1173 #define memmove memmove_$1
1174 void *memmove(void *dest, const void *src, size_t n);
1175 #endif
1176 ])
1177
1178 dnl provide strlcat compat prototype.
1179 dnl $1: unique name for compat code
1180 AC_DEFUN([AHX_CONFIG_STRLCAT],
1181 [
1182 #ifndef HAVE_STRLCAT
1183 #define strlcat strlcat_$1
1184 size_t strlcat(char *dst, const char *src, size_t siz);
1185 #endif
1186 ])
1187
1188 dnl provide strlcpy compat prototype.
1189 dnl $1: unique name for compat code
1190 AC_DEFUN([AHX_CONFIG_STRLCPY],
1191 [
1192 #ifndef HAVE_STRLCPY
1193 #define strlcpy strlcpy_$1
1194 size_t strlcpy(char *dst, const char *src, size_t siz);
1195 #endif
1196 ])
1197
1198 dnl provide gmtime_r compat prototype.
1199 dnl $1: unique name for compat code
1200 AC_DEFUN([AHX_CONFIG_GMTIME_R],
1201 [
1202 #ifndef HAVE_GMTIME_R
1203 #define gmtime_r gmtime_r_$1
1204 struct tm *gmtime_r(const time_t *timep, struct tm *result);
1205 #endif
1206 ])
1207
1208 dnl provide w32 compat definition for sleep
1209 AC_DEFUN([AHX_CONFIG_W32_SLEEP],
1210 [
1211 #ifndef HAVE_SLEEP
1212 #define sleep(x) Sleep((x)*1000) /* on win32 */
1213 #endif /* HAVE_SLEEP */
1214 ])
1215
1216 dnl provide w32 compat definition for usleep
1217 AC_DEFUN([AHX_CONFIG_W32_USLEEP],
1218 [
1219 #ifndef HAVE_USLEEP
1220 #define usleep(x) Sleep((x)/1000 + 1) /* on win32 */
1221 #endif /* HAVE_USLEEP */
1222 ])
1223
1224 dnl provide w32 compat definition for random
1225 AC_DEFUN([AHX_CONFIG_W32_RANDOM],
1226 [
1227 #ifndef HAVE_RANDOM
1228 #define random rand /* on win32, for tests only (bad random) */
1229 #endif /* HAVE_RANDOM */
1230 ])
1231
1232 dnl provide w32 compat definition for srandom
1233 AC_DEFUN([AHX_CONFIG_W32_SRANDOM],
1234 [
1235 #ifndef HAVE_SRANDOM
1236 #define srandom(x) srand(x) /* on win32, for tests only (bad random) */
1237 #endif /* HAVE_SRANDOM */
1238 ])
1239
1240 dnl provide w32 compat definition for FD_SET_T
1241 AC_DEFUN([AHX_CONFIG_W32_FD_SET_T],
1242 [
1243 /* detect if we need to cast to unsigned int for FD_SET to avoid warnings */
1244 #ifdef HAVE_WINSOCK2_H
1245 #define FD_SET_T (u_int)
1246 #else
1247 #define FD_SET_T 
1248 #endif
1249 ])
1250
1251 dnl Remove an extension flag from CFLAGS, define replacement to be made.
1252 dnl Used by ACX_STRIP_EXT_FLAGS.
1253 dnl $1: the name of the flag, for example -D_GNU_SOURCE.
1254 AC_DEFUN([ACX_CFLAGS_STRIP],
1255 [
1256   if echo $CFLAGS | grep " $1" >/dev/null 2>&1; then
1257     CFLAGS="`echo $CFLAGS | sed -e 's/ $1//g'`"
1258     AC_DEFINE(m4_bpatsubst(OMITTED_$1,[[-=]],_), 1, Put $1 define in config.h)
1259   fi
1260 ])
1261
1262 dnl Remove EXT flags from the CFLAGS and set them to be defined in config.h
1263 dnl use with ACX_DETERMINE_EXT_FLAGS.
1264 AC_DEFUN([ACX_STRIP_EXT_FLAGS],
1265 [
1266   AC_MSG_NOTICE([Stripping extension flags...])
1267   ACX_CFLAGS_STRIP(-D_GNU_SOURCE)
1268   ACX_CFLAGS_STRIP(-D_BSD_SOURCE)
1269   ACX_CFLAGS_STRIP(-D__EXTENSIONS__)
1270   ACX_CFLAGS_STRIP(-D_POSIX_C_SOURCE=200112)
1271   ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE=600)
1272   ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE_EXTENDED=1)
1273   ACX_CFLAGS_STRIP(-D_ALL_SOURCE)
1274   ACX_CFLAGS_STRIP(-D_LARGEFILE_SOURCE=1)
1275 ]) dnl End of ACX_STRIP_EXT_FLAGS
1276
1277 dnl define one omitted flag for config.h
1278 dnl $1: flag name. -D_GNU_SOURCE
1279 dnl $2: replacement define. _GNU_SOURCE
1280 dnl $3: define value, 1
1281 AC_DEFUN([AHX_CONFIG_FLAG_OMITTED],
1282 [#if defined($1) && !defined($2)
1283 #define $2 $3
1284 [#]endif ])
1285
1286 dnl Wrapper for AHX_CONFIG_FLAG_OMITTED for -D style flags
1287 dnl $1: the -DNAME or -DNAME=value string.
1288 AC_DEFUN([AHX_CONFIG_FLAG_EXT],
1289 [AHX_CONFIG_FLAG_OMITTED(m4_bpatsubst(OMITTED_$1,[[-=]],_),m4_bpatsubst(m4_bpatsubst($1,-D,),=.*$,),m4_if(m4_bregexp($1,=),-1,1,m4_bpatsubst($1,^.*=,)))
1290 ])
1291
1292 dnl config.h part to define omitted cflags, use with ACX_STRIP_EXT_FLAGS.
1293 AC_DEFUN([AHX_CONFIG_EXT_FLAGS],
1294 [AHX_CONFIG_FLAG_EXT(-D_GNU_SOURCE)
1295 AHX_CONFIG_FLAG_EXT(-D_BSD_SOURCE)
1296 AHX_CONFIG_FLAG_EXT(-D__EXTENSIONS__)
1297 AHX_CONFIG_FLAG_EXT(-D_POSIX_C_SOURCE=200112)
1298 AHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE=600)
1299 AHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE_EXTENDED=1)
1300 AHX_CONFIG_FLAG_EXT(-D_ALL_SOURCE)
1301 AHX_CONFIG_FLAG_EXT(-D_LARGEFILE_SOURCE=1)
1302 ])
1303
1304 dnl check if memcmp is using signed characters and replace if so.
1305 AC_DEFUN([ACX_CHECK_MEMCMP_SIGNED],
1306 [AC_MSG_CHECKING([if memcmp compares unsigned])
1307 AC_RUN_IFELSE([AC_LANG_SOURCE([[
1308 #include <stdio.h>
1309 #include <stdlib.h>
1310 #include <string.h>
1311 int main(void)
1312 {
1313         char a = 255, b = 0;
1314         if(memcmp(&a, &b, 1) < 0)
1315                 return 1;
1316         return 0;
1317 }
1318 ]])], [AC_MSG_RESULT([yes]) ],
1319 [ AC_MSG_RESULT([no])
1320   AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes])
1321   AC_LIBOBJ([memcmp])
1322 ], [ AC_MSG_RESULT([cross-compile no])
1323   AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes])
1324   AC_LIBOBJ([memcmp]) 
1325 ]) ])
1326
1327 dnl define memcmp to its replacement, pass unique id for program as arg
1328 AC_DEFUN([AHX_MEMCMP_BROKEN], [
1329 #ifdef MEMCMP_IS_BROKEN
1330 #include "compat/memcmp.h"
1331 #define memcmp memcmp_$1
1332 int memcmp(const void *x, const void *y, size_t n);
1333 #endif
1334 ])
1335
1336 dnl ACX_CHECK_SS_FAMILY           - check for sockaddr_storage.ss_family
1337 AC_DEFUN([ACX_CHECK_SS_FAMILY],
1338 [AC_CHECK_MEMBER([struct sockaddr_storage.ss_family], [], [
1339         AC_CHECK_MEMBER([struct sockaddr_storage.__ss_family], [
1340                 AC_DEFINE([ss_family], [__ss_family], [Fallback member name for socket family in struct sockaddr_storage])
1341         ],, [AC_INCLUDES_DEFAULT
1342 #ifdef HAVE_NETINET_IN_H
1343 #include <netinet/in.h>
1344 #endif
1345 #ifdef HAVE_SYS_SOCKET_H
1346 #include <sys/socket.h>
1347 #endif
1348 #ifdef HAVE_NETDB_H
1349 #include <netdb.h>
1350 #endif
1351 #ifdef HAVE_ARPA_INET_H
1352 #include <arpa/inet.h>
1353 #endif
1354     ])
1355 ], [AC_INCLUDES_DEFAULT
1356 #ifdef HAVE_NETINET_IN_H
1357 #include <netinet/in.h>
1358 #endif
1359 #ifdef HAVE_SYS_SOCKET_H
1360 #include <sys/socket.h>
1361 #endif
1362 #ifdef HAVE_NETDB_H
1363 #include <netdb.h>
1364 #endif
1365 #ifdef HAVE_ARPA_INET_H
1366 #include <arpa/inet.h>
1367 #endif
1368 ]) ])
1369
1370 dnl End of file