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