13b6c3722Schristos# acx_nlnetlabs.m4 - common macros for configure checks 23b6c3722Schristos# Copyright 2009, Wouter Wijngaards, NLnet Labs. 33b6c3722Schristos# BSD licensed. 43b6c3722Schristos# 5*91f7d55fSchristos# Version 46 6*91f7d55fSchristos# 2023-05-04 fix to remove unused whitespace. 7*91f7d55fSchristos# 2023-01-26 fix -Wstrict-prototypes. 8*91f7d55fSchristos# 2022-09-01 fix checking if nonblocking sockets work on OpenBSD. 97a540f2bSchristos# 2021-08-17 fix sed script in ssldir split handling. 107a540f2bSchristos# 2021-08-17 fix for openssl to detect split version, with ssldir_include 117a540f2bSchristos# and ssldir_lib output directories. 127a540f2bSchristos# 2021-07-30 fix for openssl use of lib64 directory. 137a540f2bSchristos# 2021-06-14 fix nonblocking test to use host instead of target for mingw test. 147a540f2bSchristos# 2021-05-17 fix nonblocking socket test from grep on mingw32 to mingw for 157a540f2bSchristos# 64bit compatibility. 167a540f2bSchristos# 2021-03-24 fix ACX_FUNC_DEPRECATED to use CPPFLAGS and CFLAGS. 17d0eba39bSchristos# 2021-01-05 fix defun for aclocal 18d0eba39bSchristos# 2021-01-05 autoconf 2.70 autoupdate and fixes, no AC_TRY_COMPILE 19d0eba39bSchristos# 2020-08-24 Use EVP_sha256 instead of HMAC_Update (for openssl-3.0.0). 203b6c3722Schristos# 2016-03-21 Check -ldl -pthread for libcrypto for ldns and openssl 1.1.0. 213b6c3722Schristos# 2016-03-21 Use HMAC_Update instead of HMAC_CTX_Init (for openssl-1.1.0). 223b6c3722Schristos# 2016-01-04 -D_DEFAULT_SOURCE defined with -D_BSD_SOURCE for Linux glibc 2.20 233b6c3722Schristos# 2015-12-11 FLTO check for new OSX, clang. 243b6c3722Schristos# 2015-11-18 spelling check fix. 253b6c3722Schristos# 2015-11-05 ACX_SSL_CHECKS no longer adds -ldl needlessly. 263b6c3722Schristos# 2015-08-28 ACX_CHECK_PIE and ACX_CHECK_RELRO_NOW added. 273b6c3722Schristos# 2015-03-17 AHX_CONFIG_REALLOCARRAY added 283b6c3722Schristos# 2013-09-19 FLTO help text improved. 293b6c3722Schristos# 2013-07-18 Enable ACX_CHECK_COMPILER_FLAG to test for -Wstrict-prototypes 303b6c3722Schristos# 2013-06-25 FLTO has --disable-flto option. 313b6c3722Schristos# 2013-05-03 Update W32_SLEEP for newer mingw that links but not defines it. 323b6c3722Schristos# 2013-03-22 Fix ACX_RSRC_VERSION for long version numbers. 333b6c3722Schristos# 2012-02-09 Fix AHX_MEMCMP_BROKEN with undef in compat/memcmp.h. 343b6c3722Schristos# 2012-01-20 Fix COMPILER_FLAGS_UNBOUND for gcc 4.6.2 assigned-not-used-warns. 353b6c3722Schristos# 2011-12-05 Fix getaddrinfowithincludes on windows with fedora16 mingw32-gcc. 363b6c3722Schristos# Fix ACX_MALLOC for redefined malloc error. 373b6c3722Schristos# Fix GETADDRINFO_WITH_INCLUDES to add -lws2_32 383b6c3722Schristos# 2011-11-10 Fix FLTO test to not drop a.out in current directory. 393b6c3722Schristos# 2011-11-01 Fix FLTO test for llvm on Lion. 403b6c3722Schristos# 2011-08-01 Fix nonblock test (broken at v13). 413b6c3722Schristos# 2011-08-01 Fix autoconf 2.68 warnings 423b6c3722Schristos# 2011-06-23 Add ACX_CHECK_FLTO to check -flto. 433b6c3722Schristos# 2010-08-16 Fix FLAG_OMITTED for AS_TR_CPP changes in autoconf-2.66. 443b6c3722Schristos# 2010-07-02 Add check for ss_family (for minix). 453b6c3722Schristos# 2010-04-26 Fix to use CPPFLAGS for CHECK_COMPILER_FLAGS. 463b6c3722Schristos# 2010-03-01 Fix RPATH using CONFIG_COMMANDS to run at the very end. 473b6c3722Schristos# 2010-02-18 WITH_SSL outputs the LIBSSL_LDFLAGS, LIBS, CPPFLAGS separate, -ldl 483b6c3722Schristos# 2010-02-01 added ACX_CHECK_MEMCMP_SIGNED, AHX_MEMCMP_BROKEN 493b6c3722Schristos# 2010-01-20 added AHX_COONFIG_STRLCAT 503b6c3722Schristos# 2009-07-14 U_CHAR detection improved for windows crosscompile. 513b6c3722Schristos# added ACX_FUNC_MALLOC 523b6c3722Schristos# fixup some #if to #ifdef 533b6c3722Schristos# NONBLOCKING test for mingw crosscompile. 543b6c3722Schristos# 2009-07-13 added ACX_WITH_SSL_OPTIONAL 553b6c3722Schristos# 2009-07-03 fixup LDFLAGS for empty ssl dir. 563b6c3722Schristos# 573b6c3722Schristos# Automates some of the checking constructs. Aims at portability for POSIX. 583b6c3722Schristos# Documentation for functions is below. 593b6c3722Schristos# 603b6c3722Schristos# the following macro's are provided in this file: 613b6c3722Schristos# (see below for details on each macro). 623b6c3722Schristos# 633b6c3722Schristos# ACX_ESCAPE_BACKSLASH - escape backslashes in var for C-preproc. 643b6c3722Schristos# ACX_RSRC_VERSION - create windows resource version number. 653b6c3722Schristos# ACX_CHECK_COMPILER_FLAG - see if cc supports a flag. 663b6c3722Schristos# ACX_CHECK_ERROR_FLAGS - see which flag is -werror (used below). 673b6c3722Schristos# ACX_CHECK_COMPILER_FLAG_NEEDED - see if flags make the code compile cleanly. 683b6c3722Schristos# ACX_DEPFLAG - find cc dependency flags. 693b6c3722Schristos# ACX_DETERMINE_EXT_FLAGS_UNBOUND - find out which flags enable BSD and POSIX. 703b6c3722Schristos# ACX_CHECK_FORMAT_ATTRIBUTE - find cc printf format syntax. 713b6c3722Schristos# ACX_CHECK_UNUSED_ATTRIBUTE - find cc variable unused syntax. 723b6c3722Schristos# ACX_CHECK_FLTO - see if cc supports -flto and use it if so. 733b6c3722Schristos# ACX_LIBTOOL_C_ONLY - create libtool for C only, improved. 743b6c3722Schristos# ACX_TYPE_U_CHAR - u_char type. 753b6c3722Schristos# ACX_TYPE_RLIM_T - rlim_t type. 763b6c3722Schristos# ACX_TYPE_SOCKLEN_T - socklen_t type. 773b6c3722Schristos# ACX_TYPE_IN_ADDR_T - in_addr_t type. 783b6c3722Schristos# ACX_TYPE_IN_PORT_T - in_port_t type. 793b6c3722Schristos# ACX_ARG_RPATH - add --disable-rpath option. 803b6c3722Schristos# ACX_WITH_SSL - add --with-ssl option, link -lcrypto. 813b6c3722Schristos# ACX_WITH_SSL_OPTIONAL - add --with-ssl option, link -lcrypto, 823b6c3722Schristos# where --without-ssl is also accepted 833b6c3722Schristos# ACX_LIB_SSL - setup to link -lssl. 843b6c3722Schristos# ACX_SYS_LARGEFILE - improved sys_largefile, fseeko, >2G files. 853b6c3722Schristos# ACX_CHECK_GETADDRINFO_WITH_INCLUDES - find getaddrinfo, portably. 863b6c3722Schristos# ACX_FUNC_DEPRECATED - see if func is deprecated. 873b6c3722Schristos# ACX_CHECK_NONBLOCKING_BROKEN - see if nonblocking sockets really work. 883b6c3722Schristos# ACX_MKDIR_ONE_ARG - determine mkdir(2) number of arguments. 893b6c3722Schristos# ACX_FUNC_IOCTLSOCKET - find ioctlsocket, portably. 903b6c3722Schristos# ACX_FUNC_MALLOC - check malloc, define replacement . 913b6c3722Schristos# AHX_CONFIG_FORMAT_ATTRIBUTE - config.h text for format. 923b6c3722Schristos# AHX_CONFIG_UNUSED_ATTRIBUTE - config.h text for unused. 933b6c3722Schristos# AHX_CONFIG_FSEEKO - define fseeko, ftello fallback. 943b6c3722Schristos# AHX_CONFIG_RAND_MAX - define RAND_MAX if needed. 953b6c3722Schristos# AHX_CONFIG_MAXHOSTNAMELEN - define MAXHOSTNAMELEN if needed. 963b6c3722Schristos# AHX_CONFIG_IPV6_MIN_MTU - define IPV6_MIN_MTU if needed. 973b6c3722Schristos# AHX_CONFIG_SNPRINTF - snprintf compat prototype 983b6c3722Schristos# AHX_CONFIG_INET_PTON - inet_pton compat prototype 993b6c3722Schristos# AHX_CONFIG_INET_NTOP - inet_ntop compat prototype 1003b6c3722Schristos# AHX_CONFIG_INET_ATON - inet_aton compat prototype 1013b6c3722Schristos# AHX_CONFIG_MEMMOVE - memmove compat prototype 1023b6c3722Schristos# AHX_CONFIG_STRLCAT - strlcat compat prototype 1033b6c3722Schristos# AHX_CONFIG_STRLCPY - strlcpy compat prototype 1043b6c3722Schristos# AHX_CONFIG_GMTIME_R - gmtime_r compat prototype 1053b6c3722Schristos# AHX_CONFIG_W32_SLEEP - w32 compat for sleep 1063b6c3722Schristos# AHX_CONFIG_W32_USLEEP - w32 compat for usleep 1073b6c3722Schristos# AHX_CONFIG_W32_RANDOM - w32 compat for random 1083b6c3722Schristos# AHX_CONFIG_W32_SRANDOM - w32 compat for srandom 1093b6c3722Schristos# AHX_CONFIG_W32_FD_SET_T - w32 detection of FD_SET_T. 1103b6c3722Schristos# ACX_CFLAGS_STRIP - strip one flag from CFLAGS 1113b6c3722Schristos# ACX_STRIP_EXT_FLAGS - strip extension flags from CFLAGS 1123b6c3722Schristos# AHX_CONFIG_FLAG_OMITTED - define omitted flag 1133b6c3722Schristos# AHX_CONFIG_FLAG_EXT - define omitted extension flag 1143b6c3722Schristos# AHX_CONFIG_EXT_FLAGS - define the stripped extension flags 1153b6c3722Schristos# ACX_CHECK_MEMCMP_SIGNED - check if memcmp uses signed characters. 1163b6c3722Schristos# AHX_MEMCMP_BROKEN - replace memcmp func for CHECK_MEMCMP_SIGNED. 1173b6c3722Schristos# ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family 1183b6c3722Schristos# ACX_CHECK_PIE - add --enable-pie option and check if works 1193b6c3722Schristos# ACX_CHECK_RELRO_NOW - add --enable-relro-now option and check it 1203b6c3722Schristos# 1213b6c3722Schristos 1223b6c3722Schristosdnl Escape backslashes as \\, for C:\ paths, for the C preprocessor defines. 1233b6c3722Schristosdnl for example, ACX_ESCAPE_BACKSLASH($from_var, to_var) 1243b6c3722Schristosdnl $1: the text to change. 1253b6c3722Schristosdnl $2: the result. 1263b6c3722SchristosAC_DEFUN([ACX_ESCAPE_BACKSLASH], [$2="`echo $1 | sed -e 's/\\\\/\\\\\\\\/g'`" 1273b6c3722Schristos]) 1283b6c3722Schristos 1293b6c3722Schristosdnl Calculate comma separated windows-resource numbers from package version. 1303b6c3722Schristosdnl Picks the first three(,0) or four numbers out of the name. 1313b6c3722Schristosdnl $1: variable for the result 1323b6c3722SchristosAC_DEFUN([ACX_RSRC_VERSION], 1333b6c3722Schristos[$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/' `] 1343b6c3722Schristos]) 1353b6c3722Schristos 1363b6c3722Schristosdnl Routine to help check for compiler flags. 1373b6c3722Schristosdnl Checks if the compiler will accept the flag. 1383b6c3722Schristosdnl $1: the flag without a - in front, so g to check -g. 1393b6c3722Schristosdnl $2: executed if yes 1403b6c3722Schristosdnl $3: executed if no 1413b6c3722SchristosAC_DEFUN([ACX_CHECK_COMPILER_FLAG], 1423b6c3722Schristos[ 1433b6c3722SchristosAC_REQUIRE([AC_PROG_CC]) 1443b6c3722SchristosAC_MSG_CHECKING(whether $CC supports -$1) 1453b6c3722Schristoscache=`echo $1 | sed 'y%.=/+-%___p_%'` 1463b6c3722SchristosAC_CACHE_VAL(cv_prog_cc_flag_$cache, 1473b6c3722Schristos[ 1483b6c3722Schristosecho 'void f(void){}' >conftest.c 1493b6c3722Schristosif test -z "`$CC $CPPFLAGS $CFLAGS -$1 -c conftest.c 2>&1`"; then 1503b6c3722Schristoseval "cv_prog_cc_flag_$cache=yes" 1513b6c3722Schristoselse 1523b6c3722Schristoseval "cv_prog_cc_flag_$cache=no" 1533b6c3722Schristosfi 1543b6c3722Schristosrm -f conftest conftest.o conftest.c 1553b6c3722Schristos]) 1563b6c3722Schristosif eval "test \"`echo '$cv_prog_cc_flag_'$cache`\" = yes"; then 1573b6c3722SchristosAC_MSG_RESULT(yes) 1583b6c3722Schristos: 1593b6c3722Schristos$2 1603b6c3722Schristoselse 1613b6c3722SchristosAC_MSG_RESULT(no) 1623b6c3722Schristos: 1633b6c3722Schristos$3 1643b6c3722Schristosfi 1653b6c3722Schristos]) 1663b6c3722Schristos 1673b6c3722Schristosdnl setup flags for ACX_CHECK_COMPILER_FLAG_NEEDED 1683b6c3722Schristosdnl ERRFLAG: result, compiler flag to turn warnings into errors 1693b6c3722SchristosAC_DEFUN([ACX_CHECK_ERROR_FLAGS], 1703b6c3722Schristos[ 1713b6c3722SchristosACX_CHECK_COMPILER_FLAG(Werror, [ERRFLAG="-Werror"], [ERRFLAG="-errwarn"]) 1723b6c3722SchristosACX_CHECK_COMPILER_FLAG(Wall, [ERRFLAG="$ERRFLAG -Wall"], 1733b6c3722Schristos [ERRFLAG="$ERRFLAG -errfmt"]) 1743b6c3722Schristos]) 1753b6c3722Schristos 1763b6c3722Schristosdnl Routine to help check for needed compiler flags. 1773b6c3722Schristosdnl $1: flags for CC 1783b6c3722Schristosdnl $2: the includes and code 1793b6c3722Schristosdnl $3: if the given code only compiles with the flag, execute argument 3 1803b6c3722Schristosdnl $4: if the given code compiles without the flag, execute argument 4 1813b6c3722Schristosdnl $5: with and without flag the compile fails, execute argument 5. 1823b6c3722SchristosAC_DEFUN([ACX_CHECK_COMPILER_FLAG_NEEDED], 1833b6c3722Schristos[ 1843b6c3722SchristosAC_REQUIRE([AC_PROG_CC]) 1853b6c3722SchristosAC_REQUIRE([ACX_CHECK_ERROR_FLAGS]) 1863b6c3722SchristosAC_MSG_CHECKING(whether we need $1 as a flag for $CC) 1873b6c3722Schristoscache=AS_TR_SH($1) 1883b6c3722Schristosdnl cache=`echo $1 | sed 'y%.=/+- %___p__%'` 1893b6c3722SchristosAC_CACHE_VAL(cv_prog_cc_flag_needed_$cache, 1903b6c3722Schristos[ 1913b6c3722Schristosecho '$2' > conftest.c 192*91f7d55fSchristosecho 'void f(void){}' >>conftest.c 1933b6c3722Schristosif test -z "`$CC $CPPFLAGS $CFLAGS $ERRFLAG -c conftest.c 2>&1`"; then 1943b6c3722Schristoseval "cv_prog_cc_flag_needed_$cache=no" 1953b6c3722Schristoselse 1963b6c3722Schristos[ 1973b6c3722Schristosif test -z "`$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`"; then 1983b6c3722Schristoseval "cv_prog_cc_flag_needed_$cache=yes" 1993b6c3722Schristoselse 2003b6c3722Schristoseval "cv_prog_cc_flag_needed_$cache=fail" 2013b6c3722Schristos#echo 'Test with flag fails too!' 2023b6c3722Schristos#cat conftest.c 2033b6c3722Schristos#echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1" 2043b6c3722Schristos#echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1` 2053b6c3722Schristos#exit 1 2063b6c3722Schristosfi 2073b6c3722Schristos] 2083b6c3722Schristosfi 2093b6c3722Schristosrm -f conftest conftest.c conftest.o 2103b6c3722Schristos]) 2113b6c3722Schristosif eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = yes"; then 2123b6c3722SchristosAC_MSG_RESULT(yes) 2133b6c3722Schristos: 2143b6c3722Schristos$3 2153b6c3722Schristoselse 2163b6c3722Schristosif eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = no"; then 2173b6c3722SchristosAC_MSG_RESULT(no) 2183b6c3722Schristos#echo 'Test with flag is no!' 2193b6c3722Schristos#cat conftest.c 2203b6c3722Schristos#echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1" 2213b6c3722Schristos#echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1` 2223b6c3722Schristos#exit 1 2233b6c3722Schristos: 2243b6c3722Schristos$4 2253b6c3722Schristoselse 2263b6c3722SchristosAC_MSG_RESULT(failed) 2273b6c3722Schristos: 2283b6c3722Schristos$5 2293b6c3722Schristosfi 2303b6c3722Schristosfi 2313b6c3722Schristos]) 2323b6c3722Schristos 2333b6c3722Schristosdnl Check for CC dependency flag 2343b6c3722Schristosdnl DEPFLAG: set to flag that generates dependencies. 2353b6c3722SchristosAC_DEFUN([ACX_DEPFLAG], 2363b6c3722Schristos[ 2373b6c3722SchristosAC_MSG_CHECKING([$CC dependency flag]) 238*91f7d55fSchristosecho 'void f(void){}' >conftest.c 2393b6c3722Schristosif test "`$CC -MM conftest.c 2>&1`" = "conftest.o: conftest.c"; then 2403b6c3722Schristos DEPFLAG="-MM" 2413b6c3722Schristoselse 2423b6c3722Schristos if test "`$CC -xM1 conftest.c 2>&1`" = "conftest.o: conftest.c"; then 2433b6c3722Schristos DEPFLAG="-xM1" 2443b6c3722Schristos else 2453b6c3722Schristos DEPFLAG="-MM" # dunno do something 2463b6c3722Schristos fi 2473b6c3722Schristosfi 2483b6c3722SchristosAC_MSG_RESULT($DEPFLAG) 2493b6c3722Schristosrm -f conftest.c 2503b6c3722SchristosAC_SUBST(DEPFLAG) 2513b6c3722Schristos]) 2523b6c3722Schristos 2533b6c3722Schristosdnl Determine flags that gives POSIX and BSD functionality. 2543b6c3722Schristosdnl CFLAGS is modified for the result. 2553b6c3722SchristosAC_DEFUN([ACX_DETERMINE_EXT_FLAGS_UNBOUND], 2563b6c3722Schristos[ 2573b6c3722SchristosACX_CHECK_COMPILER_FLAG(std=c99, [C99FLAG="-std=c99"]) 2583b6c3722SchristosACX_CHECK_COMPILER_FLAG(xc99, [C99FLAG="-xc99"]) 2593b6c3722Schristos 2603b6c3722SchristosAC_CHECK_HEADERS([getopt.h time.h],,, [AC_INCLUDES_DEFAULT]) 2613b6c3722Schristos 2623b6c3722SchristosACX_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, 2633b6c3722Schristos[ 2643b6c3722Schristos#include "confdefs.h" 2653b6c3722Schristos#include <stdlib.h> 2663b6c3722Schristos#include <ctype.h> 2673b6c3722Schristos#include <sys/time.h> 2683b6c3722Schristos#ifdef HAVE_TIME_H 2693b6c3722Schristos#include <time.h> 2703b6c3722Schristos#endif 2713b6c3722Schristos#include <unistd.h> 2723b6c3722Schristos#include <netdb.h> 2733b6c3722Schristos#ifdef HAVE_GETOPT_H 2743b6c3722Schristos#include <getopt.h> 2753b6c3722Schristos#endif 2763b6c3722Schristos 277*91f7d55fSchristosint test(void) { 2783b6c3722Schristos int a; 2793b6c3722Schristos char **opts = NULL; 2803b6c3722Schristos struct timeval tv; 2813b6c3722Schristos char *t; 2823b6c3722Schristos time_t time = 0; 2833b6c3722Schristos char *buf = NULL; 2843b6c3722Schristos const char* str = NULL; 2853b6c3722Schristos struct msghdr msg; 2863b6c3722Schristos msg.msg_control = 0; 2873b6c3722Schristos t = ctime_r(&time, buf); 2883b6c3722Schristos tv.tv_usec = 10; 2893b6c3722Schristos srandom(32); 2903b6c3722Schristos a = getopt(2, opts, "a"); 2913b6c3722Schristos a = isascii(32); 2923b6c3722Schristos str = gai_strerror(0); 2933b6c3722Schristos if(str && t && tv.tv_usec && msg.msg_control) 2943b6c3722Schristos a = 0; 2953b6c3722Schristos return a; 2963b6c3722Schristos} 2973b6c3722Schristos], [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"]) 2983b6c3722Schristos 2993b6c3722SchristosACX_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, 3003b6c3722Schristos[ 3013b6c3722Schristos#include "confdefs.h" 3023b6c3722Schristos#include <stdlib.h> 3033b6c3722Schristos#include <ctype.h> 3043b6c3722Schristos#include <sys/time.h> 3053b6c3722Schristos#ifdef HAVE_TIME_H 3063b6c3722Schristos#include <time.h> 3073b6c3722Schristos#endif 3083b6c3722Schristos#include <unistd.h> 3093b6c3722Schristos#include <netdb.h> 3103b6c3722Schristos#ifdef HAVE_GETOPT_H 3113b6c3722Schristos#include <getopt.h> 3123b6c3722Schristos#endif 3133b6c3722Schristos 314*91f7d55fSchristosint test(void) { 3153b6c3722Schristos int a; 3163b6c3722Schristos char **opts = NULL; 3173b6c3722Schristos struct timeval tv; 3183b6c3722Schristos char *t; 3193b6c3722Schristos time_t time = 0; 3203b6c3722Schristos char *buf = NULL; 3213b6c3722Schristos const char* str = NULL; 3223b6c3722Schristos struct msghdr msg; 3233b6c3722Schristos msg.msg_control = 0; 3243b6c3722Schristos t = ctime_r(&time, buf); 3253b6c3722Schristos tv.tv_usec = 10; 3263b6c3722Schristos srandom(32); 3273b6c3722Schristos a = getopt(2, opts, "a"); 3283b6c3722Schristos a = isascii(32); 3293b6c3722Schristos str = gai_strerror(0); 3303b6c3722Schristos if(str && t && tv.tv_usec && msg.msg_control) 3313b6c3722Schristos a = 0; 3323b6c3722Schristos return a; 3333b6c3722Schristos} 3343b6c3722Schristos], [CFLAGS="$CFLAGS $C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE"]) 3353b6c3722Schristos 3363b6c3722SchristosACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG, 3373b6c3722Schristos[ 3383b6c3722Schristos#include <stdbool.h> 3393b6c3722Schristos#include <ctype.h> 340*91f7d55fSchristosint test(void) { 3413b6c3722Schristos int a = 0; 3423b6c3722Schristos return a; 3433b6c3722Schristos} 3443b6c3722Schristos], [CFLAGS="$CFLAGS $C99FLAG"]) 3453b6c3722Schristos 3463b6c3722SchristosACX_CHECK_COMPILER_FLAG_NEEDED(-D_BSD_SOURCE -D_DEFAULT_SOURCE, 3473b6c3722Schristos[ 3483b6c3722Schristos#include <ctype.h> 3493b6c3722Schristos 350*91f7d55fSchristosint test(void) { 3513b6c3722Schristos int a; 3523b6c3722Schristos a = isascii(32); 3533b6c3722Schristos return a; 3543b6c3722Schristos} 3553b6c3722Schristos], [CFLAGS="$CFLAGS -D_BSD_SOURCE -D_DEFAULT_SOURCE"]) 3563b6c3722Schristos 3573b6c3722SchristosACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE, 3583b6c3722Schristos[ 3593b6c3722Schristos#include <netinet/in.h> 3603b6c3722Schristos 361*91f7d55fSchristosint test(void) { 3623b6c3722Schristos struct in6_pktinfo inf; 3633b6c3722Schristos int a = (int)sizeof(inf); 3643b6c3722Schristos return a; 3653b6c3722Schristos} 3663b6c3722Schristos], [CFLAGS="$CFLAGS -D_GNU_SOURCE"]) 3673b6c3722Schristos 3683b6c3722Schristos# check again for GNU_SOURCE for setresgid. May fail if setresgid 3693b6c3722Schristos# is not available at all. -D_FRSRESGID is to make this check unique. 3703b6c3722Schristos# otherwise we would get the previous cached result. 3713b6c3722SchristosACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE -D_FRSRESGID, 3723b6c3722Schristos[ 3733b6c3722Schristos#include <unistd.h> 3743b6c3722Schristos 375*91f7d55fSchristosint test(void) { 3763b6c3722Schristos int a = setresgid(0,0,0); 3773b6c3722Schristos a = setresuid(0,0,0); 3783b6c3722Schristos return a; 3793b6c3722Schristos} 3803b6c3722Schristos], [CFLAGS="$CFLAGS -D_GNU_SOURCE"]) 3813b6c3722Schristos 3823b6c3722SchristosACX_CHECK_COMPILER_FLAG_NEEDED(-D_POSIX_C_SOURCE=200112, 3833b6c3722Schristos[ 3843b6c3722Schristos#include "confdefs.h" 3853b6c3722Schristos#ifdef HAVE_TIME_H 3863b6c3722Schristos#include <time.h> 3873b6c3722Schristos#endif 3883b6c3722Schristos#include <netdb.h> 3893b6c3722Schristos 390*91f7d55fSchristosint test(void) { 3913b6c3722Schristos int a = 0; 3923b6c3722Schristos char *t; 3933b6c3722Schristos time_t time = 0; 3943b6c3722Schristos char *buf = NULL; 3953b6c3722Schristos const char* str = NULL; 3963b6c3722Schristos t = ctime_r(&time, buf); 3973b6c3722Schristos str = gai_strerror(0); 3983b6c3722Schristos if(t && str) 3993b6c3722Schristos a = 0; 4003b6c3722Schristos return a; 4013b6c3722Schristos} 4023b6c3722Schristos], [CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112"]) 4033b6c3722Schristos 4043b6c3722SchristosACX_CHECK_COMPILER_FLAG_NEEDED(-D__EXTENSIONS__, 4053b6c3722Schristos[ 4063b6c3722Schristos#include "confdefs.h" 4073b6c3722Schristos#include <stdlib.h> 4083b6c3722Schristos#include <ctype.h> 4093b6c3722Schristos#include <sys/time.h> 4103b6c3722Schristos#ifdef HAVE_TIME_H 4113b6c3722Schristos#include <time.h> 4123b6c3722Schristos#endif 4133b6c3722Schristos#include <unistd.h> 4143b6c3722Schristos#ifdef HAVE_GETOPT_H 4153b6c3722Schristos#include <getopt.h> 4163b6c3722Schristos#endif 4173b6c3722Schristos 418*91f7d55fSchristosint test(void) { 4193b6c3722Schristos int a; 4203b6c3722Schristos char **opts = NULL; 4213b6c3722Schristos struct timeval tv; 4223b6c3722Schristos tv.tv_usec = 10; 4233b6c3722Schristos srandom(32); 4243b6c3722Schristos a = getopt(2, opts, "a"); 4253b6c3722Schristos a = isascii(32); 4263b6c3722Schristos if(tv.tv_usec) 4273b6c3722Schristos a = 0; 4283b6c3722Schristos return a; 4293b6c3722Schristos} 4303b6c3722Schristos], [CFLAGS="$CFLAGS -D__EXTENSIONS__"]) 4313b6c3722Schristos 4323b6c3722Schristos])dnl End of ACX_DETERMINE_EXT_FLAGS_UNBOUND 4333b6c3722Schristos 4343b6c3722Schristosdnl Check if CC supports -flto. 4353b6c3722Schristosdnl in a way that supports clang and suncc (that flag does something else, 4363b6c3722Schristosdnl but fails to link). It sets it in CFLAGS if it works. 4373b6c3722SchristosAC_DEFUN([ACX_CHECK_FLTO], [ 4383b6c3722Schristos AC_ARG_ENABLE([flto], AS_HELP_STRING([--disable-flto], [Disable link-time optimization (gcc specific option)])) 4393b6c3722Schristos AS_IF([test "x$enable_flto" != "xno"], [ 4403b6c3722Schristos AC_MSG_CHECKING([if $CC supports -flto]) 4413b6c3722Schristos BAKCFLAGS="$CFLAGS" 4423b6c3722Schristos CFLAGS="$CFLAGS -flto" 4433b6c3722Schristos AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [ 4443b6c3722Schristos if $CC $CFLAGS -o conftest conftest.c 2>&1 | $GREP -e "warning: no debug symbols in executable" -e "warning: object" >/dev/null; then 4453b6c3722Schristos CFLAGS="$BAKCFLAGS" 4463b6c3722Schristos AC_MSG_RESULT(no) 4473b6c3722Schristos else 4483b6c3722Schristos AC_MSG_RESULT(yes) 4493b6c3722Schristos fi 4503b6c3722Schristos rm -f conftest conftest.c conftest.o 4513b6c3722Schristos ], [CFLAGS="$BAKCFLAGS" ; AC_MSG_RESULT(no)]) 4523b6c3722Schristos ]) 4533b6c3722Schristos]) 4543b6c3722Schristos 4553b6c3722Schristosdnl Check the printf-format attribute (if any) 4563b6c3722Schristosdnl result in HAVE_ATTR_FORMAT. 4573b6c3722Schristosdnl Make sure you also include the AHX_CONFIG_FORMAT_ATTRIBUTE. 4583b6c3722SchristosAC_DEFUN([ACX_CHECK_FORMAT_ATTRIBUTE], 4593b6c3722Schristos[AC_REQUIRE([AC_PROG_CC]) 4603b6c3722SchristosAC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute) 4613b6c3722SchristosAC_CACHE_VAL(ac_cv_c_format_attribute, 4623b6c3722Schristos[ac_cv_c_format_attribute=no 463d0eba39bSchristosAC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h> 4643b6c3722Schristosvoid f (char *format, ...) __attribute__ ((format (printf, 1, 2))); 4653b6c3722Schristosvoid (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2))); 466d0eba39bSchristos]], [[ 4673b6c3722Schristos f ("%s", "str"); 468d0eba39bSchristos]])],[ac_cv_c_format_attribute="yes"],[ac_cv_c_format_attribute="no"]) 4693b6c3722Schristos]) 4703b6c3722Schristos 4713b6c3722SchristosAC_MSG_RESULT($ac_cv_c_format_attribute) 4723b6c3722Schristosif test $ac_cv_c_format_attribute = yes; then 4733b6c3722Schristos AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute]) 4743b6c3722Schristosfi 4753b6c3722Schristos])dnl End of ACX_CHECK_FORMAT_ATTRIBUTE 4763b6c3722Schristos 4773b6c3722Schristosdnl Setup ATTR_FORMAT config.h parts. 4783b6c3722Schristosdnl make sure you call ACX_CHECK_FORMAT_ATTRIBUTE also. 4793b6c3722SchristosAC_DEFUN([AHX_CONFIG_FORMAT_ATTRIBUTE], 4803b6c3722Schristos[ 4813b6c3722Schristos#ifdef HAVE_ATTR_FORMAT 4823b6c3722Schristos# define ATTR_FORMAT(archetype, string_index, first_to_check) \ 4833b6c3722Schristos __attribute__ ((format (archetype, string_index, first_to_check))) 4843b6c3722Schristos#else /* !HAVE_ATTR_FORMAT */ 4853b6c3722Schristos# define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */ 4863b6c3722Schristos#endif /* !HAVE_ATTR_FORMAT */ 4873b6c3722Schristos]) 4883b6c3722Schristos 4893b6c3722Schristosdnl Check how to mark function arguments as unused. 4903b6c3722Schristosdnl result in HAVE_ATTR_UNUSED. 4913b6c3722Schristosdnl Make sure you include AHX_CONFIG_UNUSED_ATTRIBUTE also. 4923b6c3722SchristosAC_DEFUN([ACX_CHECK_UNUSED_ATTRIBUTE], 4933b6c3722Schristos[AC_REQUIRE([AC_PROG_CC]) 4943b6c3722SchristosAC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute) 4953b6c3722SchristosAC_CACHE_VAL(ac_cv_c_unused_attribute, 4963b6c3722Schristos[ac_cv_c_unused_attribute=no 497d0eba39bSchristosAC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h> 4983b6c3722Schristosvoid f (char *u __attribute__((unused))); 499d0eba39bSchristos]], [[ 5003b6c3722Schristos f ("x"); 501d0eba39bSchristos]])],[ac_cv_c_unused_attribute="yes"],[ac_cv_c_unused_attribute="no"]) 5023b6c3722Schristos]) 5033b6c3722Schristos 5043b6c3722Schristosdnl Setup ATTR_UNUSED config.h parts. 5053b6c3722Schristosdnl make sure you call ACX_CHECK_UNUSED_ATTRIBUTE also. 5063b6c3722SchristosAC_DEFUN([AHX_CONFIG_UNUSED_ATTRIBUTE], 5073b6c3722Schristos[ 5083b6c3722Schristos#if defined(DOXYGEN) 5093b6c3722Schristos# define ATTR_UNUSED(x) x 5103b6c3722Schristos#elif defined(__cplusplus) 5113b6c3722Schristos# define ATTR_UNUSED(x) 5123b6c3722Schristos#elif defined(HAVE_ATTR_UNUSED) 5133b6c3722Schristos# define ATTR_UNUSED(x) x __attribute__((unused)) 5143b6c3722Schristos#else /* !HAVE_ATTR_UNUSED */ 5153b6c3722Schristos# define ATTR_UNUSED(x) x 5163b6c3722Schristos#endif /* !HAVE_ATTR_UNUSED */ 5173b6c3722Schristos]) 5183b6c3722Schristos 5193b6c3722SchristosAC_MSG_RESULT($ac_cv_c_unused_attribute) 5203b6c3722Schristosif test $ac_cv_c_unused_attribute = yes; then 5213b6c3722Schristos AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute]) 5223b6c3722Schristosfi 5233b6c3722Schristos])dnl 5243b6c3722Schristos 5253b6c3722Schristosdnl Pre-fun for ACX_LIBTOOL_C_ONLY 5263b6c3722SchristosAC_DEFUN([ACX_LIBTOOL_C_PRE], [ 5273b6c3722Schristos# skip these tests, we do not need them. 5283b6c3722SchristosAC_DEFUN([AC_PROG_F77], [:]) 5293b6c3722SchristosAC_DEFUN([AC_PROG_FC], [:]) 5303b6c3722SchristosAC_DEFUN([AC_PROG_CXX], [:]) 5313b6c3722SchristosAC_DEFUN([AC_PROG_CXXCPP], [:]) 5323b6c3722SchristosAC_DEFUN([AC_PROG_OBJC], [:]) 5333b6c3722SchristosAC_DEFUN([AC_PROG_OBJCCPP], [:]) 5343b6c3722SchristosAC_DEFUN([AC_LIBTOOL_CXX], [:]) 5353b6c3722SchristosAC_DEFUN([AC_LIBTOOL_F77], [:]) 5363b6c3722Schristos# always use ./libtool unless override from commandline (libtool=mylibtool) 5373b6c3722Schristosif test -z "$libtool"; then 5383b6c3722Schristos libtool="./libtool" 5393b6c3722Schristosfi 5403b6c3722SchristosAC_SUBST(libtool) 5413b6c3722Schristos# avoid libtool max commandline length test on systems that fork slowly. 5423b6c3722SchristosAC_CANONICAL_HOST 5433b6c3722Schristosif echo "$host_os" | grep "sunos4" >/dev/null; then 5443b6c3722Schristos lt_cv_sys_max_cmd_len=32750; 5453b6c3722Schristosfi 5463b6c3722SchristosAC_PATH_TOOL(AR, ar, [false]) 5473b6c3722Schristosif test $AR = false; then 5483b6c3722Schristos AC_MSG_ERROR([Cannot find 'ar', please extend PATH to include it]) 5493b6c3722Schristosfi 5503b6c3722Schristos]) 5513b6c3722Schristos 5523b6c3722Schristosdnl Perform libtool check, portably, only for C 5533b6c3722SchristosAC_DEFUN([ACX_LIBTOOL_C_ONLY], [ 5543b6c3722Schristosdnl as a requirement so that is gets called before LIBTOOL 5553b6c3722Schristosdnl because libtools 'AC_REQUIRE' names are right after this one, before 5563b6c3722Schristosdnl this function contents. 5573b6c3722SchristosAC_REQUIRE([ACX_LIBTOOL_C_PRE]) 558d0eba39bSchristosLT_INIT 5593b6c3722Schristos]) 5603b6c3722Schristos 5613b6c3722Schristosdnl Detect if u_char type is defined, otherwise define it. 5623b6c3722SchristosAC_DEFUN([ACX_TYPE_U_CHAR], 5633b6c3722Schristos[AC_CHECK_TYPE([u_char], , 5643b6c3722Schristos [AC_DEFINE([u_char], [unsigned char], [Define to 'unsigned char if not defined])], [ 5653b6c3722SchristosAC_INCLUDES_DEFAULT 5663b6c3722Schristos#ifdef HAVE_WINSOCK2_H 5673b6c3722Schristos# include <winsock2.h> 5683b6c3722Schristos#endif 5693b6c3722Schristos]) ]) 5703b6c3722Schristos 5713b6c3722Schristosdnl Detect if rlim_t type is defined, otherwise define it. 5723b6c3722SchristosAC_DEFUN([ACX_TYPE_RLIM_T], 5733b6c3722Schristos[AC_CHECK_TYPE(rlim_t, , 5743b6c3722Schristos [AC_DEFINE([rlim_t], [unsigned long], [Define to 'int' if not defined])], [ 5753b6c3722SchristosAC_INCLUDES_DEFAULT 5763b6c3722Schristos#ifdef HAVE_SYS_RESOURCE_H 5773b6c3722Schristos# include <sys/resource.h> 5783b6c3722Schristos#endif 5793b6c3722Schristos]) ]) 5803b6c3722Schristos 5813b6c3722Schristosdnl Detect if socklen_t type is defined, otherwise define it. 5823b6c3722SchristosAC_DEFUN([ACX_TYPE_SOCKLEN_T], 5833b6c3722Schristos[ 5843b6c3722SchristosAC_CHECK_TYPE(socklen_t, , 5853b6c3722Schristos [AC_DEFINE([socklen_t], [int], [Define to 'int' if not defined])], [ 5863b6c3722SchristosAC_INCLUDES_DEFAULT 5873b6c3722Schristos#ifdef HAVE_SYS_SOCKET_H 5883b6c3722Schristos# include <sys/socket.h> 5893b6c3722Schristos#endif 5903b6c3722Schristos#ifdef HAVE_WS2TCPIP_H 5913b6c3722Schristos# include <ws2tcpip.h> 5923b6c3722Schristos#endif 5933b6c3722Schristos]) ]) 5943b6c3722Schristos 5953b6c3722Schristosdnl Detect if in_addr_t type is defined, otherwise define it. 5963b6c3722SchristosAC_DEFUN([ACX_TYPE_IN_ADDR_T], 5973b6c3722Schristos[ AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [ 5983b6c3722SchristosAC_INCLUDES_DEFAULT 5993b6c3722Schristos#ifdef HAVE_SYS_TYPES_H 6003b6c3722Schristos# include <sys/types.h> 6013b6c3722Schristos#endif 6023b6c3722Schristos#ifdef HAVE_NETINET_IN_H 6033b6c3722Schristos# include <netinet/in.h> 6043b6c3722Schristos#endif 6053b6c3722Schristos]) ]) 6063b6c3722Schristos 6073b6c3722Schristosdnl Detect if in_port_t type is defined, otherwise define it. 6083b6c3722SchristosAC_DEFUN([ACX_TYPE_IN_PORT_T], 6093b6c3722Schristos[ AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])], [ 6103b6c3722SchristosAC_INCLUDES_DEFAULT 6113b6c3722Schristos#ifdef HAVE_SYS_TYPES_H 6123b6c3722Schristos# include <sys/types.h> 6133b6c3722Schristos#endif 6143b6c3722Schristos#ifdef HAVE_NETINET_IN_H 6153b6c3722Schristos# include <netinet/in.h> 6163b6c3722Schristos#endif 6173b6c3722Schristos]) ]) 6183b6c3722Schristos 6193b6c3722Schristosdnl Add option to disable the evil rpath. Check whether to use rpath or not. 6203b6c3722Schristosdnl Adds the --disable-rpath option. Uses trick to edit the ./libtool. 6213b6c3722SchristosAC_DEFUN([ACX_ARG_RPATH], 6223b6c3722Schristos[ 6233b6c3722SchristosAC_ARG_ENABLE(rpath, 6243b6c3722Schristos [ --disable-rpath disable hardcoded rpath (default=enabled)], 6253b6c3722Schristos enable_rpath=$enableval, enable_rpath=yes) 6263b6c3722Schristosif test "x$enable_rpath" = xno; then 6273b6c3722Schristos dnl AC_MSG_RESULT([Fixing libtool for -rpath problems.]) 6283b6c3722Schristos AC_CONFIG_COMMANDS([disable-rpath], [ 6293b6c3722Schristos sed < libtool > libtool-2 \ 6303b6c3722Schristos 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_RPATH_SED__ "/' 6313b6c3722Schristos mv libtool-2 libtool 6323b6c3722Schristos chmod 755 libtool 6333b6c3722Schristos libtool="./libtool" 6343b6c3722Schristos ]) 6353b6c3722Schristosfi 6363b6c3722Schristos]) 6373b6c3722Schristos 6383b6c3722Schristosdnl Add a -R to the RUNTIME_PATH. Only if rpath is enabled and it is 6393b6c3722Schristosdnl an absolute path. 6403b6c3722Schristosdnl $1: the pathname to add. 6413b6c3722SchristosAC_DEFUN([ACX_RUNTIME_PATH_ADD], [ 6423b6c3722Schristos if test "x$enable_rpath" = xyes; then 6433b6c3722Schristos if echo "$1" | grep "^/" >/dev/null; then 6443b6c3722Schristos RUNTIME_PATH="$RUNTIME_PATH -R$1" 6453b6c3722Schristos fi 6463b6c3722Schristos fi 6473b6c3722Schristos]) 6483b6c3722Schristos 6493b6c3722Schristosdnl Common code for both ACX_WITH_SSL and ACX_WITH_SSL_OPTIONAL 6503b6c3722Schristosdnl Takes one argument; the withval checked in those 2 functions 6513b6c3722Schristosdnl sets up the environment for the given openssl path 6523b6c3722SchristosAC_DEFUN([ACX_SSL_CHECKS], [ 6533b6c3722Schristos withval=$1 6543b6c3722Schristos if test x_$withval != x_no; then 6553b6c3722Schristos AC_MSG_CHECKING(for SSL) 6567a540f2bSchristos if test -n "$withval"; then 6577a540f2bSchristos dnl look for openssl install with different version, eg. 6587a540f2bSchristos dnl in /usr/include/openssl11/openssl/ssl.h 6597a540f2bSchristos dnl and /usr/lib64/openssl11/libssl.so 6607a540f2bSchristos dnl with the --with-ssl=/usr/include/openssl11 6617a540f2bSchristos if test ! -f "$withval/include/openssl/ssl.h" -a -f "$withval/openssl/ssl.h"; then 6627a540f2bSchristos ssldir="$withval" 6637a540f2bSchristos found_ssl="yes" 6647a540f2bSchristos withval="" 6657a540f2bSchristos ssldir_include="$ssldir" 6667a540f2bSchristos dnl find the libdir 6677a540f2bSchristos ssldir_lib=`echo $ssldir | sed -e 's/include/lib/'` 6687a540f2bSchristos if test -f "$ssldir_lib/libssl.a" -o -f "$ssldir_lib/libssl.so"; then 6697a540f2bSchristos : # found here 6707a540f2bSchristos else 6717a540f2bSchristos ssldir_lib=`echo $ssldir | sed -e 's/include/lib64/'` 6727a540f2bSchristos if test -f "$ssldir_lib/libssl.a" -o -f "$ssldir_lib/libssl.so"; then 6737a540f2bSchristos : # found here 6747a540f2bSchristos else 6757a540f2bSchristos AC_MSG_ERROR([Could not find openssl lib file, $ssldir_lib/libssl.[so,a], pass like "/usr/local" or "/usr/include/openssl11"]) 6767a540f2bSchristos fi 6777a540f2bSchristos fi 6787a540f2bSchristos fi 6797a540f2bSchristos fi 6803b6c3722Schristos if test x_$withval = x_ -o x_$withval = x_yes; then 6813b6c3722Schristos withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr" 6823b6c3722Schristos fi 6833b6c3722Schristos for dir in $withval; do 6843b6c3722Schristos ssldir="$dir" 6853b6c3722Schristos if test -f "$dir/include/openssl/ssl.h"; then 6863b6c3722Schristos found_ssl="yes" 6877a540f2bSchristos ssldir_include="$ssldir/include" 6887a540f2bSchristos if test ! -d "$ssldir/lib" -a -d "$ssldir/lib64"; then 6897a540f2bSchristos ssldir_lib="$ssldir/lib64" 6907a540f2bSchristos else 6917a540f2bSchristos ssldir_lib="$ssldir/lib" 6923b6c3722Schristos fi 6933b6c3722Schristos break; 6943b6c3722Schristos fi 6953b6c3722Schristos done 6963b6c3722Schristos if test x_$found_ssl != x_yes; then 6973b6c3722Schristos AC_MSG_ERROR(Cannot find the SSL libraries in $withval) 6983b6c3722Schristos else 6993b6c3722Schristos AC_MSG_RESULT(found in $ssldir) 7007a540f2bSchristos AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.]) 7013b6c3722Schristos HAVE_SSL=yes 7027a540f2bSchristos dnl assume /usr is already in the include, lib and dynlib paths. 7037a540f2bSchristos if test "$ssldir" != "/usr"; then 7047a540f2bSchristos CPPFLAGS="$CPPFLAGS -I$ssldir_include" 7057a540f2bSchristos LIBSSL_CPPFLAGS="$LIBSSL_CPPFLAGS -I$ssldir_include" 7067a540f2bSchristos LDFLAGS="$LDFLAGS -L$ssldir_lib" 7077a540f2bSchristos LIBSSL_LDFLAGS="$LIBSSL_LDFLAGS -L$ssldir_lib" 7087a540f2bSchristos ACX_RUNTIME_PATH_ADD([$ssldir_lib]) 7093b6c3722Schristos fi 7103b6c3722Schristos 711d0eba39bSchristos AC_MSG_CHECKING([for EVP_sha256 in -lcrypto]) 7123b6c3722Schristos LIBS="$LIBS -lcrypto" 7133b6c3722Schristos LIBSSL_LIBS="$LIBSSL_LIBS -lcrypto" 714d0eba39bSchristos AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ 715d0eba39bSchristos int EVP_sha256(void); 716d0eba39bSchristos (void)EVP_sha256(); 717d0eba39bSchristos ]])],[ 7183b6c3722Schristos AC_MSG_RESULT(yes) 719d0eba39bSchristos AC_DEFINE([HAVE_EVP_SHA256], 1, 720d0eba39bSchristos [If you have EVP_sha256]) 7213b6c3722Schristos ],[ 7223b6c3722Schristos AC_MSG_RESULT(no) 7233b6c3722Schristos # check if -lwsock32 or -lgdi32 are needed. 7243b6c3722Schristos BAKLIBS="$LIBS" 7253b6c3722Schristos BAKSSLLIBS="$LIBSSL_LIBS" 7260cd9f4ecSchristos LIBS="$LIBS -lgdi32 -lws2_32" 7270cd9f4ecSchristos LIBSSL_LIBS="$LIBSSL_LIBS -lgdi32 -lws2_32" 7283b6c3722Schristos AC_MSG_CHECKING([if -lcrypto needs -lgdi32]) 729d0eba39bSchristos AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ 730d0eba39bSchristos int EVP_sha256(void); 731d0eba39bSchristos (void)EVP_sha256(); 732d0eba39bSchristos ]])],[ 733d0eba39bSchristos AC_DEFINE([HAVE_EVP_SHA256], 1, 734d0eba39bSchristos [If you have EVP_sha256]) 7353b6c3722Schristos AC_MSG_RESULT(yes) 7363b6c3722Schristos ],[ 7373b6c3722Schristos AC_MSG_RESULT(no) 7383b6c3722Schristos LIBS="$BAKLIBS" 7393b6c3722Schristos LIBSSL_LIBS="$BAKSSLLIBS" 7403b6c3722Schristos LIBS="$LIBS -ldl" 7413b6c3722Schristos LIBSSL_LIBS="$LIBSSL_LIBS -ldl" 7423b6c3722Schristos AC_MSG_CHECKING([if -lcrypto needs -ldl]) 743d0eba39bSchristos AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ 744d0eba39bSchristos int EVP_sha256(void); 745d0eba39bSchristos (void)EVP_sha256(); 746d0eba39bSchristos ]])],[ 747d0eba39bSchristos AC_DEFINE([HAVE_EVP_SHA256], 1, 748d0eba39bSchristos [If you have EVP_sha256]) 7493b6c3722Schristos AC_MSG_RESULT(yes) 7503b6c3722Schristos ],[ 7513b6c3722Schristos AC_MSG_RESULT(no) 7523b6c3722Schristos LIBS="$BAKLIBS" 7533b6c3722Schristos LIBSSL_LIBS="$BAKSSLLIBS" 7543b6c3722Schristos LIBS="$LIBS -ldl -pthread" 7553b6c3722Schristos LIBSSL_LIBS="$LIBSSL_LIBS -ldl -pthread" 7563b6c3722Schristos AC_MSG_CHECKING([if -lcrypto needs -ldl -pthread]) 757d0eba39bSchristos AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ 758d0eba39bSchristos int EVP_sha256(void); 759d0eba39bSchristos (void)EVP_sha256(); 760d0eba39bSchristos ]])],[ 761d0eba39bSchristos AC_DEFINE([HAVE_EVP_SHA256], 1, 762d0eba39bSchristos [If you have EVP_sha256]) 7633b6c3722Schristos AC_MSG_RESULT(yes) 7643b6c3722Schristos ],[ 7653b6c3722Schristos AC_MSG_RESULT(no) 7663b6c3722Schristos AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required]) 7673b6c3722Schristos ]) 7683b6c3722Schristos ]) 7693b6c3722Schristos ]) 7703b6c3722Schristos ]) 7713b6c3722Schristos fi 7723b6c3722Schristos AC_SUBST(HAVE_SSL) 7733b6c3722Schristos AC_SUBST(RUNTIME_PATH) 7743b6c3722Schristos fi 7753b6c3722SchristosAC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT]) 7763b6c3722SchristosAC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT]) 7773b6c3722SchristosAC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT]) 7783b6c3722Schristos])dnl End of ACX_SSL_CHECKS 7793b6c3722Schristos 7803b6c3722Schristosdnl Check for SSL, where SSL is mandatory 7813b6c3722Schristosdnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found 7823b6c3722Schristosdnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS. 7833b6c3722Schristosdnl Checks main header files of SSL. 7843b6c3722Schristosdnl 7853b6c3722SchristosAC_DEFUN([ACX_WITH_SSL], 7863b6c3722Schristos[ 787d0eba39bSchristosAC_ARG_WITH(ssl, AS_HELP_STRING([--with-ssl=pathname],[enable SSL (will check /usr/local/ssl 7887a540f2bSchristos /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr or specify like /usr/include/openssl11)]),[ 7893b6c3722Schristos ],[ 7903b6c3722Schristos withval="yes" 7913b6c3722Schristos ]) 7923b6c3722Schristos if test x_$withval = x_no; then 7933b6c3722Schristos AC_MSG_ERROR([Need SSL library to do digital signature cryptography]) 7943b6c3722Schristos fi 7953b6c3722Schristos ACX_SSL_CHECKS($withval) 7963b6c3722Schristos])dnl End of ACX_WITH_SSL 7973b6c3722Schristos 7983b6c3722Schristosdnl Check for SSL, where ssl is optional (--without-ssl is allowed) 7993b6c3722Schristosdnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found 8003b6c3722Schristosdnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS. 8013b6c3722Schristosdnl Checks main header files of SSL. 8023b6c3722Schristosdnl 8033b6c3722SchristosAC_DEFUN([ACX_WITH_SSL_OPTIONAL], 8043b6c3722Schristos[ 805d0eba39bSchristosAC_ARG_WITH(ssl, AS_HELP_STRING([--with-ssl=pathname],[enable SSL (will check /usr/local/ssl 8067a540f2bSchristos /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr or specify like /usr/include/openssl11)]),[ 8073b6c3722Schristos ],[ 8083b6c3722Schristos withval="yes" 8093b6c3722Schristos ]) 8103b6c3722Schristos ACX_SSL_CHECKS($withval) 8113b6c3722Schristos])dnl End of ACX_WITH_SSL_OPTIONAL 8123b6c3722Schristos 8133b6c3722Schristosdnl Setup to use -lssl 8143b6c3722Schristosdnl To use -lcrypto, use the ACX_WITH_SSL setup (before this one). 8153b6c3722SchristosAC_DEFUN([ACX_LIB_SSL], 8163b6c3722Schristos[ 8173b6c3722Schristos# check if libssl needs libdl 8183b6c3722SchristosBAKLIBS="$LIBS" 8193b6c3722SchristosLIBS="-lssl $LIBS" 8203b6c3722SchristosAC_MSG_CHECKING([if libssl needs libdl]) 8213b6c3722SchristosAC_TRY_LINK_FUNC([SSL_CTX_new], [ 8223b6c3722Schristos AC_MSG_RESULT([no]) 8233b6c3722Schristos LIBS="$BAKLIBS" 8243b6c3722Schristos] , [ 8253b6c3722Schristos AC_MSG_RESULT([yes]) 8263b6c3722Schristos LIBS="$BAKLIBS" 8273b6c3722Schristos AC_SEARCH_LIBS([dlopen], [dl]) 8283b6c3722Schristos]) ])dnl End of ACX_LIB_SSL 8293b6c3722Schristos 8303b6c3722Schristosdnl Setup to use very large files (>2Gb). 8313b6c3722Schristosdnl setups fseeko and its own 8323b6c3722SchristosAC_DEFUN([ACX_SYS_LARGEFILE], 8333b6c3722Schristos[ 8343b6c3722SchristosAC_SYS_LARGEFILE 8353b6c3722Schristosdnl try to see if an additional _LARGEFILE_SOURCE 1 is needed to get fseeko 8363b6c3722SchristosACX_CHECK_COMPILER_FLAG_NEEDED(-D_LARGEFILE_SOURCE=1, 8373b6c3722Schristos[ 8383b6c3722Schristos#include <stdio.h> 839*91f7d55fSchristosint test(void) { 8403b6c3722Schristos int a = fseeko(stdin, 0, 0); 8413b6c3722Schristos return a; 8423b6c3722Schristos} 8433b6c3722Schristos], [CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE=1"]) 8443b6c3722Schristos]) 8453b6c3722Schristos 8463b6c3722Schristosdnl Check getaddrinfo. 8473b6c3722Schristosdnl Works on linux, solaris, bsd and windows(links winsock). 8483b6c3722Schristosdnl defines HAVE_GETADDRINFO, USE_WINSOCK. 8493b6c3722SchristosAC_DEFUN([ACX_CHECK_GETADDRINFO_WITH_INCLUDES], 8503b6c3722Schristos[AC_REQUIRE([AC_PROG_CC]) 8513b6c3722SchristosAC_MSG_CHECKING(for getaddrinfo) 8523b6c3722Schristosac_cv_func_getaddrinfo=no 8533b6c3722SchristosAC_LINK_IFELSE( 8543b6c3722Schristos[AC_LANG_SOURCE([[ 8553b6c3722Schristos#ifdef __cplusplus 8563b6c3722Schristosextern "C" 8573b6c3722Schristos{ 8583b6c3722Schristos#endif 8593b6c3722Schristoschar* getaddrinfo(); 8603b6c3722Schristoschar* (*f) () = getaddrinfo; 8613b6c3722Schristos#ifdef __cplusplus 8623b6c3722Schristos} 8633b6c3722Schristos#endif 864*91f7d55fSchristosint main(void) { 8653b6c3722Schristos ; 8663b6c3722Schristos return 0; 8673b6c3722Schristos} 8683b6c3722Schristos]])], 8693b6c3722Schristosdnl this case on linux, solaris, bsd 8703b6c3722Schristos[ac_cv_func_getaddrinfo="yes" 8713b6c3722Schristosdnl see if on windows 8723b6c3722Schristosif test "$ac_cv_header_windows_h" = "yes"; then 8733b6c3722Schristos AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used]) 8743b6c3722Schristos USE_WINSOCK="1" 8750cd9f4ecSchristos if echo $LIBS | grep 'lws2_32' >/dev/null; then 8760cd9f4ecSchristos : 8770cd9f4ecSchristos else 8783b6c3722Schristos LIBS="$LIBS -lws2_32" 8793b6c3722Schristos fi 8800cd9f4ecSchristosfi 8813b6c3722Schristos], 8823b6c3722Schristosdnl no quick getaddrinfo, try mingw32 and winsock2 library. 8833b6c3722SchristosORIGLIBS="$LIBS" 8843b6c3722SchristosLIBS="$LIBS -lws2_32" 8853b6c3722SchristosAC_LINK_IFELSE( 8863b6c3722Schristos[AC_LANG_PROGRAM( 8873b6c3722Schristos[ 8883b6c3722Schristos#ifdef HAVE_WS2TCPIP_H 8893b6c3722Schristos#include <ws2tcpip.h> 8903b6c3722Schristos#endif 8913b6c3722Schristos], 8923b6c3722Schristos[ 8933b6c3722Schristos (void)getaddrinfo(NULL, NULL, NULL, NULL); 8943b6c3722Schristos] 8953b6c3722Schristos)], 8963b6c3722Schristos[ 8973b6c3722Schristosac_cv_func_getaddrinfo="yes" 8983b6c3722Schristosdnl already: LIBS="$LIBS -lws2_32" 8993b6c3722SchristosAC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used]) 9003b6c3722SchristosUSE_WINSOCK="1" 9013b6c3722Schristos], 9023b6c3722Schristos[ 9033b6c3722Schristosac_cv_func_getaddrinfo="no" 9043b6c3722SchristosLIBS="$ORIGLIBS" 9053b6c3722Schristos]) 9063b6c3722Schristos) 9073b6c3722Schristos 9083b6c3722SchristosAC_MSG_RESULT($ac_cv_func_getaddrinfo) 9093b6c3722Schristosif test $ac_cv_func_getaddrinfo = yes; then 9103b6c3722Schristos AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether getaddrinfo is available]) 9113b6c3722Schristosfi 9123b6c3722Schristos])dnl Endof AC_CHECK_GETADDRINFO_WITH_INCLUDES 9133b6c3722Schristos 9143b6c3722Schristosdnl check if a function is deprecated. defines DEPRECATED_func in config.h. 9153b6c3722Schristosdnl $1: function name 9163b6c3722Schristosdnl $2: C-statement that calls the function. 9173b6c3722Schristosdnl $3: includes for the program. 9183b6c3722Schristosdnl $4: executes if yes 9193b6c3722Schristosdnl $5: executes if no 9203b6c3722SchristosAC_DEFUN([ACX_FUNC_DEPRECATED], 9213b6c3722Schristos[ 9223b6c3722SchristosAC_REQUIRE([AC_PROG_CC]) 9233b6c3722SchristosAC_MSG_CHECKING(if $1 is deprecated) 9243b6c3722Schristoscache=`echo $1 | sed 'y%.=/+-%___p_%'` 9253b6c3722SchristosAC_CACHE_VAL(cv_cc_deprecated_$cache, 9263b6c3722Schristos[ 9273b6c3722Schristosecho '$3' >conftest.c 928*91f7d55fSchristosecho 'void f(void){ $2 }' >>conftest.c 9297a540f2bSchristosif test -z "`$CC $CPPFLAGS $CFLAGS -c conftest.c 2>&1 | grep -e deprecated -e unavailable`"; then 9303b6c3722Schristoseval "cv_cc_deprecated_$cache=no" 9313b6c3722Schristoselse 9323b6c3722Schristoseval "cv_cc_deprecated_$cache=yes" 9333b6c3722Schristosfi 9343b6c3722Schristosrm -f conftest conftest.o conftest.c 9353b6c3722Schristos]) 9363b6c3722Schristosif eval "test \"`echo '$cv_cc_deprecated_'$cache`\" = yes"; then 9373b6c3722SchristosAC_MSG_RESULT(yes) 9383b6c3722SchristosAC_DEFINE_UNQUOTED(AS_TR_CPP([DEPRECATED_$1]), 1, [Whether $1 is deprecated]) 9393b6c3722Schristos: 9403b6c3722Schristos$4 9413b6c3722Schristoselse 9423b6c3722SchristosAC_MSG_RESULT(no) 9433b6c3722Schristos: 9443b6c3722Schristos$5 9453b6c3722Schristosfi 9463b6c3722Schristos])dnl end of ACX_FUNC_DEPRECATED 9473b6c3722Schristos 9483b6c3722Schristosdnl check if select and nonblocking sockets actually work. 9493b6c3722Schristosdnl Needs fork(2) and select(2). 9503b6c3722Schristosdnl defines NONBLOCKING_IS_BROKEN, and if that is true multiple reads from 9513b6c3722Schristosdnl a nonblocking socket do not work, a new call to select is necessary. 9523b6c3722SchristosAC_DEFUN([ACX_CHECK_NONBLOCKING_BROKEN], 9533b6c3722Schristos[ 9543b6c3722SchristosAC_MSG_CHECKING([if nonblocking sockets work]) 9557a540f2bSchristosif echo $host | grep mingw >/dev/null; then 9563b6c3722Schristos AC_MSG_RESULT([no (windows)]) 9573b6c3722Schristos AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).]) 9583b6c3722Schristoselse 9593b6c3722SchristosAC_RUN_IFELSE([ 9603b6c3722SchristosAC_LANG_SOURCE([[ 9613b6c3722Schristos#include <stdio.h> 9623b6c3722Schristos#include <string.h> 9633b6c3722Schristos#include <stdlib.h> 9643b6c3722Schristos#include <fcntl.h> 9653b6c3722Schristos#include <errno.h> 9663b6c3722Schristos#ifdef HAVE_SYS_TYPES_H 9673b6c3722Schristos#include <sys/types.h> 9683b6c3722Schristos#endif 969*91f7d55fSchristos#ifdef HAVE_SYS_SELECT_H 970*91f7d55fSchristos#include <sys/select.h> 971*91f7d55fSchristos#endif 9723b6c3722Schristos#ifdef HAVE_SYS_SOCKET_H 9733b6c3722Schristos#include <sys/socket.h> 9743b6c3722Schristos#endif 9753b6c3722Schristos#ifdef HAVE_NETINET_IN_H 9763b6c3722Schristos#include <netinet/in.h> 9773b6c3722Schristos#endif 9783b6c3722Schristos#ifdef HAVE_ARPA_INET_H 9793b6c3722Schristos#include <arpa/inet.h> 9803b6c3722Schristos#endif 9813b6c3722Schristos#ifdef HAVE_UNISTD_H 9823b6c3722Schristos#include <unistd.h> 9833b6c3722Schristos#endif 9843b6c3722Schristos#ifdef HAVE_TIME_H 9853b6c3722Schristos#include <time.h> 9863b6c3722Schristos#endif 9873b6c3722Schristos 9883b6c3722Schristosint main(void) 9893b6c3722Schristos{ 9903b6c3722Schristos int port; 9913b6c3722Schristos int sfd, cfd; 9923b6c3722Schristos int num = 10; 9933b6c3722Schristos int i, p; 9943b6c3722Schristos struct sockaddr_in a; 9953b6c3722Schristos /* test if select and nonblocking reads work well together */ 9963b6c3722Schristos /* open port. 9973b6c3722Schristos fork child to send 10 messages. 9983b6c3722Schristos select to read. 9993b6c3722Schristos then try to nonblocking read the 10 messages 10003b6c3722Schristos then, nonblocking read must give EAGAIN 10013b6c3722Schristos */ 10023b6c3722Schristos 10033b6c3722Schristos port = 12345 + (time(0)%32); 10043b6c3722Schristos sfd = socket(PF_INET, SOCK_DGRAM, 0); 10053b6c3722Schristos if(sfd == -1) { 10063b6c3722Schristos perror("socket"); 10073b6c3722Schristos return 1; 10083b6c3722Schristos } 10093b6c3722Schristos memset(&a, 0, sizeof(a)); 10103b6c3722Schristos a.sin_family = AF_INET; 10113b6c3722Schristos a.sin_port = htons(port); 10123b6c3722Schristos a.sin_addr.s_addr = inet_addr("127.0.0.1"); 10133b6c3722Schristos if(bind(sfd, (struct sockaddr*)&a, sizeof(a)) < 0) { 10143b6c3722Schristos perror("bind"); 10153b6c3722Schristos return 1; 10163b6c3722Schristos } 10173b6c3722Schristos if(fcntl(sfd, F_SETFL, O_NONBLOCK) == -1) { 10183b6c3722Schristos perror("fcntl"); 10193b6c3722Schristos return 1; 10203b6c3722Schristos } 10213b6c3722Schristos 10223b6c3722Schristos cfd = socket(PF_INET, SOCK_DGRAM, 0); 10233b6c3722Schristos if(cfd == -1) { 10243b6c3722Schristos perror("client socket"); 10253b6c3722Schristos return 1; 10263b6c3722Schristos } 10273b6c3722Schristos a.sin_port = 0; 10283b6c3722Schristos if(bind(cfd, (struct sockaddr*)&a, sizeof(a)) < 0) { 10293b6c3722Schristos perror("client bind"); 10303b6c3722Schristos return 1; 10313b6c3722Schristos } 10323b6c3722Schristos a.sin_port = htons(port); 10333b6c3722Schristos 10343b6c3722Schristos /* no handler, causes exit in 10 seconds */ 10353b6c3722Schristos alarm(10); 10363b6c3722Schristos 10373b6c3722Schristos /* send and receive on the socket */ 10383b6c3722Schristos if((p=fork()) == 0) { 10393b6c3722Schristos for(i=0; i<num; i++) { 10403b6c3722Schristos if(sendto(cfd, &i, sizeof(i), 0, 10413b6c3722Schristos (struct sockaddr*)&a, sizeof(a)) < 0) { 10423b6c3722Schristos perror("sendto"); 10433b6c3722Schristos return 1; 10443b6c3722Schristos } 10453b6c3722Schristos } 10463b6c3722Schristos } else { 10473b6c3722Schristos /* parent */ 10483b6c3722Schristos fd_set rset; 10493b6c3722Schristos int x; 10503b6c3722Schristos if(p == -1) { 10513b6c3722Schristos perror("fork"); 10523b6c3722Schristos return 1; 10533b6c3722Schristos } 10543b6c3722Schristos FD_ZERO(&rset); 10553b6c3722Schristos FD_SET(sfd, &rset); 10563b6c3722Schristos if(select(sfd+1, &rset, NULL, NULL, NULL) < 1) { 10573b6c3722Schristos perror("select"); 10583b6c3722Schristos return 1; 10593b6c3722Schristos } 10603b6c3722Schristos i = 0; 10613b6c3722Schristos while(i < num) { 10623b6c3722Schristos if(recv(sfd, &x, sizeof(x), 0) != sizeof(x)) { 10633b6c3722Schristos if(errno == EAGAIN) 10643b6c3722Schristos continue; 10653b6c3722Schristos perror("recv"); 10663b6c3722Schristos return 1; 10673b6c3722Schristos } 10683b6c3722Schristos i++; 10693b6c3722Schristos } 10703b6c3722Schristos /* now we want to get EAGAIN: nonblocking goodness */ 10713b6c3722Schristos errno = 0; 10723b6c3722Schristos recv(sfd, &x, sizeof(x), 0); 10733b6c3722Schristos if(errno != EAGAIN) { 10743b6c3722Schristos perror("trying to recv again"); 10753b6c3722Schristos return 1; 10763b6c3722Schristos } 10773b6c3722Schristos /* EAGAIN encountered */ 10783b6c3722Schristos } 10793b6c3722Schristos 10803b6c3722Schristos close(sfd); 10813b6c3722Schristos close(cfd); 10823b6c3722Schristos return 0; 10833b6c3722Schristos} 10843b6c3722Schristos]])], [ 10853b6c3722Schristos AC_MSG_RESULT([yes]) 10863b6c3722Schristos], [ 10873b6c3722Schristos AC_MSG_RESULT([no]) 10883b6c3722Schristos AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).]) 10893b6c3722Schristos], [ 10903b6c3722Schristos AC_MSG_RESULT([crosscompile(yes)]) 10913b6c3722Schristos]) 10923b6c3722Schristosfi 10933b6c3722Schristos])dnl End of ACX_CHECK_NONBLOCKING_BROKEN 10943b6c3722Schristos 10953b6c3722Schristosdnl Check if mkdir has one or two arguments. 10963b6c3722Schristosdnl defines MKDIR_HAS_ONE_ARG 10973b6c3722SchristosAC_DEFUN([ACX_MKDIR_ONE_ARG], 10983b6c3722Schristos[ 10993b6c3722SchristosAC_MSG_CHECKING([whether mkdir has one arg]) 1100d0eba39bSchristosAC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 11013b6c3722Schristos#include <stdio.h> 11023b6c3722Schristos#include <unistd.h> 11033b6c3722Schristos#ifdef HAVE_WINSOCK2_H 11043b6c3722Schristos#include <winsock2.h> 11053b6c3722Schristos#endif 11063b6c3722Schristos#ifdef HAVE_SYS_STAT_H 11073b6c3722Schristos#include <sys/stat.h> 11083b6c3722Schristos#endif 1109d0eba39bSchristos]], [[ 11103b6c3722Schristos (void)mkdir("directory"); 1111d0eba39bSchristos]])],[AC_MSG_RESULT(yes) 11123b6c3722SchristosAC_DEFINE(MKDIR_HAS_ONE_ARG, 1, [Define if mkdir has one argument.]) 1113d0eba39bSchristos],[AC_MSG_RESULT(no) 1114d0eba39bSchristos]) 11153b6c3722Schristos])dnl end of ACX_MKDIR_ONE_ARG 11163b6c3722Schristos 11173b6c3722Schristosdnl Check for ioctlsocket function. works on mingw32 too. 11183b6c3722SchristosAC_DEFUN([ACX_FUNC_IOCTLSOCKET], 11193b6c3722Schristos[ 11203b6c3722Schristos# check ioctlsocket 11213b6c3722SchristosAC_MSG_CHECKING(for ioctlsocket) 11223b6c3722SchristosAC_LINK_IFELSE([AC_LANG_PROGRAM([ 11233b6c3722Schristos#ifdef HAVE_WINSOCK2_H 11243b6c3722Schristos#include <winsock2.h> 11253b6c3722Schristos#endif 11263b6c3722Schristos], [ 11273b6c3722Schristos (void)ioctlsocket(0, 0, NULL); 11283b6c3722Schristos])], [ 11293b6c3722SchristosAC_MSG_RESULT(yes) 11303b6c3722SchristosAC_DEFINE(HAVE_IOCTLSOCKET, 1, [if the function 'ioctlsocket' is available]) 11313b6c3722Schristos],[AC_MSG_RESULT(no)]) 11323b6c3722Schristos])dnl end of ACX_FUNC_IOCTLSOCKET 11333b6c3722Schristos 11343b6c3722Schristosdnl detect malloc and provide malloc compat prototype. 11353b6c3722Schristosdnl $1: unique name for compat code 11363b6c3722SchristosAC_DEFUN([ACX_FUNC_MALLOC], 11373b6c3722Schristos[ 11383b6c3722Schristos AC_MSG_CHECKING([for GNU libc compatible malloc]) 11393b6c3722Schristos AC_RUN_IFELSE([AC_LANG_PROGRAM( 11403b6c3722Schristos[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H 11413b6c3722Schristos#include <stdlib.h> 11423b6c3722Schristos#else 11433b6c3722Schristoschar *malloc (); 11443b6c3722Schristos#endif 11453b6c3722Schristos]], [ if(malloc(0) != 0) return 1;]) 11463b6c3722Schristos], 11473b6c3722Schristos [AC_MSG_RESULT([no]) 11483b6c3722Schristos AC_LIBOBJ(malloc) 11493b6c3722Schristos AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] , 11503b6c3722Schristos [AC_MSG_RESULT([yes]) 11513b6c3722Schristos AC_DEFINE([HAVE_MALLOC], 1, [If have GNU libc compatible malloc])], 11523b6c3722Schristos [AC_MSG_RESULT([no (crosscompile)]) 11533b6c3722Schristos AC_LIBOBJ(malloc) 11543b6c3722Schristos AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] ) 11553b6c3722Schristos]) 11563b6c3722Schristos 11573b6c3722Schristosdnl Define fallback for fseeko and ftello if needed. 11583b6c3722SchristosAC_DEFUN([AHX_CONFIG_FSEEKO], 11593b6c3722Schristos[ 11603b6c3722Schristos#ifndef HAVE_FSEEKO 11613b6c3722Schristos#define fseeko fseek 11623b6c3722Schristos#define ftello ftell 11633b6c3722Schristos#endif /* HAVE_FSEEKO */ 11643b6c3722Schristos]) 11653b6c3722Schristos 11663b6c3722Schristosdnl Define RAND_MAX if not defined 11673b6c3722SchristosAC_DEFUN([AHX_CONFIG_RAND_MAX], 11683b6c3722Schristos[ 11693b6c3722Schristos#ifndef RAND_MAX 11703b6c3722Schristos#define RAND_MAX 2147483647 11713b6c3722Schristos#endif 11723b6c3722Schristos]) 11733b6c3722Schristos 11743b6c3722Schristosdnl Define MAXHOSTNAMELEN if not defined 11753b6c3722SchristosAC_DEFUN([AHX_CONFIG_MAXHOSTNAMELEN], 11763b6c3722Schristos[ 11773b6c3722Schristos#ifndef MAXHOSTNAMELEN 11783b6c3722Schristos#define MAXHOSTNAMELEN 256 11793b6c3722Schristos#endif 11803b6c3722Schristos]) 11813b6c3722Schristos 11823b6c3722Schristosdnl Define IPV6_MIN_MTU if not defined 11833b6c3722SchristosAC_DEFUN([AHX_CONFIG_IPV6_MIN_MTU], 11843b6c3722Schristos[ 11853b6c3722Schristos#ifndef IPV6_MIN_MTU 11863b6c3722Schristos#define IPV6_MIN_MTU 1280 11873b6c3722Schristos#endif /* IPV6_MIN_MTU */ 11883b6c3722Schristos]) 11893b6c3722Schristos 11903b6c3722Schristosdnl provide snprintf, vsnprintf compat prototype 11913b6c3722Schristosdnl $1: unique name for compat code 11923b6c3722SchristosAC_DEFUN([AHX_CONFIG_SNPRINTF], 11933b6c3722Schristos[ 11943b6c3722Schristos#ifndef HAVE_SNPRINTF 11953b6c3722Schristos#define snprintf snprintf_$1 11963b6c3722Schristos#define vsnprintf vsnprintf_$1 11973b6c3722Schristos#include <stdarg.h> 11983b6c3722Schristosint snprintf (char *str, size_t count, const char *fmt, ...); 11993b6c3722Schristosint vsnprintf (char *str, size_t count, const char *fmt, va_list arg); 12003b6c3722Schristos#endif /* HAVE_SNPRINTF */ 12013b6c3722Schristos]) 12023b6c3722Schristos 12033b6c3722Schristosdnl provide inet_pton compat prototype. 12043b6c3722Schristosdnl $1: unique name for compat code 12053b6c3722SchristosAC_DEFUN([AHX_CONFIG_INET_PTON], 12063b6c3722Schristos[ 12073b6c3722Schristos#ifndef HAVE_INET_PTON 12083b6c3722Schristos#define inet_pton inet_pton_$1 12093b6c3722Schristosint inet_pton(int af, const char* src, void* dst); 12103b6c3722Schristos#endif /* HAVE_INET_PTON */ 12113b6c3722Schristos]) 12123b6c3722Schristos 12133b6c3722Schristosdnl provide inet_ntop compat prototype. 12143b6c3722Schristosdnl $1: unique name for compat code 12153b6c3722SchristosAC_DEFUN([AHX_CONFIG_INET_NTOP], 12163b6c3722Schristos[ 12173b6c3722Schristos#ifndef HAVE_INET_NTOP 12183b6c3722Schristos#define inet_ntop inet_ntop_$1 12193b6c3722Schristosconst char *inet_ntop(int af, const void *src, char *dst, size_t size); 12203b6c3722Schristos#endif 12213b6c3722Schristos]) 12223b6c3722Schristos 12233b6c3722Schristosdnl provide inet_aton compat prototype. 12243b6c3722Schristosdnl $1: unique name for compat code 12253b6c3722SchristosAC_DEFUN([AHX_CONFIG_INET_ATON], 12263b6c3722Schristos[ 12273b6c3722Schristos#ifndef HAVE_INET_ATON 12283b6c3722Schristos#define inet_aton inet_aton_$1 12293b6c3722Schristosint inet_aton(const char *cp, struct in_addr *addr); 12303b6c3722Schristos#endif 12313b6c3722Schristos]) 12323b6c3722Schristos 12333b6c3722Schristosdnl provide memmove compat prototype. 12343b6c3722Schristosdnl $1: unique name for compat code 12353b6c3722SchristosAC_DEFUN([AHX_CONFIG_MEMMOVE], 12363b6c3722Schristos[ 12373b6c3722Schristos#ifndef HAVE_MEMMOVE 12383b6c3722Schristos#define memmove memmove_$1 12393b6c3722Schristosvoid *memmove(void *dest, const void *src, size_t n); 12403b6c3722Schristos#endif 12413b6c3722Schristos]) 12423b6c3722Schristos 12433b6c3722Schristosdnl provide strlcat compat prototype. 12443b6c3722Schristosdnl $1: unique name for compat code 12453b6c3722SchristosAC_DEFUN([AHX_CONFIG_STRLCAT], 12463b6c3722Schristos[ 12473b6c3722Schristos#ifndef HAVE_STRLCAT 12483b6c3722Schristos#define strlcat strlcat_$1 12493b6c3722Schristossize_t strlcat(char *dst, const char *src, size_t siz); 12503b6c3722Schristos#endif 12513b6c3722Schristos]) 12523b6c3722Schristos 12533b6c3722Schristosdnl provide strlcpy compat prototype. 12543b6c3722Schristosdnl $1: unique name for compat code 12553b6c3722SchristosAC_DEFUN([AHX_CONFIG_STRLCPY], 12563b6c3722Schristos[ 12573b6c3722Schristos#ifndef HAVE_STRLCPY 12583b6c3722Schristos#define strlcpy strlcpy_$1 12593b6c3722Schristossize_t strlcpy(char *dst, const char *src, size_t siz); 12603b6c3722Schristos#endif 12613b6c3722Schristos]) 12623b6c3722Schristos 12633b6c3722Schristosdnl provide gmtime_r compat prototype. 12643b6c3722Schristosdnl $1: unique name for compat code 12653b6c3722SchristosAC_DEFUN([AHX_CONFIG_GMTIME_R], 12663b6c3722Schristos[ 12673b6c3722Schristos#ifndef HAVE_GMTIME_R 12683b6c3722Schristos#define gmtime_r gmtime_r_$1 12693b6c3722Schristosstruct tm *gmtime_r(const time_t *timep, struct tm *result); 12703b6c3722Schristos#endif 12713b6c3722Schristos]) 12723b6c3722Schristos 12733b6c3722Schristosdnl provide reallocarray compat prototype. 12743b6c3722Schristosdnl $1: unique name for compat code 12753b6c3722SchristosAC_DEFUN([AHX_CONFIG_REALLOCARRAY], 12763b6c3722Schristos[ 12773b6c3722Schristos#ifndef HAVE_REALLOCARRAY 12783b6c3722Schristos#define reallocarray reallocarray$1 12793b6c3722Schristosvoid* reallocarray(void *ptr, size_t nmemb, size_t size); 12803b6c3722Schristos#endif 12813b6c3722Schristos]) 12823b6c3722Schristos 12833b6c3722Schristosdnl provide w32 compat definition for sleep 12843b6c3722SchristosAC_DEFUN([AHX_CONFIG_W32_SLEEP], 12853b6c3722Schristos[ 12863b6c3722Schristos#if !defined(HAVE_SLEEP) || defined(HAVE_WINDOWS_H) 12873b6c3722Schristos#define sleep(x) Sleep((x)*1000) /* on win32 */ 12883b6c3722Schristos#endif /* HAVE_SLEEP */ 12893b6c3722Schristos]) 12903b6c3722Schristos 12913b6c3722Schristosdnl provide w32 compat definition for usleep 12923b6c3722SchristosAC_DEFUN([AHX_CONFIG_W32_USLEEP], 12933b6c3722Schristos[ 12943b6c3722Schristos#ifndef HAVE_USLEEP 12953b6c3722Schristos#define usleep(x) Sleep((x)/1000 + 1) /* on win32 */ 12963b6c3722Schristos#endif /* HAVE_USLEEP */ 12973b6c3722Schristos]) 12983b6c3722Schristos 12993b6c3722Schristosdnl provide w32 compat definition for random 13003b6c3722SchristosAC_DEFUN([AHX_CONFIG_W32_RANDOM], 13013b6c3722Schristos[ 13023b6c3722Schristos#ifndef HAVE_RANDOM 13033b6c3722Schristos#define random rand /* on win32, for tests only (bad random) */ 13043b6c3722Schristos#endif /* HAVE_RANDOM */ 13053b6c3722Schristos]) 13063b6c3722Schristos 13073b6c3722Schristosdnl provide w32 compat definition for srandom 13083b6c3722SchristosAC_DEFUN([AHX_CONFIG_W32_SRANDOM], 13093b6c3722Schristos[ 13103b6c3722Schristos#ifndef HAVE_SRANDOM 13113b6c3722Schristos#define srandom(x) srand(x) /* on win32, for tests only (bad random) */ 13123b6c3722Schristos#endif /* HAVE_SRANDOM */ 13133b6c3722Schristos]) 13143b6c3722Schristos 13153b6c3722Schristosdnl provide w32 compat definition for FD_SET_T 13163b6c3722SchristosAC_DEFUN([AHX_CONFIG_W32_FD_SET_T], 13173b6c3722Schristos[ 13183b6c3722Schristos/* detect if we need to cast to unsigned int for FD_SET to avoid warnings */ 13193b6c3722Schristos#ifdef HAVE_WINSOCK2_H 13203b6c3722Schristos#define FD_SET_T (u_int) 13213b6c3722Schristos#else 13223b6c3722Schristos#define FD_SET_T 13233b6c3722Schristos#endif 13243b6c3722Schristos]) 13253b6c3722Schristos 13263b6c3722Schristosdnl Remove an extension flag from CFLAGS, define replacement to be made. 13273b6c3722Schristosdnl Used by ACX_STRIP_EXT_FLAGS. 13283b6c3722Schristosdnl $1: the name of the flag, for example -D_GNU_SOURCE. 13293b6c3722SchristosAC_DEFUN([ACX_CFLAGS_STRIP], 13303b6c3722Schristos[ 13313b6c3722Schristos if echo $CFLAGS | grep " $1" >/dev/null 2>&1; then 13323b6c3722Schristos CFLAGS="`echo $CFLAGS | sed -e 's/ $1//g'`" 13333b6c3722Schristos AC_DEFINE(m4_bpatsubst(OMITTED_$1,[[-=]],_), 1, Put $1 define in config.h) 13343b6c3722Schristos fi 13353b6c3722Schristos]) 13363b6c3722Schristos 13373b6c3722Schristosdnl Remove EXT flags from the CFLAGS and set them to be defined in config.h 13383b6c3722Schristosdnl use with ACX_DETERMINE_EXT_FLAGS. 13393b6c3722SchristosAC_DEFUN([ACX_STRIP_EXT_FLAGS], 13403b6c3722Schristos[ 13413b6c3722Schristos AC_MSG_NOTICE([Stripping extension flags...]) 13423b6c3722Schristos ACX_CFLAGS_STRIP(-D_GNU_SOURCE) 13433b6c3722Schristos ACX_CFLAGS_STRIP(-D_BSD_SOURCE) 13443b6c3722Schristos ACX_CFLAGS_STRIP(-D_DEFAULT_SOURCE) 13453b6c3722Schristos ACX_CFLAGS_STRIP(-D__EXTENSIONS__) 13463b6c3722Schristos ACX_CFLAGS_STRIP(-D_POSIX_C_SOURCE=200112) 13473b6c3722Schristos ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE=600) 13483b6c3722Schristos ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE_EXTENDED=1) 13493b6c3722Schristos ACX_CFLAGS_STRIP(-D_ALL_SOURCE) 13503b6c3722Schristos ACX_CFLAGS_STRIP(-D_LARGEFILE_SOURCE=1) 13513b6c3722Schristos]) dnl End of ACX_STRIP_EXT_FLAGS 13523b6c3722Schristos 13533b6c3722Schristosdnl define one omitted flag for config.h 13543b6c3722Schristosdnl $1: flag name. -D_GNU_SOURCE 13553b6c3722Schristosdnl $2: replacement define. _GNU_SOURCE 13563b6c3722Schristosdnl $3: define value, 1 13573b6c3722SchristosAC_DEFUN([AHX_CONFIG_FLAG_OMITTED], 13583b6c3722Schristos[#if defined($1) && !defined($2) 13593b6c3722Schristos#define $2 $3 13603b6c3722Schristos[#]endif]) 13613b6c3722Schristos 13623b6c3722Schristosdnl Wrapper for AHX_CONFIG_FLAG_OMITTED for -D style flags 13633b6c3722Schristosdnl $1: the -DNAME or -DNAME=value string. 13643b6c3722SchristosAC_DEFUN([AHX_CONFIG_FLAG_EXT], 13653b6c3722Schristos[AHX_CONFIG_FLAG_OMITTED(m4_bpatsubst(OMITTED_$1,[[-=]],_),m4_bpatsubst(m4_bpatsubst($1,-D,),=.*$,),m4_if(m4_bregexp($1,=),-1,1,m4_bpatsubst($1,^.*=,))) 13663b6c3722Schristos]) 13673b6c3722Schristos 13683b6c3722Schristosdnl config.h part to define omitted cflags, use with ACX_STRIP_EXT_FLAGS. 13693b6c3722SchristosAC_DEFUN([AHX_CONFIG_EXT_FLAGS], 13703b6c3722Schristos[AHX_CONFIG_FLAG_EXT(-D_GNU_SOURCE) 13713b6c3722SchristosAHX_CONFIG_FLAG_EXT(-D_BSD_SOURCE) 13723b6c3722SchristosAHX_CONFIG_FLAG_EXT(-D_DEFAULT_SOURCE) 13733b6c3722SchristosAHX_CONFIG_FLAG_EXT(-D__EXTENSIONS__) 13743b6c3722SchristosAHX_CONFIG_FLAG_EXT(-D_POSIX_C_SOURCE=200112) 13753b6c3722SchristosAHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE=600) 13763b6c3722SchristosAHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE_EXTENDED=1) 13773b6c3722SchristosAHX_CONFIG_FLAG_EXT(-D_ALL_SOURCE) 13783b6c3722SchristosAHX_CONFIG_FLAG_EXT(-D_LARGEFILE_SOURCE=1) 13793b6c3722Schristos]) 13803b6c3722Schristos 13813b6c3722Schristosdnl check if memcmp is using signed characters and replace if so. 13823b6c3722SchristosAC_DEFUN([ACX_CHECK_MEMCMP_SIGNED], 13833b6c3722Schristos[AC_MSG_CHECKING([if memcmp compares unsigned]) 13843b6c3722SchristosAC_RUN_IFELSE([AC_LANG_SOURCE([[ 13853b6c3722Schristos#include <stdio.h> 13863b6c3722Schristos#include <stdlib.h> 13873b6c3722Schristos#include <string.h> 13883b6c3722Schristosint main(void) 13893b6c3722Schristos{ 13903b6c3722Schristos char a = 255, b = 0; 13913b6c3722Schristos if(memcmp(&a, &b, 1) < 0) 13923b6c3722Schristos return 1; 13933b6c3722Schristos return 0; 13943b6c3722Schristos} 13953b6c3722Schristos]])], [AC_MSG_RESULT([yes]) ], 13963b6c3722Schristos[ AC_MSG_RESULT([no]) 13973b6c3722Schristos AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes]) 13983b6c3722Schristos AC_LIBOBJ([memcmp]) 13993b6c3722Schristos], [ AC_MSG_RESULT([cross-compile no]) 14003b6c3722Schristos AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes]) 14013b6c3722Schristos AC_LIBOBJ([memcmp]) 14023b6c3722Schristos]) ]) 14033b6c3722Schristos 14043b6c3722Schristosdnl define memcmp to its replacement, pass unique id for program as arg 14053b6c3722SchristosAC_DEFUN([AHX_MEMCMP_BROKEN], [ 14063b6c3722Schristos#ifdef MEMCMP_IS_BROKEN 14073b6c3722Schristos#include "compat/memcmp.h" 14083b6c3722Schristos#define memcmp memcmp_$1 14093b6c3722Schristosint memcmp(const void *x, const void *y, size_t n); 14103b6c3722Schristos#endif 14113b6c3722Schristos]) 14123b6c3722Schristos 14133b6c3722Schristosdnl ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family 14143b6c3722SchristosAC_DEFUN([ACX_CHECK_SS_FAMILY], 14153b6c3722Schristos[AC_CHECK_MEMBER([struct sockaddr_storage.ss_family], [], [ 14163b6c3722Schristos AC_CHECK_MEMBER([struct sockaddr_storage.__ss_family], [ 14173b6c3722Schristos AC_DEFINE([ss_family], [__ss_family], [Fallback member name for socket family in struct sockaddr_storage]) 14183b6c3722Schristos ],, [AC_INCLUDES_DEFAULT 14193b6c3722Schristos#ifdef HAVE_NETINET_IN_H 14203b6c3722Schristos#include <netinet/in.h> 14213b6c3722Schristos#endif 14223b6c3722Schristos#ifdef HAVE_SYS_SOCKET_H 14233b6c3722Schristos#include <sys/socket.h> 14243b6c3722Schristos#endif 14253b6c3722Schristos#ifdef HAVE_NETDB_H 14263b6c3722Schristos#include <netdb.h> 14273b6c3722Schristos#endif 14283b6c3722Schristos#ifdef HAVE_ARPA_INET_H 14293b6c3722Schristos#include <arpa/inet.h> 14303b6c3722Schristos#endif 14313b6c3722Schristos ]) 14323b6c3722Schristos], [AC_INCLUDES_DEFAULT 14333b6c3722Schristos#ifdef HAVE_NETINET_IN_H 14343b6c3722Schristos#include <netinet/in.h> 14353b6c3722Schristos#endif 14363b6c3722Schristos#ifdef HAVE_SYS_SOCKET_H 14373b6c3722Schristos#include <sys/socket.h> 14383b6c3722Schristos#endif 14393b6c3722Schristos#ifdef HAVE_NETDB_H 14403b6c3722Schristos#include <netdb.h> 14413b6c3722Schristos#endif 14423b6c3722Schristos#ifdef HAVE_ARPA_INET_H 14433b6c3722Schristos#include <arpa/inet.h> 14443b6c3722Schristos#endif 14453b6c3722Schristos]) ]) 14463b6c3722Schristos 14473b6c3722Schristosdnl Check if CC and linker support -fPIE and -pie. 14483b6c3722Schristosdnl If so, sets them in CFLAGS / LDFLAGS. 14493b6c3722SchristosAC_DEFUN([ACX_CHECK_PIE], [ 14503b6c3722Schristos AC_ARG_ENABLE([pie], AS_HELP_STRING([--enable-pie], [Enable Position-Independent Executable (eg. to fully benefit from ASLR, small performance penalty)])) 14513b6c3722Schristos AS_IF([test "x$enable_pie" = "xyes"], [ 14523b6c3722Schristos AC_MSG_CHECKING([if $CC supports PIE]) 14533b6c3722Schristos BAKLDFLAGS="$LDFLAGS" 14543b6c3722Schristos BAKCFLAGS="$CFLAGS" 14553b6c3722Schristos LDFLAGS="$LDFLAGS -pie" 14563b6c3722Schristos CFLAGS="$CFLAGS -fPIE" 14573b6c3722Schristos AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [ 14583b6c3722Schristos if $CC $CFLAGS $LDFLAGS -o conftest conftest.c 2>&1 | grep "warning: no debug symbols in executable" >/dev/null; then 14593b6c3722Schristos LDFLAGS="$BAKLDFLAGS" 14603b6c3722Schristos AC_MSG_RESULT(no) 14613b6c3722Schristos else 14623b6c3722Schristos AC_MSG_RESULT(yes) 14633b6c3722Schristos fi 14643b6c3722Schristos rm -f conftest conftest.c conftest.o 14653b6c3722Schristos ], [LDFLAGS="$BAKLDFLAGS" ; CFLAGS="$BAKCFLAGS" ; AC_MSG_RESULT(no)]) 14663b6c3722Schristos ]) 14673b6c3722Schristos]) 14683b6c3722Schristos 14693b6c3722Schristosdnl Check if linker supports -Wl,-z,relro,-z,now. 14703b6c3722Schristosdnl If so, adds it to LDFLAGS. 14713b6c3722SchristosAC_DEFUN([ACX_CHECK_RELRO_NOW], [ 14723b6c3722Schristos 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)])) 14733b6c3722Schristos AS_IF([test "x$enable_relro_now" = "xyes"], [ 14743b6c3722Schristos AC_MSG_CHECKING([if $CC supports -Wl,-z,relro,-z,now]) 14753b6c3722Schristos BAKLDFLAGS="$LDFLAGS" 14763b6c3722Schristos LDFLAGS="$LDFLAGS -Wl,-z,relro,-z,now" 14773b6c3722Schristos AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [ 14783b6c3722Schristos if $CC $CFLAGS $LDFLAGS -o conftest conftest.c 2>&1 | grep "warning: no debug symbols in executable" >/dev/null; then 14793b6c3722Schristos LDFLAGS="$BAKLDFLAGS" 14803b6c3722Schristos AC_MSG_RESULT(no) 14813b6c3722Schristos else 14823b6c3722Schristos AC_MSG_RESULT(yes) 14833b6c3722Schristos fi 14843b6c3722Schristos rm -f conftest conftest.c conftest.o 14853b6c3722Schristos ], [LDFLAGS="$BAKLDFLAGS" ; AC_MSG_RESULT(no)]) 14863b6c3722Schristos ]) 14873b6c3722Schristos]) 14883b6c3722Schristos 14893b6c3722Schristosdnl End of file 1490