acx_nlnetlabs.m4 revision 266114
1238106Sdes# acx_nlnetlabs.m4 - common macros for configure checks 2238106Sdes# Copyright 2009, Wouter Wijngaards, NLnet Labs. 3238106Sdes# BSD licensed. 4238106Sdes# 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. 11238106Sdes# 2012-02-09 Fix AHX_MEMCMP_BROKEN with undef in compat/memcmp.h. 12238106Sdes# 2012-01-20 Fix COMPILER_FLAGS_UNBOUND for gcc 4.6.2 assigned-not-used-warns. 13238106Sdes# 2011-12-05 Fix getaddrinfowithincludes on windows with fedora16 mingw32-gcc. 14238106Sdes# Fix ACX_MALLOC for redefined malloc error. 15238106Sdes# Fix GETADDRINFO_WITH_INCLUDES to add -lws2_32 16238106Sdes# 2011-11-10 Fix FLTO test to not drop a.out in current directory. 17238106Sdes# 2011-11-01 Fix FLTO test for llvm on Lion. 18238106Sdes# 2011-08-01 Fix nonblock test (broken at v13). 19238106Sdes# 2011-08-01 Fix autoconf 2.68 warnings 20238106Sdes# 2011-06-23 Add ACX_CHECK_FLTO to check -flto. 21238106Sdes# 2010-08-16 Fix FLAG_OMITTED for AS_TR_CPP changes in autoconf-2.66. 22238106Sdes# 2010-07-02 Add check for ss_family (for minix). 23238106Sdes# 2010-04-26 Fix to use CPPFLAGS for CHECK_COMPILER_FLAGS. 24238106Sdes# 2010-03-01 Fix RPATH using CONFIG_COMMANDS to run at the very end. 25238106Sdes# 2010-02-18 WITH_SSL outputs the LIBSSL_LDFLAGS, LIBS, CPPFLAGS seperate, -ldl 26238106Sdes# 2010-02-01 added ACX_CHECK_MEMCMP_SIGNED, AHX_MEMCMP_BROKEN 27238106Sdes# 2010-01-20 added AHX_COONFIG_STRLCAT 28238106Sdes# 2009-07-14 U_CHAR detection improved for windows crosscompile. 29238106Sdes# added ACX_FUNC_MALLOC 30238106Sdes# fixup some #if to #ifdef 31238106Sdes# NONBLOCKING test for mingw crosscompile. 32238106Sdes# 2009-07-13 added ACX_WITH_SSL_OPTIONAL 33238106Sdes# 2009-07-03 fixup LDFLAGS for empty ssl dir. 34238106Sdes# 35238106Sdes# Automates some of the checking constructs. Aims at portability for POSIX. 36238106Sdes# Documentation for functions is below. 37238106Sdes# 38238106Sdes# the following macro's are provided in this file: 39238106Sdes# (see below for details on each macro). 40238106Sdes# 41238106Sdes# ACX_ESCAPE_BACKSLASH - escape backslashes in var for C-preproc. 42238106Sdes# ACX_RSRC_VERSION - create windows resource version number. 43238106Sdes# ACX_CHECK_COMPILER_FLAG - see if cc supports a flag. 44238106Sdes# ACX_CHECK_ERROR_FLAGS - see which flag is -werror (used below). 45238106Sdes# ACX_CHECK_COMPILER_FLAG_NEEDED - see if flags make the code compile cleanly. 46238106Sdes# ACX_DEPFLAG - find cc dependency flags. 47238106Sdes# ACX_DETERMINE_EXT_FLAGS_UNBOUND - find out which flags enable BSD and POSIX. 48238106Sdes# ACX_CHECK_FORMAT_ATTRIBUTE - find cc printf format syntax. 49238106Sdes# ACX_CHECK_UNUSED_ATTRIBUTE - find cc variable unused syntax. 50238106Sdes# ACX_CHECK_FLTO - see if cc supports -flto and use it if so. 51238106Sdes# ACX_LIBTOOL_C_ONLY - create libtool for C only, improved. 52238106Sdes# ACX_TYPE_U_CHAR - u_char type. 53238106Sdes# ACX_TYPE_RLIM_T - rlim_t type. 54238106Sdes# ACX_TYPE_SOCKLEN_T - socklen_t type. 55238106Sdes# ACX_TYPE_IN_ADDR_T - in_addr_t type. 56238106Sdes# ACX_TYPE_IN_PORT_T - in_port_t type. 57238106Sdes# ACX_ARG_RPATH - add --disable-rpath option. 58238106Sdes# ACX_WITH_SSL - add --with-ssl option, link -lcrypto. 59238106Sdes# ACX_WITH_SSL_OPTIONAL - add --with-ssl option, link -lcrypto, 60238106Sdes# where --without-ssl is also accepted 61238106Sdes# ACX_LIB_SSL - setup to link -lssl. 62238106Sdes# ACX_SYS_LARGEFILE - improved sys_largefile, fseeko, >2G files. 63238106Sdes# ACX_CHECK_GETADDRINFO_WITH_INCLUDES - find getaddrinfo, portably. 64238106Sdes# ACX_FUNC_DEPRECATED - see if func is deprecated. 65238106Sdes# ACX_CHECK_NONBLOCKING_BROKEN - see if nonblocking sockets really work. 66238106Sdes# ACX_MKDIR_ONE_ARG - determine mkdir(2) number of arguments. 67238106Sdes# ACX_FUNC_IOCTLSOCKET - find ioctlsocket, portably. 68238106Sdes# ACX_FUNC_MALLOC - check malloc, define replacement . 69238106Sdes# AHX_CONFIG_FORMAT_ATTRIBUTE - config.h text for format. 70238106Sdes# AHX_CONFIG_UNUSED_ATTRIBUTE - config.h text for unused. 71238106Sdes# AHX_CONFIG_FSEEKO - define fseeko, ftello fallback. 72238106Sdes# AHX_CONFIG_RAND_MAX - define RAND_MAX if needed. 73238106Sdes# AHX_CONFIG_MAXHOSTNAMELEN - define MAXHOSTNAMELEN if needed. 74238106Sdes# AHX_CONFIG_IPV6_MIN_MTU - define IPV6_MIN_MTU if needed. 75238106Sdes# AHX_CONFIG_SNPRINTF - snprintf compat prototype 76238106Sdes# AHX_CONFIG_INET_PTON - inet_pton compat prototype 77238106Sdes# AHX_CONFIG_INET_NTOP - inet_ntop compat prototype 78238106Sdes# AHX_CONFIG_INET_ATON - inet_aton compat prototype 79238106Sdes# AHX_CONFIG_MEMMOVE - memmove compat prototype 80238106Sdes# AHX_CONFIG_STRLCAT - strlcat compat prototype 81238106Sdes# AHX_CONFIG_STRLCPY - strlcpy compat prototype 82238106Sdes# AHX_CONFIG_GMTIME_R - gmtime_r compat prototype 83238106Sdes# AHX_CONFIG_W32_SLEEP - w32 compat for sleep 84238106Sdes# AHX_CONFIG_W32_USLEEP - w32 compat for usleep 85238106Sdes# AHX_CONFIG_W32_RANDOM - w32 compat for random 86238106Sdes# AHX_CONFIG_W32_SRANDOM - w32 compat for srandom 87238106Sdes# AHX_CONFIG_W32_FD_SET_T - w32 detection of FD_SET_T. 88238106Sdes# ACX_CFLAGS_STRIP - strip one flag from CFLAGS 89238106Sdes# ACX_STRIP_EXT_FLAGS - strip extension flags from CFLAGS 90238106Sdes# AHX_CONFIG_FLAG_OMITTED - define omitted flag 91238106Sdes# AHX_CONFIG_FLAG_EXT - define omitted extension flag 92238106Sdes# AHX_CONFIG_EXT_FLAGS - define the stripped extension flags 93238106Sdes# ACX_CHECK_MEMCMP_SIGNED - check if memcmp uses signed characters. 94238106Sdes# AHX_MEMCMP_BROKEN - replace memcmp func for CHECK_MEMCMP_SIGNED. 95238106Sdes# ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family 96238106Sdes# 97238106Sdes 98238106Sdesdnl Escape backslashes as \\, for C:\ paths, for the C preprocessor defines. 99238106Sdesdnl for example, ACX_ESCAPE_BACKSLASH($from_var, to_var) 100238106Sdesdnl $1: the text to change. 101238106Sdesdnl $2: the result. 102238106SdesAC_DEFUN([ACX_ESCAPE_BACKSLASH], [$2="`echo $1 | sed -e 's/\\\\/\\\\\\\\/g'`" 103238106Sdes]) 104238106Sdes 105238106Sdesdnl Calculate comma separated windows-resource numbers from package version. 106238106Sdesdnl Picks the first three(,0) or four numbers out of the name. 107238106Sdesdnl $1: variable for the result 108238106SdesAC_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/' `] 110238106Sdes]) 111238106Sdes 112238106Sdesdnl Routine to help check for compiler flags. 113238106Sdesdnl Checks if the compiler will accept the flag. 114238106Sdesdnl $1: the flag without a - in front, so g to check -g. 115238106Sdesdnl $2: executed if yes 116238106Sdesdnl $3: executed if no 117238106SdesAC_DEFUN([ACX_CHECK_COMPILER_FLAG], 118238106Sdes[ 119238106SdesAC_REQUIRE([AC_PROG_CC]) 120238106SdesAC_MSG_CHECKING(whether $CC supports -$1) 121238106Sdescache=`echo $1 | sed 'y%.=/+-%___p_%'` 122238106SdesAC_CACHE_VAL(cv_prog_cc_flag_$cache, 123238106Sdes[ 124266114Sdesecho 'void f(void){}' >conftest.c 125238106Sdesif test -z "`$CC $CPPFLAGS $CFLAGS -$1 -c conftest.c 2>&1`"; then 126238106Sdeseval "cv_prog_cc_flag_$cache=yes" 127238106Sdeselse 128238106Sdeseval "cv_prog_cc_flag_$cache=no" 129238106Sdesfi 130238106Sdesrm -f conftest conftest.o conftest.c 131238106Sdes]) 132238106Sdesif eval "test \"`echo '$cv_prog_cc_flag_'$cache`\" = yes"; then 133238106SdesAC_MSG_RESULT(yes) 134238106Sdes: 135238106Sdes$2 136238106Sdeselse 137238106SdesAC_MSG_RESULT(no) 138238106Sdes: 139238106Sdes$3 140238106Sdesfi 141238106Sdes]) 142238106Sdes 143238106Sdesdnl setup flags for ACX_CHECK_COMPILER_FLAG_NEEDED 144238106Sdesdnl ERRFLAG: result, compiler flag to turn warnings into errors 145238106SdesAC_DEFUN([ACX_CHECK_ERROR_FLAGS], 146238106Sdes[ 147238106SdesACX_CHECK_COMPILER_FLAG(Werror, [ERRFLAG="-Werror"], [ERRFLAG="-errwarn"]) 148238106SdesACX_CHECK_COMPILER_FLAG(Wall, [ERRFLAG="$ERRFLAG -Wall"], 149238106Sdes [ERRFLAG="$ERRFLAG -errfmt"]) 150238106Sdes]) 151238106Sdes 152238106Sdesdnl Routine to help check for needed compiler flags. 153238106Sdesdnl $1: flags for CC 154238106Sdesdnl $2: the includes and code 155238106Sdesdnl $3: if the given code only compiles with the flag, execute argument 3 156238106Sdesdnl $4: if the given code compiles without the flag, execute argument 4 157238106Sdesdnl $5: with and without flag the compile fails, execute argument 5. 158238106SdesAC_DEFUN([ACX_CHECK_COMPILER_FLAG_NEEDED], 159238106Sdes[ 160238106SdesAC_REQUIRE([AC_PROG_CC]) 161238106SdesAC_REQUIRE([ACX_CHECK_ERROR_FLAGS]) 162238106SdesAC_MSG_CHECKING(whether we need $1 as a flag for $CC) 163238106Sdescache=AS_TR_SH($1) 164238106Sdesdnl cache=`echo $1 | sed 'y%.=/+- %___p__%'` 165238106SdesAC_CACHE_VAL(cv_prog_cc_flag_needed_$cache, 166238106Sdes[ 167238106Sdesecho '$2' > conftest.c 168238106Sdesecho 'void f(){}' >>conftest.c 169238106Sdesif test -z "`$CC $CPPFLAGS $CFLAGS $ERRFLAG -c conftest.c 2>&1`"; then 170238106Sdeseval "cv_prog_cc_flag_needed_$cache=no" 171238106Sdeselse 172238106Sdes[ 173238106Sdesif test -z "`$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`"; then 174238106Sdeseval "cv_prog_cc_flag_needed_$cache=yes" 175238106Sdeselse 176238106Sdeseval "cv_prog_cc_flag_needed_$cache=fail" 177238106Sdes#echo 'Test with flag fails too!' 178238106Sdes#cat conftest.c 179238106Sdes#echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1" 180238106Sdes#echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1` 181238106Sdes#exit 1 182238106Sdesfi 183238106Sdes] 184238106Sdesfi 185238106Sdesrm -f conftest conftest.c conftest.o 186238106Sdes]) 187238106Sdesif eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = yes"; then 188238106SdesAC_MSG_RESULT(yes) 189238106Sdes: 190238106Sdes$3 191238106Sdeselse 192238106Sdesif eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = no"; then 193238106SdesAC_MSG_RESULT(no) 194238106Sdes#echo 'Test with flag is no!' 195238106Sdes#cat conftest.c 196238106Sdes#echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1" 197238106Sdes#echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1` 198238106Sdes#exit 1 199238106Sdes: 200238106Sdes$4 201238106Sdeselse 202238106SdesAC_MSG_RESULT(failed) 203238106Sdes: 204238106Sdes$5 205238106Sdesfi 206238106Sdesfi 207238106Sdes]) 208238106Sdes 209238106Sdesdnl Check for CC dependency flag 210238106Sdesdnl DEPFLAG: set to flag that generates dependencies. 211238106SdesAC_DEFUN([ACX_DEPFLAG], 212238106Sdes[ 213238106SdesAC_MSG_CHECKING([$CC dependency flag]) 214238106Sdesecho 'void f(){}' >conftest.c 215238106Sdesif test "`$CC -MM conftest.c 2>&1`" = "conftest.o: conftest.c"; then 216238106Sdes DEPFLAG="-MM" 217238106Sdeselse 218238106Sdes if test "`$CC -xM1 conftest.c 2>&1`" = "conftest.o: conftest.c"; then 219238106Sdes DEPFLAG="-xM1" 220238106Sdes else 221238106Sdes DEPFLAG="-MM" # dunno do something 222238106Sdes fi 223238106Sdesfi 224238106SdesAC_MSG_RESULT($DEPFLAG) 225238106Sdesrm -f conftest.c 226238106SdesAC_SUBST(DEPFLAG) 227238106Sdes]) 228238106Sdes 229238106Sdesdnl Determine flags that gives POSIX and BSD functionality. 230238106Sdesdnl CFLAGS is modified for the result. 231238106SdesAC_DEFUN([ACX_DETERMINE_EXT_FLAGS_UNBOUND], 232238106Sdes[ 233238106SdesACX_CHECK_COMPILER_FLAG(std=c99, [C99FLAG="-std=c99"]) 234238106SdesACX_CHECK_COMPILER_FLAG(xc99, [C99FLAG="-xc99"]) 235238106Sdes 236238106SdesAC_CHECK_HEADERS([getopt.h time.h],,, [AC_INCLUDES_DEFAULT]) 237238106Sdes 238238106SdesACX_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, 239238106Sdes[ 240238106Sdes#include "confdefs.h" 241238106Sdes#include <stdlib.h> 242238106Sdes#include <ctype.h> 243238106Sdes#include <sys/time.h> 244238106Sdes#ifdef HAVE_TIME_H 245238106Sdes#include <time.h> 246238106Sdes#endif 247238106Sdes#include <unistd.h> 248238106Sdes#include <netdb.h> 249238106Sdes#ifdef HAVE_GETOPT_H 250238106Sdes#include <getopt.h> 251238106Sdes#endif 252238106Sdes 253238106Sdesint test() { 254238106Sdes int a; 255238106Sdes char **opts = NULL; 256238106Sdes struct timeval tv; 257238106Sdes char *t; 258238106Sdes time_t time = 0; 259238106Sdes char *buf = NULL; 260238106Sdes const char* str = NULL; 261238106Sdes struct msghdr msg; 262238106Sdes msg.msg_control = 0; 263238106Sdes t = ctime_r(&time, buf); 264238106Sdes tv.tv_usec = 10; 265238106Sdes srandom(32); 266238106Sdes a = getopt(2, opts, "a"); 267238106Sdes a = isascii(32); 268238106Sdes str = gai_strerror(0); 269238106Sdes if(str && t && tv.tv_usec && msg.msg_control) 270238106Sdes a = 0; 271238106Sdes return a; 272238106Sdes} 273238106Sdes], [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"]) 274238106Sdes 275238106SdesACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE, 276238106Sdes[ 277238106Sdes#include "confdefs.h" 278238106Sdes#include <stdlib.h> 279238106Sdes#include <ctype.h> 280238106Sdes#include <sys/time.h> 281238106Sdes#ifdef HAVE_TIME_H 282238106Sdes#include <time.h> 283238106Sdes#endif 284238106Sdes#include <unistd.h> 285238106Sdes#include <netdb.h> 286238106Sdes#ifdef HAVE_GETOPT_H 287238106Sdes#include <getopt.h> 288238106Sdes#endif 289238106Sdes 290238106Sdesint test() { 291238106Sdes int a; 292238106Sdes char **opts = NULL; 293238106Sdes struct timeval tv; 294238106Sdes char *t; 295238106Sdes time_t time = 0; 296238106Sdes char *buf = NULL; 297238106Sdes const char* str = NULL; 298238106Sdes struct msghdr msg; 299238106Sdes msg.msg_control = 0; 300238106Sdes t = ctime_r(&time, buf); 301238106Sdes tv.tv_usec = 10; 302238106Sdes srandom(32); 303238106Sdes a = getopt(2, opts, "a"); 304238106Sdes a = isascii(32); 305238106Sdes str = gai_strerror(0); 306238106Sdes if(str && t && tv.tv_usec && msg.msg_control) 307238106Sdes a = 0; 308238106Sdes return a; 309238106Sdes} 310238106Sdes], [CFLAGS="$CFLAGS $C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE"]) 311238106Sdes 312238106SdesACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG, 313238106Sdes[ 314238106Sdes#include <stdbool.h> 315238106Sdes#include <ctype.h> 316238106Sdesint test() { 317238106Sdes int a = 0; 318238106Sdes return a; 319238106Sdes} 320238106Sdes], [CFLAGS="$CFLAGS $C99FLAG"]) 321238106Sdes 322238106SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_BSD_SOURCE, 323238106Sdes[ 324238106Sdes#include <ctype.h> 325238106Sdes 326238106Sdesint test() { 327238106Sdes int a; 328238106Sdes a = isascii(32); 329238106Sdes return a; 330238106Sdes} 331238106Sdes], [CFLAGS="$CFLAGS -D_BSD_SOURCE"]) 332238106Sdes 333238106SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE, 334238106Sdes[ 335238106Sdes#include <netinet/in.h> 336238106Sdes 337238106Sdesint test() { 338238106Sdes struct in6_pktinfo inf; 339238106Sdes int a = (int)sizeof(inf); 340238106Sdes return a; 341238106Sdes} 342238106Sdes], [CFLAGS="$CFLAGS -D_GNU_SOURCE"]) 343238106Sdes 344238106Sdes# check again for GNU_SOURCE for setresgid. May fail if setresgid 345238106Sdes# is not available at all. -D_FRSRESGID is to make this check unique. 346238106Sdes# otherwise we would get the previous cached result. 347238106SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE -D_FRSRESGID, 348238106Sdes[ 349238106Sdes#include <unistd.h> 350238106Sdes 351238106Sdesint test() { 352238106Sdes int a = setresgid(0,0,0); 353238106Sdes a = setresuid(0,0,0); 354238106Sdes return a; 355238106Sdes} 356238106Sdes], [CFLAGS="$CFLAGS -D_GNU_SOURCE"]) 357238106Sdes 358238106SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D_POSIX_C_SOURCE=200112, 359238106Sdes[ 360238106Sdes#include "confdefs.h" 361238106Sdes#ifdef HAVE_TIME_H 362238106Sdes#include <time.h> 363238106Sdes#endif 364238106Sdes#include <netdb.h> 365238106Sdes 366238106Sdesint test() { 367238106Sdes int a = 0; 368238106Sdes char *t; 369238106Sdes time_t time = 0; 370238106Sdes char *buf = NULL; 371238106Sdes const char* str = NULL; 372238106Sdes t = ctime_r(&time, buf); 373238106Sdes str = gai_strerror(0); 374238106Sdes if(t && str) 375238106Sdes a = 0; 376238106Sdes return a; 377238106Sdes} 378238106Sdes], [CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112"]) 379238106Sdes 380238106SdesACX_CHECK_COMPILER_FLAG_NEEDED(-D__EXTENSIONS__, 381238106Sdes[ 382238106Sdes#include "confdefs.h" 383238106Sdes#include <stdlib.h> 384238106Sdes#include <ctype.h> 385238106Sdes#include <sys/time.h> 386238106Sdes#ifdef HAVE_TIME_H 387238106Sdes#include <time.h> 388238106Sdes#endif 389238106Sdes#include <unistd.h> 390238106Sdes#ifdef HAVE_GETOPT_H 391238106Sdes#include <getopt.h> 392238106Sdes#endif 393238106Sdes 394238106Sdesint test() { 395238106Sdes int a; 396238106Sdes char **opts = NULL; 397238106Sdes struct timeval tv; 398238106Sdes tv.tv_usec = 10; 399238106Sdes srandom(32); 400238106Sdes a = getopt(2, opts, "a"); 401238106Sdes a = isascii(32); 402238106Sdes if(tv.tv_usec) 403238106Sdes a = 0; 404238106Sdes return a; 405238106Sdes} 406238106Sdes], [CFLAGS="$CFLAGS -D__EXTENSIONS__"]) 407238106Sdes 408238106Sdes])dnl End of ACX_DETERMINE_EXT_FLAGS_UNBOUND 409238106Sdes 410238106Sdesdnl Check if CC supports -flto. 411238106Sdesdnl in a way that supports clang and suncc (that flag does something else, 412238106Sdesdnl 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 ]) 429238106Sdes]) 430238106Sdes 431238106Sdesdnl Check the printf-format attribute (if any) 432238106Sdesdnl result in HAVE_ATTR_FORMAT. 433238106Sdesdnl Make sure you also include the AHX_CONFIG_FORMAT_ATTRIBUTE. 434238106SdesAC_DEFUN([ACX_CHECK_FORMAT_ATTRIBUTE], 435238106Sdes[AC_REQUIRE([AC_PROG_CC]) 436238106SdesAC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute) 437238106SdesAC_CACHE_VAL(ac_cv_c_format_attribute, 438238106Sdes[ac_cv_c_format_attribute=no 439238106SdesAC_TRY_COMPILE( 440238106Sdes[#include <stdio.h> 441238106Sdesvoid f (char *format, ...) __attribute__ ((format (printf, 1, 2))); 442238106Sdesvoid (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2))); 443238106Sdes], [ 444238106Sdes f ("%s", "str"); 445238106Sdes], 446238106Sdes[ac_cv_c_format_attribute="yes"], 447238106Sdes[ac_cv_c_format_attribute="no"]) 448238106Sdes]) 449238106Sdes 450238106SdesAC_MSG_RESULT($ac_cv_c_format_attribute) 451238106Sdesif test $ac_cv_c_format_attribute = yes; then 452238106Sdes AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute]) 453238106Sdesfi 454238106Sdes])dnl End of ACX_CHECK_FORMAT_ATTRIBUTE 455238106Sdes 456238106Sdesdnl Setup ATTR_FORMAT config.h parts. 457238106Sdesdnl make sure you call ACX_CHECK_FORMAT_ATTRIBUTE also. 458238106SdesAC_DEFUN([AHX_CONFIG_FORMAT_ATTRIBUTE], 459238106Sdes[ 460238106Sdes#ifdef HAVE_ATTR_FORMAT 461238106Sdes# define ATTR_FORMAT(archetype, string_index, first_to_check) \ 462238106Sdes __attribute__ ((format (archetype, string_index, first_to_check))) 463238106Sdes#else /* !HAVE_ATTR_FORMAT */ 464238106Sdes# define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */ 465238106Sdes#endif /* !HAVE_ATTR_FORMAT */ 466238106Sdes]) 467238106Sdes 468238106Sdesdnl Check how to mark function arguments as unused. 469238106Sdesdnl result in HAVE_ATTR_UNUSED. 470238106Sdesdnl Make sure you include AHX_CONFIG_UNUSED_ATTRIBUTE also. 471238106SdesAC_DEFUN([ACX_CHECK_UNUSED_ATTRIBUTE], 472238106Sdes[AC_REQUIRE([AC_PROG_CC]) 473238106SdesAC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute) 474238106SdesAC_CACHE_VAL(ac_cv_c_unused_attribute, 475238106Sdes[ac_cv_c_unused_attribute=no 476238106SdesAC_TRY_COMPILE( 477238106Sdes[#include <stdio.h> 478238106Sdesvoid f (char *u __attribute__((unused))); 479238106Sdes], [ 480238106Sdes f ("x"); 481238106Sdes], 482238106Sdes[ac_cv_c_unused_attribute="yes"], 483238106Sdes[ac_cv_c_unused_attribute="no"]) 484238106Sdes]) 485238106Sdes 486238106Sdesdnl Setup ATTR_UNUSED config.h parts. 487238106Sdesdnl make sure you call ACX_CHECK_UNUSED_ATTRIBUTE also. 488238106SdesAC_DEFUN([AHX_CONFIG_UNUSED_ATTRIBUTE], 489238106Sdes[ 490238106Sdes#if defined(DOXYGEN) 491238106Sdes# define ATTR_UNUSED(x) x 492238106Sdes#elif defined(__cplusplus) 493238106Sdes# define ATTR_UNUSED(x) 494238106Sdes#elif defined(HAVE_ATTR_UNUSED) 495238106Sdes# define ATTR_UNUSED(x) x __attribute__((unused)) 496238106Sdes#else /* !HAVE_ATTR_UNUSED */ 497238106Sdes# define ATTR_UNUSED(x) x 498238106Sdes#endif /* !HAVE_ATTR_UNUSED */ 499238106Sdes]) 500238106Sdes 501238106SdesAC_MSG_RESULT($ac_cv_c_unused_attribute) 502238106Sdesif test $ac_cv_c_unused_attribute = yes; then 503238106Sdes AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute]) 504238106Sdesfi 505238106Sdes])dnl 506238106Sdes 507238106Sdesdnl Pre-fun for ACX_LIBTOOL_C_ONLY 508238106SdesAC_DEFUN([ACX_LIBTOOL_C_PRE], [ 509238106Sdes# skip these tests, we do not need them. 510238106SdesAC_DEFUN([AC_PROG_F77], [:]) 511238106SdesAC_DEFUN([AC_PROG_FC], [:]) 512238106SdesAC_DEFUN([AC_PROG_CXX], [:]) 513238106SdesAC_DEFUN([AC_PROG_CXXCPP], [:]) 514238106SdesAC_DEFUN([AC_PROG_OBJC], [:]) 515238106SdesAC_DEFUN([AC_PROG_OBJCCPP], [:]) 516238106SdesAC_DEFUN([AC_LIBTOOL_CXX], [:]) 517238106SdesAC_DEFUN([AC_LIBTOOL_F77], [:]) 518238106Sdes# always use ./libtool unless override from commandline (libtool=mylibtool) 519238106Sdesif test -z "$libtool"; then 520238106Sdes libtool="./libtool" 521238106Sdesfi 522238106SdesAC_SUBST(libtool) 523238106Sdes# avoid libtool max commandline length test on systems that fork slowly. 524238106SdesAC_CANONICAL_HOST 525238106Sdesif echo "$host_os" | grep "sunos4" >/dev/null; then 526238106Sdes lt_cv_sys_max_cmd_len=32750; 527238106Sdesfi 528238106SdesAC_PATH_TOOL(AR, ar, [false]) 529238106Sdesif test $AR = false; then 530238106Sdes AC_MSG_ERROR([Cannot find 'ar', please extend PATH to include it]) 531238106Sdesfi 532238106Sdes]) 533238106Sdes 534238106Sdesdnl Perform libtool check, portably, only for C 535238106SdesAC_DEFUN([ACX_LIBTOOL_C_ONLY], [ 536238106Sdesdnl as a requirement so that is gets called before LIBTOOL 537238106Sdesdnl because libtools 'AC_REQUIRE' names are right after this one, before 538238106Sdesdnl this function contents. 539238106SdesAC_REQUIRE([ACX_LIBTOOL_C_PRE]) 540238106SdesAC_PROG_LIBTOOL 541238106Sdes]) 542238106Sdes 543238106Sdesdnl Detect if u_char type is defined, otherwise define it. 544238106SdesAC_DEFUN([ACX_TYPE_U_CHAR], 545238106Sdes[AC_CHECK_TYPE([u_char], , 546238106Sdes [AC_DEFINE([u_char], [unsigned char], [Define to 'unsigned char if not defined])], [ 547238106SdesAC_INCLUDES_DEFAULT 548238106Sdes#ifdef HAVE_WINSOCK2_H 549238106Sdes# include <winsock2.h> 550238106Sdes#endif 551238106Sdes]) ]) 552238106Sdes 553238106Sdesdnl Detect if rlim_t type is defined, otherwise define it. 554238106SdesAC_DEFUN([ACX_TYPE_RLIM_T], 555238106Sdes[AC_CHECK_TYPE(rlim_t, , 556238106Sdes [AC_DEFINE([rlim_t], [unsigned long], [Define to 'int' if not defined])], [ 557238106SdesAC_INCLUDES_DEFAULT 558238106Sdes#ifdef HAVE_SYS_RESOURCE_H 559238106Sdes# include <sys/resource.h> 560238106Sdes#endif 561238106Sdes]) ]) 562238106Sdes 563238106Sdesdnl Detect if socklen_t type is defined, otherwise define it. 564238106SdesAC_DEFUN([ACX_TYPE_SOCKLEN_T], 565238106Sdes[ 566238106SdesAC_CHECK_TYPE(socklen_t, , 567238106Sdes [AC_DEFINE([socklen_t], [int], [Define to 'int' if not defined])], [ 568238106SdesAC_INCLUDES_DEFAULT 569238106Sdes#ifdef HAVE_SYS_SOCKET_H 570238106Sdes# include <sys/socket.h> 571238106Sdes#endif 572238106Sdes#ifdef HAVE_WS2TCPIP_H 573238106Sdes# include <ws2tcpip.h> 574238106Sdes#endif 575238106Sdes]) ]) 576238106Sdes 577238106Sdesdnl Detect if in_addr_t type is defined, otherwise define it. 578238106SdesAC_DEFUN([ACX_TYPE_IN_ADDR_T], 579238106Sdes[ AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [ 580238106SdesAC_INCLUDES_DEFAULT 581238106Sdes#ifdef HAVE_SYS_TYPES_H 582238106Sdes# include <sys/types.h> 583238106Sdes#endif 584238106Sdes#ifdef HAVE_NETINET_IN_H 585238106Sdes# include <netinet/in.h> 586238106Sdes#endif 587238106Sdes]) ]) 588238106Sdes 589238106Sdesdnl Detect if in_port_t type is defined, otherwise define it. 590238106SdesAC_DEFUN([ACX_TYPE_IN_PORT_T], 591238106Sdes[ AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])], [ 592238106SdesAC_INCLUDES_DEFAULT 593238106Sdes#ifdef HAVE_SYS_TYPES_H 594238106Sdes# include <sys/types.h> 595238106Sdes#endif 596238106Sdes#ifdef HAVE_NETINET_IN_H 597238106Sdes# include <netinet/in.h> 598238106Sdes#endif 599238106Sdes]) ]) 600238106Sdes 601238106Sdesdnl Add option to disable the evil rpath. Check whether to use rpath or not. 602238106Sdesdnl Adds the --disable-rpath option. Uses trick to edit the ./libtool. 603238106SdesAC_DEFUN([ACX_ARG_RPATH], 604238106Sdes[ 605238106SdesAC_ARG_ENABLE(rpath, 606238106Sdes [ --disable-rpath disable hardcoded rpath (default=enabled)], 607238106Sdes enable_rpath=$enableval, enable_rpath=yes) 608238106Sdesif test "x$enable_rpath" = xno; then 609238106Sdes dnl AC_MSG_RESULT([Fixing libtool for -rpath problems.]) 610238106Sdes AC_CONFIG_COMMANDS([disable-rpath], [ 611238106Sdes sed < libtool > libtool-2 \ 612238106Sdes 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_RPATH_SED__ "/' 613238106Sdes mv libtool-2 libtool 614238106Sdes chmod 755 libtool 615238106Sdes libtool="./libtool" 616238106Sdes ]) 617238106Sdesfi 618238106Sdes]) 619238106Sdes 620238106Sdesdnl Add a -R to the RUNTIME_PATH. Only if rpath is enabled and it is 621238106Sdesdnl an absolute path. 622238106Sdesdnl $1: the pathname to add. 623238106SdesAC_DEFUN([ACX_RUNTIME_PATH_ADD], [ 624238106Sdes if test "x$enable_rpath" = xyes; then 625238106Sdes if echo "$1" | grep "^/" >/dev/null; then 626238106Sdes RUNTIME_PATH="$RUNTIME_PATH -R$1" 627238106Sdes fi 628238106Sdes fi 629238106Sdes]) 630238106Sdes 631238106Sdesdnl Common code for both ACX_WITH_SSL and ACX_WITH_SSL_OPTIONAL 632238106Sdesdnl Takes one argument; the withval checked in those 2 functions 633238106Sdesdnl sets up the environment for the given openssl path 634238106SdesAC_DEFUN([ACX_SSL_CHECKS], [ 635238106Sdes withval=$1 636238106Sdes if test x_$withval != x_no; then 637238106Sdes AC_MSG_CHECKING(for SSL) 638238106Sdes if test x_$withval = x_ -o x_$withval = x_yes; then 639238106Sdes withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr" 640238106Sdes fi 641238106Sdes for dir in $withval; do 642238106Sdes ssldir="$dir" 643238106Sdes if test -f "$dir/include/openssl/ssl.h"; then 644238106Sdes found_ssl="yes" 645238106Sdes AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.]) 646238106Sdes dnl assume /usr/include is already in the include-path. 647238106Sdes if test "$ssldir" != "/usr"; then 648238106Sdes CPPFLAGS="$CPPFLAGS -I$ssldir/include" 649238106Sdes LIBSSL_CPPFLAGS="$LIBSSL_CPPFLAGS -I$ssldir/include" 650238106Sdes fi 651238106Sdes break; 652238106Sdes fi 653238106Sdes done 654238106Sdes if test x_$found_ssl != x_yes; then 655238106Sdes AC_MSG_ERROR(Cannot find the SSL libraries in $withval) 656238106Sdes else 657238106Sdes AC_MSG_RESULT(found in $ssldir) 658238106Sdes HAVE_SSL=yes 659238106Sdes dnl assume /usr is already in the lib and dynlib paths. 660238106Sdes if test "$ssldir" != "/usr" -a "$ssldir" != ""; then 661238106Sdes LDFLAGS="$LDFLAGS -L$ssldir/lib" 662238106Sdes LIBSSL_LDFLAGS="$LIBSSL_LDFLAGS -L$ssldir/lib" 663238106Sdes ACX_RUNTIME_PATH_ADD([$ssldir/lib]) 664238106Sdes fi 665238106Sdes 666238106Sdes AC_MSG_CHECKING([for HMAC_CTX_init in -lcrypto]) 667238106Sdes LIBS="$LIBS -lcrypto" 668238106Sdes LIBSSL_LIBS="$LIBSSL_LIBS -lcrypto" 669238106Sdes AC_TRY_LINK(, [ 670238106Sdes int HMAC_CTX_init(void); 671238106Sdes (void)HMAC_CTX_init(); 672238106Sdes ], [ 673238106Sdes AC_MSG_RESULT(yes) 674238106Sdes AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 675238106Sdes [If you have HMAC_CTX_init]) 676238106Sdes ], [ 677238106Sdes AC_MSG_RESULT(no) 678238106Sdes # check if -lwsock32 or -lgdi32 are needed. 679238106Sdes BAKLIBS="$LIBS" 680238106Sdes BAKSSLLIBS="$LIBSSL_LIBS" 681238106Sdes LIBS="$LIBS -lgdi32" 682238106Sdes LIBSSL_LIBS="$LIBSSL_LIBS -lgdi32" 683238106Sdes AC_MSG_CHECKING([if -lcrypto needs -lgdi32]) 684238106Sdes AC_TRY_LINK([], [ 685238106Sdes int HMAC_CTX_init(void); 686238106Sdes (void)HMAC_CTX_init(); 687238106Sdes ],[ 688238106Sdes AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 689238106Sdes [If you have HMAC_CTX_init]) 690238106Sdes AC_MSG_RESULT(yes) 691238106Sdes ],[ 692238106Sdes AC_MSG_RESULT(no) 693238106Sdes LIBS="$BAKLIBS" 694238106Sdes LIBSSL_LIBS="$BAKSSLLIBS" 695238106Sdes LIBS="$LIBS -ldl" 696238106Sdes LIBSSL_LIBS="$LIBSSL_LIBS -ldl" 697238106Sdes AC_MSG_CHECKING([if -lcrypto needs -ldl]) 698238106Sdes AC_TRY_LINK([], [ 699238106Sdes int HMAC_CTX_init(void); 700238106Sdes (void)HMAC_CTX_init(); 701238106Sdes ],[ 702238106Sdes AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 703238106Sdes [If you have HMAC_CTX_init]) 704238106Sdes AC_MSG_RESULT(yes) 705238106Sdes ],[ 706238106Sdes AC_MSG_RESULT(no) 707238106Sdes AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required]) 708238106Sdes ]) 709238106Sdes ]) 710238106Sdes ]) 711238106Sdes fi 712238106Sdes AC_SUBST(HAVE_SSL) 713238106Sdes AC_SUBST(RUNTIME_PATH) 714238106Sdes # openssl engine functionality needs dlopen(). 715238106Sdes BAKLIBS="$LIBS" 716238106Sdes AC_SEARCH_LIBS([dlopen], [dl]) 717238106Sdes if test "$LIBS" != "$BAKLIBS"; then 718238106Sdes LIBSSL_LIBS="$LIBSSL_LIBS -ldl" 719238106Sdes fi 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 1216238106Sdesdnl provide w32 compat definition for sleep 1217238106SdesAC_DEFUN([AHX_CONFIG_W32_SLEEP], 1218238106Sdes[ 1219266114Sdes#if !defined(HAVE_SLEEP) || defined(HAVE_WINDOWS_H) 1220238106Sdes#define sleep(x) Sleep((x)*1000) /* on win32 */ 1221238106Sdes#endif /* HAVE_SLEEP */ 1222238106Sdes]) 1223238106Sdes 1224238106Sdesdnl provide w32 compat definition for usleep 1225238106SdesAC_DEFUN([AHX_CONFIG_W32_USLEEP], 1226238106Sdes[ 1227238106Sdes#ifndef HAVE_USLEEP 1228238106Sdes#define usleep(x) Sleep((x)/1000 + 1) /* on win32 */ 1229238106Sdes#endif /* HAVE_USLEEP */ 1230238106Sdes]) 1231238106Sdes 1232238106Sdesdnl provide w32 compat definition for random 1233238106SdesAC_DEFUN([AHX_CONFIG_W32_RANDOM], 1234238106Sdes[ 1235238106Sdes#ifndef HAVE_RANDOM 1236238106Sdes#define random rand /* on win32, for tests only (bad random) */ 1237238106Sdes#endif /* HAVE_RANDOM */ 1238238106Sdes]) 1239238106Sdes 1240238106Sdesdnl provide w32 compat definition for srandom 1241238106SdesAC_DEFUN([AHX_CONFIG_W32_SRANDOM], 1242238106Sdes[ 1243238106Sdes#ifndef HAVE_SRANDOM 1244238106Sdes#define srandom(x) srand(x) /* on win32, for tests only (bad random) */ 1245238106Sdes#endif /* HAVE_SRANDOM */ 1246238106Sdes]) 1247238106Sdes 1248238106Sdesdnl provide w32 compat definition for FD_SET_T 1249238106SdesAC_DEFUN([AHX_CONFIG_W32_FD_SET_T], 1250238106Sdes[ 1251238106Sdes/* detect if we need to cast to unsigned int for FD_SET to avoid warnings */ 1252238106Sdes#ifdef HAVE_WINSOCK2_H 1253238106Sdes#define FD_SET_T (u_int) 1254238106Sdes#else 1255238106Sdes#define FD_SET_T 1256238106Sdes#endif 1257238106Sdes]) 1258238106Sdes 1259238106Sdesdnl Remove an extension flag from CFLAGS, define replacement to be made. 1260238106Sdesdnl Used by ACX_STRIP_EXT_FLAGS. 1261238106Sdesdnl $1: the name of the flag, for example -D_GNU_SOURCE. 1262238106SdesAC_DEFUN([ACX_CFLAGS_STRIP], 1263238106Sdes[ 1264238106Sdes if echo $CFLAGS | grep " $1" >/dev/null 2>&1; then 1265238106Sdes CFLAGS="`echo $CFLAGS | sed -e 's/ $1//g'`" 1266238106Sdes AC_DEFINE(m4_bpatsubst(OMITTED_$1,[[-=]],_), 1, Put $1 define in config.h) 1267238106Sdes fi 1268238106Sdes]) 1269238106Sdes 1270238106Sdesdnl Remove EXT flags from the CFLAGS and set them to be defined in config.h 1271238106Sdesdnl use with ACX_DETERMINE_EXT_FLAGS. 1272238106SdesAC_DEFUN([ACX_STRIP_EXT_FLAGS], 1273238106Sdes[ 1274238106Sdes AC_MSG_NOTICE([Stripping extension flags...]) 1275238106Sdes ACX_CFLAGS_STRIP(-D_GNU_SOURCE) 1276238106Sdes ACX_CFLAGS_STRIP(-D_BSD_SOURCE) 1277238106Sdes ACX_CFLAGS_STRIP(-D__EXTENSIONS__) 1278238106Sdes ACX_CFLAGS_STRIP(-D_POSIX_C_SOURCE=200112) 1279238106Sdes ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE=600) 1280238106Sdes ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE_EXTENDED=1) 1281238106Sdes ACX_CFLAGS_STRIP(-D_ALL_SOURCE) 1282238106Sdes ACX_CFLAGS_STRIP(-D_LARGEFILE_SOURCE=1) 1283238106Sdes]) dnl End of ACX_STRIP_EXT_FLAGS 1284238106Sdes 1285238106Sdesdnl define one omitted flag for config.h 1286238106Sdesdnl $1: flag name. -D_GNU_SOURCE 1287238106Sdesdnl $2: replacement define. _GNU_SOURCE 1288238106Sdesdnl $3: define value, 1 1289238106SdesAC_DEFUN([AHX_CONFIG_FLAG_OMITTED], 1290238106Sdes[#if defined($1) && !defined($2) 1291238106Sdes#define $2 $3 1292238106Sdes[#]endif ]) 1293238106Sdes 1294238106Sdesdnl Wrapper for AHX_CONFIG_FLAG_OMITTED for -D style flags 1295238106Sdesdnl $1: the -DNAME or -DNAME=value string. 1296238106SdesAC_DEFUN([AHX_CONFIG_FLAG_EXT], 1297238106Sdes[AHX_CONFIG_FLAG_OMITTED(m4_bpatsubst(OMITTED_$1,[[-=]],_),m4_bpatsubst(m4_bpatsubst($1,-D,),=.*$,),m4_if(m4_bregexp($1,=),-1,1,m4_bpatsubst($1,^.*=,))) 1298238106Sdes]) 1299238106Sdes 1300238106Sdesdnl config.h part to define omitted cflags, use with ACX_STRIP_EXT_FLAGS. 1301238106SdesAC_DEFUN([AHX_CONFIG_EXT_FLAGS], 1302238106Sdes[AHX_CONFIG_FLAG_EXT(-D_GNU_SOURCE) 1303238106SdesAHX_CONFIG_FLAG_EXT(-D_BSD_SOURCE) 1304238106SdesAHX_CONFIG_FLAG_EXT(-D__EXTENSIONS__) 1305238106SdesAHX_CONFIG_FLAG_EXT(-D_POSIX_C_SOURCE=200112) 1306238106SdesAHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE=600) 1307238106SdesAHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE_EXTENDED=1) 1308238106SdesAHX_CONFIG_FLAG_EXT(-D_ALL_SOURCE) 1309238106SdesAHX_CONFIG_FLAG_EXT(-D_LARGEFILE_SOURCE=1) 1310238106Sdes]) 1311238106Sdes 1312238106Sdesdnl check if memcmp is using signed characters and replace if so. 1313238106SdesAC_DEFUN([ACX_CHECK_MEMCMP_SIGNED], 1314238106Sdes[AC_MSG_CHECKING([if memcmp compares unsigned]) 1315238106SdesAC_RUN_IFELSE([AC_LANG_SOURCE([[ 1316238106Sdes#include <stdio.h> 1317238106Sdes#include <stdlib.h> 1318238106Sdes#include <string.h> 1319238106Sdesint main(void) 1320238106Sdes{ 1321238106Sdes char a = 255, b = 0; 1322238106Sdes if(memcmp(&a, &b, 1) < 0) 1323238106Sdes return 1; 1324238106Sdes return 0; 1325238106Sdes} 1326238106Sdes]])], [AC_MSG_RESULT([yes]) ], 1327238106Sdes[ AC_MSG_RESULT([no]) 1328238106Sdes AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes]) 1329238106Sdes AC_LIBOBJ([memcmp]) 1330238106Sdes], [ AC_MSG_RESULT([cross-compile no]) 1331238106Sdes AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes]) 1332238106Sdes AC_LIBOBJ([memcmp]) 1333238106Sdes]) ]) 1334238106Sdes 1335238106Sdesdnl define memcmp to its replacement, pass unique id for program as arg 1336238106SdesAC_DEFUN([AHX_MEMCMP_BROKEN], [ 1337238106Sdes#ifdef MEMCMP_IS_BROKEN 1338238106Sdes#include "compat/memcmp.h" 1339238106Sdes#define memcmp memcmp_$1 1340238106Sdesint memcmp(const void *x, const void *y, size_t n); 1341238106Sdes#endif 1342238106Sdes]) 1343238106Sdes 1344238106Sdesdnl ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family 1345238106SdesAC_DEFUN([ACX_CHECK_SS_FAMILY], 1346238106Sdes[AC_CHECK_MEMBER([struct sockaddr_storage.ss_family], [], [ 1347238106Sdes AC_CHECK_MEMBER([struct sockaddr_storage.__ss_family], [ 1348238106Sdes AC_DEFINE([ss_family], [__ss_family], [Fallback member name for socket family in struct sockaddr_storage]) 1349238106Sdes ],, [AC_INCLUDES_DEFAULT 1350238106Sdes#ifdef HAVE_NETINET_IN_H 1351238106Sdes#include <netinet/in.h> 1352238106Sdes#endif 1353238106Sdes#ifdef HAVE_SYS_SOCKET_H 1354238106Sdes#include <sys/socket.h> 1355238106Sdes#endif 1356238106Sdes#ifdef HAVE_NETDB_H 1357238106Sdes#include <netdb.h> 1358238106Sdes#endif 1359238106Sdes#ifdef HAVE_ARPA_INET_H 1360238106Sdes#include <arpa/inet.h> 1361238106Sdes#endif 1362238106Sdes ]) 1363238106Sdes], [AC_INCLUDES_DEFAULT 1364238106Sdes#ifdef HAVE_NETINET_IN_H 1365238106Sdes#include <netinet/in.h> 1366238106Sdes#endif 1367238106Sdes#ifdef HAVE_SYS_SOCKET_H 1368238106Sdes#include <sys/socket.h> 1369238106Sdes#endif 1370238106Sdes#ifdef HAVE_NETDB_H 1371238106Sdes#include <netdb.h> 1372238106Sdes#endif 1373238106Sdes#ifdef HAVE_ARPA_INET_H 1374238106Sdes#include <arpa/inet.h> 1375238106Sdes#endif 1376238106Sdes]) ]) 1377238106Sdes 1378238106Sdesdnl End of file 1379