1 # acx_nlnetlabs.m4 - common macros for configure checks
2 # Copyright 2009, Wouter Wijngaards, NLnet Labs.
6 # 2021-08-17 fix sed script in ssldir split handling.
7 # 2021-08-17 fix for openssl to detect split version, with ssldir_include
8 # and ssldir_lib output directories.
9 # 2021-07-30 fix for openssl use of lib64 directory.
10 # 2021-06-14 fix nonblocking test to use host instead of target for mingw test.
11 # 2021-05-17 fix nonblocking socket test from grep on mingw32 to mingw for
12 # 64bit compatibility.
13 # 2021-03-24 fix ACX_FUNC_DEPRECATED to use CPPFLAGS and CFLAGS.
14 # 2021-01-05 fix defun for aclocal
15 # 2021-01-05 autoconf 2.70 autoupdate and fixes, no AC_TRY_COMPILE
16 # 2020-08-24 Use EVP_sha256 instead of HMAC_Update (for openssl-3.0.0).
17 # 2016-03-21 Check -ldl -pthread for libcrypto for ldns and openssl 1.1.0.
18 # 2016-03-21 Use HMAC_Update instead of HMAC_CTX_Init (for openssl-1.1.0).
19 # 2016-01-04 -D_DEFAULT_SOURCE defined with -D_BSD_SOURCE for Linux glibc 2.20
20 # 2015-12-11 FLTO check for new OSX, clang.
21 # 2015-11-18 spelling check fix.
22 # 2015-11-05 ACX_SSL_CHECKS no longer adds -ldl needlessly.
23 # 2015-08-28 ACX_CHECK_PIE and ACX_CHECK_RELRO_NOW added.
24 # 2015-03-17 AHX_CONFIG_REALLOCARRAY added
25 # 2013-09-19 FLTO help text improved.
26 # 2013-07-18 Enable ACX_CHECK_COMPILER_FLAG to test for -Wstrict-prototypes
27 # 2013-06-25 FLTO has --disable-flto option.
28 # 2013-05-03 Update W32_SLEEP for newer mingw that links but not defines it.
29 # 2013-03-22 Fix ACX_RSRC_VERSION for long version numbers.
30 # 2012-02-09 Fix AHX_MEMCMP_BROKEN with undef in compat/memcmp.h.
31 # 2012-01-20 Fix COMPILER_FLAGS_UNBOUND for gcc 4.6.2 assigned-not-used-warns.
32 # 2011-12-05 Fix getaddrinfowithincludes on windows with fedora16 mingw32-gcc.
33 # Fix ACX_MALLOC for redefined malloc error.
34 # Fix GETADDRINFO_WITH_INCLUDES to add -lws2_32
35 # 2011-11-10 Fix FLTO test to not drop a.out in current directory.
36 # 2011-11-01 Fix FLTO test for llvm on Lion.
37 # 2011-08-01 Fix nonblock test (broken at v13).
38 # 2011-08-01 Fix autoconf 2.68 warnings
39 # 2011-06-23 Add ACX_CHECK_FLTO to check -flto.
40 # 2010-08-16 Fix FLAG_OMITTED for AS_TR_CPP changes in autoconf-2.66.
41 # 2010-07-02 Add check for ss_family (for minix).
42 # 2010-04-26 Fix to use CPPFLAGS for CHECK_COMPILER_FLAGS.
43 # 2010-03-01 Fix RPATH using CONFIG_COMMANDS to run at the very end.
44 # 2010-02-18 WITH_SSL outputs the LIBSSL_LDFLAGS, LIBS, CPPFLAGS separate, -ldl
45 # 2010-02-01 added ACX_CHECK_MEMCMP_SIGNED, AHX_MEMCMP_BROKEN
46 # 2010-01-20 added AHX_COONFIG_STRLCAT
47 # 2009-07-14 U_CHAR detection improved for windows crosscompile.
48 # added ACX_FUNC_MALLOC
49 # fixup some #if to #ifdef
50 # NONBLOCKING test for mingw crosscompile.
51 # 2009-07-13 added ACX_WITH_SSL_OPTIONAL
52 # 2009-07-03 fixup LDFLAGS for empty ssl dir.
54 # Automates some of the checking constructs. Aims at portability for POSIX.
55 # Documentation for functions is below.
57 # the following macro's are provided in this file:
58 # (see below for details on each macro).
60 # ACX_ESCAPE_BACKSLASH - escape backslashes in var for C-preproc.
61 # ACX_RSRC_VERSION - create windows resource version number.
62 # ACX_CHECK_COMPILER_FLAG - see if cc supports a flag.
63 # ACX_CHECK_ERROR_FLAGS - see which flag is -werror (used below).
64 # ACX_CHECK_COMPILER_FLAG_NEEDED - see if flags make the code compile cleanly.
65 # ACX_DEPFLAG - find cc dependency flags.
66 # ACX_DETERMINE_EXT_FLAGS_UNBOUND - find out which flags enable BSD and POSIX.
67 # ACX_CHECK_FORMAT_ATTRIBUTE - find cc printf format syntax.
68 # ACX_CHECK_UNUSED_ATTRIBUTE - find cc variable unused syntax.
69 # ACX_CHECK_FLTO - see if cc supports -flto and use it if so.
70 # ACX_LIBTOOL_C_ONLY - create libtool for C only, improved.
71 # ACX_TYPE_U_CHAR - u_char type.
72 # ACX_TYPE_RLIM_T - rlim_t type.
73 # ACX_TYPE_SOCKLEN_T - socklen_t type.
74 # ACX_TYPE_IN_ADDR_T - in_addr_t type.
75 # ACX_TYPE_IN_PORT_T - in_port_t type.
76 # ACX_ARG_RPATH - add --disable-rpath option.
77 # ACX_WITH_SSL - add --with-ssl option, link -lcrypto.
78 # ACX_WITH_SSL_OPTIONAL - add --with-ssl option, link -lcrypto,
79 # where --without-ssl is also accepted
80 # ACX_LIB_SSL - setup to link -lssl.
81 # ACX_SYS_LARGEFILE - improved sys_largefile, fseeko, >2G files.
82 # ACX_CHECK_GETADDRINFO_WITH_INCLUDES - find getaddrinfo, portably.
83 # ACX_FUNC_DEPRECATED - see if func is deprecated.
84 # ACX_CHECK_NONBLOCKING_BROKEN - see if nonblocking sockets really work.
85 # ACX_MKDIR_ONE_ARG - determine mkdir(2) number of arguments.
86 # ACX_FUNC_IOCTLSOCKET - find ioctlsocket, portably.
87 # ACX_FUNC_MALLOC - check malloc, define replacement .
88 # AHX_CONFIG_FORMAT_ATTRIBUTE - config.h text for format.
89 # AHX_CONFIG_UNUSED_ATTRIBUTE - config.h text for unused.
90 # AHX_CONFIG_FSEEKO - define fseeko, ftello fallback.
91 # AHX_CONFIG_RAND_MAX - define RAND_MAX if needed.
92 # AHX_CONFIG_MAXHOSTNAMELEN - define MAXHOSTNAMELEN if needed.
93 # AHX_CONFIG_IPV6_MIN_MTU - define IPV6_MIN_MTU if needed.
94 # AHX_CONFIG_SNPRINTF - snprintf compat prototype
95 # AHX_CONFIG_INET_PTON - inet_pton compat prototype
96 # AHX_CONFIG_INET_NTOP - inet_ntop compat prototype
97 # AHX_CONFIG_INET_ATON - inet_aton compat prototype
98 # AHX_CONFIG_MEMMOVE - memmove compat prototype
99 # AHX_CONFIG_STRLCAT - strlcat compat prototype
100 # AHX_CONFIG_STRLCPY - strlcpy compat prototype
101 # AHX_CONFIG_GMTIME_R - gmtime_r compat prototype
102 # AHX_CONFIG_W32_SLEEP - w32 compat for sleep
103 # AHX_CONFIG_W32_USLEEP - w32 compat for usleep
104 # AHX_CONFIG_W32_RANDOM - w32 compat for random
105 # AHX_CONFIG_W32_SRANDOM - w32 compat for srandom
106 # AHX_CONFIG_W32_FD_SET_T - w32 detection of FD_SET_T.
107 # ACX_CFLAGS_STRIP - strip one flag from CFLAGS
108 # ACX_STRIP_EXT_FLAGS - strip extension flags from CFLAGS
109 # AHX_CONFIG_FLAG_OMITTED - define omitted flag
110 # AHX_CONFIG_FLAG_EXT - define omitted extension flag
111 # AHX_CONFIG_EXT_FLAGS - define the stripped extension flags
112 # ACX_CHECK_MEMCMP_SIGNED - check if memcmp uses signed characters.
113 # AHX_MEMCMP_BROKEN - replace memcmp func for CHECK_MEMCMP_SIGNED.
114 # ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family
115 # ACX_CHECK_PIE - add --enable-pie option and check if works
116 # ACX_CHECK_RELRO_NOW - add --enable-relro-now option and check it
119 dnl Escape backslashes as \\, for C:\ paths, for the C preprocessor defines.
120 dnl for example, ACX_ESCAPE_BACKSLASH($from_var, to_var)
121 dnl $1: the text to change.
123 AC_DEFUN([ACX_ESCAPE_BACKSLASH], [$2="`echo $1 | sed -e 's/\\\\/\\\\\\\\/g'`"
126 dnl Calculate comma separated windows-resource numbers from package version.
127 dnl Picks the first three(,0) or four numbers out of the name.
128 dnl $1: variable for the result
129 AC_DEFUN([ACX_RSRC_VERSION],
130 [$1=[`echo $PACKAGE_VERSION | sed -e 's/^[^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\)[^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]*\)[^0-9][^0-9]*\([0-9][0-9]*\)[^0-9]*$/\1,\2,\3,0/' `]
133 dnl Routine to help check for compiler flags.
134 dnl Checks if the compiler will accept the flag.
135 dnl $1: the flag without a - in front, so g to check -g.
136 dnl $2: executed if yes
137 dnl $3: executed if no
138 AC_DEFUN([ACX_CHECK_COMPILER_FLAG],
140 AC_REQUIRE([AC_PROG_CC])
141 AC_MSG_CHECKING(whether $CC supports -$1)
142 cache=`echo $1 | sed 'y%.=/+-%___p_%'`
143 AC_CACHE_VAL(cv_prog_cc_flag_$cache,
145 echo 'void f(void){}' >conftest.c
146 if test -z "`$CC $CPPFLAGS $CFLAGS -$1 -c conftest.c 2>&1`"; then
147 eval "cv_prog_cc_flag_$cache=yes"
149 eval "cv_prog_cc_flag_$cache=no"
151 rm -f conftest conftest.o conftest.c
153 if eval "test \"`echo '$cv_prog_cc_flag_'$cache`\" = yes"; then
164 dnl setup flags for ACX_CHECK_COMPILER_FLAG_NEEDED
165 dnl ERRFLAG: result, compiler flag to turn warnings into errors
166 AC_DEFUN([ACX_CHECK_ERROR_FLAGS],
168 ACX_CHECK_COMPILER_FLAG(Werror, [ERRFLAG="-Werror"], [ERRFLAG="-errwarn"])
169 ACX_CHECK_COMPILER_FLAG(Wall, [ERRFLAG="$ERRFLAG -Wall"],
170 [ERRFLAG="$ERRFLAG -errfmt"])
173 dnl Routine to help check for needed compiler flags.
175 dnl $2: the includes and code
176 dnl $3: if the given code only compiles with the flag, execute argument 3
177 dnl $4: if the given code compiles without the flag, execute argument 4
178 dnl $5: with and without flag the compile fails, execute argument 5.
179 AC_DEFUN([ACX_CHECK_COMPILER_FLAG_NEEDED],
181 AC_REQUIRE([AC_PROG_CC])
182 AC_REQUIRE([ACX_CHECK_ERROR_FLAGS])
183 AC_MSG_CHECKING(whether we need $1 as a flag for $CC)
185 dnl cache=`echo $1 | sed 'y%.=/+- %___p__%'`
186 AC_CACHE_VAL(cv_prog_cc_flag_needed_$cache,
188 echo '$2' > conftest.c
189 echo 'void f(){}' >>conftest.c
190 if test -z "`$CC $CPPFLAGS $CFLAGS $ERRFLAG -c conftest.c 2>&1`"; then
191 eval "cv_prog_cc_flag_needed_$cache=no"
194 if test -z "`$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`"; then
195 eval "cv_prog_cc_flag_needed_$cache=yes"
197 eval "cv_prog_cc_flag_needed_$cache=fail"
198 #echo 'Test with flag fails too!'
200 #echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1"
201 #echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`
206 rm -f conftest conftest.c conftest.o
208 if eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = yes"; then
213 if eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = no"; then
215 #echo 'Test with flag is no!'
217 #echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1"
218 #echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`
223 AC_MSG_RESULT(failed)
230 dnl Check for CC dependency flag
231 dnl DEPFLAG: set to flag that generates dependencies.
232 AC_DEFUN([ACX_DEPFLAG],
234 AC_MSG_CHECKING([$CC dependency flag])
235 echo 'void f(){}' >conftest.c
236 if test "`$CC -MM conftest.c 2>&1`" = "conftest.o: conftest.c"; then
239 if test "`$CC -xM1 conftest.c 2>&1`" = "conftest.o: conftest.c"; then
242 DEPFLAG="-MM" # dunno do something
245 AC_MSG_RESULT($DEPFLAG)
250 dnl Determine flags that gives POSIX and BSD functionality.
251 dnl CFLAGS is modified for the result.
252 AC_DEFUN([ACX_DETERMINE_EXT_FLAGS_UNBOUND],
254 ACX_CHECK_COMPILER_FLAG(std=c99, [C99FLAG="-std=c99"])
255 ACX_CHECK_COMPILER_FLAG(xc99, [C99FLAG="-xc99"])
257 AC_CHECK_HEADERS([getopt.h time.h],,, [AC_INCLUDES_DEFAULT])
259 ACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_ALL_SOURCE,
261 #include "confdefs.h"
264 #include <sys/time.h>
281 const char* str = NULL;
284 t = ctime_r(&time, buf);
287 a = getopt(2, opts, "a");
289 str = gai_strerror(0);
290 if(str && t && tv.tv_usec && msg.msg_control)
294 ], [CFLAGS="$CFLAGS $C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_ALL_SOURCE"])
296 ACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE,
298 #include "confdefs.h"
301 #include <sys/time.h>
318 const char* str = NULL;
321 t = ctime_r(&time, buf);
324 a = getopt(2, opts, "a");
326 str = gai_strerror(0);
327 if(str && t && tv.tv_usec && msg.msg_control)
331 ], [CFLAGS="$CFLAGS $C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE"])
333 ACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG,
341 ], [CFLAGS="$CFLAGS $C99FLAG"])
343 ACX_CHECK_COMPILER_FLAG_NEEDED(-D_BSD_SOURCE -D_DEFAULT_SOURCE,
352 ], [CFLAGS="$CFLAGS -D_BSD_SOURCE -D_DEFAULT_SOURCE"])
354 ACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE,
356 #include <netinet/in.h>
359 struct in6_pktinfo inf;
360 int a = (int)sizeof(inf);
363 ], [CFLAGS="$CFLAGS -D_GNU_SOURCE"])
365 # check again for GNU_SOURCE for setresgid. May fail if setresgid
366 # is not available at all. -D_FRSRESGID is to make this check unique.
367 # otherwise we would get the previous cached result.
368 ACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE -D_FRSRESGID,
373 int a = setresgid(0,0,0);
374 a = setresuid(0,0,0);
377 ], [CFLAGS="$CFLAGS -D_GNU_SOURCE"])
379 ACX_CHECK_COMPILER_FLAG_NEEDED(-D_POSIX_C_SOURCE=200112,
381 #include "confdefs.h"
392 const char* str = NULL;
393 t = ctime_r(&time, buf);
394 str = gai_strerror(0);
399 ], [CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112"])
401 ACX_CHECK_COMPILER_FLAG_NEEDED(-D__EXTENSIONS__,
403 #include "confdefs.h"
406 #include <sys/time.h>
421 a = getopt(2, opts, "a");
427 ], [CFLAGS="$CFLAGS -D__EXTENSIONS__"])
429 ])dnl End of ACX_DETERMINE_EXT_FLAGS_UNBOUND
431 dnl Check if CC supports -flto.
432 dnl in a way that supports clang and suncc (that flag does something else,
433 dnl but fails to link). It sets it in CFLAGS if it works.
434 AC_DEFUN([ACX_CHECK_FLTO], [
435 AC_ARG_ENABLE([flto], AS_HELP_STRING([--disable-flto], [Disable link-time optimization (gcc specific option)]))
436 AS_IF([test "x$enable_flto" != "xno"], [
437 AC_MSG_CHECKING([if $CC supports -flto])
439 CFLAGS="$CFLAGS -flto"
440 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [
441 if $CC $CFLAGS -o conftest conftest.c 2>&1 | $GREP -e "warning: no debug symbols in executable" -e "warning: object" >/dev/null; then
447 rm -f conftest conftest.c conftest.o
448 ], [CFLAGS="$BAKCFLAGS" ; AC_MSG_RESULT(no)])
452 dnl Check the printf-format attribute (if any)
453 dnl result in HAVE_ATTR_FORMAT.
454 dnl Make sure you also include the AHX_CONFIG_FORMAT_ATTRIBUTE.
455 AC_DEFUN([ACX_CHECK_FORMAT_ATTRIBUTE],
456 [AC_REQUIRE([AC_PROG_CC])
457 AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute)
458 AC_CACHE_VAL(ac_cv_c_format_attribute,
459 [ac_cv_c_format_attribute=no
460 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
461 void f (char *format, ...) __attribute__ ((format (printf, 1, 2)));
462 void (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2)));
465 ]])],[ac_cv_c_format_attribute="yes"],[ac_cv_c_format_attribute="no"])
468 AC_MSG_RESULT($ac_cv_c_format_attribute)
469 if test $ac_cv_c_format_attribute = yes; then
470 AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute])
472 ])dnl End of ACX_CHECK_FORMAT_ATTRIBUTE
474 dnl Setup ATTR_FORMAT config.h parts.
475 dnl make sure you call ACX_CHECK_FORMAT_ATTRIBUTE also.
476 AC_DEFUN([AHX_CONFIG_FORMAT_ATTRIBUTE],
478 #ifdef HAVE_ATTR_FORMAT
479 # define ATTR_FORMAT(archetype, string_index, first_to_check) \
480 __attribute__ ((format (archetype, string_index, first_to_check)))
481 #else /* !HAVE_ATTR_FORMAT */
482 # define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */
483 #endif /* !HAVE_ATTR_FORMAT */
486 dnl Check how to mark function arguments as unused.
487 dnl result in HAVE_ATTR_UNUSED.
488 dnl Make sure you include AHX_CONFIG_UNUSED_ATTRIBUTE also.
489 AC_DEFUN([ACX_CHECK_UNUSED_ATTRIBUTE],
490 [AC_REQUIRE([AC_PROG_CC])
491 AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute)
492 AC_CACHE_VAL(ac_cv_c_unused_attribute,
493 [ac_cv_c_unused_attribute=no
494 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
495 void f (char *u __attribute__((unused)));
498 ]])],[ac_cv_c_unused_attribute="yes"],[ac_cv_c_unused_attribute="no"])
501 dnl Setup ATTR_UNUSED config.h parts.
502 dnl make sure you call ACX_CHECK_UNUSED_ATTRIBUTE also.
503 AC_DEFUN([AHX_CONFIG_UNUSED_ATTRIBUTE],
506 # define ATTR_UNUSED(x) x
507 #elif defined(__cplusplus)
508 # define ATTR_UNUSED(x)
509 #elif defined(HAVE_ATTR_UNUSED)
510 # define ATTR_UNUSED(x) x __attribute__((unused))
511 #else /* !HAVE_ATTR_UNUSED */
512 # define ATTR_UNUSED(x) x
513 #endif /* !HAVE_ATTR_UNUSED */
516 AC_MSG_RESULT($ac_cv_c_unused_attribute)
517 if test $ac_cv_c_unused_attribute = yes; then
518 AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute])
522 dnl Pre-fun for ACX_LIBTOOL_C_ONLY
523 AC_DEFUN([ACX_LIBTOOL_C_PRE], [
524 # skip these tests, we do not need them.
525 AC_DEFUN([AC_PROG_F77], [:])
526 AC_DEFUN([AC_PROG_FC], [:])
527 AC_DEFUN([AC_PROG_CXX], [:])
528 AC_DEFUN([AC_PROG_CXXCPP], [:])
529 AC_DEFUN([AC_PROG_OBJC], [:])
530 AC_DEFUN([AC_PROG_OBJCCPP], [:])
531 AC_DEFUN([AC_LIBTOOL_CXX], [:])
532 AC_DEFUN([AC_LIBTOOL_F77], [:])
533 # always use ./libtool unless override from commandline (libtool=mylibtool)
534 if test -z "$libtool"; then
538 # avoid libtool max commandline length test on systems that fork slowly.
540 if echo "$host_os" | grep "sunos4" >/dev/null; then
541 lt_cv_sys_max_cmd_len=32750;
543 AC_PATH_TOOL(AR, ar, [false])
544 if test $AR = false; then
545 AC_MSG_ERROR([Cannot find 'ar', please extend PATH to include it])
549 dnl Perform libtool check, portably, only for C
550 AC_DEFUN([ACX_LIBTOOL_C_ONLY], [
551 dnl as a requirement so that is gets called before LIBTOOL
552 dnl because libtools 'AC_REQUIRE' names are right after this one, before
553 dnl this function contents.
554 AC_REQUIRE([ACX_LIBTOOL_C_PRE])
558 dnl Detect if u_char type is defined, otherwise define it.
559 AC_DEFUN([ACX_TYPE_U_CHAR],
560 [AC_CHECK_TYPE([u_char], ,
561 [AC_DEFINE([u_char], [unsigned char], [Define to 'unsigned char if not defined])], [
563 #ifdef HAVE_WINSOCK2_H
564 # include <winsock2.h>
568 dnl Detect if rlim_t type is defined, otherwise define it.
569 AC_DEFUN([ACX_TYPE_RLIM_T],
570 [AC_CHECK_TYPE(rlim_t, ,
571 [AC_DEFINE([rlim_t], [unsigned long], [Define to 'int' if not defined])], [
573 #ifdef HAVE_SYS_RESOURCE_H
574 # include <sys/resource.h>
578 dnl Detect if socklen_t type is defined, otherwise define it.
579 AC_DEFUN([ACX_TYPE_SOCKLEN_T],
581 AC_CHECK_TYPE(socklen_t, ,
582 [AC_DEFINE([socklen_t], [int], [Define to 'int' if not defined])], [
584 #ifdef HAVE_SYS_SOCKET_H
585 # include <sys/socket.h>
587 #ifdef HAVE_WS2TCPIP_H
588 # include <ws2tcpip.h>
592 dnl Detect if in_addr_t type is defined, otherwise define it.
593 AC_DEFUN([ACX_TYPE_IN_ADDR_T],
594 [ AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [
596 #ifdef HAVE_SYS_TYPES_H
597 # include <sys/types.h>
599 #ifdef HAVE_NETINET_IN_H
600 # include <netinet/in.h>
604 dnl Detect if in_port_t type is defined, otherwise define it.
605 AC_DEFUN([ACX_TYPE_IN_PORT_T],
606 [ AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])], [
608 #ifdef HAVE_SYS_TYPES_H
609 # include <sys/types.h>
611 #ifdef HAVE_NETINET_IN_H
612 # include <netinet/in.h>
616 dnl Add option to disable the evil rpath. Check whether to use rpath or not.
617 dnl Adds the --disable-rpath option. Uses trick to edit the ./libtool.
618 AC_DEFUN([ACX_ARG_RPATH],
621 [ --disable-rpath disable hardcoded rpath (default=enabled)],
622 enable_rpath=$enableval, enable_rpath=yes)
623 if test "x$enable_rpath" = xno; then
624 dnl AC_MSG_RESULT([Fixing libtool for -rpath problems.])
625 AC_CONFIG_COMMANDS([disable-rpath], [
626 sed < libtool > libtool-2 \
627 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_RPATH_SED__ "/'
635 dnl Add a -R to the RUNTIME_PATH. Only if rpath is enabled and it is
636 dnl an absolute path.
637 dnl $1: the pathname to add.
638 AC_DEFUN([ACX_RUNTIME_PATH_ADD], [
639 if test "x$enable_rpath" = xyes; then
640 if echo "$1" | grep "^/" >/dev/null; then
641 RUNTIME_PATH="$RUNTIME_PATH -R$1"
646 dnl Common code for both ACX_WITH_SSL and ACX_WITH_SSL_OPTIONAL
647 dnl Takes one argument; the withval checked in those 2 functions
648 dnl sets up the environment for the given openssl path
649 AC_DEFUN([ACX_SSL_CHECKS], [
651 if test x_$withval != x_no; then
652 AC_MSG_CHECKING(for SSL)
653 if test -n "$withval"; then
654 dnl look for openssl install with different version, eg.
655 dnl in /usr/include/openssl11/openssl/ssl.h
656 dnl and /usr/lib64/openssl11/libssl.so
657 dnl with the --with-ssl=/usr/include/openssl11
658 if test ! -f "$withval/include/openssl/ssl.h" -a -f "$withval/openssl/ssl.h"; then
662 ssldir_include="$ssldir"
664 ssldir_lib=`echo $ssldir | sed -e 's/include/lib/'`
665 if test -f "$ssldir_lib/libssl.a" -o -f "$ssldir_lib/libssl.so"; then
668 ssldir_lib=`echo $ssldir | sed -e 's/include/lib64/'`
669 if test -f "$ssldir_lib/libssl.a" -o -f "$ssldir_lib/libssl.so"; then
672 AC_MSG_ERROR([Could not find openssl lib file, $ssldir_lib/libssl.[so,a], pass like "/usr/local" or "/usr/include/openssl11"])
677 if test x_$withval = x_ -o x_$withval = x_yes; then
678 withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr"
680 for dir in $withval; do
682 if test -f "$dir/include/openssl/ssl.h"; then
684 ssldir_include="$ssldir/include"
685 if test ! -d "$ssldir/lib" -a -d "$ssldir/lib64"; then
686 ssldir_lib="$ssldir/lib64"
688 ssldir_lib="$ssldir/lib"
693 if test x_$found_ssl != x_yes; then
694 AC_MSG_ERROR(Cannot find the SSL libraries in $withval)
696 AC_MSG_RESULT(found in $ssldir)
697 AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.])
699 dnl assume /usr is already in the include, lib and dynlib paths.
700 if test "$ssldir" != "/usr"; then
701 CPPFLAGS="$CPPFLAGS -I$ssldir_include"
702 LIBSSL_CPPFLAGS="$LIBSSL_CPPFLAGS -I$ssldir_include"
703 LDFLAGS="$LDFLAGS -L$ssldir_lib"
704 LIBSSL_LDFLAGS="$LIBSSL_LDFLAGS -L$ssldir_lib"
705 ACX_RUNTIME_PATH_ADD([$ssldir_lib])
708 AC_MSG_CHECKING([for EVP_sha256 in -lcrypto])
709 LIBS="$LIBS -lcrypto"
710 LIBSSL_LIBS="$LIBSSL_LIBS -lcrypto"
711 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
712 int EVP_sha256(void);
716 AC_DEFINE([HAVE_EVP_SHA256], 1,
717 [If you have EVP_sha256])
720 # check if -lwsock32 or -lgdi32 are needed.
722 BAKSSLLIBS="$LIBSSL_LIBS"
723 LIBS="$LIBS -lgdi32 -lws2_32"
724 LIBSSL_LIBS="$LIBSSL_LIBS -lgdi32 -lws2_32"
725 AC_MSG_CHECKING([if -lcrypto needs -lgdi32])
726 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
727 int EVP_sha256(void);
730 AC_DEFINE([HAVE_EVP_SHA256], 1,
731 [If you have EVP_sha256])
736 LIBSSL_LIBS="$BAKSSLLIBS"
738 LIBSSL_LIBS="$LIBSSL_LIBS -ldl"
739 AC_MSG_CHECKING([if -lcrypto needs -ldl])
740 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
741 int EVP_sha256(void);
744 AC_DEFINE([HAVE_EVP_SHA256], 1,
745 [If you have EVP_sha256])
750 LIBSSL_LIBS="$BAKSSLLIBS"
751 LIBS="$LIBS -ldl -pthread"
752 LIBSSL_LIBS="$LIBSSL_LIBS -ldl -pthread"
753 AC_MSG_CHECKING([if -lcrypto needs -ldl -pthread])
754 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
755 int EVP_sha256(void);
758 AC_DEFINE([HAVE_EVP_SHA256], 1,
759 [If you have EVP_sha256])
763 AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required])
770 AC_SUBST(RUNTIME_PATH)
772 AC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT])
773 AC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT])
774 AC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT])
775 ])dnl End of ACX_SSL_CHECKS
777 dnl Check for SSL, where SSL is mandatory
778 dnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found
779 dnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS.
780 dnl Checks main header files of SSL.
782 AC_DEFUN([ACX_WITH_SSL],
784 AC_ARG_WITH(ssl, AS_HELP_STRING([--with-ssl=pathname],[enable SSL (will check /usr/local/ssl
785 /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr or specify like /usr/include/openssl11)]),[
789 if test x_$withval = x_no; then
790 AC_MSG_ERROR([Need SSL library to do digital signature cryptography])
792 ACX_SSL_CHECKS($withval)
793 ])dnl End of ACX_WITH_SSL
795 dnl Check for SSL, where ssl is optional (--without-ssl is allowed)
796 dnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found
797 dnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS.
798 dnl Checks main header files of SSL.
800 AC_DEFUN([ACX_WITH_SSL_OPTIONAL],
802 AC_ARG_WITH(ssl, AS_HELP_STRING([--with-ssl=pathname],[enable SSL (will check /usr/local/ssl
803 /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr or specify like /usr/include/openssl11)]),[
807 ACX_SSL_CHECKS($withval)
808 ])dnl End of ACX_WITH_SSL_OPTIONAL
810 dnl Setup to use -lssl
811 dnl To use -lcrypto, use the ACX_WITH_SSL setup (before this one).
812 AC_DEFUN([ACX_LIB_SSL],
814 # check if libssl needs libdl
817 AC_MSG_CHECKING([if libssl needs libdl])
818 AC_TRY_LINK_FUNC([SSL_CTX_new], [
824 AC_SEARCH_LIBS([dlopen], [dl])
825 ]) ])dnl End of ACX_LIB_SSL
827 dnl Setup to use very large files (>2Gb).
828 dnl setups fseeko and its own
829 AC_DEFUN([ACX_SYS_LARGEFILE],
832 dnl try to see if an additional _LARGEFILE_SOURCE 1 is needed to get fseeko
833 ACX_CHECK_COMPILER_FLAG_NEEDED(-D_LARGEFILE_SOURCE=1,
837 int a = fseeko(stdin, 0, 0);
840 ], [CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE=1"])
843 dnl Check getaddrinfo.
844 dnl Works on linux, solaris, bsd and windows(links winsock).
845 dnl defines HAVE_GETADDRINFO, USE_WINSOCK.
846 AC_DEFUN([ACX_CHECK_GETADDRINFO_WITH_INCLUDES],
847 [AC_REQUIRE([AC_PROG_CC])
848 AC_MSG_CHECKING(for getaddrinfo)
849 ac_cv_func_getaddrinfo=no
857 char* (*f) () = getaddrinfo;
866 dnl this case on linux, solaris, bsd
867 [ac_cv_func_getaddrinfo="yes"
868 dnl see if on windows
869 if test "$ac_cv_header_windows_h" = "yes"; then
870 AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used])
872 if echo $LIBS | grep 'lws2_32' >/dev/null; then
875 LIBS="$LIBS -lws2_32"
879 dnl no quick getaddrinfo, try mingw32 and winsock2 library.
881 LIBS="$LIBS -lws2_32"
885 #ifdef HAVE_WS2TCPIP_H
886 #include <ws2tcpip.h>
890 (void)getaddrinfo(NULL, NULL, NULL, NULL);
894 ac_cv_func_getaddrinfo="yes"
895 dnl already: LIBS="$LIBS -lws2_32"
896 AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used])
900 ac_cv_func_getaddrinfo="no"
905 AC_MSG_RESULT($ac_cv_func_getaddrinfo)
906 if test $ac_cv_func_getaddrinfo = yes; then
907 AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether getaddrinfo is available])
909 ])dnl Endof AC_CHECK_GETADDRINFO_WITH_INCLUDES
911 dnl check if a function is deprecated. defines DEPRECATED_func in config.h.
912 dnl $1: function name
913 dnl $2: C-statement that calls the function.
914 dnl $3: includes for the program.
915 dnl $4: executes if yes
916 dnl $5: executes if no
917 AC_DEFUN([ACX_FUNC_DEPRECATED],
919 AC_REQUIRE([AC_PROG_CC])
920 AC_MSG_CHECKING(if $1 is deprecated)
921 cache=`echo $1 | sed 'y%.=/+-%___p_%'`
922 AC_CACHE_VAL(cv_cc_deprecated_$cache,
924 echo '$3' >conftest.c
925 echo 'void f(){ $2 }' >>conftest.c
926 if test -z "`$CC $CPPFLAGS $CFLAGS -c conftest.c 2>&1 | grep -e deprecated -e unavailable`"; then
927 eval "cv_cc_deprecated_$cache=no"
929 eval "cv_cc_deprecated_$cache=yes"
931 rm -f conftest conftest.o conftest.c
933 if eval "test \"`echo '$cv_cc_deprecated_'$cache`\" = yes"; then
935 AC_DEFINE_UNQUOTED(AS_TR_CPP([DEPRECATED_$1]), 1, [Whether $1 is deprecated])
943 ])dnl end of ACX_FUNC_DEPRECATED
945 dnl check if select and nonblocking sockets actually work.
946 dnl Needs fork(2) and select(2).
947 dnl defines NONBLOCKING_IS_BROKEN, and if that is true multiple reads from
948 dnl a nonblocking socket do not work, a new call to select is necessary.
949 AC_DEFUN([ACX_CHECK_NONBLOCKING_BROKEN],
951 AC_MSG_CHECKING([if nonblocking sockets work])
952 if echo $host | grep mingw >/dev/null; then
953 AC_MSG_RESULT([no (windows)])
954 AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).])
963 #ifdef HAVE_SYS_TYPES_H
964 #include <sys/types.h>
966 #ifdef HAVE_SYS_SOCKET_H
967 #include <sys/socket.h>
969 #ifdef HAVE_NETINET_IN_H
970 #include <netinet/in.h>
972 #ifdef HAVE_ARPA_INET_H
973 #include <arpa/inet.h>
988 struct sockaddr_in a;
989 /* test if select and nonblocking reads work well together */
991 fork child to send 10 messages.
993 then try to nonblocking read the 10 messages
994 then, nonblocking read must give EAGAIN
997 port = 12345 + (time(0)%32);
998 sfd = socket(PF_INET, SOCK_DGRAM, 0);
1003 memset(&a, 0, sizeof(a));
1004 a.sin_family = AF_INET;
1005 a.sin_port = htons(port);
1006 a.sin_addr.s_addr = inet_addr("127.0.0.1");
1007 if(bind(sfd, (struct sockaddr*)&a, sizeof(a)) < 0) {
1011 if(fcntl(sfd, F_SETFL, O_NONBLOCK) == -1) {
1016 cfd = socket(PF_INET, SOCK_DGRAM, 0);
1018 perror("client socket");
1022 if(bind(cfd, (struct sockaddr*)&a, sizeof(a)) < 0) {
1023 perror("client bind");
1026 a.sin_port = htons(port);
1028 /* no handler, causes exit in 10 seconds */
1031 /* send and receive on the socket */
1032 if((p=fork()) == 0) {
1033 for(i=0; i<num; i++) {
1034 if(sendto(cfd, &i, sizeof(i), 0,
1035 (struct sockaddr*)&a, sizeof(a)) < 0) {
1050 if(select(sfd+1, &rset, NULL, NULL, NULL) < 1) {
1056 if(recv(sfd, &x, sizeof(x), 0) != sizeof(x)) {
1064 /* now we want to get EAGAIN: nonblocking goodness */
1066 recv(sfd, &x, sizeof(x), 0);
1067 if(errno != EAGAIN) {
1068 perror("trying to recv again");
1071 /* EAGAIN encountered */
1079 AC_MSG_RESULT([yes])
1082 AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).])
1084 AC_MSG_RESULT([crosscompile(yes)])
1087 ])dnl End of ACX_CHECK_NONBLOCKING_BROKEN
1089 dnl Check if mkdir has one or two arguments.
1090 dnl defines MKDIR_HAS_ONE_ARG
1091 AC_DEFUN([ACX_MKDIR_ONE_ARG],
1093 AC_MSG_CHECKING([whether mkdir has one arg])
1094 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1097 #ifdef HAVE_WINSOCK2_H
1098 #include <winsock2.h>
1100 #ifdef HAVE_SYS_STAT_H
1101 #include <sys/stat.h>
1104 (void)mkdir("directory");
1105 ]])],[AC_MSG_RESULT(yes)
1106 AC_DEFINE(MKDIR_HAS_ONE_ARG, 1, [Define if mkdir has one argument.])
1107 ],[AC_MSG_RESULT(no)
1109 ])dnl end of ACX_MKDIR_ONE_ARG
1111 dnl Check for ioctlsocket function. works on mingw32 too.
1112 AC_DEFUN([ACX_FUNC_IOCTLSOCKET],
1115 AC_MSG_CHECKING(for ioctlsocket)
1116 AC_LINK_IFELSE([AC_LANG_PROGRAM([
1117 #ifdef HAVE_WINSOCK2_H
1118 #include <winsock2.h>
1121 (void)ioctlsocket(0, 0, NULL);
1124 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [if the function 'ioctlsocket' is available])
1125 ],[AC_MSG_RESULT(no)])
1126 ])dnl end of ACX_FUNC_IOCTLSOCKET
1128 dnl detect malloc and provide malloc compat prototype.
1129 dnl $1: unique name for compat code
1130 AC_DEFUN([ACX_FUNC_MALLOC],
1132 AC_MSG_CHECKING([for GNU libc compatible malloc])
1133 AC_RUN_IFELSE([AC_LANG_PROGRAM(
1134 [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
1139 ]], [ if(malloc(0) != 0) return 1;])
1141 [AC_MSG_RESULT([no])
1143 AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] ,
1144 [AC_MSG_RESULT([yes])
1145 AC_DEFINE([HAVE_MALLOC], 1, [If have GNU libc compatible malloc])],
1146 [AC_MSG_RESULT([no (crosscompile)])
1148 AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] )
1151 dnl Define fallback for fseeko and ftello if needed.
1152 AC_DEFUN([AHX_CONFIG_FSEEKO],
1155 #define fseeko fseek
1156 #define ftello ftell
1157 #endif /* HAVE_FSEEKO */
1160 dnl Define RAND_MAX if not defined
1161 AC_DEFUN([AHX_CONFIG_RAND_MAX],
1164 #define RAND_MAX 2147483647
1168 dnl Define MAXHOSTNAMELEN if not defined
1169 AC_DEFUN([AHX_CONFIG_MAXHOSTNAMELEN],
1171 #ifndef MAXHOSTNAMELEN
1172 #define MAXHOSTNAMELEN 256
1176 dnl Define IPV6_MIN_MTU if not defined
1177 AC_DEFUN([AHX_CONFIG_IPV6_MIN_MTU],
1179 #ifndef IPV6_MIN_MTU
1180 #define IPV6_MIN_MTU 1280
1181 #endif /* IPV6_MIN_MTU */
1184 dnl provide snprintf, vsnprintf compat prototype
1185 dnl $1: unique name for compat code
1186 AC_DEFUN([AHX_CONFIG_SNPRINTF],
1188 #ifndef HAVE_SNPRINTF
1189 #define snprintf snprintf_$1
1190 #define vsnprintf vsnprintf_$1
1192 int snprintf (char *str, size_t count, const char *fmt, ...);
1193 int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
1194 #endif /* HAVE_SNPRINTF */
1197 dnl provide inet_pton compat prototype.
1198 dnl $1: unique name for compat code
1199 AC_DEFUN([AHX_CONFIG_INET_PTON],
1201 #ifndef HAVE_INET_PTON
1202 #define inet_pton inet_pton_$1
1203 int inet_pton(int af, const char* src, void* dst);
1204 #endif /* HAVE_INET_PTON */
1207 dnl provide inet_ntop compat prototype.
1208 dnl $1: unique name for compat code
1209 AC_DEFUN([AHX_CONFIG_INET_NTOP],
1211 #ifndef HAVE_INET_NTOP
1212 #define inet_ntop inet_ntop_$1
1213 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
1217 dnl provide inet_aton compat prototype.
1218 dnl $1: unique name for compat code
1219 AC_DEFUN([AHX_CONFIG_INET_ATON],
1221 #ifndef HAVE_INET_ATON
1222 #define inet_aton inet_aton_$1
1223 int inet_aton(const char *cp, struct in_addr *addr);
1227 dnl provide memmove compat prototype.
1228 dnl $1: unique name for compat code
1229 AC_DEFUN([AHX_CONFIG_MEMMOVE],
1231 #ifndef HAVE_MEMMOVE
1232 #define memmove memmove_$1
1233 void *memmove(void *dest, const void *src, size_t n);
1237 dnl provide strlcat compat prototype.
1238 dnl $1: unique name for compat code
1239 AC_DEFUN([AHX_CONFIG_STRLCAT],
1241 #ifndef HAVE_STRLCAT
1242 #define strlcat strlcat_$1
1243 size_t strlcat(char *dst, const char *src, size_t siz);
1247 dnl provide strlcpy compat prototype.
1248 dnl $1: unique name for compat code
1249 AC_DEFUN([AHX_CONFIG_STRLCPY],
1251 #ifndef HAVE_STRLCPY
1252 #define strlcpy strlcpy_$1
1253 size_t strlcpy(char *dst, const char *src, size_t siz);
1257 dnl provide gmtime_r compat prototype.
1258 dnl $1: unique name for compat code
1259 AC_DEFUN([AHX_CONFIG_GMTIME_R],
1261 #ifndef HAVE_GMTIME_R
1262 #define gmtime_r gmtime_r_$1
1263 struct tm *gmtime_r(const time_t *timep, struct tm *result);
1267 dnl provide reallocarray compat prototype.
1268 dnl $1: unique name for compat code
1269 AC_DEFUN([AHX_CONFIG_REALLOCARRAY],
1271 #ifndef HAVE_REALLOCARRAY
1272 #define reallocarray reallocarray$1
1273 void* reallocarray(void *ptr, size_t nmemb, size_t size);
1277 dnl provide w32 compat definition for sleep
1278 AC_DEFUN([AHX_CONFIG_W32_SLEEP],
1280 #if !defined(HAVE_SLEEP) || defined(HAVE_WINDOWS_H)
1281 #define sleep(x) Sleep((x)*1000) /* on win32 */
1282 #endif /* HAVE_SLEEP */
1285 dnl provide w32 compat definition for usleep
1286 AC_DEFUN([AHX_CONFIG_W32_USLEEP],
1289 #define usleep(x) Sleep((x)/1000 + 1) /* on win32 */
1290 #endif /* HAVE_USLEEP */
1293 dnl provide w32 compat definition for random
1294 AC_DEFUN([AHX_CONFIG_W32_RANDOM],
1297 #define random rand /* on win32, for tests only (bad random) */
1298 #endif /* HAVE_RANDOM */
1301 dnl provide w32 compat definition for srandom
1302 AC_DEFUN([AHX_CONFIG_W32_SRANDOM],
1304 #ifndef HAVE_SRANDOM
1305 #define srandom(x) srand(x) /* on win32, for tests only (bad random) */
1306 #endif /* HAVE_SRANDOM */
1309 dnl provide w32 compat definition for FD_SET_T
1310 AC_DEFUN([AHX_CONFIG_W32_FD_SET_T],
1312 /* detect if we need to cast to unsigned int for FD_SET to avoid warnings */
1313 #ifdef HAVE_WINSOCK2_H
1314 #define FD_SET_T (u_int)
1320 dnl Remove an extension flag from CFLAGS, define replacement to be made.
1321 dnl Used by ACX_STRIP_EXT_FLAGS.
1322 dnl $1: the name of the flag, for example -D_GNU_SOURCE.
1323 AC_DEFUN([ACX_CFLAGS_STRIP],
1325 if echo $CFLAGS | grep " $1" >/dev/null 2>&1; then
1326 CFLAGS="`echo $CFLAGS | sed -e 's/ $1//g'`"
1327 AC_DEFINE(m4_bpatsubst(OMITTED_$1,[[-=]],_), 1, Put $1 define in config.h)
1331 dnl Remove EXT flags from the CFLAGS and set them to be defined in config.h
1332 dnl use with ACX_DETERMINE_EXT_FLAGS.
1333 AC_DEFUN([ACX_STRIP_EXT_FLAGS],
1335 AC_MSG_NOTICE([Stripping extension flags...])
1336 ACX_CFLAGS_STRIP(-D_GNU_SOURCE)
1337 ACX_CFLAGS_STRIP(-D_BSD_SOURCE)
1338 ACX_CFLAGS_STRIP(-D_DEFAULT_SOURCE)
1339 ACX_CFLAGS_STRIP(-D__EXTENSIONS__)
1340 ACX_CFLAGS_STRIP(-D_POSIX_C_SOURCE=200112)
1341 ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE=600)
1342 ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE_EXTENDED=1)
1343 ACX_CFLAGS_STRIP(-D_ALL_SOURCE)
1344 ACX_CFLAGS_STRIP(-D_LARGEFILE_SOURCE=1)
1345 ]) dnl End of ACX_STRIP_EXT_FLAGS
1347 dnl define one omitted flag for config.h
1348 dnl $1: flag name. -D_GNU_SOURCE
1349 dnl $2: replacement define. _GNU_SOURCE
1350 dnl $3: define value, 1
1351 AC_DEFUN([AHX_CONFIG_FLAG_OMITTED],
1352 [#if defined($1) && !defined($2)
1356 dnl Wrapper for AHX_CONFIG_FLAG_OMITTED for -D style flags
1357 dnl $1: the -DNAME or -DNAME=value string.
1358 AC_DEFUN([AHX_CONFIG_FLAG_EXT],
1359 [AHX_CONFIG_FLAG_OMITTED(m4_bpatsubst(OMITTED_$1,[[-=]],_),m4_bpatsubst(m4_bpatsubst($1,-D,),=.*$,),m4_if(m4_bregexp($1,=),-1,1,m4_bpatsubst($1,^.*=,)))
1362 dnl config.h part to define omitted cflags, use with ACX_STRIP_EXT_FLAGS.
1363 AC_DEFUN([AHX_CONFIG_EXT_FLAGS],
1364 [AHX_CONFIG_FLAG_EXT(-D_GNU_SOURCE)
1365 AHX_CONFIG_FLAG_EXT(-D_BSD_SOURCE)
1366 AHX_CONFIG_FLAG_EXT(-D_DEFAULT_SOURCE)
1367 AHX_CONFIG_FLAG_EXT(-D__EXTENSIONS__)
1368 AHX_CONFIG_FLAG_EXT(-D_POSIX_C_SOURCE=200112)
1369 AHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE=600)
1370 AHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE_EXTENDED=1)
1371 AHX_CONFIG_FLAG_EXT(-D_ALL_SOURCE)
1372 AHX_CONFIG_FLAG_EXT(-D_LARGEFILE_SOURCE=1)
1375 dnl check if memcmp is using signed characters and replace if so.
1376 AC_DEFUN([ACX_CHECK_MEMCMP_SIGNED],
1377 [AC_MSG_CHECKING([if memcmp compares unsigned])
1378 AC_RUN_IFELSE([AC_LANG_SOURCE([[
1384 char a = 255, b = 0;
1385 if(memcmp(&a, &b, 1) < 0)
1389 ]])], [AC_MSG_RESULT([yes]) ],
1390 [ AC_MSG_RESULT([no])
1391 AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes])
1393 ], [ AC_MSG_RESULT([cross-compile no])
1394 AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes])
1398 dnl define memcmp to its replacement, pass unique id for program as arg
1399 AC_DEFUN([AHX_MEMCMP_BROKEN], [
1400 #ifdef MEMCMP_IS_BROKEN
1401 #include "compat/memcmp.h"
1402 #define memcmp memcmp_$1
1403 int memcmp(const void *x, const void *y, size_t n);
1407 dnl ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family
1408 AC_DEFUN([ACX_CHECK_SS_FAMILY],
1409 [AC_CHECK_MEMBER([struct sockaddr_storage.ss_family], [], [
1410 AC_CHECK_MEMBER([struct sockaddr_storage.__ss_family], [
1411 AC_DEFINE([ss_family], [__ss_family], [Fallback member name for socket family in struct sockaddr_storage])
1412 ],, [AC_INCLUDES_DEFAULT
1413 #ifdef HAVE_NETINET_IN_H
1414 #include <netinet/in.h>
1416 #ifdef HAVE_SYS_SOCKET_H
1417 #include <sys/socket.h>
1422 #ifdef HAVE_ARPA_INET_H
1423 #include <arpa/inet.h>
1426 ], [AC_INCLUDES_DEFAULT
1427 #ifdef HAVE_NETINET_IN_H
1428 #include <netinet/in.h>
1430 #ifdef HAVE_SYS_SOCKET_H
1431 #include <sys/socket.h>
1436 #ifdef HAVE_ARPA_INET_H
1437 #include <arpa/inet.h>
1441 dnl Check if CC and linker support -fPIE and -pie.
1442 dnl If so, sets them in CFLAGS / LDFLAGS.
1443 AC_DEFUN([ACX_CHECK_PIE], [
1444 AC_ARG_ENABLE([pie], AS_HELP_STRING([--enable-pie], [Enable Position-Independent Executable (eg. to fully benefit from ASLR, small performance penalty)]))
1445 AS_IF([test "x$enable_pie" = "xyes"], [
1446 AC_MSG_CHECKING([if $CC supports PIE])
1447 BAKLDFLAGS="$LDFLAGS"
1449 LDFLAGS="$LDFLAGS -pie"
1450 CFLAGS="$CFLAGS -fPIE"
1451 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [
1452 if $CC $CFLAGS $LDFLAGS -o conftest conftest.c 2>&1 | grep "warning: no debug symbols in executable" >/dev/null; then
1453 LDFLAGS="$BAKLDFLAGS"
1458 rm -f conftest conftest.c conftest.o
1459 ], [LDFLAGS="$BAKLDFLAGS" ; CFLAGS="$BAKCFLAGS" ; AC_MSG_RESULT(no)])
1463 dnl Check if linker supports -Wl,-z,relro,-z,now.
1464 dnl If so, adds it to LDFLAGS.
1465 AC_DEFUN([ACX_CHECK_RELRO_NOW], [
1466 AC_ARG_ENABLE([relro_now], AS_HELP_STRING([--enable-relro-now], [Enable full relocation binding at load-time (RELRO NOW, to protect GOT and .dtor areas)]))
1467 AS_IF([test "x$enable_relro_now" = "xyes"], [
1468 AC_MSG_CHECKING([if $CC supports -Wl,-z,relro,-z,now])
1469 BAKLDFLAGS="$LDFLAGS"
1470 LDFLAGS="$LDFLAGS -Wl,-z,relro,-z,now"
1471 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [
1472 if $CC $CFLAGS $LDFLAGS -o conftest conftest.c 2>&1 | grep "warning: no debug symbols in executable" >/dev/null; then
1473 LDFLAGS="$BAKLDFLAGS"
1478 rm -f conftest conftest.c conftest.o
1479 ], [LDFLAGS="$BAKLDFLAGS" ; AC_MSG_RESULT(no)])