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