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