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