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