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