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