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