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