1# acx_nlnetlabs.m4 - common macros for configure checks 2# Copyright 2009, Wouter Wijngaards, NLnet Labs. 3# BSD licensed. 4# 5# Version 20 6# 2012-01-20 Fix COMPILER_FLAGS_UNBOUND for gcc 4.6.2 assigned-not-used-warns. 7# 2011-12-05 Fix getaddrinfowithincludes on windows with fedora16 mingw32-gcc. 8# Fix ACX_MALLOC for redefined malloc error. 9# Fix GETADDRINFO_WITH_INCLUDES to add -lws2_32 10# 2011-11-10 Fix FLTO test to not drop a.out in current directory. 11# 2011-11-01 Fix FLTO test for llvm on Lion. 12# 2011-08-01 Fix nonblock test (broken at v13). 13# 2011-08-01 Fix autoconf 2.68 warnings 14# 2011-06-23 Add ACX_CHECK_FLTO to check -flto. 15# 2010-08-16 Fix FLAG_OMITTED for AS_TR_CPP changes in autoconf-2.66. 16# 2010-07-02 Add check for ss_family (for minix). 17# 2010-04-26 Fix to use CPPFLAGS for CHECK_COMPILER_FLAGS. 18# 2010-03-01 Fix RPATH using CONFIG_COMMANDS to run at the very end. 19# 2010-02-18 WITH_SSL outputs the LIBSSL_LDFLAGS, LIBS, CPPFLAGS seperate, -ldl 20# 2010-02-01 added ACX_CHECK_MEMCMP_SIGNED, AHX_MEMCMP_BROKEN 21# 2010-01-20 added AHX_COONFIG_STRLCAT 22# 2009-07-14 U_CHAR detection improved for windows crosscompile. 23# added ACX_FUNC_MALLOC 24# fixup some #if to #ifdef 25# NONBLOCKING test for mingw crosscompile. 26# 2009-07-13 added ACX_WITH_SSL_OPTIONAL 27# 2009-07-03 fixup LDFLAGS for empty ssl dir. 28# 29# Automates some of the checking constructs. Aims at portability for POSIX. 30# Documentation for functions is below. 31# 32# the following macro's are provided in this file: 33# (see below for details on each macro). 34# 35# ACX_ESCAPE_BACKSLASH - escape backslashes in var for C-preproc. 36# ACX_RSRC_VERSION - create windows resource version number. 37# ACX_CHECK_COMPILER_FLAG - see if cc supports a flag. 38# ACX_CHECK_ERROR_FLAGS - see which flag is -werror (used below). 39# ACX_CHECK_COMPILER_FLAG_NEEDED - see if flags make the code compile cleanly. 40# ACX_DEPFLAG - find cc dependency flags. 41# ACX_DETERMINE_EXT_FLAGS_UNBOUND - find out which flags enable BSD and POSIX. 42# ACX_CHECK_FORMAT_ATTRIBUTE - find cc printf format syntax. 43# ACX_CHECK_UNUSED_ATTRIBUTE - find cc variable unused syntax. 44# ACX_CHECK_FLTO - see if cc supports -flto and use it if so. 45# ACX_LIBTOOL_C_ONLY - create libtool for C only, improved. 46# ACX_TYPE_U_CHAR - u_char type. 47# ACX_TYPE_RLIM_T - rlim_t type. 48# ACX_TYPE_SOCKLEN_T - socklen_t type. 49# ACX_TYPE_IN_ADDR_T - in_addr_t type. 50# ACX_TYPE_IN_PORT_T - in_port_t type. 51# ACX_ARG_RPATH - add --disable-rpath option. 52# ACX_WITH_SSL - add --with-ssl option, link -lcrypto. 53# ACX_WITH_SSL_OPTIONAL - add --with-ssl option, link -lcrypto, 54# where --without-ssl is also accepted 55# ACX_LIB_SSL - setup to link -lssl. 56# ACX_SYS_LARGEFILE - improved sys_largefile, fseeko, >2G files. 57# ACX_CHECK_GETADDRINFO_WITH_INCLUDES - find getaddrinfo, portably. 58# ACX_FUNC_DEPRECATED - see if func is deprecated. 59# ACX_CHECK_NONBLOCKING_BROKEN - see if nonblocking sockets really work. 60# ACX_MKDIR_ONE_ARG - determine mkdir(2) number of arguments. 61# ACX_FUNC_IOCTLSOCKET - find ioctlsocket, portably. 62# ACX_FUNC_MALLOC - check malloc, define replacement . 63# AHX_CONFIG_FORMAT_ATTRIBUTE - config.h text for format. 64# AHX_CONFIG_UNUSED_ATTRIBUTE - config.h text for unused. 65# AHX_CONFIG_FSEEKO - define fseeko, ftello fallback. 66# AHX_CONFIG_RAND_MAX - define RAND_MAX if needed. 67# AHX_CONFIG_MAXHOSTNAMELEN - define MAXHOSTNAMELEN if needed. 68# AHX_CONFIG_IPV6_MIN_MTU - define IPV6_MIN_MTU if needed. 69# AHX_CONFIG_SNPRINTF - snprintf compat prototype 70# AHX_CONFIG_INET_PTON - inet_pton compat prototype 71# AHX_CONFIG_INET_NTOP - inet_ntop compat prototype 72# AHX_CONFIG_INET_ATON - inet_aton compat prototype 73# AHX_CONFIG_MEMMOVE - memmove compat prototype 74# AHX_CONFIG_STRLCAT - strlcat compat prototype 75# AHX_CONFIG_STRLCPY - strlcpy compat prototype 76# AHX_CONFIG_GMTIME_R - gmtime_r compat prototype 77# AHX_CONFIG_W32_SLEEP - w32 compat for sleep 78# AHX_CONFIG_W32_USLEEP - w32 compat for usleep 79# AHX_CONFIG_W32_RANDOM - w32 compat for random 80# AHX_CONFIG_W32_SRANDOM - w32 compat for srandom 81# AHX_CONFIG_W32_FD_SET_T - w32 detection of FD_SET_T. 82# ACX_CFLAGS_STRIP - strip one flag from CFLAGS 83# ACX_STRIP_EXT_FLAGS - strip extension flags from CFLAGS 84# AHX_CONFIG_FLAG_OMITTED - define omitted flag 85# AHX_CONFIG_FLAG_EXT - define omitted extension flag 86# AHX_CONFIG_EXT_FLAGS - define the stripped extension flags 87# ACX_CHECK_MEMCMP_SIGNED - check if memcmp uses signed characters. 88# AHX_MEMCMP_BROKEN - replace memcmp func for CHECK_MEMCMP_SIGNED. 89# ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family 90# 91 92dnl Escape backslashes as \\, for C:\ paths, for the C preprocessor defines. 93dnl for example, ACX_ESCAPE_BACKSLASH($from_var, to_var) 94dnl $1: the text to change. 95dnl $2: the result. 96AC_DEFUN([ACX_ESCAPE_BACKSLASH], [$2="`echo $1 | sed -e 's/\\\\/\\\\\\\\/g'`" 97]) 98 99dnl Calculate comma separated windows-resource numbers from package version. 100dnl Picks the first three(,0) or four numbers out of the name. 101dnl $1: variable for the result 102AC_DEFUN([ACX_RSRC_VERSION], 103[$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/' `] 104]) 105 106dnl Routine to help check for compiler flags. 107dnl Checks if the compiler will accept the flag. 108dnl $1: the flag without a - in front, so g to check -g. 109dnl $2: executed if yes 110dnl $3: executed if no 111AC_DEFUN([ACX_CHECK_COMPILER_FLAG], 112[ 113AC_REQUIRE([AC_PROG_CC]) 114AC_MSG_CHECKING(whether $CC supports -$1) 115cache=`echo $1 | sed 'y%.=/+-%___p_%'` 116AC_CACHE_VAL(cv_prog_cc_flag_$cache, 117[ 118echo 'void f(){}' >conftest.c 119if test -z "`$CC $CPPFLAGS $CFLAGS -$1 -c conftest.c 2>&1`"; then 120eval "cv_prog_cc_flag_$cache=yes" 121else 122eval "cv_prog_cc_flag_$cache=no" 123fi 124rm -f conftest conftest.o conftest.c 125]) 126if eval "test \"`echo '$cv_prog_cc_flag_'$cache`\" = yes"; then 127AC_MSG_RESULT(yes) 128: 129$2 130else 131AC_MSG_RESULT(no) 132: 133$3 134fi 135]) 136 137dnl setup flags for ACX_CHECK_COMPILER_FLAG_NEEDED 138dnl ERRFLAG: result, compiler flag to turn warnings into errors 139AC_DEFUN([ACX_CHECK_ERROR_FLAGS], 140[ 141ACX_CHECK_COMPILER_FLAG(Werror, [ERRFLAG="-Werror"], [ERRFLAG="-errwarn"]) 142ACX_CHECK_COMPILER_FLAG(Wall, [ERRFLAG="$ERRFLAG -Wall"], 143 [ERRFLAG="$ERRFLAG -errfmt"]) 144]) 145 146dnl Routine to help check for needed compiler flags. 147dnl $1: flags for CC 148dnl $2: the includes and code 149dnl $3: if the given code only compiles with the flag, execute argument 3 150dnl $4: if the given code compiles without the flag, execute argument 4 151dnl $5: with and without flag the compile fails, execute argument 5. 152AC_DEFUN([ACX_CHECK_COMPILER_FLAG_NEEDED], 153[ 154AC_REQUIRE([AC_PROG_CC]) 155AC_REQUIRE([ACX_CHECK_ERROR_FLAGS]) 156AC_MSG_CHECKING(whether we need $1 as a flag for $CC) 157cache=AS_TR_SH($1) 158dnl cache=`echo $1 | sed 'y%.=/+- %___p__%'` 159AC_CACHE_VAL(cv_prog_cc_flag_needed_$cache, 160[ 161echo '$2' > conftest.c 162echo 'void f(){}' >>conftest.c 163if test -z "`$CC $CPPFLAGS $CFLAGS $ERRFLAG -c conftest.c 2>&1`"; then 164eval "cv_prog_cc_flag_needed_$cache=no" 165else 166[ 167if test -z "`$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1`"; then 168eval "cv_prog_cc_flag_needed_$cache=yes" 169else 170eval "cv_prog_cc_flag_needed_$cache=fail" 171#echo 'Test with flag fails too!' 172#cat conftest.c 173#echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1" 174#echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1` 175#exit 1 176fi 177] 178fi 179rm -f conftest conftest.c conftest.o 180]) 181if eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = yes"; then 182AC_MSG_RESULT(yes) 183: 184$3 185else 186if eval "test \"`echo '$cv_prog_cc_flag_needed_'$cache`\" = no"; then 187AC_MSG_RESULT(no) 188#echo 'Test with flag is no!' 189#cat conftest.c 190#echo "$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1" 191#echo `$CC $CPPFLAGS $CFLAGS $1 $ERRFLAG -c conftest.c 2>&1` 192#exit 1 193: 194$4 195else 196AC_MSG_RESULT(failed) 197: 198$5 199fi 200fi 201]) 202 203dnl Check for CC dependency flag 204dnl DEPFLAG: set to flag that generates dependencies. 205AC_DEFUN([ACX_DEPFLAG], 206[ 207AC_MSG_CHECKING([$CC dependency flag]) 208echo 'void f(){}' >conftest.c 209if test "`$CC -MM conftest.c 2>&1`" = "conftest.o: conftest.c"; then 210 DEPFLAG="-MM" 211else 212 if test "`$CC -xM1 conftest.c 2>&1`" = "conftest.o: conftest.c"; then 213 DEPFLAG="-xM1" 214 else 215 DEPFLAG="-MM" # dunno do something 216 fi 217fi 218AC_MSG_RESULT($DEPFLAG) 219rm -f conftest.c 220AC_SUBST(DEPFLAG) 221]) 222 223dnl Determine flags that gives POSIX and BSD functionality. 224dnl CFLAGS is modified for the result. 225AC_DEFUN([ACX_DETERMINE_EXT_FLAGS_UNBOUND], 226[ 227ACX_CHECK_COMPILER_FLAG(std=c99, [C99FLAG="-std=c99"]) 228ACX_CHECK_COMPILER_FLAG(xc99, [C99FLAG="-xc99"]) 229 230AC_CHECK_HEADERS([getopt.h time.h],,, [AC_INCLUDES_DEFAULT]) 231 232ACX_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, 233[ 234#include "confdefs.h" 235#include <stdlib.h> 236#include <ctype.h> 237#include <sys/time.h> 238#ifdef HAVE_TIME_H 239#include <time.h> 240#endif 241#include <unistd.h> 242#include <netdb.h> 243#ifdef HAVE_GETOPT_H 244#include <getopt.h> 245#endif 246 247int test() { 248 int a; 249 char **opts = NULL; 250 struct timeval tv; 251 char *t; 252 time_t time = 0; 253 char *buf = NULL; 254 const char* str = NULL; 255 struct msghdr msg; 256 msg.msg_control = 0; 257 t = ctime_r(&time, buf); 258 tv.tv_usec = 10; 259 srandom(32); 260 a = getopt(2, opts, "a"); 261 a = isascii(32); 262 str = gai_strerror(0); 263 if(str && t && tv.tv_usec && msg.msg_control) 264 a = 0; 265 return a; 266} 267], [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"]) 268 269ACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE, 270[ 271#include "confdefs.h" 272#include <stdlib.h> 273#include <ctype.h> 274#include <sys/time.h> 275#ifdef HAVE_TIME_H 276#include <time.h> 277#endif 278#include <unistd.h> 279#include <netdb.h> 280#ifdef HAVE_GETOPT_H 281#include <getopt.h> 282#endif 283 284int test() { 285 int a; 286 char **opts = NULL; 287 struct timeval tv; 288 char *t; 289 time_t time = 0; 290 char *buf = NULL; 291 const char* str = NULL; 292 struct msghdr msg; 293 msg.msg_control = 0; 294 t = ctime_r(&time, buf); 295 tv.tv_usec = 10; 296 srandom(32); 297 a = getopt(2, opts, "a"); 298 a = isascii(32); 299 str = gai_strerror(0); 300 if(str && t && tv.tv_usec && msg.msg_control) 301 a = 0; 302 return a; 303} 304], [CFLAGS="$CFLAGS $C99FLAG -D__EXTENSIONS__ -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_ALL_SOURCE"]) 305 306ACX_CHECK_COMPILER_FLAG_NEEDED($C99FLAG, 307[ 308#include <stdbool.h> 309#include <ctype.h> 310int test() { 311 int a = 0; 312 return a; 313} 314], [CFLAGS="$CFLAGS $C99FLAG"]) 315 316ACX_CHECK_COMPILER_FLAG_NEEDED(-D_BSD_SOURCE, 317[ 318#include <ctype.h> 319 320int test() { 321 int a; 322 a = isascii(32); 323 return a; 324} 325], [CFLAGS="$CFLAGS -D_BSD_SOURCE"]) 326 327ACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE, 328[ 329#include <netinet/in.h> 330 331int test() { 332 struct in6_pktinfo inf; 333 int a = (int)sizeof(inf); 334 return a; 335} 336], [CFLAGS="$CFLAGS -D_GNU_SOURCE"]) 337 338# check again for GNU_SOURCE for setresgid. May fail if setresgid 339# is not available at all. -D_FRSRESGID is to make this check unique. 340# otherwise we would get the previous cached result. 341ACX_CHECK_COMPILER_FLAG_NEEDED(-D_GNU_SOURCE -D_FRSRESGID, 342[ 343#include <unistd.h> 344 345int test() { 346 int a = setresgid(0,0,0); 347 a = setresuid(0,0,0); 348 return a; 349} 350], [CFLAGS="$CFLAGS -D_GNU_SOURCE"]) 351 352ACX_CHECK_COMPILER_FLAG_NEEDED(-D_POSIX_C_SOURCE=200112, 353[ 354#include "confdefs.h" 355#ifdef HAVE_TIME_H 356#include <time.h> 357#endif 358#include <netdb.h> 359 360int test() { 361 int a = 0; 362 char *t; 363 time_t time = 0; 364 char *buf = NULL; 365 const char* str = NULL; 366 t = ctime_r(&time, buf); 367 str = gai_strerror(0); 368 if(t && str) 369 a = 0; 370 return a; 371} 372], [CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112"]) 373 374ACX_CHECK_COMPILER_FLAG_NEEDED(-D__EXTENSIONS__, 375[ 376#include "confdefs.h" 377#include <stdlib.h> 378#include <ctype.h> 379#include <sys/time.h> 380#ifdef HAVE_TIME_H 381#include <time.h> 382#endif 383#include <unistd.h> 384#ifdef HAVE_GETOPT_H 385#include <getopt.h> 386#endif 387 388int test() { 389 int a; 390 char **opts = NULL; 391 struct timeval tv; 392 tv.tv_usec = 10; 393 srandom(32); 394 a = getopt(2, opts, "a"); 395 a = isascii(32); 396 if(tv.tv_usec) 397 a = 0; 398 return a; 399} 400], [CFLAGS="$CFLAGS -D__EXTENSIONS__"]) 401 402])dnl End of ACX_DETERMINE_EXT_FLAGS_UNBOUND 403 404dnl Check if CC supports -flto. 405dnl in a way that supports clang and suncc (that flag does something else, 406dnl but fails to link). It sets it in CFLAGS if it works. 407AC_DEFUN([ACX_CHECK_FLTO], 408[AC_MSG_CHECKING([if $CC supports -flto]) 409BAKCFLAGS="$CFLAGS" 410CFLAGS="$CFLAGS -flto" 411AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [ 412 if $CC $CFLAGS -o conftest conftest.c 2>&1 | grep "warning: no debug symbols in executable" >/dev/null; then 413 CFLAGS="$BAKCFLAGS" 414 AC_MSG_RESULT(no) 415 else 416 AC_MSG_RESULT(yes) 417 fi 418 rm -f conftest conftest.c conftest.o 419], [CFLAGS="$BAKCFLAGS" ; AC_MSG_RESULT(no)]) 420]) 421 422dnl Check the printf-format attribute (if any) 423dnl result in HAVE_ATTR_FORMAT. 424dnl Make sure you also include the AHX_CONFIG_FORMAT_ATTRIBUTE. 425AC_DEFUN([ACX_CHECK_FORMAT_ATTRIBUTE], 426[AC_REQUIRE([AC_PROG_CC]) 427AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute) 428AC_CACHE_VAL(ac_cv_c_format_attribute, 429[ac_cv_c_format_attribute=no 430AC_TRY_COMPILE( 431[#include <stdio.h> 432void f (char *format, ...) __attribute__ ((format (printf, 1, 2))); 433void (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2))); 434], [ 435 f ("%s", "str"); 436], 437[ac_cv_c_format_attribute="yes"], 438[ac_cv_c_format_attribute="no"]) 439]) 440 441AC_MSG_RESULT($ac_cv_c_format_attribute) 442if test $ac_cv_c_format_attribute = yes; then 443 AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute]) 444fi 445])dnl End of ACX_CHECK_FORMAT_ATTRIBUTE 446 447dnl Setup ATTR_FORMAT config.h parts. 448dnl make sure you call ACX_CHECK_FORMAT_ATTRIBUTE also. 449AC_DEFUN([AHX_CONFIG_FORMAT_ATTRIBUTE], 450[ 451#ifdef HAVE_ATTR_FORMAT 452# define ATTR_FORMAT(archetype, string_index, first_to_check) \ 453 __attribute__ ((format (archetype, string_index, first_to_check))) 454#else /* !HAVE_ATTR_FORMAT */ 455# define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */ 456#endif /* !HAVE_ATTR_FORMAT */ 457]) 458 459dnl Check how to mark function arguments as unused. 460dnl result in HAVE_ATTR_UNUSED. 461dnl Make sure you include AHX_CONFIG_UNUSED_ATTRIBUTE also. 462AC_DEFUN([ACX_CHECK_UNUSED_ATTRIBUTE], 463[AC_REQUIRE([AC_PROG_CC]) 464AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute) 465AC_CACHE_VAL(ac_cv_c_unused_attribute, 466[ac_cv_c_unused_attribute=no 467AC_TRY_COMPILE( 468[#include <stdio.h> 469void f (char *u __attribute__((unused))); 470], [ 471 f ("x"); 472], 473[ac_cv_c_unused_attribute="yes"], 474[ac_cv_c_unused_attribute="no"]) 475]) 476 477dnl Setup ATTR_UNUSED config.h parts. 478dnl make sure you call ACX_CHECK_UNUSED_ATTRIBUTE also. 479AC_DEFUN([AHX_CONFIG_UNUSED_ATTRIBUTE], 480[ 481#if defined(DOXYGEN) 482# define ATTR_UNUSED(x) x 483#elif defined(__cplusplus) 484# define ATTR_UNUSED(x) 485#elif defined(HAVE_ATTR_UNUSED) 486# define ATTR_UNUSED(x) x __attribute__((unused)) 487#else /* !HAVE_ATTR_UNUSED */ 488# define ATTR_UNUSED(x) x 489#endif /* !HAVE_ATTR_UNUSED */ 490]) 491 492AC_MSG_RESULT($ac_cv_c_unused_attribute) 493if test $ac_cv_c_unused_attribute = yes; then 494 AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute]) 495fi 496])dnl 497 498dnl Pre-fun for ACX_LIBTOOL_C_ONLY 499AC_DEFUN([ACX_LIBTOOL_C_PRE], [ 500# skip these tests, we do not need them. 501AC_DEFUN([AC_PROG_F77], [:]) 502AC_DEFUN([AC_PROG_FC], [:]) 503AC_DEFUN([AC_PROG_CXX], [:]) 504AC_DEFUN([AC_PROG_CXXCPP], [:]) 505AC_DEFUN([AC_PROG_OBJC], [:]) 506AC_DEFUN([AC_PROG_OBJCCPP], [:]) 507AC_DEFUN([AC_LIBTOOL_CXX], [:]) 508AC_DEFUN([AC_LIBTOOL_F77], [:]) 509# always use ./libtool unless override from commandline (libtool=mylibtool) 510if test -z "$libtool"; then 511 libtool="./libtool" 512fi 513AC_SUBST(libtool) 514# avoid libtool max commandline length test on systems that fork slowly. 515AC_CANONICAL_HOST 516if echo "$host_os" | grep "sunos4" >/dev/null; then 517 lt_cv_sys_max_cmd_len=32750; 518fi 519AC_PATH_TOOL(AR, ar, [false]) 520if test $AR = false; then 521 AC_MSG_ERROR([Cannot find 'ar', please extend PATH to include it]) 522fi 523]) 524 525dnl Perform libtool check, portably, only for C 526AC_DEFUN([ACX_LIBTOOL_C_ONLY], [ 527dnl as a requirement so that is gets called before LIBTOOL 528dnl because libtools 'AC_REQUIRE' names are right after this one, before 529dnl this function contents. 530AC_REQUIRE([ACX_LIBTOOL_C_PRE]) 531AC_PROG_LIBTOOL 532]) 533 534dnl Detect if u_char type is defined, otherwise define it. 535AC_DEFUN([ACX_TYPE_U_CHAR], 536[AC_CHECK_TYPE([u_char], , 537 [AC_DEFINE([u_char], [unsigned char], [Define to 'unsigned char if not defined])], [ 538AC_INCLUDES_DEFAULT 539#ifdef HAVE_WINSOCK2_H 540# include <winsock2.h> 541#endif 542]) ]) 543 544dnl Detect if rlim_t type is defined, otherwise define it. 545AC_DEFUN([ACX_TYPE_RLIM_T], 546[AC_CHECK_TYPE(rlim_t, , 547 [AC_DEFINE([rlim_t], [unsigned long], [Define to 'int' if not defined])], [ 548AC_INCLUDES_DEFAULT 549#ifdef HAVE_SYS_RESOURCE_H 550# include <sys/resource.h> 551#endif 552]) ]) 553 554dnl Detect if socklen_t type is defined, otherwise define it. 555AC_DEFUN([ACX_TYPE_SOCKLEN_T], 556[ 557AC_CHECK_TYPE(socklen_t, , 558 [AC_DEFINE([socklen_t], [int], [Define to 'int' if not defined])], [ 559AC_INCLUDES_DEFAULT 560#ifdef HAVE_SYS_SOCKET_H 561# include <sys/socket.h> 562#endif 563#ifdef HAVE_WS2TCPIP_H 564# include <ws2tcpip.h> 565#endif 566]) ]) 567 568dnl Detect if in_addr_t type is defined, otherwise define it. 569AC_DEFUN([ACX_TYPE_IN_ADDR_T], 570[ AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [ 571AC_INCLUDES_DEFAULT 572#ifdef HAVE_SYS_TYPES_H 573# include <sys/types.h> 574#endif 575#ifdef HAVE_NETINET_IN_H 576# include <netinet/in.h> 577#endif 578]) ]) 579 580dnl Detect if in_port_t type is defined, otherwise define it. 581AC_DEFUN([ACX_TYPE_IN_PORT_T], 582[ AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])], [ 583AC_INCLUDES_DEFAULT 584#ifdef HAVE_SYS_TYPES_H 585# include <sys/types.h> 586#endif 587#ifdef HAVE_NETINET_IN_H 588# include <netinet/in.h> 589#endif 590]) ]) 591 592dnl Add option to disable the evil rpath. Check whether to use rpath or not. 593dnl Adds the --disable-rpath option. Uses trick to edit the ./libtool. 594AC_DEFUN([ACX_ARG_RPATH], 595[ 596AC_ARG_ENABLE(rpath, 597 [ --disable-rpath disable hardcoded rpath (default=enabled)], 598 enable_rpath=$enableval, enable_rpath=yes) 599if test "x$enable_rpath" = xno; then 600 dnl AC_MSG_RESULT([Fixing libtool for -rpath problems.]) 601 AC_CONFIG_COMMANDS([disable-rpath], [ 602 sed < libtool > libtool-2 \ 603 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_RPATH_SED__ "/' 604 mv libtool-2 libtool 605 chmod 755 libtool 606 libtool="./libtool" 607 ]) 608fi 609]) 610 611dnl Add a -R to the RUNTIME_PATH. Only if rpath is enabled and it is 612dnl an absolute path. 613dnl $1: the pathname to add. 614AC_DEFUN([ACX_RUNTIME_PATH_ADD], [ 615 if test "x$enable_rpath" = xyes; then 616 if echo "$1" | grep "^/" >/dev/null; then 617 RUNTIME_PATH="$RUNTIME_PATH -R$1" 618 fi 619 fi 620]) 621 622dnl Common code for both ACX_WITH_SSL and ACX_WITH_SSL_OPTIONAL 623dnl Takes one argument; the withval checked in those 2 functions 624dnl sets up the environment for the given openssl path 625AC_DEFUN([ACX_SSL_CHECKS], [ 626 withval=$1 627 if test x_$withval != x_no; then 628 AC_MSG_CHECKING(for SSL) 629 if test x_$withval = x_ -o x_$withval = x_yes; then 630 withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr" 631 fi 632 for dir in $withval; do 633 ssldir="$dir" 634 if test -f "$dir/include/openssl/ssl.h"; then 635 found_ssl="yes" 636 AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.]) 637 dnl assume /usr/include is already in the include-path. 638 if test "$ssldir" != "/usr"; then 639 CPPFLAGS="$CPPFLAGS -I$ssldir/include" 640 LIBSSL_CPPFLAGS="$LIBSSL_CPPFLAGS -I$ssldir/include" 641 fi 642 break; 643 fi 644 done 645 if test x_$found_ssl != x_yes; then 646 AC_MSG_ERROR(Cannot find the SSL libraries in $withval) 647 else 648 AC_MSG_RESULT(found in $ssldir) 649 HAVE_SSL=yes 650 dnl assume /usr is already in the lib and dynlib paths. 651 if test "$ssldir" != "/usr" -a "$ssldir" != ""; then 652 LDFLAGS="$LDFLAGS -L$ssldir/lib" 653 LIBSSL_LDFLAGS="$LIBSSL_LDFLAGS -L$ssldir/lib" 654 ACX_RUNTIME_PATH_ADD([$ssldir/lib]) 655 fi 656 657 AC_MSG_CHECKING([for HMAC_CTX_init in -lcrypto]) 658 LIBS="$LIBS -lcrypto" 659 LIBSSL_LIBS="$LIBSSL_LIBS -lcrypto" 660 AC_TRY_LINK(, [ 661 int HMAC_CTX_init(void); 662 (void)HMAC_CTX_init(); 663 ], [ 664 AC_MSG_RESULT(yes) 665 AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 666 [If you have HMAC_CTX_init]) 667 ], [ 668 AC_MSG_RESULT(no) 669 # check if -lwsock32 or -lgdi32 are needed. 670 BAKLIBS="$LIBS" 671 BAKSSLLIBS="$LIBSSL_LIBS" 672 LIBS="$LIBS -lgdi32" 673 LIBSSL_LIBS="$LIBSSL_LIBS -lgdi32" 674 AC_MSG_CHECKING([if -lcrypto needs -lgdi32]) 675 AC_TRY_LINK([], [ 676 int HMAC_CTX_init(void); 677 (void)HMAC_CTX_init(); 678 ],[ 679 AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 680 [If you have HMAC_CTX_init]) 681 AC_MSG_RESULT(yes) 682 ],[ 683 AC_MSG_RESULT(no) 684 LIBS="$BAKLIBS" 685 LIBSSL_LIBS="$BAKSSLLIBS" 686 LIBS="$LIBS -ldl" 687 LIBSSL_LIBS="$LIBSSL_LIBS -ldl" 688 AC_MSG_CHECKING([if -lcrypto needs -ldl]) 689 AC_TRY_LINK([], [ 690 int HMAC_CTX_init(void); 691 (void)HMAC_CTX_init(); 692 ],[ 693 AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, 694 [If you have HMAC_CTX_init]) 695 AC_MSG_RESULT(yes) 696 ],[ 697 AC_MSG_RESULT(no) 698 AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required]) 699 ]) 700 ]) 701 ]) 702 fi 703 AC_SUBST(HAVE_SSL) 704 AC_SUBST(RUNTIME_PATH) 705 # openssl engine functionality needs dlopen(). 706 BAKLIBS="$LIBS" 707 AC_SEARCH_LIBS([dlopen], [dl]) 708 if test "$LIBS" != "$BAKLIBS"; then 709 LIBSSL_LIBS="$LIBSSL_LIBS -ldl" 710 fi 711 fi 712AC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT]) 713AC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT]) 714AC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT]) 715])dnl End of ACX_SSL_CHECKS 716 717dnl Check for SSL, where SSL is mandatory 718dnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found 719dnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS. 720dnl Checks main header files of SSL. 721dnl 722AC_DEFUN([ACX_WITH_SSL], 723[ 724AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname], 725 [enable SSL (will check /usr/local/ssl 726 /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr)]),[ 727 ],[ 728 withval="yes" 729 ]) 730 if test x_$withval = x_no; then 731 AC_MSG_ERROR([Need SSL library to do digital signature cryptography]) 732 fi 733 ACX_SSL_CHECKS($withval) 734])dnl End of ACX_WITH_SSL 735 736dnl Check for SSL, where ssl is optional (--without-ssl is allowed) 737dnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found 738dnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS. 739dnl Checks main header files of SSL. 740dnl 741AC_DEFUN([ACX_WITH_SSL_OPTIONAL], 742[ 743AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname], 744 [enable SSL (will check /usr/local/ssl 745 /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr)]),[ 746 ],[ 747 withval="yes" 748 ]) 749 ACX_SSL_CHECKS($withval) 750])dnl End of ACX_WITH_SSL_OPTIONAL 751 752dnl Setup to use -lssl 753dnl To use -lcrypto, use the ACX_WITH_SSL setup (before this one). 754AC_DEFUN([ACX_LIB_SSL], 755[ 756# check if libssl needs libdl 757BAKLIBS="$LIBS" 758LIBS="-lssl $LIBS" 759AC_MSG_CHECKING([if libssl needs libdl]) 760AC_TRY_LINK_FUNC([SSL_CTX_new], [ 761 AC_MSG_RESULT([no]) 762 LIBS="$BAKLIBS" 763] , [ 764 AC_MSG_RESULT([yes]) 765 LIBS="$BAKLIBS" 766 AC_SEARCH_LIBS([dlopen], [dl]) 767]) ])dnl End of ACX_LIB_SSL 768 769dnl Setup to use very large files (>2Gb). 770dnl setups fseeko and its own 771AC_DEFUN([ACX_SYS_LARGEFILE], 772[ 773AC_SYS_LARGEFILE 774dnl try to see if an additional _LARGEFILE_SOURCE 1 is needed to get fseeko 775ACX_CHECK_COMPILER_FLAG_NEEDED(-D_LARGEFILE_SOURCE=1, 776[ 777#include <stdio.h> 778int test() { 779 int a = fseeko(stdin, 0, 0); 780 return a; 781} 782], [CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE=1"]) 783]) 784 785dnl Check getaddrinfo. 786dnl Works on linux, solaris, bsd and windows(links winsock). 787dnl defines HAVE_GETADDRINFO, USE_WINSOCK. 788AC_DEFUN([ACX_CHECK_GETADDRINFO_WITH_INCLUDES], 789[AC_REQUIRE([AC_PROG_CC]) 790AC_MSG_CHECKING(for getaddrinfo) 791ac_cv_func_getaddrinfo=no 792AC_LINK_IFELSE( 793[AC_LANG_SOURCE([[ 794#ifdef __cplusplus 795extern "C" 796{ 797#endif 798char* getaddrinfo(); 799char* (*f) () = getaddrinfo; 800#ifdef __cplusplus 801} 802#endif 803int main() { 804 ; 805 return 0; 806} 807]])], 808dnl this case on linux, solaris, bsd 809[ac_cv_func_getaddrinfo="yes" 810dnl see if on windows 811if test "$ac_cv_header_windows_h" = "yes"; then 812 AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used]) 813 USE_WINSOCK="1" 814 LIBS="$LIBS -lws2_32" 815fi 816], 817dnl no quick getaddrinfo, try mingw32 and winsock2 library. 818ORIGLIBS="$LIBS" 819LIBS="$LIBS -lws2_32" 820AC_LINK_IFELSE( 821[AC_LANG_PROGRAM( 822[ 823#ifdef HAVE_WS2TCPIP_H 824#include <ws2tcpip.h> 825#endif 826], 827[ 828 (void)getaddrinfo(NULL, NULL, NULL, NULL); 829] 830)], 831[ 832ac_cv_func_getaddrinfo="yes" 833dnl already: LIBS="$LIBS -lws2_32" 834AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used]) 835USE_WINSOCK="1" 836], 837[ 838ac_cv_func_getaddrinfo="no" 839LIBS="$ORIGLIBS" 840]) 841) 842 843AC_MSG_RESULT($ac_cv_func_getaddrinfo) 844if test $ac_cv_func_getaddrinfo = yes; then 845 AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether getaddrinfo is available]) 846fi 847])dnl Endof AC_CHECK_GETADDRINFO_WITH_INCLUDES 848 849dnl check if a function is deprecated. defines DEPRECATED_func in config.h. 850dnl $1: function name 851dnl $2: C-statement that calls the function. 852dnl $3: includes for the program. 853dnl $4: executes if yes 854dnl $5: executes if no 855AC_DEFUN([ACX_FUNC_DEPRECATED], 856[ 857AC_REQUIRE([AC_PROG_CC]) 858AC_MSG_CHECKING(if $1 is deprecated) 859cache=`echo $1 | sed 'y%.=/+-%___p_%'` 860AC_CACHE_VAL(cv_cc_deprecated_$cache, 861[ 862echo '$3' >conftest.c 863echo 'void f(){ $2 }' >>conftest.c 864if test -z "`$CC -c conftest.c 2>&1 | grep deprecated`"; then 865eval "cv_cc_deprecated_$cache=no" 866else 867eval "cv_cc_deprecated_$cache=yes" 868fi 869rm -f conftest conftest.o conftest.c 870]) 871if eval "test \"`echo '$cv_cc_deprecated_'$cache`\" = yes"; then 872AC_MSG_RESULT(yes) 873AC_DEFINE_UNQUOTED(AS_TR_CPP([DEPRECATED_$1]), 1, [Whether $1 is deprecated]) 874: 875$4 876else 877AC_MSG_RESULT(no) 878: 879$5 880fi 881])dnl end of ACX_FUNC_DEPRECATED 882 883dnl check if select and nonblocking sockets actually work. 884dnl Needs fork(2) and select(2). 885dnl defines NONBLOCKING_IS_BROKEN, and if that is true multiple reads from 886dnl a nonblocking socket do not work, a new call to select is necessary. 887AC_DEFUN([ACX_CHECK_NONBLOCKING_BROKEN], 888[ 889AC_MSG_CHECKING([if nonblocking sockets work]) 890if echo $target | grep mingw32 >/dev/null; then 891 AC_MSG_RESULT([no (windows)]) 892 AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).]) 893else 894AC_RUN_IFELSE([ 895AC_LANG_SOURCE([[ 896#include <stdio.h> 897#include <string.h> 898#include <stdlib.h> 899#include <fcntl.h> 900#include <errno.h> 901#ifdef HAVE_SYS_TYPES_H 902#include <sys/types.h> 903#endif 904#ifdef HAVE_SYS_SOCKET_H 905#include <sys/socket.h> 906#endif 907#ifdef HAVE_NETINET_IN_H 908#include <netinet/in.h> 909#endif 910#ifdef HAVE_ARPA_INET_H 911#include <arpa/inet.h> 912#endif 913#ifdef HAVE_UNISTD_H 914#include <unistd.h> 915#endif 916#ifdef HAVE_TIME_H 917#include <time.h> 918#endif 919 920int main(void) 921{ 922 int port; 923 int sfd, cfd; 924 int num = 10; 925 int i, p; 926 struct sockaddr_in a; 927 /* test if select and nonblocking reads work well together */ 928 /* open port. 929 fork child to send 10 messages. 930 select to read. 931 then try to nonblocking read the 10 messages 932 then, nonblocking read must give EAGAIN 933 */ 934 935 port = 12345 + (time(0)%32); 936 sfd = socket(PF_INET, SOCK_DGRAM, 0); 937 if(sfd == -1) { 938 perror("socket"); 939 return 1; 940 } 941 memset(&a, 0, sizeof(a)); 942 a.sin_family = AF_INET; 943 a.sin_port = htons(port); 944 a.sin_addr.s_addr = inet_addr("127.0.0.1"); 945 if(bind(sfd, (struct sockaddr*)&a, sizeof(a)) < 0) { 946 perror("bind"); 947 return 1; 948 } 949 if(fcntl(sfd, F_SETFL, O_NONBLOCK) == -1) { 950 perror("fcntl"); 951 return 1; 952 } 953 954 cfd = socket(PF_INET, SOCK_DGRAM, 0); 955 if(cfd == -1) { 956 perror("client socket"); 957 return 1; 958 } 959 a.sin_port = 0; 960 if(bind(cfd, (struct sockaddr*)&a, sizeof(a)) < 0) { 961 perror("client bind"); 962 return 1; 963 } 964 a.sin_port = htons(port); 965 966 /* no handler, causes exit in 10 seconds */ 967 alarm(10); 968 969 /* send and receive on the socket */ 970 if((p=fork()) == 0) { 971 for(i=0; i<num; i++) { 972 if(sendto(cfd, &i, sizeof(i), 0, 973 (struct sockaddr*)&a, sizeof(a)) < 0) { 974 perror("sendto"); 975 return 1; 976 } 977 } 978 } else { 979 /* parent */ 980 fd_set rset; 981 int x; 982 if(p == -1) { 983 perror("fork"); 984 return 1; 985 } 986 FD_ZERO(&rset); 987 FD_SET(sfd, &rset); 988 if(select(sfd+1, &rset, NULL, NULL, NULL) < 1) { 989 perror("select"); 990 return 1; 991 } 992 i = 0; 993 while(i < num) { 994 if(recv(sfd, &x, sizeof(x), 0) != sizeof(x)) { 995 if(errno == EAGAIN) 996 continue; 997 perror("recv"); 998 return 1; 999 } 1000 i++; 1001 } 1002 /* now we want to get EAGAIN: nonblocking goodness */ 1003 errno = 0; 1004 recv(sfd, &x, sizeof(x), 0); 1005 if(errno != EAGAIN) { 1006 perror("trying to recv again"); 1007 return 1; 1008 } 1009 /* EAGAIN encountered */ 1010 } 1011 1012 close(sfd); 1013 close(cfd); 1014 return 0; 1015} 1016]])], [ 1017 AC_MSG_RESULT([yes]) 1018], [ 1019 AC_MSG_RESULT([no]) 1020 AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).]) 1021], [ 1022 AC_MSG_RESULT([crosscompile(yes)]) 1023]) 1024fi 1025])dnl End of ACX_CHECK_NONBLOCKING_BROKEN 1026 1027dnl Check if mkdir has one or two arguments. 1028dnl defines MKDIR_HAS_ONE_ARG 1029AC_DEFUN([ACX_MKDIR_ONE_ARG], 1030[ 1031AC_MSG_CHECKING([whether mkdir has one arg]) 1032AC_TRY_COMPILE([ 1033#include <stdio.h> 1034#include <unistd.h> 1035#ifdef HAVE_WINSOCK2_H 1036#include <winsock2.h> 1037#endif 1038#ifdef HAVE_SYS_STAT_H 1039#include <sys/stat.h> 1040#endif 1041], [ 1042 (void)mkdir("directory"); 1043], 1044AC_MSG_RESULT(yes) 1045AC_DEFINE(MKDIR_HAS_ONE_ARG, 1, [Define if mkdir has one argument.]) 1046, 1047AC_MSG_RESULT(no) 1048) 1049])dnl end of ACX_MKDIR_ONE_ARG 1050 1051dnl Check for ioctlsocket function. works on mingw32 too. 1052AC_DEFUN([ACX_FUNC_IOCTLSOCKET], 1053[ 1054# check ioctlsocket 1055AC_MSG_CHECKING(for ioctlsocket) 1056AC_LINK_IFELSE([AC_LANG_PROGRAM([ 1057#ifdef HAVE_WINSOCK2_H 1058#include <winsock2.h> 1059#endif 1060], [ 1061 (void)ioctlsocket(0, 0, NULL); 1062])], [ 1063AC_MSG_RESULT(yes) 1064AC_DEFINE(HAVE_IOCTLSOCKET, 1, [if the function 'ioctlsocket' is available]) 1065],[AC_MSG_RESULT(no)]) 1066])dnl end of ACX_FUNC_IOCTLSOCKET 1067 1068dnl detect malloc and provide malloc compat prototype. 1069dnl $1: unique name for compat code 1070AC_DEFUN([ACX_FUNC_MALLOC], 1071[ 1072 AC_MSG_CHECKING([for GNU libc compatible malloc]) 1073 AC_RUN_IFELSE([AC_LANG_PROGRAM( 1074[[#if defined STDC_HEADERS || defined HAVE_STDLIB_H 1075#include <stdlib.h> 1076#else 1077char *malloc (); 1078#endif 1079]], [ if(malloc(0) != 0) return 1;]) 1080], 1081 [AC_MSG_RESULT([no]) 1082 AC_LIBOBJ(malloc) 1083 AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] , 1084 [AC_MSG_RESULT([yes]) 1085 AC_DEFINE([HAVE_MALLOC], 1, [If have GNU libc compatible malloc])], 1086 [AC_MSG_RESULT([no (crosscompile)]) 1087 AC_LIBOBJ(malloc) 1088 AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.])] ) 1089]) 1090 1091dnl Define fallback for fseeko and ftello if needed. 1092AC_DEFUN([AHX_CONFIG_FSEEKO], 1093[ 1094#ifndef HAVE_FSEEKO 1095#define fseeko fseek 1096#define ftello ftell 1097#endif /* HAVE_FSEEKO */ 1098]) 1099 1100dnl Define RAND_MAX if not defined 1101AC_DEFUN([AHX_CONFIG_RAND_MAX], 1102[ 1103#ifndef RAND_MAX 1104#define RAND_MAX 2147483647 1105#endif 1106]) 1107 1108dnl Define MAXHOSTNAMELEN if not defined 1109AC_DEFUN([AHX_CONFIG_MAXHOSTNAMELEN], 1110[ 1111#ifndef MAXHOSTNAMELEN 1112#define MAXHOSTNAMELEN 256 1113#endif 1114]) 1115 1116dnl Define IPV6_MIN_MTU if not defined 1117AC_DEFUN([AHX_CONFIG_IPV6_MIN_MTU], 1118[ 1119#ifndef IPV6_MIN_MTU 1120#define IPV6_MIN_MTU 1280 1121#endif /* IPV6_MIN_MTU */ 1122]) 1123 1124dnl provide snprintf, vsnprintf compat prototype 1125dnl $1: unique name for compat code 1126AC_DEFUN([AHX_CONFIG_SNPRINTF], 1127[ 1128#ifndef HAVE_SNPRINTF 1129#define snprintf snprintf_$1 1130#define vsnprintf vsnprintf_$1 1131#include <stdarg.h> 1132int snprintf (char *str, size_t count, const char *fmt, ...); 1133int vsnprintf (char *str, size_t count, const char *fmt, va_list arg); 1134#endif /* HAVE_SNPRINTF */ 1135]) 1136 1137dnl provide inet_pton compat prototype. 1138dnl $1: unique name for compat code 1139AC_DEFUN([AHX_CONFIG_INET_PTON], 1140[ 1141#ifndef HAVE_INET_PTON 1142#define inet_pton inet_pton_$1 1143int inet_pton(int af, const char* src, void* dst); 1144#endif /* HAVE_INET_PTON */ 1145]) 1146 1147dnl provide inet_ntop compat prototype. 1148dnl $1: unique name for compat code 1149AC_DEFUN([AHX_CONFIG_INET_NTOP], 1150[ 1151#ifndef HAVE_INET_NTOP 1152#define inet_ntop inet_ntop_$1 1153const char *inet_ntop(int af, const void *src, char *dst, size_t size); 1154#endif 1155]) 1156 1157dnl provide inet_aton compat prototype. 1158dnl $1: unique name for compat code 1159AC_DEFUN([AHX_CONFIG_INET_ATON], 1160[ 1161#ifndef HAVE_INET_ATON 1162#define inet_aton inet_aton_$1 1163int inet_aton(const char *cp, struct in_addr *addr); 1164#endif 1165]) 1166 1167dnl provide memmove compat prototype. 1168dnl $1: unique name for compat code 1169AC_DEFUN([AHX_CONFIG_MEMMOVE], 1170[ 1171#ifndef HAVE_MEMMOVE 1172#define memmove memmove_$1 1173void *memmove(void *dest, const void *src, size_t n); 1174#endif 1175]) 1176 1177dnl provide strlcat compat prototype. 1178dnl $1: unique name for compat code 1179AC_DEFUN([AHX_CONFIG_STRLCAT], 1180[ 1181#ifndef HAVE_STRLCAT 1182#define strlcat strlcat_$1 1183size_t strlcat(char *dst, const char *src, size_t siz); 1184#endif 1185]) 1186 1187dnl provide strlcpy compat prototype. 1188dnl $1: unique name for compat code 1189AC_DEFUN([AHX_CONFIG_STRLCPY], 1190[ 1191#ifndef HAVE_STRLCPY 1192#define strlcpy strlcpy_$1 1193size_t strlcpy(char *dst, const char *src, size_t siz); 1194#endif 1195]) 1196 1197dnl provide gmtime_r compat prototype. 1198dnl $1: unique name for compat code 1199AC_DEFUN([AHX_CONFIG_GMTIME_R], 1200[ 1201#ifndef HAVE_GMTIME_R 1202#define gmtime_r gmtime_r_$1 1203struct tm *gmtime_r(const time_t *timep, struct tm *result); 1204#endif 1205]) 1206 1207dnl provide w32 compat definition for sleep 1208AC_DEFUN([AHX_CONFIG_W32_SLEEP], 1209[ 1210#ifndef HAVE_SLEEP 1211#define sleep(x) Sleep((x)*1000) /* on win32 */ 1212#endif /* HAVE_SLEEP */ 1213]) 1214 1215dnl provide w32 compat definition for usleep 1216AC_DEFUN([AHX_CONFIG_W32_USLEEP], 1217[ 1218#ifndef HAVE_USLEEP 1219#define usleep(x) Sleep((x)/1000 + 1) /* on win32 */ 1220#endif /* HAVE_USLEEP */ 1221]) 1222 1223dnl provide w32 compat definition for random 1224AC_DEFUN([AHX_CONFIG_W32_RANDOM], 1225[ 1226#ifndef HAVE_RANDOM 1227#define random rand /* on win32, for tests only (bad random) */ 1228#endif /* HAVE_RANDOM */ 1229]) 1230 1231dnl provide w32 compat definition for srandom 1232AC_DEFUN([AHX_CONFIG_W32_SRANDOM], 1233[ 1234#ifndef HAVE_SRANDOM 1235#define srandom(x) srand(x) /* on win32, for tests only (bad random) */ 1236#endif /* HAVE_SRANDOM */ 1237]) 1238 1239dnl provide w32 compat definition for FD_SET_T 1240AC_DEFUN([AHX_CONFIG_W32_FD_SET_T], 1241[ 1242/* detect if we need to cast to unsigned int for FD_SET to avoid warnings */ 1243#ifdef HAVE_WINSOCK2_H 1244#define FD_SET_T (u_int) 1245#else 1246#define FD_SET_T 1247#endif 1248]) 1249 1250dnl Remove an extension flag from CFLAGS, define replacement to be made. 1251dnl Used by ACX_STRIP_EXT_FLAGS. 1252dnl $1: the name of the flag, for example -D_GNU_SOURCE. 1253AC_DEFUN([ACX_CFLAGS_STRIP], 1254[ 1255 if echo $CFLAGS | grep " $1" >/dev/null 2>&1; then 1256 CFLAGS="`echo $CFLAGS | sed -e 's/ $1//g'`" 1257 AC_DEFINE(m4_bpatsubst(OMITTED_$1,[[-=]],_), 1, Put $1 define in config.h) 1258 fi 1259]) 1260 1261dnl Remove EXT flags from the CFLAGS and set them to be defined in config.h 1262dnl use with ACX_DETERMINE_EXT_FLAGS. 1263AC_DEFUN([ACX_STRIP_EXT_FLAGS], 1264[ 1265 AC_MSG_NOTICE([Stripping extension flags...]) 1266 ACX_CFLAGS_STRIP(-D_GNU_SOURCE) 1267 ACX_CFLAGS_STRIP(-D_BSD_SOURCE) 1268 ACX_CFLAGS_STRIP(-D__EXTENSIONS__) 1269 ACX_CFLAGS_STRIP(-D_POSIX_C_SOURCE=200112) 1270 ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE=600) 1271 ACX_CFLAGS_STRIP(-D_XOPEN_SOURCE_EXTENDED=1) 1272 ACX_CFLAGS_STRIP(-D_ALL_SOURCE) 1273 ACX_CFLAGS_STRIP(-D_LARGEFILE_SOURCE=1) 1274]) dnl End of ACX_STRIP_EXT_FLAGS 1275 1276dnl define one omitted flag for config.h 1277dnl $1: flag name. -D_GNU_SOURCE 1278dnl $2: replacement define. _GNU_SOURCE 1279dnl $3: define value, 1 1280AC_DEFUN([AHX_CONFIG_FLAG_OMITTED], 1281[#if defined($1) && !defined($2) 1282#define $2 $3 1283[#]endif ]) 1284 1285dnl Wrapper for AHX_CONFIG_FLAG_OMITTED for -D style flags 1286dnl $1: the -DNAME or -DNAME=value string. 1287AC_DEFUN([AHX_CONFIG_FLAG_EXT], 1288[AHX_CONFIG_FLAG_OMITTED(m4_bpatsubst(OMITTED_$1,[[-=]],_),m4_bpatsubst(m4_bpatsubst($1,-D,),=.*$,),m4_if(m4_bregexp($1,=),-1,1,m4_bpatsubst($1,^.*=,))) 1289]) 1290 1291dnl config.h part to define omitted cflags, use with ACX_STRIP_EXT_FLAGS. 1292AC_DEFUN([AHX_CONFIG_EXT_FLAGS], 1293[AHX_CONFIG_FLAG_EXT(-D_GNU_SOURCE) 1294AHX_CONFIG_FLAG_EXT(-D_BSD_SOURCE) 1295AHX_CONFIG_FLAG_EXT(-D__EXTENSIONS__) 1296AHX_CONFIG_FLAG_EXT(-D_POSIX_C_SOURCE=200112) 1297AHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE=600) 1298AHX_CONFIG_FLAG_EXT(-D_XOPEN_SOURCE_EXTENDED=1) 1299AHX_CONFIG_FLAG_EXT(-D_ALL_SOURCE) 1300AHX_CONFIG_FLAG_EXT(-D_LARGEFILE_SOURCE=1) 1301]) 1302 1303dnl check if memcmp is using signed characters and replace if so. 1304AC_DEFUN([ACX_CHECK_MEMCMP_SIGNED], 1305[AC_MSG_CHECKING([if memcmp compares unsigned]) 1306AC_RUN_IFELSE([AC_LANG_SOURCE([[ 1307#include <stdio.h> 1308#include <stdlib.h> 1309#include <string.h> 1310int main(void) 1311{ 1312 char a = 255, b = 0; 1313 if(memcmp(&a, &b, 1) < 0) 1314 return 1; 1315 return 0; 1316} 1317]])], [AC_MSG_RESULT([yes]) ], 1318[ AC_MSG_RESULT([no]) 1319 AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes]) 1320 AC_LIBOBJ([memcmp]) 1321], [ AC_MSG_RESULT([cross-compile no]) 1322 AC_DEFINE([MEMCMP_IS_BROKEN], [1], [Define if memcmp() does not compare unsigned bytes]) 1323 AC_LIBOBJ([memcmp]) 1324]) ]) 1325 1326dnl define memcmp to its replacement, pass unique id for program as arg 1327AC_DEFUN([AHX_MEMCMP_BROKEN], [ 1328#ifdef MEMCMP_IS_BROKEN 1329# ifdef memcmp 1330# undef memcmp 1331# endif 1332#define memcmp memcmp_$1 1333int memcmp(const void *x, const void *y, size_t n); 1334#endif 1335]) 1336 1337dnl ACX_CHECK_SS_FAMILY - check for sockaddr_storage.ss_family 1338AC_DEFUN([ACX_CHECK_SS_FAMILY], 1339[AC_CHECK_MEMBER([struct sockaddr_storage.ss_family], [], [ 1340 AC_CHECK_MEMBER([struct sockaddr_storage.__ss_family], [ 1341 AC_DEFINE([ss_family], [__ss_family], [Fallback member name for socket family in struct sockaddr_storage]) 1342 ],, [AC_INCLUDES_DEFAULT 1343#ifdef HAVE_NETINET_IN_H 1344#include <netinet/in.h> 1345#endif 1346#ifdef HAVE_SYS_SOCKET_H 1347#include <sys/socket.h> 1348#endif 1349#ifdef HAVE_NETDB_H 1350#include <netdb.h> 1351#endif 1352#ifdef HAVE_ARPA_INET_H 1353#include <arpa/inet.h> 1354#endif 1355 ]) 1356], [AC_INCLUDES_DEFAULT 1357#ifdef HAVE_NETINET_IN_H 1358#include <netinet/in.h> 1359#endif 1360#ifdef HAVE_SYS_SOCKET_H 1361#include <sys/socket.h> 1362#endif 1363#ifdef HAVE_NETDB_H 1364#include <netdb.h> 1365#endif 1366#ifdef HAVE_ARPA_INET_H 1367#include <arpa/inet.h> 1368#endif 1369]) ]) 1370 1371dnl End of file 1372