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