acx_nlnetlabs.m4 revision 266114
1238104Sdes# acx_nlnetlabs.m4 - common macros for configure checks 2238104Sdes# Copyright 2009, Wouter Wijngaards, NLnet Labs. 3238104Sdes# BSD licensed. 4238104Sdes# 5266114Sdes# Version 26 6266114Sdes# 2013-09-19 FLTO help text improved. 7266114Sdes# 2013-07-18 Enable ACX_CHECK_COMPILER_FLAG to test for -Wstrict-prototypes 8266114Sdes# 2013-06-25 FLTO has --disable-flto option. 9266114Sdes# 2013-05-03 Update W32_SLEEP for newer mingw that links but not defines it. 10266114Sdes# 2013-03-22 Fix ACX_RSRC_VERSION for long version numbers. 11238104Sdes# 2012-02-09 Fix AHX_MEMCMP_BROKEN with undef in compat/memcmp.h. 12238104Sdes# 2012-01-20 Fix COMPILER_FLAGS_UNBOUND for gcc 4.6.2 assigned-not-used-warns. 13238104Sdes# 2011-12-05 Fix getaddrinfowithincludes on windows with fedora16 mingw32-gcc. 14238104Sdes# Fix ACX_MALLOC for redefined malloc error. 15238104Sdes# Fix GETADDRINFO_WITH_INCLUDES to add -lws2_32 16238104Sdes# 2011-11-10 Fix FLTO test to not drop a.out in current directory. 17238104Sdes# 2011-11-01 Fix FLTO test for llvm on Lion. 18238104Sdes# 2011-08-01 Fix nonblock test (broken at v13). 19238104Sdes# 2011-08-01 Fix autoconf 2.68 warnings 20238104Sdes# 2011-06-23 Add ACX_CHECK_FLTO to check -flto. 21238104Sdes# 2010-08-16 Fix FLAG_OMITTED for AS_TR_CPP changes in autoconf-2.66. 22238104Sdes# 2010-07-02 Add check for ss_family (for minix). 23238104Sdes# 2010-04-26 Fix to use CPPFLAGS for CHECK_COMPILER_FLAGS. 24238104Sdes# 2010-03-01 Fix RPATH using CONFIG_COMMANDS to run at the very end. 25266114Sdes# 2010-02-18 WITH_SSL outputs the LIBSSL_LDFLAGS, LIBS, CPPFLAGS separate, -ldl 26238104Sdes# 2010-02-01 added ACX_CHECK_MEMCMP_SIGNED, AHX_MEMCMP_BROKEN 27238104Sdes# 2010-01-20 added AHX_COONFIG_STRLCAT 28238104Sdes# 2009-07-14 U_CHAR detection improved for windows crosscompile. 29238104Sdes# added ACX_FUNC_MALLOC 30238104Sdes# fixup some #if to #ifdef 31238104Sdes# NONBLOCKING test for mingw crosscompile. 32238104Sdes# 2009-07-13 added ACX_WITH_SSL_OPTIONAL 33238104Sdes# 2009-07-03 fixup LDFLAGS for empty ssl dir. 34238104Sdes# 35238104Sdes# Automates some of the checking constructs. Aims at portability for POSIX. 36238104Sdes# Documentation for functions is below. 37238104Sdes# 38238104Sdes# the following macro's are provided in this file: 39238104Sdes# (see below for details on each macro). 40238104Sdes# 41238104Sdes# ACX_ESCAPE_BACKSLASH - escape backslashes in var for C-preproc. 42238104Sdes# ACX_RSRC_VERSION - create windows resource version number. 43238104Sdes# ACX_CHECK_COMPILER_FLAG - see if cc supports a flag. 44238104Sdes# ACX_CHECK_ERROR_FLAGS - see which flag is -werror (used below). 45238104Sdes# ACX_CHECK_COMPILER_FLAG_NEEDED - see if flags make the code compile cleanly. 46238104Sdes# ACX_DEPFLAG - find cc dependency flags. 47238104Sdes# ACX_DETERMINE_EXT_FLAGS_UNBOUND - find out which flags enable BSD and POSIX. 48238104Sdes# ACX_CHECK_FORMAT_ATTRIBUTE - find cc printf format syntax. 49238104Sdes# ACX_CHECK_UNUSED_ATTRIBUTE - find cc variable unused syntax. 50238104Sdes# ACX_CHECK_FLTO - see if cc supports -flto and use it if so. 51238104Sdes# ACX_LIBTOOL_C_ONLY - create libtool for C only, improved. 52238104Sdes# ACX_TYPE_U_CHAR - u_char type. 53238104Sdes# ACX_TYPE_RLIM_T - rlim_t type. 54238104Sdes# ACX_TYPE_SOCKLEN_T - socklen_t type. 55238104Sdes# ACX_TYPE_IN_ADDR_T - in_addr_t type. 56238104Sdes# ACX_TYPE_IN_PORT_T - in_port_t type. 57238104Sdes# ACX_ARG_RPATH - add --disable-rpath option. 58238104Sdes# ACX_WITH_SSL - add --with-ssl option, link -lcrypto. 59238104Sdes# ACX_WITH_SSL_OPTIONAL - add --with-ssl option, link -lcrypto, 60238104Sdes# where --without-ssl is also accepted 61238104Sdes# ACX_LIB_SSL - setup to link -lssl. 62238104Sdes# ACX_SYS_LARGEFILE - improved sys_largefile, fseeko, >2G files. 63238104Sdes# ACX_CHECK_GETADDRINFO_WITH_INCLUDES - find getaddrinfo, portably. 64238104Sdes# ACX_FUNC_DEPRECATED - see if func is deprecated. 65238104Sdes# ACX_CHECK_NONBLOCKING_BROKEN - see if nonblocking sockets really work. 66238104Sdes# ACX_MKDIR_ONE_ARG - determine mkdir(2) number of arguments. 67238104Sdes# ACX_FUNC_IOCTLSOCKET - find ioctlsocket, portably. 68238104Sdes# ACX_FUNC_MALLOC - check malloc, define replacement . 69238104Sdes# AHX_CONFIG_FORMAT_ATTRIBUTE - config.h text for format. 70238104Sdes# AHX_CONFIG_UNUSED_ATTRIBUTE - config.h text for unused. 71238104Sdes# AHX_CONFIG_FSEEKO - define fseeko, ftello fallback. 72238104Sdes# AHX_CONFIG_RAND_MAX - define RAND_MAX if needed. 73238104Sdes# AHX_CONFIG_MAXHOSTNAMELEN - define MAXHOSTNAMELEN if needed. 74238104Sdes# AHX_CONFIG_IPV6_MIN_MTU - define IPV6_MIN_MTU if needed. 75238104Sdes# AHX_CONFIG_SNPRINTF - snprintf compat prototype 76238104Sdes# AHX_CONFIG_INET_PTON - inet_pton compat prototype 77238104Sdes# AHX_CONFIG_INET_NTOP - inet_ntop compat prototype 78238104Sdes# AHX_CONFIG_INET_ATON - inet_aton compat prototype 79238104Sdes# AHX_CONFIG_MEMMOVE - memmove compat prototype 80238104Sdes# AHX_CONFIG_STRLCAT - strlcat compat prototype 81238104Sdes# AHX_CONFIG_STRLCPY - strlcpy compat prototype 82238104Sdes# AHX_CONFIG_GMTIME_R - gmtime_r compat prototype 83238104Sdes# AHX_CONFIG_W32_SLEEP - w32 compat for sleep 84238104Sdes# AHX_CONFIG_W32_USLEEP - w32 compat for usleep 85238104Sdes# AHX_CONFIG_W32_RANDOM - w32 compat for random 86238104Sdes# AHX_CONFIG_W32_SRANDOM - w32 compat for srandom 87238104Sdes# AHX_CONFIG_W32_FD_SET_T - w32 detection of FD_SET_T. 88238104Sdes# ACX_CFLAGS_STRIP - strip one flag from CFLAGS 89238104Sdes# ACX_STRIP_EXT_FLAGS - strip extension flags from CFLAGS 90238104Sdes# AHX_CONFIG_FLAG_OMITTED - define omitted flag 91238104Sdes# AHX_CONFIG_FLAG_EXT - define omitted extension flag 92238104Sdes# AHX_CONFIG_EXT_FLAGS - define the stripped extension flags 93238104Sdes# ACX_CHECK_MEMCMP_SIGNED - check if memcmp uses signed characters. 94238104Sdes# AHX_MEMCMP_BROKEN - replace memcmp func for CHECK_MEMCMP_SIGNED. 95238104Sdes# ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family 96238104Sdes# 97238104Sdes 98238104Sdesdnl Escape backslashes as \\, for C:\ paths, for the C preprocessor defines. 99238104Sdesdnl for example, ACX_ESCAPE_BACKSLASH($from_var, to_var) 100238104Sdesdnl $1: the text to change. 101238104Sdesdnl $2: the result. 102238104SdesAC_DEFUN([ACX_ESCAPE_BACKSLASH], [$2="`echo $1 | sed -e 's/\\\\/\\\\\\\\/g'`" 103238104Sdes]) 104238104Sdes 105238104Sdesdnl Calculate comma separated windows-resource numbers from package version. 106238104Sdesdnl Picks the first three(,0) or four numbers out of the name. 107238104Sdesdnl $1: variable for the result 108238104SdesAC_DEFUN([ACX_RSRC_VERSION], 109266114Sdes[$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/' `] 110238104Sdes]) 111238104Sdes 112238104Sdesdnl Routine to help check for compiler flags. 113238104Sdesdnl Checks if the compiler will accept the flag. 114238104Sdesdnl $1: the flag without a - in front, so g to check -g. 115238104Sdesdnl $2: executed if yes 116238104Sdesdnl $3: executed if no 117238104SdesAC_DEFUN([ACX_CHECK_COMPILER_FLAG], 118238104Sdes[ 119238104SdesAC_REQUIRE([AC_PROG_CC]) 120238104SdesAC_MSG_CHECKING(whether $CC supports -$1) 121238104Sdescache=`echo $1 | sed 'y%.=/+-%___p_%'` 122238104SdesAC_CACHE_VAL(cv_prog_cc_flag_$cache, 123238104Sdes[ 124266114Sdesecho 'void f(void){}' >conftest.c 125238104Sdesif test -z "`$CC $CPPFLAGS $CFLAGS -$1 -c conftest.c 2>&1`"; then 126238104Sdeseval "cv_prog_cc_flag_$cache=yes" 127238104Sdeselse 128238104Sdeseval "cv_prog_cc_flag_$cache=no" 129238104Sdesfi 130238104Sdesrm -f conftest conftest.o conftest.c 131238104Sdes]) 132238104Sdesif eval "test \"`echo '$cv_prog_cc_flag_'$cache`\" = yes"; then 133238104SdesAC_MSG_RESULT(yes) 134238104Sdes: 135238104Sdes$2 136238104Sdeselse 137238104SdesAC_MSG_RESULT(no) 138238104Sdes: 139238104Sdes$3 140238104Sdesfi 141238104Sdes]) 142238104Sdes 143238104Sdesdnl setup flags for ACX_CHECK_COMPILER_FLAG_NEEDED 144238104Sdesdnl ERRFLAG: result, compiler flag to turn warnings into errors 145238104SdesAC_DEFUN([ACX_CHECK_ERROR_FLAGS], 146238104Sdes[ 147238104SdesACX_CHECK_COMPILER_FLAG(Werror, [ERRFLAG="-Werror"], [ERRFLAG="-errwarn"]) 148238104SdesACX_CHECK_COMPILER_FLAG(Wall, [ERRFLAG="$ERRFLAG -Wall"], 149238104Sdes [ERRFLAG="$ERRFLAG -errfmt"]) 150238104Sdes]) 151238104Sdes 152238104Sdesdnl Routine to help check for needed compiler flags. 153238104Sdesdnl $1: flags for CC 154238104Sdesdnl $2: the includes and code 155238104Sdesdnl $3: if the given code only compiles with the flag, execute argument 3 156238104Sdesdnl $4: if the given code compiles without the flag, execute argument 4 157238104Sdesdnl $5: with and without flag the compile fails, execute argument 5. 158238104SdesAC_DEFUN([ACX_CHECK_COMPILER_FLAG_NEEDED], 159238104Sdes[ 160238104SdesAC_REQUIRE([AC_PROG_CC]) 161238104SdesAC_REQUIRE([ACX_CHECK_ERROR_FLAGS]) 162238104SdesAC_MSG_CHECKING(whether we need $1 as a flag for $CC) 163238104Sdescache=AS_TR_SH($1) 164238104Sdesdnl cache=`echo $1 | sed 'y%.=/+- %___p__%'` 165238104SdesAC_CACHE_VAL(cv_prog_cc_flag_needed_$cache, 166238104Sdes[ 167238104Sdesecho '$2' > conftest.c 168238104Sdesecho 'void f(){}' >>conftest.c 169238104Sdesif test -z "`$CC $CPPFLAGS $CFLAGS $ERRFLAG -c conftest.c 2>&1`"; then 170238104Sdeseval "cv_prog_cc_flag_needed_$cache=no" 171238104Sdeselse 172238104Sdes[ 173238104Sdesif test -z "`$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`"; then 174238104Sdeseval "cv_prog_cc_flag_needed_$cache=yes" 175238104Sdeselse 176238104Sdeseval "cv_prog_cc_flag_needed_$cache=fail" 177238104Sdes#echo 'Test with flag fails too!' 178238104Sdes#cat conftest.c 179238104Sdes#echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1" 180238104Sdes#echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1` 181238104Sdes#exit 1 182238104Sdesfi 183238104Sdes] 184238104Sdesfi 185238104Sdesrm -f conftest conftest.c conftest.o 186238104Sdes]) 187238104Sdesif eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = yes"; then 188238104SdesAC_MSG_RESULT(yes) 189238104Sdes: 190238104Sdes$3 191238104Sdeselse 192238104Sdesif eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = no"; then 193238104SdesAC_MSG_RESULT(no) 194238104Sdes#echo 'Test with flag is no!' 195238104Sdes#cat conftest.c 196238104Sdes#echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1" 197238104Sdes#echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1` 198238104Sdes#exit 1 199238104Sdes: 200238104Sdes$4 201238104Sdeselse 202238104SdesAC_MSG_RESULT(failed) 203238104Sdes: 204238104Sdes$5 205238104Sdesfi 206238104Sdesfi 207238104Sdes]) 208238104Sdes 209238104Sdesdnl Check for CC dependency flag 210238104Sdesdnl DEPFLAG: set to flag that generates dependencies. 211238104SdesAC_DEFUN([ACX_DEPFLAG], 212238104Sdes[ 213238104SdesAC_MSG_CHECKING([$CC dependency flag]) 214238104Sdesecho 'void f(){}' >conftest.c 215238104Sdesif test "`$CC -MM conftest.c 2>&1`" = "conftest.o: conftest.c"; then 216238104Sdes DEPFLAG="-MM" 217238104Sdeselse 218238104Sdes if test "`$CC -xM1 conftest.c 2>&1`" = "conftest.o: conftest.c"; then 219238104Sdes DEPFLAG="-xM1" 220238104Sdes else 221238104Sdes DEPFLAG="-MM" # dunno do something 222238104Sdes fi 223238104Sdesfi 224238104SdesAC_MSG_RESULT($DEPFLAG) 225238104Sdesrm -f conftest.c 226238104SdesAC_SUBST(DEPFLAG) 227238104Sdes]) 228238104Sdes 229238104Sdesdnl Determine flags that gives POSIX and BSD functionality. 230238104Sdesdnl CFLAGS is modified for the result. 231238104SdesAC_DEFUN([ACX_DETERMINE_EXT_FLAGS_UNBOUND], 232238104Sdes[ 233238104SdesACX_CHECK_COMPILER_FLAG(std=c99, [C99FLAG="-std=c99"]) 234238104SdesACX_CHECK_COMPILER_FLAG(xc99, [C99FLAG="-xc99"]) 235238104Sdes 236238104SdesAC_CHECK_HEADERS([getopt.h time.h],,, [AC_INCLUDES_DEFAULT]) 237238104Sdes 238238104SdesACX_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, 239238104Sdes[ 240238104Sdes#include "confdefs.h" 241238104Sdes#include <stdlib.h> 242238104Sdes#include <ctype.h> 243238104Sdes#include <sys/time.h> 244238104Sdes#ifdef HAVE_TIME_H 245238104Sdes#include <time.h> 246238104Sdes#endif 247238104Sdes#include <unistd.h> 248238104Sdes#include <netdb.h> 249238104Sdes#ifdef HAVE_GETOPT_H 250238104Sdes#include <getopt.h> 251238104Sdes#endif 252238104Sdes 253238104Sdesint test() { 254238104Sdes int a; 255238104Sdes char **opts = NULL; 256238104Sdes struct timeval tv; 257238104Sdes char *t; 258238104Sdes time_t time = 0; 259238104Sdes char *buf = NULL; 260238104Sdes const char* str = NULL; 261238104Sdes struct msghdr msg; 262238104Sdes msg.msg_control = 0; 263238104Sdes t = ctime_r(&time, buf); 264238104Sdes tv.tv_usec = 10; 265238104Sdes srandom(32); 266238104Sdes a = getopt(2, opts, "a"); 267238104Sdes a = isascii(32); 268238104Sdes str = gai_strerror(0); 269238104Sdes if(str && t && tv.tv_usec && msg.msg_control) 270238104Sdes a = 0; 271238104Sdes return a; 272238104Sdes} 273238104Sdes], [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"]) 274238104Sdes 275238104SdesACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE, 276238104Sdes[ 277238104Sdes#include "confdefs.h" 278238104Sdes#include <stdlib.h> 279238104Sdes#include <ctype.h> 280238104Sdes#include <sys/time.h> 281238104Sdes#ifdef HAVE_TIME_H 282238104Sdes#include <time.h> 283238104Sdes#endif 284238104Sdes#include <unistd.h> 285238104Sdes#include <netdb.h> 286238104Sdes#ifdef HAVE_GETOPT_H 287238104Sdes#include <getopt.h> 288238104Sdes#endif 289238104Sdes 290238104Sdesint test() { 291238104Sdes int a; 292238104Sdes char **opts = NULL; 293238104Sdes struct timeval tv; 294238104Sdes char *t; 295238104Sdes time_t time = 0; 296238104Sdes char *buf = NULL; 297238104Sdes const char* str = NULL; 298238104Sdes struct msghdr msg; 299238104Sdes msg.msg_control = 0; 300238104Sdes t = ctime_r(&time, buf); 301238104Sdes tv.tv_usec = 10; 302238104Sdes srandom(32); 303238104Sdes a = getopt(2, opts, "a"); 304238104Sdes a = isascii(32); 305238104Sdes str = gai_strerror(0); 306238104Sdes if(str && t && tv.tv_usec && msg.msg_control) 307238104Sdes a = 0; 308238104Sdes return a; 309238104Sdes} 310238104Sdes], [CFLAGS="$CFLAGS $C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE"]) 311238104Sdes 312238104SdesACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG, 313238104Sdes[ 314238104Sdes#include <stdbool.h> 315238104Sdes#include <ctype.h> 316238104Sdesint test() { 317238104Sdes int a = 0; 318238104Sdes return a; 319238104Sdes} 320238104Sdes], [CFLAGS="$CFLAGS $C99FLAG"]) 321238104Sdes 322238104SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_BSD_SOURCE, 323238104Sdes[ 324238104Sdes#include <ctype.h> 325238104Sdes 326238104Sdesint test() { 327238104Sdes int a; 328238104Sdes a = isascii(32); 329238104Sdes return a; 330238104Sdes} 331238104Sdes], [CFLAGS="$CFLAGS -D_BSD_SOURCE"]) 332238104Sdes 333238104SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE, 334238104Sdes[ 335238104Sdes#include <netinet/in.h> 336238104Sdes 337238104Sdesint test() { 338238104Sdes struct in6_pktinfo inf; 339238104Sdes int a = (int)sizeof(inf); 340238104Sdes return a; 341238104Sdes} 342238104Sdes], [CFLAGS="$CFLAGS -D_GNU_SOURCE"]) 343238104Sdes 344238104Sdes# check again for GNU_SOURCE for setresgid. May fail if setresgid 345238104Sdes# is not available at all. -D_FRSRESGID is to make this check unique. 346238104Sdes# otherwise we would get the previous cached result. 347238104SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE -D_FRSRESGID, 348238104Sdes[ 349238104Sdes#include <unistd.h> 350238104Sdes 351238104Sdesint test() { 352238104Sdes int a = setresgid(0,0,0); 353238104Sdes a = setresuid(0,0,0); 354238104Sdes return a; 355238104Sdes} 356238104Sdes], [CFLAGS="$CFLAGS -D_GNU_SOURCE"]) 357238104Sdes 358238104SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_POSIX_C_SOURCE=200112, 359238104Sdes[ 360238104Sdes#include "confdefs.h" 361238104Sdes#ifdef HAVE_TIME_H 362238104Sdes#include <time.h> 363238104Sdes#endif 364238104Sdes#include <netdb.h> 365238104Sdes 366238104Sdesint test() { 367238104Sdes int a = 0; 368238104Sdes char *t; 369238104Sdes time_t time = 0; 370238104Sdes char *buf = NULL; 371238104Sdes const char* str = NULL; 372238104Sdes t = ctime_r(&time, buf); 373238104Sdes str = gai_strerror(0); 374238104Sdes if(t && str) 375238104Sdes a = 0; 376238104Sdes return a; 377238104Sdes} 378238104Sdes], [CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112"]) 379238104Sdes 380238104SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D__EXTENSIONS__, 381238104Sdes[ 382238104Sdes#include "confdefs.h" 383238104Sdes#include <stdlib.h> 384238104Sdes#include <ctype.h> 385238104Sdes#include <sys/time.h> 386238104Sdes#ifdef HAVE_TIME_H 387238104Sdes#include <time.h> 388238104Sdes#endif 389238104Sdes#include <unistd.h> 390238104Sdes#ifdef HAVE_GETOPT_H 391238104Sdes#include <getopt.h> 392238104Sdes#endif 393238104Sdes 394238104Sdesint test() { 395238104Sdes int a; 396238104Sdes char **opts = NULL; 397238104Sdes struct timeval tv; 398238104Sdes tv.tv_usec = 10; 399238104Sdes srandom(32); 400238104Sdes a = getopt(2, opts, "a"); 401238104Sdes a = isascii(32); 402238104Sdes if(tv.tv_usec) 403238104Sdes a = 0; 404238104Sdes return a; 405238104Sdes} 406238104Sdes], [CFLAGS="$CFLAGS -D__EXTENSIONS__"]) 407238104Sdes 408238104Sdes])dnl End of ACX_DETERMINE_EXT_FLAGS_UNBOUND 409238104Sdes 410238104Sdesdnl Check if CC supports -flto. 411238104Sdesdnl in a way that supports clang and suncc (that flag does something else, 412238104Sdesdnl but fails to link). It sets it in CFLAGS if it works. 413266114SdesAC_DEFUN([ACX_CHECK_FLTO], [ 414266114Sdes AC_ARG_ENABLE([flto], AS_HELP_STRING([--disable-flto], [Disable link-time optimization (gcc specific option)])) 415266114Sdes AS_IF([test "x$enable_flto" != "xno"], [ 416266114Sdes AC_MSG_CHECKING([if $CC supports -flto]) 417266114Sdes BAKCFLAGS="$CFLAGS" 418266114Sdes CFLAGS="$CFLAGS -flto" 419266114Sdes AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [ 420266114Sdes if $CC $CFLAGS -o conftest conftest.c 2>&1 | grep "warning: no debug symbols in executable" >/dev/null; then 421266114Sdes CFLAGS="$BAKCFLAGS" 422266114Sdes AC_MSG_RESULT(no) 423266114Sdes else 424266114Sdes AC_MSG_RESULT(yes) 425266114Sdes fi 426266114Sdes rm -f conftest conftest.c conftest.o 427266114Sdes ], [CFLAGS="$BAKCFLAGS" ; AC_MSG_RESULT(no)]) 428266114Sdes ]) 429238104Sdes]) 430238104Sdes 431238104Sdesdnl Check the printf-format attribute (if any) 432238104Sdesdnl result in HAVE_ATTR_FORMAT. 433238104Sdesdnl Make sure you also include the AHX_CONFIG_FORMAT_ATTRIBUTE. 434238104SdesAC_DEFUN([ACX_CHECK_FORMAT_ATTRIBUTE], 435238104Sdes[AC_REQUIRE([AC_PROG_CC]) 436238104SdesAC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute) 437238104SdesAC_CACHE_VAL(ac_cv_c_format_attribute, 438238104Sdes[ac_cv_c_format_attribute=no 439238104SdesAC_TRY_COMPILE( 440238104Sdes[#include <stdio.h> 441238104Sdesvoid f (char *format, ...) __attribute__ ((format (printf, 1, 2))); 442238104Sdesvoid (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2))); 443238104Sdes], [ 444238104Sdes f ("%s", "str"); 445238104Sdes], 446238104Sdes[ac_cv_c_format_attribute="yes"], 447238104Sdes[ac_cv_c_format_attribute="no"]) 448238104Sdes]) 449238104Sdes 450238104SdesAC_MSG_RESULT($ac_cv_c_format_attribute) 451238104Sdesif test $ac_cv_c_format_attribute = yes; then 452238104Sdes AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute]) 453238104Sdesfi 454238104Sdes])dnl End of ACX_CHECK_FORMAT_ATTRIBUTE 455238104Sdes 456238104Sdesdnl Setup ATTR_FORMAT config.h parts. 457238104Sdesdnl make sure you call ACX_CHECK_FORMAT_ATTRIBUTE also. 458238104SdesAC_DEFUN([AHX_CONFIG_FORMAT_ATTRIBUTE], 459238104Sdes[ 460238104Sdes#ifdef HAVE_ATTR_FORMAT 461238104Sdes# define ATTR_FORMAT(archetype, string_index, first_to_check) \ 462238104Sdes __attribute__ ((format (archetype, string_index, first_to_check))) 463238104Sdes#else /* !HAVE_ATTR_FORMAT */ 464238104Sdes# define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */ 465238104Sdes#endif /* !HAVE_ATTR_FORMAT */ 466238104Sdes]) 467238104Sdes 468238104Sdesdnl Check how to mark function arguments as unused. 469238104Sdesdnl result in HAVE_ATTR_UNUSED. 470238104Sdesdnl Make sure you include AHX_CONFIG_UNUSED_ATTRIBUTE also. 471238104SdesAC_DEFUN([ACX_CHECK_UNUSED_ATTRIBUTE], 472238104Sdes[AC_REQUIRE([AC_PROG_CC]) 473238104SdesAC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute) 474238104SdesAC_CACHE_VAL(ac_cv_c_unused_attribute, 475238104Sdes[ac_cv_c_unused_attribute=no 476238104SdesAC_TRY_COMPILE( 477238104Sdes[#include <stdio.h> 478238104Sdesvoid f (char *u __attribute__((unused))); 479238104Sdes], [ 480238104Sdes f ("x"); 481238104Sdes], 482238104Sdes[ac_cv_c_unused_attribute="yes"], 483238104Sdes[ac_cv_c_unused_attribute="no"]) 484238104Sdes]) 485238104Sdes 486238104Sdesdnl Setup ATTR_UNUSED config.h parts. 487238104Sdesdnl make sure you call ACX_CHECK_UNUSED_ATTRIBUTE also. 488238104SdesAC_DEFUN([AHX_CONFIG_UNUSED_ATTRIBUTE], 489238104Sdes[ 490238104Sdes#if defined(DOXYGEN) 491238104Sdes# define ATTR_UNUSED(x) x 492238104Sdes#elif defined(__cplusplus) 493238104Sdes# define ATTR_UNUSED(x) 494238104Sdes#elif defined(HAVE_ATTR_UNUSED) 495238104Sdes# define ATTR_UNUSED(x) x __attribute__((unused)) 496238104Sdes#else /* !HAVE_ATTR_UNUSED */ 497238104Sdes# define ATTR_UNUSED(x) x 498238104Sdes#endif /* !HAVE_ATTR_UNUSED */ 499238104Sdes]) 500238104Sdes 501238104SdesAC_MSG_RESULT($ac_cv_c_unused_attribute) 502238104Sdesif test $ac_cv_c_unused_attribute = yes; then 503238104Sdes AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute]) 504238104Sdesfi 505238104Sdes])dnl 506238104Sdes 507238104Sdesdnl Pre-fun for ACX_LIBTOOL_C_ONLY 508238104SdesAC_DEFUN([ACX_LIBTOOL_C_PRE], [ 509238104Sdes# skip these tests, we do not need them. 510238104SdesAC_DEFUN([AC_PROG_F77], [:]) 511238104SdesAC_DEFUN([AC_PROG_FC], [:]) 512238104SdesAC_DEFUN([AC_PROG_CXX], [:]) 513238104SdesAC_DEFUN([AC_PROG_CXXCPP], [:]) 514238104SdesAC_DEFUN([AC_PROG_OBJC], [:]) 515238104SdesAC_DEFUN([AC_PROG_OBJCCPP], [:]) 516238104SdesAC_DEFUN([AC_LIBTOOL_CXX], [:]) 517238104SdesAC_DEFUN([AC_LIBTOOL_F77], [:]) 518238104Sdes# always use ./libtool unless override from commandline (libtool=mylibtool) 519238104Sdesif test -z "$libtool"; then 520238104Sdes libtool="./libtool" 521238104Sdesfi 522238104SdesAC_SUBST(libtool) 523238104Sdes# avoid libtool max commandline length test on systems that fork slowly. 524238104SdesAC_CANONICAL_HOST 525238104Sdesif echo "$host_os" | grep "sunos4" >/dev/null; then 526238104Sdes lt_cv_sys_max_cmd_len=32750; 527238104Sdesfi 528238104SdesAC_PATH_TOOL(AR, ar, [false]) 529238104Sdesif test $AR = false; then 530238104Sdes AC_MSG_ERROR([Cannot find 'ar', please extend PATH to include it]) 531238104Sdesfi 532238104Sdes]) 533238104Sdes 534238104Sdesdnl Perform libtool check, portably, only for C 535238104SdesAC_DEFUN([ACX_LIBTOOL_C_ONLY], [ 536238104Sdesdnl as a requirement so that is gets called before LIBTOOL 537238104Sdesdnl because libtools 'AC_REQUIRE' names are right after this one, before 538238104Sdesdnl this function contents. 539238104SdesAC_REQUIRE([ACX_LIBTOOL_C_PRE]) 540238104SdesAC_PROG_LIBTOOL 541238104Sdes]) 542238104Sdes 543238104Sdesdnl Detect if u_char type is defined, otherwise define it. 544238104SdesAC_DEFUN([ACX_TYPE_U_CHAR], 545238104Sdes[AC_CHECK_TYPE([u_char], , 546238104Sdes [AC_DEFINE([u_char], [unsigned char], [Define to 'unsigned char if not defined])], [ 547238104SdesAC_INCLUDES_DEFAULT 548238104Sdes#ifdef HAVE_WINSOCK2_H 549238104Sdes# include <winsock2.h> 550238104Sdes#endif 551238104Sdes]) ]) 552238104Sdes 553238104Sdesdnl Detect if rlim_t type is defined, otherwise define it. 554238104SdesAC_DEFUN([ACX_TYPE_RLIM_T], 555238104Sdes[AC_CHECK_TYPE(rlim_t, , 556238104Sdes [AC_DEFINE([rlim_t], [unsigned long], [Define to 'int' if not defined])], [ 557238104SdesAC_INCLUDES_DEFAULT 558238104Sdes#ifdef HAVE_SYS_RESOURCE_H 559238104Sdes# include <sys/resource.h> 560238104Sdes#endif 561238104Sdes]) ]) 562238104Sdes 563238104Sdesdnl Detect if socklen_t type is defined, otherwise define it. 564238104SdesAC_DEFUN([ACX_TYPE_SOCKLEN_T], 565238104Sdes[ 566238104SdesAC_CHECK_TYPE(socklen_t, , 567238104Sdes [AC_DEFINE([socklen_t], [int], [Define to 'int' if not defined])], [ 568238104SdesAC_INCLUDES_DEFAULT 569238104Sdes#ifdef HAVE_SYS_SOCKET_H 570238104Sdes# include <sys/socket.h> 571238104Sdes#endif 572238104Sdes#ifdef HAVE_WS2TCPIP_H 573238104Sdes# include <ws2tcpip.h> 574238104Sdes#endif 575238104Sdes]) ]) 576238104Sdes 577238104Sdesdnl Detect if in_addr_t type is defined, otherwise define it. 578238104SdesAC_DEFUN([ACX_TYPE_IN_ADDR_T], 579238104Sdes[ AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [ 580238104SdesAC_INCLUDES_DEFAULT 581238104Sdes#ifdef HAVE_SYS_TYPES_H 582238104Sdes# include <sys/types.h> 583238104Sdes#endif 584238104Sdes#ifdef HAVE_NETINET_IN_H 585238104Sdes# include <netinet/in.h> 586238104Sdes#endif 587238104Sdes]) ]) 588238104Sdes 589238104Sdesdnl Detect if in_port_t type is defined, otherwise define it. 590238104SdesAC_DEFUN([ACX_TYPE_IN_PORT_T], 591238104Sdes[ AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])], [ 592238104SdesAC_INCLUDES_DEFAULT 593238104Sdes#ifdef HAVE_SYS_TYPES_H 594238104Sdes# include <sys/types.h> 595238104Sdes#endif 596238104Sdes#ifdef HAVE_NETINET_IN_H 597238104Sdes# include <netinet/in.h> 598238104Sdes#endif 599238104Sdes]) ]) 600238104Sdes 601238104Sdesdnl Add option to disable the evil rpath. Check whether to use rpath or not. 602238104Sdesdnl Adds the --disable-rpath option. Uses trick to edit the ./libtool. 603238104SdesAC_DEFUN([ACX_ARG_RPATH], 604238104Sdes[ 605238104SdesAC_ARG_ENABLE(rpath, 606238104Sdes [ --disable-rpath disable hardcoded rpath (default=enabled)], 607238104Sdes enable_rpath=$enableval, enable_rpath=yes) 608238104Sdesif test "x$enable_rpath" = xno; then 609238104Sdes dnl AC_MSG_RESULT([Fixing libtool for -rpath problems.]) 610238104Sdes AC_CONFIG_COMMANDS([disable-rpath], [ 611238104Sdes sed < libtool > libtool-2 \ 612238104Sdes 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_RPATH_SED__ "/' 613238104Sdes mv libtool-2 libtool 614238104Sdes chmod 755 libtool 615238104Sdes libtool="./libtool" 616238104Sdes ]) 617238104Sdesfi 618238104Sdes]) 619238104Sdes 620238104Sdesdnl Add a -R to the RUNTIME_PATH. Only if rpath is enabled and it is 621238104Sdesdnl an absolute path. 622238104Sdesdnl $1: the pathname to add. 623238104SdesAC_DEFUN([ACX_RUNTIME_PATH_ADD], [ 624238104Sdes if test "x$enable_rpath" = xyes; then 625238104Sdes if echo "$1" | grep "^/" >/dev/null; then 626238104Sdes RUNTIME_PATH="$RUNTIME_PATH -R$1" 627238104Sdes fi 628238104Sdes fi 629238104Sdes]) 630238104Sdes 631238104Sdesdnl Common code for both ACX_WITH_SSL and ACX_WITH_SSL_OPTIONAL 632238104Sdesdnl Takes one argument; the withval checked in those 2 functions 633238104Sdesdnl sets up the environment for the given openssl path 634238104SdesAC_DEFUN([ACX_SSL_CHECKS], [ 635238104Sdes withval=$1 636238104Sdes if test x_$withval != x_no; then 637238104Sdes AC_MSG_CHECKING(for SSL) 638238104Sdes if test x_$withval = x_ -o x_$withval = x_yes; then 639238104Sdes withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr" 640238104Sdes fi 641238104Sdes for dir in $withval; do 642238104Sdes ssldir="$dir" 643238104Sdes if test -f "$dir/include/openssl/ssl.h"; then 644238104Sdes found_ssl="yes" 645238104Sdes AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.]) 646238104Sdes dnl assume /usr/include is already in the include-path. 647238104Sdes if test "$ssldir" != "/usr"; then 648238104Sdes CPPFLAGS="$CPPFLAGS -I$ssldir/include" 649238104Sdes LIBSSL_CPPFLAGS="$LIBSSL_CPPFLAGS -I$ssldir/include" 650238104Sdes fi 651238104Sdes break; 652238104Sdes fi 653238104Sdes done 654238104Sdes if test x_$found_ssl != x_yes; then 655238104Sdes AC_MSG_ERROR(Cannot find the SSL libraries in $withval) 656238104Sdes else 657238104Sdes AC_MSG_RESULT(found in $ssldir) 658238104Sdes HAVE_SSL=yes 659238104Sdes dnl assume /usr is already in the lib and dynlib paths. 660238104Sdes if test "$ssldir" != "/usr" -a "$ssldir" != ""; then 661238104Sdes LDFLAGS="$LDFLAGS -L$ssldir/lib" 662238104Sdes LIBSSL_LDFLAGS="$LIBSSL_LDFLAGS -L$ssldir/lib" 663238104Sdes ACX_RUNTIME_PATH_ADD([$ssldir/lib]) 664238104Sdes fi 665238104Sdes 666238104Sdes AC_MSG_CHECKING([for HMAC_CTX_init in -lcrypto]) 667238104Sdes LIBS="$LIBS -lcrypto" 668238104Sdes LIBSSL_LIBS="$LIBSSL_LIBS -lcrypto" 669238104Sdes AC_TRY_LINK(, [ 670238104Sdes int HMAC_CTX_init(void); 671238104Sdes (void)HMAC_CTX_init(); 672238104Sdes ], [ 673238104Sdes AC_MSG_RESULT(yes) 674238104Sdes AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 675238104Sdes [If you have HMAC_CTX_init]) 676238104Sdes ], [ 677238104Sdes AC_MSG_RESULT(no) 678238104Sdes # check if -lwsock32 or -lgdi32 are needed. 679238104Sdes BAKLIBS="$LIBS" 680238104Sdes BAKSSLLIBS="$LIBSSL_LIBS" 681238104Sdes LIBS="$LIBS -lgdi32" 682238104Sdes LIBSSL_LIBS="$LIBSSL_LIBS -lgdi32" 683238104Sdes AC_MSG_CHECKING([if -lcrypto needs -lgdi32]) 684238104Sdes AC_TRY_LINK([], [ 685238104Sdes int HMAC_CTX_init(void); 686238104Sdes (void)HMAC_CTX_init(); 687238104Sdes ],[ 688238104Sdes AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 689238104Sdes [If you have HMAC_CTX_init]) 690238104Sdes AC_MSG_RESULT(yes) 691238104Sdes ],[ 692238104Sdes AC_MSG_RESULT(no) 693238104Sdes LIBS="$BAKLIBS" 694238104Sdes LIBSSL_LIBS="$BAKSSLLIBS" 695238104Sdes LIBS="$LIBS -ldl" 696238104Sdes LIBSSL_LIBS="$LIBSSL_LIBS -ldl" 697238104Sdes AC_MSG_CHECKING([if -lcrypto needs -ldl]) 698238104Sdes AC_TRY_LINK([], [ 699238104Sdes int HMAC_CTX_init(void); 700238104Sdes (void)HMAC_CTX_init(); 701238104Sdes ],[ 702238104Sdes AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 703238104Sdes [If you have HMAC_CTX_init]) 704238104Sdes AC_MSG_RESULT(yes) 705238104Sdes ],[ 706238104Sdes AC_MSG_RESULT(no) 707238104Sdes AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required]) 708238104Sdes ]) 709238104Sdes ]) 710238104Sdes ]) 711238104Sdes fi 712238104Sdes AC_SUBST(HAVE_SSL) 713238104Sdes AC_SUBST(RUNTIME_PATH) 714238104Sdes # openssl engine functionality needs dlopen(). 715238104Sdes BAKLIBS="$LIBS" 716238104Sdes AC_SEARCH_LIBS([dlopen], [dl]) 717238104Sdes if test "$LIBS" != "$BAKLIBS"; then 718238104Sdes LIBSSL_LIBS="$LIBSSL_LIBS -ldl" 719238104Sdes fi 720238104Sdes fi 721238104SdesAC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT]) 722238104SdesAC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT]) 723238104SdesAC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT]) 724238104Sdes])dnl End of ACX_SSL_CHECKS 725238104Sdes 726238104Sdesdnl Check for SSL, where SSL is mandatory 727238104Sdesdnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found 728238104Sdesdnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS. 729238104Sdesdnl Checks main header files of SSL. 730238104Sdesdnl 731238104SdesAC_DEFUN([ACX_WITH_SSL], 732238104Sdes[ 733238104SdesAC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname], 734238104Sdes [enable SSL (will check /usr/local/ssl 735238104Sdes /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr)]),[ 736238104Sdes ],[ 737238104Sdes withval="yes" 738238104Sdes ]) 739238104Sdes if test x_$withval = x_no; then 740238104Sdes AC_MSG_ERROR([Need SSL library to do digital signature cryptography]) 741238104Sdes fi 742238104Sdes ACX_SSL_CHECKS($withval) 743238104Sdes])dnl End of ACX_WITH_SSL 744238104Sdes 745238104Sdesdnl Check for SSL, where ssl is optional (--without-ssl is allowed) 746238104Sdesdnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found 747238104Sdesdnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS. 748238104Sdesdnl Checks main header files of SSL. 749238104Sdesdnl 750238104SdesAC_DEFUN([ACX_WITH_SSL_OPTIONAL], 751238104Sdes[ 752238104SdesAC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname], 753238104Sdes [enable SSL (will check /usr/local/ssl 754238104Sdes /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr)]),[ 755238104Sdes ],[ 756238104Sdes withval="yes" 757238104Sdes ]) 758238104Sdes ACX_SSL_CHECKS($withval) 759238104Sdes])dnl End of ACX_WITH_SSL_OPTIONAL 760238104Sdes 761238104Sdesdnl Setup to use -lssl 762238104Sdesdnl To use -lcrypto, use the ACX_WITH_SSL setup (before this one). 763238104SdesAC_DEFUN([ACX_LIB_SSL], 764238104Sdes[ 765238104Sdes# check if libssl needs libdl 766238104SdesBAKLIBS="$LIBS" 767238104SdesLIBS="-lssl $LIBS" 768238104SdesAC_MSG_CHECKING([if libssl needs libdl]) 769238104SdesAC_TRY_LINK_FUNC([SSL_CTX_new], [ 770238104Sdes AC_MSG_RESULT([no]) 771238104Sdes LIBS="$BAKLIBS" 772238104Sdes] , [ 773238104Sdes AC_MSG_RESULT([yes]) 774238104Sdes LIBS="$BAKLIBS" 775238104Sdes AC_SEARCH_LIBS([dlopen], [dl]) 776238104Sdes]) ])dnl End of ACX_LIB_SSL 777238104Sdes 778238104Sdesdnl Setup to use very large files (>2Gb). 779238104Sdesdnl setups fseeko and its own 780238104SdesAC_DEFUN([ACX_SYS_LARGEFILE], 781238104Sdes[ 782238104SdesAC_SYS_LARGEFILE 783238104Sdesdnl try to see if an additional _LARGEFILE_SOURCE 1 is needed to get fseeko 784238104SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_LARGEFILE_SOURCE=1, 785238104Sdes[ 786238104Sdes#include <stdio.h> 787238104Sdesint test() { 788238104Sdes int a = fseeko(stdin, 0, 0); 789238104Sdes return a; 790238104Sdes} 791238104Sdes], [CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE=1"]) 792238104Sdes]) 793238104Sdes 794238104Sdesdnl Check getaddrinfo. 795238104Sdesdnl Works on linux, solaris, bsd and windows(links winsock). 796238104Sdesdnl defines HAVE_GETADDRINFO, USE_WINSOCK. 797238104SdesAC_DEFUN([ACX_CHECK_GETADDRINFO_WITH_INCLUDES], 798238104Sdes[AC_REQUIRE([AC_PROG_CC]) 799238104SdesAC_MSG_CHECKING(for getaddrinfo) 800238104Sdesac_cv_func_getaddrinfo=no 801238104SdesAC_LINK_IFELSE( 802238104Sdes[AC_LANG_SOURCE([[ 803238104Sdes#ifdef __cplusplus 804238104Sdesextern "C" 805238104Sdes{ 806238104Sdes#endif 807238104Sdeschar* getaddrinfo(); 808238104Sdeschar* (*f) () = getaddrinfo; 809238104Sdes#ifdef __cplusplus 810238104Sdes} 811238104Sdes#endif 812238104Sdesint main() { 813238104Sdes ; 814238104Sdes return 0; 815238104Sdes} 816238104Sdes]])], 817238104Sdesdnl this case on linux, solaris, bsd 818238104Sdes[ac_cv_func_getaddrinfo="yes" 819238104Sdesdnl see if on windows 820238104Sdesif test "$ac_cv_header_windows_h" = "yes"; then 821238104Sdes AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used]) 822238104Sdes USE_WINSOCK="1" 823238104Sdes LIBS="$LIBS -lws2_32" 824238104Sdesfi 825238104Sdes], 826238104Sdesdnl no quick getaddrinfo, try mingw32 and winsock2 library. 827238104SdesORIGLIBS="$LIBS" 828238104SdesLIBS="$LIBS -lws2_32" 829238104SdesAC_LINK_IFELSE( 830238104Sdes[AC_LANG_PROGRAM( 831238104Sdes[ 832238104Sdes#ifdef HAVE_WS2TCPIP_H 833238104Sdes#include <ws2tcpip.h> 834238104Sdes#endif 835238104Sdes], 836238104Sdes[ 837238104Sdes (void)getaddrinfo(NULL, NULL, NULL, NULL); 838238104Sdes] 839238104Sdes)], 840238104Sdes[ 841238104Sdesac_cv_func_getaddrinfo="yes" 842238104Sdesdnl already: LIBS="$LIBS -lws2_32" 843238104SdesAC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used]) 844238104SdesUSE_WINSOCK="1" 845238104Sdes], 846238104Sdes[ 847238104Sdesac_cv_func_getaddrinfo="no" 848238104SdesLIBS="$ORIGLIBS" 849238104Sdes]) 850238104Sdes) 851238104Sdes 852238104SdesAC_MSG_RESULT($ac_cv_func_getaddrinfo) 853238104Sdesif test $ac_cv_func_getaddrinfo = yes; then 854238104Sdes AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether getaddrinfo is available]) 855238104Sdesfi 856238104Sdes])dnl Endof AC_CHECK_GETADDRINFO_WITH_INCLUDES 857238104Sdes 858238104Sdesdnl check if a function is deprecated. defines DEPRECATED_func in config.h. 859238104Sdesdnl $1: function name 860238104Sdesdnl $2: C-statement that calls the function. 861238104Sdesdnl $3: includes for the program. 862238104Sdesdnl $4: executes if yes 863238104Sdesdnl $5: executes if no 864238104SdesAC_DEFUN([ACX_FUNC_DEPRECATED], 865238104Sdes[ 866238104SdesAC_REQUIRE([AC_PROG_CC]) 867238104SdesAC_MSG_CHECKING(if $1 is deprecated) 868238104Sdescache=`echo $1 | sed 'y%.=/+-%___p_%'` 869238104SdesAC_CACHE_VAL(cv_cc_deprecated_$cache, 870238104Sdes[ 871238104Sdesecho '$3' >conftest.c 872238104Sdesecho 'void f(){ $2 }' >>conftest.c 873238104Sdesif test -z "`$CC -c conftest.c 2>&1 | grep deprecated`"; then 874238104Sdeseval "cv_cc_deprecated_$cache=no" 875238104Sdeselse 876238104Sdeseval "cv_cc_deprecated_$cache=yes" 877238104Sdesfi 878238104Sdesrm -f conftest conftest.o conftest.c 879238104Sdes]) 880238104Sdesif eval "test \"`echo '$cv_cc_deprecated_'$cache`\" = yes"; then 881238104SdesAC_MSG_RESULT(yes) 882238104SdesAC_DEFINE_UNQUOTED(AS_TR_CPP([DEPRECATED_$1]), 1, [Whether $1 is deprecated]) 883238104Sdes: 884238104Sdes$4 885238104Sdeselse 886238104SdesAC_MSG_RESULT(no) 887238104Sdes: 888238104Sdes$5 889238104Sdesfi 890238104Sdes])dnl end of ACX_FUNC_DEPRECATED 891238104Sdes 892238104Sdesdnl check if select and nonblocking sockets actually work. 893238104Sdesdnl Needs fork(2) and select(2). 894238104Sdesdnl defines NONBLOCKING_IS_BROKEN, and if that is true multiple reads from 895238104Sdesdnl a nonblocking socket do not work, a new call to select is necessary. 896238104SdesAC_DEFUN([ACX_CHECK_NONBLOCKING_BROKEN], 897238104Sdes[ 898238104SdesAC_MSG_CHECKING([if nonblocking sockets work]) 899238104Sdesif echo $target | grep mingw32 >/dev/null; then 900238104Sdes AC_MSG_RESULT([no (windows)]) 901238104Sdes AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).]) 902238104Sdeselse 903238104SdesAC_RUN_IFELSE([ 904238104SdesAC_LANG_SOURCE([[ 905238104Sdes#include <stdio.h> 906238104Sdes#include <string.h> 907238104Sdes#include <stdlib.h> 908238104Sdes#include <fcntl.h> 909238104Sdes#include <errno.h> 910238104Sdes#ifdef HAVE_SYS_TYPES_H 911238104Sdes#include <sys/types.h> 912238104Sdes#endif 913238104Sdes#ifdef HAVE_SYS_SOCKET_H 914238104Sdes#include <sys/socket.h> 915238104Sdes#endif 916238104Sdes#ifdef HAVE_NETINET_IN_H 917238104Sdes#include <netinet/in.h> 918238104Sdes#endif 919238104Sdes#ifdef HAVE_ARPA_INET_H 920238104Sdes#include <arpa/inet.h> 921238104Sdes#endif 922238104Sdes#ifdef HAVE_UNISTD_H 923238104Sdes#include <unistd.h> 924238104Sdes#endif 925238104Sdes#ifdef HAVE_TIME_H 926238104Sdes#include <time.h> 927238104Sdes#endif 928238104Sdes 929238104Sdesint main(void) 930238104Sdes{ 931238104Sdes int port; 932238104Sdes int sfd, cfd; 933238104Sdes int num = 10; 934238104Sdes int i, p; 935238104Sdes struct sockaddr_in a; 936238104Sdes /* test if select and nonblocking reads work well together */ 937238104Sdes /* open port. 938238104Sdes fork child to send 10 messages. 939238104Sdes select to read. 940238104Sdes then try to nonblocking read the 10 messages 941238104Sdes then, nonblocking read must give EAGAIN 942238104Sdes */ 943238104Sdes 944238104Sdes port = 12345 + (time(0)%32); 945238104Sdes sfd = socket(PF_INET, SOCK_DGRAM, 0); 946238104Sdes if(sfd == -1) { 947238104Sdes perror("socket"); 948238104Sdes return 1; 949238104Sdes } 950238104Sdes memset(&a, 0, sizeof(a)); 951238104Sdes a.sin_family = AF_INET; 952238104Sdes a.sin_port = htons(port); 953238104Sdes a.sin_addr.s_addr = inet_addr("127.0.0.1"); 954238104Sdes if(bind(sfd, (struct sockaddr*)&a, sizeof(a)) < 0) { 955238104Sdes perror("bind"); 956238104Sdes return 1; 957238104Sdes } 958238104Sdes if(fcntl(sfd, F_SETFL, O_NONBLOCK) == -1) { 959238104Sdes perror("fcntl"); 960238104Sdes return 1; 961238104Sdes } 962238104Sdes 963238104Sdes cfd = socket(PF_INET, SOCK_DGRAM, 0); 964238104Sdes if(cfd == -1) { 965238104Sdes perror("client socket"); 966238104Sdes return 1; 967238104Sdes } 968238104Sdes a.sin_port = 0; 969238104Sdes if(bind(cfd, (struct sockaddr*)&a, sizeof(a)) < 0) { 970238104Sdes perror("client bind"); 971238104Sdes return 1; 972238104Sdes } 973238104Sdes a.sin_port = htons(port); 974238104Sdes 975238104Sdes /* no handler, causes exit in 10 seconds */ 976238104Sdes alarm(10); 977238104Sdes 978238104Sdes /* send and receive on the socket */ 979238104Sdes if((p=fork()) == 0) { 980238104Sdes for(i=0; i<num; i++) { 981238104Sdes if(sendto(cfd, &i, sizeof(i), 0, 982238104Sdes (struct sockaddr*)&a, sizeof(a)) < 0) { 983238104Sdes perror("sendto"); 984238104Sdes return 1; 985238104Sdes } 986238104Sdes } 987238104Sdes } else { 988238104Sdes /* parent */ 989238104Sdes fd_set rset; 990238104Sdes int x; 991238104Sdes if(p == -1) { 992238104Sdes perror("fork"); 993238104Sdes return 1; 994238104Sdes } 995238104Sdes FD_ZERO(&rset); 996238104Sdes FD_SET(sfd, &rset); 997238104Sdes if(select(sfd+1, &rset, NULL, NULL, NULL) < 1) { 998238104Sdes perror("select"); 999238104Sdes return 1; 1000238104Sdes } 1001238104Sdes i = 0; 1002238104Sdes while(i < num) { 1003238104Sdes if(recv(sfd, &x, sizeof(x), 0) != sizeof(x)) { 1004238104Sdes if(errno == EAGAIN) 1005238104Sdes continue; 1006238104Sdes perror("recv"); 1007238104Sdes return 1; 1008238104Sdes } 1009238104Sdes i++; 1010238104Sdes } 1011238104Sdes /* now we want to get EAGAIN: nonblocking goodness */ 1012238104Sdes errno = 0; 1013238104Sdes recv(sfd, &x, sizeof(x), 0); 1014238104Sdes if(errno != EAGAIN) { 1015238104Sdes perror("trying to recv again"); 1016238104Sdes return 1; 1017238104Sdes } 1018238104Sdes /* EAGAIN encountered */ 1019238104Sdes } 1020238104Sdes 1021238104Sdes close(sfd); 1022238104Sdes close(cfd); 1023238104Sdes return 0; 1024238104Sdes} 1025238104Sdes]])], [ 1026238104Sdes AC_MSG_RESULT([yes]) 1027238104Sdes], [ 1028238104Sdes AC_MSG_RESULT([no]) 1029238104Sdes AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).]) 1030238104Sdes], [ 1031238104Sdes AC_MSG_RESULT([crosscompile(yes)]) 1032238104Sdes]) 1033238104Sdesfi 1034238104Sdes])dnl End of ACX_CHECK_NONBLOCKING_BROKEN 1035238104Sdes 1036238104Sdesdnl Check if mkdir has one or two arguments. 1037238104Sdesdnl defines MKDIR_HAS_ONE_ARG 1038238104SdesAC_DEFUN([ACX_MKDIR_ONE_ARG], 1039238104Sdes[ 1040238104SdesAC_MSG_CHECKING([whether mkdir has one arg]) 1041238104SdesAC_TRY_COMPILE([ 1042238104Sdes#include <stdio.h> 1043238104Sdes#include <unistd.h> 1044238104Sdes#ifdef HAVE_WINSOCK2_H 1045238104Sdes#include <winsock2.h> 1046238104Sdes#endif 1047238104Sdes#ifdef HAVE_SYS_STAT_H 1048238104Sdes#include <sys/stat.h> 1049238104Sdes#endif 1050238104Sdes], [ 1051238104Sdes (void)mkdir("directory"); 1052238104Sdes], 1053238104SdesAC_MSG_RESULT(yes) 1054238104SdesAC_DEFINE(MKDIR_HAS_ONE_ARG, 1, [Define if mkdir has one argument.]) 1055238104Sdes, 1056238104SdesAC_MSG_RESULT(no) 1057238104Sdes) 1058238104Sdes])dnl end of ACX_MKDIR_ONE_ARG 1059238104Sdes 1060238104Sdesdnl Check for ioctlsocket function. works on mingw32 too. 1061238104SdesAC_DEFUN([ACX_FUNC_IOCTLSOCKET], 1062238104Sdes[ 1063238104Sdes# check ioctlsocket 1064238104SdesAC_MSG_CHECKING(for ioctlsocket) 1065238104SdesAC_LINK_IFELSE([AC_LANG_PROGRAM([ 1066238104Sdes#ifdef HAVE_WINSOCK2_H 1067238104Sdes#include <winsock2.h> 1068238104Sdes#endif 1069238104Sdes], [ 1070238104Sdes (void)ioctlsocket(0, 0, NULL); 1071238104Sdes])], [ 1072238104SdesAC_MSG_RESULT(yes) 1073238104SdesAC_DEFINE(HAVE_IOCTLSOCKET, 1, [if the function 'ioctlsocket' is available]) 1074238104Sdes],[AC_MSG_RESULT(no)]) 1075238104Sdes])dnl end of ACX_FUNC_IOCTLSOCKET 1076238104Sdes 1077238104Sdesdnl detect malloc and provide malloc compat prototype. 1078238104Sdesdnl $1: unique name for compat code 1079238104SdesAC_DEFUN([ACX_FUNC_MALLOC], 1080238104Sdes[ 1081238104Sdes AC_MSG_CHECKING([for GNU libc compatible malloc]) 1082238104Sdes AC_RUN_IFELSE([AC_LANG_PROGRAM( 1083238104Sdes[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H 1084238104Sdes#include <stdlib.h> 1085238104Sdes#else 1086238104Sdeschar *malloc (); 1087238104Sdes#endif 1088238104Sdes]], [ if(malloc(0) != 0) return 1;]) 1089238104Sdes], 1090238104Sdes [AC_MSG_RESULT([no]) 1091238104Sdes AC_LIBOBJ(malloc) 1092238104Sdes AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] , 1093238104Sdes [AC_MSG_RESULT([yes]) 1094238104Sdes AC_DEFINE([HAVE_MALLOC], 1, [If have GNU libc compatible malloc])], 1095238104Sdes [AC_MSG_RESULT([no (crosscompile)]) 1096238104Sdes AC_LIBOBJ(malloc) 1097238104Sdes AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] ) 1098238104Sdes]) 1099238104Sdes 1100238104Sdesdnl Define fallback for fseeko and ftello if needed. 1101238104SdesAC_DEFUN([AHX_CONFIG_FSEEKO], 1102238104Sdes[ 1103238104Sdes#ifndef HAVE_FSEEKO 1104238104Sdes#define fseeko fseek 1105238104Sdes#define ftello ftell 1106238104Sdes#endif /* HAVE_FSEEKO */ 1107238104Sdes]) 1108238104Sdes 1109238104Sdesdnl Define RAND_MAX if not defined 1110238104SdesAC_DEFUN([AHX_CONFIG_RAND_MAX], 1111238104Sdes[ 1112238104Sdes#ifndef RAND_MAX 1113238104Sdes#define RAND_MAX 2147483647 1114238104Sdes#endif 1115238104Sdes]) 1116238104Sdes 1117238104Sdesdnl Define MAXHOSTNAMELEN if not defined 1118238104SdesAC_DEFUN([AHX_CONFIG_MAXHOSTNAMELEN], 1119238104Sdes[ 1120238104Sdes#ifndef MAXHOSTNAMELEN 1121238104Sdes#define MAXHOSTNAMELEN 256 1122238104Sdes#endif 1123238104Sdes]) 1124238104Sdes 1125238104Sdesdnl Define IPV6_MIN_MTU if not defined 1126238104SdesAC_DEFUN([AHX_CONFIG_IPV6_MIN_MTU], 1127238104Sdes[ 1128238104Sdes#ifndef IPV6_MIN_MTU 1129238104Sdes#define IPV6_MIN_MTU 1280 1130238104Sdes#endif /* IPV6_MIN_MTU */ 1131238104Sdes]) 1132238104Sdes 1133238104Sdesdnl provide snprintf, vsnprintf compat prototype 1134238104Sdesdnl $1: unique name for compat code 1135238104SdesAC_DEFUN([AHX_CONFIG_SNPRINTF], 1136238104Sdes[ 1137238104Sdes#ifndef HAVE_SNPRINTF 1138238104Sdes#define snprintf snprintf_$1 1139238104Sdes#define vsnprintf vsnprintf_$1 1140238104Sdes#include <stdarg.h> 1141238104Sdesint snprintf (char *str, size_t count, const char *fmt, ...); 1142238104Sdesint vsnprintf (char *str, size_t count, const char *fmt, va_list arg); 1143238104Sdes#endif /* HAVE_SNPRINTF */ 1144238104Sdes]) 1145238104Sdes 1146238104Sdesdnl provide inet_pton compat prototype. 1147238104Sdesdnl $1: unique name for compat code 1148238104SdesAC_DEFUN([AHX_CONFIG_INET_PTON], 1149238104Sdes[ 1150238104Sdes#ifndef HAVE_INET_PTON 1151238104Sdes#define inet_pton inet_pton_$1 1152238104Sdesint inet_pton(int af, const char* src, void* dst); 1153238104Sdes#endif /* HAVE_INET_PTON */ 1154238104Sdes]) 1155238104Sdes 1156238104Sdesdnl provide inet_ntop compat prototype. 1157238104Sdesdnl $1: unique name for compat code 1158238104SdesAC_DEFUN([AHX_CONFIG_INET_NTOP], 1159238104Sdes[ 1160238104Sdes#ifndef HAVE_INET_NTOP 1161238104Sdes#define inet_ntop inet_ntop_$1 1162238104Sdesconst char *inet_ntop(int af, const void *src, char *dst, size_t size); 1163238104Sdes#endif 1164238104Sdes]) 1165238104Sdes 1166238104Sdesdnl provide inet_aton compat prototype. 1167238104Sdesdnl $1: unique name for compat code 1168238104SdesAC_DEFUN([AHX_CONFIG_INET_ATON], 1169238104Sdes[ 1170238104Sdes#ifndef HAVE_INET_ATON 1171238104Sdes#define inet_aton inet_aton_$1 1172238104Sdesint inet_aton(const char *cp, struct in_addr *addr); 1173238104Sdes#endif 1174238104Sdes]) 1175238104Sdes 1176238104Sdesdnl provide memmove compat prototype. 1177238104Sdesdnl $1: unique name for compat code 1178238104SdesAC_DEFUN([AHX_CONFIG_MEMMOVE], 1179238104Sdes[ 1180238104Sdes#ifndef HAVE_MEMMOVE 1181238104Sdes#define memmove memmove_$1 1182238104Sdesvoid *memmove(void *dest, const void *src, size_t n); 1183238104Sdes#endif 1184238104Sdes]) 1185238104Sdes 1186238104Sdesdnl provide strlcat compat prototype. 1187238104Sdesdnl $1: unique name for compat code 1188238104SdesAC_DEFUN([AHX_CONFIG_STRLCAT], 1189238104Sdes[ 1190238104Sdes#ifndef HAVE_STRLCAT 1191238104Sdes#define strlcat strlcat_$1 1192238104Sdessize_t strlcat(char *dst, const char *src, size_t siz); 1193238104Sdes#endif 1194238104Sdes]) 1195238104Sdes 1196238104Sdesdnl provide strlcpy compat prototype. 1197238104Sdesdnl $1: unique name for compat code 1198238104SdesAC_DEFUN([AHX_CONFIG_STRLCPY], 1199238104Sdes[ 1200238104Sdes#ifndef HAVE_STRLCPY 1201238104Sdes#define strlcpy strlcpy_$1 1202238104Sdessize_t strlcpy(char *dst, const char *src, size_t siz); 1203238104Sdes#endif 1204238104Sdes]) 1205238104Sdes 1206238104Sdesdnl provide gmtime_r compat prototype. 1207238104Sdesdnl $1: unique name for compat code 1208238104SdesAC_DEFUN([AHX_CONFIG_GMTIME_R], 1209238104Sdes[ 1210238104Sdes#ifndef HAVE_GMTIME_R 1211238104Sdes#define gmtime_r gmtime_r_$1 1212238104Sdesstruct tm *gmtime_r(const time_t *timep, struct tm *result); 1213238104Sdes#endif 1214238104Sdes]) 1215238104Sdes 1216238104Sdesdnl provide w32 compat definition for sleep 1217238104SdesAC_DEFUN([AHX_CONFIG_W32_SLEEP], 1218238104Sdes[ 1219266114Sdes#if !defined(HAVE_SLEEP) || defined(HAVE_WINDOWS_H) 1220238104Sdes#define sleep(x) Sleep((x)*1000) /* on win32 */ 1221238104Sdes#endif /* HAVE_SLEEP */ 1222238104Sdes]) 1223238104Sdes 1224238104Sdesdnl provide w32 compat definition for usleep 1225238104SdesAC_DEFUN([AHX_CONFIG_W32_USLEEP], 1226238104Sdes[ 1227238104Sdes#ifndef HAVE_USLEEP 1228238104Sdes#define usleep(x) Sleep((x)/1000 + 1) /* on win32 */ 1229238104Sdes#endif /* HAVE_USLEEP */ 1230238104Sdes]) 1231238104Sdes 1232238104Sdesdnl provide w32 compat definition for random 1233238104SdesAC_DEFUN([AHX_CONFIG_W32_RANDOM], 1234238104Sdes[ 1235238104Sdes#ifndef HAVE_RANDOM 1236238104Sdes#define random rand /* on win32, for tests only (bad random) */ 1237238104Sdes#endif /* HAVE_RANDOM */ 1238238104Sdes]) 1239238104Sdes 1240238104Sdesdnl provide w32 compat definition for srandom 1241238104SdesAC_DEFUN([AHX_CONFIG_W32_SRANDOM], 1242238104Sdes[ 1243238104Sdes#ifndef HAVE_SRANDOM 1244238104Sdes#define srandom(x) srand(x) /* on win32, for tests only (bad random) */ 1245238104Sdes#endif /* HAVE_SRANDOM */ 1246238104Sdes]) 1247238104Sdes 1248238104Sdesdnl provide w32 compat definition for FD_SET_T 1249238104SdesAC_DEFUN([AHX_CONFIG_W32_FD_SET_T], 1250238104Sdes[ 1251238104Sdes/* detect if we need to cast to unsigned int for FD_SET to avoid warnings */ 1252238104Sdes#ifdef HAVE_WINSOCK2_H 1253238104Sdes#define FD_SET_T (u_int) 1254238104Sdes#else 1255238104Sdes#define FD_SET_T 1256238104Sdes#endif 1257238104Sdes]) 1258238104Sdes 1259238104Sdesdnl Remove an extension flag from CFLAGS, define replacement to be made. 1260238104Sdesdnl Used by ACX_STRIP_EXT_FLAGS. 1261238104Sdesdnl $1: the name of the flag, for example -D_GNU_SOURCE. 1262238104SdesAC_DEFUN([ACX_CFLAGS_STRIP], 1263238104Sdes[ 1264238104Sdes if echo $CFLAGS | grep " $1" >/dev/null 2>&1; then 1265238104Sdes CFLAGS="`echo $CFLAGS | sed -e 's/ $1//g'`" 1266238104Sdes AC_DEFINE(m4_bpatsubst(OMITTED_$1,[[-=]],_), 1, Put $1 define in config.h) 1267238104Sdes fi 1268238104Sdes]) 1269238104Sdes 1270238104Sdesdnl Remove EXT flags from the CFLAGS and set them to be defined in config.h 1271238104Sdesdnl use with ACX_DETERMINE_EXT_FLAGS. 1272238104SdesAC_DEFUN([ACX_STRIP_EXT_FLAGS], 1273238104Sdes[ 1274238104Sdes AC_MSG_NOTICE([Stripping extension flags...]) 1275238104Sdes ACX_CFLAGS_STRIP(-D_GNU_SOURCE) 1276238104Sdes ACX_CFLAGS_STRIP(-D_BSD_SOURCE) 1277238104Sdes ACX_CFLAGS_STRIP(-D__EXTENSIONS__) 1278238104Sdes ACX_CFLAGS_STRIP(-D_POSIX_C_SOURCE=200112) 1279238104Sdes ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE=600) 1280238104Sdes ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE_EXTENDED=1) 1281238104Sdes ACX_CFLAGS_STRIP(-D_ALL_SOURCE) 1282238104Sdes ACX_CFLAGS_STRIP(-D_LARGEFILE_SOURCE=1) 1283238104Sdes]) dnl End of ACX_STRIP_EXT_FLAGS 1284238104Sdes 1285238104Sdesdnl define one omitted flag for config.h 1286238104Sdesdnl $1: flag name. -D_GNU_SOURCE 1287238104Sdesdnl $2: replacement define. _GNU_SOURCE 1288238104Sdesdnl $3: define value, 1 1289238104SdesAC_DEFUN([AHX_CONFIG_FLAG_OMITTED], 1290238104Sdes[#if defined($1) && !defined($2) 1291238104Sdes#define $2 $3 1292238104Sdes[#]endif ]) 1293238104Sdes 1294238104Sdesdnl Wrapper for AHX_CONFIG_FLAG_OMITTED for -D style flags 1295238104Sdesdnl $1: the -DNAME or -DNAME=value string. 1296238104SdesAC_DEFUN([AHX_CONFIG_FLAG_EXT], 1297238104Sdes[AHX_CONFIG_FLAG_OMITTED(m4_bpatsubst(OMITTED_$1,[[-=]],_),m4_bpatsubst(m4_bpatsubst($1,-D,),=.*$,),m4_if(m4_bregexp($1,=),-1,1,m4_bpatsubst($1,^.*=,))) 1298238104Sdes]) 1299238104Sdes 1300238104Sdesdnl config.h part to define omitted cflags, use with ACX_STRIP_EXT_FLAGS. 1301238104SdesAC_DEFUN([AHX_CONFIG_EXT_FLAGS], 1302238104Sdes[AHX_CONFIG_FLAG_EXT(-D_GNU_SOURCE) 1303238104SdesAHX_CONFIG_FLAG_EXT(-D_BSD_SOURCE) 1304238104SdesAHX_CONFIG_FLAG_EXT(-D__EXTENSIONS__) 1305238104SdesAHX_CONFIG_FLAG_EXT(-D_POSIX_C_SOURCE=200112) 1306238104SdesAHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE=600) 1307238104SdesAHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE_EXTENDED=1) 1308238104SdesAHX_CONFIG_FLAG_EXT(-D_ALL_SOURCE) 1309238104SdesAHX_CONFIG_FLAG_EXT(-D_LARGEFILE_SOURCE=1) 1310238104Sdes]) 1311238104Sdes 1312238104Sdesdnl check if memcmp is using signed characters and replace if so. 1313238104SdesAC_DEFUN([ACX_CHECK_MEMCMP_SIGNED], 1314238104Sdes[AC_MSG_CHECKING([if memcmp compares unsigned]) 1315238104SdesAC_RUN_IFELSE([AC_LANG_SOURCE([[ 1316238104Sdes#include <stdio.h> 1317238104Sdes#include <stdlib.h> 1318238104Sdes#include <string.h> 1319238104Sdesint main(void) 1320238104Sdes{ 1321238104Sdes char a = 255, b = 0; 1322238104Sdes if(memcmp(&a, &b, 1) < 0) 1323238104Sdes return 1; 1324238104Sdes return 0; 1325238104Sdes} 1326238104Sdes]])], [AC_MSG_RESULT([yes]) ], 1327238104Sdes[ AC_MSG_RESULT([no]) 1328238104Sdes AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes]) 1329238104Sdes AC_LIBOBJ([memcmp]) 1330238104Sdes], [ AC_MSG_RESULT([cross-compile no]) 1331238104Sdes AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes]) 1332238104Sdes AC_LIBOBJ([memcmp]) 1333238104Sdes]) ]) 1334238104Sdes 1335238104Sdesdnl define memcmp to its replacement, pass unique id for program as arg 1336238104SdesAC_DEFUN([AHX_MEMCMP_BROKEN], [ 1337238104Sdes#ifdef MEMCMP_IS_BROKEN 1338238104Sdes#include "compat/memcmp.h" 1339238104Sdes#define memcmp memcmp_$1 1340238104Sdesint memcmp(const void *x, const void *y, size_t n); 1341238104Sdes#endif 1342238104Sdes]) 1343238104Sdes 1344238104Sdesdnl ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family 1345238104SdesAC_DEFUN([ACX_CHECK_SS_FAMILY], 1346238104Sdes[AC_CHECK_MEMBER([struct sockaddr_storage.ss_family], [], [ 1347238104Sdes AC_CHECK_MEMBER([struct sockaddr_storage.__ss_family], [ 1348238104Sdes AC_DEFINE([ss_family], [__ss_family], [Fallback member name for socket family in struct sockaddr_storage]) 1349238104Sdes ],, [AC_INCLUDES_DEFAULT 1350238104Sdes#ifdef HAVE_NETINET_IN_H 1351238104Sdes#include <netinet/in.h> 1352238104Sdes#endif 1353238104Sdes#ifdef HAVE_SYS_SOCKET_H 1354238104Sdes#include <sys/socket.h> 1355238104Sdes#endif 1356238104Sdes#ifdef HAVE_NETDB_H 1357238104Sdes#include <netdb.h> 1358238104Sdes#endif 1359238104Sdes#ifdef HAVE_ARPA_INET_H 1360238104Sdes#include <arpa/inet.h> 1361238104Sdes#endif 1362238104Sdes ]) 1363238104Sdes], [AC_INCLUDES_DEFAULT 1364238104Sdes#ifdef HAVE_NETINET_IN_H 1365238104Sdes#include <netinet/in.h> 1366238104Sdes#endif 1367238104Sdes#ifdef HAVE_SYS_SOCKET_H 1368238104Sdes#include <sys/socket.h> 1369238104Sdes#endif 1370238104Sdes#ifdef HAVE_NETDB_H 1371238104Sdes#include <netdb.h> 1372238104Sdes#endif 1373238104Sdes#ifdef HAVE_ARPA_INET_H 1374238104Sdes#include <arpa/inet.h> 1375238104Sdes#endif 1376238104Sdes]) ]) 1377238104Sdes 1378238104Sdesdnl End of file 1379