acx_nlnetlabs.m4 revision 296415
1238106Sdes# acx_nlnetlabs.m4 - common macros for configure checks 2238106Sdes# Copyright 2009, Wouter Wijngaards, NLnet Labs. 3238106Sdes# BSD licensed. 4238106Sdes# 5296415Sdes# Version 32 6296415Sdes# 2016-01-04 -D_DEFAULT_SOURCE defined with -D_BSD_SOURCE for Linux glibc 2.20 7296415Sdes# 2015-12-11 FLTO check for new OSX, clang. 8292206Sdes# 2015-11-18 spelling check fix. 9292206Sdes# 2015-11-05 ACX_SSL_CHECKS no longer adds -ldl needlessly. 10289063Sdes# 2015-08-28 ACX_CHECK_PIE and ACX_CHECK_RELRO_NOW added. 11287917Sdes# 2015-03-17 AHX_CONFIG_REALLOCARRAY added 12266114Sdes# 2013-09-19 FLTO help text improved. 13266114Sdes# 2013-07-18 Enable ACX_CHECK_COMPILER_FLAG to test for -Wstrict-prototypes 14266114Sdes# 2013-06-25 FLTO has --disable-flto option. 15266114Sdes# 2013-05-03 Update W32_SLEEP for newer mingw that links but not defines it. 16266114Sdes# 2013-03-22 Fix ACX_RSRC_VERSION for long version numbers. 17238106Sdes# 2012-02-09 Fix AHX_MEMCMP_BROKEN with undef in compat/memcmp.h. 18238106Sdes# 2012-01-20 Fix COMPILER_FLAGS_UNBOUND for gcc 4.6.2 assigned-not-used-warns. 19238106Sdes# 2011-12-05 Fix getaddrinfowithincludes on windows with fedora16 mingw32-gcc. 20238106Sdes# Fix ACX_MALLOC for redefined malloc error. 21238106Sdes# Fix GETADDRINFO_WITH_INCLUDES to add -lws2_32 22238106Sdes# 2011-11-10 Fix FLTO test to not drop a.out in current directory. 23238106Sdes# 2011-11-01 Fix FLTO test for llvm on Lion. 24238106Sdes# 2011-08-01 Fix nonblock test (broken at v13). 25238106Sdes# 2011-08-01 Fix autoconf 2.68 warnings 26238106Sdes# 2011-06-23 Add ACX_CHECK_FLTO to check -flto. 27238106Sdes# 2010-08-16 Fix FLAG_OMITTED for AS_TR_CPP changes in autoconf-2.66. 28238106Sdes# 2010-07-02 Add check for ss_family (for minix). 29238106Sdes# 2010-04-26 Fix to use CPPFLAGS for CHECK_COMPILER_FLAGS. 30238106Sdes# 2010-03-01 Fix RPATH using CONFIG_COMMANDS to run at the very end. 31292206Sdes# 2010-02-18 WITH_SSL outputs the LIBSSL_LDFLAGS, LIBS, CPPFLAGS separate, -ldl 32238106Sdes# 2010-02-01 added ACX_CHECK_MEMCMP_SIGNED, AHX_MEMCMP_BROKEN 33238106Sdes# 2010-01-20 added AHX_COONFIG_STRLCAT 34238106Sdes# 2009-07-14 U_CHAR detection improved for windows crosscompile. 35238106Sdes# added ACX_FUNC_MALLOC 36238106Sdes# fixup some #if to #ifdef 37238106Sdes# NONBLOCKING test for mingw crosscompile. 38238106Sdes# 2009-07-13 added ACX_WITH_SSL_OPTIONAL 39238106Sdes# 2009-07-03 fixup LDFLAGS for empty ssl dir. 40238106Sdes# 41238106Sdes# Automates some of the checking constructs. Aims at portability for POSIX. 42238106Sdes# Documentation for functions is below. 43238106Sdes# 44238106Sdes# the following macro's are provided in this file: 45238106Sdes# (see below for details on each macro). 46238106Sdes# 47238106Sdes# ACX_ESCAPE_BACKSLASH - escape backslashes in var for C-preproc. 48238106Sdes# ACX_RSRC_VERSION - create windows resource version number. 49238106Sdes# ACX_CHECK_COMPILER_FLAG - see if cc supports a flag. 50238106Sdes# ACX_CHECK_ERROR_FLAGS - see which flag is -werror (used below). 51238106Sdes# ACX_CHECK_COMPILER_FLAG_NEEDED - see if flags make the code compile cleanly. 52238106Sdes# ACX_DEPFLAG - find cc dependency flags. 53238106Sdes# ACX_DETERMINE_EXT_FLAGS_UNBOUND - find out which flags enable BSD and POSIX. 54238106Sdes# ACX_CHECK_FORMAT_ATTRIBUTE - find cc printf format syntax. 55238106Sdes# ACX_CHECK_UNUSED_ATTRIBUTE - find cc variable unused syntax. 56238106Sdes# ACX_CHECK_FLTO - see if cc supports -flto and use it if so. 57238106Sdes# ACX_LIBTOOL_C_ONLY - create libtool for C only, improved. 58238106Sdes# ACX_TYPE_U_CHAR - u_char type. 59238106Sdes# ACX_TYPE_RLIM_T - rlim_t type. 60238106Sdes# ACX_TYPE_SOCKLEN_T - socklen_t type. 61238106Sdes# ACX_TYPE_IN_ADDR_T - in_addr_t type. 62238106Sdes# ACX_TYPE_IN_PORT_T - in_port_t type. 63238106Sdes# ACX_ARG_RPATH - add --disable-rpath option. 64238106Sdes# ACX_WITH_SSL - add --with-ssl option, link -lcrypto. 65238106Sdes# ACX_WITH_SSL_OPTIONAL - add --with-ssl option, link -lcrypto, 66238106Sdes# where --without-ssl is also accepted 67238106Sdes# ACX_LIB_SSL - setup to link -lssl. 68238106Sdes# ACX_SYS_LARGEFILE - improved sys_largefile, fseeko, >2G files. 69238106Sdes# ACX_CHECK_GETADDRINFO_WITH_INCLUDES - find getaddrinfo, portably. 70238106Sdes# ACX_FUNC_DEPRECATED - see if func is deprecated. 71238106Sdes# ACX_CHECK_NONBLOCKING_BROKEN - see if nonblocking sockets really work. 72238106Sdes# ACX_MKDIR_ONE_ARG - determine mkdir(2) number of arguments. 73238106Sdes# ACX_FUNC_IOCTLSOCKET - find ioctlsocket, portably. 74238106Sdes# ACX_FUNC_MALLOC - check malloc, define replacement . 75238106Sdes# AHX_CONFIG_FORMAT_ATTRIBUTE - config.h text for format. 76238106Sdes# AHX_CONFIG_UNUSED_ATTRIBUTE - config.h text for unused. 77238106Sdes# AHX_CONFIG_FSEEKO - define fseeko, ftello fallback. 78238106Sdes# AHX_CONFIG_RAND_MAX - define RAND_MAX if needed. 79238106Sdes# AHX_CONFIG_MAXHOSTNAMELEN - define MAXHOSTNAMELEN if needed. 80238106Sdes# AHX_CONFIG_IPV6_MIN_MTU - define IPV6_MIN_MTU if needed. 81238106Sdes# AHX_CONFIG_SNPRINTF - snprintf compat prototype 82238106Sdes# AHX_CONFIG_INET_PTON - inet_pton compat prototype 83238106Sdes# AHX_CONFIG_INET_NTOP - inet_ntop compat prototype 84238106Sdes# AHX_CONFIG_INET_ATON - inet_aton compat prototype 85238106Sdes# AHX_CONFIG_MEMMOVE - memmove compat prototype 86238106Sdes# AHX_CONFIG_STRLCAT - strlcat compat prototype 87238106Sdes# AHX_CONFIG_STRLCPY - strlcpy compat prototype 88238106Sdes# AHX_CONFIG_GMTIME_R - gmtime_r compat prototype 89238106Sdes# AHX_CONFIG_W32_SLEEP - w32 compat for sleep 90238106Sdes# AHX_CONFIG_W32_USLEEP - w32 compat for usleep 91238106Sdes# AHX_CONFIG_W32_RANDOM - w32 compat for random 92238106Sdes# AHX_CONFIG_W32_SRANDOM - w32 compat for srandom 93238106Sdes# AHX_CONFIG_W32_FD_SET_T - w32 detection of FD_SET_T. 94238106Sdes# ACX_CFLAGS_STRIP - strip one flag from CFLAGS 95238106Sdes# ACX_STRIP_EXT_FLAGS - strip extension flags from CFLAGS 96238106Sdes# AHX_CONFIG_FLAG_OMITTED - define omitted flag 97238106Sdes# AHX_CONFIG_FLAG_EXT - define omitted extension flag 98238106Sdes# AHX_CONFIG_EXT_FLAGS - define the stripped extension flags 99238106Sdes# ACX_CHECK_MEMCMP_SIGNED - check if memcmp uses signed characters. 100238106Sdes# AHX_MEMCMP_BROKEN - replace memcmp func for CHECK_MEMCMP_SIGNED. 101238106Sdes# ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family 102289063Sdes# ACX_CHECK_PIE - add --enable-pie option and check if works 103289063Sdes# ACX_CHECK_RELRO_NOW - add --enable-relro-now option and check it 104238106Sdes# 105238106Sdes 106238106Sdesdnl Escape backslashes as \\, for C:\ paths, for the C preprocessor defines. 107238106Sdesdnl for example, ACX_ESCAPE_BACKSLASH($from_var, to_var) 108238106Sdesdnl $1: the text to change. 109238106Sdesdnl $2: the result. 110238106SdesAC_DEFUN([ACX_ESCAPE_BACKSLASH], [$2="`echo $1 | sed -e 's/\\\\/\\\\\\\\/g'`" 111238106Sdes]) 112238106Sdes 113238106Sdesdnl Calculate comma separated windows-resource numbers from package version. 114238106Sdesdnl Picks the first three(,0) or four numbers out of the name. 115238106Sdesdnl $1: variable for the result 116238106SdesAC_DEFUN([ACX_RSRC_VERSION], 117266114Sdes[$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/' `] 118238106Sdes]) 119238106Sdes 120238106Sdesdnl Routine to help check for compiler flags. 121238106Sdesdnl Checks if the compiler will accept the flag. 122238106Sdesdnl $1: the flag without a - in front, so g to check -g. 123238106Sdesdnl $2: executed if yes 124238106Sdesdnl $3: executed if no 125238106SdesAC_DEFUN([ACX_CHECK_COMPILER_FLAG], 126238106Sdes[ 127238106SdesAC_REQUIRE([AC_PROG_CC]) 128238106SdesAC_MSG_CHECKING(whether $CC supports -$1) 129238106Sdescache=`echo $1 | sed 'y%.=/+-%___p_%'` 130238106SdesAC_CACHE_VAL(cv_prog_cc_flag_$cache, 131238106Sdes[ 132266114Sdesecho 'void f(void){}' >conftest.c 133238106Sdesif test -z "`$CC $CPPFLAGS $CFLAGS -$1 -c conftest.c 2>&1`"; then 134238106Sdeseval "cv_prog_cc_flag_$cache=yes" 135238106Sdeselse 136238106Sdeseval "cv_prog_cc_flag_$cache=no" 137238106Sdesfi 138238106Sdesrm -f conftest conftest.o conftest.c 139238106Sdes]) 140238106Sdesif eval "test \"`echo '$cv_prog_cc_flag_'$cache`\" = yes"; then 141238106SdesAC_MSG_RESULT(yes) 142238106Sdes: 143238106Sdes$2 144238106Sdeselse 145238106SdesAC_MSG_RESULT(no) 146238106Sdes: 147238106Sdes$3 148238106Sdesfi 149238106Sdes]) 150238106Sdes 151238106Sdesdnl setup flags for ACX_CHECK_COMPILER_FLAG_NEEDED 152238106Sdesdnl ERRFLAG: result, compiler flag to turn warnings into errors 153238106SdesAC_DEFUN([ACX_CHECK_ERROR_FLAGS], 154238106Sdes[ 155238106SdesACX_CHECK_COMPILER_FLAG(Werror, [ERRFLAG="-Werror"], [ERRFLAG="-errwarn"]) 156238106SdesACX_CHECK_COMPILER_FLAG(Wall, [ERRFLAG="$ERRFLAG -Wall"], 157238106Sdes [ERRFLAG="$ERRFLAG -errfmt"]) 158238106Sdes]) 159238106Sdes 160238106Sdesdnl Routine to help check for needed compiler flags. 161238106Sdesdnl $1: flags for CC 162238106Sdesdnl $2: the includes and code 163238106Sdesdnl $3: if the given code only compiles with the flag, execute argument 3 164238106Sdesdnl $4: if the given code compiles without the flag, execute argument 4 165238106Sdesdnl $5: with and without flag the compile fails, execute argument 5. 166238106SdesAC_DEFUN([ACX_CHECK_COMPILER_FLAG_NEEDED], 167238106Sdes[ 168238106SdesAC_REQUIRE([AC_PROG_CC]) 169238106SdesAC_REQUIRE([ACX_CHECK_ERROR_FLAGS]) 170238106SdesAC_MSG_CHECKING(whether we need $1 as a flag for $CC) 171238106Sdescache=AS_TR_SH($1) 172238106Sdesdnl cache=`echo $1 | sed 'y%.=/+- %___p__%'` 173238106SdesAC_CACHE_VAL(cv_prog_cc_flag_needed_$cache, 174238106Sdes[ 175238106Sdesecho '$2' > conftest.c 176238106Sdesecho 'void f(){}' >>conftest.c 177238106Sdesif test -z "`$CC $CPPFLAGS $CFLAGS $ERRFLAG -c conftest.c 2>&1`"; then 178238106Sdeseval "cv_prog_cc_flag_needed_$cache=no" 179238106Sdeselse 180238106Sdes[ 181238106Sdesif test -z "`$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`"; then 182238106Sdeseval "cv_prog_cc_flag_needed_$cache=yes" 183238106Sdeselse 184238106Sdeseval "cv_prog_cc_flag_needed_$cache=fail" 185238106Sdes#echo 'Test with flag fails too!' 186238106Sdes#cat conftest.c 187238106Sdes#echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1" 188238106Sdes#echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1` 189238106Sdes#exit 1 190238106Sdesfi 191238106Sdes] 192238106Sdesfi 193238106Sdesrm -f conftest conftest.c conftest.o 194238106Sdes]) 195238106Sdesif eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = yes"; then 196238106SdesAC_MSG_RESULT(yes) 197238106Sdes: 198238106Sdes$3 199238106Sdeselse 200238106Sdesif eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = no"; then 201238106SdesAC_MSG_RESULT(no) 202238106Sdes#echo 'Test with flag is no!' 203238106Sdes#cat conftest.c 204238106Sdes#echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1" 205238106Sdes#echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1` 206238106Sdes#exit 1 207238106Sdes: 208238106Sdes$4 209238106Sdeselse 210238106SdesAC_MSG_RESULT(failed) 211238106Sdes: 212238106Sdes$5 213238106Sdesfi 214238106Sdesfi 215238106Sdes]) 216238106Sdes 217238106Sdesdnl Check for CC dependency flag 218238106Sdesdnl DEPFLAG: set to flag that generates dependencies. 219238106SdesAC_DEFUN([ACX_DEPFLAG], 220238106Sdes[ 221238106SdesAC_MSG_CHECKING([$CC dependency flag]) 222238106Sdesecho 'void f(){}' >conftest.c 223238106Sdesif test "`$CC -MM conftest.c 2>&1`" = "conftest.o: conftest.c"; then 224238106Sdes DEPFLAG="-MM" 225238106Sdeselse 226238106Sdes if test "`$CC -xM1 conftest.c 2>&1`" = "conftest.o: conftest.c"; then 227238106Sdes DEPFLAG="-xM1" 228238106Sdes else 229238106Sdes DEPFLAG="-MM" # dunno do something 230238106Sdes fi 231238106Sdesfi 232238106SdesAC_MSG_RESULT($DEPFLAG) 233238106Sdesrm -f conftest.c 234238106SdesAC_SUBST(DEPFLAG) 235238106Sdes]) 236238106Sdes 237238106Sdesdnl Determine flags that gives POSIX and BSD functionality. 238238106Sdesdnl CFLAGS is modified for the result. 239238106SdesAC_DEFUN([ACX_DETERMINE_EXT_FLAGS_UNBOUND], 240238106Sdes[ 241238106SdesACX_CHECK_COMPILER_FLAG(std=c99, [C99FLAG="-std=c99"]) 242238106SdesACX_CHECK_COMPILER_FLAG(xc99, [C99FLAG="-xc99"]) 243238106Sdes 244238106SdesAC_CHECK_HEADERS([getopt.h time.h],,, [AC_INCLUDES_DEFAULT]) 245238106Sdes 246296415SdesACX_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, 247238106Sdes[ 248238106Sdes#include "confdefs.h" 249238106Sdes#include <stdlib.h> 250238106Sdes#include <ctype.h> 251238106Sdes#include <sys/time.h> 252238106Sdes#ifdef HAVE_TIME_H 253238106Sdes#include <time.h> 254238106Sdes#endif 255238106Sdes#include <unistd.h> 256238106Sdes#include <netdb.h> 257238106Sdes#ifdef HAVE_GETOPT_H 258238106Sdes#include <getopt.h> 259238106Sdes#endif 260238106Sdes 261238106Sdesint test() { 262238106Sdes int a; 263238106Sdes char **opts = NULL; 264238106Sdes struct timeval tv; 265238106Sdes char *t; 266238106Sdes time_t time = 0; 267238106Sdes char *buf = NULL; 268238106Sdes const char* str = NULL; 269238106Sdes struct msghdr msg; 270238106Sdes msg.msg_control = 0; 271238106Sdes t = ctime_r(&time, buf); 272238106Sdes tv.tv_usec = 10; 273238106Sdes srandom(32); 274238106Sdes a = getopt(2, opts, "a"); 275238106Sdes a = isascii(32); 276238106Sdes str = gai_strerror(0); 277238106Sdes if(str && t && tv.tv_usec && msg.msg_control) 278238106Sdes a = 0; 279238106Sdes return a; 280238106Sdes} 281296415Sdes], [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"]) 282238106Sdes 283296415SdesACX_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, 284238106Sdes[ 285238106Sdes#include "confdefs.h" 286238106Sdes#include <stdlib.h> 287238106Sdes#include <ctype.h> 288238106Sdes#include <sys/time.h> 289238106Sdes#ifdef HAVE_TIME_H 290238106Sdes#include <time.h> 291238106Sdes#endif 292238106Sdes#include <unistd.h> 293238106Sdes#include <netdb.h> 294238106Sdes#ifdef HAVE_GETOPT_H 295238106Sdes#include <getopt.h> 296238106Sdes#endif 297238106Sdes 298238106Sdesint test() { 299238106Sdes int a; 300238106Sdes char **opts = NULL; 301238106Sdes struct timeval tv; 302238106Sdes char *t; 303238106Sdes time_t time = 0; 304238106Sdes char *buf = NULL; 305238106Sdes const char* str = NULL; 306238106Sdes struct msghdr msg; 307238106Sdes msg.msg_control = 0; 308238106Sdes t = ctime_r(&time, buf); 309238106Sdes tv.tv_usec = 10; 310238106Sdes srandom(32); 311238106Sdes a = getopt(2, opts, "a"); 312238106Sdes a = isascii(32); 313238106Sdes str = gai_strerror(0); 314238106Sdes if(str && t && tv.tv_usec && msg.msg_control) 315238106Sdes a = 0; 316238106Sdes return a; 317238106Sdes} 318296415Sdes], [CFLAGS="$CFLAGS $C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE"]) 319238106Sdes 320238106SdesACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG, 321238106Sdes[ 322238106Sdes#include <stdbool.h> 323238106Sdes#include <ctype.h> 324238106Sdesint test() { 325238106Sdes int a = 0; 326238106Sdes return a; 327238106Sdes} 328238106Sdes], [CFLAGS="$CFLAGS $C99FLAG"]) 329238106Sdes 330296415SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_BSD_SOURCE -D_DEFAULT_SOURCE, 331238106Sdes[ 332238106Sdes#include <ctype.h> 333238106Sdes 334238106Sdesint test() { 335238106Sdes int a; 336238106Sdes a = isascii(32); 337238106Sdes return a; 338238106Sdes} 339296415Sdes], [CFLAGS="$CFLAGS -D_BSD_SOURCE -D_DEFAULT_SOURCE"]) 340238106Sdes 341238106SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE, 342238106Sdes[ 343238106Sdes#include <netinet/in.h> 344238106Sdes 345238106Sdesint test() { 346238106Sdes struct in6_pktinfo inf; 347238106Sdes int a = (int)sizeof(inf); 348238106Sdes return a; 349238106Sdes} 350238106Sdes], [CFLAGS="$CFLAGS -D_GNU_SOURCE"]) 351238106Sdes 352238106Sdes# check again for GNU_SOURCE for setresgid. May fail if setresgid 353238106Sdes# is not available at all. -D_FRSRESGID is to make this check unique. 354238106Sdes# otherwise we would get the previous cached result. 355238106SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE -D_FRSRESGID, 356238106Sdes[ 357238106Sdes#include <unistd.h> 358238106Sdes 359238106Sdesint test() { 360238106Sdes int a = setresgid(0,0,0); 361238106Sdes a = setresuid(0,0,0); 362238106Sdes return a; 363238106Sdes} 364238106Sdes], [CFLAGS="$CFLAGS -D_GNU_SOURCE"]) 365238106Sdes 366238106SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_POSIX_C_SOURCE=200112, 367238106Sdes[ 368238106Sdes#include "confdefs.h" 369238106Sdes#ifdef HAVE_TIME_H 370238106Sdes#include <time.h> 371238106Sdes#endif 372238106Sdes#include <netdb.h> 373238106Sdes 374238106Sdesint test() { 375238106Sdes int a = 0; 376238106Sdes char *t; 377238106Sdes time_t time = 0; 378238106Sdes char *buf = NULL; 379238106Sdes const char* str = NULL; 380238106Sdes t = ctime_r(&time, buf); 381238106Sdes str = gai_strerror(0); 382238106Sdes if(t && str) 383238106Sdes a = 0; 384238106Sdes return a; 385238106Sdes} 386238106Sdes], [CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112"]) 387238106Sdes 388238106SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D__EXTENSIONS__, 389238106Sdes[ 390238106Sdes#include "confdefs.h" 391238106Sdes#include <stdlib.h> 392238106Sdes#include <ctype.h> 393238106Sdes#include <sys/time.h> 394238106Sdes#ifdef HAVE_TIME_H 395238106Sdes#include <time.h> 396238106Sdes#endif 397238106Sdes#include <unistd.h> 398238106Sdes#ifdef HAVE_GETOPT_H 399238106Sdes#include <getopt.h> 400238106Sdes#endif 401238106Sdes 402238106Sdesint test() { 403238106Sdes int a; 404238106Sdes char **opts = NULL; 405238106Sdes struct timeval tv; 406238106Sdes tv.tv_usec = 10; 407238106Sdes srandom(32); 408238106Sdes a = getopt(2, opts, "a"); 409238106Sdes a = isascii(32); 410238106Sdes if(tv.tv_usec) 411238106Sdes a = 0; 412238106Sdes return a; 413238106Sdes} 414238106Sdes], [CFLAGS="$CFLAGS -D__EXTENSIONS__"]) 415238106Sdes 416238106Sdes])dnl End of ACX_DETERMINE_EXT_FLAGS_UNBOUND 417238106Sdes 418238106Sdesdnl Check if CC supports -flto. 419238106Sdesdnl in a way that supports clang and suncc (that flag does something else, 420238106Sdesdnl but fails to link). It sets it in CFLAGS if it works. 421266114SdesAC_DEFUN([ACX_CHECK_FLTO], [ 422266114Sdes AC_ARG_ENABLE([flto], AS_HELP_STRING([--disable-flto], [Disable link-time optimization (gcc specific option)])) 423266114Sdes AS_IF([test "x$enable_flto" != "xno"], [ 424266114Sdes AC_MSG_CHECKING([if $CC supports -flto]) 425266114Sdes BAKCFLAGS="$CFLAGS" 426266114Sdes CFLAGS="$CFLAGS -flto" 427266114Sdes AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [ 428296415Sdes if $CC $CFLAGS -o conftest conftest.c 2>&1 | $GREP -e "warning: no debug symbols in executable" -e "warning: object" >/dev/null; then 429266114Sdes CFLAGS="$BAKCFLAGS" 430266114Sdes AC_MSG_RESULT(no) 431266114Sdes else 432266114Sdes AC_MSG_RESULT(yes) 433266114Sdes fi 434266114Sdes rm -f conftest conftest.c conftest.o 435266114Sdes ], [CFLAGS="$BAKCFLAGS" ; AC_MSG_RESULT(no)]) 436266114Sdes ]) 437238106Sdes]) 438238106Sdes 439238106Sdesdnl Check the printf-format attribute (if any) 440238106Sdesdnl result in HAVE_ATTR_FORMAT. 441238106Sdesdnl Make sure you also include the AHX_CONFIG_FORMAT_ATTRIBUTE. 442238106SdesAC_DEFUN([ACX_CHECK_FORMAT_ATTRIBUTE], 443238106Sdes[AC_REQUIRE([AC_PROG_CC]) 444238106SdesAC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute) 445238106SdesAC_CACHE_VAL(ac_cv_c_format_attribute, 446238106Sdes[ac_cv_c_format_attribute=no 447238106SdesAC_TRY_COMPILE( 448238106Sdes[#include <stdio.h> 449238106Sdesvoid f (char *format, ...) __attribute__ ((format (printf, 1, 2))); 450238106Sdesvoid (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2))); 451238106Sdes], [ 452238106Sdes f ("%s", "str"); 453238106Sdes], 454238106Sdes[ac_cv_c_format_attribute="yes"], 455238106Sdes[ac_cv_c_format_attribute="no"]) 456238106Sdes]) 457238106Sdes 458238106SdesAC_MSG_RESULT($ac_cv_c_format_attribute) 459238106Sdesif test $ac_cv_c_format_attribute = yes; then 460238106Sdes AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute]) 461238106Sdesfi 462238106Sdes])dnl End of ACX_CHECK_FORMAT_ATTRIBUTE 463238106Sdes 464238106Sdesdnl Setup ATTR_FORMAT config.h parts. 465238106Sdesdnl make sure you call ACX_CHECK_FORMAT_ATTRIBUTE also. 466238106SdesAC_DEFUN([AHX_CONFIG_FORMAT_ATTRIBUTE], 467238106Sdes[ 468238106Sdes#ifdef HAVE_ATTR_FORMAT 469238106Sdes# define ATTR_FORMAT(archetype, string_index, first_to_check) \ 470238106Sdes __attribute__ ((format (archetype, string_index, first_to_check))) 471238106Sdes#else /* !HAVE_ATTR_FORMAT */ 472238106Sdes# define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */ 473238106Sdes#endif /* !HAVE_ATTR_FORMAT */ 474238106Sdes]) 475238106Sdes 476238106Sdesdnl Check how to mark function arguments as unused. 477238106Sdesdnl result in HAVE_ATTR_UNUSED. 478238106Sdesdnl Make sure you include AHX_CONFIG_UNUSED_ATTRIBUTE also. 479238106SdesAC_DEFUN([ACX_CHECK_UNUSED_ATTRIBUTE], 480238106Sdes[AC_REQUIRE([AC_PROG_CC]) 481238106SdesAC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute) 482238106SdesAC_CACHE_VAL(ac_cv_c_unused_attribute, 483238106Sdes[ac_cv_c_unused_attribute=no 484238106SdesAC_TRY_COMPILE( 485238106Sdes[#include <stdio.h> 486238106Sdesvoid f (char *u __attribute__((unused))); 487238106Sdes], [ 488238106Sdes f ("x"); 489238106Sdes], 490238106Sdes[ac_cv_c_unused_attribute="yes"], 491238106Sdes[ac_cv_c_unused_attribute="no"]) 492238106Sdes]) 493238106Sdes 494238106Sdesdnl Setup ATTR_UNUSED config.h parts. 495238106Sdesdnl make sure you call ACX_CHECK_UNUSED_ATTRIBUTE also. 496238106SdesAC_DEFUN([AHX_CONFIG_UNUSED_ATTRIBUTE], 497238106Sdes[ 498238106Sdes#if defined(DOXYGEN) 499238106Sdes# define ATTR_UNUSED(x) x 500238106Sdes#elif defined(__cplusplus) 501238106Sdes# define ATTR_UNUSED(x) 502238106Sdes#elif defined(HAVE_ATTR_UNUSED) 503238106Sdes# define ATTR_UNUSED(x) x __attribute__((unused)) 504238106Sdes#else /* !HAVE_ATTR_UNUSED */ 505238106Sdes# define ATTR_UNUSED(x) x 506238106Sdes#endif /* !HAVE_ATTR_UNUSED */ 507238106Sdes]) 508238106Sdes 509238106SdesAC_MSG_RESULT($ac_cv_c_unused_attribute) 510238106Sdesif test $ac_cv_c_unused_attribute = yes; then 511238106Sdes AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute]) 512238106Sdesfi 513238106Sdes])dnl 514238106Sdes 515238106Sdesdnl Pre-fun for ACX_LIBTOOL_C_ONLY 516238106SdesAC_DEFUN([ACX_LIBTOOL_C_PRE], [ 517238106Sdes# skip these tests, we do not need them. 518238106SdesAC_DEFUN([AC_PROG_F77], [:]) 519238106SdesAC_DEFUN([AC_PROG_FC], [:]) 520238106SdesAC_DEFUN([AC_PROG_CXX], [:]) 521238106SdesAC_DEFUN([AC_PROG_CXXCPP], [:]) 522238106SdesAC_DEFUN([AC_PROG_OBJC], [:]) 523238106SdesAC_DEFUN([AC_PROG_OBJCCPP], [:]) 524238106SdesAC_DEFUN([AC_LIBTOOL_CXX], [:]) 525238106SdesAC_DEFUN([AC_LIBTOOL_F77], [:]) 526238106Sdes# always use ./libtool unless override from commandline (libtool=mylibtool) 527238106Sdesif test -z "$libtool"; then 528238106Sdes libtool="./libtool" 529238106Sdesfi 530238106SdesAC_SUBST(libtool) 531238106Sdes# avoid libtool max commandline length test on systems that fork slowly. 532238106SdesAC_CANONICAL_HOST 533238106Sdesif echo "$host_os" | grep "sunos4" >/dev/null; then 534238106Sdes lt_cv_sys_max_cmd_len=32750; 535238106Sdesfi 536238106SdesAC_PATH_TOOL(AR, ar, [false]) 537238106Sdesif test $AR = false; then 538238106Sdes AC_MSG_ERROR([Cannot find 'ar', please extend PATH to include it]) 539238106Sdesfi 540238106Sdes]) 541238106Sdes 542238106Sdesdnl Perform libtool check, portably, only for C 543238106SdesAC_DEFUN([ACX_LIBTOOL_C_ONLY], [ 544238106Sdesdnl as a requirement so that is gets called before LIBTOOL 545238106Sdesdnl because libtools 'AC_REQUIRE' names are right after this one, before 546238106Sdesdnl this function contents. 547238106SdesAC_REQUIRE([ACX_LIBTOOL_C_PRE]) 548238106SdesAC_PROG_LIBTOOL 549238106Sdes]) 550238106Sdes 551238106Sdesdnl Detect if u_char type is defined, otherwise define it. 552238106SdesAC_DEFUN([ACX_TYPE_U_CHAR], 553238106Sdes[AC_CHECK_TYPE([u_char], , 554238106Sdes [AC_DEFINE([u_char], [unsigned char], [Define to 'unsigned char if not defined])], [ 555238106SdesAC_INCLUDES_DEFAULT 556238106Sdes#ifdef HAVE_WINSOCK2_H 557238106Sdes# include <winsock2.h> 558238106Sdes#endif 559238106Sdes]) ]) 560238106Sdes 561238106Sdesdnl Detect if rlim_t type is defined, otherwise define it. 562238106SdesAC_DEFUN([ACX_TYPE_RLIM_T], 563238106Sdes[AC_CHECK_TYPE(rlim_t, , 564238106Sdes [AC_DEFINE([rlim_t], [unsigned long], [Define to 'int' if not defined])], [ 565238106SdesAC_INCLUDES_DEFAULT 566238106Sdes#ifdef HAVE_SYS_RESOURCE_H 567238106Sdes# include <sys/resource.h> 568238106Sdes#endif 569238106Sdes]) ]) 570238106Sdes 571238106Sdesdnl Detect if socklen_t type is defined, otherwise define it. 572238106SdesAC_DEFUN([ACX_TYPE_SOCKLEN_T], 573238106Sdes[ 574238106SdesAC_CHECK_TYPE(socklen_t, , 575238106Sdes [AC_DEFINE([socklen_t], [int], [Define to 'int' if not defined])], [ 576238106SdesAC_INCLUDES_DEFAULT 577238106Sdes#ifdef HAVE_SYS_SOCKET_H 578238106Sdes# include <sys/socket.h> 579238106Sdes#endif 580238106Sdes#ifdef HAVE_WS2TCPIP_H 581238106Sdes# include <ws2tcpip.h> 582238106Sdes#endif 583238106Sdes]) ]) 584238106Sdes 585238106Sdesdnl Detect if in_addr_t type is defined, otherwise define it. 586238106SdesAC_DEFUN([ACX_TYPE_IN_ADDR_T], 587238106Sdes[ AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [ 588238106SdesAC_INCLUDES_DEFAULT 589238106Sdes#ifdef HAVE_SYS_TYPES_H 590238106Sdes# include <sys/types.h> 591238106Sdes#endif 592238106Sdes#ifdef HAVE_NETINET_IN_H 593238106Sdes# include <netinet/in.h> 594238106Sdes#endif 595238106Sdes]) ]) 596238106Sdes 597238106Sdesdnl Detect if in_port_t type is defined, otherwise define it. 598238106SdesAC_DEFUN([ACX_TYPE_IN_PORT_T], 599238106Sdes[ AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])], [ 600238106SdesAC_INCLUDES_DEFAULT 601238106Sdes#ifdef HAVE_SYS_TYPES_H 602238106Sdes# include <sys/types.h> 603238106Sdes#endif 604238106Sdes#ifdef HAVE_NETINET_IN_H 605238106Sdes# include <netinet/in.h> 606238106Sdes#endif 607238106Sdes]) ]) 608238106Sdes 609238106Sdesdnl Add option to disable the evil rpath. Check whether to use rpath or not. 610238106Sdesdnl Adds the --disable-rpath option. Uses trick to edit the ./libtool. 611238106SdesAC_DEFUN([ACX_ARG_RPATH], 612238106Sdes[ 613238106SdesAC_ARG_ENABLE(rpath, 614238106Sdes [ --disable-rpath disable hardcoded rpath (default=enabled)], 615238106Sdes enable_rpath=$enableval, enable_rpath=yes) 616238106Sdesif test "x$enable_rpath" = xno; then 617238106Sdes dnl AC_MSG_RESULT([Fixing libtool for -rpath problems.]) 618238106Sdes AC_CONFIG_COMMANDS([disable-rpath], [ 619238106Sdes sed < libtool > libtool-2 \ 620238106Sdes 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_RPATH_SED__ "/' 621238106Sdes mv libtool-2 libtool 622238106Sdes chmod 755 libtool 623238106Sdes libtool="./libtool" 624238106Sdes ]) 625238106Sdesfi 626238106Sdes]) 627238106Sdes 628238106Sdesdnl Add a -R to the RUNTIME_PATH. Only if rpath is enabled and it is 629238106Sdesdnl an absolute path. 630238106Sdesdnl $1: the pathname to add. 631238106SdesAC_DEFUN([ACX_RUNTIME_PATH_ADD], [ 632238106Sdes if test "x$enable_rpath" = xyes; then 633238106Sdes if echo "$1" | grep "^/" >/dev/null; then 634238106Sdes RUNTIME_PATH="$RUNTIME_PATH -R$1" 635238106Sdes fi 636238106Sdes fi 637238106Sdes]) 638238106Sdes 639238106Sdesdnl Common code for both ACX_WITH_SSL and ACX_WITH_SSL_OPTIONAL 640238106Sdesdnl Takes one argument; the withval checked in those 2 functions 641238106Sdesdnl sets up the environment for the given openssl path 642238106SdesAC_DEFUN([ACX_SSL_CHECKS], [ 643238106Sdes withval=$1 644238106Sdes if test x_$withval != x_no; then 645238106Sdes AC_MSG_CHECKING(for SSL) 646238106Sdes if test x_$withval = x_ -o x_$withval = x_yes; then 647238106Sdes withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr" 648238106Sdes fi 649238106Sdes for dir in $withval; do 650238106Sdes ssldir="$dir" 651238106Sdes if test -f "$dir/include/openssl/ssl.h"; then 652238106Sdes found_ssl="yes" 653238106Sdes AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.]) 654238106Sdes dnl assume /usr/include is already in the include-path. 655238106Sdes if test "$ssldir" != "/usr"; then 656238106Sdes CPPFLAGS="$CPPFLAGS -I$ssldir/include" 657238106Sdes LIBSSL_CPPFLAGS="$LIBSSL_CPPFLAGS -I$ssldir/include" 658238106Sdes fi 659238106Sdes break; 660238106Sdes fi 661238106Sdes done 662238106Sdes if test x_$found_ssl != x_yes; then 663238106Sdes AC_MSG_ERROR(Cannot find the SSL libraries in $withval) 664238106Sdes else 665238106Sdes AC_MSG_RESULT(found in $ssldir) 666238106Sdes HAVE_SSL=yes 667238106Sdes dnl assume /usr is already in the lib and dynlib paths. 668238106Sdes if test "$ssldir" != "/usr" -a "$ssldir" != ""; then 669238106Sdes LDFLAGS="$LDFLAGS -L$ssldir/lib" 670238106Sdes LIBSSL_LDFLAGS="$LIBSSL_LDFLAGS -L$ssldir/lib" 671238106Sdes ACX_RUNTIME_PATH_ADD([$ssldir/lib]) 672238106Sdes fi 673238106Sdes 674238106Sdes AC_MSG_CHECKING([for HMAC_CTX_init in -lcrypto]) 675238106Sdes LIBS="$LIBS -lcrypto" 676238106Sdes LIBSSL_LIBS="$LIBSSL_LIBS -lcrypto" 677238106Sdes AC_TRY_LINK(, [ 678238106Sdes int HMAC_CTX_init(void); 679238106Sdes (void)HMAC_CTX_init(); 680238106Sdes ], [ 681238106Sdes AC_MSG_RESULT(yes) 682238106Sdes AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 683238106Sdes [If you have HMAC_CTX_init]) 684238106Sdes ], [ 685238106Sdes AC_MSG_RESULT(no) 686238106Sdes # check if -lwsock32 or -lgdi32 are needed. 687238106Sdes BAKLIBS="$LIBS" 688238106Sdes BAKSSLLIBS="$LIBSSL_LIBS" 689238106Sdes LIBS="$LIBS -lgdi32" 690238106Sdes LIBSSL_LIBS="$LIBSSL_LIBS -lgdi32" 691238106Sdes AC_MSG_CHECKING([if -lcrypto needs -lgdi32]) 692238106Sdes AC_TRY_LINK([], [ 693238106Sdes int HMAC_CTX_init(void); 694238106Sdes (void)HMAC_CTX_init(); 695238106Sdes ],[ 696238106Sdes AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 697238106Sdes [If you have HMAC_CTX_init]) 698238106Sdes AC_MSG_RESULT(yes) 699238106Sdes ],[ 700238106Sdes AC_MSG_RESULT(no) 701238106Sdes LIBS="$BAKLIBS" 702238106Sdes LIBSSL_LIBS="$BAKSSLLIBS" 703238106Sdes LIBS="$LIBS -ldl" 704238106Sdes LIBSSL_LIBS="$LIBSSL_LIBS -ldl" 705238106Sdes AC_MSG_CHECKING([if -lcrypto needs -ldl]) 706238106Sdes AC_TRY_LINK([], [ 707238106Sdes int HMAC_CTX_init(void); 708238106Sdes (void)HMAC_CTX_init(); 709238106Sdes ],[ 710238106Sdes AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 711238106Sdes [If you have HMAC_CTX_init]) 712238106Sdes AC_MSG_RESULT(yes) 713238106Sdes ],[ 714238106Sdes AC_MSG_RESULT(no) 715238106Sdes AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required]) 716238106Sdes ]) 717238106Sdes ]) 718238106Sdes ]) 719238106Sdes fi 720238106Sdes AC_SUBST(HAVE_SSL) 721238106Sdes AC_SUBST(RUNTIME_PATH) 722238106Sdes fi 723238106SdesAC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT]) 724238106SdesAC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT]) 725238106SdesAC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT]) 726238106Sdes])dnl End of ACX_SSL_CHECKS 727238106Sdes 728238106Sdesdnl Check for SSL, where SSL is mandatory 729238106Sdesdnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found 730238106Sdesdnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS. 731238106Sdesdnl Checks main header files of SSL. 732238106Sdesdnl 733238106SdesAC_DEFUN([ACX_WITH_SSL], 734238106Sdes[ 735238106SdesAC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname], 736238106Sdes [enable SSL (will check /usr/local/ssl 737238106Sdes /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr)]),[ 738238106Sdes ],[ 739238106Sdes withval="yes" 740238106Sdes ]) 741238106Sdes if test x_$withval = x_no; then 742238106Sdes AC_MSG_ERROR([Need SSL library to do digital signature cryptography]) 743238106Sdes fi 744238106Sdes ACX_SSL_CHECKS($withval) 745238106Sdes])dnl End of ACX_WITH_SSL 746238106Sdes 747238106Sdesdnl Check for SSL, where ssl is optional (--without-ssl is allowed) 748238106Sdesdnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found 749238106Sdesdnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS. 750238106Sdesdnl Checks main header files of SSL. 751238106Sdesdnl 752238106SdesAC_DEFUN([ACX_WITH_SSL_OPTIONAL], 753238106Sdes[ 754238106SdesAC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname], 755238106Sdes [enable SSL (will check /usr/local/ssl 756238106Sdes /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr)]),[ 757238106Sdes ],[ 758238106Sdes withval="yes" 759238106Sdes ]) 760238106Sdes ACX_SSL_CHECKS($withval) 761238106Sdes])dnl End of ACX_WITH_SSL_OPTIONAL 762238106Sdes 763238106Sdesdnl Setup to use -lssl 764238106Sdesdnl To use -lcrypto, use the ACX_WITH_SSL setup (before this one). 765238106SdesAC_DEFUN([ACX_LIB_SSL], 766238106Sdes[ 767238106Sdes# check if libssl needs libdl 768238106SdesBAKLIBS="$LIBS" 769238106SdesLIBS="-lssl $LIBS" 770238106SdesAC_MSG_CHECKING([if libssl needs libdl]) 771238106SdesAC_TRY_LINK_FUNC([SSL_CTX_new], [ 772238106Sdes AC_MSG_RESULT([no]) 773238106Sdes LIBS="$BAKLIBS" 774238106Sdes] , [ 775238106Sdes AC_MSG_RESULT([yes]) 776238106Sdes LIBS="$BAKLIBS" 777238106Sdes AC_SEARCH_LIBS([dlopen], [dl]) 778238106Sdes]) ])dnl End of ACX_LIB_SSL 779238106Sdes 780238106Sdesdnl Setup to use very large files (>2Gb). 781238106Sdesdnl setups fseeko and its own 782238106SdesAC_DEFUN([ACX_SYS_LARGEFILE], 783238106Sdes[ 784238106SdesAC_SYS_LARGEFILE 785238106Sdesdnl try to see if an additional _LARGEFILE_SOURCE 1 is needed to get fseeko 786238106SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_LARGEFILE_SOURCE=1, 787238106Sdes[ 788238106Sdes#include <stdio.h> 789238106Sdesint test() { 790238106Sdes int a = fseeko(stdin, 0, 0); 791238106Sdes return a; 792238106Sdes} 793238106Sdes], [CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE=1"]) 794238106Sdes]) 795238106Sdes 796238106Sdesdnl Check getaddrinfo. 797238106Sdesdnl Works on linux, solaris, bsd and windows(links winsock). 798238106Sdesdnl defines HAVE_GETADDRINFO, USE_WINSOCK. 799238106SdesAC_DEFUN([ACX_CHECK_GETADDRINFO_WITH_INCLUDES], 800238106Sdes[AC_REQUIRE([AC_PROG_CC]) 801238106SdesAC_MSG_CHECKING(for getaddrinfo) 802238106Sdesac_cv_func_getaddrinfo=no 803238106SdesAC_LINK_IFELSE( 804238106Sdes[AC_LANG_SOURCE([[ 805238106Sdes#ifdef __cplusplus 806238106Sdesextern "C" 807238106Sdes{ 808238106Sdes#endif 809238106Sdeschar* getaddrinfo(); 810238106Sdeschar* (*f) () = getaddrinfo; 811238106Sdes#ifdef __cplusplus 812238106Sdes} 813238106Sdes#endif 814238106Sdesint main() { 815238106Sdes ; 816238106Sdes return 0; 817238106Sdes} 818238106Sdes]])], 819238106Sdesdnl this case on linux, solaris, bsd 820238106Sdes[ac_cv_func_getaddrinfo="yes" 821238106Sdesdnl see if on windows 822238106Sdesif test "$ac_cv_header_windows_h" = "yes"; then 823238106Sdes AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used]) 824238106Sdes USE_WINSOCK="1" 825238106Sdes LIBS="$LIBS -lws2_32" 826238106Sdesfi 827238106Sdes], 828238106Sdesdnl no quick getaddrinfo, try mingw32 and winsock2 library. 829238106SdesORIGLIBS="$LIBS" 830238106SdesLIBS="$LIBS -lws2_32" 831238106SdesAC_LINK_IFELSE( 832238106Sdes[AC_LANG_PROGRAM( 833238106Sdes[ 834238106Sdes#ifdef HAVE_WS2TCPIP_H 835238106Sdes#include <ws2tcpip.h> 836238106Sdes#endif 837238106Sdes], 838238106Sdes[ 839238106Sdes (void)getaddrinfo(NULL, NULL, NULL, NULL); 840238106Sdes] 841238106Sdes)], 842238106Sdes[ 843238106Sdesac_cv_func_getaddrinfo="yes" 844238106Sdesdnl already: LIBS="$LIBS -lws2_32" 845238106SdesAC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used]) 846238106SdesUSE_WINSOCK="1" 847238106Sdes], 848238106Sdes[ 849238106Sdesac_cv_func_getaddrinfo="no" 850238106SdesLIBS="$ORIGLIBS" 851238106Sdes]) 852238106Sdes) 853238106Sdes 854238106SdesAC_MSG_RESULT($ac_cv_func_getaddrinfo) 855238106Sdesif test $ac_cv_func_getaddrinfo = yes; then 856238106Sdes AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether getaddrinfo is available]) 857238106Sdesfi 858238106Sdes])dnl Endof AC_CHECK_GETADDRINFO_WITH_INCLUDES 859238106Sdes 860238106Sdesdnl check if a function is deprecated. defines DEPRECATED_func in config.h. 861238106Sdesdnl $1: function name 862238106Sdesdnl $2: C-statement that calls the function. 863238106Sdesdnl $3: includes for the program. 864238106Sdesdnl $4: executes if yes 865238106Sdesdnl $5: executes if no 866238106SdesAC_DEFUN([ACX_FUNC_DEPRECATED], 867238106Sdes[ 868238106SdesAC_REQUIRE([AC_PROG_CC]) 869238106SdesAC_MSG_CHECKING(if $1 is deprecated) 870238106Sdescache=`echo $1 | sed 'y%.=/+-%___p_%'` 871238106SdesAC_CACHE_VAL(cv_cc_deprecated_$cache, 872238106Sdes[ 873238106Sdesecho '$3' >conftest.c 874238106Sdesecho 'void f(){ $2 }' >>conftest.c 875238106Sdesif test -z "`$CC -c conftest.c 2>&1 | grep deprecated`"; then 876238106Sdeseval "cv_cc_deprecated_$cache=no" 877238106Sdeselse 878238106Sdeseval "cv_cc_deprecated_$cache=yes" 879238106Sdesfi 880238106Sdesrm -f conftest conftest.o conftest.c 881238106Sdes]) 882238106Sdesif eval "test \"`echo '$cv_cc_deprecated_'$cache`\" = yes"; then 883238106SdesAC_MSG_RESULT(yes) 884238106SdesAC_DEFINE_UNQUOTED(AS_TR_CPP([DEPRECATED_$1]), 1, [Whether $1 is deprecated]) 885238106Sdes: 886238106Sdes$4 887238106Sdeselse 888238106SdesAC_MSG_RESULT(no) 889238106Sdes: 890238106Sdes$5 891238106Sdesfi 892238106Sdes])dnl end of ACX_FUNC_DEPRECATED 893238106Sdes 894238106Sdesdnl check if select and nonblocking sockets actually work. 895238106Sdesdnl Needs fork(2) and select(2). 896238106Sdesdnl defines NONBLOCKING_IS_BROKEN, and if that is true multiple reads from 897238106Sdesdnl a nonblocking socket do not work, a new call to select is necessary. 898238106SdesAC_DEFUN([ACX_CHECK_NONBLOCKING_BROKEN], 899238106Sdes[ 900238106SdesAC_MSG_CHECKING([if nonblocking sockets work]) 901238106Sdesif echo $target | grep mingw32 >/dev/null; then 902238106Sdes AC_MSG_RESULT([no (windows)]) 903238106Sdes AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).]) 904238106Sdeselse 905238106SdesAC_RUN_IFELSE([ 906238106SdesAC_LANG_SOURCE([[ 907238106Sdes#include <stdio.h> 908238106Sdes#include <string.h> 909238106Sdes#include <stdlib.h> 910238106Sdes#include <fcntl.h> 911238106Sdes#include <errno.h> 912238106Sdes#ifdef HAVE_SYS_TYPES_H 913238106Sdes#include <sys/types.h> 914238106Sdes#endif 915238106Sdes#ifdef HAVE_SYS_SOCKET_H 916238106Sdes#include <sys/socket.h> 917238106Sdes#endif 918238106Sdes#ifdef HAVE_NETINET_IN_H 919238106Sdes#include <netinet/in.h> 920238106Sdes#endif 921238106Sdes#ifdef HAVE_ARPA_INET_H 922238106Sdes#include <arpa/inet.h> 923238106Sdes#endif 924238106Sdes#ifdef HAVE_UNISTD_H 925238106Sdes#include <unistd.h> 926238106Sdes#endif 927238106Sdes#ifdef HAVE_TIME_H 928238106Sdes#include <time.h> 929238106Sdes#endif 930238106Sdes 931238106Sdesint main(void) 932238106Sdes{ 933238106Sdes int port; 934238106Sdes int sfd, cfd; 935238106Sdes int num = 10; 936238106Sdes int i, p; 937238106Sdes struct sockaddr_in a; 938238106Sdes /* test if select and nonblocking reads work well together */ 939238106Sdes /* open port. 940238106Sdes fork child to send 10 messages. 941238106Sdes select to read. 942238106Sdes then try to nonblocking read the 10 messages 943238106Sdes then, nonblocking read must give EAGAIN 944238106Sdes */ 945238106Sdes 946238106Sdes port = 12345 + (time(0)%32); 947238106Sdes sfd = socket(PF_INET, SOCK_DGRAM, 0); 948238106Sdes if(sfd == -1) { 949238106Sdes perror("socket"); 950238106Sdes return 1; 951238106Sdes } 952238106Sdes memset(&a, 0, sizeof(a)); 953238106Sdes a.sin_family = AF_INET; 954238106Sdes a.sin_port = htons(port); 955238106Sdes a.sin_addr.s_addr = inet_addr("127.0.0.1"); 956238106Sdes if(bind(sfd, (struct sockaddr*)&a, sizeof(a)) < 0) { 957238106Sdes perror("bind"); 958238106Sdes return 1; 959238106Sdes } 960238106Sdes if(fcntl(sfd, F_SETFL, O_NONBLOCK) == -1) { 961238106Sdes perror("fcntl"); 962238106Sdes return 1; 963238106Sdes } 964238106Sdes 965238106Sdes cfd = socket(PF_INET, SOCK_DGRAM, 0); 966238106Sdes if(cfd == -1) { 967238106Sdes perror("client socket"); 968238106Sdes return 1; 969238106Sdes } 970238106Sdes a.sin_port = 0; 971238106Sdes if(bind(cfd, (struct sockaddr*)&a, sizeof(a)) < 0) { 972238106Sdes perror("client bind"); 973238106Sdes return 1; 974238106Sdes } 975238106Sdes a.sin_port = htons(port); 976238106Sdes 977238106Sdes /* no handler, causes exit in 10 seconds */ 978238106Sdes alarm(10); 979238106Sdes 980238106Sdes /* send and receive on the socket */ 981238106Sdes if((p=fork()) == 0) { 982238106Sdes for(i=0; i<num; i++) { 983238106Sdes if(sendto(cfd, &i, sizeof(i), 0, 984238106Sdes (struct sockaddr*)&a, sizeof(a)) < 0) { 985238106Sdes perror("sendto"); 986238106Sdes return 1; 987238106Sdes } 988238106Sdes } 989238106Sdes } else { 990238106Sdes /* parent */ 991238106Sdes fd_set rset; 992238106Sdes int x; 993238106Sdes if(p == -1) { 994238106Sdes perror("fork"); 995238106Sdes return 1; 996238106Sdes } 997238106Sdes FD_ZERO(&rset); 998238106Sdes FD_SET(sfd, &rset); 999238106Sdes if(select(sfd+1, &rset, NULL, NULL, NULL) < 1) { 1000238106Sdes perror("select"); 1001238106Sdes return 1; 1002238106Sdes } 1003238106Sdes i = 0; 1004238106Sdes while(i < num) { 1005238106Sdes if(recv(sfd, &x, sizeof(x), 0) != sizeof(x)) { 1006238106Sdes if(errno == EAGAIN) 1007238106Sdes continue; 1008238106Sdes perror("recv"); 1009238106Sdes return 1; 1010238106Sdes } 1011238106Sdes i++; 1012238106Sdes } 1013238106Sdes /* now we want to get EAGAIN: nonblocking goodness */ 1014238106Sdes errno = 0; 1015238106Sdes recv(sfd, &x, sizeof(x), 0); 1016238106Sdes if(errno != EAGAIN) { 1017238106Sdes perror("trying to recv again"); 1018238106Sdes return 1; 1019238106Sdes } 1020238106Sdes /* EAGAIN encountered */ 1021238106Sdes } 1022238106Sdes 1023238106Sdes close(sfd); 1024238106Sdes close(cfd); 1025238106Sdes return 0; 1026238106Sdes} 1027238106Sdes]])], [ 1028238106Sdes AC_MSG_RESULT([yes]) 1029238106Sdes], [ 1030238106Sdes AC_MSG_RESULT([no]) 1031238106Sdes AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).]) 1032238106Sdes], [ 1033238106Sdes AC_MSG_RESULT([crosscompile(yes)]) 1034238106Sdes]) 1035238106Sdesfi 1036238106Sdes])dnl End of ACX_CHECK_NONBLOCKING_BROKEN 1037238106Sdes 1038238106Sdesdnl Check if mkdir has one or two arguments. 1039238106Sdesdnl defines MKDIR_HAS_ONE_ARG 1040238106SdesAC_DEFUN([ACX_MKDIR_ONE_ARG], 1041238106Sdes[ 1042238106SdesAC_MSG_CHECKING([whether mkdir has one arg]) 1043238106SdesAC_TRY_COMPILE([ 1044238106Sdes#include <stdio.h> 1045238106Sdes#include <unistd.h> 1046238106Sdes#ifdef HAVE_WINSOCK2_H 1047238106Sdes#include <winsock2.h> 1048238106Sdes#endif 1049238106Sdes#ifdef HAVE_SYS_STAT_H 1050238106Sdes#include <sys/stat.h> 1051238106Sdes#endif 1052238106Sdes], [ 1053238106Sdes (void)mkdir("directory"); 1054238106Sdes], 1055238106SdesAC_MSG_RESULT(yes) 1056238106SdesAC_DEFINE(MKDIR_HAS_ONE_ARG, 1, [Define if mkdir has one argument.]) 1057238106Sdes, 1058238106SdesAC_MSG_RESULT(no) 1059238106Sdes) 1060238106Sdes])dnl end of ACX_MKDIR_ONE_ARG 1061238106Sdes 1062238106Sdesdnl Check for ioctlsocket function. works on mingw32 too. 1063238106SdesAC_DEFUN([ACX_FUNC_IOCTLSOCKET], 1064238106Sdes[ 1065238106Sdes# check ioctlsocket 1066238106SdesAC_MSG_CHECKING(for ioctlsocket) 1067238106SdesAC_LINK_IFELSE([AC_LANG_PROGRAM([ 1068238106Sdes#ifdef HAVE_WINSOCK2_H 1069238106Sdes#include <winsock2.h> 1070238106Sdes#endif 1071238106Sdes], [ 1072238106Sdes (void)ioctlsocket(0, 0, NULL); 1073238106Sdes])], [ 1074238106SdesAC_MSG_RESULT(yes) 1075238106SdesAC_DEFINE(HAVE_IOCTLSOCKET, 1, [if the function 'ioctlsocket' is available]) 1076238106Sdes],[AC_MSG_RESULT(no)]) 1077238106Sdes])dnl end of ACX_FUNC_IOCTLSOCKET 1078238106Sdes 1079238106Sdesdnl detect malloc and provide malloc compat prototype. 1080238106Sdesdnl $1: unique name for compat code 1081238106SdesAC_DEFUN([ACX_FUNC_MALLOC], 1082238106Sdes[ 1083238106Sdes AC_MSG_CHECKING([for GNU libc compatible malloc]) 1084238106Sdes AC_RUN_IFELSE([AC_LANG_PROGRAM( 1085238106Sdes[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H 1086238106Sdes#include <stdlib.h> 1087238106Sdes#else 1088238106Sdeschar *malloc (); 1089238106Sdes#endif 1090238106Sdes]], [ if(malloc(0) != 0) return 1;]) 1091238106Sdes], 1092238106Sdes [AC_MSG_RESULT([no]) 1093238106Sdes AC_LIBOBJ(malloc) 1094238106Sdes AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] , 1095238106Sdes [AC_MSG_RESULT([yes]) 1096238106Sdes AC_DEFINE([HAVE_MALLOC], 1, [If have GNU libc compatible malloc])], 1097238106Sdes [AC_MSG_RESULT([no (crosscompile)]) 1098238106Sdes AC_LIBOBJ(malloc) 1099238106Sdes AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] ) 1100238106Sdes]) 1101238106Sdes 1102238106Sdesdnl Define fallback for fseeko and ftello if needed. 1103238106SdesAC_DEFUN([AHX_CONFIG_FSEEKO], 1104238106Sdes[ 1105238106Sdes#ifndef HAVE_FSEEKO 1106238106Sdes#define fseeko fseek 1107238106Sdes#define ftello ftell 1108238106Sdes#endif /* HAVE_FSEEKO */ 1109238106Sdes]) 1110238106Sdes 1111238106Sdesdnl Define RAND_MAX if not defined 1112238106SdesAC_DEFUN([AHX_CONFIG_RAND_MAX], 1113238106Sdes[ 1114238106Sdes#ifndef RAND_MAX 1115238106Sdes#define RAND_MAX 2147483647 1116238106Sdes#endif 1117238106Sdes]) 1118238106Sdes 1119238106Sdesdnl Define MAXHOSTNAMELEN if not defined 1120238106SdesAC_DEFUN([AHX_CONFIG_MAXHOSTNAMELEN], 1121238106Sdes[ 1122238106Sdes#ifndef MAXHOSTNAMELEN 1123238106Sdes#define MAXHOSTNAMELEN 256 1124238106Sdes#endif 1125238106Sdes]) 1126238106Sdes 1127238106Sdesdnl Define IPV6_MIN_MTU if not defined 1128238106SdesAC_DEFUN([AHX_CONFIG_IPV6_MIN_MTU], 1129238106Sdes[ 1130238106Sdes#ifndef IPV6_MIN_MTU 1131238106Sdes#define IPV6_MIN_MTU 1280 1132238106Sdes#endif /* IPV6_MIN_MTU */ 1133238106Sdes]) 1134238106Sdes 1135238106Sdesdnl provide snprintf, vsnprintf compat prototype 1136238106Sdesdnl $1: unique name for compat code 1137238106SdesAC_DEFUN([AHX_CONFIG_SNPRINTF], 1138238106Sdes[ 1139238106Sdes#ifndef HAVE_SNPRINTF 1140238106Sdes#define snprintf snprintf_$1 1141238106Sdes#define vsnprintf vsnprintf_$1 1142238106Sdes#include <stdarg.h> 1143238106Sdesint snprintf (char *str, size_t count, const char *fmt, ...); 1144238106Sdesint vsnprintf (char *str, size_t count, const char *fmt, va_list arg); 1145238106Sdes#endif /* HAVE_SNPRINTF */ 1146238106Sdes]) 1147238106Sdes 1148238106Sdesdnl provide inet_pton compat prototype. 1149238106Sdesdnl $1: unique name for compat code 1150238106SdesAC_DEFUN([AHX_CONFIG_INET_PTON], 1151238106Sdes[ 1152238106Sdes#ifndef HAVE_INET_PTON 1153238106Sdes#define inet_pton inet_pton_$1 1154238106Sdesint inet_pton(int af, const char* src, void* dst); 1155238106Sdes#endif /* HAVE_INET_PTON */ 1156238106Sdes]) 1157238106Sdes 1158238106Sdesdnl provide inet_ntop compat prototype. 1159238106Sdesdnl $1: unique name for compat code 1160238106SdesAC_DEFUN([AHX_CONFIG_INET_NTOP], 1161238106Sdes[ 1162238106Sdes#ifndef HAVE_INET_NTOP 1163238106Sdes#define inet_ntop inet_ntop_$1 1164238106Sdesconst char *inet_ntop(int af, const void *src, char *dst, size_t size); 1165238106Sdes#endif 1166238106Sdes]) 1167238106Sdes 1168238106Sdesdnl provide inet_aton compat prototype. 1169238106Sdesdnl $1: unique name for compat code 1170238106SdesAC_DEFUN([AHX_CONFIG_INET_ATON], 1171238106Sdes[ 1172238106Sdes#ifndef HAVE_INET_ATON 1173238106Sdes#define inet_aton inet_aton_$1 1174238106Sdesint inet_aton(const char *cp, struct in_addr *addr); 1175238106Sdes#endif 1176238106Sdes]) 1177238106Sdes 1178238106Sdesdnl provide memmove compat prototype. 1179238106Sdesdnl $1: unique name for compat code 1180238106SdesAC_DEFUN([AHX_CONFIG_MEMMOVE], 1181238106Sdes[ 1182238106Sdes#ifndef HAVE_MEMMOVE 1183238106Sdes#define memmove memmove_$1 1184238106Sdesvoid *memmove(void *dest, const void *src, size_t n); 1185238106Sdes#endif 1186238106Sdes]) 1187238106Sdes 1188238106Sdesdnl provide strlcat compat prototype. 1189238106Sdesdnl $1: unique name for compat code 1190238106SdesAC_DEFUN([AHX_CONFIG_STRLCAT], 1191238106Sdes[ 1192238106Sdes#ifndef HAVE_STRLCAT 1193238106Sdes#define strlcat strlcat_$1 1194238106Sdessize_t strlcat(char *dst, const char *src, size_t siz); 1195238106Sdes#endif 1196238106Sdes]) 1197238106Sdes 1198238106Sdesdnl provide strlcpy compat prototype. 1199238106Sdesdnl $1: unique name for compat code 1200238106SdesAC_DEFUN([AHX_CONFIG_STRLCPY], 1201238106Sdes[ 1202238106Sdes#ifndef HAVE_STRLCPY 1203238106Sdes#define strlcpy strlcpy_$1 1204238106Sdessize_t strlcpy(char *dst, const char *src, size_t siz); 1205238106Sdes#endif 1206238106Sdes]) 1207238106Sdes 1208238106Sdesdnl provide gmtime_r compat prototype. 1209238106Sdesdnl $1: unique name for compat code 1210238106SdesAC_DEFUN([AHX_CONFIG_GMTIME_R], 1211238106Sdes[ 1212238106Sdes#ifndef HAVE_GMTIME_R 1213238106Sdes#define gmtime_r gmtime_r_$1 1214238106Sdesstruct tm *gmtime_r(const time_t *timep, struct tm *result); 1215238106Sdes#endif 1216238106Sdes]) 1217238106Sdes 1218287917Sdesdnl provide reallocarray compat prototype. 1219287917Sdesdnl $1: unique name for compat code 1220287917SdesAC_DEFUN([AHX_CONFIG_REALLOCARRAY], 1221287917Sdes[ 1222287917Sdes#ifndef HAVE_REALLOCARRAY 1223287917Sdes#define reallocarray reallocarray$1 1224287917Sdesvoid* reallocarray(void *ptr, size_t nmemb, size_t size); 1225287917Sdes#endif 1226287917Sdes]) 1227287917Sdes 1228238106Sdesdnl provide w32 compat definition for sleep 1229238106SdesAC_DEFUN([AHX_CONFIG_W32_SLEEP], 1230238106Sdes[ 1231266114Sdes#if !defined(HAVE_SLEEP) || defined(HAVE_WINDOWS_H) 1232238106Sdes#define sleep(x) Sleep((x)*1000) /* on win32 */ 1233238106Sdes#endif /* HAVE_SLEEP */ 1234238106Sdes]) 1235238106Sdes 1236238106Sdesdnl provide w32 compat definition for usleep 1237238106SdesAC_DEFUN([AHX_CONFIG_W32_USLEEP], 1238238106Sdes[ 1239238106Sdes#ifndef HAVE_USLEEP 1240238106Sdes#define usleep(x) Sleep((x)/1000 + 1) /* on win32 */ 1241238106Sdes#endif /* HAVE_USLEEP */ 1242238106Sdes]) 1243238106Sdes 1244238106Sdesdnl provide w32 compat definition for random 1245238106SdesAC_DEFUN([AHX_CONFIG_W32_RANDOM], 1246238106Sdes[ 1247238106Sdes#ifndef HAVE_RANDOM 1248238106Sdes#define random rand /* on win32, for tests only (bad random) */ 1249238106Sdes#endif /* HAVE_RANDOM */ 1250238106Sdes]) 1251238106Sdes 1252238106Sdesdnl provide w32 compat definition for srandom 1253238106SdesAC_DEFUN([AHX_CONFIG_W32_SRANDOM], 1254238106Sdes[ 1255238106Sdes#ifndef HAVE_SRANDOM 1256238106Sdes#define srandom(x) srand(x) /* on win32, for tests only (bad random) */ 1257238106Sdes#endif /* HAVE_SRANDOM */ 1258238106Sdes]) 1259238106Sdes 1260238106Sdesdnl provide w32 compat definition for FD_SET_T 1261238106SdesAC_DEFUN([AHX_CONFIG_W32_FD_SET_T], 1262238106Sdes[ 1263238106Sdes/* detect if we need to cast to unsigned int for FD_SET to avoid warnings */ 1264238106Sdes#ifdef HAVE_WINSOCK2_H 1265238106Sdes#define FD_SET_T (u_int) 1266238106Sdes#else 1267238106Sdes#define FD_SET_T 1268238106Sdes#endif 1269238106Sdes]) 1270238106Sdes 1271238106Sdesdnl Remove an extension flag from CFLAGS, define replacement to be made. 1272238106Sdesdnl Used by ACX_STRIP_EXT_FLAGS. 1273238106Sdesdnl $1: the name of the flag, for example -D_GNU_SOURCE. 1274238106SdesAC_DEFUN([ACX_CFLAGS_STRIP], 1275238106Sdes[ 1276238106Sdes if echo $CFLAGS | grep " $1" >/dev/null 2>&1; then 1277238106Sdes CFLAGS="`echo $CFLAGS | sed -e 's/ $1//g'`" 1278238106Sdes AC_DEFINE(m4_bpatsubst(OMITTED_$1,[[-=]],_), 1, Put $1 define in config.h) 1279238106Sdes fi 1280238106Sdes]) 1281238106Sdes 1282238106Sdesdnl Remove EXT flags from the CFLAGS and set them to be defined in config.h 1283238106Sdesdnl use with ACX_DETERMINE_EXT_FLAGS. 1284238106SdesAC_DEFUN([ACX_STRIP_EXT_FLAGS], 1285238106Sdes[ 1286238106Sdes AC_MSG_NOTICE([Stripping extension flags...]) 1287238106Sdes ACX_CFLAGS_STRIP(-D_GNU_SOURCE) 1288238106Sdes ACX_CFLAGS_STRIP(-D_BSD_SOURCE) 1289296415Sdes ACX_CFLAGS_STRIP(-D_DEFAULT_SOURCE) 1290238106Sdes ACX_CFLAGS_STRIP(-D__EXTENSIONS__) 1291238106Sdes ACX_CFLAGS_STRIP(-D_POSIX_C_SOURCE=200112) 1292238106Sdes ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE=600) 1293238106Sdes ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE_EXTENDED=1) 1294238106Sdes ACX_CFLAGS_STRIP(-D_ALL_SOURCE) 1295238106Sdes ACX_CFLAGS_STRIP(-D_LARGEFILE_SOURCE=1) 1296238106Sdes]) dnl End of ACX_STRIP_EXT_FLAGS 1297238106Sdes 1298238106Sdesdnl define one omitted flag for config.h 1299238106Sdesdnl $1: flag name. -D_GNU_SOURCE 1300238106Sdesdnl $2: replacement define. _GNU_SOURCE 1301238106Sdesdnl $3: define value, 1 1302238106SdesAC_DEFUN([AHX_CONFIG_FLAG_OMITTED], 1303238106Sdes[#if defined($1) && !defined($2) 1304238106Sdes#define $2 $3 1305238106Sdes[#]endif ]) 1306238106Sdes 1307238106Sdesdnl Wrapper for AHX_CONFIG_FLAG_OMITTED for -D style flags 1308238106Sdesdnl $1: the -DNAME or -DNAME=value string. 1309238106SdesAC_DEFUN([AHX_CONFIG_FLAG_EXT], 1310238106Sdes[AHX_CONFIG_FLAG_OMITTED(m4_bpatsubst(OMITTED_$1,[[-=]],_),m4_bpatsubst(m4_bpatsubst($1,-D,),=.*$,),m4_if(m4_bregexp($1,=),-1,1,m4_bpatsubst($1,^.*=,))) 1311238106Sdes]) 1312238106Sdes 1313238106Sdesdnl config.h part to define omitted cflags, use with ACX_STRIP_EXT_FLAGS. 1314238106SdesAC_DEFUN([AHX_CONFIG_EXT_FLAGS], 1315238106Sdes[AHX_CONFIG_FLAG_EXT(-D_GNU_SOURCE) 1316238106SdesAHX_CONFIG_FLAG_EXT(-D_BSD_SOURCE) 1317296415SdesAHX_CONFIG_FLAG_EXT(-D_DEFAULT_SOURCE) 1318238106SdesAHX_CONFIG_FLAG_EXT(-D__EXTENSIONS__) 1319238106SdesAHX_CONFIG_FLAG_EXT(-D_POSIX_C_SOURCE=200112) 1320238106SdesAHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE=600) 1321238106SdesAHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE_EXTENDED=1) 1322238106SdesAHX_CONFIG_FLAG_EXT(-D_ALL_SOURCE) 1323238106SdesAHX_CONFIG_FLAG_EXT(-D_LARGEFILE_SOURCE=1) 1324238106Sdes]) 1325238106Sdes 1326238106Sdesdnl check if memcmp is using signed characters and replace if so. 1327238106SdesAC_DEFUN([ACX_CHECK_MEMCMP_SIGNED], 1328238106Sdes[AC_MSG_CHECKING([if memcmp compares unsigned]) 1329238106SdesAC_RUN_IFELSE([AC_LANG_SOURCE([[ 1330238106Sdes#include <stdio.h> 1331238106Sdes#include <stdlib.h> 1332238106Sdes#include <string.h> 1333238106Sdesint main(void) 1334238106Sdes{ 1335238106Sdes char a = 255, b = 0; 1336238106Sdes if(memcmp(&a, &b, 1) < 0) 1337238106Sdes return 1; 1338238106Sdes return 0; 1339238106Sdes} 1340238106Sdes]])], [AC_MSG_RESULT([yes]) ], 1341238106Sdes[ AC_MSG_RESULT([no]) 1342238106Sdes AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes]) 1343238106Sdes AC_LIBOBJ([memcmp]) 1344238106Sdes], [ AC_MSG_RESULT([cross-compile no]) 1345238106Sdes AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes]) 1346238106Sdes AC_LIBOBJ([memcmp]) 1347238106Sdes]) ]) 1348238106Sdes 1349238106Sdesdnl define memcmp to its replacement, pass unique id for program as arg 1350238106SdesAC_DEFUN([AHX_MEMCMP_BROKEN], [ 1351238106Sdes#ifdef MEMCMP_IS_BROKEN 1352238106Sdes#include "compat/memcmp.h" 1353238106Sdes#define memcmp memcmp_$1 1354238106Sdesint memcmp(const void *x, const void *y, size_t n); 1355238106Sdes#endif 1356238106Sdes]) 1357238106Sdes 1358238106Sdesdnl ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family 1359238106SdesAC_DEFUN([ACX_CHECK_SS_FAMILY], 1360238106Sdes[AC_CHECK_MEMBER([struct sockaddr_storage.ss_family], [], [ 1361238106Sdes AC_CHECK_MEMBER([struct sockaddr_storage.__ss_family], [ 1362238106Sdes AC_DEFINE([ss_family], [__ss_family], [Fallback member name for socket family in struct sockaddr_storage]) 1363238106Sdes ],, [AC_INCLUDES_DEFAULT 1364238106Sdes#ifdef HAVE_NETINET_IN_H 1365238106Sdes#include <netinet/in.h> 1366238106Sdes#endif 1367238106Sdes#ifdef HAVE_SYS_SOCKET_H 1368238106Sdes#include <sys/socket.h> 1369238106Sdes#endif 1370238106Sdes#ifdef HAVE_NETDB_H 1371238106Sdes#include <netdb.h> 1372238106Sdes#endif 1373238106Sdes#ifdef HAVE_ARPA_INET_H 1374238106Sdes#include <arpa/inet.h> 1375238106Sdes#endif 1376238106Sdes ]) 1377238106Sdes], [AC_INCLUDES_DEFAULT 1378238106Sdes#ifdef HAVE_NETINET_IN_H 1379238106Sdes#include <netinet/in.h> 1380238106Sdes#endif 1381238106Sdes#ifdef HAVE_SYS_SOCKET_H 1382238106Sdes#include <sys/socket.h> 1383238106Sdes#endif 1384238106Sdes#ifdef HAVE_NETDB_H 1385238106Sdes#include <netdb.h> 1386238106Sdes#endif 1387238106Sdes#ifdef HAVE_ARPA_INET_H 1388238106Sdes#include <arpa/inet.h> 1389238106Sdes#endif 1390238106Sdes]) ]) 1391238106Sdes 1392289063Sdesdnl Check if CC and linker support -fPIE and -pie. 1393289063Sdesdnl If so, sets them in CFLAGS / LDFLAGS. 1394289063SdesAC_DEFUN([ACX_CHECK_PIE], [ 1395289063Sdes AC_ARG_ENABLE([pie], AS_HELP_STRING([--enable-pie], [Enable Position-Independent Executable (eg. to fully benefit from ASLR, small performance penalty)])) 1396289063Sdes AS_IF([test "x$enable_pie" = "xyes"], [ 1397289063Sdes AC_MSG_CHECKING([if $CC supports PIE]) 1398289063Sdes BAKLDFLAGS="$LDFLAGS" 1399289063Sdes BAKCFLAGS="$CFLAGS" 1400289063Sdes LDFLAGS="$LDFLAGS -pie" 1401289063Sdes CFLAGS="$CFLAGS -fPIE" 1402289063Sdes AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [ 1403289063Sdes if $CC $CFLAGS $LDFLAGS -o conftest conftest.c 2>&1 | grep "warning: no debug symbols in executable" >/dev/null; then 1404289063Sdes LDFLAGS="$BAKLDFLAGS" 1405289063Sdes AC_MSG_RESULT(no) 1406289063Sdes else 1407289063Sdes AC_MSG_RESULT(yes) 1408289063Sdes fi 1409289063Sdes rm -f conftest conftest.c conftest.o 1410289063Sdes ], [LDFLAGS="$BAKLDFLAGS" ; CFLAGS="$BAKCFLAGS" ; AC_MSG_RESULT(no)]) 1411289063Sdes ]) 1412289063Sdes]) 1413289063Sdes 1414289063Sdesdnl Check if linker supports -Wl,-z,relro,-z,now. 1415289063Sdesdnl If so, adds it to LDFLAGS. 1416289063SdesAC_DEFUN([ACX_CHECK_RELRO_NOW], [ 1417289063Sdes 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)])) 1418289063Sdes AS_IF([test "x$enable_relro_now" = "xyes"], [ 1419289063Sdes AC_MSG_CHECKING([if $CC supports -Wl,-z,relro,-z,now]) 1420289063Sdes BAKLDFLAGS="$LDFLAGS" 1421289063Sdes LDFLAGS="$LDFLAGS -Wl,-z,relro,-z,now" 1422289063Sdes AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [ 1423289063Sdes if $CC $CFLAGS $LDFLAGS -o conftest conftest.c 2>&1 | grep "warning: no debug symbols in executable" >/dev/null; then 1424289063Sdes LDFLAGS="$BAKLDFLAGS" 1425289063Sdes AC_MSG_RESULT(no) 1426289063Sdes else 1427289063Sdes AC_MSG_RESULT(yes) 1428289063Sdes fi 1429289063Sdes rm -f conftest conftest.c conftest.o 1430289063Sdes ], [LDFLAGS="$BAKLDFLAGS" ; AC_MSG_RESULT(no)]) 1431289063Sdes ]) 1432289063Sdes]) 1433289063Sdes 1434238106Sdesdnl End of file 1435