1 2dnl ********************************************************************** 3dnl CURL_DETECT_ICC ([ACTION-IF-YES]) 4dnl 5dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES 6dnl sets the $ICC variable to "yes" or "no" 7dnl ********************************************************************** 8AC_DEFUN([CURL_DETECT_ICC], 9[ 10 ICC="no" 11 AC_MSG_CHECKING([for icc in use]) 12 if test "$GCC" = "yes"; then 13 dnl check if this is icc acting as gcc in disguise 14 AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER], 15 dnl action if the text is found, this it has not been replaced by the 16 dnl cpp 17 ICC="no", 18 dnl the text was not found, it was replaced by the cpp 19 ICC="yes" 20 AC_MSG_RESULT([yes]) 21 [$1] 22 ) 23 fi 24 if test "$ICC" = "no"; then 25 # this is not ICC 26 AC_MSG_RESULT([no]) 27 fi 28]) 29 30dnl We create a function for detecting which compiler we use and then set as 31dnl pendantic compiler options as possible for that particular compiler. The 32dnl options are only used for debug-builds. 33 34AC_DEFUN([CURL_CC_DEBUG_OPTS], 35[ 36 if test "z$ICC" = "z"; then 37 CURL_DETECT_ICC 38 fi 39 40 if test "$GCC" = "yes"; then 41 42 dnl figure out gcc version! 43 AC_MSG_CHECKING([gcc version]) 44 gccver=`$CC -dumpversion` 45 num1=`echo $gccver | cut -d . -f1` 46 num2=`echo $gccver | cut -d . -f2` 47 gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null` 48 AC_MSG_RESULT($gccver) 49 50 if test "$ICC" = "yes"; then 51 dnl this is icc, not gcc. 52 53 dnl ICC warnings we ignore: 54 dnl * 269 warns on our "%Od" printf formatters for curl_off_t output: 55 dnl "invalid format string conversion" 56 dnl * 279 warns on static conditions in while expressions 57 dnl * 981 warns on "operands are evaluated in unspecified order" 58 dnl * 1418 "external definition with no prior declaration" 59 dnl * 1419 warns on "external declaration in primary source file" 60 dnl which we know and do on purpose. 61 62 WARN="-wd279,269,981,1418,1419" 63 64 if test "$gccnum" -gt "600"; then 65 dnl icc 6.0 and older doesn't have the -Wall flag 66 WARN="-Wall $WARN" 67 fi 68 else dnl $ICC = yes 69 dnl this is a set of options we believe *ALL* gcc versions support: 70 WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes" 71 72 dnl -Wcast-align is a bit too annoying on all gcc versions ;-) 73 74 if test "$gccnum" -ge "207"; then 75 dnl gcc 2.7 or later 76 WARN="$WARN -Wmissing-declarations" 77 fi 78 79 if test "$gccnum" -gt "295"; then 80 dnl only if the compiler is newer than 2.95 since we got lots of 81 dnl "`_POSIX_C_SOURCE' is not defined" in system headers with 82 dnl gcc 2.95.4 on FreeBSD 4.9! 83 WARN="$WARN -Wundef -Wno-long-long -Wsign-compare" 84 fi 85 86 if test "$gccnum" -ge "296"; then 87 dnl gcc 2.96 or later 88 WARN="$WARN -Wfloat-equal" 89 fi 90 91 if test "$gccnum" -gt "296"; then 92 dnl this option does not exist in 2.96 93 WARN="$WARN -Wno-format-nonliteral" 94 fi 95 96 dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on 97 dnl on i686-Linux as it gives us heaps with false positives. 98 dnl Also, on gcc 4.0.X it is totally unbearable and complains all 99 dnl over making it unusable for generic purposes. Let's not use it. 100 101 if test "$gccnum" -ge "303"; then 102 dnl gcc 3.3 and later 103 WARN="$WARN -Wendif-labels -Wstrict-prototypes" 104 fi 105 106 if test "$gccnum" -ge "304"; then 107 # try these on gcc 3.4 108 WARN="$WARN -Wdeclaration-after-statement" 109 fi 110 111 for flag in $CPPFLAGS; do 112 case "$flag" in 113 -I*) 114 dnl Include path, provide a -isystem option for the same dir 115 dnl to prevent warnings in those dirs. The -isystem was not very 116 dnl reliable on earlier gcc versions. 117 add=`echo $flag | sed 's/^-I/-isystem /g'` 118 WARN="$WARN $add" 119 ;; 120 esac 121 done 122 123 fi dnl $ICC = no 124 125 CFLAGS="$CFLAGS $WARN" 126 127 AC_MSG_NOTICE([Added this set of compiler options: $WARN]) 128 129 else dnl $GCC = yes 130 131 AC_MSG_NOTICE([Added no extra compiler options]) 132 133 fi dnl $GCC = yes 134 135 dnl strip off optimizer flags 136 NEWFLAGS="" 137 for flag in $CFLAGS; do 138 case "$flag" in 139 -O*) 140 dnl echo "cut off $flag" 141 ;; 142 *) 143 NEWFLAGS="$NEWFLAGS $flag" 144 ;; 145 esac 146 done 147 CFLAGS=$NEWFLAGS 148 149]) dnl end of AC_DEFUN() 150 151dnl CURL_CHECK_NONBLOCKING_SOCKET 152dnl ------------------------------------------------- 153dnl Check for how to set a socket to non-blocking state. There seems to exist 154dnl four known different ways, with the one used almost everywhere being POSIX 155dnl and XPG3, while the other different ways for different systems (old BSD, 156dnl Windows and Amiga). 157dnl 158dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the 159dnl O_NONBLOCK define is found but does not work. This condition is attempted 160dnl to get caught in this script by using an excessive number of #ifdefs... 161dnl 162AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET], 163[ 164 AC_MSG_CHECKING([non-blocking sockets style]) 165 166 AC_TRY_COMPILE([ 167/* headers for O_NONBLOCK test */ 168#include <sys/types.h> 169#include <unistd.h> 170#include <fcntl.h> 171],[ 172/* try to compile O_NONBLOCK */ 173 174#if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) 175# if defined(__SVR4) || defined(__srv4__) 176# define PLATFORM_SOLARIS 177# else 178# define PLATFORM_SUNOS4 179# endif 180#endif 181#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41) 182# define PLATFORM_AIX_V3 183#endif 184 185#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__) 186#error "O_NONBLOCK does not work on this platform" 187#endif 188 int socket; 189 int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK); 190],[ 191dnl the O_NONBLOCK test was fine 192nonblock="O_NONBLOCK" 193AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets]) 194],[ 195dnl the code was bad, try a different program now, test 2 196 197 AC_TRY_COMPILE([ 198/* headers for FIONBIO test */ 199#include <unistd.h> 200#include <stropts.h> 201],[ 202/* FIONBIO source test (old-style unix) */ 203 int socket; 204 int flags = ioctl(socket, FIONBIO, &flags); 205],[ 206dnl FIONBIO test was good 207nonblock="FIONBIO" 208AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets]) 209],[ 210dnl FIONBIO test was also bad 211dnl the code was bad, try a different program now, test 3 212 213 AC_TRY_COMPILE([ 214/* headers for ioctlsocket test (Windows) */ 215#undef inline 216#ifdef HAVE_WINDOWS_H 217#ifndef WIN32_LEAN_AND_MEAN 218#define WIN32_LEAN_AND_MEAN 219#endif 220#include <windows.h> 221#ifdef HAVE_WINSOCK2_H 222#include <winsock2.h> 223#else 224#ifdef HAVE_WINSOCK_H 225#include <winsock.h> 226#endif 227#endif 228#endif 229],[ 230/* ioctlsocket source code */ 231 SOCKET sd; 232 unsigned long flags = 0; 233 sd = socket(0, 0, 0); 234 ioctlsocket(sd, FIONBIO, &flags); 235],[ 236dnl ioctlsocket test was good 237nonblock="ioctlsocket" 238AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets]) 239],[ 240dnl ioctlsocket didnt compile!, go to test 4 241 242 AC_TRY_LINK([ 243/* headers for IoctlSocket test (Amiga?) */ 244#include <sys/ioctl.h> 245],[ 246/* IoctlSocket source code */ 247 int socket; 248 int flags = IoctlSocket(socket, FIONBIO, (long)1); 249],[ 250dnl ioctlsocket test was good 251nonblock="IoctlSocket" 252AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets]) 253],[ 254dnl Ioctlsocket didnt compile, do test 5! 255 AC_TRY_COMPILE([ 256/* headers for SO_NONBLOCK test (BeOS) */ 257#include <socket.h> 258],[ 259/* SO_NONBLOCK source code */ 260 long b = 1; 261 int socket; 262 int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); 263],[ 264dnl the SO_NONBLOCK test was good 265nonblock="SO_NONBLOCK" 266AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets]) 267],[ 268dnl test 5 didnt compile! 269nonblock="nada" 270AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets]) 271]) 272dnl end of fifth test 273 274]) 275dnl end of forth test 276 277]) 278dnl end of third test 279 280]) 281dnl end of second test 282 283]) 284dnl end of non-blocking try-compile test 285 AC_MSG_RESULT($nonblock) 286 287 if test "$nonblock" = "nada"; then 288 AC_MSG_WARN([non-block sockets disabled]) 289 fi 290]) 291 292dnl CURL_CHECK_NEED_REENTRANT_SYSTEM 293dnl ------------------------------------------------- 294dnl Checks if the preprocessor _REENTRANT definition 295dnl must be unconditionally done for this platform. 296dnl Internal macro for CURL_CONFIGURE_REENTRANT. 297 298AC_DEFUN([CURL_CHECK_NEED_REENTRANT_SYSTEM], [ 299 case $host in 300 *-*-solaris* | *-*-hpux*) 301 tmp_need_reentrant="yes" 302 ;; 303 *) 304 tmp_need_reentrant="no" 305 ;; 306 esac 307]) 308 309 310dnl CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT 311dnl ------------------------------------------------- 312dnl This macro ensures that configuration tests done 313dnl after this will execute with preprocessor symbol 314dnl _REENTRANT defined. This macro also ensures that 315dnl the generated config file defines NEED_REENTRANT 316dnl and that in turn setup.h will define _REENTRANT. 317dnl Internal macro for CURL_CONFIGURE_REENTRANT. 318 319AC_DEFUN([CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT], [ 320AC_DEFINE(NEED_REENTRANT, 1, 321 [Define to 1 if _REENTRANT preprocessor symbol must be defined.]) 322cat >>confdefs.h <<_EOF 323#ifndef _REENTRANT 324# define _REENTRANT 325#endif 326_EOF 327]) 328 329 330dnl CURL_CONFIGURE_REENTRANT 331dnl ------------------------------------------------- 332dnl This first checks if the preprocessor _REENTRANT 333dnl symbol is already defined. If it isn't currently 334dnl defined a set of checks are performed to verify 335dnl if its definition is required to make visible to 336dnl the compiler a set of *_r functions. Finally, if 337dnl _REENTRANT is already defined or needed it takes 338dnl care of making adjustments necessary to ensure 339dnl that it is defined equally for further configure 340dnl tests and generated config file. 341 342AC_DEFUN([CURL_CONFIGURE_REENTRANT], [ 343 AC_PREREQ([2.50])dnl 344 # 345 AC_MSG_CHECKING([if _REENTRANT is already defined]) 346 AC_COMPILE_IFELSE([ 347 AC_LANG_PROGRAM([[ 348 ]],[[ 349#ifdef _REENTRANT 350 int dummy=1; 351#else 352 force compilation error 353#endif 354 ]]) 355 ],[ 356 AC_MSG_RESULT([yes]) 357 tmp_reentrant_initially_defined="yes" 358 ],[ 359 AC_MSG_RESULT([no]) 360 tmp_reentrant_initially_defined="no" 361 ]) 362 # 363 if test "$tmp_reentrant_initially_defined" = "no"; then 364 AC_MSG_CHECKING([if _REENTRANT is actually needed]) 365 CURL_CHECK_NEED_REENTRANT_SYSTEM 366 367 if test "$tmp_need_reentrant" = "yes"; then 368 AC_MSG_RESULT([yes]) 369 else 370 AC_MSG_RESULT([no]) 371 fi 372 fi 373 # 374 AC_MSG_CHECKING([if _REENTRANT is onwards defined]) 375 if test "$tmp_reentrant_initially_defined" = "yes" || 376 test "$tmp_need_reentrant" = "yes"; then 377 CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT 378 AC_MSG_RESULT([yes]) 379 else 380 AC_MSG_RESULT([no]) 381 fi 382 # 383]) 384 385dnl LIBSSH2_LIB_HAVE_LINKFLAGS 386dnl -------------------------- 387dnl Wrapper around AC_LIB_HAVE_LINKFLAGS to also check $prefix/lib, if set. 388dnl 389dnl autoconf only checks $prefix/lib64 if gcc -print-search-dirs output 390dnl includes a directory named lib64. So, to find libraries in $prefix/lib 391dnl we append -L$prefix/lib to LDFLAGS before checking. 392dnl 393dnl For conveniece, $4 is expanded if [lib]$1 is found. 394 395AC_DEFUN([LIBSSH2_LIB_HAVE_LINKFLAGS], [ 396 libssh2_save_CPPFLAGS="$CPPFLAGS" 397 libssh2_save_LDFLAGS="$LDFLAGS" 398 399 if test "${with_lib$1_prefix+set}" = set; then 400 CPPFLAGS="$CPPFLAGS${CPPFLAGS:+ }-I${with_lib$1_prefix}/include" 401 LDFLAGS="$LDFLAGS${LDFLAGS:+ }-L${with_lib$1_prefix}/lib" 402 fi 403 404 AC_LIB_HAVE_LINKFLAGS([$1], [$2], [$3]) 405 406 LDFLAGS="$libssh2_save_LDFLAGS" 407 408 if test "$ac_cv_lib$1" = "yes"; then : 409 $4 410 else 411 CPPFLAGS="$libssh2_save_CPPFLAGS" 412 fi 413]) 414 415AC_DEFUN([LIBSSH2_CHECK_CRYPTO], [ 416if test "$use_crypto" = "auto" && test "$found_crypto" = "none" || test "$use_crypto" = "$1"; then 417m4_case([$1], 418[openssl], [ 419 LIBSSH2_LIB_HAVE_LINKFLAGS([ssl], [crypto], [#include <openssl/ssl.h>], [ 420 AC_DEFINE(LIBSSH2_OPENSSL, 1, [Use $1]) 421 LIBSREQUIRED="$LIBSREQUIRED${LIBSREQUIRED:+ }libssl libcrypto" 422 423 # Not all OpenSSL have AES-CTR functions. 424 libssh2_save_LIBS="$LIBS" 425 LIBS="$LIBS $LIBSSL" 426 AC_CHECK_FUNCS(EVP_aes_128_ctr) 427 LIBS="$libssh2_save_LIBS" 428 429 found_crypto="$1" 430 found_crypto_str="OpenSSL (AES-CTR: ${ac_cv_func_EVP_aes_128_ctr:-N/A})" 431 ]) 432], 433 434[libgcrypt], [ 435 LIBSSH2_LIB_HAVE_LINKFLAGS([gcrypt], [], [#include <gcrypt.h>], [ 436 AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use $1]) 437 found_crypto="$1" 438 ]) 439], 440 441[mbedtls], [ 442 LIBSSH2_LIB_HAVE_LINKFLAGS([mbedcrypto], [], [#include <mbedtls/version.h>], [ 443 AC_DEFINE(LIBSSH2_MBEDTLS, 1, [Use $1]) 444 LIBS="$LIBS -lmbedcrypto" 445 found_crypto="$1" 446 support_clear_memory=yes 447 ]) 448], 449 450[wincng], [ 451 # Look for Windows Cryptography API: Next Generation 452 453 AC_CHECK_HEADERS([ntdef.h ntstatus.h], [], [], [#include <windows.h>]) 454 AC_CHECK_DECLS([SecureZeroMemory], [], [], [#include <windows.h>]) 455 456 LIBSSH2_LIB_HAVE_LINKFLAGS([crypt32], [], [ 457 #include <windows.h> 458 #include <wincrypt.h> 459 ]) 460 LIBSSH2_LIB_HAVE_LINKFLAGS([bcrypt], [], [ 461 #include <windows.h> 462 #include <bcrypt.h> 463 ], [ 464 AC_DEFINE(LIBSSH2_WINCNG, 1, [Use $1]) 465 found_crypto="$1" 466 found_crypto_str="Windows Cryptography API: Next Generation" 467 support_clear_memory="$ac_cv_have_decl_SecureZeroMemory" 468 ]) 469], 470) 471 test "$found_crypto" = "none" && 472 crypto_errors="${crypto_errors}No $1 crypto library found! 473" 474fi 475]) 476 477 478dnl LIBSSH2_CHECK_OPTION_WERROR 479dnl ------------------------------------------------- 480dnl Verify if configure has been invoked with option 481dnl --enable-werror or --disable-werror, and set 482dnl shell variable want_werror as appropriate. 483 484AC_DEFUN([LIBSSH2_CHECK_OPTION_WERROR], [ 485 AC_BEFORE([$0],[LIBSSH2_CHECK_COMPILER])dnl 486 AC_MSG_CHECKING([whether to enable compiler warnings as errors]) 487 OPT_COMPILER_WERROR="default" 488 AC_ARG_ENABLE(werror, 489AC_HELP_STRING([--enable-werror],[Enable compiler warnings as errors]) 490AC_HELP_STRING([--disable-werror],[Disable compiler warnings as errors]), 491 OPT_COMPILER_WERROR=$enableval) 492 case "$OPT_COMPILER_WERROR" in 493 no) 494 dnl --disable-werror option used 495 want_werror="no" 496 ;; 497 default) 498 dnl configure option not specified 499 want_werror="no" 500 ;; 501 *) 502 dnl --enable-werror option used 503 want_werror="yes" 504 ;; 505 esac 506 AC_MSG_RESULT([$want_werror]) 507 508 if test X"$want_werror" = Xyes; then 509 CFLAGS="$CFLAGS -Werror" 510 fi 511]) 512 513