configure.ac (295343B)
1 # This file is part of libmicrohttpd. 2 # (C) 2006-2021 Christian Grothoff (and other contributing authors) 3 # (C) 2014-2024 Evgeny Grin (Karlson2k) 4 # 5 # libmicrohttpd is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published 7 # by the Free Software Foundation; either version 3, or (at your 8 # option) any later version. 9 # 10 # libmicrohttpd is distributed in the hope that it will be useful, but 11 # WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 # General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with libmicrohttpd; see the file COPYING. If not, write to the 17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 # Boston, MA 02110-1301, USA. 19 # 20 # 21 # Process this file with autoconf to produce a configure script. 22 # 23 # 24 AC_PREREQ([2.64]) 25 LT_PREREQ([2.4.0]) 26 AC_INIT([GNU libmicrohttpd2],[1.99.0],[libmicrohttpd@gnu.org]) 27 AC_CONFIG_AUX_DIR([build-aux]) 28 MHD_AUX_DIR='build-aux' # Must be set to the same value as in the previous line 29 AC_CONFIG_HEADERS([src/incl_priv/config/mhd_config.h]) 30 AC_CONFIG_MACRO_DIR([m4]) 31 m4_pattern_forbid([^_?MHD_[A-Z_]+_CC_])dnl 32 33 LIB_VER_CURRENT=0 34 LIB_VER_REVISION=0 35 LIB_VER_AGE=0 36 AC_SUBST([LIB_VER_CURRENT]) 37 AC_SUBST([LIB_VER_REVISION]) 38 AC_SUBST([LIB_VER_AGE]) 39 40 41 PACKAGE_VERSION_MAJOR='m4_car(m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))' 42 PACKAGE_VERSION_MINOR='m4_argn(2, m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))' 43 PACKAGE_VERSION_SUBMINOR='m4_argn(3, m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))' 44 AS_VAR_ARITH([MHD_W32_DLL_SUFF],[[$LIB_VER_CURRENT - $LIB_VER_AGE]]) 45 AC_SUBST([PACKAGE_VERSION_MAJOR]) 46 AC_SUBST([PACKAGE_VERSION_MINOR]) 47 AC_SUBST([PACKAGE_VERSION_SUBMINOR]) 48 AC_SUBST([MHD_W32_DLL_SUFF]) 49 50 CONF_FINAL_WARNS="" 51 52 MHD_LIB_CPPFLAGS="" 53 MHD_LIB_CFLAGS="" 54 MHD_LIB_LDFLAGS="" 55 MHD_LIBDEPS="" 56 # for pkg-config 57 MHD_REQ_PRIVATE='' 58 MHD_LIBDEPS_PKGCFG='' 59 60 AH_TOP([#ifndef MHD_SYS_OPTIONS_H 61 #error "mhd_config.h" must not be used directly 62 #error include "mhd_sys_options.h" wrapper instead 63 #endif /* ! MHD_SYS_OPTIONS_H */]) 64 65 AS_IF([test -z "$CC" && test -z "$CPP"], [ 66 AC_MSG_CHECKING([[whether z/OS special settings are required]]) 67 AS_IF([test `uname -s` = "OS/390"], 68 [ 69 # configure binaries for z/OS 70 AS_IF([test -z "$CC"], 71 [CC=`pwd`"/contrib/xcc" 72 chmod +x $CC || true]) 73 AS_IF([test -z "$CPP"], 74 CPP="c89 -E") 75 AC_MSG_RESULT([[yes]]) 76 ], 77 [AC_MSG_RESULT([[no]])] 78 ) 79 ]) 80 81 82 AC_MSG_CHECKING([for build type]) 83 AC_ARG_ENABLE([build-type], 84 [AS_HELP_STRING([[--enable-build-type=TYPE]], 85 [enable build TYPE, a set of configuration parameters; individual settings ] 86 [(asserts, sanitizers, compiler and linker flags) can be overridden by ] 87 [additional configure parameters (debug, debugger, neutral, release, release-compact, ] 88 [release-hardened) [neutral]])], 89 [], [enable_build_type=neutral]) 90 AS_IF([test "x${enable_build_type}" = "x"], [enable_build_type="neutral"]) 91 AS_VAR_IF([enable_build_type], ["no"], [enable_build_type="neutral"]) 92 AS_VAR_IF([enable_build_type], ["yes"], [AC_MSG_ERROR([[Missing TYPE for --enable-build-type=]])]) 93 AS_CASE([${enable_build_type}], 94 [debug], [AC_MSG_RESULT([debug. Defaults: enable asserts, sanitizers (if any supported), debug information, compiler optimisation for debugging])], 95 [debugger], [AC_MSG_RESULT([debugger. Defaults: enable asserts, disable sanitizers, debug information, no compiler optimisation, static lib])], 96 [neutral], [AC_MSG_RESULT([neutral. Defaults: use only user-specified compiler and linker flags])], 97 [release], [AC_MSG_RESULT([release. Defaults: disable asserts, enable compiler optimisations])], 98 [release-compact], [AC_MSG_RESULT([release-compact. Defaults: disable asserts, enable compiler optimisations for size, enable compact code])], 99 [release-hardened], [AC_MSG_RESULT([release-hardened. Defaults: disable asserts, enable compiler optimisations, enable linker and compiler hardening])], 100 [AC_MSG_ERROR([[Unknown build type: ${enable_build_type}]])] 101 ) 102 AS_VAR_IF([enable_build_type], ["neutral"], [:], 103 [ 104 # For all non-neutral build types do not use automatic "-g -O2" for CFLAGS 105 AS_IF([test -z "${CFLAGS}"], [CFLAGS=""]) 106 ] 107 ) 108 AS_VAR_IF([enable_build_type], ["debugger"], 109 [ # Build only static version unless something else is specified by the user 110 AS_IF([test -z "${enable_static}" || test "x${enable_static}" = "xyes"], 111 [ 112 AS_IF([test -z "${enable_shared}"], 113 [ 114 enable_shared="no" 115 enable_static="yes" 116 ] 117 ) 118 ], 119 [ 120 AS_CASE([${enable_static}],[*libmicrohttpd*], 121 [AS_IF([test -z "${enable_shared}"], [enable_shared="no"])], 122 ) 123 ] 124 ) 125 ] 126 ) 127 AS_CASE([${enable_build_type}],[debug|debugger], 128 [ AS_IF([test -z "${enable_silent_rules}"], [ enable_silent_rules="yes" ])] 129 ) 130 131 AM_INIT_AUTOMAKE([gnu] [check-news] [filename-length-max=99] [tar-v7] [silent-rules] [subdir-objects]) 132 133 # Checks for programs. 134 AC_PROG_AWK 135 AC_PROG_GREP 136 AC_PROG_FGREP 137 AC_PROG_INSTALL 138 AC_PROG_LN_S 139 AC_PROG_MAKE_SET 140 AC_CANONICAL_HOST 141 m4_version_prereq([2.70], 142 [ 143 # Find C compiler and compiler options to support 144 # the latest C standard (C11). Fallback to C99 and C89 145 # if later C versions are not supported. 146 AC_PROG_CC 147 ], 148 [ 149 # Find C compiler and compiler options to support 150 # the latest C standard (C99). Fallback to C89 151 # if later C versions are not supported. 152 AC_PROG_CC_STDC 153 ] 154 ) 155 156 user_CFLAGS="$CFLAGS" 157 user_LDFLAGS="$LDFLAGS" 158 user_CPPFLAGS="$CPPFLAGS" 159 160 CFLAGS_ac="" 161 LDFLAGS_ac="" 162 CPPFLAGS_ac="" 163 164 MHD_SYS_EXT([CPPFLAGS_ac]) 165 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 166 m4_version_prereq([2.72], 167 [ 168 AC_SYS_YEAR2038 169 ], 170 [ 171 AC_SYS_LARGEFILE 172 ] 173 ) 174 AC_FUNC_FSEEKO 175 LT_INIT([win32-dll]) 176 LT_LANG([Windows Resource]) 177 178 AC_LANG_CONFTEST([AC_LANG_SOURCE([[ 179 ]AC_INCLUDES_DEFAULT[ 180 #include <stdio.h> 181 182 int main (int argc, char *argv[]) 183 { 184 if (1 <= argc) 185 return (0 < printf ("Self-name: %s\n", argv[0])) ? 0 : 1; 186 return 2; 187 } 188 ]] 189 ) 190 ] 191 ) 192 AC_CACHE_CHECK([whether $CC compiles simple C code without warnings], 193 [mhd_cv_cc_warnless_c_noflags], 194 [ 195 ac_c_werror_flag="yes" 196 AC_LINK_IFELSE([],[mhd_cv_cc_warnless_c_noflags="yes"], 197 [mhd_cv_cc_warnless_c_noflags="no"]) 198 ac_c_werror_flag="" 199 ] 200 ) 201 AS_VAR_IF([mhd_cv_cc_warnless_c_noflags],["yes"], 202 [mhd_cv_cc_warnless_c_flags=""], 203 [ 204 AC_CACHE_CHECK([for $CC flags to mute warnings for simple C code], 205 [mhd_cv_cc_warnless_c_flags], 206 [ 207 mhd_cv_cc_warnless_c_flags="no" 208 ac_c_werror_flag="yes" 209 for flag_chk in '-Wno-deprecated' '-fpermissive' 210 do 211 CFLAGS="${CFLAGS_ac} ${flag_chk} ${user_CFLAGS}" 212 AC_LINK_IFELSE([],[mhd_cv_cc_warnless_c_flags="${flag_chk}"]) 213 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 214 test "X${mhd_cv_cc_warnless_c_flags}" = "Xno" || break 215 done 216 AS_UNSET([flag_chk]) 217 ac_c_werror_flag="" 218 ] 219 ) 220 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:], 221 [MHD_PREPEND_FLAG_TO_VAR([user_CFLAGS],[${mhd_cv_cc_warnless_c_flags}])] 222 ) 223 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 224 ] 225 ) 226 rm -f conftest.$ac_ext 227 228 AC_ARG_ENABLE([compact-code], 229 [AS_HELP_STRING([[--enable-compact-code]], 230 [enable use of a reduced size version of the code, resulting in smaller ] 231 [binaries with a slight performance hit [auto]])], 232 [], [enable_compact_code=auto]) 233 AS_IF([test "x${enable_compact_code}" = "x"], [enable_compact_code="auto"]) 234 AH_TEMPLATE([[MHD_FAVOR_SMALL_CODE]], [Define to '1' to use compact code version]) 235 AH_TEMPLATE([[MHD_FAVOR_FAST_CODE]], [Define to '1' to use fast (and larger) code version]) 236 AS_UNSET([compact_code_MSG]) 237 AS_CASE([${enable_compact_code}], [auto], 238 [ 239 # Parameter not set. 240 # Check preprocessor macros 241 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE], 242 [ 243 enable_compact_code="yes" 244 compact_code_MSG="enabled by preprocessor macro" 245 ], 246 [],[/* no includes */] 247 ) 248 AC_CHECK_DECL([MHD_FAVOR_FAST_CODE], 249 [ 250 AS_VAR_IF([enable_compact_code],["yes"], 251 [AC_MSG_ERROR([Both MHD_FAVOR_SMALL_CODE and MHD_FAVOR_FAST_CODE macros are defined])] 252 ) 253 enable_compact_code="no" 254 compact_code_MSG="set by preprocessor macro" 255 ],[],[/* no includes */] 256 ) 257 258 AS_VAR_IF([enable_compact_code], ["auto"], 259 [ 260 # No preference by preprocessor macros 261 AC_CACHE_CHECK([whether compiler is configured to optimize for size], 262 [mhd_cv_cc_optim_size], 263 [ 264 AC_COMPILE_IFELSE( 265 [ 266 AC_LANG_PROGRAM([[ 267 #ifndef __OPTIMIZE_SIZE__ 268 #error Looks like compiler does not optimize for size 269 choke me now 270 #endif 271 ]],[]) 272 ], 273 [mhd_cv_cc_optim_size="yes"],[mhd_cv_cc_optim_size="no"] 274 ) 275 ] 276 ) 277 AS_VAR_IF([mhd_cv_cc_optim_size], ["yes"], 278 [ 279 enable_compact_code="yes" 280 compact_code_MSG="enabled automatically as compiler optimizes for size" 281 AC_DEFINE([MHD_FAVOR_SMALL_CODE],[1]) 282 ] 283 ) 284 ] 285 ) 286 287 AS_VAR_IF([enable_compact_code], ["auto"], 288 [ 289 # No preference by preprocessor macros and compiler flags 290 AS_CASE([${enable_build_type}],[*-compact], 291 [ 292 enable_compact_code="yes" 293 compact_code_MSG="enabled by --enable-build-type=${enable_build_type}" 294 AC_DEFINE([MHD_FAVOR_SMALL_CODE],[1]) 295 ] 296 ) 297 ] 298 ) 299 300 AS_VAR_IF([enable_compact_code], ["auto"], 301 [ 302 # No preference 303 enable_compact_code="no" 304 compact_code_MSG="by default" 305 AC_DEFINE([MHD_FAVOR_FAST_CODE],[1]) 306 ] 307 ) 308 ], 309 [yes], 310 [ 311 compact_code_MSG="enabled by configure parameter" 312 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE], 313 [], 314 [AC_DEFINE([MHD_FAVOR_SMALL_CODE],[1])],[/* no includes */] 315 ) 316 AC_CHECK_DECL([MHD_FAVOR_FAST_CODE], 317 [AC_MSG_ERROR([MHD_FAVOR_FAST_CODE macro is defined, --enable-compact-code could not be used]) 318 ], 319 [],[/* no includes */] 320 ) 321 ], 322 [no], 323 [ 324 compact_code_MSG="disabled by configure parameter" 325 AC_CHECK_DECL([MHD_FAVOR_FAST_CODE], 326 [], 327 [AC_DEFINE([MHD_FAVOR_FAST_CODE],[1])],[/* no includes */] 328 ) 329 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE], 330 [AC_MSG_ERROR([MHD_FAVOR_SMALL_CODE macro is defined, --disable-compact-code could not be used]) 331 ], 332 [],[/* no includes */] 333 ) 334 ], 335 [AC_MSG_ERROR([[Unknown parameter value: --enable-compact-code=${enable_compact_code}]])] 336 ) 337 338 AC_MSG_CHECKING([whether to use a reduced size version of the code]) 339 AC_MSG_RESULT([${enable_compact_code} (${compact_code_MSG})]) 340 341 342 CFLAGS="${user_CFLAGS}" 343 # Compiler options to always enable (if supported) 344 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-fno-strict-aliasing], [-qnoansialias]) 345 # '-qlonglong' is XLC option for C89, not used with C99 or later 346 MHD_CHECK_ADD_CC_CFLAG([-qlonglong], [CFLAGS_ac]) 347 348 # Set basic optimisation flags 349 AS_VAR_IF([enable_build_type],["neutral"],[], 350 [ # Any non-neutral build types 351 AC_CACHE_CHECK([whether workarounds for clang or clang-based compiler are required], 352 [mhd_cv_cc_clang_based], 353 [ 354 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 355 #if ! defined(__clang__) && ! defined(__llvm__) 356 #error Compiler is not clang-based 357 choke me now 358 #endif 359 ]] 360 ) 361 ], 362 [mhd_cv_cc_clang_based="yes"],[mhd_cv_cc_clang_based="no"] 363 ) 364 ] 365 ) 366 ] 367 ) 368 AS_CASE([${enable_build_type}],[debug|debugger], 369 [ # Debug build or build for walking with debugger 370 CFLAGS="${user_CFLAGS}" 371 AS_VAR_IF([enable_build_type],["debug"], 372 [ 373 # Clang has ASAN (pointer compare) broken when '-Og' optimisations are used 374 AS_IF([test "x${enable_sanitizers}" != "xno" && test "x${mhd_cv_cc_clang_based}" = "xyes"], 375 [MHD_CHECK_ADD_CC_CFLAG([-O0], [CFLAGS_ac])], 376 [MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Og], [-O0])] 377 ) 378 ], 379 [MHD_CHECK_ADD_CC_CFLAG([-O0], [CFLAGS_ac])] 380 ) 381 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 382 ] 383 ) 384 AS_CASE([${enable_build_type}],[release|release-*], 385 [ # All release types 386 AS_VAR_IF([enable_build_type],["release-compact"], 387 [ 388 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 389 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],[], 390 [AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],[], 391 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DMHD_FAVOR_SMALL_CODE=1])], 392 [/* no includes */])],[/* no includes */]) 393 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 394 CFLAGS="${user_CFLAGS}" 395 MHD_FIND_ADD_CC_CFLAG_IFELSE( 396 [AC_DEFINE([MHD_CC_OPTIMISE_FOR_SIZE],[1],[Define to 1 if compiler optimises binary for size])], 397 [], 398 [CFLAGS_ac], [-Oz], [-Os], [-xO3], [-O] 399 ) 400 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 401 ], 402 [ # All non-compact release types 403 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 404 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],[], 405 [AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],[], 406 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DMHD_FAVOR_FAST_CODE=1])], 407 [/* no includes */])],[/* no includes */]) 408 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 409 CFLAGS="${user_CFLAGS}" 410 MHD_FIND_ADD_CC_CFLAG_IFELSE( 411 [AC_DEFINE([MHD_CC_OPTIMISE_FOR_SPEED],[1],[Define to 1 if compiler optimises binary for speed])], 412 [], 413 [CFLAGS_ac], [-O2], [-xO4], [-O] 414 ) 415 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 416 ] 417 ) 418 ] 419 ) 420 421 AS_VAR_IF([enable_build_type],["neutral"],[], 422 [ # Any non-neutral build types 423 MHD_CHECK_ADD_CC_CFLAGS([-Wall -Wnull-dereference], [CFLAGS_ac]) 424 MHD_CHECK_ADD_CC_CFLAGS([-Wdeclaration-after-statement -Wimplicit -Wnested-externs], [CFLAGS_ac]) 425 MHD_CHECK_ADD_CC_CFLAGS([-Wredundant-decls -Wtrampolines -Wunsafe-loop-optimizations], [CFLAGS_ac]) 426 MHD_CHECK_ADD_CC_CFLAGS([-Wpoison-system-directories], [CFLAGS_ac]) 427 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 428 LDFLAGS="${user_LDFLAGS}" 429 MHD_CHECK_ADD_CC_LDFLAG([-Wl,--warn-common], [LDFLAGS_ac]) 430 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 431 ] 432 ) 433 AS_CASE([${enable_build_type}],[debug|debugger], 434 [ # Debug build or build for walking with debugger 435 CFLAGS="${user_CFLAGS}" 436 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-ggdb3], [-g3], [-ggdb], [-g]) 437 MHD_CHECK_ADD_CC_CFLAG([-Wextra], [CFLAGS_ac]) 438 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wpedantic], [-pedantic]) 439 save_find_CFLAGS_ac="$CFLAGS_ac" 440 MHD_FIND_ADD_CC_CFLAG_IFELSE( 441 [ 442 AC_CACHE_CHECK([whether format warnings work with v*printf() functions], 443 [mhd_cv_wformat_works_vfprintf], 444 [ 445 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 446 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 447 AC_COMPILE_IFELSE( 448 [ 449 AC_LANG_SOURCE([[ 450 #include <stdio.h> 451 #include <stdarg.h> 452 453 static int 454 my_vprint (const char *fm, va_list ap) 455 { 456 return vfprintf (stderr, fm, ap); 457 } 458 459 static int 460 my_printf (const char *fm, ...) 461 { 462 int res; 463 va_list vargs; 464 va_start (vargs, fm); 465 res = my_vprint(fm, vargs); 466 va_end (vargs); 467 return res; 468 } 469 470 int main(void) 471 { 472 const char *pnt_str = "printf string\n"; 473 return (0 < my_printf (pnt_str)) ? 0 : 5; 474 } 475 ]] 476 ) 477 ], 478 [mhd_cv_wformat_works_vfprintf="yes"], 479 [mhd_cv_wformat_works_vfprintf="no"] 480 ) 481 CFLAGS="${user_CFLAGS}" 482 ac_c_werror_flag="" 483 ] 484 ) 485 AS_VAR_IF([mhd_cv_wformat_works_vfprintf],["no"], 486 [ 487 # Check whether "enable" flag is supported as "disable" flag could be silently 488 # accepted when the compiled code itself does not produce any warnings 489 MHD_CHECK_CC_CFLAG([-Wformat-nonliteral],[CFLAGS_ac], 490 [ 491 MHD_CHECK_ADD_CC_CFLAG([-Wno-format-nonliteral],[CFLAGS_ac], 492 [],[CFLAGS_ac="$save_find_CFLAGS_ac"] 493 ) 494 ],[CFLAGS_ac="$save_find_CFLAGS_ac"] 495 ) 496 ] 497 ) 498 ],[], 499 [CFLAGS_ac], [-Wformat=2], [-Wformat] 500 ) 501 AS_UNSET([save_find_CFLAGS_ac]) 502 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wimplicit-fallthrough=3], [-Wimplicit-fallthrough]) 503 MHD_CHECK_ADD_CC_CFLAGS([-Wformat-overflow -Wformat-truncation -Wformat-security -Wformat-signedness], [CFLAGS_ac]) 504 MHD_CHECK_ADD_CC_CFLAG([-Wdouble-promotion], [CFLAGS_ac]) 505 MHD_CHECK_ADD_CC_CFLAGS([-Wmissing-include-dirs -Wshift-overflow=2 -Wstringop-overflow=4 -Walloc-zero], [CFLAGS_ac]) 506 MHD_CHECK_ADD_CC_CFLAGS([-Wduplicated-branches -Wduplicated-cond -Wfloat-equal -Wpointer-arith], [CFLAGS_ac]) 507 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wshadow-all], [-Wshadow]) 508 MHD_CHECK_ADD_CC_CFLAGS([-Wbad-function-cast -Wcast-qual -Wwrite-strings -Wconversion], [CFLAGS_ac]) 509 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wcast-align=strict], [-Wcast-align]) 510 MHD_CHECK_ADD_CC_CFLAGS([-Wjump-misses-init -Wlogical-op -Waggregate-return -Wstrict-prototypes], [CFLAGS_ac]) 511 MHD_CHECK_ADD_CC_CFLAGS([-Wold-style-definition -Wmissing-declarations -Wmissing-prototypes], [CFLAGS_ac]) 512 MHD_CHECK_ADD_CC_CFLAGS([-Wuninitialized -Winit-self -Wshift-negative-value -Wswitch-enum], [CFLAGS_ac]) 513 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wstrict-overflow=4], [-Wstrict-overflow]) 514 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wnormalized=nfkc], [-Wnormalized]) 515 MHD_CHECK_ADD_CC_CFLAGS([-Walloca -Wbidi-chars=any -Warray-bounds -Wpacked -Wvariadic-macros], [CFLAGS_ac]) 516 MHD_CHECK_ADD_CC_CFLAGS([-Wundef], [CFLAGS_ac]) 517 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wtrailing-whitespace=any], [-Wtrailing-whitespace]) 518 519 MHD_CHECK_ADD_CC_CFLAGS([-Wanon-enum-enum-conversion -Warray-bounds-pointer-arithmetic -Wassign-enum], [CFLAGS_ac]) 520 MHD_CHECK_ADD_CC_CFLAGS([-Wbit-int-extension -Wbitfield-enum-conversion -Wparentheses -Wbool-operation], [CFLAGS_ac]) 521 MHD_CHECK_ADD_CC_CFLAGS([-Wcast-function-type -Wcomma -Wcomment -Wcompound-token-split], [CFLAGS_ac]) 522 MHD_CHECK_ADD_CC_CFLAGS([-Wconditional-uninitialized -Wdeprecated], [CFLAGS_ac]) 523 MHD_CHECK_ADD_CC_CFLAGS([-Wdocumentation -Wdocumentation-pedantic], [CFLAGS_ac]) 524 MHD_CHECK_ADD_CC_CFLAGS([-Wempty-init-stmt -Wenum-conversion -Wexpansion-to-defined], [CFLAGS_ac]) 525 MHD_CHECK_ADD_CC_CFLAGS([-Wflexible-array-extensions -Wloop-analysis -Wfour-char-constants -Wgcc-compat], [CFLAGS_ac]) 526 MHD_CHECK_ADD_CC_CFLAGS([-Wformat-pedantic -Wformat-non-iso -Wformat-type-confusion], [CFLAGS_ac]) 527 MHD_CHECK_ADD_CC_CFLAG([-Wgnu], [CFLAGS_ac], 528 [], 529 [ 530 MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-anonymous-struct -Wgnu-compound-literal-initializer], [CFLAGS_ac]) 531 MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-conditional-omitted-operand -Wgnu-designator -Wgnu-empty-initializer], [CFLAGS_ac]) 532 MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-empty-struct -Wgnu-flexible-array-initializer -Wgnu-folding-constant], [CFLAGS_ac]) 533 MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-null-pointer-arithmetic -Wgnu-pointer-arith -Wgnu-redeclared-enum], [CFLAGS_ac]) 534 MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-union-cast -Wgnu-variable-sized-type-not-at-end], [CFLAGS_ac]) 535 ] 536 ) 537 MHD_CHECK_ADD_CC_CFLAGS([-Wmissing-noreturn -Wmissing-variable-declarations -Wnested-anon-types], [CFLAGS_ac]) 538 MHD_CHECK_ADD_CC_CFLAGS([-Wnewline-eof -Wover-aligned -Wredundant-parens -Widiomatic-parentheses], [CFLAGS_ac]) 539 MHD_CHECK_ADD_CC_CFLAGS([-Wshift-sign-overflow -Wtautological-compare -Wunaligned-access], [CFLAGS_ac]) 540 MHD_CHECK_ADD_CC_CFLAGS([-Wunused -Wzero-as-null-pointer-constant -Wzero-length-array], [CFLAGS_ac]) 541 MHD_CHECK_ADD_CC_CFLAGS([-Waarch64-sme-attributes -Watomic-implicit-seq-cst -Warray-parameter], [CFLAGS_ac]) 542 MHD_CHECK_ADD_CC_CFLAGS([-Wc++-compat -Wc23-compat -Wcalled-once-parameter -Wdecls-in-multiple-modules], [CFLAGS_ac]) 543 MHD_CHECK_ADD_CC_CFLAGS([-Wduplicate-decl-specifier -Wduplicate-enum -Wembedded-directive], [CFLAGS_ac]) 544 MHD_CHECK_ADD_CC_CFLAGS([-Wfunction-effects -Wignored-qualifiers -Wnonportable-system-include-path], [CFLAGS_ac]) 545 MHD_CHECK_ADD_CC_CFLAGS([-Wincompatible-function-pointer-types-strict -Wmain -Wmain-return-type], [CFLAGS_ac]) 546 MHD_CHECK_ADD_CC_CFLAGS([-Wnullable-to-nonnull-conversion -Woverlength-strings -Wpragmas], [CFLAGS_ac]) 547 MHD_CHECK_ADD_CC_CFLAGS([-Wreserved-identifier -Wshift-bool -Wstatic-in-inline -Wswitch-default], [CFLAGS_ac]) 548 MHD_CHECK_ADD_CC_CFLAGS([-Wthread-safety -Wunused-function], [CFLAGS_ac]) 549 MHD_CHECK_CC_CFLAG([-Wused-but-marked-unused],[CFLAGS_ac], 550 [ 551 AC_CACHE_CHECK([whether $[]CC -Wused-but-marked-unused works with system headers], 552 [mhd_cv_wused_but_marked_unused_sys_header], 553 [ 554 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 555 CFLAGS="${CFLAGS_ac} -Wused-but-marked-unused ${user_CFLAGS}" 556 AC_COMPILE_IFELSE( 557 [ 558 AC_LANG_SOURCE([[ 559 #include <stdio.h> 560 561 int main(void) 562 { 563 char buf[16]; 564 return (int) snprintf(buf, 16, "test"); 565 } 566 ]] 567 ) 568 ], 569 [mhd_cv_wused_but_marked_unused_sys_header="yes"], 570 [mhd_cv_wused_but_marked_unused_sys_header="no"] 571 ) 572 ac_c_werror_flag="" 573 ] 574 ) 575 AS_VAR_IF([mhd_cv_wused_but_marked_unused_sys_header],["yes"], 576 [MHD_APPEND_FLAG_TO_VAR([CFLAGS_ac],[-Wused-but-marked-unused])] 577 ) 578 ] 579 ) 580 # Check whether "enable" flag is supported as "disable" flag could be silently 581 # accepted when the compiled code itself does not produce any warnings 582 MHD_CHECK_CC_CFLAG([-Wunreachable-code-break],[CFLAGS_ac], 583 [MHD_CHECK_ADD_CC_CFLAG([-Wno-unreachable-code-break], [CFLAGS_ac])] 584 ) 585 # 586 # Removed flags: 587 # 588 # -Wdisabled-macro-expansion - warns about macros from system headers 589 590 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 591 LDFLAGS="${user_LDFLAGS}" 592 MHD_CHECK_ADD_CC_LDFLAG([-Wl,--enable-long-section-names], [LDFLAGS_ac]) 593 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 594 ] 595 ) 596 AS_CASE([${enable_build_type}],[release|release-*], 597 [ # All release types 598 CFLAGS="${user_CFLAGS}" 599 MHD_CHECK_ADD_CC_CFLAGS([-floop-block -fgraphite-identity -floop-parallelize-all], [CFLAGS_ac]) 600 AS_VAR_IF([enable_build_type],["release-compact"], 601 [], 602 [ # All non-compact release types 603 MHD_CHECK_ADD_CC_CFLAGS([-fsched-pressure -fira-loop-pressure -fmerge-all-constants], [CFLAGS_ac]) # These flags may improve size, recheck with LTO and linker garbage collection 604 MHD_CHECK_ADD_CC_CFLAGS([-ftree-partial-pre -fgcse-after-reload -fipa-pta], [CFLAGS_ac]) 605 MHD_CHECK_ADD_CC_CFLAGS([-fisolate-erroneous-paths-attribute -ffinite-loops -floop-nest-optimize], [CFLAGS_ac]) 606 MHD_CHECK_ADD_CC_CFLAGS([-fpredictive-commoning -frename-registers], [CFLAGS_ac]) 607 MHD_CHECK_ADD_CC_CFLAGS([-ftree-loop-distribute-patterns -fpeel-loops -fsplit-loops -ftree-vectorize], [CFLAGS_ac]) 608 ] 609 ) 610 611 AS_VAR_IF([enable_build_type],["release-hardened"], 612 [ 613 MHD_CHECK_ADD_CC_CFLAGS([-Wformat-security -Wstack-protector], [CFLAGS_ac]) 614 MHD_CHECK_ADD_CC_CFLAGS([-Wuninitialized -Winit-self -Walloc-zero -Wbidi-chars=any], [CFLAGS_ac]) 615 ], 616 [ 617 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-fno-plt], [-mno-plt], [-Gy]) 618 MHD_CHECK_ADD_CC_CFLAGS([-fno-semantic-interposition], [CFLAGS_ac]) 619 ] 620 ) 621 AS_VAR_IF([enable_build_type],["release"], 622 [ # Flags are not suitable for 'compact' and for 'hardened' 623 MHD_CHECK_ADD_CC_CFLAGS([-ffast-math -fno-trapping-math], [CFLAGS_ac]) 624 ] 625 ) 626 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 627 LDFLAGS="${user_LDFLAGS}" 628 MHD_FIND_ADD_CC_LDFLAG([LDFLAGS_ac], [-Wl,-O2], [-Wl,-O1]) 629 MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--as-needed], [LDFLAGS_ac]) 630 AS_VAR_IF([enable_build_type],["release-hardened"], 631 [:], 632 [MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--gc-sections -Wl,--icf=all], [LDFLAGS_ac])] 633 ) 634 # W32-specific 635 MHD_CHECK_ADD_CC_LDFLAG([-Wl,--disable-long-section-names], [LDFLAGS_ac]) 636 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 637 ] 638 ) 639 CFLAGS="${user_CFLAGS}" 640 MHD_CHECK_CC_CFLAG([-Wused-but-marked-unused],[CFLAGS_ac], 641 [ 642 AC_DEFINE([[HAVE_WUSED_BUT_MARKED_UNUSED]],[[1]],[Define to '1' i][f -Wused-but-marked-unused flag is supported by compiler]) 643 ] 644 ) 645 MHD_CHECK_CC_CFLAG([-Wzero-as-null-pointer-constant],[CFLAGS_ac], 646 [ 647 AC_DEFINE([[HAVE_WZERO_AS_NULL_POINTER_CONSTANT]],[[1]],[Define to '1' i][f -Wzero-as-null-pointer-constant flag is supported by compiler]) 648 ] 649 ) 650 MHD_CHECK_CC_CFLAG([-Wredundant-decls],[CFLAGS_ac], 651 [ 652 AC_DEFINE([[HAVE_WREDUNDANT_DECLS]],[[1]],[Define to '1' i][f -Wredundant-decls flag is supported by compiler]) 653 ] 654 ) 655 MHD_CHECK_CC_CFLAG([-Wswitch-enum],[CFLAGS_ac], 656 [ 657 AC_DEFINE([[HAVE_WSWITCH_ENUM]],[[1]],[Define to '1' i][f -Wswitch-enum flag is supported by compiler]) 658 ] 659 ) 660 MHD_CHECK_CC_CFLAG([-Wdocumentation-deprecated-sync],[CFLAGS_ac], 661 [ 662 AC_DEFINE([[HAVE_WDOCUMENTATION_DEPRECATED_SYNC]],[[1]],[Define to '1' i][f -Wdocumentation-deprecated-sync flag is supported by compiler]) 663 ] 664 ) 665 MHD_CHECK_CC_CFLAG([-Wdocumentation-unknown-command],[CFLAGS_ac], 666 [ 667 AC_DEFINE([[HAVE_WDOCUMENTATION_UNKNOWN_COMMAND]],[[1]],[Define to '1' i][f -Wdocumentation-unknown-command flag is supported by compiler]) 668 ] 669 ) 670 MHD_CHECK_CC_CFLAG([-Wdocumentation-pedantic],[CFLAGS_ac], 671 [ 672 AC_DEFINE([[HAVE_WDOCUMENTATION_PEDANTIC]],[[1]],[Define to '1' i][f -Wdocumentation-pedantic flag is supported by compiler]) 673 ] 674 ) 675 AS_UNSET([nocxx_compat_CFLAGS]) 676 MHD_CHECK_CC_CFLAG([-Wc++-compat],[CFLAGS_ac], 677 [ 678 AC_DEFINE([[HAVE_WCXX_COMPAT]],[[1]],[Define to '1' i][f -Wc++-compat flag is supported by compiler]) 679 MHD_CHECK_CC_CFLAG([-Wno-c++-compat],[CFLAGS_ac], 680 [nocxx_compat_CFLAGS="-Wno-c++-compat"] 681 ) 682 ] 683 ) 684 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 685 # Additional flags are checked and added at the end of 'configure' 686 687 # Check for headers that are ALWAYS required 688 AC_CHECK_HEADERS_ONCE([stdio.h string.h stdint.h stdarg.h errno.h limits.h fcntl.h], [], 689 [AC_MSG_ERROR([Compiling libmicrohttpd requires standard C and POSIX headers files])], [AC_INCLUDES_DEFAULT]) 690 691 # Check for basic optional headers 692 AC_CHECK_HEADERS([stddef.h stdlib.h inttypes.h sys/types.h sys/stat.h unistd.h \ 693 sys/uio.h crtdefs.h malloc.h io.h stdbit.h], [], [], [AC_INCLUDES_DEFAULT]) 694 695 # Check for clock-specific optional headers 696 AC_CHECK_HEADERS([sys/time.h time.h], [], [], [AC_INCLUDES_DEFAULT]) 697 698 # Check for system information and parameters optional headers 699 AC_CHECK_HEADERS([endian.h machine/endian.h sys/endian.h sys/byteorder.h \ 700 sys/machine.h machine/param.h sys/param.h sys/isa_defs.h \ 701 sys/ioctl.h], [], [], [AC_INCLUDES_DEFAULT]) 702 703 # Check for network and sockets optional headers 704 AC_CHECK_HEADERS([sys/socket.h sys/select.h netinet/in_systm.h netinet/in.h \ 705 sys/un.h arpa/inet.h netinet/ip.h netinet/tcp.h net/if.h \ 706 netdb.h sockLib.h inetLib.h selectLib.h afunix.h], [], [], 707 [AC_INCLUDES_DEFAULT 708 [ 709 #ifdef HAVE_SYS_TYPES_H 710 #include <sys/types.h> 711 #endif /* HAVE_SYS_TYPES_H */ 712 #ifdef HAVE_INTTYPES_H 713 #include <inttypes.h> 714 #endif /* HAVE_INTTYPES_H */ 715 #ifdef HAVE_SYS_SOCKET_H 716 #include <sys/socket.h> 717 #elif defined(HAVE_UNISTD_H) 718 #include <unistd.h> 719 #endif 720 #ifdef HAVE_NETINET_IN_SYSTM_H 721 #include <netinet/in_systm.h> 722 #endif /* HAVE_NETINET_IN_SYSTM_H */ 723 #ifdef HAVE_NETINET_IN_H 724 #include <netinet/in.h> 725 #endif /* HAVE_NETINET_IN_H */ 726 #ifdef HAVE_NETINET_IP_H 727 #include <netinet/ip.h> 728 #endif /* HAVE_NETINET_IP_H */ 729 #ifdef HAVE_NETINET_TCP_H 730 #include <netinet/tcp.h> 731 #endif /* HAVE_NETINET_TCP_H */ 732 ]] 733 ) 734 735 # Check for other optional headers 736 AC_CHECK_HEADERS([sys/msg.h sys/mman.h signal.h], [], [], [AC_INCLUDES_DEFAULT]) 737 738 AC_CHECK_TYPES([size_t,ssize_t,ptrdiff_t,intptr_t,uintptr_t,uint8_t,time_t,suseconds_t],[],[], 739 [[ 740 /* Keep in sync with src/mhd2/sys_base_types.h */ 741 #include <stdint.h> /* uint_fast_XXt, int_fast_XXt */ 742 #if defined(HAVE_STDDEF_H) 743 # include <stddef.h> /* size_t, NULL */ 744 #elif defined(HAVE_STDLIB_H) 745 # include <stdlib.h> /* should provide size_t, NULL */ 746 #else 747 # include <stdio.h> /* should provide size_t, NULL */ 748 #endif 749 #if defined(HAVE_SYS_TYPES_H) 750 # include <sys/types.h> /* ssize_t */ 751 #elif defined(HAVE_UNISTD_H) 752 # include <unistd.h> /* should provide ssize_t */ 753 #endif 754 #ifdef HAVE_CRTDEFS_H 755 # include <crtdefs.h> /* W32-specific header */ 756 #endif 757 ]] 758 ) 759 AS_IF([test "x$ac_cv_type_size_t" != "xyes"], 760 [AC_MSG_FAILURE(['size_t' type is not provided by system headers])] 761 ) 762 AS_IF([test "x$ac_cv_type_uint8_t" != "xyes"], 763 [AC_MSG_FAILURE(['uint8_t' type is not provided by system headers])] 764 ) 765 AC_CHECK_SIZEOF([char]) 766 AS_IF([test "x$ac_cv_sizeof_char" != "x1"], 767 [AC_MSG_FAILURE(['char' type with size different from '1' is not supported])] 768 ) 769 770 771 AC_CHECK_TYPE([socklen_t], 772 [], 773 [AC_DEFINE([socklen_t],[int],[Define to suitable 'socklen_t' replacement if 'socklen_t' is not defined by system headers])], 774 [[ 775 #ifdef HAVE_SYS_TYPES_H 776 #include <sys/types.h> 777 #endif /* HAVE_SYS_TYPES_H */ 778 #include <stdint.h> 779 #ifdef HAVE_INTTYPES_H 780 #include <inttypes.h> 781 #endif /* HAVE_INTTYPES_H */ 782 #ifdef HAVE_SYS_SOCKET_H 783 #include <sys/socket.h> 784 #endif /* HAVE_SYS_SOCKET_H */ 785 #ifdef HAVE_NETINET_IN_SYSTM_H 786 #include <netinet/in_systm.h> 787 #endif /* HAVE_NETINET_IN_SYSTM_H */ 788 #ifdef HAVE_NETINET_IN_H 789 #include <netinet/in.h> 790 #endif /* HAVE_NETINET_IN_H */ 791 #ifdef HAVE_UNISTD_H 792 #include <unistd.h> 793 #endif /* HAVE_UNISTD_H */ 794 #ifdef HAVE_SOCKLIB_H 795 #include <sockLib.h> 796 #endif /* HAVE_SOCKLIB_H */ 797 #if defined(_WIN32) && !defined(__CYGWIN__) 798 #include <winsock2.h> 799 #include <ws2tcpip.h> 800 #endif /* _WIN32 && ! __CYGWIN__ */ 801 ]] 802 ) 803 804 AC_CHECK_HEADER([[search.h]], 805 [ 806 MHD_CHECK_LINK_RUN([[for proper tsearch(), tfind() and tdelete()]],[[mhd_cv_sys_tsearch_usable]], 807 [ 808 AS_CASE([$host_os], 809 [openbsd*], 810 [[ # Some OpenBSD versions have wrong return value for tdelete() 811 mhd_cv_sys_tsearch_usable='assuming no' 812 ]], 813 [netbsd*], 814 [[ # NetBSD had leaked root node for years 815 mhd_cv_sys_tsearch_usable='assuming no' 816 ]], 817 [[mhd_cv_sys_tsearch_usable='assuming yes']] 818 ) 819 ], 820 [ 821 AC_LANG_SOURCE( 822 [[ 823 #ifdef HAVE_STDDEF_H 824 #include <stddef.h> 825 #endif /* HAVE_STDDEF_H */ 826 #ifdef HAVE_STDLIB_H 827 #include <stdlib.h> 828 #endif /* HAVE_STDLIB_H */ 829 830 #include <stdio.h> 831 #include <search.h> 832 833 static int cmp_func(const void *p1, const void *p2) 834 { 835 return (*((const int *)p1)) - (*((const int *)p2)); 836 } 837 838 int main(void) 839 { 840 int ret = 0; 841 void *root_ptr = NULL; 842 int element1 = 1; 843 int **element_ptr_ptr1; 844 int **element_ptr_ptr2; 845 846 element_ptr_ptr1 = 847 (int **) tsearch ((void*) &element1, &root_ptr, &cmp_func); 848 if (NULL == element_ptr_ptr1) 849 { 850 fprintf (stderr, "NULL pointer has been returned when tsearch() called for the first time.\n"); 851 return ++ret; 852 } 853 if (*element_ptr_ptr1 != &element1) 854 { 855 fprintf (stderr, "Wrong pointer has been returned when tsearch() called for the first time.\n"); 856 return ++ret; 857 } 858 if (NULL == root_ptr) 859 { 860 fprintf (stderr, "Root pointer has not been set by tsearch().\n"); 861 return ++ret; 862 } 863 864 element_ptr_ptr2 = 865 (int **) tsearch ((void*) &element1, &root_ptr, &cmp_func); 866 if (NULL == element_ptr_ptr2) 867 { 868 fprintf (stderr, "NULL pointer has been returned when tsearch() called for the second time.\n"); 869 return ++ret; 870 } 871 if (*element_ptr_ptr2 != &element1) 872 { 873 fprintf (stderr, "Wrong pointer has been returned when tsearch() called for the second time.\n"); 874 ++ret; 875 } 876 if (element_ptr_ptr2 != element_ptr_ptr1) 877 { 878 fprintf (stderr, "Wrong element has been returned when tsearch() called for the second time.\n"); 879 ++ret; 880 } 881 882 element_ptr_ptr2 = 883 (int **) tfind ((void*) &element1, &root_ptr, &cmp_func); 884 if (NULL == element_ptr_ptr2) 885 { 886 fprintf (stderr, "NULL pointer has been returned by tfind().\n"); 887 ++ret; 888 } 889 if (*element_ptr_ptr2 != &element1) 890 { 891 fprintf (stderr, "Wrong pointer has been returned when by tfind().\n"); 892 ++ret; 893 } 894 if (element_ptr_ptr2 != element_ptr_ptr1) 895 { 896 fprintf (stderr, "Wrong element has been returned when tsearch() called for the second time.\n"); 897 ++ret; 898 } 899 900 element_ptr_ptr1 = 901 (int **) tdelete ((void*) &element1, &root_ptr, &cmp_func); 902 if (NULL == element_ptr_ptr1) 903 { 904 fprintf (stderr, "NULL pointer has been returned by tdelete().\n"); 905 ++ret; 906 } 907 if (NULL != root_ptr) 908 { 909 fprintf (stderr, "Root pointer has not been set to NULL by tdelete().\n"); 910 ++ret; 911 } 912 913 return ret; 914 } 915 ]] 916 ) 917 ], 918 [AC_DEFINE([[MHD_USE_SYS_TSEARCH]], [[1]], [Define to 1 if you have properly working tsearch(), tfind() and tdelete() functions.])] 919 ) 920 ], 921 [], [AC_INCLUDES_DEFAULT] 922 ) 923 AM_CONDITIONAL([MHD_USE_SYS_TSEARCH], [[test "x$mhd_cv_sys_tsearch_usable" = "xyes" || test "x$mhd_cv_sys_tsearch_usable" = "xassuming yes"]]) 924 925 # Optional headers used for tests 926 AC_CHECK_HEADERS([sys/sysctl.h netinet/ip_icmp.h netinet/icmp_var.h], [], [], 927 [[ 928 #ifdef HAVE_SYS_TYPES_H 929 #include <sys/types.h> 930 #endif /* HAVE_SYS_TYPES_H */ 931 #ifdef HAVE_SYS_SYSCTL_H 932 #include <sys/sysctl.h> 933 #endif /* HAVE_SYS_SYSCTL_H */ 934 #ifdef HAVE_SYS_SOCKET_H 935 #include <sys/socket.h> 936 #elif defined(HAVE_UNISTD_H) 937 #include <unistd.h> 938 #endif 939 #ifdef HAVE_NETINET_IN_SYSTM_H 940 #include <netinet/in_systm.h> 941 #endif /* HAVE_NETINET_IN_SYSTM_H */ 942 #ifdef HAVE_NETINET_IN_H 943 #include <netinet/in.h> 944 #endif /* HAVE_NETINET_IN_H */ 945 #ifdef HAVE_NETINET_IP_H 946 #include <netinet/ip.h> 947 #endif /* HAVE_NETINET_IP_H */ 948 #ifdef HAVE_NETINET_IP_ICMP_H 949 #include <netinet/ip_icmp.h> 950 #endif /* HAVE_NETINET_IP_ICMP_H */ 951 ]] 952 ) 953 954 AC_ARG_ENABLE([compiler-hardening], 955 [AS_HELP_STRING([--enable-compiler-hardening], [enable compiler security checks])], 956 [], 957 [AS_CASE([${enable_build_type}],[*-hardened], 958 [enable_compiler_hardening='yes'],[enable_compiler_hardening='no'])] 959 ) 960 AS_VAR_IF([enable_compiler_hardening],["yes"], 961 [ 962 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 963 AC_CHECK_DECL([_FORTIFY_SOURCE], 964 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-U_FORTIFY_SOURCE])], 965 [],[/* no includes */]) 966 MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-D_FORTIFY_SOURCE=2]) 967 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 968 CFLAGS="${user_CFLAGS}" 969 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac],[-fstack-protector-strong],[-fstack-protector-all],[-fstack-protector]) 970 MHD_CHECK_ADD_CC_CFLAGS([-fstack-clash-protection],[CFLAGS_ac]) 971 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac],[-ftrivial-auto-var-init=pattern],[-ftrivial-auto-var-init=zero]) 972 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 973 AS_IF([test "x${enable_static}" = "xyes" && test "x${pic_mode}" != "xyes"], 974 [ 975 # PIE static lib can be used within non-PIE application, but 976 # PIE static lib cannot be used in non-PIE shared lib. Let's assume 977 # that static lib will not be used in shared lib 978 # All "pie" flags will be used automatically by libtool only 979 # for static library objects. 980 CFLAGS="${user_CFLAGS}" 981 # Perform tests here with "-pie" enabled 982 LDFLAGS="${LDFLAGS_ac} -pie ${user_LDFLAGS}" 983 MHD_CHECK_ADD_CC_CFLAG([-fPIE],[CFLAGS_ac], 984 [ 985 MHD_APPEND_FLAG_TO_VAR([LDFLAGS_ac],[-pie]) 986 ], 987 [ 988 MHD_CHECK_ADD_CC_CFLAG([-fpie],[CFLAGS_ac], 989 [ 990 MHD_APPEND_FLAG_TO_VAR([LDFLAGS_ac],[-pie]) 991 ] 992 ) 993 ] 994 ) 995 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 996 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 997 ] 998 ) 999 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1000 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 1001 ] 1002 ) 1003 1004 # Linker hardening options 1005 # Currently these options are ELF specific, they don't work on Darwin and W32 1006 AC_ARG_ENABLE([linker-hardening], 1007 [AS_HELP_STRING([--enable-linker-hardening], [enable linker security fixups])], 1008 [], 1009 [AS_CASE([${enable_build_type}],[*-hardened], 1010 [enable_linker_hardening='yes'],[enable_linker_hardening='no'])] 1011 ) 1012 AS_VAR_IF([enable_linker_hardening],["yes"], 1013 [ 1014 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1015 LDFLAGS="${user_LDFLAGS}" 1016 MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,relro],[LDFLAGS_ac], 1017 [MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,now],[LDFLAGS_ac])]) 1018 # Actually should be "noexec" by default, but let's try to enforce it. 1019 MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,noexecstack],[LDFLAGS_ac]) 1020 # W32-specific. Some are enabled by default, but they will be enfored to be sure. 1021 MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--large-address-aware -Wl,--enable-auto-image-base],[LDFLAGS_ac]) 1022 MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va],[LDFLAGS_ac]) 1023 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 1024 ] 1025 ) 1026 1027 MHD_BOOL 1028 1029 AC_CACHE_CHECK([whether the NULL pointer has all zero bits], 1030 [mhd_cv_ptr_null_all_zeros], 1031 [ 1032 AC_RUN_IFELSE( 1033 [ 1034 AC_LANG_SOURCE([[ 1035 #include <string.h> 1036 #if defined(HAVE_STDDEF_H) 1037 #include <stddef.h> 1038 #elif defined(HAVE_STDLIB_H) 1039 #include <stdlib.h> 1040 #else 1041 #include <stdio.h> 1042 #endif 1043 1044 int main(void) 1045 { 1046 void *ptr1; 1047 void *ptr2; 1048 1049 ptr1 = &ptr2; 1050 ptr2 = NULL; 1051 memset(&ptr1, 0, sizeof(ptr1)); 1052 if (ptr2 != ptr1) 1053 return 2; 1054 1055 ptr2 = &ptr1; 1056 ptr1 = NULL; 1057 memset(&ptr2, 0, sizeof(ptr2)); 1058 if (0 != memcmp (&ptr1, &ptr2, sizeof(ptr1))) 1059 return 3; 1060 1061 ptr1 = (void*)&ptr1; 1062 ptr2 = (void*)&ptr2; 1063 memset(&ptr1, 0, sizeof(ptr1)); 1064 memset(&ptr2, 0, sizeof(ptr2)); 1065 if (NULL != ptr1) 1066 return 4; 1067 if (NULL != ptr2) 1068 return 5; 1069 1070 return 0; 1071 } 1072 ]] 1073 ) 1074 ], 1075 [mhd_cv_ptr_null_all_zeros="yes"], 1076 [mhd_cv_ptr_null_all_zeros="no"], 1077 [ 1078 AS_CASE([$host_cpu],dnl 1079 [[i[234567]86|x86_64|amd64|arm|armeb|armv[0123456789]|armv[0123456789]eb|aarch64|aarch64_be|arm64|mips|mipsel|mips64|mips64el|powerpc|powerpcle|powerpc64|powerpc64le|riscv32|riscv32be|riscv64|riscv64be]], 1080 [ 1081 AS_CASE([$host_os],dnl 1082 [[linux*|freebsd|cygwin|mingw*|msys|gnu|netbsd*|openbsd*|darwin*|solaris2*|haiku]], 1083 [mhd_cv_ptr_null_all_zeros="assuming yes"], 1084 [mhd_cv_ptr_null_all_zeros="assuming no"] 1085 ) 1086 ], 1087 [mhd_cv_ptr_null_all_zeros="assuming no"] 1088 ) 1089 ] 1090 ) 1091 ] 1092 ) 1093 AS_IF([test "x${mhd_cv_ptr_null_all_zeros}" = "xyes" || test "x${mhd_cv_ptr_null_all_zeros}" = "xassuming yes"], 1094 [AC_DEFINE([HAVE_NULL_PTR_ALL_ZEROS],[1],[Define to '1' if NULL pointers binary representation is all zero bits])] 1095 ) 1096 1097 AC_CACHE_CHECK([whether $CC supports variadic macros],[mhd_cv_cc_macro_variadic], 1098 [ 1099 AS_CASE([$ac_prog_cc_stdc], 1100 [c89],[:], 1101 [c??],[mhd_cv_cc_macro_variadic="yes"] 1102 ) 1103 AS_VAR_SET_IF([mhd_cv_cc_macro_variadic],[:], 1104 [ 1105 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1106 AC_COMPILE_IFELSE( 1107 [ 1108 AC_LANG_SOURCE([[ 1109 #define GET_THIRD(arg1,arg2,arg3,arg4) (arg3) 1110 #define GET_THIRD_VARIADIC(...) GET_THIRD(__VA_ARGS__) 1111 1112 int main(void) 1113 { 1114 int arr[GET_THIRD_VARIADIC(-1,-2,5,-3) - 4] = {0}; 1115 if (0 != arr[GET_THIRD_VARIADIC(100,1000,0,10000)]) 1116 return 2; 1117 return 0; 1118 } 1119 ]] 1120 ) 1121 ], 1122 [mhd_cv_cc_macro_variadic="yes"], 1123 [mhd_cv_cc_macro_variadic="no"] 1124 ) 1125 ac_c_werror_flag="" 1126 ] 1127 ) 1128 ] 1129 ) 1130 AS_VAR_IF([mhd_cv_cc_macro_variadic],["yes"], 1131 [AC_DEFINE([HAVE_MACRO_VARIADIC],[1],[Define to '1' if your compiler supports variadic macros])] 1132 ) 1133 1134 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${nocxx_compat_CFLAGS}" 1135 AC_CACHE_CHECK([whether $CC supports compound literals],[mhd_cv_cc_compound_literals], 1136 [ 1137 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1138 AC_COMPILE_IFELSE( 1139 [ 1140 AC_LANG_SOURCE([[ 1141 struct test_strct 1142 { 1143 char c; 1144 int i; 1145 }; 1146 1147 int main(void) 1148 { 1149 struct test_strct strct_var; 1150 int i; 1151 1152 strct_var = (struct test_strct) { 'a', 0 }; 1153 1154 i = (int){0}; 1155 1156 if (strct_var.i != i) /* Process all variables to avoid warnings */ 1157 return 2; 1158 1159 return 0; 1160 } 1161 ]] 1162 ) 1163 ], 1164 [mhd_cv_cc_compound_literals="yes"], 1165 [mhd_cv_cc_compound_literals="no"] 1166 ) 1167 ac_c_werror_flag="" 1168 ] 1169 ) 1170 AS_VAR_IF([mhd_cv_cc_compound_literals],["yes"], 1171 [ 1172 AC_DEFINE([HAVE_COMPOUND_LITERALS],[1],[Define to '1' if your compiler supports compound literals]) 1173 1174 AC_CACHE_CHECK([whether $CC supports compound literals as arrays of the scope],[mhd_cv_cc_compound_literals_arr_scope], 1175 [ 1176 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1177 AC_COMPILE_IFELSE( 1178 [ 1179 AC_LANG_SOURCE([[ 1180 struct test_strct 1181 { 1182 char c; 1183 int i; 1184 }; 1185 1186 static int test_strct_func(struct test_strct *strc) 1187 { 1188 return 3 == strc->i; 1189 } 1190 1191 int main(void) 1192 { 1193 struct test_strct *strct_ptr1; 1194 struct test_strct *strct_ptr2; 1195 int *int_ptr; 1196 void *ptr; 1197 1198 ptr = (struct test_strct[]) { { 'p', 11 }, { 'q', 22 }, { 'r', 33 } }; 1199 strct_ptr1 = (struct test_strct[]) { { 'a', 1 }, { 'b', 2 }, { 'c', 3 } }; 1200 int_ptr = (int[]){0xFF,0xFE,0xFD,0xFC,0xFB,0xFA}; 1201 1202 if (2 != (strct_ptr1 + 1)->i) 1203 return 3; 1204 1205 strct_ptr2 = (struct test_strct[]) { { 'a', 8 }, { 'b', 9 }, { 'c', 7 } }; 1206 1207 if (0xFE != int_ptr[1]) 1208 return 4; 1209 1210 if (*(int_ptr + 4) != 0xFB) 1211 return 5; 1212 1213 if (!test_strct_func(strct_ptr1 + 2)) 1214 return 6; 1215 1216 if (int_ptr[2] != 0xFD) 1217 return 7; 1218 1219 if (((struct test_strct *)ptr)[0].c == 'p') 1220 ptr = (struct test_strct[]) { { 'x', 55 }, { 'y', 66 }, { 'z', 77 } }; 1221 1222 if (*((char *)ptr) != 'x') 1223 return 8; 1224 1225 if (*(int_ptr + 5) != 0xFA) 1226 return 9; 1227 1228 if (strct_ptr2[1].c != 'b') 1229 return 10; 1230 1231 return strct_ptr1[1].i == 2 ? 0 : 11; 1232 } 1233 1234 #ifdef __cplusplus 1235 choke me now; /* Actually, some C++ compilers *may* handle this properly, 1236 * but it is too tricky to test it correctly. 1237 * False-positive results will lead to run-time errors, 1238 * so just block it when C++ is used. */ 1239 #error This is a C++ compiler 1240 #endif 1241 1242 ]] 1243 ) 1244 ], 1245 [mhd_cv_cc_compound_literals_arr_scope="yes"], 1246 [mhd_cv_cc_compound_literals_arr_scope="no"] 1247 ) 1248 ac_c_werror_flag="" 1249 ] 1250 ) 1251 AS_VAR_IF([mhd_cv_cc_compound_literals_arr_scope],["yes"], 1252 [AC_DEFINE([HAVE_COMPOUND_LITERALS_ARRAYS_SCOPE],[1],[Define to '1' if your compiler supports compound literals as arrays of the scope])] 1253 ) 1254 1255 AC_CACHE_CHECK([whether $CC supports compound literals as local arrays],[mhd_cv_cc_compound_literals_arr_local], 1256 [ 1257 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1258 AC_COMPILE_IFELSE( 1259 [ 1260 AC_LANG_SOURCE([[ 1261 struct test_strct 1262 { 1263 char c; 1264 int i; 1265 }; 1266 1267 static int test_strct_func(struct test_strct *strc) 1268 { 1269 return 0 == strc->i; 1270 } 1271 1272 int main(void) 1273 { 1274 if (test_strct_func((struct test_strct[]) { { 'a', 0 }, { 'b', 1 }, { 'c', 2 } })) 1275 return 4; 1276 1277 return ((struct test_strct[]) { { 'a', 0 }, { 'b', 1 }, { 'c', 2 } })->i; 1278 } 1279 ]] 1280 ) 1281 ], 1282 [mhd_cv_cc_compound_literals_arr_local="yes"], 1283 [mhd_cv_cc_compound_literals_arr_local="no"] 1284 ) 1285 ac_c_werror_flag="" 1286 ] 1287 ) 1288 AS_VAR_IF([mhd_cv_cc_compound_literals_arr_local],["yes"], 1289 [AC_DEFINE([HAVE_COMPOUND_LITERALS_ARRAYS_LOCAL],[1],[Define to '1' if your compiler supports compound literals as local arrays])] 1290 ) 1291 1292 AC_CACHE_CHECK([whether $CC supports compound literals as lvalue],[mhd_cv_cc_compound_literals_lvalues], 1293 [ 1294 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1295 AC_COMPILE_IFELSE( 1296 [ 1297 AC_LANG_SOURCE([[ 1298 struct test_strct 1299 { 1300 char c; 1301 int i; 1302 }; 1303 1304 static int test_strct_func(struct test_strct *strc) 1305 { 1306 return 0 != strc->i; 1307 } 1308 1309 int main(void) 1310 { 1311 int int_var; 1312 int *int_ptr; 1313 1314 int_var = ++(int) {0}; 1315 int_ptr = &((int) {1}); 1316 1317 if (int_var != *int_ptr) /* Process all variables to avoid warnings */ 1318 return 2; 1319 1320 if (test_strct_func(&( (struct test_strct) { 'a', 0 } ))) 1321 return 4; 1322 1323 return 0; 1324 } 1325 ]] 1326 ) 1327 ], 1328 [mhd_cv_cc_compound_literals_lvalues="yes"], 1329 [mhd_cv_cc_compound_literals_lvalues="no"] 1330 ) 1331 ac_c_werror_flag="" 1332 ] 1333 ) 1334 AS_VAR_IF([mhd_cv_cc_compound_literals_lvalues],["yes"], 1335 [AC_DEFINE([HAVE_COMPOUND_LITERALS_LVALUES],[1],[Define to '1' if your compiler supports compound literals as lvalues])] 1336 ) 1337 ], 1338 [ 1339 AS_UNSET([mhd_cv_cc_compound_literals_arr_local]) 1340 AS_UNSET([mhd_cv_cc_compound_literals_lvalue]) 1341 AS_UNSET([mhd_cv_cc_compound_literals_arr_scope]) 1342 ] 1343 ) 1344 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1345 AC_CACHE_CHECK([whether $CC supports trailing comma in enum],[mhd_cv_enum_trailing_comma], 1346 [ 1347 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1348 AC_COMPILE_IFELSE( 1349 [AC_LANG_SOURCE([[enum TestEnum {ENM_VAL_A, ENM_VAL_B,};]])], 1350 [mhd_cv_enum_trailing_comma="yes"], 1351 [mhd_cv_enum_trailing_comma="no"] 1352 ) 1353 ac_c_werror_flag="" 1354 ] 1355 ) 1356 AS_VAR_IF([mhd_cv_enum_trailing_comma],["yes"],[], 1357 [AC_DEFINE([MHD_ENUMS_NEED_TRAILING_VALUE],[1],[Define to '1' if your compiler does not support enum with trailing comma])] 1358 ) 1359 AC_CACHE_CHECK([whether $CC supports enum fixed underlying type],[mhd_cv_enum_base_type], 1360 [ 1361 AC_COMPILE_IFELSE( 1362 [AC_LANG_SOURCE([[enum TestEnum : unsigned char {ENM_VAL_A, ENM_VAL_B};]])], 1363 [mhd_cv_enum_base_type="yes"], 1364 [ 1365 mhd_cv_enum_base_type="no" 1366 mhd_cv_enum_base_type_warnless="no" 1367 ] 1368 ) 1369 ] 1370 ) 1371 AS_VAR_IF([mhd_cv_enum_base_type],["yes"], 1372 [ 1373 AC_DEFINE([HAVE_ENUM_BASE_TYPE],[1],[Define to '1' if your compiler supports enum with fixed underlying type]) 1374 AH_TEMPLATE([HAVE_ENUM_BASE_TYPE_WARNLESS],[Define to '1' i][f your compiler supports enum with fixed underlying type without extra warnings]) 1375 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"], 1376 [AC_DEFINE([HAVE_ENUM_BASE_TYPE_WARNLESS],[1])], 1377 [ 1378 AC_CACHE_CHECK([whether enum fixed underlying type works without extra warnings],[mhd_cv_enum_base_type_warnless], 1379 [ 1380 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1381 AC_COMPILE_IFELSE( 1382 [AC_LANG_SOURCE([[enum TestEnum : unsigned char {ENM_VAL_A, ENM_VAL_B};]])], 1383 [mhd_cv_enum_base_type_warnless="yes"], 1384 [mhd_cv_enum_base_type_warnless="no"] 1385 ) 1386 ac_c_werror_flag="" 1387 ] 1388 ) 1389 AS_VAR_IF([mhd_cv_enum_base_type_warnless],["yes"],[AC_DEFINE([HAVE_ENUM_BASE_TYPE_WARNLESS],[1])]) 1390 ] 1391 ) 1392 ] 1393 ) 1394 1395 1396 AS_VAR_SET_IF([ac_cv_c_restrict],[], 1397 [ 1398 # "cache" result in advance if it is known from the compiler test 1399 AS_CASE([$ac_prog_cc_stdc], 1400 [c89],[:], 1401 [c??],[ac_cv_c_restrict="restrict"] 1402 ) 1403 ] 1404 ) 1405 AC_C_RESTRICT 1406 AS_VAR_IF([ac_cv_c_restrict],["no"],[], 1407 [AC_DEFINE([HAVE_RESTRICT],[1],[Define to '1' if your compiler supports 'restrict' keyword])] 1408 ) 1409 AC_C_INLINE 1410 AS_VAR_IF([ac_cv_c_inline],["no"],[], 1411 [ 1412 # Check whether "enable" flag is supported as "disable" flag could be silently 1413 # accepted when the compiled code itself does not produce any warnings 1414 CFLAGS="${user_CFLAGS}" 1415 MHD_CHECK_CC_CFLAG([-Winline],[CFLAGS_ac], 1416 [MHD_CHECK_ADD_CC_CFLAG([-Wno-inline],[CFLAGS_ac])] 1417 ) 1418 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1419 ] 1420 ) 1421 AS_UNSET([errattr_CFLAGS]) 1422 CFLAGS="${user_CFLAGS}" 1423 MHD_CHECK_CC_CFLAG([-Werror=attributes],[CFLAGS_ac], 1424 [ 1425 AC_CACHE_CHECK([whether -Werror=attributes actually works],[mhd_cv_cflag_werror_attr_works], 1426 [ 1427 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} -Werror=attributes" 1428 AC_COMPILE_IFELSE([ 1429 AC_LANG_PROGRAM( 1430 [[__attribute__((non_existing_attrb_dummy)) static int SimpleFunc(void) {return 3;}]], 1431 [[int r = SimpleFunc(); if (r) return r;]] 1432 ) 1433 ], 1434 [mhd_cv_cflag_werror_attr_works="no"], 1435 [mhd_cv_cflag_werror_attr_works="yes"] 1436 ) 1437 ] 1438 ) 1439 AS_VAR_IF([mhd_cv_cflag_werror_attr_works],["yes"], 1440 [errattr_CFLAGS="-Werror=attributes"],[errattr_CFLAGS=""] 1441 ) 1442 ] 1443 ) 1444 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1445 AS_IF([test "x$ac_cv_c_inline" != "xno"], 1446 [ 1447 AC_DEFINE([HAVE_INLINE_FUNCS],[1],[Define to 1 if your C compiler supports inline functions.]) 1448 AC_CACHE_CHECK([for function force static inline keywords supported by $CC],[mhd_cv_cc_kwd_static_forceinline], 1449 [ 1450 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1451 mhd_cv_cc_kwd_static_forceinline="none" 1452 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} $errattr_CFLAGS" 1453 for keyword_chk in 'static inline __attribute__((always_inline))' 'static __forceinline' '_Pragma("inline=forced") static inline' 1454 do 1455 AS_CASE([${keyword_chk}], 1456 [*attribute*], 1457 [AS_IF([test "x$errattr_CFLAGS" = "x"],[continue])] 1458 ) 1459 AC_LINK_IFELSE([ 1460 AC_LANG_SOURCE([[ 1461 #ifdef HAVE_STDBOOL_H 1462 #include <stdbool.h> 1463 #endif 1464 ${keyword_chk} bool cmpfn(int x, int y) 1465 { return x > y; } 1466 ${keyword_chk} int sumfn(int x, int y) 1467 { return x + y; } 1468 1469 int main(void) 1470 { 1471 int a = 1, b = 100, c; 1472 if (cmpfn(a, b)) 1473 c = sumfn(a, b); 1474 else 1475 c = 0 - sumfn(a, b); 1476 return (cmpfn(0, c) ? 0 : 5); 1477 } 1478 ]] 1479 ) 1480 ], 1481 [mhd_cv_cc_kwd_static_forceinline="${keyword_chk}"] 1482 ) 1483 test "x${mhd_cv_cc_kwd_static_forceinline}" != "xnone" && break 1484 done 1485 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1486 ac_c_werror_flag="" 1487 ] 1488 ) 1489 ] 1490 ) 1491 AS_IF([test "x$ac_cv_c_inline" != "xno" && test "x${mhd_cv_cc_kwd_static_forceinline}" != "xnone"], 1492 [AC_DEFINE_UNQUOTED([mhd_static_inline],[$mhd_cv_cc_kwd_static_forceinline],[Define to prefix which will be used with MHD internal static inline functions.])] 1493 , 1494 [AC_DEFINE([mhd_static_inline],[static inline],[Define to prefix which will be used with MHD static inline functions.])] 1495 ) 1496 1497 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1498 AC_CACHE_CHECK([whether 'constexpr' keywords supported by $CC],[mhd_cv_cc_kwd_constexpr], 1499 [ 1500 AC_LINK_IFELSE([ 1501 AC_LANG_SOURCE([[ 1502 1503 static constexpr int zero_const_expr_s = 0; 1504 constexpr unsigned int one_const_expr_u = 1; 1505 1506 enum some_Enm 1507 { 1508 enm_Val_Zero = 0, 1509 enm_Val_One = one_const_expr_u, 1510 enm_Val_Two = 2 1511 }; 1512 1513 int main(int argc, char *argv[]) 1514 { 1515 enum some_Enm local_e_var; 1516 static constexpr unsigned int arr0[1 + zero_const_expr_s] = { one_const_expr_u }; 1517 constexpr int arr1[one_const_expr_u] = { zero_const_expr_s }; 1518 1519 switch(argc) 1520 { 1521 case zero_const_expr_s: 1522 local_e_var = enm_Val_One; 1523 break; 1524 case 1: 1525 local_e_var = enm_Val_Zero; 1526 break; 1527 case 10: 1528 local_e_var = enm_Val_Two; 1529 break; 1530 default: 1531 local_e_var = enm_Val_Two; 1532 break; 1533 } 1534 1535 return (arr0[0] + (unsigned int)local_e_var) == 1536 one_const_expr_u ? (arr1[0] - zero_const_expr_s) : (!! argv[0]); 1537 } 1538 ]] 1539 ) 1540 ], 1541 [mhd_cv_cc_kwd_constexpr="yes"],[mhd_cv_cc_kwd_constexpr="no"] 1542 ) 1543 ] 1544 ) 1545 AS_VAR_IF([mhd_cv_cc_kwd_constexpr],["yes"], 1546 [AC_DEFINE([MHD_HAVE_C_CONSTEXPR],[1],[Define to '1' if compiler supports "constexpr" keyword])] 1547 ) 1548 AC_CACHE_CHECK([for 'unreachable' keywords supported by $CC],[mhd_cv_cc_kwd_unreachable], 1549 [ 1550 mhd_cv_cc_kwd_unreachable="none" 1551 for keyword_chk in '__builtin_unreachable()' '__assume(0)' 'unreachable()' 1552 do 1553 AC_LINK_IFELSE([ 1554 AC_LANG_SOURCE([[ 1555 #ifdef HAVE_STDDEF_H 1556 #include <stddef.h> 1557 #endif 1558 1559 static int zero_if_positive(int val) 1560 { 1561 if (val > 0) 1562 return 0; 1563 ${keyword_chk}; 1564 return 1; 1565 } 1566 1567 int main(void) 1568 { 1569 return zero_if_positive(1); 1570 } 1571 ]] 1572 ) 1573 ], 1574 [mhd_cv_cc_kwd_unreachable="$keyword_chk"] 1575 ) 1576 test "x${mhd_cv_cc_kwd_unreachable}" != "xnone" && break 1577 done 1578 ] 1579 ) 1580 AS_IF([test "x${mhd_cv_cc_kwd_unreachable}" != "xnone"], 1581 [ 1582 AC_DEFINE_UNQUOTED([MHD_UNREACHABLE_KEYWORD],[$mhd_cv_cc_kwd_unreachable],[Define to keyword supported to indicate unreachable code paths]) 1583 AS_IF([test "x${mhd_cv_cc_kwd_unreachable}" = "xunreachable()" && test "x$ac_cv_header_stddef_h" = "xyes"], 1584 [AC_DEFINE([MHD_UNREACHABLE_NEEDS_STDDEF_H],[$mhd_cv_cc_kwd_unreachable],[Define to '1' if MHD_UNREACHABLE_KEYWORD requires include of <stddef.h> header])] 1585 ) 1586 ] 1587 ) 1588 1589 AC_CACHE_CHECK([for 'assume' hint keywords supported by $CC],[mhd_cv_cc_kwd_assume], 1590 [ 1591 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}" 1592 mhd_cv_cc_kwd_assume="none" 1593 for keyword_chk in '__attribute__((assume(statement)))' '__builtin_assume(statement)' '[[assume(statement)]]' '__assume(statement)' 1594 do 1595 AC_LINK_IFELSE([ 1596 AC_LANG_SOURCE([[ 1597 1598 #define MACRO_ASSUME(statement) ${keyword_chk} 1599 1600 static int zero_or_n(int cnd, int val) 1601 { 1602 MACRO_ASSUME(cnd >= 0); 1603 MACRO_ASSUME(cnd <= 1); 1604 return cnd * val; 1605 } 1606 1607 int main(int argc, char *const *argv) 1608 { 1609 (void) argv; 1610 return zero_or_n(0 > argc, 2); 1611 } 1612 ]] 1613 ) 1614 ], 1615 [mhd_cv_cc_kwd_assume="$keyword_chk"] 1616 ) 1617 test "x${mhd_cv_cc_kwd_assume}" != "xnone" && break 1618 done 1619 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1620 ] 1621 ) 1622 AS_IF([test "x${mhd_cv_cc_kwd_assume}" != "xnone"], 1623 [AC_DEFINE_UNQUOTED([MHD_ASSUME_KEYWORD(statement)],[$mhd_cv_cc_kwd_assume],[Define to keyword supported to indicate a hard promise])] 1624 ) 1625 ac_c_werror_flag="" 1626 1627 # Check for 'fallthrough' keywords 1628 save_CFLAGS_ac="${CFLAGS_ac}" 1629 CFLAGS="${user_CFLAGS}" 1630 # Use strictest warning flags 1631 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wimplicit-fallthrough=5],[-Wimplicit-fallthrough=4],[-Wimplicit-fallthrough=3], 1632 [-Wimplicit-fallthrough]) 1633 AC_CACHE_CHECK([for 'fallthrough' keyword supported by $CC],[mhd_cv_cc_kwd_fallthrough], 1634 [ 1635 mhd_cv_cc_kwd_fallthrough="no" 1636 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}" 1637 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1638 [for keyword_chk in '[[fallthrough]]' '[[__fallthrough__]]' '[[gnu::fallthrough]]' '[[clang::fallthrough]]' '__attribute__((fallthrough))' ''] 1639 do 1640 AC_LINK_IFELSE([ 1641 AC_LANG_SOURCE([[ 1642 int main(int argc, char *argv[]) 1643 { 1644 int ret = 0; 1645 (void) argv; 1646 switch (argc) 1647 { 1648 case 0: 1649 ++ret; 1650 ${keyword_chk}; 1651 case 3: 1652 ++ret; 1653 ${keyword_chk}; 1654 case 10: 1655 ++ret; 1656 ${keyword_chk}; 1657 default: 1658 break; 1659 } 1660 return ret; 1661 } 1662 ]] 1663 ) 1664 ], 1665 [mhd_cv_cc_kwd_fallthrough="$keyword_chk"] 1666 ) 1667 test "x${mhd_cv_cc_kwd_fallthrough}" != "xno" && break 1668 done 1669 AS_IF([test -z "${mhd_cv_cc_kwd_fallthrough}"], [mhd_cv_cc_kwd_fallthrough="none needed"]) 1670 ac_c_werror_flag="" 1671 ] 1672 ) 1673 AH_TEMPLATE([mhd_FALLTHROUGH],[Define to keyword marking intentional missing 'break' at the end of 'case:']) 1674 AS_CASE([${mhd_cv_cc_kwd_fallthrough}], 1675 [no],[AC_DEFINE([mhd_FALLTHROUGH],[((void) 0) /* no keyword supported */])], 1676 ["none needed"],[AC_DEFINE([mhd_FALLTHROUGH],[((void) 0) /* not needed */])], 1677 [AC_DEFINE_UNQUOTED([mhd_FALLTHROUGH],[$mhd_cv_cc_kwd_fallthrough])] 1678 ) 1679 CFLAGS_ac="${save_CFLAGS_ac}" 1680 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1681 1682 # Check for full support of atomic variables 1683 AC_CACHE_CHECK([whether $CC supports atomic variables], 1684 [mhd_cv_c_atomic_variables], 1685 [ 1686 AC_COMPILE_IFELSE( 1687 [ 1688 AC_LANG_SOURCE( 1689 [[ 1690 #include <stdatomic.h> 1691 1692 #ifdef __STDC_NO_ATOMICS__ 1693 #error __STDC_NO_ATOMICS__ is declared 1694 choke me now 1695 #endif 1696 1697 int main(void) 1698 { 1699 volatile _Atomic int atmc_var; 1700 int natmc_var; 1701 1702 atomic_init(&atmc_var, 0); 1703 1704 if (0 == atomic_exchange_explicit(&atmc_var, 16, memory_order_relaxed)) 1705 atomic_store_explicit(&atmc_var, 7, memory_order_release); 1706 1707 natmc_var = atomic_fetch_add_explicit(&atmc_var, 15, memory_order_acq_rel); 1708 1709 natmc_var = atomic_fetch_sub_explicit(&atmc_var, natmc_var, memory_order_relaxed); 1710 1711 natmc_var = atomic_fetch_or_explicit(&atmc_var, natmc_var, memory_order_seq_cst); 1712 1713 natmc_var = atomic_fetch_and_explicit(&atmc_var, natmc_var, memory_order_relaxed); 1714 1715 natmc_var = atomic_fetch_xor_explicit(&atmc_var, natmc_var, memory_order_release); 1716 1717 return natmc_var + 1 - atomic_load_explicit(&atmc_var, memory_order_acquire); 1718 } 1719 ]] 1720 ) 1721 ], 1722 [mhd_cv_c_atomic_variables="yes"],[mhd_cv_c_atomic_variables="no"] 1723 ) 1724 ] 1725 ) 1726 AS_VAR_IF([mhd_cv_c_atomic_variables],["yes"], 1727 [ 1728 AC_DEFINE([MHD_SUPPORT_ATOMIC_VARIABLES],[1],[Define to 1 i][f atomic variables are fully supported]) 1729 AC_DEFINE([MHD_SUPPORT_ATOMIC_COUNTERS],[1],[Define to 1 i][f counter subset of atomic operations is supported]) 1730 ], 1731 [ 1732 # Check for minimal atomic variables support 1733 AC_CACHE_CHECK([whether $CC supports atomic counters], 1734 [mhd_cv_c_atomic_counters], 1735 [ 1736 AC_COMPILE_IFELSE( 1737 [ 1738 AC_LANG_SOURCE( 1739 [[ 1740 #if defined(HAVE_STDDEF_H) 1741 # include <stddef.h> /* size_t */ 1742 #elif defined(HAVE_STDLIB_H) 1743 # include <stdlib.h> /* should provide size_t */ 1744 #else 1745 # include <stdio.h> /* should provide size_t */ 1746 #endif 1747 #ifdef HAVE_CRTDEFS_H 1748 # include <crtdefs.h> /* W32-specific header */ 1749 #endif 1750 1751 #include <stdatomic.h> 1752 1753 #ifdef __STDC_NO_ATOMICS__ 1754 #error __STDC_NO_ATOMICS__ is declared 1755 choke me now 1756 #endif 1757 1758 int main(void) 1759 { 1760 volatile _Atomic size_t cntr; 1761 1762 atomic_init(&cntr, 0); 1763 1764 atomic_fetch_add_explicit(&cntr, 1, memory_order_relaxed); 1765 atomic_fetch_sub_explicit(&cntr, 1, memory_order_release); 1766 1767 return 1768 (0u == atomic_load_explicit(&cntr, memory_order_relaxed)) ? 1769 0 : 2; 1770 } 1771 ]] 1772 ) 1773 ], 1774 [mhd_cv_c_atomic_counters="yes"],[mhd_cv_c_atomic_counters="no"] 1775 ) 1776 ] 1777 ) 1778 AS_VAR_IF([mhd_cv_c_atomic_counters],["yes"], 1779 [AC_DEFINE([MHD_SUPPORT_ATOMIC_COUNTERS],[1],[Define to 1 i][f counter subset of atomic operations is supported])] 1780 ) 1781 ] 1782 ) 1783 1784 AC_CHECK_HEADERS([stdalign.h], [], [], [AC_INCLUDES_DEFAULT]) 1785 AC_CACHE_CHECK([[for C11 'alignof()' support]], [[mhd_cv_c_alignof]], 1786 [AC_COMPILE_IFELSE( 1787 [AC_LANG_PROGRAM( 1788 [[ 1789 #ifdef HAVE_STDALIGN_H 1790 #include <stdalign.h> 1791 #endif 1792 ]], [[ 1793 int var1[(alignof(int) >= 2) ? 1 : -1]; 1794 int var2[alignof(unsigned int) - 1]; 1795 int var3[(alignof(char) > 0) ? 1 : -1]; 1796 int var4[(alignof(long) >= 4) ? 1 : -1]; 1797 1798 /* Mute compiler warnings */ 1799 var1[0] = var2[0] = var3[0] = 0; 1800 var4[0] = 1; 1801 if (var1[0] + var2[0] + var3[0] == var4[0]) 1802 return 1; 1803 ]]) 1804 ], [ 1805 AC_COMPILE_IFELSE( 1806 [AC_LANG_PROGRAM( 1807 [[ 1808 #ifdef HAVE_STDALIGN_H 1809 #include <stdalign.h> 1810 #endif 1811 ]], [[ 1812 /* Should fail if 'alignof()' works */ 1813 int var1[alignof(nonexisting_type)]; 1814 1815 /* Mute compiler warnings */ 1816 var1[0] = 1; 1817 if (var1[0] + 1 == 1) 1818 return 1; 1819 ]]) 1820 ], [[mhd_cv_c_alignof='no']], [[mhd_cv_c_alignof='yes']]) 1821 ], [[mhd_cv_c_alignof='no']]) 1822 ]) 1823 AS_VAR_IF([mhd_cv_c_alignof], ["yes"], 1824 [AC_DEFINE([[HAVE_C_ALIGNOF]], [1], [Define to 1 if your compiler supports 'alignof()'])]) 1825 1826 AC_CACHE_CHECK([whether $CC supports __attribute__((aligned ( )))],[mhd_cv_cc_attr_aligned], 1827 [ 1828 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}" 1829 AC_LINK_IFELSE( 1830 [ 1831 AC_LANG_SOURCE( 1832 [[ 1833 int main(void) 1834 { 1835 __attribute__((aligned (4))) signed char schr[1] = {0}; 1836 return schr[0]; 1837 } 1838 ]] 1839 ) 1840 ], 1841 [mhd_cv_cc_attr_aligned="yes"],[mhd_cv_cc_attr_aligned="no"] 1842 ) 1843 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1844 ] 1845 ) 1846 AS_VAR_IF([mhd_cv_cc_attr_aligned],["yes"], 1847 [AC_DEFINE([[HAVE_ATTR_ALIGNED]], [1], [Define to 1 if compiler supports __attribute__((aligned (X)))])], 1848 [ 1849 AC_CACHE_CHECK([whether $CC supports __declspec(align( )))],[mhd_cv_cc_declspec_align], 1850 [ 1851 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}" 1852 AC_LINK_IFELSE( 1853 [ 1854 AC_LANG_SOURCE( 1855 [[ 1856 int main(void) 1857 { 1858 __declspec(align(4))) signed char schr[1] = {0}; 1859 return schr[0]; 1860 } 1861 ]] 1862 ) 1863 ], 1864 [mhd_cv_cc_declspec_align="yes"],[mhd_cv_cc_declspec_align="no"] 1865 ) 1866 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1867 ] 1868 ) 1869 AS_VAR_IF([mhd_cv_cc_declspec_align],["yes"], 1870 [AC_DEFINE([[HAVE_DECLSPEC_ALIGN]], [1], [Define to 1 if compiler supports __declspec(align(X)))])] 1871 ) 1872 ] 1873 ) 1874 AC_CACHE_CHECK([fo][r C11 alignas() support],[mhd_cv_c_alignas], 1875 [ 1876 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}" 1877 AC_LINK_IFELSE( 1878 [ 1879 AC_LANG_SOURCE( 1880 [[ 1881 #ifdef HAVE_STDALIGN_H 1882 #if ! defined(__STDC_VERSION__) || (__STDC_VERSION__+0) < 202311 1883 #include <stdalign.h> 1884 #endif 1885 #endif 1886 1887 int main(void) 1888 { 1889 alignas(4) signed char schr[1] = {0}; 1890 alignas(int) signed char schr_var = 0; 1891 return schr[0] + schr_var; 1892 } 1893 ]] 1894 ) 1895 ], 1896 [mhd_cv_c_alignas="yes"],[mhd_cv_c_alignas="no"] 1897 ) 1898 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1899 ] 1900 ) 1901 AS_VAR_IF([mhd_cv_c_alignas],["yes"], 1902 [AC_DEFINE([[HAVE_C_ALIGNAS]], [1], [Define to 1 if C11 alignas() is supported])] 1903 ) 1904 AS_IF([test "x${mhd_cv_cc_attr_aligned}${mhd_cv_cc_declspec_align}${mhd_cv_c_alignas}" != "xnonono"], 1905 [ 1906 AC_CACHE_CHECK([fo][r large alignment number supported],[mhd_cv_alignment_large_num], 1907 [ 1908 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}" 1909 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 1910 for mhd_cv_alignment_large_num in 65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 0; do 1911 AC_LINK_IFELSE( 1912 [ 1913 AC_LANG_SOURCE( 1914 [[ 1915 #ifdef HAVE_STDALIGN_H 1916 #if ! defined(__STDC_VERSION__) || (__STDC_VERSION__+0) < 202311 1917 #include <stdalign.h> 1918 #endif 1919 #endif 1920 1921 /* Priority for alignas() implementation as it should warn more */ 1922 #ifdef HAVE_C_ALIGNAS 1923 #define test_alignas(x) alignas(x) 1924 #elif defined(HAVE_ATTR_ALIGNED) 1925 #define test_alignas(x) __attribute__((aligned (x))) 1926 #elif defined(HAVE_DECLSPEC_ALIGN) 1927 #define test_alignas(x) __declspec(align(x))) 1928 #else 1929 #error No alignas() implementation available 1930 choke me now 1931 #endif 1932 1933 int main(void) 1934 { 1935 test_alignas($mhd_cv_alignment_large_num) signed char ret = 0; 1936 return ret; 1937 } 1938 ]] 1939 ) 1940 ], 1941 [break 1942 ] 1943 ) 1944 done 1945 ac_c_werror_flag="" 1946 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1947 ] 1948 ) 1949 AS_IF([test "$mhd_cv_alignment_large_num" -gt "1"], 1950 [ 1951 AC_DEFINE_UNQUOTED([MHD_ALIGNMENT_LARGE_NUM],[$mhd_cv_alignment_large_num], 1952 [Define to large enough number that is still supported as an alignment]) 1953 ] 1954 , 1955 [AC_MSG_WARN([no supported aligment number can be detected])] 1956 ) 1957 ] 1958 ) 1959 1960 1961 # Check system type 1962 AC_MSG_CHECKING([[for target host OS]]) 1963 os_is_windows="no" 1964 os_is_native_w32="no" 1965 AS_CASE(["$host_os"], 1966 [*darwin* | *rhapsody* | *macosx*], 1967 [AC_DEFINE([OSX],[1],[This is an OS X system]) 1968 mhd_host_os='Darwin' 1969 AC_MSG_RESULT([[$mhd_host_os]])], 1970 [kfreebsd*-gnu], 1971 [AC_DEFINE([SOMEBSD],[1],[This is a BSD system]) 1972 AC_DEFINE([FREEBSD],[1],[This is a FreeBSD system]) 1973 mhd_host_os='FreeBSD kernel with GNU userland' 1974 AC_MSG_RESULT([[$mhd_host_os]])], 1975 [freebsd*], 1976 [AC_DEFINE([SOMEBSD],[1],[This is a BSD system]) 1977 AC_DEFINE([FREEBSD],[1],[This is a FreeBSD system]) 1978 mhd_host_os='FreeBSD' 1979 AC_MSG_RESULT([[$mhd_host_os]])], 1980 [openbsd*], 1981 [AC_DEFINE([SOMEBSD],[1],[This is a BSD system]) 1982 AC_DEFINE([OPENBSD],[1],[This is an OpenBSD system]) 1983 mhd_host_os='OpenBSD' 1984 AC_MSG_RESULT([[$mhd_host_os]])], 1985 [netbsd*], 1986 [AC_DEFINE([SOMEBSD],[1],[This is a BSD system]) 1987 AC_DEFINE([NETBSD],[1],[This is a NetBSD system]) 1988 mhd_host_os='NetBSD' 1989 AC_MSG_RESULT([[$mhd_host_os]])], 1990 [*solaris*], 1991 [AC_DEFINE([SOLARIS],[1],[This is a Solaris system]) 1992 AC_DEFINE([_REENTRANT],[1],[Need with solaris or errno does not work]) 1993 mhd_host_os='Solaris' 1994 AC_MSG_RESULT([[$mhd_host_os]])], 1995 [linux-gnu], 1996 [AC_DEFINE([LINUX],[1],[This is a Linux kernel]) 1997 mhd_host_os='GNU/Linux' 1998 AC_MSG_RESULT([[$mhd_host_os]])], 1999 [linux-android*], 2000 [AC_DEFINE([LINUX],[1],[This is a Linux kernel]) 2001 mhd_host_os='Android' 2002 AC_MSG_RESULT([[$mhd_host_os]])], 2003 [*linux*], 2004 [AC_DEFINE([LINUX],[1],[This is a Linux kernel]) 2005 mhd_host_os='Linux' 2006 AC_MSG_RESULT([[$mhd_host_os]])], 2007 [*cygwin*], 2008 [AC_DEFINE([CYGWIN],[1],[This is a Cygwin system]) 2009 mhd_host_os='Windows/Cygwin' 2010 AC_MSG_RESULT([[$mhd_host_os]]) 2011 os_is_windows="yes"], 2012 [*mingw*], 2013 [ 2014 AC_DEFINE([MINGW],[1],[This is a MinGW system]) 2015 AC_DEFINE([WINDOWS],[1],[This is a Windows system]) 2016 mhd_host_os='Windows/MinGW' 2017 AC_MSG_RESULT([[$mhd_host_os]]) 2018 AC_CHECK_HEADERS([winsock2.h ws2tcpip.h], [], [AC_MSG_ERROR([[Winsock2 headers are required for W32]])], [AC_INCLUDES_DEFAULT]) 2019 AC_CHECK_HEADERS([sdkddkver.h], [], [], [AC_INCLUDES_DEFAULT]) 2020 AC_CACHE_CHECK([for MS lib utility], [ac_cv_use_ms_lib_tool], 2021 [mslibcheck=`lib 2>&1` 2022 AS_IF([echo "$mslibcheck" | $GREP -e '^Microsoft (R) Library Manager' - >/dev/null], 2023 [ac_cv_use_ms_lib_tool=yes], 2024 [ac_cv_use_ms_lib_tool=no]) 2025 ]) 2026 AS_IF([test "x$ac_cv_use_ms_lib_tool" = "xyes"], 2027 [AC_SUBST([MS_LIB_TOOL], [[lib]])]) 2028 AC_SUBST([lt_cv_objdir]) 2029 os_is_windows="yes" 2030 os_is_native_w32="yes" 2031 ], 2032 [*openedition*], 2033 [AC_DEFINE([OS390],[1],[This is a OS/390 system]) 2034 mhd_host_os='OS/390' 2035 AC_MSG_RESULT([[$mhd_host_os]])], 2036 [gnu*], 2037 [AC_DEFINE([[GNU_HURD]], [[1]], [Define to `1' if host machine runs on GNU Hurd.]) 2038 mhd_host_os='GNU Hurd' 2039 AC_MSG_RESULT([[$mhd_host_os]]) 2040 ], 2041 [haiku], 2042 [AC_DEFINE([[mhd_OS_IS_HAIKU]], [[1]], [Define to '1' if the library is hosted on Haiku.]) 2043 mhd_host_os='Haiku' 2044 AC_MSG_RESULT([[$mhd_host_os]]) 2045 ], 2046 [ 2047 AC_MSG_RESULT([unrecognised OS]) 2048 mhd_host_os="${host_os}" 2049 AC_MSG_WARN([Unrecognised OS $host_os]) 2050 AC_DEFINE([OTHEROS],1,[Some strange OS]) 2051 ] 2052 ) 2053 2054 AM_CONDITIONAL([CYGWIN_TARGET], [[test "x$os_is_windows" = "xyes" && \ 2055 test "x${os_is_native_w32}" != "xyes"]]) 2056 2057 AS_VAR_IF([os_is_windows], ["yes"], 2058 [ 2059 AC_MSG_CHECKING([[whether target W32 version is specified by precompiler defines]]) 2060 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 2061 /* Note: check logic is reversed for easy log reading */ 2062 #ifdef WINVER 2063 #error WINVER is defined 2064 choke me now; 2065 #endif 2066 #ifdef _WIN32_WINNT 2067 #error _WIN32_WINNT is defined 2068 choke me now; 2069 #endif 2070 #ifdef NTDDI 2071 #error NTDDI is defined 2072 choke me now; 2073 #endif 2074 ]],[[(void)0]]) 2075 ], [[mhd_w32_ver_preselect=no]], [[mhd_w32_ver_preselect=yes]] 2076 ) 2077 AC_MSG_RESULT([[${mhd_w32_ver_preselect}]]) 2078 AC_CHECK_HEADERS([windows.h sdkddkver.h], [], [], [AC_INCLUDES_DEFAULT]) 2079 AS_VAR_IF([mhd_w32_ver_preselect],["yes"], 2080 [ 2081 AC_MSG_CHECKING([[for specified target W32 version]]) 2082 AS_UNSET([[mhd_w32_ver]]) 2083 AS_UNSET([[mhd_w32_ver_msg]]) 2084 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 2085 #if _WIN32_WINNT+0 < 0x0501 2086 /* Check before headers inclusion */ 2087 #error _WIN32_WINNT is less than 0x0501 2088 choke me now; 2089 #endif 2090 2091 #ifdef HAVE_SDKDDKVER_H 2092 #include <sdkddkver.h> 2093 #endif 2094 #ifdef HAVE_WINDOWS_H 2095 #include <windows.h> 2096 #endif 2097 2098 #if _WIN32_WINNT+0 < 0x0501 2099 #error _WIN32_WINNT is less than 0x0501 2100 choke me now; 2101 #endif 2102 ]],[[(void)0]]) 2103 ], [], [ 2104 AC_MSG_RESULT([[pre-WinXP]]) 2105 AC_MSG_ERROR([[libmicrohttpd cannot be compiled for Windows version before Windows XP]]) 2106 ] 2107 ) 2108 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 2109 #ifdef HAVE_SDKDDKVER_H 2110 #include <sdkddkver.h> 2111 #endif 2112 #ifdef HAVE_WINDOWS_H 2113 #include <windows.h> 2114 #endif 2115 2116 #if _WIN32_WINNT+0 == 0x0501 2117 #error _WIN32_WINNT is 0x0501 2118 choke me now; 2119 #endif 2120 #if _WIN32_WINNT+0 == 0x0502 2121 #error _WIN32_WINNT is 0x0502 2122 choke me now; 2123 #endif 2124 ]],[[(void)0]]) 2125 ], [], [ 2126 mhd_w32_ver="WinXP" 2127 mhd_w32_ver_msg="WinXP (selected by precompiler flags)" 2128 ] 2129 ) 2130 AS_VAR_SET_IF([mhd_w32_ver], [], 2131 [ 2132 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 2133 #ifdef HAVE_SDKDDKVER_H 2134 #include <sdkddkver.h> 2135 #endif 2136 #ifdef HAVE_WINDOWS_H 2137 #include <windows.h> 2138 #endif 2139 2140 #if _WIN32_WINNT+0 < 0x0600 2141 #error _WIN32_WINNT is less than 0x0600 but greater than 0x0502 2142 choke me now; 2143 #endif 2144 ]],[[(void)0]]) 2145 ], [], [ 2146 AC_MSG_ERROR([[_WIN32_WINNT value is wrong (less than 0x0600 but greater than 0x0502)]]) 2147 ] 2148 ) 2149 2150 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 2151 #ifdef HAVE_SDKDDKVER_H 2152 #include <sdkddkver.h> 2153 #endif 2154 #ifdef HAVE_WINDOWS_H 2155 #include <windows.h> 2156 #endif 2157 2158 #if _WIN32_WINNT+0 == 0x0600 2159 #error _WIN32_WINNT is 0x0600 2160 choke me now; 2161 #endif 2162 ]],[[(void)0]]) 2163 ], [], [ 2164 mhd_w32_ver="Vista" 2165 mhd_w32_ver_msg="Vista (selected by precompiler flags)" 2166 ] 2167 ) 2168 ] 2169 ) 2170 2171 AS_VAR_SET_IF([mhd_w32_ver], [], 2172 [ 2173 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 2174 #ifdef HAVE_SDKDDKVER_H 2175 #include <sdkddkver.h> 2176 #endif 2177 #ifdef HAVE_WINDOWS_H 2178 #include <windows.h> 2179 #endif 2180 2181 #if _WIN32_WINNT+0 > 0x0600 2182 #error _WIN32_WINNT is greater than 0x0600 2183 choke me now; 2184 #endif 2185 ]],[[(void)0]]) 2186 ], [ 2187 mhd_w32_ver="unknown" 2188 mhd_w32_ver_msg="unknown (cannot be detected)" 2189 ], [ 2190 mhd_w32_ver="newer than Vista" 2191 mhd_w32_ver_msg="newer than Vista (selected by precompiler flags)" 2192 ] 2193 ) 2194 ] 2195 ) 2196 AC_MSG_RESULT([[${mhd_w32_ver}]]) 2197 ], [ 2198 mhd_w32_ver="Vista" 2199 mhd_w32_ver_msg="Vista (default, override by CPPFLAGS=-D_WIN32_WINNT=0xNNNN)" 2200 CPPFLAGS_ac="${CPPFLAGS_ac} -D_WIN32_WINNT=0x0600" 2201 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 2202 AC_MSG_CHECKING([[whether headers accept _WIN32_WINNT=0x0600]]) 2203 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 2204 #ifdef HAVE_SDKDDKVER_H 2205 #include <sdkddkver.h> 2206 #endif 2207 #ifdef HAVE_WINDOWS_H 2208 #include <windows.h> 2209 #endif 2210 #include <stdio.h> 2211 ]],[[(void)0]]) 2212 ], [ 2213 AC_MSG_RESULT([[yes]]) 2214 ], [ 2215 AC_MSG_RESULT([[no]]) 2216 AC_MSG_ERROR([Headers do not accept _WIN32_WINNT=0x0600. Consider override target W32 version by CPPFLAGS=-D_WIN32_WINNT=0xNNNN]) 2217 ] 2218 ) 2219 ] 2220 ) 2221 ] 2222 ) 2223 2224 AS_IF([test "x${os_is_windows}" = "xyes" && test "x${os_is_native_w32}" = "xyes"], 2225 [ 2226 AC_CACHE_CHECK([W32 run-time library type], [mhd_cv_wctr_type], 2227 [ 2228 AC_EGREP_CPP([MHDMARKER: UCRT run-time library in use!], [ 2229 #include <stdio.h> 2230 #if defined(_UCRT) 2231 #define CRT_STR "MHDMARKER: UCRT run-time library in use!" 2232 #endif 2233 #if defined(__MSVCRT_VERSION__) 2234 #if (__MSVCRT_VERSION__ >= 0xE00) && (__MSVCRT_VERSION__ < 0x1000) 2235 #define CRT_STR "MHDMARKER: UCRT run-time library in use!" 2236 #endif 2237 #if (__MSVCRT_VERSION__ > 0x1400) 2238 #define CRT_STR "MHDMARKER: UCRT run-time library in use!" 2239 #endif 2240 #endif 2241 2242 #ifndef CRT_STR 2243 #define CRT_STR "MHDMARKER: MSVCRT run-time library in use!" 2244 #endif 2245 2246 int main(void) 2247 { 2248 printf ("%\n", CRT_STR); 2249 return 0; 2250 } 2251 ], 2252 [mhd_cv_wctr_type="ucrt"], [mhd_cv_wctr_type="msvcrt"]) 2253 ] 2254 ) 2255 mhd_host_os="${mhd_host_os}-${mhd_cv_wctr_type}" 2256 AS_VAR_IF([mhd_cv_wctr_type], ["msvcrt"], 2257 [ 2258 # Use CFLAGS here to override user-supplied wrong CPPFLAGS. Durty trick, but choice is limited. 2259 AX_APPEND_COMPILE_FLAGS([-U__USE_MINGW_ANSI_STDIO -D__USE_MINGW_ANSI_STDIO=0], [CFLAGS_ac]) 2260 AC_SUBST([W32CRT], [MSVCRT]) 2261 ], [AC_SUBST([W32CRT], [UCRT])] 2262 ) 2263 2264 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 2265 LDFLAGS="${user_LDFLAGS}" 2266 AS_CASE([$mhd_w32_ver], 2267 [WinXP], 2268 [MHD_CHECK_ADD_CC_LDFLAG([-Wl,--major-subsystem-version,5,--minor-subsystem-version,1],[LDFLAGS_ac])], 2269 [Vista], 2270 [MHD_CHECK_ADD_CC_LDFLAG([-Wl,--major-subsystem-version,6,--minor-subsystem-version,0],[LDFLAGS_ac])] 2271 ) 2272 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 2273 ] 2274 ) 2275 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 2276 2277 2278 AC_ARG_WITH([threads], 2279 [AS_HELP_STRING([--with-threads=LIB],[choose threading library (posix, w32, auto, none) [auto]])], 2280 [], [with_threads='auto']) 2281 AS_CASE([[$with_threads]], 2282 [[win32]], [[with_threads='w32']], 2283 [[pthreads]], [[with_threads='posix']], 2284 [[posix]], [[:]], 2285 [[w32]], [[:]], 2286 [[none]], [[with_threads='none']], 2287 [[no]], [[with_threads='none']], 2288 [[auto]], [[:]], 2289 [AC_MSG_ERROR([[incorrect parameter "$with_threads" specified for --with-threads]])] 2290 ) 2291 2292 # Check for posix threads support, regardless of configure parameters as 2293 # testsuite uses only posix threads. 2294 AX_PTHREAD( 2295 [ 2296 mhd_have_posix_threads='yes' 2297 AC_DEFINE([[HAVE_PTHREAD_H]],[[1]],[Define to 1 if you have the <pthread.h> header file.]) 2298 CFLAGS="${CFLAGS_ac} ${PTHREAD_CFLAGS} ${user_CFLAGS}" 2299 MHD_CHECK_FUNC([pthread_sigmask], 2300 [[ 2301 #include <pthread.h> 2302 #include <signal.h> 2303 ]], 2304 [[ 2305 sigset_t nset, oset; 2306 sigemptyset (&nset); 2307 sigaddset (&nset, SIGPIPE); 2308 i][f (0 != pthread_sigmask(SIG_BLOCK, &nset, &oset)) return 1; 2309 ]], 2310 [AC_DEFINE([[HAVE_PTHREAD_SIGMASK]],[[1]],[Define to 1 if you have the pthread_sigmask(3) function.])] 2311 ) 2312 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 2313 ],[[mhd_have_posix_threads='no']]) 2314 AM_CONDITIONAL([HAVE_POSIX_THREADS],[test "x$mhd_have_posix_threads" = "xyes"]) 2315 2316 mhd_have_w32_threads='no' 2317 AS_IF([[test "x$with_threads" = "xauto"]], 2318 [ 2319 AS_IF([[test "x$os_is_windows" = "xyes"]], 2320 [ 2321 AC_MSG_CHECKING([[for W32 threads]]) 2322 AC_LINK_IFELSE( 2323 [AC_LANG_PROGRAM([[ 2324 #include <windows.h> 2325 ]], [ HANDLE h = CreateThread(NULL, 0, NULL, NULL, 0, NULL);])] 2326 , [[mhd_have_w32_threads='yes']], [[mhd_have_w32_threads='no']] 2327 ) 2328 AC_MSG_RESULT([[$mhd_have_w32_threads]]) 2329 ]) 2330 ] 2331 ) 2332 2333 AC_MSG_CHECKING([[for threading lib to use with libmicrohttpd ($with_threads)]]) 2334 AS_IF([test "x$with_threads" = "xposix"], 2335 [ # forced posix threads 2336 AS_IF([test "x$mhd_have_posix_threads" = "xyes"], [USE_THREADS='posix'], 2337 [ AS_IF([[test "x$os_is_windows" = "xyes"]] , 2338 [ AC_MSG_ERROR([[Posix threads are not available. Try to configure --with-threads=auto]])], 2339 [ AC_MSG_ERROR([[No threading lib is available. Consider installing pthreads]])] ) 2340 ]) 2341 ]) 2342 AS_IF([test "x$with_threads" = "xw32"], 2343 [ # forced w32 threads 2344 AS_IF([[test "x$mhd_have_w32_threads" = "xyes"]], 2345 [[ USE_THREADS='w32' ]], 2346 [ AC_MSG_ERROR([[W32 threads are not available. Try to configure --with-threads=auto]])]) 2347 ]) 2348 AS_IF([test "x$with_threads" = "xauto"], 2349 [# automatic threads lib selection 2350 AS_IF([[test "x$os_is_native_w32" = "xyes" && test "x$mhd_have_w32_threads" = "xyes"]] , 2351 [[ USE_THREADS='w32' ]] , 2352 [[ test "x$mhd_have_posix_threads" = "xyes" ]], [[ USE_THREADS='posix' ]], 2353 [[ test "x$mhd_have_w32_threads" = "xyes" ]], [[ USE_THREADS='w32' ]], 2354 [ AC_MSG_ERROR([[No threading lib is available. Consider installing pthreads]]) ] 2355 )]) 2356 AS_IF([test "x$with_threads" = "xnone"], 2357 [USE_THREADS='none']) 2358 2359 AS_IF([test "x$USE_THREADS" = "xposix"], 2360 [CC="$PTHREAD_CC" 2361 AC_DEFINE([mhd_THREADS_KIND_POSIX],[1],[define to use pthreads]) 2362 MHD_LIB_CFLAGS="$MHD_LIB_CFLAGS $PTHREAD_CFLAGS" 2363 MHD_LIBDEPS="$PTHREAD_LIBS $MHD_LIBDEPS" 2364 MHD_LIBDEPS_PKGCFG="$PTHREAD_LIBS $MHD_LIBDEPS_PKGCFG"], 2365 [AS_IF([test "x$USE_THREADS" = "xw32"], 2366 [AC_DEFINE([mhd_THREADS_KIND_W32],[1],[define to use W32 threads])])]) 2367 AM_CONDITIONAL([USE_POSIX_THREADS], [test "x$USE_THREADS" = "xposix"]) 2368 AM_CONDITIONAL([USE_W32_THREADS], [test "x$USE_THREADS" = "xw32"]) 2369 AM_CONDITIONAL([MHD_SUPPORT_THREADS], [test "x$USE_THREADS" != "xnone"]) 2370 AC_MSG_RESULT([$USE_THREADS]) 2371 2372 AC_ARG_ENABLE([[thread-names]], 2373 [AS_HELP_STRING([--disable-thread-names],[do not set names on MHD generated threads [auto]])], 2374 [], [enable_thread_names='auto']) 2375 2376 AS_IF([test "x$enable_thread_names" != "xno" && test "x$USE_THREADS" = "xposix"],[ 2377 # Check for thread name function 2378 HAVE_THREAD_NAME_FUNC="no" 2379 SAVE_LIBS="$LIBS" 2380 LIBS="$PTHREAD_LIBS $LIBS" 2381 CFLAGS="${CFLAGS_ac} $PTHREAD_CFLAGS ${user_CFLAGS}" 2382 AC_CHECK_HEADERS([pthread_np.h],[],[], 2383 [ 2384 AC_INCLUDES_DEFAULT 2385 [ 2386 #include <pthread.h> 2387 ] 2388 ]) 2389 2390 # Try to find how to set thread name by thread attributes. 2391 # If pthread_attr_setname_np(3) is not declared, it's not possible to detect 2392 # form of pthread_attr_setname_np(3) due to C "feature" "implicit declaration". 2393 AC_CHECK_DECL([[pthread_attr_setname_np]],[],[],[[ 2394 #include <pthread.h> 2395 #ifdef HAVE_PTHREAD_NP_H 2396 #include <pthread_np.h> 2397 #endif 2398 ]]) 2399 2400 AS_IF([[test "x$ac_cv_have_decl_pthread_attr_setname_np" = "xyes"]], 2401 [AC_MSG_CHECKING([[for pthread_attr_setname_np(3) in NetBSD or OSF1 form]]) 2402 AC_LINK_IFELSE( 2403 [AC_LANG_PROGRAM([[ 2404 #include <pthread.h> 2405 #ifdef HAVE_PTHREAD_NP_H 2406 #include <pthread_np.h> 2407 #endif 2408 ]], [[ 2409 pthread_attr_t thr_attr; 2410 pthread_attr_init(&thr_attr); 2411 pthread_attr_setname_np(&thr_attr, "name", 0); 2412 pthread_attr_destroy(&thr_attr); 2413 ]])], 2414 [AC_DEFINE([[HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD]], [[1]], [Define if you have NetBSD form (or OSF1 form) of pthread_attr_setname_np(3) function.]) 2415 HAVE_THREAD_NAME_FUNC="yes" 2416 AC_MSG_RESULT([[yes]])], 2417 [AC_MSG_RESULT([[no]])] 2418 ) 2419 ]) 2420 2421 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_attr_setname_np" = "xyes"]], 2422 [AC_MSG_CHECKING([[for pthread_attr_setname_np(3) in IBM i or Solaris form]]) 2423 AC_LINK_IFELSE( 2424 [AC_LANG_PROGRAM([[ 2425 #include <pthread.h> 2426 #ifdef HAVE_PTHREAD_NP_H 2427 #include <pthread_np.h> 2428 #endif 2429 ]], [[ 2430 pthread_attr_t thr_attr; 2431 pthread_attr_init(&thr_attr); 2432 pthread_attr_setname_np(&thr_attr, "name"); 2433 pthread_attr_destroy(&thr_attr); 2434 ]])], 2435 [AC_DEFINE([[HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI]], [[1]], [Define if you have IBM i form (or Solaris form) of pthread_attr_setname_np(3) function.]) 2436 HAVE_THREAD_NAME_FUNC="yes" 2437 AC_MSG_RESULT([[yes]])], 2438 [AC_MSG_RESULT([[no]])] 2439 ) 2440 ]) 2441 2442 # Try to find how to set thread name for started thread - less convenient 2443 # than setting name by attributes. 2444 # If pthread_setname_np(3) is not declared, it's not possible to detect 2445 # form of pthread_setname_np(3) due to C "feature" "implicit declaration". 2446 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes"]], 2447 [AC_CHECK_DECL([[pthread_setname_np]],[],[],[[ 2448 #include <pthread.h> 2449 #ifdef HAVE_PTHREAD_NP_H 2450 #include <pthread_np.h> 2451 #endif 2452 ]]) 2453 ]) 2454 2455 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]], 2456 [AC_MSG_CHECKING([[for pthread_setname_np(3) in NetBSD or OSF1 form]]) 2457 AC_LINK_IFELSE( 2458 [AC_LANG_PROGRAM([[ 2459 #include <pthread.h> 2460 #ifdef HAVE_PTHREAD_NP_H 2461 #include <pthread_np.h> 2462 #endif 2463 ]], [[int res = pthread_setname_np(pthread_self(), "name", 0); if (res) return res;]])], 2464 [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_NETBSD]], [[1]], [Define if you have NetBSD form (or OSF1 form) of pthread_setname_np(3) function.]) 2465 HAVE_THREAD_NAME_FUNC="yes" 2466 AC_MSG_RESULT([[yes]])], 2467 [AC_MSG_RESULT([[no]])] 2468 ) 2469 ]) 2470 2471 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]], 2472 [AC_MSG_CHECKING([[for pthread_setname_np(3) in GNU/Linux form]]) 2473 AC_LINK_IFELSE( 2474 [AC_LANG_PROGRAM([[ 2475 #include <pthread.h> 2476 #ifdef HAVE_PTHREAD_NP_H 2477 #include <pthread_np.h> 2478 #endif 2479 ]], [[int res = pthread_setname_np(pthread_self(), "name"); if (res) return res;]])], 2480 [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_GNU]], [[1]], [Define if you have GNU/Linux form of pthread_setname_np(3) function.]) 2481 HAVE_THREAD_NAME_FUNC="yes" 2482 AC_MSG_RESULT([[yes]])], 2483 [AC_MSG_RESULT([[no]])] 2484 ) 2485 ]) 2486 2487 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]], 2488 [AC_MSG_CHECKING([[for pthread_setname_np(3) in Darwin form]]) 2489 AC_LINK_IFELSE( 2490 [AC_LANG_PROGRAM([[ 2491 #include <pthread.h> 2492 #ifdef HAVE_PTHREAD_NP_H 2493 #include <pthread_np.h> 2494 #endif 2495 ]], [[int res = pthread_setname_np("name"); if (res) return res;]])], 2496 [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_DARWIN]], [[1]], [Define if you have Darwin form of pthread_setname_np(3) function.]) 2497 HAVE_THREAD_NAME_FUNC="yes" 2498 AC_MSG_RESULT([[yes]])], 2499 [AC_MSG_RESULT([[no]])] 2500 ) 2501 ]) 2502 2503 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes"]], 2504 [ 2505 AC_CHECK_DECL([[pthread_set_name_np]], 2506 [ 2507 AC_MSG_CHECKING([[for pthread_set_name_np(3) in FreeBSD form]]) 2508 AC_LINK_IFELSE( 2509 [AC_LANG_PROGRAM([[ 2510 #include <pthread.h> 2511 #ifdef HAVE_PTHREAD_NP_H 2512 #include <pthread_np.h> 2513 #endif 2514 ]], [[pthread_set_name_np(pthread_self(), "name");]])], 2515 [AC_DEFINE([[HAVE_PTHREAD_SET_NAME_NP_FREEBSD]], [[1]], [Define if you have FreeBSD form of pthread_set_name_np(3) function.]) 2516 HAVE_THREAD_NAME_FUNC="yes" 2517 AC_MSG_RESULT([[yes]])], 2518 [AC_MSG_RESULT([[no]])] 2519 ) 2520 ],[],[[ 2521 #include <pthread.h> 2522 #ifdef HAVE_PTHREAD_NP_H 2523 #include <pthread_np.h> 2524 #endif 2525 ]] 2526 ) 2527 ]) 2528 2529 LIBS="$SAVE_LIBS" 2530 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 2531 ]) 2532 2533 AS_IF([[test "x$enable_thread_names" != "xno"]], 2534 [ 2535 AC_MSG_CHECKING([[whether to enable thread names]]) 2536 AC_COMPILE_IFELSE( 2537 [AC_LANG_PROGRAM([], [[ 2538 #ifdef MHD_NO_THREAD_NAMES 2539 #error Thread names are disabled. 2540 choke me 2541 #endif 2542 2543 /* Keep in sync with mhd_threads.h */ 2544 #if defined(mhd_THREADS_KIND_POSIX) && (defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) || \ 2545 defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || \ 2546 defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) ) 2547 (void) 0; /* no-op */ 2548 #elif defined(mhd_THREADS_KIND_W32) && defined(_MSC_FULL_VER) 2549 (void) 0; /* no-op */ 2550 #else 2551 #error No thread name function is available. 2552 choke me 2553 #endif 2554 ]]) 2555 ], [ 2556 enable_thread_names='yes' 2557 ], [ 2558 AS_IF([[test "x$enable_thread_names" = "xyes"]], 2559 [ 2560 AC_MSG_RESULT([[no]]) 2561 AC_MSG_ERROR([[thread names was explicitly requested, but thread name function is not available]]) 2562 ]) 2563 enable_thread_names='no' 2564 ]) 2565 AC_MSG_RESULT([[$enable_thread_names]]) 2566 ]) 2567 2568 AS_IF([[test "x$enable_thread_names" = "xno"]], 2569 [AC_DEFINE([[MHD_NO_THREAD_NAMES]], [[1]], [Define to 1 to disable setting name on generated threads])]) 2570 2571 AM_CONDITIONAL(HAVE_W32, [test "x$os_is_native_w32" = "xyes"]) 2572 AM_CONDITIONAL(MHD_SOCKETS_KIND_POSIX, [test "x$os_is_native_w32" != "xyes"]) 2573 AM_CONDITIONAL(MHD_SOCKETS_KIND_WINSOCK, [test "x$os_is_native_w32" = "xyes"]) 2574 w32_shared_lib_exp=no 2575 AS_IF([test "x$enable_shared" = "xyes" && test "x$os_is_native_w32" = "xyes"], 2576 [ 2577 AS_IF([test "x$ac_cv_use_ms_lib_tool" = "xyes" || test -n "$DLLTOOL"], 2578 [ 2579 w32_shared_lib_exp=yes 2580 use_expfile="no" 2581 AS_VAR_IF([ac_cv_use_ms_lib_tool], ["yes"], [use_expfile="yes"], 2582 [ 2583 AC_CACHE_CHECK([whether $DLLTOOL supports export file generation], [mhd_cv_dlltool_expfile], 2584 [ 2585 AS_IF([AC_RUN_LOG([$DLLTOOL -e conftest.exp >&2 ])], 2586 [ 2587 AS_IF([test -f conftest.exp], [mhd_cv_dlltool_expfile="yes"], [mhd_cv_dlltool_expfile="no"]) 2588 ], [mhd_cv_dlltool_expfile="no"] 2589 ) 2590 rm -f conftest.exp 2591 ] 2592 ) 2593 use_expfile="${mhd_cv_dlltool_expfile}" 2594 ] 2595 ) 2596 ], 2597 [ 2598 AC_MSG_WARN([[GNU dlltool or MS lib.exe is required for creating shared library export on W32]]) 2599 AC_MSG_WARN([[Export library libmicrohttpd.lib will not be created]]) 2600 ] 2601 ) 2602 ] 2603 ) 2604 AM_CONDITIONAL([W32_SHARED_LIB_EXP], [test "x$w32_shared_lib_exp" = "xyes"]) 2605 AM_CONDITIONAL([USE_MS_LIB_TOOL], [test "x$ac_cv_use_ms_lib_tool" = "xyes"]) 2606 AM_CONDITIONAL([USE_EXPORT_FILE], [test "x$use_expfile" = "xyes"]) 2607 2608 dnl gethostbyname() is not really needed 2609 dnl AC_SEARCH_LIBS([gethostbyname], [nsl]) 2610 MHD_FIND_LIB([socket], 2611 [[ 2612 #ifdef HAVE_SYS_TYPES_H 2613 #include <sys/types.h> 2614 #endif 2615 #ifdef HAVE_SYS_SOCKET_H 2616 #include <sys/socket.h> 2617 #elif defined(HAVE_UNISTD_H) 2618 #include <unistd.h> 2619 #endif 2620 #ifdef HAVE_SOCKLIB_H 2621 #include <sockLib.h> 2622 #endif 2623 #if defined(_WIN32) && ! defined(__CYGWIN__) 2624 #include <winsock2.h> 2625 #endif 2626 ]], 2627 [(void)socket(0, 0, 0);], 2628 [socket ws2_32 xnet network], 2629 [ 2630 AS_VAR_IF([[mhd_cv_find_lib_socket]],[["none required"]], [], 2631 [ 2632 MHD_LIBDEPS_PKGCFG="${mhd_cv_find_lib_socket} $MHD_LIBDEPS_PKGCFG" 2633 ] 2634 ) 2635 ], 2636 [AC_MSG_ERROR([[cannot find header or library required for function socket()]])] 2637 ) 2638 2639 MHD_CHECK_SOCKET_SHUTDOWN_TRIGGER([AC_DEFINE([HAVE_LISTEN_SHUTDOWN],[1],[can use shutdown on listen sockets])]) 2640 AM_CONDITIONAL([HAVE_LISTEN_SHUTDOWN], [test "x$mhd_cv_host_shtdwn_trgr_select" = "xyes"]) 2641 2642 AC_CACHE_CHECK([fo][r system default FD_SETSIZE value],[mhd_cv_sys_fd_setsize_value], 2643 [ 2644 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} -UFD_SETSIZE" 2645 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS} -UFD_SETSIZE" 2646 AC_COMPUTE_INT([mhd_cv_sys_fd_setsize_value],[FD_SETSIZE],dnl 2647 [[ 2648 #ifdef HAVE_SYS_TIME_H 2649 #include <sys/time.h> 2650 #endif 2651 #ifdef HAVE_SYS_TYPES_H 2652 #include <sys/types.h> 2653 #endif 2654 #ifdef HAVE_UNISTD_H 2655 #include <unistd.h> 2656 #endif 2657 #ifdef HAVE_SYS_SOCKET_H 2658 #include <sys/socket.h> 2659 #endif 2660 #ifdef HAVE_SOCKLIB_H 2661 #include <sockLib.h> 2662 #endif 2663 #if defined(_WIN32) && ! defined(__CYGWIN__) 2664 #include <winsock2.h> 2665 #endif 2666 #ifdef HAVE_SYS_SELECT_H 2667 #include <sys/select.h> 2668 #endif 2669 ]], [mhd_cv_sys_fd_setsize_value="unknown"] 2670 ) 2671 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 2672 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 2673 AS_IF([test "x${mhd_cv_sys_fd_setsize_value}" != "xunknown" && \ 2674 test "${mhd_cv_sys_fd_setsize_value}" -eq "0" \ 2675 ], [mhd_cv_sys_fd_setsize_value="unknown"] 2676 ) 2677 ] 2678 ) 2679 AS_VAR_IF([mhd_cv_sys_fd_setsize_value],["unknown"],[:], 2680 [ 2681 AC_DEFINE_UNQUOTED([MHD_SYS_FD_SETSIZE_],[${mhd_cv_sys_fd_setsize_value}], 2682 [Define to system default value of FD_SETSIZE macro] 2683 ) 2684 ] 2685 ) 2686 AM_CONDITIONAL([NEED_SYS_FD_SET_SIZE_VALUE],[test "x${mhd_cv_sys_fd_setsize_value}" = "xunknown"]) 2687 2688 AC_CACHE_CHECK([fo][r current FD_SETSIZE value],[mhd_cv_fd_setsize_value], 2689 [ 2690 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 2691 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 2692 AS_IF([test "x${cross_compiling}" != "xno" && test "x${mhd_cv_sys_fd_setsize_value}" != "xunknown"], 2693 [ 2694 AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 2695 [[ 2696 #ifdef HAVE_SYS_TIME_H 2697 #include <sys/time.h> 2698 #endif 2699 #ifdef HAVE_SYS_TYPES_H 2700 #include <sys/types.h> 2701 #endif 2702 #ifdef HAVE_UNISTD_H 2703 #include <unistd.h> 2704 #endif 2705 #ifdef HAVE_SYS_SOCKET_H 2706 #include <sys/socket.h> 2707 #endif 2708 #ifdef HAVE_SOCKLIB_H 2709 #include <sockLib.h> 2710 #endif 2711 #if defined(_WIN32) && ! defined(__CYGWIN__) 2712 #include <winsock2.h> 2713 #endif 2714 #ifdef HAVE_SYS_SELECT_H 2715 #include <sys/select.h> 2716 #endif 2717 2718 #define DETECTED_FD_SETZIE_VALUE ${mhd_cv_sys_fd_setsize_value} 2719 2720 #if (FD_SETSIZE) != (DETECTED_FD_SETZIE_VALUE) 2721 #error The current default FD_SETSIZE value is different from ${mhd_cv_sys_fd_setsize_value} 2722 choke me here now 2723 #endif /* (FD_SETSIZE) != (DETECTED_FD_SETZIE_VALUE) */ 2724 2725 #if (FD_SETSIZE) != (${mhd_cv_sys_fd_setsize_value}) 2726 #error The current default FD_SETSIZE value is different from ${mhd_cv_sys_fd_setsize_value} 2727 choke me here now 2728 #endif /* (FD_SETSIZE) != (${mhd_cv_sys_fd_setsize_value}) */ 2729 ]],[] 2730 ) 2731 ], 2732 [mhd_cv_fd_setsize_value="${mhd_cv_sys_fd_setsize_value}"] 2733 ) 2734 ] 2735 ) 2736 AS_VAR_SET_IF([mhd_cv_fd_setsize_value],[:], 2737 [ 2738 AC_COMPUTE_INT([mhd_cv_fd_setsize_value],[FD_SETSIZE],dnl 2739 [[ 2740 #ifdef HAVE_SYS_TIME_H 2741 #include <sys/time.h> 2742 #endif 2743 #ifdef HAVE_SYS_TYPES_H 2744 #include <sys/types.h> 2745 #endif 2746 #ifdef HAVE_UNISTD_H 2747 #include <unistd.h> 2748 #endif 2749 #ifdef HAVE_SYS_SOCKET_H 2750 #include <sys/socket.h> 2751 #endif 2752 #ifdef HAVE_SOCKLIB_H 2753 #include <sockLib.h> 2754 #endif 2755 #if defined(_WIN32) && ! defined(__CYGWIN__) 2756 #include <winsock2.h> 2757 #endif 2758 #ifdef HAVE_SYS_SELECT_H 2759 #include <sys/select.h> 2760 #endif 2761 ]], [mhd_cv_fd_setsize_value="unknown"] 2762 ) 2763 ] 2764 ) 2765 AS_IF([test "x${mhd_cv_fd_setsize_value}" != "xunknown" && \ 2766 test "${mhd_cv_fd_setsize_value}" -eq "0"], 2767 [mhd_cv_fd_setsize_value="unknown"] 2768 ) 2769 ] 2770 ) 2771 2772 2773 AC_CACHE_CHECK([whether FD_SETSIZE is overridable],[mhd_cv_fd_setsize_overridable], 2774 [ 2775 AS_VAR_IF([mhd_cv_fd_setsize_value],["unknown"], 2776 [ 2777 AS_VAR_IF([mhd_cv_sys_fd_setsize_value],["unknown"], 2778 [ 2779 # Assume the most popular FD_SETSIZE value 2780 base_fd_setsize=1024 2781 ], 2782 [base_fd_setsize="${mhd_cv_sys_fd_setsize_value}"] 2783 ) 2784 base_min_fd_setsize="${base_fd_setsize}" 2785 ], 2786 [ 2787 AS_VAR_IF([mhd_cv_sys_fd_setsize_value],["unknown"], 2788 [ 2789 base_fd_setsize="${mhd_cv_fd_setsize_value}" 2790 base_min_fd_setsize="${base_fd_setsize}" 2791 ], 2792 [ 2793 AS_IF([test "${mhd_cv_fd_setsize_value}" -ge "${mhd_cv_sys_fd_setsize_value}"], 2794 [ 2795 base_fd_setsize="${mhd_cv_fd_setsize_value}" 2796 base_min_fd_setsize="${mhd_cv_sys_fd_setsize_value}" 2797 ], 2798 [ 2799 base_fd_setsize="${mhd_cv_sys_fd_setsize_value}" 2800 base_min_fd_setsize="${mhd_cv_fd_setsize_value}" 2801 ] 2802 ) 2803 ] 2804 ) 2805 ] 2806 ) 2807 # Use two times larger FD_SETSIZE value for test 2808 AS_VAR_ARITH([test_fd_setsize],[${base_fd_setsize} '+' ${base_fd_setsize}]) 2809 AS_IF([test "${test_fd_setsize}" -lt "128"],[test_fd_setsize=128]) 2810 test_type_fd_setsize="larger" 2811 2812 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 2813 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 2814 2815 _AS_ECHO_LOG([testing whether FD_SETSIZE test value (${test_fd_setsize}) is suitable for 'int' type]) 2816 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], 2817 [[ 2818 static int test_arr1[(((long long)${test_fd_setsize}) != ((int)${test_fd_setsize})) ? -1 : 1]; 2819 static int test_arr2[(0 > ((int)${test_fd_setsize})) ? -1 : 1]; 2820 test_arr1[0] = 0; 2821 test_arr2[0] = 0; 2822 i][f (test_arr1[0] != test_arr2[0]) return 1; 2823 ]] 2824 ) 2825 ],[], 2826 [ 2827 _AS_ECHO_LOG([The selected test FD_SETSIZE value (${test_fd_setsize}) is too large for 'int' type]) 2828 AS_VAR_ARITH([test_fd_setsize],[${base_min_fd_setsize} '/' '2']) 2829 test_type_fd_setsize="smaller" 2830 ] 2831 ) 2832 2833 _AS_ECHO_LOG([will try ${test_fd_setsize} as FD_SETSIZE value]) 2834 2835 AS_IF([test "x${cross_compiling}" = "xno" && test "x${test_type_fd_setsize}" = "xlarger"], 2836 [ 2837 _AS_ECHO_LOG([will try ${test_fd_setsize} as FD_SETSIZE value with run test]) 2838 AC_RUN_IFELSE( 2839 [ 2840 AC_LANG_SOURCE( 2841 [[ 2842 #ifdef FD_SETSIZE 2843 #undef FD_SETSIZE 2844 #endif /* FD_SETSIZE */ 2845 2846 #define FD_SETSIZE ${test_fd_setsize} 2847 #define MY_TEST_FD_SETSIZE ${test_fd_setsize} 2848 2849 #ifdef HAVE_SYS_TIME_H 2850 #include <sys/time.h> 2851 #endif 2852 #ifdef HAVE_SYS_TYPES_H 2853 #include <sys/types.h> 2854 #endif 2855 #ifdef HAVE_UNISTD_H 2856 #include <unistd.h> 2857 #endif 2858 #ifdef HAVE_SYS_SOCKET_H 2859 #include <sys/socket.h> 2860 #endif 2861 #ifdef HAVE_SOCKLIB_H 2862 #include <sockLib.h> 2863 #endif 2864 #if defined(_WIN32) && ! defined(__CYGWIN__) 2865 #include <winsock2.h> 2866 #define MHD_TEST_SOCKET_TYPE SOCKET 2867 #else 2868 #define MHD_TEST_SOCKET_TYPE int 2869 #endif 2870 #ifdef HAVE_SYS_SELECT_H 2871 #include <sys/select.h> 2872 #endif 2873 2874 #include <string.h> 2875 #include <stdio.h> 2876 2877 /* Test fo][r mismatch by macro check */ 2878 #if (FD_SETSIZE) != (MY_TEST_FD_SETSIZE) 2879 #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize} 2880 choke me here now; 2881 #endif /* (FD_SETSIZE) != (MY_TEST_FD_SETSIZE) */ 2882 2883 /* Additional test fo][r mismatch by macro check */ 2884 #if (FD_SETSIZE) != (${test_fd_setsize}) 2885 #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize} 2886 choke me here now; 2887 #endif /* (FD_SETSIZE) != (${test_fd_setsize}) */ 2888 2889 static unsigned long var_fd_setsize_value = FD_SETSIZE; 2890 static unsigned long var_my_test_fd_setsize_value = MY_TEST_FD_SETSIZE; 2891 2892 int main(void) 2893 { 2894 fd_set fds_num_one_copy; 2895 fd_set fds_num_three_copy; 2896 fd_set test_fdsets[6]; 2897 int i; 2898 int ret = 0; 2899 #if defined(_WIN32) && ! defined(__CYGWIN__) 2900 WSADATA wsa_data; 2901 2902 if (0 != WSAStartup(MAKEWORD(2, 2), &wsa_data)) 2903 return 21; 2904 if (MAKEWORD(2, 2) != wsa_data.wVersion) 2905 { 2906 WSACleanup(); 2907 return 22; 2908 } 2909 #endif /* _WIN32 && ! __CYGWIN__ */ 2910 2911 /* Init with zeros to make sure that slack areas are equal */ 2912 memset(test_fdsets, 0, sizeof(test_fdsets)); 2913 2914 /* Correctly init fd_sets */ 2915 for (i = 0; i < 6; ++i) 2916 FD_ZERO(test_fdsets + i); 2917 2918 /* Make copies of zero-inited fd_sets */ 2919 memcpy(&fds_num_one_copy, test_fdsets + 1, sizeof(fd_set)); 2920 memcpy(&fds_num_three_copy, test_fdsets + 3, sizeof(fd_set)); 2921 2922 if (var_fd_setsize_value != var_my_test_fd_setsize_value) 2923 { 2924 fprintf (stderr, "System headers redefined FD_SETSIZE to another value (%lu).\n", 2925 (unsigned long) FD_SETSIZE); 2926 ret = 2; 2927 } 2928 else 2929 { 2930 /* Set (almost) all FDs in test_fdset[2] */ 2931 for (i = 1; i < FD_SETSIZE; ++i) 2932 FD_SET((MHD_TEST_SOCKET_TYPE)i, test_fdsets + 2); 2933 2934 if (! FD_ISSET((MHD_TEST_SOCKET_TYPE)1, test_fdsets + 2)) 2935 { 2936 fprintf (stderr, "FD number one in original fd_set is unset, while should be set.\n"); 2937 ret |= 3; 2938 } 2939 if (! FD_ISSET((MHD_TEST_SOCKET_TYPE)(FD_SETSIZE - 1), test_fdsets + 2)) 2940 { 2941 fprintf (stderr, "FD number %lu in original fd_set is unset, while should be set.\n", 2942 (unsigned long) FD_SETSIZE); 2943 ret |= 3; 2944 } 2945 2946 if (FD_ISSET((MHD_TEST_SOCKET_TYPE)1, test_fdsets + 1)) 2947 { 2948 fprintf (stderr, "FD number one in the first fd_set is unset, while should be set.\n"); 2949 ret |= 4; 2950 } 2951 if (FD_ISSET((MHD_TEST_SOCKET_TYPE)(FD_SETSIZE - 1), test_fdsets + 1)) 2952 { 2953 fprintf (stderr, "FD number %lu in the first fd_set is unset, while should be set.\n", 2954 (unsigned long) FD_SETSIZE); 2955 ret |= 4; 2956 } 2957 if (0 != memcmp (&fds_num_one_copy, test_fdsets + 1, sizeof(fd_set))) 2958 { 2959 fprintf (stderr, "The first fd_set has been altered.\n"); 2960 ret |= 4; 2961 } 2962 2963 if (FD_ISSET((MHD_TEST_SOCKET_TYPE)1, test_fdsets + 3)) 2964 { 2965 fprintf (stderr, "FD number one in the third fd_set is unset, while should be set.\n"); 2966 ret |= 8; 2967 } 2968 if (FD_ISSET((MHD_TEST_SOCKET_TYPE)(FD_SETSIZE - 1), test_fdsets + 3)) 2969 { 2970 fprintf (stderr, "FD number %lu in the third fd_set is unset, while should be set.\n", 2971 (unsigned long) FD_SETSIZE); 2972 ret |= 8; 2973 } 2974 if (0 != memcmp (&fds_num_three_copy, test_fdsets + 3, sizeof(fd_set))) 2975 { 2976 fprintf (stderr, "The third fd_set has been altered.\n"); 2977 ret |= 8; 2978 } 2979 } 2980 #if defined(_WIN32) && ! defined(__CYGWIN__) 2981 WSACleanup(); 2982 #endif /* _WIN32 && ! __CYGWIN__ */ 2983 return ret; 2984 } 2985 ]] 2986 ) 2987 ], 2988 [mhd_cv_fd_setsize_overridable="yes"], 2989 [mhd_cv_fd_setsize_overridable="no"], 2990 [[# Not used when cross-compiling ]] 2991 ) 2992 ], 2993 [ 2994 _AS_ECHO_LOG([will try ${test_fd_setsize} as FD_SETSIZE with simple compile test]) 2995 AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 2996 [[ 2997 #ifdef FD_SETSIZE 2998 #undef FD_SETSIZE 2999 #endif /* FD_SETSIZE */ 3000 3001 #define FD_SETSIZE ${test_fd_setsize} 3002 #define MY_TEST_FD_SETSIZE ${test_fd_setsize} 3003 3004 #ifdef HAVE_SYS_TIME_H 3005 #include <sys/time.h> 3006 #endif 3007 #ifdef HAVE_SYS_TYPES_H 3008 #include <sys/types.h> 3009 #endif 3010 #ifdef HAVE_UNISTD_H 3011 #include <unistd.h> 3012 #endif 3013 #ifdef HAVE_SYS_SOCKET_H 3014 #include <sys/socket.h> 3015 #endif 3016 #ifdef HAVE_SOCKLIB_H 3017 #include <sockLib.h> 3018 #endif 3019 #if defined(_WIN32) && ! defined(__CYGWIN__) 3020 #include <winsock2.h> 3021 #endif 3022 #ifdef HAVE_SYS_SELECT_H 3023 #include <sys/select.h> 3024 #endif 3025 3026 /* Test fo][r mismatch by macro check */ 3027 #if (FD_SETSIZE) != (MY_TEST_FD_SETSIZE) 3028 #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize} 3029 choke me here now 3030 #endif /* (FD_SETSIZE) != (MY_TEST_FD_SETSIZE) */ 3031 3032 /* Additional test fo][r mismatch by macro check */ 3033 #if (FD_SETSIZE) != (${test_fd_setsize}) 3034 #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize} 3035 choke me here now 3036 #endif /* (FD_SETSIZE) != (${test_fd_setsize}) */ 3037 ]],[] 3038 ) 3039 ], 3040 [ 3041 _AS_ECHO_LOG([comple test succeed, will check whether another FD_SETSIZE value changes the size of 'fd_set']) 3042 3043 # Check current size of fd_set 3044 _AS_ECHO_LOG([find the sizeof(fd_setsize) with current default (${mhd_cv_fd_setsize_value}) FD_SETSIZE value]) 3045 AC_COMPUTE_INT([sizeof_cur_fd_set],[sizeof(fd_set)],dnl 3046 [[ 3047 #ifdef HAVE_SYS_TIME_H 3048 #include <sys/time.h> 3049 #endif 3050 #ifdef HAVE_SYS_TYPES_H 3051 #include <sys/types.h> 3052 #endif 3053 #ifdef HAVE_UNISTD_H 3054 #include <unistd.h> 3055 #endif 3056 #ifdef HAVE_SYS_SOCKET_H 3057 #include <sys/socket.h> 3058 #endif 3059 #ifdef HAVE_SOCKLIB_H 3060 #include <sockLib.h> 3061 #endif 3062 #if defined(_WIN32) && ! defined(__CYGWIN__) 3063 #include <winsock2.h> 3064 #endif 3065 #ifdef HAVE_SYS_SELECT_H 3066 #include <sys/select.h> 3067 #endif 3068 ]], [sizeof_cur_fd_set="unknown"] 3069 ) 3070 _AS_ECHO_LOG([the sizeof(fd_setsize) with current default (${mhd_cv_fd_setsize_value}) FD_SETSIZE value is ${sizeof_cur_fd_set}]) 3071 3072 # Check the size of fd_set with redefined FD_SETSIZE 3073 _AS_ECHO_LOG([find the sizeof(fd_setsize) with redefined (${test_fd_setsize}) FD_SETSIZE value]) 3074 AC_COMPUTE_INT([sizeof_mod_fd_set],[sizeof(fd_set)],dnl 3075 [[ 3076 #ifdef FD_SETSIZE 3077 #undef FD_SETSIZE 3078 #endif /* FD_SETSIZE */ 3079 3080 #define FD_SETSIZE ${test_fd_setsize} 3081 3082 #ifdef HAVE_SYS_TIME_H 3083 #include <sys/time.h> 3084 #endif 3085 #ifdef HAVE_SYS_TYPES_H 3086 #include <sys/types.h> 3087 #endif 3088 #ifdef HAVE_UNISTD_H 3089 #include <unistd.h> 3090 #endif 3091 #ifdef HAVE_SYS_SOCKET_H 3092 #include <sys/socket.h> 3093 #endif 3094 #ifdef HAVE_SOCKLIB_H 3095 #include <sockLib.h> 3096 #endif 3097 #if defined(_WIN32) && ! defined(__CYGWIN__) 3098 #include <winsock2.h> 3099 #endif 3100 #ifdef HAVE_SYS_SELECT_H 3101 #include <sys/select.h> 3102 #endif 3103 ]], [sizeof_mod_fd_set="unknown"] 3104 ) 3105 _AS_ECHO_LOG([the sizeof(fd_setsize) with redefined (${test_fd_setsize}) FD_SETSIZE value is ${sizeof_mod_fd_set}]) 3106 _AS_ECHO_LOG([detected sizes of 'fd_set': '${sizeof_cur_fd_set}' (by default), '${sizeof_mod_fd_set}' with modified FD_SETSIZE]) 3107 AS_IF([test "x${sizeof_cur_fd_set}" != "x${sizeof_mod_fd_set}"], 3108 [mhd_cv_fd_setsize_overridable="yes"], 3109 [mhd_cv_fd_setsize_overridable="no"] 3110 ) 3111 AS_UNSET([sizeof_mod_fd_set]) 3112 AS_UNSET([sizeof_cur_fd_set]) 3113 ], 3114 [mhd_cv_fd_setsize_overridable="no"] 3115 ) 3116 ] 3117 ) 3118 AS_UNSET([test_type_fd_setsize]) 3119 AS_UNSET([test_fd_setsize]) 3120 AS_UNSET([base_min_fd_setsize]) 3121 AS_UNSET([base_fd_setsize]) 3122 ] 3123 ) 3124 3125 AS_VAR_IF([mhd_cv_fd_setsize_overridable],["no"], 3126 [ 3127 AS_VAR_IF([os_is_native_w32],["yes"], 3128 [AC_MSG_ERROR([Non-overridable FD_SETSIZE detected for native W32 build. FD_SETSIZE is overridable on W32.])] 3129 ) 3130 AS_IF([test "x${mhd_cv_fd_setsize_value}" != "xunknown" && test "x${mhd_cv_sys_fd_setsize_value}" != "xunknown" && test "${mhd_cv_fd_setsize_value}" -ne "${mhd_cv_sys_fd_setsize_value}"], 3131 [AC_MSG_WARN([Detected non-overridable FD_SETSIZE, but the toolchain uses FD_SETSIZE (${mhd_cv_fd_setsize_value}) different from system default (${mhd_cv_sys_fd_setsize_value})])] 3132 ) 3133 ], 3134 [AC_DEFINE([HAS_FD_SETSIZE_OVERRIDABLE],[1],[Define to 1 i][f your system allow overriding the value of FD_SETSIZE macro])] 3135 ) 3136 3137 AC_CACHE_CHECK([whether socket value is a signed type],[mhd_cv_socket_signed], 3138 [ 3139 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 3140 #ifdef HAVE_SYS_TIME_H 3141 #include <sys/time.h> 3142 #endif 3143 #ifdef HAVE_SYS_TYPES_H 3144 #include <sys/types.h> 3145 #endif 3146 #ifdef HAVE_UNISTD_H 3147 #include <unistd.h> 3148 #endif 3149 #ifdef HAVE_SYS_SOCKET_H 3150 #include <sys/socket.h> 3151 #endif 3152 #ifdef HAVE_SOCKLIB_H 3153 #include <sockLib.h> 3154 #endif 3155 #if defined(_WIN32) && ! defined(__CYGWIN__) 3156 #include <winsock2.h> 3157 #endif 3158 #ifdef HAVE_SYS_SELECT_H 3159 #include <sys/select.h> 3160 #endif 3161 3162 /* Keep in sync with microhttpd.h */ 3163 #if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET) 3164 typedef int MHD_Socket; 3165 #else /* defined(_WIN32) && ! defined(_SYS_TYPES_FD_SET) */ 3166 typedef SOCKET MHD_Socket; 3167 #endif /* defined(_WIN32) && ! defined(_SYS_TYPES_FD_SET) */ 3168 3169 int main(void) 3170 { 3171 int test_arr[2 - 5*(!!(0 < ((MHD_Socket)-1)))]; 3172 test_arr[1] = 0; 3173 return test_arr[1]; 3174 } 3175 ]] 3176 ) 3177 ], 3178 [mhd_cv_socket_signed="yes"], 3179 [mhd_cv_socket_signed="no"] 3180 ) 3181 ] 3182 ) 3183 AS_VAR_IF([mhd_cv_socket_signed],["yes"], 3184 [AC_DEFINE([HAS_SIGNED_SOCKET],[1],[Define to 1 i][f your socket type is signed])] 3185 ) 3186 3187 MHD_CHECK_FUNC([writev], 3188 [[#include <sys/uio.h>]], 3189 [[ 3190 struct iovec iov[2]; 3191 char some_str[4] = "OK\n"; 3192 iov[0].iov_base = (void *) some_str; 3193 iov[0].iov_len = 3; 3194 i][f (0 > writev(1, iov, 1)) 3195 return 2; 3196 ]] 3197 ) 3198 MHD_FIND_LIB([sendmsg], 3199 [[ 3200 #ifdef HAVE_SYS_TYPES_H 3201 #include <sys/types.h> 3202 #endif 3203 #ifdef HAVE_SYS_SOCKET_H 3204 #include <sys/socket.h> 3205 #elif defined(HAVE_UNISTD_H) 3206 #include <unistd.h> 3207 #endif 3208 #ifdef HAVE_SOCKLIB_H 3209 #include <sockLib.h> 3210 #endif 3211 #ifdef HAVE_SYS_UIO_H 3212 #include <sys/uio.h> 3213 #endif 3214 ]], 3215 [[ 3216 struct msghdr msg; 3217 struct iovec iov; 3218 unsigned int i; 3219 char some_str[5] = "test"; 3220 3221 iov.iov_base = (void*)some_str; 3222 iov.iov_len = 4; 3223 3224 for (i = 0; i < (unsigned int) sizeof(msg); i++) 3225 { 3226 *(((unsigned char *)&msg) + i) = 0; 3227 } 3228 msg.msg_iov = &iov; 3229 msg.msg_iovlen = 1; 3230 3231 i][f (0 > sendmsg(1, &msg, 0)) 3232 return -1; 3233 ]], 3234 [socket], 3235 [ 3236 AC_DEFINE([HAVE_SENDMSG],[1],[Define to '1' if your have sendmsg() function]) 3237 AS_VAR_IF([[mhd_cv_find_lib_sendmsg]],[["none required"]], [], 3238 [ 3239 MHD_LIBDEPS_PKGCFG="${mhd_cv_find_lib_sendmsg} $MHD_LIBDEPS_PKGCFG" 3240 ] 3241 ) 3242 ],[], 3243 [MHD_LIBDEPS] 3244 ) 3245 3246 AC_C_BIGENDIAN 3247 AC_C_VARARRAYS 3248 3249 AC_CACHE_CHECK([[whether __func__ magic-macro is available]], 3250 [[mhd_cv_macro___func___avail]], [dnl 3251 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[const char *funcname = __func__ ; if (!funcname) return 1;]])], 3252 [[mhd_cv_macro___func___avail="yes"]],[[mhd_cv_macro___func___avail="no"]]) 3253 ]) 3254 AS_VAR_IF([mhd_cv_macro___func___avail], ["yes"], 3255 [AC_DEFINE([HAVE___FUNC__], [1], [Define to 1 if your compiler supports __func__ magic-macro.])], 3256 [ 3257 AC_CACHE_CHECK([[whether __FUNCTION__ magic-macro is available]], 3258 [[mhd_cv_macro___function___avail]], [dnl 3259 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[const char *funcname = __FUNCTION__ ; if (!funcname) return 1;]])], 3260 [[mhd_cv_macro___function___avail="yes"]],[[mhd_cv_macro___function___avail="no"]]) 3261 ]) 3262 AS_VAR_IF([mhd_cv_macro___function___avail], ["yes"], 3263 [AC_DEFINE([HAVE___FUNCTION__], [1], [Define to 1 if your compiler supports __FUNCTION__ magic-macro.])], 3264 [ 3265 AC_CACHE_CHECK([[whether __PRETTY_FUNCTION__ magic-macro is available]], 3266 [[mhd_cv_macro___pretty_function___avail]], [dnl 3267 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[const char *funcname = __PRETTY_FUNCTION__ ; if (!funcname) return 1;]])], 3268 [[mhd_cv_macro___pretty_function___avail="yes"]],[[mhd_cv_macro___pretty_function___avail="no"]]) 3269 ]) 3270 AS_VAR_IF([mhd_cv_macro___pretty_function___avail], ["yes"], 3271 [AC_DEFINE([HAVE___PRETTY_FUNCTION__], [1], [Define to 1 if your compiler supports __PRETTY_FUNCTION__ magic-macro.])], 3272 ) 3273 ] 3274 ) 3275 ] 3276 ) 3277 AC_CACHE_CHECK([[whether __builtin_bswap16() is available]], 3278 [[mhd_cv_func___builtin_bswap16_avail]], [dnl 3279 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include<stdint.h>]], [[uint_least16_t a = 1; uint_least16_t b = __builtin_bswap16(a); a = b; (void) a;]])], 3280 [[mhd_cv_func___builtin_bswap16_avail="yes"]],[[mhd_cv_func___builtin_bswap16_avail="no"]]) 3281 ]) 3282 AS_IF([[test "x$mhd_cv_func___builtin_bswap16_avail" = "xyes"]], 3283 [AC_DEFINE([[MHD_HAVE___BUILTIN_BSWAP16]], [[1]], [Define to 1 if you have __builtin_bswap16() builtin function])]) 3284 3285 AC_CACHE_CHECK([[whether __builtin_bswap32() is available]], 3286 [[mhd_cv_func___builtin_bswap32_avail]], [dnl 3287 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include<stdint.h>]], [[uint_least32_t a = 1; uint_least32_t b = __builtin_bswap32(a); a = b; (void) a;]])], 3288 [[mhd_cv_func___builtin_bswap32_avail="yes"]],[[mhd_cv_func___builtin_bswap32_avail="no"]]) 3289 ]) 3290 AS_IF([[test "x$mhd_cv_func___builtin_bswap32_avail" = "xyes"]], 3291 [AC_DEFINE([[MHD_HAVE___BUILTIN_BSWAP32]], [[1]], [Define to 1 if you have __builtin_bswap32() builtin function])]) 3292 AC_CACHE_CHECK([[whether __builtin_bswap64() is available]], 3293 [[mhd_cv_func___builtin_bswap64_avail]], [dnl 3294 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include<stdint.h>]], [[uint_least64_t a = 1; uint_least64_t b = __builtin_bswap64(a); a = b; (void) a;]])], 3295 [[mhd_cv_func___builtin_bswap64_avail="yes"]], [[mhd_cv_func___builtin_bswap64_avail="no"]]) 3296 ]) 3297 AS_IF([[test "x$mhd_cv_func___builtin_bswap64_avail" = "xyes"]], 3298 [AC_DEFINE([[MHD_HAVE___BUILTIN_BSWAP64]], [[1]], [Define to 1 if you have __builtin_bswap64() builtin function])]) 3299 3300 AC_CACHE_CHECK([[whether __builtin_clz() is available]], 3301 [[mhd_cv_func___builtin_clz_avail]], [dnl 3302 AC_LINK_IFELSE([AC_LANG_SOURCE([[ 3303 int main(void) 3304 { 3305 unsigned int val = 2u; 3306 return __builtin_clz(val) > 8 ? 0 : 1; 3307 } 3308 ]] 3309 ) 3310 ], 3311 [[mhd_cv_func___builtin_clz_avail="yes"]], 3312 [[mhd_cv_func___builtin_clz_avail="no"]] 3313 ) 3314 ] 3315 ) 3316 AS_VAR_IF([mhd_cv_func___builtin_clz_avail],["yes"], 3317 [AC_DEFINE([[MHD_HAVE___BUILTIN_CLZ]], [[1]], [Define to 1 if __builtin_clz() builtin function is supported by compiler])] 3318 ) 3319 AC_CACHE_CHECK([[whether __builtin_clzl() is available]], 3320 [[mhd_cv_func___builtin_clzl_avail]], [dnl 3321 AC_LINK_IFELSE([AC_LANG_SOURCE([[ 3322 int main(void) 3323 { 3324 unsigned long val = 2u; 3325 return __builtin_clzl(val) > 8 ? 0 : 1; 3326 } 3327 ]] 3328 ) 3329 ], 3330 [[mhd_cv_func___builtin_clzl_avail="yes"]], 3331 [[mhd_cv_func___builtin_clzl_avail="no"]] 3332 ) 3333 ] 3334 ) 3335 AS_VAR_IF([mhd_cv_func___builtin_clzl_avail],["yes"], 3336 [AC_DEFINE([[MHD_HAVE___BUILTIN_CLZL]], [[1]], [Define to 1 if __builtin_clzl() builtin function is supported by compiler])] 3337 ) 3338 AC_CACHE_CHECK([[whether __builtin_clzll() is available]], 3339 [[mhd_cv_func___builtin_clzll_avail]], [dnl 3340 AC_LINK_IFELSE([AC_LANG_SOURCE([[ 3341 int main(void) 3342 { 3343 unsigned long long val = 2u; 3344 return __builtin_clzl(val) > 8 ? 0 : 1; 3345 } 3346 ]] 3347 ) 3348 ], 3349 [[mhd_cv_func___builtin_clzll_avail="yes"]], 3350 [[mhd_cv_func___builtin_clzll_avail="no"]] 3351 ) 3352 ] 3353 ) 3354 AS_VAR_IF([mhd_cv_func___builtin_clzll_avail],["yes"], 3355 [AC_DEFINE([[MHD_HAVE___BUILTIN_CLZLL]], [[1]], [Define to 1 if __builtin_clzll() builtin function is supported by compiler])] 3356 ) 3357 AC_CACHE_CHECK([[whether __builtin_clzg(v) is available]], 3358 [[mhd_cv_func___builtin_clzg1_avail]], [dnl 3359 AC_LINK_IFELSE([AC_LANG_SOURCE([[ 3360 int main(void) 3361 { 3362 unsigned int val = 2u; 3363 return __builtin_clzg(val) > 8 ? 0 : 1; 3364 } 3365 ]] 3366 ) 3367 ], 3368 [[mhd_cv_func___builtin_clzg1_avail="yes"]], 3369 [[mhd_cv_func___builtin_clzg1_avail="no"]] 3370 ) 3371 ] 3372 ) 3373 AS_VAR_IF([mhd_cv_func___builtin_clzg1_avail],["yes"], 3374 [AC_DEFINE([[MHD_HAVE___BUILTIN_CLZG1]], [[1]], [Define to 1 if __builtin_clzg(v) builtin function is supported by compiler])] 3375 ) 3376 AC_CACHE_CHECK([[whether __builtin_clzg(v,z) is available]], 3377 [[mhd_cv_func___builtin_clzg2_avail]], [dnl 3378 AC_LINK_IFELSE([AC_LANG_SOURCE([[ 3379 int main(void) 3380 { 3381 unsigned int val = 0u; 3382 return __builtin_clzg(val, 0); 3383 } 3384 ]] 3385 ) 3386 ], 3387 [[mhd_cv_func___builtin_clzg2_avail="yes"]], 3388 [[mhd_cv_func___builtin_clzg2_avail="no"]] 3389 ) 3390 ] 3391 ) 3392 AS_VAR_IF([mhd_cv_func___builtin_clzg2_avail],["yes"], 3393 [AC_DEFINE([[MHD_HAVE___BUILTIN_CLZG2]], [[1]], [Define to 1 if __builtin_clzg(v,z) builtin function is supported by compiler])] 3394 ) 3395 3396 AC_CACHE_CHECK([whether $CC supports __builtin_expect_with_probability()],[mhd_cv_cc___builtin_expect_with_probability_avail], 3397 [ 3398 AC_LINK_IFELSE( 3399 [ 3400 AC_LANG_SOURCE( 3401 [[ 3402 int main(int argc, char *argv[]) 3403 { 3404 (void) argv; 3405 if (__builtin_expect_with_probability(argc < 1, 0, 0.9999)) return 1; 3406 return 0; 3407 } 3408 ]] 3409 ) 3410 ], 3411 [[mhd_cv_cc___builtin_expect_with_probability_avail="yes"]], 3412 [[mhd_cv_cc___builtin_expect_with_probability_avail="no"]] 3413 ) 3414 ] 3415 ) 3416 AS_VAR_IF([mhd_cv_cc___builtin_expect_with_probability_avail],["yes"], 3417 [AC_DEFINE([[MHD_HAVE___BUILTIN_EXPECT_WITH_PROBABILITY]], [[1]], [Define to 1 if compiler supports __builtin_expect_with_probability() builtin function])], 3418 [ 3419 AC_CACHE_CHECK([whether $CC supports __builtin_expect()],[mhd_cv_cc___builtin_expect_avail], 3420 [ 3421 AC_LINK_IFELSE( 3422 [ 3423 AC_LANG_SOURCE( 3424 [[ 3425 int main(int argc, char *argv[]) 3426 { 3427 (void) argv; 3428 if (__builtin_expect(argc < 1, 0)) return 1; 3429 return 0; 3430 } 3431 ]] 3432 ) 3433 ], 3434 [[mhd_cv_cc___builtin_expect_avail="yes"]], 3435 [[mhd_cv_cc___builtin_expect_avail="no"]] 3436 ) 3437 ] 3438 ) 3439 AS_VAR_IF([mhd_cv_cc___builtin_expect_avail],["yes"], 3440 [AC_DEFINE([[MHD_HAVE___BUILTIN_EXPECT]], [[1]], [Define to 1 if compiler supports __builtin_expect() builtin function])] 3441 ) 3442 ] 3443 ) 3444 3445 AC_CHECK_PROG([HAVE_CURL_BINARY],[curl],[yes],[no]) 3446 AM_CONDITIONAL([HAVE_CURL_BINARY],[test "x$HAVE_CURL_BINARY" = "xyes"]) 3447 AC_CHECK_PROG([HAVE_MAKEINFO_BINARY],[makeinfo],[yes],[no]) 3448 AM_CONDITIONAL([HAVE_MAKEINFO_BINARY],[test "x$HAVE_MAKEINFO_BINARY" = "xyes"]) 3449 AM_CONDITIONAL(W32_STATIC_LIB, [test "x$os_is_native_w32" = "xyes" && test "x$enable_static" = "xyes"]) 3450 3451 3452 AC_ARG_ENABLE([[doc]], 3453 [AS_HELP_STRING([[--disable-doc]], [do not build any documentation])], , 3454 [enable_doc=yes]) 3455 test "x$enable_doc" = "xno" || enable_doc=yes 3456 AM_CONDITIONAL([BUILD_DOC], [test "x$enable_doc" = "xyes"]) 3457 3458 AC_ARG_ENABLE([[examples]], 3459 [AS_HELP_STRING([[--disable-examples]], [do not build any examples])], , 3460 [enable_examples=yes]) 3461 test "x$enable_examples" = "xno" || enable_examples=yes 3462 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" = "xyes"]) 3463 3464 AC_ARG_ENABLE([[tools]], 3465 [AS_HELP_STRING([[--disable-tools]], [do not build testing and demo tools])], , 3466 [enable_tools=yes]) 3467 test "x$enable_tools" = "xyes" || enable_tools=no 3468 AM_CONDITIONAL([BUILD_TOOLS], [test "x$enable_tools" = "xyes"]) 3469 3470 AC_ARG_ENABLE([[heavy-tests]], 3471 [AS_HELP_STRING([[--enable-heavy-tests[=SCOPE]]], [use SCOPE of heavy tests in test-suite. WARNING:] 3472 [a dedicated host with minimal number of background processes and no network] 3473 [activity is recommended to enable. (basic, full)])], [], 3474 [enable_heavy_tests=no]) 3475 use_heavy_tests="no" 3476 use_vheavy_tests="no" 3477 use_heavy_tests_MSG="no" 3478 AS_CASE([${enable_heavy_tests}], 3479 [yes|basic], 3480 [ 3481 enable_heavy_tests="basic" 3482 use_heavy_tests="yes" 3483 use_vheavy_tests="no" 3484 use_heavy_tests_MSG="yes, basic heavy tests (a dedicated host is recommended)" 3485 ], 3486 [all|full], 3487 [ 3488 enable_heavy_tests="full" 3489 use_heavy_tests="yes" 3490 use_vheavy_tests="yes" 3491 use_heavy_tests_MSG="yes, full set of heavy tests (a dedicated host is recommended)" 3492 ], 3493 [no], 3494 [ 3495 use_heavy_tests="no" 3496 use_vheavy_tests="no" 3497 use_heavy_tests_MSG="no" 3498 ], 3499 [AC_MSG_ERROR([[Unknown parameter value: --enable-heavy-tests=${enable_heavy_tests}]])] 3500 ) 3501 AC_ARG_ENABLE([[slow-tests]], 3502 [ 3503 AS_HELP_STRING([[--enable-slow-tests]], 3504 [enable slow (time and/or CPU consuming) tests] 3505 ) 3506 ], 3507 [ 3508 AS_CASE([$enableval],[yes|no],[:], 3509 [AC_MSG_ERROR([Unrecognised parameter value: --enable-slow-tests=$enableval])] 3510 ) 3511 ],[enable_slow_tests="no"] 3512 ) 3513 AS_VAR_IF([use_heavy_tests], ["yes"], 3514 [ 3515 HEAVY_TESTS_NOTPARALLEL='.NOTPARALLEL:' 3516 AC_DEFINE([MHD_ENABLE_HEAVY_TESTS], [1], [Define to 1 to enable "heavy" test paths.]) 3517 AS_VAR_IF([use_vheavy_tests], ["yes"], 3518 [AC_DEFINE([MHD_ENABLE_VHEAVY_TESTS], [1], [Define to 1 to enable "very heavy" test paths.])] 3519 ) 3520 ], 3521 [ 3522 HEAVY_TESTS_NOTPARALLEL=" " 3523 ] 3524 ) 3525 AS_VAR_IF([enable_slow_tests], ["yes"], [AC_DEFINE([MHD_ENABLE_SLOW_TESTS], [1], [Define to 1 to enable long-running and CPU-intensive test paths.])]) 3526 AM_CONDITIONAL([SLOW_TESTS],[test "x$enable_slow_tests" = "xyes"]) 3527 AM_CONDITIONAL([HEAVY_TESTS],[test "x$use_heavy_tests" = "xyes"]) 3528 AM_CONDITIONAL([VHEAVY_TESTS],[test "x$use_vheavy_tests" = "xyes"]) 3529 AM_CONDITIONAL([TESTS_STRESS_OS],[false]) 3530 3531 AC_ARG_ENABLE([[select]], 3532 [AS_HELP_STRING([[--enable-select[=ARG]]], [enable 'select()' support (yes, no, auto) [auto]]) 3533 ],[],[enable_select='auto'] 3534 ) 3535 AC_CACHE_CHECK([for select() function],[mhd_cv_func_select], 3536 [ 3537 AS_IF([test "x$os_is_native_w32" = "xyes"], 3538 [mhd_cv_func_select="yes"], 3539 [ 3540 AC_LINK_IFELSE( 3541 [ 3542 AC_LANG_SOURCE([[ 3543 #ifdef HAVE_SYS_TYPES_H 3544 #include <sys/types.h> 3545 #endif 3546 #ifdef HAVE_SYS_TIME_H 3547 #include <sys/time.h> 3548 #endif 3549 #ifdef HAVE_UNISTD_H 3550 #include <unistd.h> 3551 #endif 3552 #ifdef HAVE_SYS_SELECT_H 3553 #include <sys/select.h> 3554 #endif 3555 #ifdef HAVE_SELECTLIB_H 3556 #include <selectLib.h> 3557 #endif 3558 3559 int main(void) 3560 { 3561 int res; 3562 fd_set rfds; 3563 fd_set wfds; 3564 fd_set efds; 3565 struct timeval tv_to; 3566 3567 tv_to.tv_sec = 1; 3568 tv_to.tv_usec = 0; 3569 FD_ZERO(&rfds); 3570 FD_ZERO(&wfds); 3571 FD_ZERO(&efds); 3572 FD_SET(1, &wfds); 3573 3574 res = select(2, &rfds, &wfds, &efds, &tv_to); 3575 if (res < 0) 3576 return 3; 3577 3578 FD_CLR(1, &efds); 3579 if (FD_ISSET(1, &efds)) 3580 return 4; 3581 3582 return 0; 3583 } 3584 ]] 3585 ) 3586 ], 3587 [mhd_cv_func_select="yes"], 3588 [mhd_cv_func_select="no"] 3589 ) 3590 ] 3591 ) 3592 ] 3593 ) 3594 AS_VAR_IF([mhd_cv_func_select],["yes"], 3595 [ 3596 AC_DEFINE([[HAVE_SELECT]],[[1]],[Define to '1' if select() is supported on your platform]) 3597 AS_IF([test "x$enable_select" != "xno"], 3598 [ 3599 enable_select="yes" 3600 AC_DEFINE([[MHD_SUPPORT_SELECT]],[[1]],[Define to '1' to enable use of select() system call]) 3601 ] 3602 ) 3603 ], 3604 [ 3605 AS_VAR_IF([enable_select],["yes"], 3606 [AC_MSG_ERROR([Support for select() was explicitly requested but cannot be enabled on this platform.])] 3607 ) 3608 ] 3609 ) 3610 AM_CONDITIONAL([MHD_SUPPORT_SELECT],[test "x${enable_select}" = "xyes"]) 3611 3612 AC_ARG_ENABLE([[poll]], 3613 [AS_HELP_STRING([[--enable-poll[=ARG]]], [enable 'poll()' support (yes, no, auto) [auto]]) 3614 ],[],[enable_poll='auto'] 3615 ) 3616 AS_IF([test "$os_is_native_w32" != "yes"], 3617 [ 3618 AC_CHECK_HEADERS([poll.h], 3619 [ 3620 MHD_CHECK_FUNC([poll], 3621 [[ 3622 #include <poll.h> 3623 ]], 3624 [[ 3625 struct pollfd fds[2]; 3626 3627 fds[0].fd = 0; 3628 fds[0].events = POLLIN; 3629 if (0 > poll(fds, 1, 0)) 3630 return 2; 3631 ]], 3632 [have_poll='yes'],[have_poll='no'] 3633 ) 3634 ],[],[AC_INCLUDES_DEFAULT] 3635 ) 3636 ], 3637 [ 3638 MHD_CHECK_FUNC([WSAPoll], 3639 [[ 3640 #include <winsock2.h> 3641 ]], 3642 [[ 3643 WSAPOLLFD fda[2]; 3644 WSAPoll(fda, 2, 0); 3645 ]], 3646 [have_poll='yes'],[have_poll='no'] 3647 ) 3648 ] 3649 ) 3650 AS_VAR_IF([have_poll],["yes"], 3651 [ 3652 AC_DEFINE([[HAVE_POLL]],[[1]],[Define to '1' if poll() is supported on your platform]) 3653 MHD_CHECK_DECLS([POLLRDNORM POLLIN POLLRDBAND POLLWRNORM POLLOUT POLLWRBAND POLLPRI],[[ 3654 #ifdef HAVE_POLL_H 3655 #include <poll.h> 3656 #endif 3657 #ifdef HAVE_WINSOCK2_H 3658 #include <winsock2.h> 3659 #endif 3660 ]] 3661 ) 3662 AS_IF([test "x$enable_poll" != "xno"], 3663 [ 3664 enable_poll="yes" 3665 AC_DEFINE([[MHD_SUPPORT_POLL]],[[1]],[Define to '1' to enable use of select() system call]) 3666 ] 3667 ) 3668 ], 3669 [ 3670 AS_VAR_IF([enable_poll],["yes"], 3671 [AC_MSG_ERROR([Support for poll() was explicitly requested but cannot be enabled on this platform.])] 3672 ) 3673 ] 3674 ) 3675 AM_CONDITIONAL([MHD_SUPPORT_POLL],[test "x${enable_poll}" = "xyes"]) 3676 3677 AC_ARG_ENABLE([[epoll]], 3678 [AS_HELP_STRING([[--enable-epoll[=ARG]]], [enable epoll support (yes, no, auto) [auto]]) 3679 ],[],[enable_epoll='auto'] 3680 ) 3681 AS_IF([test "$enable_epoll" != "no"], 3682 [ 3683 MHD_CHECK_FUNC_RUN([epoll_create], 3684 [[ 3685 #include <sys/epoll.h> 3686 #include <unistd.h> 3687 ]], 3688 [[ 3689 int epfd = epoll_create(64); 3690 i][f (0 > epfd) return -epfd; 3691 (void) close(epfd); 3692 return 0; 3693 ]], 3694 [cacheVar="assuming yes"], 3695 [ 3696 AC_DEFINE([[HAVE_EPOLL]],[[1]],[Define to '1' if epoll is supported on your platform]) 3697 AC_DEFINE([[MHD_SUPPORT_EPOLL]],[[1]],[Define to '1' to enable 'epoll' functionality]) 3698 enable_epoll='yes' 3699 ], 3700 [ 3701 AS_IF([test "$enable_epoll" = "yes"], 3702 [AC_MSG_ERROR([[Support for epoll was explicitly requested but cannot be enabled on this platform.]])] 3703 ) 3704 enable_epoll='no' 3705 ] 3706 ) 3707 AS_UNSET([warn_msg]) 3708 AS_VAR_IF([mhd_cv_works_func_epoll_create],["assuming yes"], 3709 [[warn_msg="When cross-compiling it is not possible to check whether 'epoll_create()' really works on the host (final) platform. 3710 'epoll' is enabled as most probably the host kernel supports it (CONFIG_EPOLL option enabled in case of Linux kernel). 3711 Use './configure mhd_cv_works_func_epoll_create=yes' to mute this warning."]] 3712 ) 3713 AS_VAR_SET_IF([warn_msg],[AC_MSG_WARN([$warn_msg]) 3714 AS_IF([test -n "${CONF_FINAL_WARNS}" ], 3715 [ 3716 CONF_FINAL_WARNS="${CONF_FINAL_WARNS} 3717 3718 WARNING: " 3719 ] 3720 ) 3721 CONF_FINAL_WARNS="${CONF_FINAL_WARNS}${warn_msg}" 3722 ] 3723 ) 3724 ] 3725 ) 3726 AM_CONDITIONAL([MHD_SUPPORT_EPOLL], [[test "x${enable_epoll}" = "xyes"]]) 3727 3728 AS_IF([test "x$enable_epoll" = "xyes"], 3729 [ 3730 MHD_CHECK_FUNC([epoll_create1], 3731 [[ 3732 #include <sys/epoll.h> 3733 ]], 3734 [[ 3735 i][f (0 > epoll_create1(EPOLL_CLOEXEC)) 3736 return 3; 3737 ]] 3738 ) 3739 ] 3740 ) 3741 3742 AC_CACHE_CHECK([for supported 'noreturn' keyword], [mhd_cv_decl_noreturn], 3743 [ 3744 mhd_cv_decl_noreturn="none" 3745 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}" 3746 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 3747 for decl_noret in ['[[noreturn]]'] '_Noreturn' '__attribute__((__noreturn__))' '__declspec(noreturn)' 3748 do 3749 AC_LINK_IFELSE([AC_LANG_SOURCE( 3750 [[ 3751 #ifdef HAVE_STDLIB_H 3752 #include <stdlib.h> 3753 #endif 3754 3755 ${decl_noret} static void myexitfunc(int code) 3756 { 3757 #ifdef HAVE_STDLIB_H 3758 exit (code); 3759 #else 3760 (void)code; 3761 #endif 3762 } 3763 3764 int main (int argc, char *const *argv) 3765 { 3766 (void) argv; 3767 if (argc > 2) 3768 myexitfunc (2); 3769 return 0; 3770 } 3771 ]] 3772 )], [mhd_cv_decl_noreturn="${decl_noret}"] 3773 ) 3774 AS_IF([test "x${mhd_cv_decl_noreturn}" != "xnone"], [break]) 3775 done 3776 ac_c_werror_flag="" 3777 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 3778 ] 3779 ) 3780 AS_VAR_IF([mhd_cv_decl_noreturn], ["none"], 3781 [AC_DEFINE([MHD_NORETURN_], [[/* empty */]], [Define to the supported 'noreturn' function declaration])], 3782 [AC_DEFINE_UNQUOTED([MHD_NORETURN_], [${mhd_cv_decl_noreturn}], [Define to the supported 'noreturn' function declaration])] 3783 ) 3784 3785 # Check for types sizes 3786 # Types sizes are used as an indirect indication of maximum allowed values for types 3787 # which is used to exclude by preprocessor some compiler checks for values clips 3788 # Assuming no staffing or uniform staffing for integer types 3789 AC_CACHE_CHECK([size of tv_sec member of struct timeval], [mhd_cv_size_timeval_tv_sec], 3790 [ 3791 AC_COMPUTE_INT([mhd_cv_size_timeval_tv_sec], [((long int)sizeof(test_var.tv_sec))], 3792 [[ 3793 #ifdef HAVE_SYS_TIME_H 3794 #include <sys/time.h> 3795 #endif /* HAVE_SYS_TIME_H */ 3796 #ifdef HAVE_TIME_H 3797 #include <time.h> 3798 #endif /* HAVE_TIME_H */ 3799 #if HAVE_SYS_TYPES_H 3800 #include <sys/types.h> 3801 #endif /* HAVE_SYS_TYPES_H */ 3802 extern struct timeval test_var; /* Declaration */ 3803 struct timeval test_var = {0, 0}; /* Definition */ 3804 ]], 3805 [ 3806 # The size is used only to exclude additional checks/comparison in code 3807 # to avoid compiler warnings. With larger size MHD code will use 3808 # additional checks which ensure that value will fit but it may produce 3809 # a harmless compiler warning. 3810 AC_MSG_WARN([The size cannot be determined, assuming 8.]) 3811 mhd_cv_size_timeval_tv_sec=8 3812 ] 3813 ) 3814 ] 3815 ) 3816 AC_DEFINE_UNQUOTED([SIZEOF_STRUCT_TIMEVAL_TV_SEC], [$mhd_cv_size_timeval_tv_sec], 3817 [The size of `tv_sec' member of `struct timeval', as computed by sizeof]) 3818 AC_CHECK_SIZEOF([uint_least8_t], [], [[#include <stdint.h>]]) 3819 AC_CHECK_SIZEOF([uint_least16_t], [], [[#include <stdint.h>]]) 3820 AC_CHECK_SIZEOF([uint_least32_t], [], [[#include <stdint.h>]]) 3821 AC_CHECK_SIZEOF([uint_fast32_t], [], [[#include <stdint.h>]]) 3822 AC_CHECK_SIZEOF([uint_least64_t], [], [[#include <stdint.h>]]) 3823 AC_CHECK_SIZEOF([int_fast64_t], [], [[#include <stdint.h>]]) 3824 AC_CHECK_SIZEOF([uint_fast64_t], [], [[#include <stdint.h>]]) 3825 AC_CHECK_SIZEOF([int]) 3826 AC_CHECK_SIZEOF([unsigned int]) 3827 AC_CHECK_SIZEOF([unsigned long]) 3828 AC_CHECK_SIZEOF([unsigned long long]) 3829 AC_CHECK_SIZEOF([size_t], [], 3830 [[ 3831 #ifdef HAVE_STDLIB_H 3832 #include <stdlib.h> 3833 #endif /* HAVE_STDLIB_H */ 3834 #ifdef HAVE_STDDEF_H 3835 #include <stddef.h> 3836 #endif /* HAVE_STDDEF_H */ 3837 #include <stdio.h> 3838 ]] 3839 ) 3840 AC_CHECK_SIZEOF([void*]) 3841 3842 AC_CHECK_HEADERS([dlfcn.h],[have_tlsplugin=yes],[have_tlsplugin=no], [AC_INCLUDES_DEFAULT]) 3843 AM_CONDITIONAL([MHD_HAVE_TLS_PLUGIN], [[test "x$have_tlsplugin" = xyes]]) 3844 3845 AC_CHECK_HEADERS([zlib.h],[have_zlib=yes],[have_zlib=no], [AC_INCLUDES_DEFAULT]) 3846 AM_CONDITIONAL([HAVE_ZLIB], [[test "x$have_zlib" = xyes]]) 3847 3848 AC_CHECK_HEADERS([jansson.h],[have_json=yes],[have_json=no], [AC_INCLUDES_DEFAULT]) 3849 AM_CONDITIONAL([HAVE_JANSSON], [[test "x$have_json" = xyes]]) 3850 3851 # Check for generic functions 3852 MHD_CHECK_FUNC([random], 3853 [ 3854 AC_INCLUDES_DEFAULT 3855 [#include <stdlib.h> 3856 ]], 3857 [[long int r = random(); (void)r;]], 3858 [], 3859 [ 3860 MHD_CHECK_FUNC([rand], 3861 [ 3862 AC_INCLUDES_DEFAULT 3863 [#include <stdlib.h> 3864 ]], 3865 [[int r = rand(); (void)r;]], 3866 ) 3867 ] 3868 ) 3869 3870 AC_CHECK_MEMBERS([struct sockaddr.sa_len, struct sockaddr_storage.ss_len, 3871 struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], 3872 [], [], 3873 [ 3874 #ifdef HAVE_SYS_TYPES_H 3875 #include <sys/types.h> 3876 #endif 3877 #ifdef HAVE_SYS_SOCKET_H 3878 #include <sys/socket.h> 3879 #elif defined(HAVE_UNISTD_H) 3880 #include <unistd.h> 3881 #endif 3882 #ifdef HAVE_NETINET_IN_H 3883 #include <netinet/in.h> 3884 #endif 3885 #ifdef HAVE_WINSOCK2_H 3886 #include <winsock2.h> 3887 #endif 3888 #ifdef HAVE_WS2TCPIP_H 3889 #include <ws2tcpip.h> 3890 #endif 3891 ]) 3892 3893 MHD_CHECK_FUNC_RUN([getsockname], 3894 [[ 3895 #ifdef HAVE_SYS_TYPES_H 3896 #include <sys/types.h> 3897 #endif 3898 #include <string.h> 3899 #ifdef HAVE_SYS_SOCKET_H 3900 #include <sys/socket.h> 3901 #endif 3902 #ifdef HAVE_UNISTD_H 3903 #include <unistd.h> 3904 #endif 3905 #if defined(_WIN32) && !defined(__CYGWIN__) 3906 #ifdef HAVE_WINSOCK2_H 3907 #include <winsock2.h> 3908 #endif 3909 #ifdef HAVE_WS2TCPIP_H 3910 #include <ws2tcpip.h> 3911 #endif 3912 #endif 3913 #ifdef HAVE_NETINET_IN_H 3914 #include <netinet/in.h> 3915 #endif 3916 #ifdef HAVE_NETINET_IP_H 3917 #include <netinet/ip.h> 3918 #endif 3919 #ifdef HAVE_ARPA_INET_H 3920 #include <arpa/inet.h> 3921 #endif 3922 3923 ]], 3924 [[ 3925 const socklen_t c_addr_size = (socklen_t)sizeof(struct sockaddr_in); 3926 struct sockaddr_in sa; 3927 socklen_t addr_size; 3928 int ret = 1; 3929 #if !defined(_WIN32) || defined(__CYGWIN__) 3930 int sckt; 3931 const int invld_sckt = -1; 3932 #else 3933 SOCKET sckt; 3934 const SOCKET invld_sckt = INVALID_SOCKET; 3935 WSADATA wsa_data; 3936 3937 i][f (0 != WSAStartup(MAKEWORD(2, 2), &wsa_data) || MAKEWORD(2, 2) != wsa_data.wVersion) 3938 return 20; 3939 #endif 3940 3941 sckt = socket (AF_INET, SOCK_STREAM, 0); 3942 i][f (invld_sckt != sckt) 3943 { 3944 memset(&sa, 0, c_addr_size); 3945 sa.sin_family = AF_INET; 3946 i][f (0 != INADDR_ANY) 3947 sa.sin_addr.s_addr = htonl (INADDR_ANY); 3948 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN 3949 sa.sin_len = c_addr_size; 3950 #endif 3951 i][f (0 == bind (sckt, (struct sockaddr *)&sa, c_addr_size)) 3952 { 3953 i][f (0 == listen (sckt, 1)) 3954 { 3955 addr_size = c_addr_size; 3956 i][f (0 == getsockname (sckt, (struct sockaddr *)&sa, &addr_size)) 3957 { 3958 i][f (c_addr_size >= addr_size) 3959 { 3960 i][f (0 != ntohs(sa.sin_port)) 3961 { ret = 0; 3962 } el][se ret = 7; 3963 } el][se ret = 6; 3964 } el][se ret = 5; 3965 } el][se ret = 4; 3966 } el][se ret = 3; 3967 } el][se ret = 2; 3968 #if !defined(_WIN32) || defined(__CYGWIN__) 3969 close (sckt); 3970 #else 3971 closesocket (sckt); 3972 WSACleanup(); 3973 #endif 3974 return ret; 3975 ]], 3976 [cacheVar='assuming yes'], 3977 [AC_DEFINE([[MHD_USE_GETSOCKNAME]], [[1]], [Define if you have usable `getsockname' function.])] 3978 ) 3979 3980 AS_VAR_IF([[os_is_native_w32]], [["yes"]],[], 3981 [ 3982 MHD_CHECK_FUNC([socketpair], 3983 [[ 3984 #ifdef HAVE_SYS_TYPES_H 3985 #include <sys/types.h> 3986 #endif 3987 #ifdef HAVE_SYS_SOCKET_H 3988 #include <sys/socket.h> 3989 #endif 3990 #if defined(HAVE_UNISTD_H) 3991 #include <unistd.h> 3992 #endif 3993 #ifdef HAVE_SYS_UN_H 3994 #include <sys/un.h> 3995 #endif 3996 ]], 3997 [[ 3998 int arr[2]; 3999 i][f (0 != socketpair(0, SOCK_STREAM, 0, arr)) return 2; 4000 close (arr[1]); 4001 close (arr[0]); 4002 ]], 4003 [], 4004 [AS_UNSET([mhd_cv_socketpair_usable])] 4005 ) 4006 ] 4007 ) 4008 4009 MHD_CHECK_DECLS([AF_UNIX AF_LOCAL SOMAXCONN IPV6_V6ONLY TCP_NODELAY TCP_FASTOPEN \ 4010 SOCK_NONBLOCK SOCK_CLOEXEC SOCK_NOSIGPIPE MSG_NOSIGNAL MSG_MORE \ 4011 SOL_SOCKET SO_REUSEADDR SO_REUSEPORT SO_LINGER SO_NOSIGPIPE \ 4012 SHUT_WR SD_SEND], 4013 [[ 4014 #ifdef HAVE_SYS_TYPES_H 4015 #include <sys/types.h> 4016 #endif 4017 #ifdef HAVE_SYS_SOCKET_H 4018 #include <sys/socket.h> 4019 #endif 4020 #if defined(HAVE_UNISTD_H) 4021 #include <unistd.h> 4022 #endif 4023 #ifdef HAVE_SOCKLIB_H 4024 #include <sockLib.h> 4025 #endif 4026 #ifdef HAVE_SYS_UN_H 4027 #include <sys/un.h> 4028 #endif 4029 #ifdef HAVE_WINSOCK2_H 4030 #include <winsock2.h> 4031 #endif 4032 #ifdef HAVE_INETLIB_H 4033 #include <inetLib.h> 4034 #endif 4035 #ifdef HAVE_NETINET_IN_H 4036 #include <netinet/in.h> 4037 #endif 4038 #ifdef HAVE_ARPA_INET_H 4039 #include <arpa/inet.h> 4040 #endif 4041 #if !defined(HAVE_NETINET_IN_H) && !defined(HAVE_ARPA_INET_H) && defined(HAVE_NETDB_H) 4042 #include <netdb.h> 4043 #endif 4044 #ifdef HAVE_NETINET_TCP_H 4045 #include <netinet/tcp.h> 4046 #endif 4047 #ifdef HAVE_AFUNIX_H 4048 #include <afunix.h> 4049 #endif 4050 #ifdef HAVE_WS2TCPIP_H 4051 #include <ws2tcpip.h> 4052 #endif 4053 ]] 4054 ) 4055 4056 AC_CACHE_CHECK([for usable PAGESIZE macro], [mhd_cv_macro_pagesize_usable], 4057 [ 4058 AC_LINK_IFELSE( 4059 [ 4060 AC_LANG_PROGRAM( 4061 [[ 4062 #ifdef HAVE_UNISTD_H 4063 #include <unistd.h> 4064 #endif 4065 #ifdef HAVE_LIMITS_H 4066 #include <limits.h> 4067 #endif 4068 #ifdef HAVE_SYS_PARAM_H 4069 #include <sys/param.h> 4070 #endif 4071 #ifndef PAGESIZE 4072 #error No PAGESIZE macro defined 4073 choke me now 4074 #endif 4075 ]], 4076 [[ 4077 long pgsz = PAGESIZE + 0; 4078 if (1 > pgsz) return 1; 4079 ]] 4080 ) 4081 ], 4082 [[mhd_cv_macro_pagesize_usable="yes"]], [[mhd_cv_macro_pagesize_usable="no"]] 4083 ) 4084 ] 4085 ) 4086 AS_VAR_IF([[mhd_cv_macro_pagesize_usable]], [["yes"]], 4087 [ 4088 AC_DEFINE([[MHD_USE_PAGESIZE_MACRO]],[[1]],[Define if you have usable PAGESIZE macro]) 4089 AC_CACHE_CHECK([whether PAGESIZE macro could be used for static init], [mhd_cv_macro_pagesize_usable_static], 4090 [ 4091 AC_LINK_IFELSE( 4092 [ 4093 AC_LANG_PROGRAM( 4094 [[ 4095 #ifdef HAVE_UNISTD_H 4096 #include <unistd.h> 4097 #endif 4098 #ifdef HAVE_LIMITS_H 4099 #include <limits.h> 4100 #endif 4101 #ifdef HAVE_SYS_PARAM_H 4102 #include <sys/param.h> 4103 #endif 4104 #ifndef PAGESIZE 4105 #error No PAGESIZE macro defined 4106 choke me now 4107 #endif 4108 static long ac_pgsz = PAGESIZE + 0; 4109 ]], 4110 [[ 4111 if (1 > ac_pgsz) return 1; 4112 ]] 4113 ) 4114 ], 4115 [[mhd_cv_macro_pagesize_usable_static="yes"]], [[mhd_cv_macro_pagesize_usable_static="no"]] 4116 ) 4117 ] 4118 ) 4119 AS_VAR_IF([[mhd_cv_macro_pagesize_usable_static]], [["yes"]], 4120 [AC_DEFINE([[MHD_USE_PAGESIZE_MACRO_STATIC]],[[1]],[Define if you have PAGESIZE macro usable for static init])] 4121 ) 4122 ], 4123 [ 4124 AC_CACHE_CHECK([for usable PAGE_SIZE macro], [mhd_cv_macro_page_size_usable], 4125 [ 4126 AC_LINK_IFELSE( 4127 [ 4128 AC_LANG_PROGRAM( 4129 [[ 4130 #ifdef HAVE_UNISTD_H 4131 #include <unistd.h> 4132 #endif 4133 #ifdef HAVE_LIMITS_H 4134 #include <limits.h> 4135 #endif 4136 #ifdef HAVE_SYS_PARAM_H 4137 #include <sys/param.h> 4138 #endif 4139 #ifndef PAGE_SIZE 4140 #error No PAGE_SIZE macro defined 4141 choke me now 4142 #endif 4143 ]], 4144 [[ 4145 long pgsz = PAGE_SIZE + 0; 4146 if (1 > pgsz) return 1; 4147 ]] 4148 ) 4149 ], 4150 [[mhd_cv_macro_page_size_usable="yes"]], [[mhd_cv_macro_page_size_usable="no"]] 4151 ) 4152 ] 4153 ) 4154 AS_VAR_IF([[mhd_cv_macro_page_size_usable]], [["yes"]], 4155 [ 4156 AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO]],[[1]],[Define if you have usable PAGE_SIZE macro]) 4157 AC_CACHE_CHECK([whether PAGE_SIZE macro could be used for static init], [mhd_cv_macro_page_size_usable_static], 4158 [ 4159 AC_LINK_IFELSE( 4160 [ 4161 AC_LANG_PROGRAM( 4162 [[ 4163 #ifdef HAVE_UNISTD_H 4164 #include <unistd.h> 4165 #endif 4166 #ifdef HAVE_LIMITS_H 4167 #include <limits.h> 4168 #endif 4169 #ifdef HAVE_SYS_PARAM_H 4170 #include <sys/param.h> 4171 #endif 4172 #ifndef PAGE_SIZE 4173 #error No PAGE_SIZE macro defined 4174 choke me now 4175 #endif 4176 static long ac_pgsz = PAGE_SIZE + 0; 4177 ]], 4178 [[ 4179 if (1 > ac_pgsz) return 1; 4180 ]] 4181 ) 4182 ], 4183 [[mhd_cv_macro_page_size_usable_static="yes"]], [[mhd_cv_macro_page_size_usable_static="no"]] 4184 ) 4185 ] 4186 ) 4187 AS_VAR_IF([[mhd_cv_macro_page_size_usable_static]], [["yes"]], 4188 [AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO_STATIC]],[[1]],[Define if you have PAGE_SIZE macro usable for static init])] 4189 ) 4190 ] 4191 ) 4192 ] 4193 ) 4194 4195 # Check for inter-thread signaling type 4196 AC_ARG_ENABLE([[itc]], 4197 [AS_HELP_STRING([[--enable-itc=TYPE]], [use TYPE of inter-thread communication (pipe, socketpair, eventfd) [auto]])], [], 4198 [[enable_itc='auto']] 4199 ) 4200 4201 AS_CASE([[$enable_itc]], 4202 [[pipe]], [[:]], 4203 [[socketpair]], [[:]], 4204 [[eventfd]], [[:]], 4205 [[auto]], [AS_VAR_IF([[os_is_windows]], [["yes"]], [[enable_itc='socketpair']])], 4206 [[eventFD]], [[enable_itc='eventfd']], 4207 [[socket]], [[enable_itc='socketpair']], 4208 [[no]], [AC_MSG_ERROR([[inter-thread communication cannot be disabled]])], 4209 [AC_MSG_ERROR([[unrecognized type "$enable_itc" of inter-thread communication specified by "--enable-itc=$enable_itc"]])] 4210 ) 4211 AS_UNSET([[use_itc]]) 4212 4213 AS_IF([[test "x$enable_itc" = "xeventfd" || test "x$enable_itc" = "xauto"]], 4214 [ 4215 MHD_CHECK_FUNC_RUN([eventfd],[[ 4216 #include <sys/eventfd.h> 4217 #include <unistd.h> 4218 ]], 4219 [[ 4220 static unsigned char buf[8]; 4221 int ret; 4222 int efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); 4223 if (0 > efd) 4224 return 2; 4225 ret = 0; 4226 buf[3] = 1; 4227 if (8 != write(efd, buf, 8)) 4228 ret = 3; 4229 else 4230 { 4231 if (8 != read(efd, buf, 8)) 4232 ret = 4; 4233 } 4234 close(efd); 4235 return ret; 4236 ]], 4237 [ 4238 AS_VAR_IF([enable_itc],["eventfd"], 4239 [cacheVar="assuming yes"],[cacheVar="assuming no"] 4240 ) 4241 ], 4242 [ 4243 use_itc='eventfd' 4244 enable_itc="$use_itc" 4245 AC_DEFINE([[MHD_ITC_EVENTFD_]], [[1]], [Define to use eventFD for inter-thread communication]) 4246 ], 4247 [ 4248 AS_VAR_IF([[enable_itc]], [["eventfd"]], [AC_MSG_ERROR([[eventfd(2) is not usable, consider using other type of inter-thread communication]])]) 4249 ] 4250 ) 4251 AS_UNSET([warn_msg]) 4252 AS_VAR_IF([mhd_cv_works_func_eventfd],["assuming yes"], 4253 [[warn_msg="When cross-compiling it is not possible to check whether 'eventfd()' really works on the host (final) platform. 4254 'eventfd' is enabled as requested by configure parameters. 4255 Use './configure mhd_cv_works_func_eventfd=yes' to mute this warning."]] 4256 ) 4257 AS_VAR_IF([mhd_cv_works_func_eventfd],["assuming no"], 4258 [[warn_msg="When cross-compiling it is not possible to check whether 'eventfd()' really works on the host (final) platform. 4259 'eventfd()' is disabled. If it is available use './configure mhd_cv_works_func_eventfd=yes' to enable. 4260 Use './configure mhd_cv_works_func_eventfd=no' to mute this warning."]] 4261 ) 4262 AS_VAR_SET_IF([warn_msg],[AC_MSG_WARN([$warn_msg]) 4263 AS_IF([test -n "${CONF_FINAL_WARNS}" ], 4264 [ 4265 CONF_FINAL_WARNS="${CONF_FINAL_WARNS} 4266 4267 WARNING: " 4268 ] 4269 ) 4270 CONF_FINAL_WARNS="${CONF_FINAL_WARNS}${warn_msg}" 4271 ] 4272 ) 4273 ] 4274 ) 4275 4276 AS_IF([[test "x$enable_itc" = "xpipe" || test "x$enable_itc" = "xauto"]], [ 4277 AS_VAR_IF([[os_is_native_w32]], [["yes"]], [], [ 4278 AC_CACHE_CHECK([[whether pipe(3) is usable]], [[mhd_cv_pipe_usable]], [ 4279 AC_LINK_IFELSE([ 4280 AC_LANG_PROGRAM([ 4281 AC_INCLUDES_DEFAULT 4282 #ifdef HAVE_UNISTD_H 4283 #include <unistd.h> 4284 #endif 4285 ], [[ 4286 int arr[2]; 4287 int res; 4288 res = pipe(arr); 4289 if (res != 0) return 33; 4290 close (arr[0]); 4291 close (arr[1]); 4292 ]]) 4293 ], [[mhd_cv_pipe_usable='yes']], [[mhd_cv_pipe_usable='no']]) 4294 ]) 4295 AS_VAR_IF([[mhd_cv_pipe_usable]], [["yes"]], [ 4296 use_itc='pipe' 4297 enable_itc="$use_itc" 4298 AC_DEFINE([[MHD_ITC_PIPE_]], [[1]], [Define to use pipe for inter-thread communication]) 4299 MHD_CHECK_FUNC_RUN([pipe2],[ 4300 AC_INCLUDES_DEFAULT 4301 [ 4302 #ifdef HAVE_FCNTL_H 4303 #include <fcntl.h> 4304 #endif 4305 #ifdef HAVE_UNISTD_H 4306 #include <unistd.h> 4307 #endif 4308 ]],[[ 4309 int arr[2]; 4310 int res; 4311 res = pipe2(arr, O_CLOEXEC | O_NONBLOCK); 4312 i][f (res != 0) return 33; 4313 close (arr[0]); 4314 close (arr[1]); 4315 return 0; 4316 ]],[ 4317 # Cross-compiling 4318 AS_CASE([${host_os}], [kfreebsd*-gnu], [cacheVar='assuming no'], 4319 [cacheVar='assuming yes']) 4320 ], 4321 [AC_DEFINE([[HAVE_PIPE2_FUNC]], [[1]], [Define if you have usable pipe2(2) function])] 4322 ) 4323 ], [ 4324 AS_VAR_IF([[enable_itc]], [["pipe"]], [AC_MSG_ERROR([[pipe(3) is not usable, consider using other type of inter-thread communication]])]) 4325 ]) 4326 ]) 4327 ]) 4328 4329 AS_IF([[test "x$enable_itc" = "xsocketpair" || test "x$enable_itc" = "xauto"]], 4330 [ 4331 AS_IF([test "x${os_is_native_w32}" = "xyes"], 4332 [mhd_cv_socketpair_usable='yes'], 4333 [test "x${mhd_cv_func_socketpair}" = "xyes"], 4334 [ 4335 AC_CACHE_CHECK([[whether socketpair(3) is usable]], [[mhd_cv_socketpair_usable]], 4336 [ 4337 AC_LINK_IFELSE([ 4338 AC_LANG_PROGRAM( 4339 [[ 4340 #ifdef HAVE_SYS_TYPES_H 4341 #include <sys/types.h> 4342 #endif 4343 #ifdef HAVE_SYS_SOCKET_H 4344 #include <sys/socket.h> 4345 #endif 4346 #if defined(HAVE_UNISTD_H) 4347 #include <unistd.h> 4348 #endif 4349 #ifdef HAVE_SYS_UN_H 4350 #include <sys/un.h> 4351 #endif 4352 ]], [[ 4353 int arr[2]; 4354 int res; 4355 #if defined(AF_UNIX) 4356 res = socketpair(AF_UNIX, SOCK_STREAM, 0, arr); 4357 #elif defined(AF_LOCAL) 4358 res = socketpair(AF_LOCAL, SOCK_STREAM, 0, arr); 4359 #else 4360 #error AF_LOCAL and AF_UNIX are both undefined 4361 choke me now; 4362 #endif 4363 if (res != 0) return 1; 4364 close (arr[1]); 4365 close (arr[0]); 4366 ]] 4367 ) 4368 ], 4369 [[mhd_cv_socketpair_usable='yes']], 4370 [[mhd_cv_socketpair_usable='no']] 4371 ) 4372 ] 4373 ) 4374 ], 4375 [AS_UNSET([mhd_cv_socketpair_usable])] 4376 ) 4377 4378 AS_VAR_IF([[mhd_cv_socketpair_usable]], [["yes"]], 4379 [ 4380 use_itc='socketpair' 4381 enable_itc="$use_itc" 4382 AC_DEFINE([[MHD_ITC_SOCKETPAIR_]], [[1]], [Define to use socketpair for inter-thread communication]) 4383 ], 4384 [ 4385 AS_VAR_IF([[enable_itc]], [["socketpair"]], [ 4386 AC_MSG_ERROR([[socketpair(3) is not usable, consider using other type of inter-thread communication]])] 4387 ) 4388 ] 4389 ) 4390 ] 4391 ) 4392 4393 AS_IF([[test -z "$use_itc"]], [AC_MSG_ERROR([[cannot find usable type of inter-thread communication]])]) 4394 4395 4396 MHD_CHECK_FUNC([accept4], 4397 [[ 4398 #if defined(HAVE_SYS_TYPES_H) 4399 # include <sys/types.h> 4400 #endif 4401 #include <sys/socket.h> 4402 ]], 4403 [[ 4404 struct sockaddr sk_addr; 4405 socklen_t addr_size; 4406 i][f (0 > accept4(0, &sk_addr, &addr_size, 0)) 4407 return 3; 4408 ]] 4409 ) 4410 MHD_CHECK_FUNC([gmtime_r], 4411 [[ 4412 #if defined(HAVE_SYS_TYPES_H) 4413 # include <sys/types.h> 4414 #endif 4415 #include <time.h> 4416 ]], 4417 [[ 4418 time_t timer = (time_t) 0; 4419 struct tm res; 4420 4421 i][f (&res != gmtime_r(&timer, &res)) 4422 return 3; 4423 ]] 4424 ) 4425 MHD_CHECK_FUNC([memmem], 4426 [[ 4427 #if defined(HAVE_STDDEF_H) 4428 # include <stddef.h> 4429 #elif defined(HAVE_STDLIB_H) 4430 # include <stdlib.h> 4431 #endif /* HAVE_STDLIB_H */ 4432 #include <string.h> 4433 ]], 4434 [[ 4435 const char *haystack = "abcd"; 4436 size_t hslen = 3; 4437 const char *needle = "bc"; 4438 size_t needlelen = 2; 4439 4440 i][f ((haystack + 1) != memmem(haystack, hslen, needle, needlelen)) 4441 return 3; 4442 ]] 4443 ) 4444 MHD_CHECK_FUNC([snprintf], 4445 [[ 4446 #include <stdio.h> 4447 ]], 4448 [[ 4449 char buf[2]; 4450 4451 i][f (1 != snprintf(buf, 2, "a")) 4452 return 3; 4453 /* Do not use the next check to avoid compiler warning */ 4454 /* i][f (4 != snprintf(buf, 2, "abcd")) 4455 return 4; */ 4456 ]] 4457 ) 4458 AC_CHECK_DECL([gmtime_s], 4459 [ 4460 AC_MSG_CHECKING([[whether gmtime_s is in C11 form]]) 4461 AC_LINK_IFELSE( 4462 [ AC_LANG_PROGRAM( 4463 [[ 4464 #define __STDC_WANT_LIB_EXT1__ 1 4465 #include <time.h> 4466 #ifdef __cplusplus 4467 extern "C" 4468 #endif 4469 struct tm* gmtime_s(const time_t* time, struct tm* result); 4470 ]], [[ 4471 static struct tm res; 4472 static time_t t = 0; 4473 gmtime_s (&t, &res); 4474 ]]) 4475 ], 4476 [ 4477 AC_DEFINE([HAVE_C11_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in C11 form.]) 4478 AC_MSG_RESULT([[yes]]) 4479 ], 4480 [ 4481 AC_MSG_RESULT([[no]]) 4482 AC_MSG_CHECKING([[whether gmtime_s is in W32 form]]) 4483 AC_LINK_IFELSE( 4484 [ AC_LANG_PROGRAM( 4485 [[ 4486 #include <time.h> 4487 #ifdef __cplusplus 4488 extern "C" 4489 #endif 4490 errno_t gmtime_s(struct tm* _tm, const time_t* time); 4491 ]], [[ 4492 static struct tm res; 4493 static time_t t = 0; 4494 gmtime_s (&res, &t); 4495 ]]) 4496 ], 4497 [ 4498 AC_DEFINE([HAVE_W32_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in W32 form.]) 4499 AC_MSG_RESULT([[yes]]) 4500 ], 4501 [AC_MSG_RESULT([[no]]) 4502 ]) 4503 ]) 4504 ], [], 4505 [[#define __STDC_WANT_LIB_EXT1__ 1 4506 #include <time.h>]]) 4507 4508 4509 MHD_FIND_LIB([clock_gettime],[[#include <time.h>]], 4510 [[ 4511 struct timespec tp; 4512 i][f (0 > clock_gettime(CLOCK_REALTIME, &tp)) 4513 return 3; 4514 ]], 4515 [rt], 4516 [ 4517 AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define to '1' if you have clock_gettime() function]) 4518 AS_VAR_IF([[mhd_cv_find_lib_clock_gettime]],[["none required"]], [], 4519 [ 4520 MHD_LIBDEPS_PKGCFG="${mhd_cv_find_lib_clock_gettime} $MHD_LIBDEPS_PKGCFG" 4521 ] 4522 ) 4523 ],[], 4524 [MHD_LIBDEPS] 4525 ) 4526 4527 MHD_CHECK_FUNC([mach_continuous_approximate_time], 4528 [[ 4529 #include <mach/mach.h> 4530 #include <mach/mach_time.h> 4531 ]], 4532 [[ 4533 struct mach_timebase_info mtb_info; 4534 i][f (KERN_SUCCESS != mach_timebase_info(&mtb_info)) 4535 return 2; 4536 i][f (0 == mach_continuous_approximate_time() * mtb_info.numer / mtb_info.denom) 4537 return 3; 4538 ]], [], [ 4539 MHD_CHECK_FUNC([mach_approximate_time], 4540 [[ 4541 #include <mach/mach.h> 4542 #include <mach/mach_time.h> 4543 ]], 4544 [[ 4545 struct mach_timebase_info mtb_info; 4546 i][f (KERN_SUCCESS != mach_timebase_info(&mtb_info)) 4547 return 2; 4548 i][f (0 == mach_approximate_time() * mtb_info.numer / mtb_info.denom) 4549 return 3; 4550 ]] 4551 ) 4552 ] 4553 ) 4554 4555 MHD_CHECK_FUNC([clock_get_time], 4556 [[ 4557 #include <mach/mach.h> 4558 #include <mach/clock.h> 4559 4560 #if !defined(SYSTEM_CLOCK) && defined(REALTIME_CLOCK) 4561 # define SYSTEM_CLOCK REALTIME_CLOCK 4562 #endif 4563 ]], 4564 [[ 4565 clock_serv_t cs; 4566 mach_timespec_t mt; 4567 host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cs); 4568 clock_get_time(cs, &mt); 4569 mach_port_deallocate(mach_task_self(), cs); 4570 ]] 4571 ) 4572 4573 MHD_CHECK_FUNC([gethrtime], 4574 [[ 4575 #ifdef HAVE_SYS_TIME_H 4576 /* Solaris define gethrtime() in sys/time.h */ 4577 #include <sys/time.h> 4578 #endif /* HAVE_SYS_TIME_H */ 4579 #ifdef HAVE_TIME_H 4580 /* HP-UX define gethrtime() in time.h */ 4581 #include <time.h> 4582 #endif /* HAVE_TIME_H */ 4583 ]], 4584 [[ 4585 hrtime_t hrt = gethrtime(); 4586 i][f (0 == hrt) 4587 return 3; 4588 ]] 4589 ) 4590 4591 AS_VAR_IF([ac_cv_header_time_h], ["yes"], 4592 [ 4593 MHD_CHECK_FUNC([timespec_get], 4594 [[ 4595 #include <time.h> 4596 4597 #ifndef TIME_UTC 4598 #error TIME_UTC must be defined to use timespec_get() 4599 choke me now 4600 #endif 4601 ]], 4602 [[ 4603 struct timespec ts; 4604 i][f (TIME_UTC != timespec_get (&ts, TIME_UTC)) 4605 return 3; 4606 ]] 4607 ) 4608 ] 4609 ) 4610 4611 MHD_CHECK_FUNC_GETTIMEOFDAY 4612 4613 # IPv6 4614 AC_CACHE_CHECK([for IPv6],[mhd_cv_have_inet6], 4615 [ 4616 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 4617 #include <stdio.h> 4618 #ifdef HAVE_SYS_SOCKET_H 4619 #include <sys/socket.h> 4620 #elif defined(HAVE_UNISTD_H) 4621 #include <unistd.h> 4622 #endif 4623 #ifdef HAVE_NETINET_IN_H 4624 #include <netinet/in.h> 4625 #endif 4626 #ifdef HAVE_WINSOCK2_H 4627 #include <winsock2.h> 4628 #endif 4629 #ifdef HAVE_WS2TCPIP_H 4630 #include <ws2tcpip.h> 4631 #endif 4632 ]], [[ 4633 int af=AF_INET6; 4634 struct sockaddr_in6 sa; 4635 printf("%d %p\n", (int) af, (void*) &sa); 4636 ]] 4637 ) 4638 ], 4639 [AS_VAR_SET([mhd_cv_have_inet6],["yes"])], 4640 [AS_VAR_SET([mhd_cv_have_inet6],["no"])] 4641 ) 4642 ] 4643 ) 4644 AS_VAR_IF([mhd_cv_have_inet6],["yes"], 4645 [AC_DEFINE([HAVE_INET6], [1], [Define to '1' if you have IPv6 headers])] 4646 ) 4647 4648 MHD_CHECK_FUNC([[sysconf]], [[#include <unistd.h>]], [[long a = sysconf(0); if (a) return 1;]]) 4649 4650 MHD_CHECK_FUNC([[sysctl]], [[ 4651 #ifdef HAVE_SYS_TYPES_H 4652 #include <sys/types.h> 4653 #endif 4654 #ifdef HAVE_SYS_SYSCTL_H 4655 #include <sys/sysctl.h> 4656 #endif 4657 #if defined(HAVE_STDDEF_H) 4658 #include <stddef.h> 4659 #elif defined(HAVE_STDLIB_H) 4660 #include <stdlib.h> 4661 #endif 4662 ]], [[ 4663 int mib[2] = {0, 0}; /* Avoid any platform-specific values */ 4664 i][f (sysctl(mib, 2, NULL, NULL, NULL, 0)) return 1; 4665 ]], 4666 [ 4667 MHD_CHECK_DECLS([CTL_NET PF_INET IPPROTO_ICMP ICMPCTL_ICMPLIM], 4668 [[ 4669 #ifdef HAVE_SYS_TYPES_H 4670 #include <sys/types.h> 4671 #endif /* HAVE_SYS_TYPES_H */ 4672 #ifdef HAVE_SYS_SYSCTL_H 4673 #include <sys/sysctl.h> 4674 #endif /* HAVE_SYS_SYSCTL_H */ 4675 #ifdef HAVE_SYS_SYSCTL_H 4676 #include <sys/sysctl.h> 4677 #endif /* HAVE_SYS_SYSCTL_H */ 4678 #ifdef HAVE_SYS_SOCKET_H 4679 #include <sys/socket.h> 4680 #elif defined(HAVE_UNISTD_H) 4681 #include <unistd.h> 4682 #endif 4683 #ifdef HAVE_NETINET_IN_SYSTM_H 4684 #include <netinet/in_systm.h> 4685 #endif /* HAVE_NETINET_IN_SYSTM_H */ 4686 #ifdef HAVE_NETINET_IN_H 4687 #include <netinet/in.h> 4688 #endif /* HAVE_NETINET_IN_H */ 4689 #ifdef HAVE_NETINET_IP_H 4690 #include <netinet/ip.h> 4691 #endif /* HAVE_NETINET_IP_H */ 4692 #ifdef HAVE_NETINET_IP_ICMP_H 4693 #include <netinet/ip_icmp.h> 4694 #endif /* HAVE_NETINET_IP_ICMP_H */ 4695 #ifdef HAVE_NETINET_ICMP_VAR_H 4696 #include <netinet/icmp_var.h> 4697 #endif /* HAVE_NETINET_ICMP_VAR_H */ 4698 ]] 4699 ) 4700 ] 4701 ) 4702 4703 MHD_CHECK_FUNC([[sysctlbyname]], [[ 4704 #ifdef HAVE_SYS_TYPES_H 4705 #include <sys/types.h> 4706 #endif 4707 #ifdef HAVE_SYS_SYSCTL_H 4708 #include <sys/sysctl.h> 4709 #endif 4710 #if defined(HAVE_STDDEF_H) 4711 #include <stddef.h> 4712 #elif defined(HAVE_STDLIB_H) 4713 #include <stdlib.h> 4714 #endif 4715 ]], [[sysctlbyname("test", NULL, NULL, NULL, 0);]] 4716 ) 4717 4718 MHD_CHECK_FUNC([[usleep]], [[#include <unistd.h>]], [[usleep(100000);]]) 4719 MHD_CHECK_FUNC([[nanosleep]], [[#include <time.h>]], [[struct timespec ts2, ts1 = {0, 0}; nanosleep(&ts1, &ts2);]]) 4720 4721 # NOTE: require setting of errattr_CFLAGS above 4722 AS_VAR_IF([mhd_cv_cc_warnless_c_flags],["no"],[:],[ac_c_werror_flag="yes"]) 4723 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}" 4724 AC_CACHE_CHECK([whether $CC supports __attribute__((used))],[mhd_cv_cc_attr_used], 4725 [ 4726 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4727 extern __attribute__((used)) int 4728 test_func(void); 4729 4730 extern __attribute__((used)) int 4731 test_func(void) {return 0;} 4732 4733 int main(void) {return test_func();} 4734 ]]) 4735 ], 4736 [mhd_cv_cc_attr_used="yes"],[mhd_cv_cc_attr_used="no"] 4737 ) 4738 ] 4739 ) 4740 AS_VAR_IF([mhd_cv_cc_attr_used],["yes"], 4741 [ 4742 AC_DEFINE([HAVE_ATTR_USED],[1], 4743 [Define to '1' if your compiler supports __attribute__((used))] 4744 ) 4745 ] 4746 ) 4747 AC_CACHE_CHECK([whether $CC supports __attribute__((pure))],[mhd_cv_cc_attr_pure], 4748 [ 4749 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4750 extern __attribute__((pure)) int 4751 test_func(const char *ptr); 4752 4753 extern __attribute__((pure)) int 4754 test_func(const char *ptr) {return (0 == (*ptr));} 4755 4756 int main(void) {return test_func("");} 4757 ]]) 4758 ], 4759 [mhd_cv_cc_attr_pure="yes"],[mhd_cv_cc_attr_pure="no"] 4760 ) 4761 ] 4762 ) 4763 AS_VAR_IF([mhd_cv_cc_attr_pure],["yes"], 4764 [ 4765 AC_DEFINE([HAVE_ATTR_PURE],[1], 4766 [Define to '1' if your compiler supports __attribute__((pure))] 4767 ) 4768 ] 4769 ) 4770 AC_CACHE_CHECK([whether $CC supports __attribute__((const))],[mhd_cv_cc_attr_const], 4771 [ 4772 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4773 extern __attribute__((const)) int 4774 test_func(int a); 4775 4776 extern __attribute__((const)) int 4777 test_func(int a) {return a + 1;} 4778 4779 int main(void) {return test_func(-1);} 4780 ]]) 4781 ], 4782 [mhd_cv_cc_attr_const="yes"],[mhd_cv_cc_attr_const="no"] 4783 ) 4784 ] 4785 ) 4786 AS_VAR_IF([mhd_cv_cc_attr_const],["yes"], 4787 [ 4788 AC_DEFINE([HAVE_ATTR_CONST],[1], 4789 [Define to '1' if your compiler supports __attribute__((const))] 4790 ) 4791 ] 4792 ) 4793 AC_CACHE_CHECK([whether $CC supports __attribute__((visibility("default")))],[mhd_cv_cc_attr_visibility_default], 4794 [ 4795 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4796 extern __attribute__((visibility("default"))) int 4797 test_extrn_func(void); 4798 4799 extern __attribute__((visibility("default"))) int 4800 test_extrn_func(void) {return 0;} 4801 4802 int main(void) {return test_extrn_func();} 4803 ]]) 4804 ], 4805 [mhd_cv_cc_attr_visibility_default="yes"],[mhd_cv_cc_attr_visibility_default="no"] 4806 ) 4807 ] 4808 ) 4809 AS_VAR_IF([mhd_cv_cc_attr_visibility_default],["yes"], 4810 [ 4811 AC_DEFINE([HAVE_ATTR_VISIBILITY_DEFAULT],[1], 4812 [Define to '1' if your compiler supports __attribute__((visibility("default")))] 4813 ) 4814 4815 AC_CACHE_CHECK([whether $CC supports __attribute__((visibility("internal")))],[mhd_cv_cc_attr_visibility_internal], 4816 [ 4817 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4818 __attribute__((visibility("internal"))) int 4819 test_intern_func(void); 4820 4821 __attribute__((visibility("internal"))) int 4822 test_intern_func(void) {return 0;} 4823 4824 int main(void) {return test_intern_func();} 4825 ]]) 4826 ], 4827 [mhd_cv_cc_attr_visibility_internal="yes"],[mhd_cv_cc_attr_visibility_internal="no"] 4828 ) 4829 ] 4830 ) 4831 AS_VAR_IF([mhd_cv_cc_attr_visibility_internal],["yes"], 4832 [ 4833 AC_DEFINE([HAVE_ATTR_VISIBILITY_INTERNAL],[1], 4834 [Define to '1' if your compiler supports __attribute__((visibility("internal")))] 4835 ) 4836 ] 4837 ) 4838 4839 AC_CACHE_CHECK([whether $CC supports __attribute__((visibility("hidden")))],[mhd_cv_cc_attr_visibility_hidden], 4840 [ 4841 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4842 __attribute__((visibility("hidden"))) int 4843 test_hidden_func(void); 4844 4845 __attribute__((visibility("hidden"))) int 4846 test_hidden_func(void) {return 0;} 4847 4848 int main(void) {return test_hidden_func();} 4849 ]]) 4850 ], 4851 [mhd_cv_cc_attr_visibility_hidden="yes"],[mhd_cv_cc_attr_visibility_hidden="no"] 4852 ) 4853 ] 4854 ) 4855 AS_VAR_IF([mhd_cv_cc_attr_visibility_hidden],["yes"], 4856 [ 4857 AC_DEFINE([HAVE_ATTR_VISIBILITY_HIDDEN],[1], 4858 [Define to '1' if your compiler supports __attribute__((visibility("hidden")))] 4859 ) 4860 ] 4861 ) 4862 4863 CFLAGS="${user_CFLAGS}" 4864 MHD_CHECK_CC_CFLAG([-fvisibility=hidden],[CFLAGS_ac], 4865 [ 4866 MHD_APPEND_FLAG_TO_VAR([MHD_LIB_CFLAGS],[-fvisibility=hidden]) 4867 ], 4868 [ 4869 AC_MSG_WARN([[$CC supports __attribute__((visibility("default"))), but does not support -fvisibility=hidden. Check compiler and compiler flags.]]) 4870 ] 4871 ) 4872 ] 4873 ) 4874 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}" 4875 AC_CACHE_CHECK([whether $CC supports __attribute__ ((externally_visible))],[mhd_cv_cc_attr_extern_vis], 4876 [ 4877 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4878 int test_func(void) __attribute__ ((externally_visible)); 4879 __attribute__ ((externally_visible)) int 4880 test_func(void) {return 0; } 4881 4882 int main(void) { return test_func(); } 4883 ]]) 4884 ], 4885 [mhd_cv_cc_attr_extern_vis="yes"],[mhd_cv_cc_attr_extern_vis="no"] 4886 ) 4887 ] 4888 ) 4889 AS_VAR_IF([mhd_cv_cc_attr_extern_vis],["yes"], 4890 [ 4891 AC_DEFINE([HAVE_ATTR_EXTERN_VISIBLE],[1], 4892 [Define to '1' if your compiler supports __attribute__((externally_visible))] 4893 ) 4894 ] 4895 ) 4896 AC_CACHE_CHECK([whether $CC supports __attribute__ ((warn_unused_result))],[mhd_cv_cc_attr_warn_unused_res], 4897 [ 4898 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4899 static __attribute__ ((warn_unused_result)) int 4900 test_func(void) {return 0; } 4901 4902 int main(void) { return test_func(); } 4903 ]]) 4904 ], 4905 [mhd_cv_cc_attr_warn_unused_res="yes"],[mhd_cv_cc_attr_warn_unused_res="no"] 4906 ) 4907 ] 4908 ) 4909 AS_VAR_IF([mhd_cv_cc_attr_warn_unused_res],["yes"], 4910 [ 4911 AC_DEFINE([HAVE_ATTR_WARN_UNUSED_RES],[1], 4912 [Define to '1' if your compiler supports __attribute__ ((warn_unused_result))] 4913 ) 4914 ] 4915 ) 4916 AC_CACHE_CHECK([whether $CC supports __attribute__ ((returns_nonnull))],[mhd_cv_cc_attr_ret_nonnull], 4917 [ 4918 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4919 static __attribute__ ((returns_nonnull)) int * 4920 test_func(void) { 4921 static int i = 0; 4922 return &i; 4923 } 4924 4925 int main(void) { 4926 return *(test_func()); 4927 } 4928 ]]) 4929 ], 4930 [mhd_cv_cc_attr_ret_nonnull="yes"],[mhd_cv_cc_attr_ret_nonnull="no"] 4931 ) 4932 ] 4933 ) 4934 AS_VAR_IF([mhd_cv_cc_attr_ret_nonnull],["yes"], 4935 [ 4936 AC_DEFINE([HAVE_ATTR_RET_NONNULL],[1], 4937 [Define to '1' if your compiler supports __attribute__ ((returns_nonnull))] 4938 ) 4939 ] 4940 ) 4941 AC_CACHE_CHECK([whether $CC supports __attribute__ ((assume_aligned (N)))],[mhd_cv_cc_attr_func_assume_aligned], 4942 [ 4943 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4944 static __attribute__((assume_aligned (1))) void* 4945 test_func(void) { 4946 static signed char c = 0; 4947 return (void*) &c; 4948 } 4949 4950 int main(void) { 4951 return test_func() ? 0 : 1; 4952 } 4953 ]]) 4954 ], 4955 [mhd_cv_cc_attr_func_assume_aligned="yes"],[mhd_cv_cc_attr_func_assume_aligned="no"] 4956 ) 4957 ] 4958 ) 4959 AS_VAR_IF([mhd_cv_cc_attr_func_assume_aligned],["yes"], 4960 [ 4961 AC_DEFINE([HAVE_ATTR_FUNC_ASSUME_ALIGNED],[1], 4962 [Define to '1' if your compiler supports __attribute__((assume_aligned(N)))] 4963 ) 4964 ] 4965 ) 4966 AC_CACHE_CHECK([whether $CC supports __attribute__ ((alloc_size (N)))],[mhd_cv_cc_attr_func_alloc_size], 4967 [ 4968 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 4969 #if defined(HAVE_STDDEF_H) 4970 # include <stddef.h> /* NULL */ 4971 #else 4972 # include <string.h> /* should provide NULL */ 4973 #endif 4974 4975 static __attribute__((alloc_size(1))) void* 4976 test_alloc(unsigned short size) { 4977 static char buf_alloc[8] = {0, 0, 0, 0, 0, 0, 0, 0}; 4978 static unsigned short allocated = 0; 4979 void *ret; 4980 if (sizeof(buf_alloc) - allocated < size) 4981 return NULL; 4982 ret = (void*) (buf_alloc + allocated); 4983 allocated -= size; 4984 return ret; 4985 } 4986 4987 int main(void) { 4988 return test_alloc(1) ? 0 : 1; 4989 } 4990 ]]) 4991 ], 4992 [mhd_cv_cc_attr_func_alloc_size="yes"],[mhd_cv_cc_attr_func_alloc_size="no"] 4993 ) 4994 ] 4995 ) 4996 AS_VAR_IF([mhd_cv_cc_attr_func_alloc_size],["yes"], 4997 [ 4998 AC_DEFINE([HAVE_ATTR_FUNC_ALLOC_SIZE],[1], 4999 [Define to '1' if your compiler supports __attribute__((alloc_size(N)))] 5000 ) 5001 ] 5002 ) 5003 AC_CACHE_CHECK([whether $CC supports __attribute__ ((malloc))],[mhd_cv_cc_attr_func_malloc], 5004 [ 5005 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5006 #if defined(HAVE_STDDEF_H) 5007 # include <stddef.h> /* NULL */ 5008 #else 5009 # include <string.h> /* should provide NULL */ 5010 #endif 5011 5012 static __attribute__((malloc)) void* 5013 test_alloc(void) { 5014 static char buf_alloc[8] = {0, 0, 0, 0, 0, 0, 0, 0}; 5015 static int used_flag = 0; 5016 if (used_flag) 5017 return NULL; 5018 used_flag = !0; 5019 return buf_alloc; 5020 } 5021 5022 int main(void) { 5023 return test_alloc() ? 0 : 1; 5024 } 5025 ]]) 5026 ], 5027 [mhd_cv_cc_attr_func_malloc="yes"],[mhd_cv_cc_attr_func_malloc="no"] 5028 ) 5029 ] 5030 ) 5031 AS_VAR_IF([mhd_cv_cc_attr_func_malloc],["yes"], 5032 [ 5033 AC_DEFINE([HAVE_ATTR_FUNC_MALLOC],[1], 5034 [Define to '1' if your compiler supports __attribute__((malloc))] 5035 ) 5036 ] 5037 ) 5038 AC_CACHE_CHECK([whether $CC supports __attribute__ ((malloc(deallocator)))],[mhd_cv_cc_attr_func_malloc_dealloc], 5039 [ 5040 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5041 #if defined(HAVE_STDDEF_H) 5042 # include <stddef.h> /* NULL */ 5043 #else 5044 # include <string.h> /* should provide NULL */ 5045 #endif 5046 5047 static int used_flag = 0; 5048 static char buf_alloc[8] = {0, 0, 0, 0, 0, 0, 0, 0}; 5049 5050 static void 5051 test_dealloc(void *ptr) { 5052 if (! used_flag) 5053 return; 5054 if (ptr != (void*) buf_alloc) 5055 return; 5056 used_flag = 0; 5057 } 5058 5059 static __attribute__((malloc(test_dealloc))) void* 5060 test_alloc(void) { 5061 if (used_flag) 5062 return NULL; 5063 used_flag = !0; 5064 return (void*) buf_alloc; 5065 } 5066 5067 int main(void) { 5068 test_dealloc(test_alloc()); 5069 return 0; 5070 } 5071 ]]) 5072 ], 5073 [mhd_cv_cc_attr_func_malloc_dealloc="yes"],[mhd_cv_cc_attr_func_malloc_dealloc="no"] 5074 ) 5075 ] 5076 ) 5077 AS_VAR_IF([mhd_cv_cc_attr_func_malloc_dealloc],["yes"], 5078 [ 5079 AC_DEFINE([HAVE_ATTR_FUNC_MALLOC_DEALLOC],[1], 5080 [Define to '1' if your compiler supports __attribute__((malloc(deallocator)))] 5081 ) 5082 ] 5083 ) 5084 AC_CACHE_CHECK([whether $CC supports __attribute__ ((nonnull))],[mhd_cv_cc_attr_nonnull], 5085 [ 5086 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5087 static __attribute__ ((nonnull)) int 5088 test_func(int *p) {return 0 == *p;} 5089 5090 int main(void) { 5091 int i = 0; 5092 return test_func(&i) ? 0 : 5; 5093 } 5094 ]]) 5095 ], 5096 [mhd_cv_cc_attr_nonnull="yes"],[mhd_cv_cc_attr_nonnull="no"] 5097 ) 5098 ] 5099 ) 5100 AS_VAR_IF([mhd_cv_cc_attr_nonnull],["yes"], 5101 [ 5102 AC_DEFINE([HAVE_ATTR_NONNULL],[1], 5103 [Define to '1' if your compiler supports __attribute__ ((nonnull))] 5104 ) 5105 ] 5106 ) 5107 AC_CACHE_CHECK([whether $CC supports __attribute__ ((nonnull(NUM)))],[mhd_cv_cc_attr_nonnull_num], 5108 [ 5109 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5110 static __attribute__ ((nonnull(2))) int 5111 test_func(int *p1, int *p2) { 5112 return (((int *)(void *)0) == p1) && (0 == *p2); 5113 } 5114 5115 int main(void) { 5116 int i = 0; 5117 return test_func( (int *)(void *)0, &i) ? 0 : 5; 5118 } 5119 ]]) 5120 ], 5121 [mhd_cv_cc_attr_nonnull_num="yes"],[mhd_cv_cc_attr_nonnull_num="no"] 5122 ) 5123 ] 5124 ) 5125 AS_VAR_IF([mhd_cv_cc_attr_nonnull_num],["yes"], 5126 [ 5127 AC_DEFINE([HAVE_ATTR_NONNULL_NUM],[1], 5128 [Define to '1' if your compiler supports __attribute__ ((nonnull(NUM)))] 5129 ) 5130 ] 5131 ) 5132 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (read_only,NUM)))],[mhd_cv_cc_attr_access_read], 5133 [ 5134 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5135 static __attribute__ ((access (read_only,1))) int 5136 test_func(int *p) {return 0 == *p;} 5137 5138 int main(void) { 5139 int i = 0; 5140 return test_func(&i) ? 0 : 5; 5141 } 5142 ]]) 5143 ], 5144 [mhd_cv_cc_attr_access_read="yes"],[mhd_cv_cc_attr_access_read="no"] 5145 ) 5146 ] 5147 ) 5148 AS_VAR_IF([mhd_cv_cc_attr_access_read],["yes"], 5149 [ 5150 AC_DEFINE([HAVE_ATTR_ACCESS_READ],[1], 5151 [Define to '1' if your compiler supports __attribute__ ((access (read_only,NUM)))] 5152 ) 5153 ] 5154 ) 5155 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (write_only,NUM)))],[mhd_cv_cc_attr_access_write], 5156 [ 5157 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5158 static __attribute__ ((access (write_only,1))) void 5159 test_func(int *p) {*p = 0;} 5160 5161 int main(void) { 5162 int i = 1; 5163 test_func(&i); 5164 return i; 5165 } 5166 ]]) 5167 ], 5168 [mhd_cv_cc_attr_access_write="yes"],[mhd_cv_cc_attr_access_write="no"] 5169 ) 5170 ] 5171 ) 5172 AS_VAR_IF([mhd_cv_cc_attr_access_write],["yes"], 5173 [ 5174 AC_DEFINE([HAVE_ATTR_ACCESS_WRITE],[1], 5175 [Define to '1' if your compiler supports __attribute__ ((access (write_only,NUM)))] 5176 ) 5177 ] 5178 ) 5179 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (read_write,NUM)))],[mhd_cv_cc_attr_access_read_write], 5180 [ 5181 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5182 static __attribute__ ((access (read_write,1))) void 5183 test_func(int *p) {*p = *p - 1;} 5184 5185 int main(void) { 5186 int i = 1; 5187 test_func(&i); 5188 return i; 5189 } 5190 ]]) 5191 ], 5192 [mhd_cv_cc_attr_access_read_write="yes"],[mhd_cv_cc_attr_access_read_write="no"] 5193 ) 5194 ] 5195 ) 5196 AS_VAR_IF([mhd_cv_cc_attr_access_read_write],["yes"], 5197 [ 5198 AC_DEFINE([HAVE_ATTR_ACCESS_READ_WRITE],[1], 5199 [Define to '1' if your compiler supports __attribute__ ((access (read_write,NUM)))] 5200 ) 5201 ] 5202 ) 5203 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (read_only,NUM,NUM_SIZE)))],[mhd_cv_cc_attr_access_read_size], 5204 [ 5205 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5206 static __attribute__ ((access (read_only,2,1))) int 5207 test_func(unsigned int num, int *arr) {return 2 == arr[num - 1];} 5208 5209 int main(void) { 5210 int arr[4] = {5, 4, 3, 2}; 5211 return test_func(4, arr) ? 0 : 5; 5212 } 5213 ]]) 5214 ], 5215 [mhd_cv_cc_attr_access_read_size="yes"],[mhd_cv_cc_attr_access_read_size="no"] 5216 ) 5217 ] 5218 ) 5219 AS_VAR_IF([mhd_cv_cc_attr_access_read_size],["yes"], 5220 [ 5221 AC_DEFINE([HAVE_ATTR_ACCESS_READ_SIZE],[1], 5222 [Define to '1' if your compiler supports __attribute__ ((access (read_only,NUM,NUM_SIZE)))] 5223 ) 5224 ] 5225 ) 5226 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (write_only,NUM,NUM_SIZE)))],[mhd_cv_cc_attr_access_write_size], 5227 [ 5228 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5229 static __attribute__ ((access (write_only,2,1))) void 5230 test_func(unsigned int num, int *arr) {arr[num-1] = 0;} 5231 5232 int main(void) { 5233 int arr[4] = {5, 4, 3, 2}; 5234 test_func(4, arr); 5235 return arr[3]; 5236 } 5237 ]]) 5238 ], 5239 [mhd_cv_cc_attr_access_write_size="yes"],[mhd_cv_cc_attr_access_write_size="no"] 5240 ) 5241 ] 5242 ) 5243 AS_VAR_IF([mhd_cv_cc_attr_access_write_size],["yes"], 5244 [ 5245 AC_DEFINE([HAVE_ATTR_ACCESS_WRITE_SIZE],[1], 5246 [Define to '1' if your compiler supports __attribute__ ((access (write_only,NUM,NUM_SIZE)))] 5247 ) 5248 ] 5249 ) 5250 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (read_write,NUM,NUM_SIZE)))],[mhd_cv_cc_attr_access_read_write_size], 5251 [ 5252 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5253 static __attribute__ ((access (read_write,2,1))) void 5254 test_func(unsigned int num, int *arr) {arr[num-1] = arr[1] - 4;} 5255 5256 int main(void) { 5257 int arr[4] = {5, 4, 3, 2}; 5258 test_func(4, arr); 5259 return arr[3]; 5260 } 5261 ]]) 5262 ], 5263 [mhd_cv_cc_attr_access_read_write_size="yes"],[mhd_cv_cc_attr_access_read_write_size="no"] 5264 ) 5265 ] 5266 ) 5267 AS_VAR_IF([mhd_cv_cc_attr_access_read_write_size],["yes"], 5268 [ 5269 AC_DEFINE([HAVE_ATTR_ACCESS_READ_WRITE_SIZE],[1], 5270 [Define to '1' if your compiler supports __attribute__ ((access (read_write,NUM,NUM_SIZE)))] 5271 ) 5272 ] 5273 ) 5274 AC_CACHE_CHECK([whether $CC supports __attribute__ ((fd_arg_read (NUM)))],[mhd_cv_cc_attr_fd_arg_read], 5275 [ 5276 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5277 #ifndef _CRT_NONSTDC_NO_WARNINGS 5278 #define _CRT_NONSTDC_NO_WARNINGS 1 5279 #endif 5280 #ifdef HAVE_SYS_TYPES_H 5281 #include <sys/types.h> 5282 #endif 5283 #include <stdio.h> 5284 #ifdef HAVE_IO_H 5285 #include <io.h> 5286 #endif 5287 #ifdef HAVE_STDLIB_H 5288 #include <stdlib.h> 5289 #endif 5290 #include <fcntl.h> 5291 #ifdef HAVE_UNISTD_H 5292 #include <unistd.h> 5293 #endif 5294 5295 static __attribute__ ((fd_arg_read (1))) int 5296 test_func(int fd) 5297 { 5298 int data_in; 5299 int read_size; 5300 read_size = (int) read(fd, &data_in, sizeof(data_in)); 5301 if (read_size < (int) sizeof(data_in)) return 4; 5302 return data_in; 5303 } 5304 5305 int main(void) { 5306 int fd = open("test.txt", O_RDONLY); 5307 int res = test_func(fd); 5308 close (fd); 5309 return res; 5310 } 5311 ]]) 5312 ], 5313 [mhd_cv_cc_attr_fd_arg_read="yes"],[mhd_cv_cc_attr_fd_arg_read="no"] 5314 ) 5315 ] 5316 ) 5317 AS_VAR_IF([mhd_cv_cc_attr_fd_arg_read],["yes"], 5318 [ 5319 AC_DEFINE([HAVE_ATTR_FD_ARG_READ],[1], 5320 [Define to '1' if your compiler supports __attribute__ ((fd_arg_read (NUM)))] 5321 ) 5322 ] 5323 ) 5324 AC_CACHE_CHECK([whether $CC supports __attribute__ ((null_terminated_string_arg (NUM)))],[mhd_cv_cc_attr_null_term_str], 5325 [ 5326 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5327 static __attribute__ ((null_terminated_string_arg (1))) int 5328 test_func(const char *str) {return (0 == str[0]) ? 5 : 0;} 5329 5330 int main(void) { 5331 return test_func("test"); 5332 } 5333 ]]) 5334 ], 5335 [mhd_cv_cc_attr_null_term_str="yes"],[mhd_cv_cc_attr_null_term_str="no"] 5336 ) 5337 ] 5338 ) 5339 AS_VAR_IF([mhd_cv_cc_attr_null_term_str],["yes"], 5340 [ 5341 AC_DEFINE([HAVE_ATTR_NULL_TERM_STR],[1], 5342 [Define to '1' if your compiler supports __attribute__ ((null_terminated_string_arg (NUM)))] 5343 ) 5344 ] 5345 ) 5346 AC_CACHE_CHECK([whether $CC supports __attribute__((enum_extensibility (closed)))],[mhd_cv_cc_attr_enum_extns_closed], 5347 [ 5348 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5349 enum __attribute__((enum_extensibility (closed))) Test_Enum 5350 {Val_A = 0, Val_B = 3}; 5351 5352 int main(void) 5353 { 5354 enum Test_Enum var = Val_A; 5355 return (var != Val_B) ? 0 : 3; 5356 } 5357 ]]) 5358 ], 5359 [mhd_cv_cc_attr_enum_extns_closed="yes"],[mhd_cv_cc_attr_enum_extns_closed="no"] 5360 ) 5361 ] 5362 ) 5363 AS_VAR_IF([mhd_cv_cc_attr_enum_extns_closed],["yes"], 5364 [ 5365 AC_DEFINE([HAVE_ATTR_ENUM_EXTNS_CLOSED],[1], 5366 [Define to '1' if your compiler supports __attribute__((enum_extensibility (closed)))] 5367 ) 5368 ] 5369 ) 5370 AC_CACHE_CHECK([whether $CC supports __attribute__((flag_enum))],[mhd_cv_cc_attr_flag_enum], 5371 [ 5372 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5373 #ifdef HAVE_ATTR_ENUM_EXTNS_CLOSED 5374 #define ATTR_EXTNS_CLOSED_IF_SUPPORTED __attribute__((enum_extensibility (closed))) 5375 #else 5376 #define ATTR_EXTNS_CLOSED_IF_SUPPORTED /* empty */ 5377 #endif 5378 enum ATTR_EXTNS_CLOSED_IF_SUPPORTED __attribute__((flag_enum)) Test_Enum 5379 {Flag_A = 1 << 0, Flag_B = 1 << 1, Flag_C = 1 << 2, Flag_D = 1 << 3}; 5380 5381 int main(void) 5382 { 5383 enum Test_Enum var = Flag_A; 5384 var |= Flag_C; 5385 var = var | Flag_D | Flag_A; 5386 return (var != Flag_B) ? 0 : 3; 5387 } 5388 ]]) 5389 ], 5390 [mhd_cv_cc_attr_flag_enum="yes"],[mhd_cv_cc_attr_flag_enum="no"] 5391 ) 5392 ] 5393 ) 5394 AS_VAR_IF([mhd_cv_cc_attr_flag_enum],["yes"], 5395 [ 5396 AC_DEFINE([HAVE_ATTR_FLAG_ENUM],[1], 5397 [Define to '1' if your compiler supports __attribute__((flag_enum))] 5398 ) 5399 ] 5400 ) 5401 ac_c_werror_flag="" 5402 AC_CACHE_CHECK([[whether $CC supports array[static N] with fixed N as a function parameter]],[mhd_cv_cc_func_param_arr_static_fixed], 5403 [ 5404 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5405 static int 5406 test_func(int arr[static 4]) { return arr[2] - 4; } 5407 5408 int main(void) { 5409 int arr[4] = {5, 4, 3, 2}; 5410 return test_func(arr); 5411 } 5412 ]]) 5413 ], 5414 [mhd_cv_cc_func_param_arr_static_fixed="yes"],[mhd_cv_cc_func_param_arr_static_fixed="no"] 5415 ) 5416 ] 5417 ) 5418 AS_VAR_IF([mhd_cv_cc_func_param_arr_static_fixed],["yes"], 5419 [ 5420 AC_DEFINE([HAVE_FUNC_PARAM_ARR_STATIC_FIXED],[1], 5421 [Define to '1' if your compiler supports 'array[static N]' with fixed N as function parameter] 5422 ) 5423 ] 5424 ) 5425 AC_CACHE_CHECK([[whether $CC supports array[static N] with variable N as a function parameter]],[mhd_cv_cc_func_param_arr_static_var], 5426 [ 5427 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 5428 static int 5429 test_func(int num, int arr[static num]) { return arr[num-2] - 4; } 5430 5431 int main(void) { 5432 int arr[4] = {5, 4, 3, 2}; 5433 return test_func(4, arr); 5434 } 5435 ]]) 5436 ], 5437 [mhd_cv_cc_func_param_arr_static_var="yes"],[mhd_cv_cc_func_param_arr_static_var="no"] 5438 ) 5439 ] 5440 ) 5441 AS_VAR_IF([mhd_cv_cc_func_param_arr_static_var],["yes"], 5442 [ 5443 AC_DEFINE([HAVE_FUNC_PARAM_ARR_STATIC_VAR],[1], 5444 [Define to '1' if your compiler supports 'array[static N]' with variable N as a function parameter] 5445 ) 5446 ] 5447 ) 5448 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 5449 5450 # libcurl (required for testing) 5451 AC_ARG_ENABLE([curl], 5452 [AS_HELP_STRING([--disable-curl],[disable cURL based testcases])], 5453 [enable_curl=${enableval}]) 5454 curl=0 5455 AS_IF([test "$enable_curl" != "no"], 5456 [LIBCURL_CHECK_CONFIG([yes],[7.16.4],[enable_curl=yes], 5457 [ 5458 AS_IF([test "x$enable_curl" = "xyes"], 5459 [AC_MSG_WARN([[cURL-based tests cannot be enabled because libcurl is missing]])]) 5460 enable_curl=no 5461 ]) 5462 ]) 5463 AM_CONDITIONAL([RUN_LIBCURL_TESTS], [test "x$enable_curl" = "xyes"]) 5464 AS_IF([test "x$enable_curl" = "xyes"], 5465 [MSG_CURL="yes"], 5466 [MSG_CURL="no, many unit tests will not run"] 5467 ) 5468 5469 MHD_CHECK_FUNC([magic_open], 5470 [[ 5471 #include <magic.h> 5472 ]], 5473 [[ 5474 char var_data[256]; 5475 const char *var_mime; 5476 magic_t var_magic = magic_open (MAGIC_MIME_TYPE); 5477 (void)magic_load (var_magic, "filename"); 5478 var_data[0] = 0; 5479 var_mime = magic_buffer (var_magic, var_data, 1); 5480 i][f (! var_mime) 5481 return 1; 5482 magic_close (var_magic); 5483 ]], 5484 [AC_DEFINE([MHD_HAVE_LIBMAGIC], [1], [Define to 1 if you have suitable libmagic.])], 5485 [], 5486 [-lmagic] 5487 ) 5488 AM_CONDITIONAL([MHD_HAVE_LIBMAGIC], [[test "x$mhd_cv_have_func_magic_open" = "xyes"]]) 5489 5490 # large file support (> 4 GB) 5491 MHD_CHECK_FUNC([lseek64], 5492 [[ 5493 #ifndef _LARGEFILE64_SOURCE 5494 # define _LARGEFILE64_SOURCE 1 5495 #endif 5496 #if defined(HAVE_SYS_TYPES_H) 5497 # include <sys/types.h> 5498 #endif 5499 #include <stdlib.h> 5500 #ifdef HAVE_UNISTD_H 5501 # include <unistd.h> 5502 #endif 5503 ]], 5504 [[ 5505 i][f (((off64_t) -1) == lseek64(0, (off64_t) 0, SEEK_SET)) 5506 return 3; 5507 ]] 5508 ) 5509 MHD_CHECK_FUNC([pread64], 5510 [[ 5511 #ifndef _LARGEFILE64_SOURCE 5512 # define _LARGEFILE64_SOURCE 1 5513 #endif 5514 #if defined(HAVE_SYS_TYPES_H) 5515 # include <sys/types.h> 5516 #endif 5517 #include <stdlib.h> 5518 #ifdef HAVE_UNISTD_H 5519 # include <unistd.h> 5520 #endif 5521 ]], 5522 [[ 5523 char buf[5]; 5524 i][f (0 > pread64(0, (void *) buf, 1, (off64_t) 0)) 5525 return 3; 5526 ]] 5527 ) 5528 MHD_CHECK_FUNC([pread], 5529 [[ 5530 #if defined(HAVE_SYS_TYPES_H) 5531 # include <sys/types.h> 5532 #endif 5533 #include <stdlib.h> 5534 #ifdef HAVE_UNISTD_H 5535 # include <unistd.h> 5536 #endif 5537 ]], 5538 [[ 5539 char buf[5]; 5540 i][f (0 > pread(0, (void *) buf, 1, 0)) 5541 return 3; 5542 ]] 5543 ) 5544 5545 AS_VAR_IF([have_poll],["yes"],[MHD_CHECK_POLL_QUIRKS()]) 5546 5547 # check for various sendfile functions 5548 AC_ARG_ENABLE([sendfile], 5549 [AS_HELP_STRING([--disable-sendfile], 5550 [disable usage of sendfile() for HTTP connections [auto]])], 5551 [], 5552 [enable_sendfile="auto"]) 5553 AS_CASE([$enable_sendfile], 5554 [[auto | yes]],[[found_sendfile="no"]], 5555 [[no]],[[found_sendfile="disabled"]], 5556 [AC_MSG_ERROR([[unknown value specified: --enable-sendfile=$enable_sendfile]])] 5557 ) 5558 AS_VAR_IF([[found_sendfile]], [["no"]], 5559 [ 5560 AC_MSG_CHECKING([[for Linux-style sendfile(2)]]) 5561 AC_LINK_IFELSE( 5562 [AC_LANG_PROGRAM( 5563 [[ 5564 #include <sys/sendfile.h> 5565 5566 static void empty_func(void) 5567 { 5568 /* Check for declaration */ 5569 #ifndef sendfile 5570 (void)sendfile; 5571 #endif 5572 } 5573 ]], 5574 [[ 5575 int fd1=0, fd2=2; 5576 off_t o = 0; 5577 size_t s = 5; 5578 ssize_t r; 5579 r = sendfile (fd1, fd2, &o, s); 5580 if (r) 5581 empty_func(); 5582 ]] 5583 ) 5584 ], 5585 [ 5586 AC_DEFINE([HAVE_LINUX_SENDFILE], [1], [Define to 1 if you have linux-style sendfile(2).]) 5587 found_sendfile="yes, Linux-style" 5588 AC_MSG_RESULT([[yes]]) 5589 MHD_CHECK_FUNC([sendfile64], 5590 [[ 5591 #ifndef _LARGEFILE64_SOURCE 5592 # define _LARGEFILE64_SOURCE 1 5593 #endif 5594 #include <sys/sendfile.h> 5595 ]], 5596 [[ 5597 off64_t f_offset = (off64_t) 0; 5598 if (0 > sendfile64 (0, 1, &f_offset, 1)) 5599 return 3; 5600 ]] 5601 ) 5602 ], 5603 [AC_MSG_RESULT([[no]]) 5604 ] 5605 ) 5606 ] 5607 ) 5608 AS_VAR_IF([[found_sendfile]], [["no"]], 5609 [ 5610 AC_MSG_CHECKING([[for FreeBSD-style sendfile(2)]]) 5611 AC_LINK_IFELSE( 5612 [AC_LANG_PROGRAM( 5613 [[ 5614 #ifdef HAVE_SYS_TYPES_H 5615 #include <sys/types.h> 5616 #endif 5617 #ifdef HAVE_UNISTD_H 5618 #include <unistd.h> 5619 #endif 5620 #ifdef HAVE_SYS_SOCKET_H 5621 #include <sys/socket.h> 5622 #endif 5623 #include <sys/uio.h> 5624 5625 static void empty_func(void) 5626 { 5627 /* Check for declaration */ 5628 #ifndef sendfile 5629 (void)sendfile; 5630 #endif 5631 } 5632 ]], 5633 [[ 5634 int fd1=0, fd2=1; 5635 off_t o = 0; 5636 size_t s = 5; 5637 off_t r1; 5638 int r2; 5639 r2 = sendfile (fd1, fd2, o, s, (struct sf_hdtr *)0, &r1, 0); 5640 if (r2) 5641 empty_func(); 5642 ]] 5643 ) 5644 ], 5645 [ 5646 AC_DEFINE([HAVE_FREEBSD_SENDFILE], [1], [Define to 1 if you have FreeBSD-style sendfile(2).]) 5647 found_sendfile="yes, FreeBSD-style" 5648 AC_MSG_RESULT([[yes]]) 5649 ], 5650 [AC_MSG_RESULT([[no]]) 5651 ] 5652 ) 5653 ] 5654 ) 5655 AS_VAR_IF([[found_sendfile]], [["no"]], 5656 [ 5657 AC_MSG_CHECKING([[for Darwin-style sendfile(2)]]) 5658 AC_LINK_IFELSE( 5659 [AC_LANG_PROGRAM( 5660 [[ 5661 #ifdef HAVE_SYS_TYPES_H 5662 #include <sys/types.h> 5663 #endif 5664 #ifdef HAVE_UNISTD_H 5665 #include <unistd.h> 5666 #endif 5667 #ifdef HAVE_SYS_SOCKET_H 5668 #include <sys/socket.h> 5669 #endif 5670 #include <sys/uio.h> 5671 5672 static void empty_func(void) 5673 { 5674 /* Check for declaration */ 5675 #ifndef sendfile 5676 (void)sendfile; 5677 #endif 5678 } 5679 ]], 5680 [[ 5681 int fd=0, s=1; 5682 off_t o = 0; 5683 off_t l = 5; 5684 int r; 5685 r = sendfile (fd, s, o, &l, (struct sf_hdtr *)0, 0); 5686 if (r) 5687 empty_func(); 5688 ]] 5689 ) 5690 ], 5691 [ 5692 AC_DEFINE([HAVE_DARWIN_SENDFILE], [1], [Define to 1 if you have Darwin-style sendfile(2).]) 5693 found_sendfile="yes, Darwin-style" 5694 AC_MSG_RESULT([[yes]]) 5695 ], 5696 [AC_MSG_RESULT([[no]]) 5697 ] 5698 ) 5699 ] 5700 ) 5701 5702 AS_VAR_IF([[found_sendfile]], [["no"]], 5703 [ 5704 AC_MSG_CHECKING([[for old Solaris-style sendfile(3)]]) 5705 SAVE_LIBS="$LIBS" 5706 LIBS="-lsendfile $LIBS" 5707 AC_LINK_IFELSE( 5708 [AC_LANG_PROGRAM( 5709 [[ 5710 #ifdef HAVE_SYS_TYPES_H 5711 #include <sys/types.h> 5712 #endif 5713 #ifdef HAVE_UNISTD_H 5714 #include <unistd.h> 5715 #endif 5716 #ifdef HAVE_SYS_SOCKET_H 5717 #include <sys/socket.h> 5718 #endif 5719 #include <sys/sendfile.h> 5720 5721 static void empty_func(void) 5722 { 5723 /* Check for declaration */ 5724 #ifndef sendfile 5725 (void)sendfile; 5726 #endif 5727 } 5728 ]], 5729 [[ 5730 int fd1=0, fd2=1; 5731 off_t o = 0; 5732 size_t l = 5; 5733 ssize_t r; 5734 r = sendfile (fd1, fd2, &o, l); 5735 if (r) 5736 empty_func(); 5737 ]] 5738 ) 5739 ], 5740 [ 5741 # Solaris uses the same format as GNU/Linux. Old versions need libsendfile. 5742 AC_DEFINE([HAVE_LINUX_SENDFILE], [1], [Define to 1 if you have linux-style sendfile(2).]) 5743 found_sendfile="yes, Solaris-style" 5744 MHD_LIBDEPS="-lsendfile $MHD_LIBDEPS" 5745 MHD_LIBDEPS_PKGCFG="-lsendfile $MHD_LIBDEPS_PKGCFG" 5746 AC_MSG_RESULT([[yes]]) 5747 MHD_CHECK_FUNC([sendfile64], 5748 [[ 5749 #ifdef HAVE_SYS_TYPES_H 5750 #include <sys/types.h> 5751 #endif 5752 #ifdef HAVE_UNISTD_H 5753 #include <unistd.h> 5754 #endif 5755 #ifdef HAVE_SYS_SOCKET_H 5756 #include <sys/socket.h> 5757 #endif 5758 #include <sys/sendfile.h> 5759 ]], 5760 [[ 5761 off64_t f_offset = (off64_t) 0; 5762 #ifndef sendfile64 5763 (void)sendfile64; 5764 #endif 5765 if (0 > sendfile64 (0, 1, &f_offset, 1)) 5766 return 3; 5767 ]] 5768 ) 5769 ], 5770 [AC_MSG_RESULT([[no]]) 5771 ] 5772 ) 5773 LIBS="$SAVE_LIBS" 5774 ] 5775 ) 5776 AS_IF([[test "x$found_sendfile" = "xno" && test "x$enable_sendfile" = "xyes"]], 5777 [AC_MSG_ERROR([[sendfile() usage was requested by configure parameter, but no usable sendfile() function is detected]])] 5778 ) 5779 5780 # optional: disable log and HTTP automatic messages 5781 AC_ARG_ENABLE([messages], 5782 [AS_HELP_STRING([--disable-messages], 5783 [disable log messages and text bodies for ] 5784 [automatic HTTP responses (to reduce the binary size)] 5785 ) 5786 ], 5787 [],[enable_messages="yes"] 5788 ) 5789 5790 AC_MSG_CHECKING([[whether to support internal logging functionality and build messages for log]]) 5791 AC_ARG_ENABLE([log-messages], 5792 [AS_HELP_STRING([--disable-log-messages], 5793 [disable logger functionality and exclude log mesages from binary] 5794 ) 5795 ], 5796 [],[enable_log_messages="$enable_messages"] 5797 ) 5798 AS_VAR_IF([enable_log_messages],["yes"], 5799 [AC_DEFINE([MHD_SUPPORT_LOG_FUNCTIONALITY],[1],[Define to '1' to enable internal logging and log messages.])], 5800 [enable_log_messages="no"] 5801 ) 5802 AC_MSG_RESULT([[$enable_log_messages]]) 5803 AM_CONDITIONAL([MHD_SUPPORT_LOG_FUNCTIONALITY], [test "x$enable_log_messages" != "xno"]) 5804 5805 AC_MSG_CHECKING([[whether to build text bodies for automatic HTTP response messages]]) 5806 AC_ARG_ENABLE([http-messages], 5807 [AS_HELP_STRING([--disable-http-messages], 5808 [use empty bodies for automatic HTTP responses (less verbose for clients)] 5809 ) 5810 ], 5811 [],[enable_http_messages="$enable_messages"] 5812 ) 5813 AS_VAR_IF([enable_http_messages],["yes"], 5814 [AC_DEFINE([MHD_ENABLE_AUTO_MESSAGES_BODIES],[1],[Define to '1' to enable verbose text bodies for automatic HTTP replies.])], 5815 [enable_http_messages="no"] 5816 ) 5817 AC_MSG_RESULT([[$enable_http_messages]]) 5818 AM_CONDITIONAL([MHD_ENABLE_AUTO_MESSAGES_BODIES], [test "x$enable_http_messages" != "xno"]) 5819 5820 5821 # optional: have postprocessor? 5822 AC_MSG_CHECKING([[whether to enable POST parser]]) 5823 AC_ARG_ENABLE([postparser], 5824 [AS_HELP_STRING([--disable-postparser], 5825 [disable MHD POST parser functionality])], 5826 [enable_postparser=${enableval}], 5827 [enable_postparser=yes]) 5828 AS_IF([[test "x$enable_postparser" != "xno"]], 5829 [ enable_postparser=yes 5830 AC_DEFINE([MHD_SUPPORT_POST_PARSER],[1],[Define to 1 if libmicrohttpd is compiled with POST parser support.]) ]) 5831 AM_CONDITIONAL([MHD_SUPPORT_POST_PARSER], [test "x$enable_postparser" != "xno"]) 5832 AC_MSG_RESULT([[$enable_postparser]]) 5833 5834 have_gnutls=no 5835 have_gnutls_pkgcfg=no 5836 have_openssl=no 5837 have_openssl_pkgcfg=no 5838 have_mbedtls=no 5839 have_mbedtls_pkgcfg=no 5840 multiple_tls="no" 5841 AS_UNSET([MHD_TLS_LIB_CPPFLAGS]) 5842 AS_UNSET([MHD_TLS_LIB_LDFLAGS]) 5843 AS_UNSET([MHD_TLS_LIBDEPS]) 5844 MSG_TLS_BACKENDS="none" 5845 5846 AC_ARG_ENABLE([http2], 5847 [AS_HELP_STRING([--disable-http2], [disable HTTP/2 support])], 5848 [ 5849 AS_CASE([${enableval}], 5850 [yes],[:], 5851 [no],[:], 5852 [AC_MSG_ERROR([wrong parameter value --enable-http2=${enableval}])] 5853 ) 5854 ], 5855 [enable_http2="yes"] 5856 ) 5857 AS_VAR_IF([enable_http2],["yes"], 5858 [AC_DEFINE([MHD_SUPPORT_HTTP2],[1],[Define to '1' to enable support for HTTP/2 protocol])] 5859 ) 5860 AM_CONDITIONAL([MHD_SUPPORT_HTTP2], [test "x$enable_http2" = "xyes"]) 5861 5862 # optional: HTTPS support. Enabled if GnuTLS is available. 5863 PKG_PROG_PKG_CONFIG 5864 AC_ARG_ENABLE([https], 5865 [AS_HELP_STRING([--enable-https], 5866 [enable HTTPS support (yes, no, auto)[auto]])], 5867 [enable_https=${enableval}]) 5868 AS_IF([test "x$enable_https" != "xno"], 5869 [ 5870 have_gnutls_pkgcfg=no 5871 AC_MSG_CHECKING([[how to find GnuTLS library]]) 5872 AC_ARG_WITH([[gnutls]], 5873 [AS_HELP_STRING([[--with-gnutls[=PRFX]]], 5874 [use GnuTLS for HTTPS support, optional PRFX overrides pkg-config data for GnuTLS headers (PRFX/include) and libs (PRFX/lib)])], 5875 [ 5876 AS_CASE([$with_gnutls], 5877 [no],[ 5878 have_gnutls="no" 5879 AS_UNSET([GNUTLS_CPPFLAGS]) 5880 AS_UNSET([GNUTLS_CFLAGS]) 5881 AS_UNSET([GNUTLS_LDFLAGS]) 5882 AS_UNSET([GNUTLS_LIBS]) 5883 AC_MSG_RESULT([[GnuTLS disabled]]) 5884 ], 5885 [yes],[ 5886 AC_MSG_RESULT([[automatically, forced]]) 5887 ], 5888 [ 5889 AC_MSG_RESULT([[-I$with_gnutls/include -L$with_gnutls/lib -lgnutls]]) 5890 LDFLAGS="${LDFLAGS_ac} -L$with_gnutls/lib ${user_LDFLAGS}" 5891 CPPFLAGS="${CPPFLAGS_ac} -I$with_gnutls/include ${user_CPPFLAGS}" 5892 have_gnutls_pkgcfg=no 5893 # A simple check for the working header and the library 5894 MHD_CHECK_FUNC([gnutls_check_version], 5895 [[ 5896 ]AC_INCLUDES_DEFAULT[ 5897 #include <gnutls/gnutls.h> 5898 ]], 5899 [ 5900 if(!gnutls_check_version("3.0.0")) 5901 return 3; 5902 ], 5903 [ 5904 have_gnutls=yes 5905 GNUTLS_CPPFLAGS="-I$with_gnutls/include" 5906 AS_UNSET([GNUTLS_CFLAGS]) 5907 GNUTLS_LDFLAGS="-L$with_gnutls/lib" 5908 GNUTLS_LIBS="-lgnutls" 5909 ], 5910 [AC_MSG_ERROR([cannot find usable libgnutls at specified prefix $with_gnutls])], 5911 [-lgnutls] 5912 ) 5913 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 5914 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 5915 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 5916 ]) 5917 ], 5918 [AC_MSG_RESULT([[automatically]])] 5919 ) 5920 5921 AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"], 5922 [ 5923 PKG_CHECK_MODULES([GNUTLS], [[gnutls]], 5924 [ 5925 CPPFLAGS="${CPPFLAGS_ac} $GNUTLS_CFLAGS ${user_CPPFLAGS}" 5926 # A simple check for the working header and the library 5927 MHD_CHECK_FUNC([gnutls_check_version], 5928 [[ 5929 ]AC_INCLUDES_DEFAULT[ 5930 #include <gnutls/gnutls.h> 5931 ]], 5932 [ 5933 if(!gnutls_check_version("3.0.0")) 5934 return 3; 5935 ], 5936 [ 5937 have_gnutls="yes" 5938 have_gnutls_pkgcfg="yes" 5939 # GNUTLS_CFLAGS is actually CPPFLAGS 5940 GNUTLS_CPPFLAGS="$GNUTLS_CFLAGS" 5941 AS_UNSET([GNUTLS_CFLAGS]) 5942 # GNUTLS_LIBS is a combination of LDFLAGS and LIBS 5943 AS_UNSET([GNUTLS_LDFLAGS]) 5944 ], 5945 [ 5946 AS_VAR_IF([with_gnutls],["yes"], 5947 [AC_MSG_ERROR([cannot find usable libgnutls])] 5948 ) 5949 AC_MSG_WARN([pkg-config reports that GnuTLS is present, but GnuTLS cannot be used]) 5950 AS_UNSET([GNUTLS_CPPFLAGS]) 5951 AS_UNSET([GNUTLS_CFLAGS]) 5952 AS_UNSET([GNUTLS_LDFLAGS]) 5953 AS_UNSET([GNUTLS_LIBS]) 5954 ], 5955 [$GNUTLS_LIBS] 5956 ) 5957 ], 5958 [ 5959 # check for GnuTLS at default paths 5960 have_gnutls_pkgcfg="no" 5961 # A simple check for the working header and the library 5962 MHD_CHECK_FUNC([gnutls_check_version], 5963 [[ 5964 ]AC_INCLUDES_DEFAULT[ 5965 #include <gnutls/gnutls.h> 5966 ]], 5967 [ 5968 if(!gnutls_check_version("3.0.0")) 5969 return 3; 5970 ], 5971 [ 5972 have_gnutls=yes 5973 AS_UNSET([GNUTLS_CPPFLAGS]) 5974 AS_UNSET([GNUTLS_CFLAGS]) 5975 AS_UNSET([GNUTLS_LDFLAGS]) 5976 GNUTLS_LIBS="-lgnutls" 5977 ], 5978 [ 5979 AS_VAR_IF([with_gnutls],["yes"], 5980 [AC_MSG_ERROR([cannot find usable libgnutls])] 5981 ) 5982 AS_UNSET([GNUTLS_CPPFLAGS]) 5983 AS_UNSET([GNUTLS_CFLAGS]) 5984 AS_UNSET([GNUTLS_LDFLAGS]) 5985 AS_UNSET([GNUTLS_LIBS]) 5986 ], 5987 [-lgnutls] 5988 ) 5989 ] 5990 ) 5991 ] 5992 ) 5993 AS_VAR_IF([have_gnutls],["yes"], 5994 [ 5995 AC_CACHE_CHECK([[whether GnuTLS is modern enough]], [mhd_cv_gnutls_ver_ok], 5996 [ 5997 CPPFLAGS="${CPPFLAGS_ac} ${GNUTLS_CPPFLAGS} ${user_CPPFLAGS}" 5998 AC_COMPILE_IFELSE( 5999 [ 6000 AC_LANG_PROGRAM( 6001 [[ 6002 ]AC_INCLUDES_DEFAULT[ 6003 #include <gnutls/gnutls.h> 6004 ]], 6005 [[ 6006 #if !defined(GNUTLS_VERSION_NUMBER) || GNUTLS_VERSION_NUMBER+0 <= 0x020c14 6007 #error Too old version of GnuTLS that requires libgcript initialisation 6008 choke me now 6009 #endif 6010 ]] 6011 ) 6012 ], 6013 [[mhd_cv_gnutls_ver_ok="yes"]], [[mhd_cv_gnutls_ver_ok="no"]] 6014 ) 6015 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 6016 ] 6017 ) 6018 AS_VAR_IF([mhd_cv_gnutls_ver_ok],["yes"],[:], 6019 [ 6020 have_gnutls="no" 6021 AS_VAR_IF([with_gnutls],["yes"], 6022 [AC_MSG_ERROR([cannot find usable libgnutls])] 6023 ) 6024 ] 6025 ) 6026 ] 6027 ) 6028 6029 AS_VAR_IF([have_gnutls],["yes"], 6030 [:], 6031 [ 6032 have_gnutls="no" 6033 have_gnutls_pkgcfg="no" 6034 AS_UNSET([GNUTLS_CPPFLAGS]) 6035 AS_UNSET([GNUTLS_CFLAGS]) 6036 AS_UNSET([GNUTLS_LDFLAGS]) 6037 AS_UNSET([GNUTLS_LIBS]) 6038 ] 6039 ) 6040 6041 6042 AC_MSG_CHECKING([[how to find OpenSSL library]]) 6043 AC_ARG_WITH([[openssl]], 6044 [AS_HELP_STRING([[--with-openssl[=PRFX]]], 6045 [use OpenSSL for HTTPS support, optional PRFX overrides pkg-config data for OpenSSL headers (PRFX/include) and libs (PRFX/lib)])], 6046 [ 6047 AS_CASE([$with_openssl], 6048 [no],[ 6049 have_openssl="no" 6050 AC_MSG_RESULT([[OpenSSL disabled]]) 6051 AS_UNSET([OPENSSL_CPPFLAGS]) 6052 AS_UNSET([OPENSSL_CFLAGS]) 6053 AS_UNSET([OPENSSL_LDFLAGS]) 6054 AS_UNSET([OPENSSL_LIBS]) 6055 ], 6056 [yes],[ 6057 AC_MSG_RESULT([[automatically, forced]]) 6058 ], 6059 [ 6060 AC_MSG_RESULT([[-I$with_openssl/include -L$with_openssl/lib -lssl -lcrypto]]) 6061 LDFLAGS="${LDFLAGS_ac} -L$with_openssl/lib ${user_LDFLAGS}" 6062 CPPFLAGS="${CPPFLAGS_ac} -I$with_openssl/include ${user_CPPFLAGS}" 6063 have_openssl_pkgcfg="no" 6064 # A simple check for the working header and the library 6065 MHD_CHECK_FUNC([SSL_CTX_new], 6066 [[ 6067 #include <openssl/ssl.h> 6068 ]], 6069 [[ 6070 SSL_CTX_free(SSL_CTX_new(TLS_server_method())); 6071 ]], 6072 [ 6073 have_openssl="yes" 6074 OPENSSL_CPPFLAGS="-I$with_openssl/include" 6075 AS_UNSET([OPENSSL_CFLAGS]) 6076 OPENSSL_LDFLAGS="-L$with_openssl/lib" 6077 OPENSSL_LIBS="-lssl -lcrypto" 6078 ], 6079 [AC_MSG_ERROR([cannot find usable OpenSSL library at specified prefix $with_openssl])], 6080 [-lssl -lcrypto] 6081 ) 6082 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 6083 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 6084 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 6085 ]) 6086 ], 6087 [AC_MSG_RESULT([[automatically]])] 6088 ) 6089 6090 AS_IF([test "x$with_openssl" != "xno" && test "x$have_openssl" != "xyes"], 6091 [ 6092 PKG_CHECK_MODULES([OPENSSL], [[openssl >= 3.0]], 6093 [ 6094 CPPFLAGS="${CPPFLAGS_ac} $OPENSSL_CFLAGS ${user_CPPFLAGS}" 6095 # A simple check for the working header and the library 6096 MHD_CHECK_FUNC([SSL_CTX_new], 6097 [[ 6098 #include <openssl/ssl.h> 6099 ]], 6100 [[ 6101 SSL_CTX_free(SSL_CTX_new(TLS_server_method())); 6102 ]], 6103 [ 6104 have_openssl=yes 6105 have_openssl_pkgcfg='yes' 6106 # OPENSSL_CFLAGS is actually CPPFLAGS 6107 OPENSSL_CPPFLAGS="$OPENSSL_CFLAGS" 6108 AS_UNSET([OPENSSL_CFLAGS]) 6109 # OPENSSL_LIBS is a combination of LDFLAGS and LIBS 6110 AS_UNSET([OPENSSL_LDFLAGS]) 6111 ], 6112 [ 6113 AS_VAR_IF([with_openssl],["yes"], 6114 [AC_MSG_ERROR([cannot find usable OpenSSL library])] 6115 ) 6116 AC_MSG_WARN([pkg-config reports that OpenSSL is present, but OpenSSL cannot be used]) 6117 AS_UNSET([OPENSSL_CPPFLAGS]) 6118 AS_UNSET([OPENSSL_CFLAGS]) 6119 AS_UNSET([OPENSSL_LDFLAGS]) 6120 AS_UNSET([OPENSSL_LIBS]) 6121 ], 6122 [$OPENSSL_LIBS] 6123 ) 6124 ], 6125 [ 6126 # check for OpenSSL at default paths 6127 have_openssl_pkgcfg="no" 6128 # A simple check for the working header and the library 6129 MHD_CHECK_FUNC([SSL_CTX_new], 6130 [[ 6131 #include <openssl/ssl.h> 6132 ]], 6133 [[ 6134 SSL_CTX_free(SSL_CTX_new(TLS_server_method())); 6135 ]], 6136 [ 6137 have_openssl="yes" 6138 AS_UNSET([OPENSSL_CPPFLAGS]) 6139 AS_UNSET([OPENSSL_CFLAGS]) 6140 AS_UNSET([OPENSSL_LDFLAGS]) 6141 OPENSSL_LIBS="-lssl -lcrypto" 6142 ], 6143 [ 6144 AS_VAR_IF([with_openssl],["yes"], 6145 [AC_MSG_ERROR([cannot find usable OpenSSL library])] 6146 ) 6147 AS_UNSET([OPENSSL_CPPFLAGS]) 6148 AS_UNSET([OPENSSL_CFLAGS]) 6149 AS_UNSET([OPENSSL_LDFLAGS]) 6150 AS_UNSET([OPENSSL_LIBS]) 6151 ], 6152 [-lssl -lcrypto] 6153 ) 6154 ] 6155 ) 6156 ] 6157 ) 6158 AS_VAR_IF([have_openssl],["yes"], 6159 [ 6160 AC_CACHE_CHECK([[whether OpenSSL is modern enough]], [mhd_cv_openssl_ver_ok], 6161 [ 6162 CPPFLAGS="${CPPFLAGS_ac} ${OPENSSL_CPPFLAGS} ${user_CPPFLAGS}" 6163 AC_COMPILE_IFELSE( 6164 [ 6165 AC_LANG_PROGRAM( 6166 [[ 6167 #include <openssl/opensslv.h> 6168 ]], 6169 [[ 6170 #ifndef OPENSSL_VERSION_PREREQ 6171 #error OPENSSL_VERSION_PREREQ is not defined. OpenSSL is too old. 6172 choke me now 6173 #endif 6174 #if !OPENSSL_VERSION_PREREQ(3,0) 6175 #error OpenSSL version is too old and not suitable. 6176 choke me now 6177 #endif 6178 ]] 6179 ) 6180 ], 6181 [[mhd_cv_openssl_ver_ok="yes"]], [[mhd_cv_openssl_ver_ok="no"]] 6182 ) 6183 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 6184 ] 6185 ) 6186 AS_VAR_IF([mhd_cv_openssl_ver_ok],["yes"],[:], 6187 [ 6188 have_openssl="no" 6189 AS_VAR_IF([with_openssl],["yes"], 6190 [AC_MSG_ERROR([cannot find usable OpenSSL library])] 6191 ) 6192 ] 6193 ) 6194 ] 6195 ) 6196 6197 AS_VAR_IF([have_openssl],["yes"], 6198 [:], 6199 [ 6200 have_openssl="no" 6201 have_openssl_pkgcfg="no" 6202 AS_UNSET([OPENSSL_CPPFLAGS]) 6203 AS_UNSET([OPENSSL_CFLAGS]) 6204 AS_UNSET([OPENSSL_LDFLAGS]) 6205 AS_UNSET([OPENSSL_LIBS]) 6206 ] 6207 ) 6208 6209 AC_MSG_CHECKING([[how to find MbedTLS library]]) 6210 AC_ARG_WITH([[mbedtls]], 6211 [AS_HELP_STRING([[--with-mbedtls[=PRFX]]], 6212 [use MbedTLS for HTTPS support, optional PRFX overrides pkg-config data for MbedTLS headers (PRFX/include) and libs (PRFX/lib)])], 6213 [ 6214 AS_CASE([$with_mbedtls], 6215 [no],[ 6216 have_mbedtls="no" 6217 have_mbedtls_pkgcfg="no" 6218 AC_MSG_RESULT([[MbedTLS disabled]]) 6219 ], 6220 [yes],[ 6221 have_mbedtls="find" 6222 have_mbedtls_pkgcfg="auto" 6223 AC_MSG_RESULT([[automatically, forced]]) 6224 ], 6225 [ 6226 AC_MSG_RESULT([[-I$with_mbedtls/include -L$with_mbedtls/lib]]) 6227 6228 AS_UNSET([MBEDTLS_FULL_CPPFLAGS]) 6229 AS_UNSET([MBEDTLS_FULL_CFLAGS]) 6230 AS_UNSET([MBEDTLS_FULL_LDFLAGS]) 6231 AS_UNSET([MBEDTLS_FULL_LIBS]) 6232 AS_UNSET([MBEDTLS_CRYPTO_CPPFLAGS]) 6233 AS_UNSET([MBEDTLS_CRYPTO_CFLAGS]) 6234 AS_UNSET([MBEDTLS_CRYPTO_LDFLAGS]) 6235 AS_UNSET([MBEDTLS_CRYPTO_LIBS]) 6236 AS_UNSET([MBEDTLS_X509_CPPFLAGS]) 6237 AS_UNSET([MBEDTLS_X509_CFLAGS]) 6238 AS_UNSET([MBEDTLS_X509_LDFLAGS]) 6239 AS_UNSET([MBEDTLS_X509_LIBS]) 6240 AS_UNSET([MBEDTLS_TLS_CPPFLAGS]) 6241 AS_UNSET([MBEDTLS_TLS_CFLAGS]) 6242 AS_UNSET([MBEDTLS_TLS_LDFLAGS]) 6243 AS_UNSET([MBEDTLS_TLS_LIBS]) 6244 have_mbedtls="find" 6245 have_mbedtls_pkgcfg="no" 6246 ] 6247 ) 6248 ], 6249 [ 6250 have_mbedtls_pkgcfg="auto" 6251 with_mbedtls="" 6252 AC_MSG_RESULT([[automatically]]) 6253 ] 6254 ) 6255 6256 AS_IF([test "x$with_mbedtls" != "xno" && test "x$have_mbedtls" != "xyes"], 6257 [ 6258 AS_VAR_SET_IF([MBEDTLS_CRYPTO_CFLAGS], 6259 [have_user_MBEDTLS_CRYPTO_CFLAGS="yes"], 6260 [have_user_MBEDTLS_CRYPTO_CFLAGS="no"] 6261 ) 6262 AS_VAR_SET_IF([MBEDTLS_CRYPTO_LIBS], 6263 [have_user_MBEDTLS_CRYPTO_LIBS="yes"], 6264 [have_user_MBEDTLS_CRYPTO_LIBS="no"] 6265 ) 6266 AS_VAR_SET_IF([MBEDTLS_X509_CFLAGS], 6267 [have_user_MBEDTLS_X509_CFLAGS="yes"], 6268 [have_user_MBEDTLS_X509_CFLAGS="no"] 6269 ) 6270 AS_VAR_SET_IF([MBEDTLS_X509_LIBS], 6271 [have_user_MBEDTLS_X509_LIBS="yes"], 6272 [have_user_MBEDTLS_X509_LIBS="no"] 6273 ) 6274 AS_VAR_SET_IF([MBEDTLS_TLS_CFLAGS], 6275 [have_user_MBEDTLS_TLS_CFLAGS="yes"], 6276 [have_user_MBEDTLS_TLS_CFLAGS="no"] 6277 ) 6278 AS_VAR_SET_IF([MBEDTLS_TLS_LIBS], 6279 [have_user_MBEDTLS_TLS_LIBS="yes"], 6280 [have_user_MBEDTLS_TLS_LIBS="no"] 6281 ) 6282 AS_IF([test "x$have_mbedtls" != "xyes" && test "x${have_mbedtls_pkgcfg}" != "xno"], 6283 [ 6284 mbedtsl_min_ver="3.0" 6285 PKG_CHECK_MODULES([MBEDTLS_CRYPTO], [[mbedcrypto-4 >= 4.0]], 6286 [ 6287 mbedtsl_min_ver="4.0" 6288 mbedtls_modules="mbedcrypto-4" 6289 PKG_CHECK_MODULES([MBEDTLS_X509], [[mbedx509-4 >= ${mbedtsl_min_ver}]], 6290 [ 6291 mbedtls_modules="${mbedtls_modules}, mbedx509-4" 6292 PKG_CHECK_MODULES([MBEDTLS_TLS], [[mbedtls-4 >= ${mbedtsl_min_ver}]], 6293 [ 6294 mbedtls_modules="${mbedtls_modules} and mbedtls-4" 6295 have_mbedtls_pkgcfg="yes" 6296 have_mbedtls="yes" 6297 ],[] 6298 ) 6299 ],[] 6300 ) 6301 ],[] 6302 ) 6303 AS_VAR_IF([have_mbedtls],["yes"],[:], 6304 [ 6305 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_CFLAGS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_CFLAGS])]) 6306 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_LIBS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_LIBS])]) 6307 AS_VAR_IF([have_user_MBEDTLS_X509_CFLAGS],["no"],[AS_UNSET([MBEDTLS_X509_CFLAGS])]) 6308 AS_VAR_IF([have_user_MBEDTLS_X509_LIBS],["no"],[AS_UNSET([MBEDTLS_X509_LIBS])]) 6309 AS_VAR_IF([have_user_MBEDTLS_TLS_CFLAGS],["no"],[AS_UNSET([MBEDTLS_TLS_CFLAGS])]) 6310 AS_VAR_IF([have_user_MBEDTLS_TLS_LIBS],["no"],[AS_UNSET([MBEDTLS_TLS_LIBS])]) 6311 PKG_CHECK_MODULES([MBEDTLS_CRYPTO], [[mbedcrypto-3 >= ${mbedtsl_min_ver}]], 6312 [ 6313 mbedtls_modules="mbedcrypto-3" 6314 PKG_CHECK_MODULES([MBEDTLS_X509], [[mbedx509-3 >= ${mbedtsl_min_ver}]], 6315 [ 6316 mbedtls_modules="${mbedtls_modules}, mbedx509-3" 6317 PKG_CHECK_MODULES([MBEDTLS_TLS], [[mbedtls-3 >= ${mbedtsl_min_ver}]], 6318 [ 6319 mbedtls_modules="${mbedtls_modules} and mbedtls-3" 6320 have_mbedtls_pkgcfg="yes" 6321 have_mbedtls="yes" 6322 ],[] 6323 ) 6324 ],[] 6325 ) 6326 ],[] 6327 ) 6328 ] 6329 ) 6330 AS_VAR_IF([have_mbedtls],["yes"],[:], 6331 [ 6332 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_CFLAGS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_CFLAGS])]) 6333 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_LIBS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_LIBS])]) 6334 AS_VAR_IF([have_user_MBEDTLS_X509_CFLAGS],["no"],[AS_UNSET([MBEDTLS_X509_CFLAGS])]) 6335 AS_VAR_IF([have_user_MBEDTLS_X509_LIBS],["no"],[AS_UNSET([MBEDTLS_X509_LIBS])]) 6336 AS_VAR_IF([have_user_MBEDTLS_TLS_CFLAGS],["no"],[AS_UNSET([MBEDTLS_TLS_CFLAGS])]) 6337 AS_VAR_IF([have_user_MBEDTLS_TLS_LIBS],["no"],[AS_UNSET([MBEDTLS_TLS_LIBS])]) 6338 PKG_CHECK_MODULES([MBEDTLS_CRYPTO], [[mbedcrypto >= ${mbedtsl_min_ver}]], 6339 [ 6340 mbedtls_modules="mbedcrypto" 6341 PKG_CHECK_MODULES([MBEDTLS_X509], [[mbedx509 >= ${mbedtsl_min_ver}]], 6342 [ 6343 mbedtls_modules="${mbedtls_modules}, mbedx509" 6344 PKG_CHECK_MODULES([MBEDTLS_TLS], [[mbedtls >= ${mbedtsl_min_ver}]], 6345 [ 6346 mbedtls_modules="${mbedtls_modules} and mbedtls" 6347 have_mbedtls_pkgcfg="yes" 6348 have_mbedtls="yes" 6349 ],[] 6350 ) 6351 ],[] 6352 ) 6353 ],[] 6354 ) 6355 ] 6356 ) 6357 AS_VAR_IF([have_mbedtls],["yes"], 6358 [ 6359 AS_UNSET([MBEDTLS_FULL_CPPFLAGS]) 6360 AS_UNSET([MBEDTLS_FULL_CFLAGS]) 6361 AS_UNSET([MBEDTLS_FULL_LDFLAGS]) 6362 AS_UNSET([MBEDTLS_FULL_LIBS]) 6363 # pkg-config's *_CFLAGS are actually *_CPPFLAGS 6364 MBEDTLS_CRYPTO_CPPFLAGS="${MBEDTLS_CRYPTO_CFLAGS}" 6365 MBEDTLS_X509_CPPFLAGS="${MBEDTLS_X509_CFLAGS}" 6366 MBEDTLS_TLS_CPPFLAGS="${MBEDTLS_TLS_CFLAGS}" 6367 AS_UNSET([MBEDTLS_CRYPTO_CFLAGS]) 6368 AS_UNSET([MBEDTLS_X509_CFLAGS]) 6369 AS_UNSET([MBEDTLS_TLS_CFLAGS]) 6370 # pkg-config's *_LIBS are combinations of *_LDFLAGS and *_LIBS 6371 AS_UNSET([MBEDTLS_CRYPTO_LDFLAGS]) 6372 AS_UNSET([MBEDTLS_X509_LDFLAGS]) 6373 AS_UNSET([MBEDTLS_TLS_LDFLAGS]) 6374 6375 # Smart-combine three libraries flags 6376 MBEDTLS_FULL_CPPFLAGS="${MBEDTLS_CRYPTO_CPPFLAGS}" 6377 AS_CASE([" ${MBEDTLS_X509_CPPFLAGS} "], 6378 [*" ${MBEDTLS_FULL_CPPFLAGS} "*],[:], 6379 [ 6380 AS_CASE([" ${MBEDTLS_FULL_CPPFLAGS} "], 6381 [*" ${MBEDTLS_X509_CPPFLAGS} "*],[MBEDTLS_FULL_CPPFLAGS="${MBEDTLS_X509_CPPFLAGS}"], 6382 [MBEDTLS_FULL_CPPFLAGS="${MBEDTLS_FULL_CPPFLAGS} ${MBEDTLS_X509_CPPFLAGS}"] 6383 ) 6384 ] 6385 ) 6386 AS_CASE([" ${MBEDTLS_TLS_CPPFLAGS} "], 6387 [*" ${MBEDTLS_FULL_CPPFLAGS} "*],[:], 6388 [ 6389 AS_CASE([" ${MBEDTLS_FULL_CPPFLAGS} "], 6390 [*" ${MBEDTLS_TLS_CPPFLAGS} "*],[MBEDTLS_FULL_CPPFLAGS="${MBEDTLS_TLS_CPPFLAGS}"], 6391 [MBEDTLS_FULL_CPPFLAGS="${MBEDTLS_FULL_CPPFLAGS} ${MBEDTLS_TLS_CPPFLAGS}"] 6392 ) 6393 ] 6394 ) 6395 MBEDTLS_FULL_LIBS="${MBEDTLS_CRYPTO_LIBS}" 6396 AS_CASE([" ${MBEDTLS_X509_LIBS} "], 6397 [*" ${MBEDTLS_FULL_LIBS} "*],[:], 6398 [ 6399 AS_CASE([" ${MBEDTLS_FULL_LIBS} "], 6400 [*" ${MBEDTLS_X509_LIBS} "*],[MBEDTLS_FULL_LIBS="${MBEDTLS_X509_LIBS}"], 6401 [MBEDTLS_FULL_LIBS="${MBEDTLS_X509_LIBS} ${MBEDTLS_FULL_LIBS}"] 6402 ) 6403 ] 6404 ) 6405 AS_CASE([" ${MBEDTLS_TLS_LIBS} "], 6406 [*" ${MBEDTLS_FULL_LIBS} "*],[:], 6407 [ 6408 AS_CASE([" ${MBEDTLS_FULL_LIBS} "], 6409 [*" ${MBEDTLS_TLS_LIBS} "*],[MBEDTLS_FULL_LIBS="${MBEDTLS_TLS_LIBS}"], 6410 [MBEDTLS_FULL_LIBS="${MBEDTLS_TLS_LIBS} ${MBEDTLS_FULL_LIBS}"] 6411 ) 6412 ] 6413 ) 6414 6415 CPPFLAGS="${CPPFLAGS_ac} ${MBEDTLS_FULL_CPPFLAGS} ${user_CPPFLAGS}" 6416 6417 MHD_CHECK_FUNC([mbedtls_ssl_init],[[#include <mbedtls/ssl.h>]], 6418 [[ 6419 mbedtls_ssl_context ssl; 6420 mbedtls_ssl_init (&ssl); 6421 mbedtls_ssl_free (&ssl); 6422 ]], 6423 [], 6424 [AC_MSG_ERROR([pkg-config reports that $mbedtls_modules modules are present, but MbedTLS cannot be used])], 6425 ["${MBEDTLS_FULL_LIBS}"] 6426 ) 6427 6428 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 6429 ], 6430 [ 6431 AS_UNSET([mbedtls_modules]) 6432 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_CFLAGS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_CFLAGS])]) 6433 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_LIBS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_LIBS])]) 6434 AS_VAR_IF([have_user_MBEDTLS_X509_CFLAGS],["no"],[AS_UNSET([MBEDTLS_X509_CFLAGS])]) 6435 AS_VAR_IF([have_user_MBEDTLS_X509_LIBS],["no"],[AS_UNSET([MBEDTLS_X509_LIBS])]) 6436 AS_VAR_IF([have_user_MBEDTLS_TLS_CFLAGS],["no"],[AS_UNSET([MBEDTLS_TLS_CFLAGS])]) 6437 AS_VAR_IF([have_user_MBEDTLS_TLS_LIBS],["no"],[AS_UNSET([MBEDTLS_TLS_LIBS])]) 6438 ] 6439 ) 6440 AS_UNSET([have_user_MBEDTLS_CRYPTO_CFLAGS]) 6441 AS_UNSET([have_user_MBEDTLS_CRYPTO_LIBS]) 6442 AS_UNSET([have_user_MBEDTLS_X509_CFLAGS]) 6443 AS_UNSET([have_user_MBEDTLS_X509_LIBS]) 6444 AS_UNSET([have_user_MBEDTLS_TLS_CFLAGS]) 6445 AS_UNSET([have_user_MBEDTLS_TLS_LIBS]) 6446 ] 6447 ) 6448 6449 AS_VAR_IF([have_mbedtls],["yes"],[:], 6450 [ 6451 have_mbedtls_pkgcfg="no" 6452 AS_CASE(["x${with_mbedtls}"], 6453 ["xyes"],[ 6454 MBEDTLS_FULL_CPPFLAGS="" 6455 MBEDTLS_FULL_LDFLAGS="" 6456 ], 6457 ["x"],[ 6458 MBEDTLS_FULL_CPPFLAGS="" 6459 MBEDTLS_FULL_LDFLAGS="" 6460 ], 6461 [ 6462 MBEDTLS_FULL_CPPFLAGS="-I$with_mbedtls/include" 6463 MBEDTLS_FULL_LDFLAGS="-L$with_mbedtls/lib" 6464 ] 6465 ) 6466 CPPFLAGS="${CPPFLAGS_ac} ${MBEDTLS_FULL_CPPFLAGS} ${user_CPPFLAGS}" 6467 LDFLAGS="${LDFLAGS_ac} ${MBEDTLS_FULL_LDFLAGS} ${user_LDFLAGS}" 6468 6469 MHD_FIND_LIB([mbedtls_md_init],[[#include <mbedtls/md.h>]], 6470 [[ 6471 /* These functions must be enabled i][f TLS is built */ 6472 mbedtls_md_context_t ctx; 6473 mbedtls_md_init (&ctx); 6474 mbedtls_md_free (&ctx); 6475 ]], 6476 [tfpsacrypto-4 tfpsacrypto mbedcrypto-3 mbedcrypto], 6477 [ 6478 AS_CASE([${MBEDTLS_CRYPTO_LIBS}], 6479 [*-4],[check_names_x509="mbedx509-4" 6480 check_names_tls="mbedtls-4"], 6481 [*-3],[check_names_x509="mbedx509-3" 6482 check_names_tls="mbedtls-3"], 6483 [*crypto],[check_names_x509="mbedx509" 6484 check_names_tls="mbedtls"], 6485 [check_names_x509="mbedx509-4 mbedx509-3 mbedx509" 6486 check_names_tls="mbedtls-4 mbedtls-3 mbedtls"] 6487 ) 6488 MHD_FIND_LIB([mbedtls_x509_crt_init],[[#include <mbedtls/x509_crt.h>]], 6489 [[ 6490 /* These functions must be enabled i][f TLS based on X509 certificates is built */ 6491 mbedtls_x509_crt crt; 6492 mbedtls_x509_crt_init(&crt); 6493 mbedtls_x509_crt_free(&crt); 6494 ]], 6495 [${check_names_x509}], 6496 [ 6497 AS_CASE([${MBEDTLS_X509_LIBS}], 6498 [*-4],[check_names_tls="mbedtls-4"], 6499 [*-3],[check_names_tls="mbedtls-3"], 6500 [*x509],[check_names_tls="mbedtls"] 6501 ) 6502 MHD_FIND_LIB([mbedtls_ssl_init],[[#include <mbedtls/ssl.h>]], 6503 [[ 6504 mbedtls_ssl_context ssl; 6505 mbedtls_ssl_init (&ssl); 6506 mbedtls_ssl_free (&ssl); 6507 ]], 6508 [${check_names_tls}], 6509 [ 6510 have_mbedtls="yes" 6511 MBEDTLS_FULL_LIBS="${MBEDTLS_TLS_LIBS} ${MBEDTLS_X509_LIBS} ${MBEDTLS_CRYPTO_LIBS}" 6512 MBEDTLS_CRYPTO_CPPFLAGS="${MBEDTLS_FULL_CPPFLAGS}" 6513 MBEDTLS_CRYPTO_LDFLAGS="${MBEDTLS_FULL_LDFLAGS}" 6514 MBEDTLS_X509_CPPFLAGS="${MBEDTLS_FULL_CPPFLAGS}" 6515 MBEDTLS_X509_LDFLAGS="${MBEDTLS_FULL_LDFLAGS}" 6516 MBEDTLS_TLS_CPPFLAGS="${MBEDTLS_FULL_CPPFLAGS}" 6517 MBEDTLS_TLS_LDFLAGS="${MBEDTLS_FULL_LDFLAGS}" 6518 ],[], 6519 [MBEDTLS_TLS_LIBS],[${MBEDTLS_X509_LIBS} ${MBEDTLS_CRYPTO_LIBS}] 6520 ) 6521 ],[], 6522 [MBEDTLS_X509_LIBS],[${MBEDTLS_CRYPTO_LIBS}] 6523 ) 6524 AS_UNSET([check_names_tls]) 6525 AS_UNSET([check_names_x509]) 6526 ],[], 6527 [MBEDTLS_CRYPTO_LIBS] 6528 ) 6529 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 6530 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 6531 ] 6532 ) 6533 ] 6534 ) 6535 6536 AS_VAR_IF([have_mbedtls],["yes"],[:], 6537 [ 6538 have_mbedtls="no" 6539 AS_CASE(["x$with_mbedtls"], 6540 ["xyes"],[AC_MSG_ERROR([connot find usable MbedTLS library])], 6541 ["x"],[with_mbedtls="no"], 6542 ["no"],[:] 6543 [AC_MSG_ERROR([cannot find usable MbedTLS library at specified prefix $with_mbedtls])] 6544 ) 6545 AS_UNSET([MBEDTLS_FULL_CPPFLAGS]) 6546 AS_UNSET([MBEDTLS_FULL_CFLAGS]) 6547 AS_UNSET([MBEDTLS_FULL_LDFLAGS]) 6548 AS_UNSET([MBEDTLS_FULL_LIBS]) 6549 AS_UNSET([MBEDTLS_CRYPTO_CPPFLAGS]) 6550 AS_UNSET([MBEDTLS_CRYPTO_CFLAGS]) 6551 AS_UNSET([MBEDTLS_CRYPTO_LDFLAGS]) 6552 AS_UNSET([MBEDTLS_CRYPTO_LIBS]) 6553 AS_UNSET([MBEDTLS_X509_CPPFLAGS]) 6554 AS_UNSET([MBEDTLS_X509_CFLAGS]) 6555 AS_UNSET([MBEDTLS_X509_LDFLAGS]) 6556 AS_UNSET([MBEDTLS_X509_LIBS]) 6557 AS_UNSET([MBEDTLS_TLS_CPPFLAGS]) 6558 AS_UNSET([MBEDTLS_TLS_CFLAGS]) 6559 AS_UNSET([MBEDTLS_TLS_LDFLAGS]) 6560 AS_UNSET([MBEDTLS_TLS_LIBS]) 6561 ] 6562 ) 6563 6564 AS_IF([test "x$have_gnutls" = "xyes" || test "x$have_openssl" = "xyes" || test "x$have_mbedtls" = "xyes"], 6565 [ 6566 enable_https="yes" 6567 multiple_tls="no" 6568 MSG_TLS_BACKENDS="" 6569 6570 AS_VAR_IF([have_gnutls],["yes"], 6571 [ 6572 AS_IF([test -n "${MSG_TLS_BACKENDS}"], 6573 [ 6574 MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}, " 6575 multiple_tls="yes" 6576 ] 6577 ) 6578 AC_DEFINE([MHD_SUPPORT_GNUTLS],[1],[Define to '1' i][f GnuTLS library should be used]) 6579 MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}GnuTLS" 6580 MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_CPPFLAGS],[$GNUTLS_CPPFLAGS]) 6581 MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_LDFLAGS],[$GNUTLS_LDFLAGS]) 6582 MHD_PREPEND_FLAG_TO_VAR([MHD_TLS_LIBDEPS],[$GNUTLS_LIBS]) 6583 ] 6584 ) 6585 AS_VAR_IF([have_openssl],["yes"], 6586 [ 6587 AS_IF([test -n "${MSG_TLS_BACKENDS}"], 6588 [ 6589 MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}, " 6590 multiple_tls="yes" 6591 ] 6592 ) 6593 AC_DEFINE([MHD_SUPPORT_OPENSSL],[1],[Define to '1' i][f OpenSSL library should be used]) 6594 MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}OpenSSL" 6595 MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_CPPFLAGS],[$OPENSSL_CPPFLAGS]) 6596 MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_LDFLAGS],[$OPENSSL_LDFLAGS]) 6597 MHD_PREPEND_FLAG_TO_VAR([MHD_TLS_LIBDEPS],[$OPENSSL_LIBS]) 6598 ] 6599 ) 6600 AS_VAR_IF([have_mbedtls],["yes"], 6601 [ 6602 AS_IF([test -n "${MSG_TLS_BACKENDS}"], 6603 [ 6604 MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}, " 6605 multiple_tls="yes" 6606 ] 6607 ) 6608 AC_DEFINE([MHD_SUPPORT_MBEDTLS],[1],[Define to '1' i][f MbedTLS library should be used]) 6609 MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}MbedTLS" 6610 MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_CPPFLAGS],[$MBEDTLS_FULL_CPPFLAGS]) 6611 MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_LDFLAGS],[$MBEDTLS_FULL_LDFLAGS]) 6612 MHD_PREPEND_FLAG_TO_VAR([MHD_TLS_LIBDEPS],[$MBEDTLS_FULL_LIBS]) 6613 ] 6614 ) 6615 AS_VAR_IF([multiple_tls],["yes"], 6616 [ 6617 MSG_HTTPS="yes (multiple backends)" 6618 AC_DEFINE([mhd_HAVE_SEVERAL_TLS_BACKENDS],[1],[Define to '1' if several TLS backend are linked]) 6619 ], 6620 [MSG_HTTPS="yes (single backend)"] 6621 ) 6622 AS_IF([test -z "$MSG_TLS_BACKENDS"],[AC_MSG_FAILURE([configure internal error: no TLS backends])]) 6623 AC_DEFINE([MHD_SUPPORT_HTTPS],[1],[Define to '1' i][f HTTPS protocol should be supported]) 6624 ], 6625 [ 6626 AS_VAR_IF([enable_https],["yes"], 6627 [AC_MSG_ERROR([no suitable TLS lib found, HTTPS cannot be enabled])] 6628 ) 6629 enable_https="no" 6630 MSG_HTTPS="no (no suitable TLS lib found)" 6631 MSG_TLS_BACKENDS="none" 6632 ] 6633 ) 6634 ], 6635 [ 6636 enable_https="no" 6637 MSG_HTTPS="no (disabled)" 6638 ] 6639 ) 6640 6641 AC_MSG_CHECKING(whether to support HTTPS) 6642 AS_VAR_IF([enable_https],["yes"], 6643 [ 6644 AS_CASE([$MSG_HTTPS],[yes*],[:], 6645 [AC_MSG_FAILURE([configure internal error: wrong MSG_HTTPS])] 6646 ) 6647 ], 6648 [ 6649 enable_https="no" 6650 MSG_TLS_BACKENDS="none" 6651 AS_UNSET([MHD_TLS_LIB_CPPFLAGS]) 6652 AS_UNSET([MHD_TLS_LIB_LDFLAGS]) 6653 AS_UNSET([MHD_TLS_LIBDEPS]) 6654 AS_CASE([$MSG_HTTPS],[no*],[:], 6655 [AC_MSG_FAILURE([configure internal error: wrong MSG_HTTPS])] 6656 ) 6657 ] 6658 ) 6659 AC_MSG_RESULT([$MSG_HTTPS]) 6660 6661 AM_CONDITIONAL([MHD_SUPPORT_GNUTLS], [[test "x$have_gnutls" = "xyes"]]) 6662 AC_SUBST([GNUTLS_CPPFLAGS]) 6663 AC_SUBST([GNUTLS_LDFLAGS]) 6664 AC_SUBST([GNUTLS_LIBS]) 6665 AM_CONDITIONAL([MHD_SUPPORT_OPENSSL], [[test "x$have_openssl" = "xyes"]]) 6666 AC_SUBST([OPENSSL_CPPFLAGS]) 6667 AC_SUBST([OPENSSL_LDFLAGS]) 6668 AC_SUBST([OPENSSL_LIBS]) 6669 AM_CONDITIONAL([MHD_SUPPORT_MBEDTLS], [[test "x$have_mbedtls" = "xyes"]]) 6670 AC_SUBST([MBEDTLS_CRYPTO_CPPFLAGS]) 6671 AC_SUBST([MBEDTLS_CRYPTO_LDFLAGS]) 6672 AC_SUBST([MBEDTLS_CRYPTO_LIBS]) 6673 AC_SUBST([MBEDTLS_FULL_CPPFLAGS]) 6674 AC_SUBST([MBEDTLS_FULL_LDFLAGS]) 6675 AC_SUBST([MBEDTLS_FULL_LIBS]) 6676 AM_CONDITIONAL([MHD_ENABLE_MULTITLS], [test "x$multiple_tls" = "xyes"]) 6677 AM_CONDITIONAL([MHD_SUPPORT_HTTPS], [test "x$enable_https" = "xyes"]) 6678 6679 AS_VAR_IF([have_gnutls], ["yes"], 6680 [ 6681 AC_CACHE_CHECK([for GnuTLS quirks], [mhd_cv_gnutls_mthread_broken], 6682 [ 6683 mhd_cv_gnutls_mthread_broken="no" 6684 AS_IF([test -r /etc/redhat-release], 6685 [ 6686 AS_IF([$FGREP ' release 6.' /etc/redhat-release >/dev/null || $FGREP '(Santiago)' /etc/redhat-release >/dev/null], 6687 [mhd_cv_gnutls_mthread_broken="found"], 6688 ) 6689 ] 6690 ) 6691 AS_VAR_IF([mhd_cv_gnutls_mthread_broken], ["no"], 6692 [ 6693 AS_IF([command -v rpm >/dev/null], 6694 [ 6695 AS_IF([test "r`rpm -E '%{rhel}' 2>/dev/null`" = "r6"], 6696 [mhd_cv_gnutls_mthread_broken="found"], 6697 ) 6698 ] 6699 ) 6700 ] 6701 ) 6702 ] 6703 ) 6704 AC_CACHE_CHECK([for gnutls-cli binary], [mhd_cv_gnutls_cli], 6705 [ 6706 mhd_cv_gnutls_cli="no" 6707 AS_IF([command -v gnutls-cli >/dev/null 2>&1], 6708 [AS_IF([AC_RUN_LOG([gnutls-cli --version >&2])], [mhd_cv_gnutls_cli="yes"])] 6709 ) 6710 ] 6711 ) 6712 ] 6713 ) 6714 AM_CONDITIONAL([HAVE_GNUTLS_MTHREAD_BROKEN], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xfound"]]) 6715 AM_CONDITIONAL([USE_UPGRADE_TLS_TESTS], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xno" || test "x${mhd_cv_gnutls_cli}" = "xyes"]]) 6716 6717 # optional: HTTP Basic Auth support. Enabled by default 6718 AC_MSG_CHECKING([[whether to support HTTP Basic authentication]]) 6719 AC_ARG_ENABLE([basic-auth], 6720 [AS_HELP_STRING([--disable-basic-auth],[disable HTTP Basic Authentication support])], 6721 [], 6722 [enable_basic_auth="yes"] 6723 ) 6724 AS_IF([[test "x$enable_basic_auth" != "xno"]], 6725 [ 6726 enable_basic_auth="yes" 6727 AC_DEFINE([MHD_SUPPORT_AUTH_BASIC],[1],[Define to '1' if libmicrohttpd should be compiled with Basic Auth support.]) 6728 ] 6729 ) 6730 AM_CONDITIONAL([MHD_SUPPORT_AUTH_BASIC], [test "x$enable_basic_auth" = "xyes"]) 6731 AC_MSG_RESULT([[$enable_basic_auth]]) 6732 6733 # optional: HTTP Digest Auth support. Enabled by default 6734 AC_MSG_CHECKING([[whether to support HTTP Digest authentication]]) 6735 AC_ARG_ENABLE([digest-auth], 6736 [AS_HELP_STRING([--disable-digest-auth], [disable HTTP Digest Authentication support])], 6737 [], 6738 [enable_digest_auth="yes"] 6739 ) 6740 AS_IF([[test "x$enable_digest_auth" != "xno"]], 6741 [ enable_digest_auth=yes 6742 AC_DEFINE([MHD_SUPPORT_AUTH_DIGEST],[1],[Define to 1 if libmicrohttpd is compiled with Digest Auth support.]) ]) 6743 AM_CONDITIONAL([MHD_SUPPORT_AUTH_DIGEST], [test "x$enable_digest_auth" != "xno"]) 6744 AC_MSG_RESULT([[$enable_digest_auth]]) 6745 6746 AS_VAR_IF([enable_digest_auth], ["yes"], 6747 [ 6748 AC_MSG_CHECKING([[for Digest Authentication default nonce timeout value]]) 6749 AC_ARG_ENABLE([digest-auth-def-timeout], 6750 [AS_HELP_STRING([--enable-digest-auth-def-timeout=NNN], 6751 [set default Digest Auth nonce validity time to NNN seconds])], 6752 [], 6753 [enable_digest_auth_def_timeout=""] 6754 ) 6755 AS_VAR_IF([enable_digest_auth_def_timeout], ["no"], 6756 [ 6757 AC_MSG_WARN([Default Diget Auth nonce validity time cannot be disabled, --disable-digest-auth-def-timeout parameter is ignored]) 6758 enable_digest_auth_def_timeout="" 6759 ] 6760 ) 6761 AS_IF([test -z "${enable_digest_auth_def_timeout}"], 6762 [ 6763 enable_digest_auth_def_timeout="90" 6764 enable_dauth_def_timeout_MSG="${enable_digest_auth_def_timeout} seconds (default)" 6765 ], 6766 [ 6767 AS_IF([[test "x${enable_digest_auth_def_timeout}" = "x`echo ${enable_digest_auth_def_timeout}|${SED-sed} 's/[^0-9]//g'`" && \ 6768 test "${enable_digest_auth_def_timeout}" -ge "0" 2>/dev/null ]],[:], 6769 [AC_MSG_ERROR([Invalid parameter --enable-digest-auth-def-timeout=${enable_digest_auth_def_timeout}. Timeout value must be a positive integer.]) 6770 ] 6771 ) 6772 AC_COMPILE_IFELSE( 6773 [ 6774 AC_LANG_PROGRAM([], 6775 [[ 6776 static int arr[((int) 2) - 4 * (int)(${enable_digest_auth_def_timeout} != ((unsigned int)${enable_digest_auth_def_timeout}))]; 6777 (void) arr; 6778 ]] 6779 ) 6780 ], 6781 [], 6782 [AC_MSG_ERROR([The value specified by --enable-digest-auth-def-timeout=${enable_digest_auth_def_timeout} is too large.])] 6783 ) 6784 enable_dauth_def_timeout_MSG="${enable_digest_auth_def_timeout} seconds (set by parameter)" 6785 ] 6786 ) 6787 AC_DEFINE_UNQUOTED([MHD_AUTH_DIGEST_DEF_TIMEOUT],[${enable_digest_auth_def_timeout}], 6788 [The default HTTP Digest Auth default nonce timeout value (in seconds)]) 6789 AC_MSG_RESULT([[${enable_dauth_def_timeout_MSG}]]) 6790 6791 AC_MSG_CHECKING([[for Digest Authentication default maximum nc value]]) 6792 AC_ARG_ENABLE([digest-auth-def-max-nc], 6793 [AS_HELP_STRING([--enable-digest-auth-def-max-nc=NNN], 6794 [set default Digest Auth maximum nc (nonce count) value to NNN])], 6795 [], 6796 [enable_digest_auth_def_max_nc=""] 6797 ) 6798 AS_VAR_IF([enable_digest_auth_def_max_nc], ["no"], 6799 [ 6800 AC_MSG_WARN([Default Diget Auth maximum nc cannot be disabled, --disable-digest-auth-def-max-nc parameter is ignored]) 6801 enable_digest_auth_def_max_nc="" 6802 ] 6803 ) 6804 AS_IF([test -z "${enable_digest_auth_def_max_nc}"], 6805 [ 6806 enable_digest_auth_def_max_nc="1000" 6807 enable_dauth_def_max_nc_MSG="${enable_digest_auth_def_max_nc} (default)" 6808 ], 6809 [ 6810 AS_IF([[test "x${enable_digest_auth_def_max_nc}" = "x`echo ${enable_digest_auth_def_max_nc}|${SED-sed} 's/[^0-9]//g'`" && \ 6811 test "${enable_digest_auth_def_max_nc}" -ge "0" 2>/dev/null ]],[:], 6812 [AC_MSG_ERROR([Invalid parameter --enable-digest-auth-def-max-nc=${enable_digest_auth_def_max_nc}. The value must be a positive integer.]) 6813 ] 6814 ) 6815 AC_COMPILE_IFELSE( 6816 [ 6817 AC_LANG_PROGRAM( 6818 [[ 6819 #include <stdint.h> 6820 ]], 6821 [[ 6822 static int arr[((int) 2) - 4 * (int)(${enable_digest_auth_def_max_nc} != ((uint_fast32_t)${enable_digest_auth_def_max_nc}))]; 6823 (void) arr; 6824 ]] 6825 ) 6826 ], 6827 [], 6828 [AC_MSG_ERROR([The value specified by --enable-digest-auth-def-max-nc=${enable_digest_auth_def_max_nc} is too large.])] 6829 ) 6830 enable_dauth_def_max_nc_MSG="${enable_digest_auth_def_max_nc} (set by parameter)" 6831 ] 6832 ) 6833 AC_DEFINE_UNQUOTED([MHD_AUTH_DIGEST_DEF_MAX_NC],[${enable_digest_auth_def_max_nc}], 6834 [The default HTTP Digest Auth default maximum nc (nonce count) value]) 6835 AC_MSG_RESULT([[${enable_dauth_def_max_nc_MSG}]]) 6836 6837 dauth_defs_MSG="timeout: ${enable_dauth_def_timeout_MSG}, max nc: ${enable_dauth_def_max_nc_MSG}" 6838 ], 6839 [ 6840 dauth_defs_MSG="N/A" 6841 ] 6842 ) 6843 6844 AM_CONDITIONAL([MHD_SUPPORT_AUTH],[test "x$enable_basic_auth" != "xno" || test "x$enable_digest_auth" != "xno"]) 6845 6846 # optional: HTTP "Upgrade" support. Enabled by default 6847 AC_MSG_CHECKING([[whether to support HTTP "Upgrade"]]) 6848 AC_ARG_ENABLE([[httpupgrade]], 6849 [AS_HELP_STRING([[--disable-httpupgrade]], [disable HTTP "Upgrade" support])], 6850 [AS_VAR_IF([[enable_httpupgrade]],[["no"]],[],[[enable_httpupgrade='yes']])], 6851 [[enable_httpupgrade='yes']]) 6852 AS_VAR_IF([[enable_httpupgrade]],[["yes"]], 6853 [ 6854 AC_DEFINE([[MHD_SUPPORT_UPGRADE]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP Upgrade support.]) ]) 6855 AM_CONDITIONAL([MHD_SUPPORT_UPGRADE], [[test "x$enable_httpupgrade" = "xyes"]]) 6856 AC_MSG_RESULT([[$enable_httpupgrade]]) 6857 6858 # optional: HTTP cookie parsing support. Enabled by default 6859 AC_MSG_CHECKING([[whether to support HTTP cookie parsing]]) 6860 AC_ARG_ENABLE([[cookie]], 6861 [AS_HELP_STRING([[--disable-cookie]], [disable HTTP cookie parser support])], 6862 [AS_VAR_IF([[enable_cookie]],[["no"]],[],[[enable_cookie='yes']])], 6863 [[enable_cookie='yes']]) 6864 AS_VAR_IF([[enable_cookie]],[["yes"]], 6865 [ 6866 AC_DEFINE([[MHD_SUPPORT_COOKIES]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP cookie parsing support.]) ]) 6867 AM_CONDITIONAL([MHD_SUPPORT_COOKIES], [[test "x$enable_cookie" = "xyes"]]) 6868 AC_MSG_RESULT([[$enable_cookie]]) 6869 6870 # optional: MD5 support for Digest Auth. Enabled by default. 6871 AC_ARG_ENABLE([[md5]], 6872 [AS_HELP_STRING([[--enable-md5=TYPE]], 6873 [enable TYPE of MD5 hashing code (yes, no, builtin, tlslib) [yes if dauth enabled]])], 6874 [ 6875 AS_VAR_IF([enable_md5],["internal"],[enable_md5='builtin']) 6876 AS_VAR_IF([enable_md5],["built-in"],[enable_md5='builtin']) 6877 AS_VAR_IF([enable_digest_auth],["yes"],[], 6878 [ 6879 AS_VAR_IF([enable_md5],["no"],[], 6880 [ 6881 AC_MSG_WARN([The parameter --enable-md5=${enable_md5} is ignored as Digest Authentication is disabled]) 6882 enable_md5='no' 6883 ] 6884 ) 6885 ] 6886 ) 6887 ], [[enable_md5="${enable_digest_auth}"]] 6888 ) 6889 AS_UNSET([have_md5_gnutls]) 6890 AS_UNSET([have_md5_openssl]) 6891 AS_UNSET([have_md5_mbedtls]) 6892 AS_CASE([${enable_md5}],[yes|tlslib], 6893 [ 6894 found_md5_tls="no" 6895 AS_IF([test "x$enable_https" = "xyes"], 6896 [ 6897 # Check GnuTLS 6898 AS_VAR_IF([have_gnutls],["yes"], 6899 [ 6900 AC_CACHE_CHECK([whether GnuTLS supports MD5 hashing],[mhd_cv_gnutls_md5], 6901 [ 6902 CPPFLAGS="${CPPFLAGS_ac} ${GNUTLS_CPPFLAGS} ${user_CPPFLAGS}" 6903 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 6904 LDFLAGS="${LDFLAGS_ac} ${GNUTLS_LDFLAGS} ${user_LDFLAGS}" 6905 save_LIBS="$LIBS" 6906 LIBS="${GNUTLS_LIBS} ${LIBS}" 6907 AC_LINK_IFELSE( 6908 [ 6909 AC_LANG_PROGRAM( 6910 [[ 6911 #include <gnutls/crypto.h> 6912 ]], 6913 [[ 6914 gnutls_hash_hd_t hash_handle; 6915 unsigned char digest[16]; 6916 int exit_code; 6917 6918 if (0 == gnutls_hash_init(&hash_handle, GNUTLS_DIG_MD5)) 6919 { 6920 if (0 == gnutls_hash(hash_handle, "", 1)) 6921 { 6922 gnutls_hash_output(hash_handle, digest); 6923 if (0x93 == digest[0]) 6924 exit_code = 0; 6925 else 6926 exit_code = 7; 6927 } 6928 else 6929 exit_code = 5; 6930 gnutls_hash_deinit(hash_handle, (void *)0); 6931 } 6932 else 6933 exit_code = 2; 6934 return exit_code; 6935 ]] 6936 ) 6937 ], 6938 [mhd_cv_gnutls_md5='yes'],[mhd_cv_gnutls_md5='no'] 6939 ) 6940 LIBS="${save_LIBS}" 6941 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 6942 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 6943 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 6944 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 6945 ] 6946 ) 6947 AS_VAR_IF([mhd_cv_gnutls_md5],["no"], 6948 [ 6949 AS_VAR_IF([enable_md5],["tlslib"], 6950 [AC_MSG_WARN([GnuTLS MD5 implementation is not available])] 6951 ) 6952 ], 6953 [ 6954 AC_DEFINE([[MHD_MD5_EXTR_GNUTLS]],[[1]], 6955 [Define to 1 if libmicrohttpd is compiled with MD5 hashing by GnuTLS.]) 6956 have_md5_gnutls="yes" 6957 found_md5_tls="yes" 6958 ] 6959 ) 6960 ] 6961 ) # end GnuTLS check 6962 6963 # Check OpenSSL 6964 AS_VAR_IF([have_openssl],["yes"], 6965 [ 6966 AC_CACHE_CHECK([whether OpenSSL supports MD5 hashing],[mhd_cv_openssl_md5], 6967 [ 6968 CPPFLAGS="${CPPFLAGS_ac} ${OPENSSL_CPPFLAGS} ${user_CPPFLAGS}" 6969 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 6970 LDFLAGS="${LDFLAGS_ac} ${OPENSSL_LDFLAGS} ${user_LDFLAGS}" 6971 save_LIBS="$LIBS" 6972 LIBS="${OPENSSL_LIBS} ${LIBS}" 6973 AC_LINK_IFELSE( 6974 [ 6975 AC_LANG_PROGRAM( 6976 [[ 6977 #include <openssl/evp.h> 6978 ]], 6979 [[ 6980 EVP_MD_CTX *ctx = EVP_MD_CTX_new(); 6981 unsigned char digest[16]; 6982 unsigned int len; 6983 if (ctx) { 6984 EVP_DigestInit_ex(ctx, EVP_md5(), NULL); 6985 EVP_DigestUpdate(ctx, "", 1); 6986 EVP_DigestFinal_ex(ctx, digest, &len); 6987 EVP_MD_CTX_free(ctx); 6988 } 6989 ]] 6990 ) 6991 ], 6992 [mhd_cv_openssl_md5='yes'],[mhd_cv_openssl_md5='no'] 6993 ) 6994 LIBS="${save_LIBS}" 6995 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 6996 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 6997 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 6998 ] 6999 ) 7000 AS_VAR_IF([mhd_cv_openssl_md5],["no"], 7001 [ 7002 AS_VAR_IF([enable_md5],["tlslib"], 7003 [AC_MSG_WARN([OpenSSL MD5 implementation is not available])] 7004 ) 7005 ], 7006 [ 7007 AC_DEFINE([[MHD_MD5_EXTR_OPENSSL]],[[1]], 7008 [Define to 1 if libmicrohttpd is compiled with MD5 hashing by OpenSSL.]) 7009 have_md5_openssl="yes" 7010 found_md5_tls="yes" 7011 ] 7012 ) 7013 ] 7014 ) 7015 7016 # Check MbedTLS 7017 AS_VAR_IF([have_mbedtls],["yes"], 7018 [ 7019 AC_CACHE_CHECK([whether MbedTLS supports MD5 hashing],[mhd_cv_mbedtls_md5], 7020 [ 7021 CPPFLAGS="${CPPFLAGS_ac} ${MBEDTLS_CRYPTO_CPPFLAGS} ${user_CPPFLAGS}" 7022 CFLAGS="${CFLAGS_ac} ${MBEDTLS_CRYPTO_CFLAGS} ${user_CFLAGS}" 7023 LDFLAGS="${LDFLAGS_ac} ${MBEDTLS_CRYPTO_LDFLAGS} ${user_LDFLAGS}" 7024 save_LIBS="$LIBS" 7025 LIBS="${MBEDTLS_CRYPTO_LIBS} ${LIBS}" 7026 AC_LINK_IFELSE( 7027 [ 7028 AC_LANG_PROGRAM( 7029 [[ 7030 #include <mbedtls/md5.h> 7031 ]], 7032 [[ 7033 mbedtls_md5_context ctx; 7034 unsigned char digest[16]; 7035 mbedtls_md5_init(&ctx); 7036 mbedtls_md5_starts(&ctx); 7037 mbedtls_md5_update(&ctx, (const unsigned char *)"", 1); 7038 mbedtls_md5_finish(&ctx, digest); 7039 mbedtls_md5_free(&ctx); 7040 ]] 7041 ) 7042 ], 7043 [mhd_cv_mbedtls_md5='yes'],[mhd_cv_mbedtls_md5='no'] 7044 ) 7045 LIBS="${save_LIBS}" 7046 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 7047 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7048 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 7049 ] 7050 ) 7051 AS_VAR_IF([mhd_cv_mbedtls_md5],["no"], 7052 [ 7053 AS_VAR_IF([enable_md5],["tlslib"], 7054 [AC_MSG_WARN([MbedTLS MD5 implementation is not available])] 7055 ) 7056 ], 7057 [ 7058 AC_DEFINE([[MHD_MD5_EXTR_MBEDTLS]],[[1]], 7059 [Define to 1 if libmicrohttpd is compiled with MD5 hashing by MbedTLS.]) 7060 have_md5_mbedtls="yes" 7061 found_md5_tls="yes" 7062 ] 7063 ) 7064 ] 7065 ) # end mbedtls check 7066 ] 7067 ) # end AS_IF (enable_https) 7068 7069 AS_IF([test "x$enable_md5" = "xyes"], 7070 [AS_VAR_IF([found_md5_tls],["yes"], 7071 [enable_md5="tlslib"], 7072 [ 7073 enable_md5="builtin" 7074 AS_UNSET([have_md5_gnutls]) 7075 AS_UNSET([have_md5_openssl]) 7076 AS_UNSET([have_md5_mbedtls]) 7077 ] 7078 )], 7079 [AS_VAR_IF([found_md5_tls],["yes"], 7080 [enable_md5="tlslib"], 7081 [AC_MSG_ERROR([TLS library support requested for MD5, but no library supports it])] 7082 )] 7083 ) 7084 ] 7085 ) # end "enable_md5 in yes|tlslib" 7086 7087 AC_MSG_CHECKING([[whether to support MD5]]) 7088 AS_UNSET([enable_md5_MSG]) 7089 AS_CASE([${enable_md5}], 7090 [builtin],[enable_md5_MSG='yes, built-in'], 7091 [tlslib],[enable_md5_MSG='yes, external (TLS library)'], 7092 [no],[enable_md5_MSG='no'], 7093 [yes],[AC_MSG_ERROR([configure internal error: unexpected variable value])], 7094 [AC_MSG_ERROR([Unrecognized parameter --enable-md5=${enable_md5}])] 7095 ) 7096 AS_IF([test "x${enable_md5}" = "xbuiltin" || test "x${enable_md5}" = "xtlslib" ], 7097 [ 7098 AC_DEFINE([[MHD_SUPPORT_MD5]],[[1]], 7099 [Define to 1 if libmicrohttpd is compiled with MD5 hashing support.]) 7100 ] 7101 ) 7102 AS_IF([test "x${enable_md5}" = "xtlslib" ], 7103 [ 7104 AC_DEFINE([[MHD_MD5_EXTR]],[[1]], 7105 [Define to 1 if libmicrohttpd is compiled with MD5 hashing by TLS library.]) 7106 ] 7107 ) 7108 AM_CONDITIONAL([MHD_SUPPORT_MD5], [[test "x${enable_md5}" = "xbuiltin" || test "x${enable_md5}" = "xtlslib" ]]) 7109 AM_CONDITIONAL([MHD_USE_MD5_INTR], [[test "X${enable_md5}" = "Xbuiltin"]]) 7110 AM_CONDITIONAL([MHD_USE_MD5_GNUTLS],[test "X${have_md5_gnutls}" = "Xyes"]) 7111 AM_CONDITIONAL([MHD_USE_MD5_OPENSSL],[test "X${have_md5_openssl}" = "Xyes"]) 7112 AM_CONDITIONAL([MHD_USE_MD5_MBEDTLS],[test "X${have_md5_mbedtls}" = "Xyes"]) 7113 AC_MSG_RESULT([[${enable_md5_MSG}]]) 7114 7115 # optional: SHA-256 support for Digest Auth. Enabled by default. 7116 AC_ARG_ENABLE([[sha256]], 7117 [AS_HELP_STRING([[--enable-sha256=TYPE]], 7118 [enable TYPE of SHA-256 hashing code (yes, no, builtin, tlslib) [yes if dauth enabled]])], 7119 [ 7120 AS_VAR_IF([enable_sha256],["internal"],[enable_sha256='builtin']) 7121 AS_VAR_IF([enable_sha256],["built-in"],[enable_sha256='builtin']) 7122 AS_VAR_IF([enable_digest_auth],["yes"],[], 7123 [ 7124 AS_VAR_IF([enable_sha256],["no"],[], 7125 [ 7126 AC_MSG_WARN([The parameter --enable-sha256=${enable_sha256} is ignored as Digest Authentication is disabled]) 7127 enable_sha256='no' 7128 ] 7129 ) 7130 ] 7131 ) 7132 ], [[enable_sha256="${enable_digest_auth}"]] 7133 ) 7134 7135 AS_UNSET([have_sha256_gnutls]) 7136 AS_UNSET([have_sha256_openssl]) 7137 AS_UNSET([have_sha256_mbedtls]) 7138 # SHA-256 external vs. internal check 7139 AS_CASE([${enable_sha256}],[yes|tlslib], 7140 [ 7141 found_sha256_tls="no" 7142 AS_IF([test "x$enable_https" = "xyes"], 7143 [ 7144 # Check GnuTLS 7145 AS_VAR_IF([have_gnutls],["yes"], 7146 [ 7147 AC_CACHE_CHECK([whether GnuTLS supports sha256 hashing],[mhd_cv_gnutls_sha256], 7148 [ 7149 CPPFLAGS="${CPPFLAGS_ac} ${GNUTLS_LIB_CPPFLAGS} ${user_CPPFLAGS}" 7150 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7151 LDFLAGS="${LDFLAGS_ac} ${GNUTLS_LDFLAGS} ${user_LDFLAGS}" 7152 save_LIBS="$LIBS" 7153 LIBS="${GNUTLS_LIBS} ${LIBS}" 7154 AC_LINK_IFELSE( 7155 [ 7156 AC_LANG_PROGRAM( 7157 [[ 7158 #include <gnutls/crypto.h> 7159 ]], 7160 [[ 7161 gnutls_hash_hd_t hash_handle; 7162 unsigned char digest[32]; 7163 int exit_code; 7164 7165 if (0 == gnutls_hash_init(&hash_handle, GNUTLS_DIG_SHA256)) 7166 { 7167 if (0 == gnutls_hash(hash_handle, "", 1)) 7168 { 7169 gnutls_hash_output(hash_handle, digest); 7170 if (0x6e == digest[0]) 7171 exit_code = 0; 7172 else 7173 exit_code = 7; 7174 } 7175 else 7176 exit_code = 5; 7177 gnutls_hash_deinit(hash_handle, (void *)0); 7178 } 7179 else 7180 exit_code = 2; 7181 return exit_code; 7182 ]] 7183 ) 7184 ], 7185 [mhd_cv_gnutls_sha256='yes'],[mhd_cv_gnutls_sha256='no'] 7186 ) 7187 LIBS="${save_LIBS}" 7188 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7189 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 7190 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7191 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 7192 ] 7193 ) 7194 AS_VAR_IF([mhd_cv_gnutls_sha256],["no"], 7195 [ 7196 AS_VAR_IF([enable_sha256],["tlslib"], 7197 [AC_MSG_WARN([GnuTLS SHA-256 implementation is not available])] 7198 ) 7199 ], 7200 [ 7201 AC_DEFINE([[MHD_SHA256_EXTR_GNUTLS]],[[1]], 7202 [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing by GnuTLS.]) 7203 have_sha256_gnutls="yes" 7204 found_sha256_tls="yes" 7205 ] 7206 ) 7207 ] 7208 ) # end check GnuTLS 7209 7210 # Check OpenSSL 7211 AS_VAR_IF([have_openssl],["yes"], 7212 [ 7213 AC_CACHE_CHECK([whether OpenSSL supports SHA-256 hashing],[mhd_cv_openssl_sha256], 7214 [ 7215 CPPFLAGS="${CPPFLAGS_ac} ${OPENSSL_CPPFLAGS} ${user_CPPFLAGS}" 7216 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7217 LDFLAGS="${LDFLAGS_ac} ${OPENSSL_LDFLAGS} ${user_LDFLAGS}" 7218 save_LIBS="$LIBS" 7219 LIBS="${OPENSSL_LIBS} ${LIBS}" 7220 AC_LINK_IFELSE( 7221 [ 7222 AC_LANG_PROGRAM( 7223 [[ 7224 #include <openssl/evp.h> 7225 ]], 7226 [[ 7227 EVP_MD_CTX *ctx = EVP_MD_CTX_new(); 7228 unsigned char digest[32]; 7229 unsigned int len; 7230 if (ctx) { 7231 EVP_DigestInit_ex(ctx, EVP_sha256(), NULL); 7232 EVP_DigestUpdate(ctx, "", 1); 7233 EVP_DigestFinal_ex(ctx, digest, &len); 7234 EVP_MD_CTX_free(ctx); 7235 } 7236 ]] 7237 ) 7238 ], 7239 [mhd_cv_openssl_sha256='yes'],[mhd_cv_openssl_sha256='no'] 7240 ) 7241 LIBS="${save_LIBS}" 7242 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 7243 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7244 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 7245 ] 7246 ) 7247 AS_VAR_IF([mhd_cv_openssl_sha256],["no"], 7248 [ 7249 AS_VAR_IF([enable_sha256],["tlslib"], 7250 [AC_MSG_WARN([OpenSSL SHA-256 implementation is not available])] 7251 ) 7252 ], 7253 [ 7254 AC_DEFINE([[MHD_SHA256_EXTR_OPENSSL]],[[1]], 7255 [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing by OpenSSL.]) 7256 have_sha256_openssl="yes" 7257 found_sha256_tls="yes" 7258 ] 7259 ) 7260 ] 7261 ) # end check OpenSSL 7262 7263 # Check MbedTLS 7264 AS_VAR_IF([have_mbedtls],["yes"], 7265 [ 7266 AC_CACHE_CHECK([whether MbedTLS supports SHA256 hashing],[mhd_cv_mbedtls_sha256], 7267 [ 7268 CPPFLAGS="${CPPFLAGS_ac} ${MBEDTLS_CRYPTO_CPPFLAGS} ${user_CPPFLAGS}" 7269 CFLAGS="${CFLAGS_ac} ${MBEDTLS_CRYPTO_CFLAGS} ${user_CFLAGS}" 7270 LDFLAGS="${LDFLAGS_ac} ${MBEDTLS_CRYPTO_LDFLAGS} ${user_LDFLAGS}" 7271 save_LIBS="$LIBS" 7272 LIBS="${MBEDTLS_CRYPTO_LIBS} ${LIBS}" 7273 AC_LINK_IFELSE( 7274 [ 7275 AC_LANG_PROGRAM( 7276 [[ 7277 #include <mbedtls/sha256.h> 7278 ]], 7279 [[ 7280 mbedtls_sha256_context ctx; 7281 unsigned char digest[16]; 7282 mbedtls_sha256_init(&ctx); 7283 mbedtls_sha256_starts(&ctx, 0); 7284 mbedtls_sha256_update(&ctx, (const unsigned char *)"", 1); 7285 mbedtls_sha256_finish(&ctx, digest); 7286 mbedtls_sha256_free(&ctx); 7287 ]] 7288 ) 7289 ], 7290 [mhd_cv_mbedtls_sha256='yes'],[mhd_cv_mbedtls_sha256='no'] 7291 ) 7292 LIBS="${save_LIBS}" 7293 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 7294 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7295 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 7296 ] 7297 ) 7298 AS_VAR_IF([mhd_cv_mbedtls_sha256],["no"], 7299 [ 7300 AS_VAR_IF([enable_sha256],["tlslib"], 7301 [AC_MSG_WARN([MbedTLS SHA256 implementation is not available])] 7302 ) 7303 ], 7304 [ 7305 AC_DEFINE([[MHD_SHA256_EXTR_MBEDTLS]],[[1]], 7306 [Define to 1 if libmicrohttpd is compiled with SHA256 hashing by MbedTLS.]) 7307 have_sha256_mbedtls="yes" 7308 found_sha256_tls="yes" 7309 ] 7310 ) 7311 ] 7312 ) # end mbedtls check 7313 ] 7314 ) # end AS_IF (enable_https) 7315 7316 AS_IF([test "x$enable_sha256" = "xyes"], 7317 [AS_VAR_IF([found_sha256_tls],["yes"], 7318 [enable_sha256="tlslib"], 7319 [ 7320 enable_sha256="builtin" 7321 AS_UNSET([have_sha256_gnutls]) 7322 AS_UNSET([have_sha256_openssl]) 7323 AS_UNSET([have_sha256_mbedtls]) 7324 ] 7325 )], 7326 [AS_VAR_IF([found_sha256_tls],["yes"], 7327 [enable_sha256="tlslib"], 7328 [AC_MSG_ERROR([TLS library support requested for SHA256, but no library supports it])] 7329 )] 7330 ) 7331 ] 7332 ) 7333 AC_MSG_CHECKING([[whether to support SHA-256]]) 7334 AS_UNSET([enable_sha256_MSG]) 7335 AS_CASE([${enable_sha256}], 7336 [builtin],[enable_sha256_MSG='yes, built-in'], 7337 [tlslib],[enable_sha256_MSG='yes, external (TLS library)'], 7338 [no],[enable_sha256_MSG='no'], 7339 [yes],[AC_MSG_ERROR([configure internal error: unexpected variable value])], 7340 [AC_MSG_ERROR([Unrecognized parameter --enable-sha256=${enable_sha256}])] 7341 ) 7342 AS_IF([test "x${enable_sha256}" = "xbuiltin" || 7343 test "x${enable_sha256}" = "xtlslib" ], 7344 [ 7345 AC_DEFINE([[MHD_SUPPORT_SHA256]],[[1]], 7346 [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing support.]) 7347 ] 7348 ) 7349 AS_IF([test "x${enable_sha256}" = "xtlslib" ], 7350 [ 7351 AC_DEFINE([[MHD_SHA256_EXTR]],[[1]], 7352 [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing by TLS library.]) 7353 ] 7354 ) 7355 AM_CONDITIONAL([MHD_SUPPORT_SHA256], [[test "x${enable_sha256}" = "xbuiltin" || test "x${enable_sha256}" = "xtlslib" ]]) 7356 AM_CONDITIONAL([MHD_USE_SHA256_INTR], [[test "X${enable_sha256}" = "Xbuiltin"]]) 7357 AM_CONDITIONAL([MHD_USE_SHA256_GNUTLS], [[test "X${have_sha256_gnutls}" = "Xyes"]]) 7358 AM_CONDITIONAL([MHD_USE_SHA256_OPENSSL], [[test "X${have_sha256_openssl}" = "Xyes"]]) 7359 AM_CONDITIONAL([MHD_USE_SHA256_MBEDTLS], [[test "X${have_sha256_mbedtls}" = "Xyes"]]) 7360 AC_MSG_RESULT([[${enable_sha256_MSG}]]) 7361 7362 # optional: SHA-512/256 support for Digest Auth. Enabled by default. 7363 AC_ARG_ENABLE([[sha512-256]], 7364 [AS_HELP_STRING([[--enable-sha512-256=TYPE]], 7365 [enable TYPE of SHA-512/256 hashing code (yes, no, builtin, tlslib) [yes if dauth enabled]])], 7366 [ 7367 AS_VAR_IF([enable_sha512_256],["internal"],[enable_sha512_256='builtin']) 7368 AS_VAR_IF([enable_sha512_256],["built-in"],[enable_sha512_256='builtin']) 7369 AS_VAR_IF([enable_digest_auth],["yes"],[], 7370 [ 7371 AS_VAR_IF([enable_sha512_256],["no"],[], 7372 [ 7373 AC_MSG_WARN([The parameter --enable-sha512x256=${enable_sha512x256} is ignored as Digest Authentication is disabled]) 7374 enable_sha512_256='no' 7375 ] 7376 ) 7377 ] 7378 ) 7379 ], [[enable_sha512_256="${enable_digest_auth}"]] 7380 ) 7381 7382 AS_UNSET([have_sha512_256_openssl]) 7383 AS_UNSET([have_sha512_256_mbedtls]) 7384 # SHA-512/256 external vs internal check 7385 AS_CASE([${enable_sha512_256}],[yes|tlslib], 7386 [ 7387 found_sha512_256_tls="no" 7388 AS_IF([test "x$enable_https" = "xyes"], 7389 [ 7390 # Check OpenSSL 7391 AS_VAR_IF([have_openssl],["yes"], 7392 [ 7393 AC_CACHE_CHECK([whether OpenSSL supports SHA-512/256 hashing],[mhd_cv_openssl_sha512_256], 7394 [ 7395 CPPFLAGS="${CPPFLAGS_ac} ${OPENSSL_CPPFLAGS} ${user_CPPFLAGS}" 7396 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7397 LDFLAGS="${LDFLAGS_ac} ${OPENSSL_LDFLAGS} ${user_LDFLAGS}" 7398 save_LIBS="$LIBS" 7399 LIBS="${OPENSSL_LIBS} ${LIBS}" 7400 AC_LINK_IFELSE( 7401 [ 7402 AC_LANG_PROGRAM( 7403 [[ 7404 #include <openssl/evp.h> 7405 ]], 7406 [[ 7407 EVP_MD_CTX *ctx = EVP_MD_CTX_new(); 7408 unsigned char digest[32]; 7409 unsigned int len; 7410 if (ctx) { 7411 EVP_DigestInit_ex(ctx, EVP_sha512_256(), NULL); 7412 EVP_DigestUpdate(ctx, "", 1); 7413 EVP_DigestFinal_ex(ctx, digest, &len); 7414 EVP_MD_CTX_free(ctx); 7415 } 7416 ]] 7417 ) 7418 ], 7419 [mhd_cv_openssl_sha512_256='yes'],[mhd_cv_openssl_sha512_256='no'] 7420 ) 7421 LIBS="${save_LIBS}" 7422 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 7423 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7424 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 7425 ] 7426 ) 7427 AS_VAR_IF([mhd_cv_openssl_sha512_256],["yes"], 7428 [ 7429 AC_DEFINE([[MHD_SHA512_256_EXTR_OPENSSL]],[[1]], 7430 [Define to 1 if libmicrohttpd is compiled with SHA-512/256 hashing by OpenSSL.]) 7431 have_sha512_256_openssl="yes" 7432 found_sha512_256_tls="yes" 7433 ] 7434 ) 7435 ] 7436 ) 7437 # Check mbedTLS - test for SHA-512 support (C code uses SHA-512 implementation) 7438 AS_VAR_IF([have_mbedtls],["yes"], 7439 [ 7440 AC_CACHE_CHECK([whether mbedTLS supports SHA-512 hashing for SHA-512/256],[mhd_cv_mbedtls_sha512], 7441 [ 7442 CPPFLAGS="${CPPFLAGS_ac} ${MBEDTLS_CPPFLAGS} ${user_CPPFLAGS}" 7443 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7444 LDFLAGS="${LDFLAGS_ac} ${MBEDTLS_LDFLAGS} ${user_LDFLAGS}" 7445 save_LIBS="$LIBS" 7446 LIBS="${MBEDTLS_LIBS} ${LIBS} -lmbedcrypto" 7447 AC_LINK_IFELSE( 7448 [ 7449 AC_LANG_PROGRAM( 7450 [[ 7451 #include <mbedtls/sha512.h> 7452 ]], 7453 [[ 7454 mbedtls_sha512_context ctx; 7455 unsigned char digest[64]; 7456 mbedtls_sha512_init(&ctx); 7457 mbedtls_sha512_starts(&ctx, 0); 7458 mbedtls_sha512_update(&ctx, (const unsigned char *)"", 1); 7459 mbedtls_sha512_finish(&ctx, digest); 7460 mbedtls_sha512_free(&ctx); 7461 ]] 7462 ) 7463 ], 7464 [mhd_cv_mbedtls_sha512='yes'],[mhd_cv_mbedtls_sha512='no'] 7465 ) 7466 LIBS="${save_LIBS}" 7467 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 7468 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 7469 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 7470 ] 7471 ) 7472 AS_VAR_IF([mhd_cv_mbedtls_sha512],["yes"], 7473 [ 7474 AC_DEFINE([[MHD_SHA512_EXTR_MBEDTLS]],[[1]], 7475 [Define to 1 if libmicrohttpd is compiled with SHA-512 hashing by mbedTLS.]) 7476 have_sha512_256_mbedtls="yes" 7477 found_sha512_256_tls="yes" 7478 ] 7479 ) 7480 ] 7481 ) 7482 ] 7483 ) # end AS_IF (enable_https) 7484 7485 AS_IF([test "x$enable_sha512_256" = "xyes"], 7486 [AS_VAR_IF([found_sha512_256_tls],["yes"], 7487 [enable_sha512_256="tlslib"], 7488 [ 7489 enable_sha512_256="builtin" 7490 AS_UNSET([have_sha512_256_openssl]) 7491 AS_UNSET([have_sha512_256_mbedtls]) 7492 ] 7493 )], 7494 [AS_VAR_IF([found_sha512_256_tls],["yes"], 7495 [enable_sha256="tlslib"], 7496 [AC_MSG_ERROR([TLS library support requested for SHA512/256, but no library supports it])] 7497 )] 7498 ) 7499 ] 7500 ) 7501 7502 7503 AC_MSG_CHECKING([[whether to support SHA-512/256]]) 7504 AS_UNSET([enable_sha512_256_MSG]) 7505 AS_CASE([${enable_sha512_256}], 7506 [builtin],[enable_sha512_256_MSG='yes, built-in'], 7507 [tlslib],[enable_sha512_256_MSG='yes, external (TLS library)'], 7508 [yes],[AC_MSG_ERROR([configure internal error: unexpected variable value])], 7509 [no],[enable_sha512_256_MSG='no'], 7510 [AC_MSG_ERROR([Unrecognized parameter --enable-sha512-256=${enable_sha512_256}])] 7511 ) 7512 7513 AS_IF([test "x${enable_sha512_256}" = "xbuiltin" || 7514 test "x${enable_sha512_256}" = "xtlslib" ], 7515 [ 7516 AC_DEFINE([[MHD_SUPPORT_SHA512_256]],[[1]], 7517 [Define to 1 if libmicrohttpd is compiled with SHA-512/256 hashing support.]) 7518 ] 7519 ) 7520 7521 AS_IF([test "x${enable_sha512_256}" = "xtlslib" ], 7522 [ 7523 AC_DEFINE([[MHD_SHA512_256_EXTR]],[[1]], 7524 [Define to 1 if libmicrohttpd is compiled with SHA-512/256 hashing by TLS library.]) 7525 ] 7526 ) 7527 AM_CONDITIONAL([MHD_SUPPORT_SHA512_256], [[test "x${enable_sha512_256}" = "xbuiltin" || test "x${enable_sha512_256}" = "xtlslib"]]) 7528 AM_CONDITIONAL([MHD_USE_SHA512_256_INTR], [[test "X${enable_sha512_256}" = "Xbuiltin"]]) 7529 AM_CONDITIONAL([MHD_USE_SHA512_256_OPENSSL], [[test "X${have_sha512_256_openssl}" = "Xyes"]]) 7530 AM_CONDITIONAL([MHD_USE_SHA512_256_MBEDTLS], [[test "X${have_sha512_256_mbedtls}" = "Xyes"]]) 7531 7532 7533 AC_MSG_RESULT([[${enable_sha512_256_MSG}]]) 7534 7535 7536 # Check if digest auth can be enabled, requires at least one hash algo 7537 AS_IF([test "x$enable_digest_auth" != "xno"], 7538 [ 7539 AS_IF([test "x${enable_md5}" = "xno" && test "x${enable_sha256}" = "xno" && test "x${enable_sha512_256}" != "xyes"], 7540 [AC_MSG_ERROR([At least one hashing algorithm must be enabled if Digest Auth is enabled])] 7541 ) 7542 ] 7543 ) 7544 7545 7546 AC_CACHE_CHECK([[for calloc()]], [[mhd_cv_have_func_calloc]], 7547 [ 7548 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 7549 #ifdef HAVE_STDLIB_H 7550 #include <stdlib.h> 7551 #elif defined(HAVE_MALLOC_H) 7552 #include <malloc.h> 7553 #else 7554 #include <unistd.h> 7555 #endif 7556 ]],[[void * ptr = calloc(1, 2); if (ptr) return 1;]]) 7557 ], 7558 [[mhd_cv_have_func_calloc='yes']], 7559 [[mhd_cv_have_func_calloc='no']] 7560 ) 7561 ] 7562 ) 7563 AS_VAR_IF([[mhd_cv_have_func_calloc]], [["yes"]], 7564 [AC_DEFINE([[HAVE_CALLOC]], [[1]], [Define to 1 if you have the usable `calloc' function.])]) 7565 AM_CONDITIONAL([HAVE_SYS_CALLOC], [[test "x${mhd_cv_have_func_calloc}" = "xyes"]]) 7566 7567 # Some systems have IPv6 disabled in kernel at run-time 7568 AS_IF([[test "x${mhd_cv_have_inet6}" = "xyes" && test "x${cross_compiling}" = "xno"]], 7569 [ 7570 AC_CACHE_CHECK([whether IPv6 could be used for testing],[mhd_cv_ipv6_for_testing], 7571 [ 7572 AC_RUN_IFELSE( 7573 [ 7574 AC_LANG_SOURCE([[ 7575 #ifdef HAVE_UNISTD_H 7576 #include <unistd.h> 7577 #endif 7578 #ifdef HAVE_SYS_TYPES_H 7579 #include <sys/types.h> 7580 #endif 7581 #ifdef HAVE_SYS_SOCKET_H 7582 #include <sys/socket.h> 7583 #endif 7584 #ifdef HAVE_WINSOCK2_H 7585 #include <winsock2.h> 7586 #endif 7587 #ifdef HAVE_WS2TCPIP_H 7588 #include <ws2tcpip.h> 7589 #endif 7590 #ifdef HAVE_NETINET_IN_H 7591 #include <netinet/in.h> 7592 #endif 7593 #ifdef HAVE_NETINET_IP_H 7594 #include <netinet/ip.h> 7595 #endif 7596 #ifdef HAVE_ARPA_INET_H 7597 #include <arpa/inet.h> 7598 #endif 7599 #ifdef HAVE_NETINET_TCP_H 7600 #include <netinet/tcp.h> 7601 #endif 7602 7603 static void zr_mem(void *ptr, socklen_t size) 7604 { char *mem = ptr; while(size--) {mem[0] = 0; mem++;} } 7605 7606 int main(void) 7607 { 7608 int ret = 30; 7609 struct sockaddr_in6 sa; 7610 #if !defined(_WIN32) || defined(__CYGWIN__) 7611 int sckt; 7612 const int invld_sckt = -1; 7613 #else 7614 SOCKET sckt; 7615 const SOCKET invld_sckt = INVALID_SOCKET; 7616 WSADATA wsa_data; 7617 7618 WSAStartup(MAKEWORD(2, 2), &wsa_data); 7619 #endif 7620 zr_mem(&sa, sizeof(sa)); 7621 sa.sin6_family = AF_INET6; 7622 sa.sin6_port = 0; 7623 sa.sin6_addr = in6addr_loopback; 7624 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN 7625 sa.sin6_len = sizeof(sa); 7626 #endif 7627 sckt = socket (PF_INET6, SOCK_STREAM, 0); 7628 if (invld_sckt != sckt) 7629 { 7630 if (0 == bind (sckt, (struct sockaddr *)&sa, sizeof(sa))) 7631 { 7632 if (0 == listen (sckt, 1)) 7633 ret = 0; 7634 else 7635 ret = 1; /* listen() failed */ 7636 } else ret = 2; /* bind() failed */ 7637 #if !defined(_WIN32) || defined(__CYGWIN__) 7638 close (sckt); 7639 #else 7640 closesocket (sckt); 7641 #endif 7642 } else ret = 3; /* socket() failed */ 7643 #if defined(_WIN32) && !defined(__CYGWIN__) 7644 WSACleanup(); 7645 #endif 7646 return ret; 7647 } 7648 ]]) 7649 ], [[mhd_cv_ipv6_for_testing="yes"]], [[mhd_cv_ipv6_for_testing="no"]], [[mhd_cv_ipv6_for_testing="no"]] 7650 ) 7651 ] 7652 ) 7653 ] 7654 ) 7655 AS_VAR_IF([mhd_cv_ipv6_for_testing],["yes"], 7656 [AC_DEFINE([[USE_IPV6_TESTING]], [[1]], [Define to 1 if your kernel supports IPv6 and IPv6 is enabled and useful for testing.])] 7657 ) 7658 AM_CONDITIONAL([USE_IPV6_TESTING], [[test "x$mhd_cv_ipv6_for_testing" = "xyes"]]) 7659 7660 7661 AS_VAR_IF([enable_tools],["yes"], 7662 [ 7663 AC_CHECK_HEADERS([features.h sys/pstat.h vxCpuLib.h],[],[],[AC_INCLUDES_DEFAULT]) 7664 MHD_CHECK_DECLS([_SC_NPROCESSORS_ONLN _SC_NPROC_ONLN _SC_CRAY_NCPU _SC_NPROCESSORS_CONF \ 7665 CTL_HW HW_NCPUONLINE HW_NCPU HW_AVAILCPU], 7666 [[ 7667 #ifdef HAVE_SYS_TYPES_H 7668 #include <sys/types.h> 7669 #endif /* HAVE_SYS_TYPES_H */ 7670 #ifdef HAVE_SYS_PARAM_H 7671 #include <sys/param.h> 7672 #endif /* HAVE_SYS_PARAM_H */ 7673 #ifdef HAVE_SYS_SYSCTL_H 7674 #include <sys/sysctl.h> 7675 #endif /* HAVE_SYS_SYSCTL_H */ 7676 #ifdef HAVE_UNISTD_H 7677 #include <unistd.h> 7678 #endif /* HAVE_UNISTD_H */ 7679 ]] 7680 ) 7681 MHD_CHECK_FUNC([pstat_getdynamic],[[ 7682 #include <sys/param.h> 7683 #include <sys/pstat.h> 7684 ]], 7685 [[ 7686 struct pst_dynamic psd_data; 7687 i][f (1 != pstat_getdynamic(&psd_data, sizeof(psd_data), (size_t)1, 0)) 7688 return 2; 7689 i][f (0 >= psd_data.psd_proc_cnt) 7690 return 3; 7691 ]] 7692 ) 7693 MHD_CHECK_FUNC([vxCpuEnabledGet],[[#include <vxCpuLib.h>]], 7694 [[ 7695 cpuset_t enb_set; 7696 enb_set = vxCpuEnabledGet(); 7697 (void) enb_set; 7698 ]] 7699 ) 7700 AC_CHECK_HEADERS([sched.h sys/_cpuset.h sys/cpuset.h],[],[],[AC_INCLUDES_DEFAULT]) 7701 # glibc / Linux kernel 7702 MHD_CHECK_FUNC([getpid],[[ 7703 #ifdef HAVE_SYS_TYPES_H 7704 #include <sys/types.h> 7705 #endif /* HAVE_SYS_TYPES_H */ 7706 #include <unistd.h> 7707 ]], 7708 [[ 7709 pid_t cur_pid; 7710 cur_pid = getpid(); 7711 (void) &cur_pid; /* Mute possible warning */ 7712 ]], 7713 [ 7714 MHD_CHECK_FUNC([sched_getaffinity],[[ 7715 #ifdef HAVE_SYS_TYPES_H 7716 #include <sys/types.h> 7717 #endif /* HAVE_SYS_TYPES_H */ 7718 #include <unistd.h> 7719 #include <sched.h> 7720 ]], 7721 [[ 7722 cpu_set_t cur_set; 7723 i][f (0 != sched_getaffinity(getpid(), sizeof(cur_set), &cur_set)) 7724 return 2; 7725 i][f (0 == CPU_SET (0, &cur_set)) 7726 return 3; /* Actually this could be a valid result */ 7727 ]], 7728 [ 7729 MHD_CHECK_FUNC([CPU_COUNT],[[ 7730 #include <stddef.h> 7731 #include <sched.h> 7732 ]], 7733 [[ 7734 cpu_set_t cur_set; 7735 CPU_ZERO(&cur_set); 7736 i][f (0 != CPU_COUNT(&cur_set)) 7737 return 2; 7738 ]], 7739 [ 7740 MHD_CHECK_FUNC([CPU_COUNT_S],[[ 7741 #include <stddef.h> 7742 #include <sched.h> 7743 ]], 7744 [[ 7745 static const unsigned int set_size_cpus = 2048u; 7746 const size_t set_size_bytes = (size_t) CPU_ALLOC_SIZE(set_size_cpus); 7747 cpu_set_t *p_set; 7748 p_set = CPU_ALLOC(set_size_cpus); 7749 i][f (!p_set) 7750 return 2; 7751 CPU_ZERO_S(set_size_bytes, p_set); 7752 i][f (0 != CPU_COUNT_S(set_size_bytes, p_set)) 7753 { 7754 CPU_FREE(p_set); 7755 return 3; 7756 } 7757 CPU_FREE(p_set); 7758 ]], 7759 [MHD_CHECK_DECLS([CPU_SETSIZE],[],[],[#include <sched.h>])] 7760 ) 7761 ] 7762 ) 7763 ] 7764 ) 7765 # NetBSD 7766 # Should work only with -lrt, but actually works without it. 7767 MHD_CHECK_FUNC([sched_getaffinity_np],[[ 7768 #ifdef HAVE_SYS_TYPES_H 7769 #include <sys/types.h> 7770 #endif /* HAVE_SYS_TYPES_H */ 7771 #include <unistd.h> 7772 #include <sched.h> 7773 ]], 7774 [[ 7775 cpuset_t *cpuset_ptr; 7776 cpuid_t cpu_num = 0; 7777 cpuset_ptr = cpuset_create(); 7778 i][f (!cpuset_ptr) 7779 return 2; 7780 i][f (0 != sched_getaffinity_np(getpid(), cpuset_size(cpuset_ptr), cpuset_ptr)) 7781 { 7782 cpuset_destroy(cpuset_ptr); 7783 return 3; 7784 } 7785 i][f (0 >= cpuset_isset(cpu_num, cpuset_ptr)) 7786 { 7787 cpuset_destroy(cpuset_ptr); 7788 return 4; /* Actually this could be a valid result */ 7789 } 7790 cpuset_destroy(cpuset_ptr); 7791 ]] 7792 ) 7793 ] 7794 ) 7795 # FreeBSD 7796 MHD_CHECK_FUNC([cpuset_getaffinity],[[ 7797 #ifdef HAVE_SYS_PARAM_H 7798 #include <sys/param.h> 7799 #endif /* HAVE_SYS_PARAM_H */ 7800 #include <sys/cpuset.h> 7801 ]], 7802 [[ 7803 cpuset_t cur_mask; 7804 i][f (0 != cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1, sizeof(cur_mask), &cur_mask)) 7805 return 2; 7806 ]], 7807 [ 7808 MHD_CHECK_FUNC([CPU_COUNT],[[ 7809 #ifdef HAVE_SYS_PARAM_H 7810 #include <sys/param.h> 7811 #endif /* HAVE_SYS_PARAM_H */ 7812 #ifdef HAVE_SYS__CPUSET_H 7813 #include <sys/_cpuset.h> 7814 #endif /* HAVE_SYS_PARAM_H */ 7815 #include <sys/cpuset.h> 7816 ]], 7817 [[ 7818 cpuset_t test_mask; 7819 CPU_ZERO(&test_mask); 7820 i][f (0 != CPU_COUNT(&test_mask)) 7821 return 2; 7822 ]], 7823 [ 7824 MHD_CHECK_FUNC([CPU_COUNT_S],[[ 7825 #ifdef HAVE_SYS_PARAM_H 7826 #include <sys/param.h> 7827 #endif /* HAVE_SYS_PARAM_H */ 7828 #ifdef HAVE_SYS__CPUSET_H 7829 #include <sys/_cpuset.h> 7830 #endif /* HAVE_SYS_PARAM_H */ 7831 #include <sys/cpuset.h> 7832 ]], 7833 [[ 7834 static const unsigned int max_cpu_num = 2048u; 7835 cpuset_t *mask_ptr; 7836 mask_ptr = CPU_ALLOC(max_cpu_num); 7837 i][f (! mask_ptr) 7838 return 2; 7839 i][f (0 != cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1, 7840 CPU_ALLOC_SIZE(max_cpu_num), mask_ptr)) 7841 { 7842 CPU_FREE(mask_ptr); 7843 return 3; 7844 } 7845 i][f (0 == CPU_COUNT_S(CPU_ALLOC_SIZE(max_cpu_num), &test_mask)) 7846 { 7847 CPU_FREE(mask_ptr); 7848 return 4; 7849 } 7850 CPU_FREE(mask_ptr); 7851 ]] 7852 ) 7853 ] 7854 ) 7855 ] 7856 ) 7857 AS_VAR_IF([mhd_cv_have_func_CPU_COUNT_S],["yes"], 7858 [ 7859 AC_CACHE_CHECK([whether CPU_COUNT_S() expects max CPU number as 'size' parameter],[mhd_cv_func_cpu_count_s_cpus], 7860 [ 7861 AS_VAR_IF([cross-compiling],["yes"],[mhd_cv_func_cpu_count_s_cpus="assuming no"], 7862 [ 7863 AC_LINK_IFELSE( 7864 [ 7865 AC_LANG_PROGRAM([[ 7866 #ifdef HAVE_SYS_TYPES_H 7867 #include <sys/types.h> 7868 #endif /* HAVE_SYS_TYPES_H */ 7869 #ifdef HAVE_SYS_PARAM_H 7870 #include <sys/param.h> 7871 #endif /* HAVE_SYS_PARAM_H */ 7872 #ifdef HAVE_SYS__CPUSET_H 7873 #include <sys/_cpuset.h> 7874 #endif /* HAVE_SYS_PARAM_H */ 7875 #ifdef HAVE_SYS_CPUSET_H 7876 #include <sys/cpuset.h> 7877 #endif /* HAVE_SYS_CPUSET_H */ 7878 #ifdef HAVE_STDDEF_H 7879 #include <stddef.h> 7880 #endif /* HAVE_STDDEF_H */ 7881 #ifdef HAVE_UNISTD_H 7882 #include <unistd.h> 7883 #endif /* HAVE_UNISTD_H */ 7884 #ifdef HAVE_SCHED_H 7885 #include <sched.h> 7886 #endif /* HAVE_SCHED_H */ 7887 #include <stdio.h> 7888 7889 #ifdef HAVE_SCHED_GETAFFINITY 7890 #define TEST_CPUSET_TYPE cpu_set_t 7891 #else /* ! HAVE_SCHED_GETAFFINITY */ 7892 #define TEST_CPUSET_TYPE cpuset_t 7893 #endif /* ! HAVE_SCHED_GETAFFINITY */ 7894 ]], 7895 [[ 7896 TEST_CPUSET_TYPE *p_testset; 7897 /* The size of the cpuset that is larger then the test cpuset (in CPUs) */ 7898 static const unsigned int testset_size_oversized_cpus = (8 * sizeof(long)) * 1024; 7899 const size_t testset_size_oversized_bytes = CPU_ALLOC_SIZE(testset_size_oversized_cpus); 7900 /* The size of the test cpuset in number of CPUs */ 7901 const unsigned int testset_size_cpus = (unsigned int) testset_size_oversized_bytes; 7902 /* The size of the test cpuset in bytes */ 7903 const size_t testset_size_bytes = CPU_ALLOC_SIZE(testset_size_cpus); 7904 /* The last one CPU in the test set */ 7905 const unsigned int test_cpu_num1 = testset_size_cpus - 1; 7906 /* The penultimate CPU in the test set */ 7907 const unsigned int test_cpu_num2 = testset_size_cpus - 2; 7908 /* The CPU numbers that should be cleared */ 7909 const unsigned int test_cpu_clear1 = testset_size_cpus - 3; 7910 const unsigned int test_cpu_clear2 = testset_size_cpus - 4; 7911 unsigned int count_res; 7912 int ret = 0; 7913 7914 /* Allocate oversize area to ensure that memory outside the buffer is not used */ 7915 p_testset = CPU_ALLOC(testset_size_oversized_cpus); 7916 if (! p_testset) 7917 { 7918 fprintf (stderr, "Error allocating memory.\n"); 7919 return 99; 7920 } 7921 /* Set the some CPU numbers and then clear them */ 7922 CPU_SET_S(test_cpu_clear1, testset_size_bytes, p_testset); 7923 CPU_SET_S(test_cpu_clear2, testset_size_bytes, p_testset); 7924 CPU_ZERO_S(testset_size_bytes, p_testset); 7925 /* Set two CPUs on */ 7926 CPU_SET_S(test_cpu_num1, testset_size_bytes, p_testset); 7927 CPU_SET_S(test_cpu_num2, testset_size_bytes, p_testset); 7928 count_res = (unsigned int) CPU_COUNT_S(testset_size_bytes, p_testset); 7929 if (0 == count_res) 7930 { 7931 fprintf (stderr, "Full cpuset cannot be read by CPU_COUNT_S() when using the number of bytes as the size parameter.\n"); 7932 /* Set the some CPU numbers and then clear them */ 7933 CPU_SET_S(test_cpu_clear1, testset_size_cpus, p_testset); 7934 CPU_SET_S(test_cpu_clear2, testset_size_cpus, p_testset); 7935 CPU_ZERO_S(testset_size_cpus, p_testset); 7936 /* Set two CPUs on */ 7937 CPU_SET_S(test_cpu_num1, testset_size_cpus, p_testset); 7938 CPU_SET_S(test_cpu_num2, testset_size_cpus, p_testset); 7939 count_res = (unsigned int) CPU_COUNT_S(testset_size_cpus, p_testset); 7940 if (2 == count_res) 7941 { 7942 fprintf (stderr, "Full cpuset is read by CPU_COUNT_S() only when using the maximum CPU number as the size parameter.\n"); 7943 ret = 3; 7944 } 7945 else 7946 { 7947 fprintf (stderr, "Wrong result returned by CPU_COUNT_S() when using the maximum CPU number as the size parameter.\n"); 7948 fprintf (stderr, "Number of 'enabled' CPUs: 2\n"); 7949 fprintf (stderr, "Number of counted CPUs: %u\n", count_res); 7950 fprintf (stderr, "CPU_COUNT_S() could be unreliable.\n"); 7951 ret = 70; 7952 } 7953 } 7954 else if (2 == count_res) 7955 { 7956 fprintf (stderr, "Full cpuset is read by CPU_COUNT_S() when using the number of bytes as the size parameter.\n"); 7957 } 7958 else 7959 { 7960 fprintf (stderr, "Wrong result returned by CPU_COUNT_S() when using the number of bytes as the size parameter.\n"); 7961 fprintf (stderr, "Number of 'enabled' CPUs: 2\n"); 7962 fprintf (stderr, "Number of counted CPUs: %u\n", count_res); 7963 fprintf (stderr, "CPU_COUNT_S() could be unreliable.\n"); 7964 ret = 71; 7965 } 7966 CPU_FREE(p_testset); 7967 if (0 != ret) 7968 return ret; 7969 ]] 7970 ) 7971 ], 7972 [ 7973 AM_RUN_LOG([./conftest$EXEEXT]) 7974 count_test_res=$? 7975 AS_IF([test $count_test_res -eq 0],[mhd_cv_func_cpu_count_s_cpus="no"], 7976 [test $count_test_res -eq 3],[mhd_cv_func_cpu_count_s_cpus="yes"], 7977 [ 7978 AC_MSG_WARN([Unexpected value returned by CPU_COUNT_S() test program. Please report to ${PACKAGE_BUGREPORT}]) 7979 mhd_cv_func_cpu_count_s_cpus="assuming no" 7980 ] 7981 ) 7982 ], 7983 [ 7984 AC_MSG_WARN([Cannot build CPU_COUNT_S() test program. Please report to ${PACKAGE_BUGREPORT}]) 7985 mhd_cv_func_cpu_count_s_cpus="assuming no" 7986 ] 7987 ) 7988 ] 7989 ) 7990 ] 7991 ) 7992 AS_VAR_IF([mhd_cv_func_cpu_count_s_cpus],["yes"], 7993 [AC_DEFINE([MHD_FUNC_CPU_COUNT_S_GETS_CPUS],[1], 7994 [Define to '1' if CPU_COUNT_S() function expects max CPU number as 'size' parameter]) 7995 ] 7996 ) 7997 ] 7998 ) 7999 ] 8000 ) 8001 8002 # Check for fork() and waitpid(). They are used for tests. 8003 AC_MSG_CHECKING([[for fork()]]) 8004 mhd_have_fork_waitpid='no' 8005 AC_LINK_IFELSE( 8006 [ 8007 AC_LANG_PROGRAM( 8008 [[ 8009 #ifdef HAVE_SYS_TYPES_H 8010 #include <sys/types.h> 8011 #endif 8012 #ifdef HAVE_UNISTD_H 8013 #include <unistd.h> 8014 #endif 8015 ]], [[ 8016 pid_t p = fork (); 8017 if (0 == p) 8018 return 1; 8019 ]]) 8020 ], [ 8021 AC_DEFINE([[HAVE_FORK]], [[1]], [Define to 1 if you have the usable `fork' function.]) 8022 AC_MSG_RESULT([[yes]]) 8023 8024 AC_MSG_CHECKING([[for waitpid()]]) 8025 AC_LINK_IFELSE( 8026 [ 8027 AC_LANG_PROGRAM( 8028 [[ 8029 #ifdef HAVE_SYS_TYPES_H 8030 #include <sys/types.h> 8031 #endif 8032 #ifdef HAVE_UNISTD_H 8033 #include <unistd.h> 8034 #endif 8035 #include <sys/wait.h> 8036 ]], [[ 8037 pid_t p = fork (); 8038 if (0 == p) 8039 return 1; 8040 waitpid (p, (void*)0, 0) 8041 ]]) 8042 ], [ 8043 AC_DEFINE([[HAVE_WAITPID]], [[1]], [Define to 1 if you have the usable `waitpid' function.]) 8044 AC_MSG_RESULT([[yes]]) 8045 mhd_have_fork_waitpid='yes' 8046 ],[ 8047 AC_MSG_RESULT([[no]]) 8048 ]) 8049 ],[ 8050 AC_MSG_RESULT([[no]]) 8051 ]) 8052 8053 AM_CONDITIONAL([HAVE_FORK_WAITPID], [test "x$mhd_have_fork_waitpid" = "xyes"]) 8054 8055 # gcov compilation 8056 AC_MSG_CHECKING(whether to compile with support for code coverage analysis) 8057 AC_ARG_ENABLE([coverage], 8058 AS_HELP_STRING([--enable-coverage], 8059 [compile the library with code coverage support]), 8060 [use_gcov=${enableval}], 8061 [use_gcov=no]) 8062 AC_MSG_RESULT($use_gcov) 8063 AM_CONDITIONAL([USE_COVERAGE], [test "x$use_gcov" = "xyes"]) 8064 8065 AX_COUNT_CPUS 8066 AC_SUBST([MHD_REAL_CPU_COUNT],[${CPU_COUNT}]) 8067 AM_SUBST_NOTMAKE([MHD_REAL_CPU_COUNT]) 8068 AC_MSG_CHECKING([for number of CPU cores to use in tests]) 8069 AS_VAR_IF([use_heavy_tests], ["yes"], 8070 [ 8071 # Enable usage of many core if heavy tests are enabled 8072 AS_IF([[test "$CPU_COUNT" -gt "32"]], [[CPU_COUNT="32"]])dnl Limit resource usage 8073 ], 8074 [ 8075 # Limit usage to just a few cores if heavy tests are not enabled 8076 AS_IF([[test "$CPU_COUNT" -gt "6"]], [[CPU_COUNT="6"]]) 8077 AS_IF([[test "$CPU_COUNT" -lt "2"]], [[CPU_COUNT="2"]]) 8078 ] 8079 ) 8080 AC_MSG_RESULT([$CPU_COUNT]) 8081 8082 8083 AC_ARG_ENABLE([[asserts]], 8084 [AS_HELP_STRING([[--enable-asserts]], 8085 [enable test build with debug asserts])], 8086 [], 8087 [enable_asserts='auto'] 8088 ) 8089 AS_UNSET([use_asserts_MSG]) 8090 AC_CACHE_CHECK([[whether NDEBUG macro is defined]], [mhd_cv_macro_ndebug_def], 8091 [ 8092 AC_LINK_IFELSE( 8093 [ 8094 AC_LANG_SOURCE([[ 8095 #ifndef NDEBUG 8096 #error NDEBUG is NOT defined 8097 chome me now 8098 #endif 8099 8100 int main(void) 8101 { 8102 return 0; 8103 } 8104 ]] 8105 ) 8106 ], 8107 [[mhd_cv_macro_ndebug_def='yes']], 8108 [[mhd_cv_macro_ndebug_def='no']] 8109 ) 8110 ] 8111 ) 8112 AS_VAR_IF([enable_asserts],["yes"], 8113 [ 8114 AS_VAR_IF([mhd_cv_macro_ndebug_def],["yes"], 8115 [ 8116 AC_MSG_FAILURE([Parameter --enable-asserts is specified, but NDEBUG macro is defined as well]) 8117 ] 8118 ) 8119 use_asserts_MSG="yes, enabled by configure parameter" 8120 ] 8121 ) 8122 AC_CACHE_CHECK([[whether _DEBUG macro is defined]], [mhd_cv_macro__debug_def], 8123 [ 8124 AC_LINK_IFELSE( 8125 [ 8126 AC_LANG_SOURCE([[ 8127 #ifndef _DEBUG 8128 #error _DEBUG is NOT defined 8129 chome me now 8130 #endif 8131 8132 int main(void) 8133 { 8134 return 0; 8135 } 8136 ]] 8137 ) 8138 ], 8139 [[mhd_cv_macro__debug_def='yes']], 8140 [[mhd_cv_macro__debug_def='no']] 8141 ) 8142 ] 8143 ) 8144 AS_VAR_IF([enable_asserts],["no"], 8145 [ 8146 AS_VAR_IF([mhd_cv_macro__debug_def],["yes"], 8147 [ 8148 AC_MSG_FAILURE([Parameter --disable-asserts is specified, but _DEBUG macro is defined as well]) 8149 ] 8150 ) 8151 use_asserts_MSG="no, set by configure parameter" 8152 ] 8153 ) 8154 AS_IF([test "x${mhd_cv_macro_ndebug_def}" = "xyes" && test "x${mhd_cv_macro__debug_def}" = "xyes"], 8155 [AC_MSG_FAILURE([Both NDEBUG and _DEBUG macros are defined])] 8156 ) 8157 AS_VAR_IF([enable_asserts],["auto"], 8158 [ 8159 AS_VAR_IF([mhd_cv_macro_ndebug_def],["yes"], 8160 [ 8161 enable_asserts="no" 8162 use_asserts_MSG="no, set by NDEBUG preprocessor macro" 8163 ] 8164 ) 8165 ] 8166 ) 8167 AS_VAR_IF([enable_asserts],["auto"], 8168 [ 8169 AS_VAR_IF([mhd_cv_macro__debug_def],["yes"], 8170 [ 8171 enable_asserts="yes" 8172 use_asserts_MSG="yes, enabled by _DEBUG preprocessor macro" 8173 ] 8174 ) 8175 ] 8176 ) 8177 AS_VAR_IF([enable_asserts],["auto"], 8178 [ 8179 AC_CACHE_CHECK([[whether DEBUG macro is defined]], [mhd_cv_macro_debug_def], 8180 [ 8181 AC_LINK_IFELSE( 8182 [ 8183 AC_LANG_SOURCE([[ 8184 #ifndef DEBUG 8185 #error DEBUG is NOT defined 8186 chome me now 8187 #endif 8188 8189 int main(void) 8190 { 8191 return 0; 8192 } 8193 ]] 8194 ) 8195 ], 8196 [[mhd_cv_macro_debug_def='yes']], 8197 [[mhd_cv_macro_debug_def='no']] 8198 ) 8199 ] 8200 ) 8201 AS_VAR_IF([mhd_cv_macro_debug_def],["yes"], 8202 [ 8203 enable_asserts="yes" 8204 use_asserts_MSG="yes, enabled by DEBUG preprocessor macro" 8205 ] 8206 ) 8207 ] 8208 ) 8209 AC_MSG_CHECKING([[whether to enable debug asserts]]) 8210 AS_VAR_IF([enable_asserts],["auto"], 8211 [ 8212 AS_CASE([${enable_build_type}], 8213 [debug|debugger], 8214 [ 8215 enable_asserts="yes" 8216 use_asserts_MSG="yes, enabled by --enable-bulid-type=${enable_build_type}" 8217 ], 8218 [ 8219 enable_asserts="no" 8220 use_asserts_MSG="no" 8221 ] 8222 ) 8223 ] 8224 ) 8225 AS_CASE([[$enable_asserts]], [[yes]], [[:]], [[no]], [[:]], [[enable_asserts='no']]) 8226 AC_MSG_RESULT([[${use_asserts_MSG=no}]]) 8227 8228 AS_VAR_IF([[enable_asserts]], [["yes"]], 8229 [ 8230 AS_VAR_IF([[mhd_cv_macro__debug_def]], [["yes"]], [:], 8231 [ 8232 MHD_PREPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-D_DEBUG=1]) 8233 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 8234 ] 8235 ) 8236 AC_CACHE_CHECK([[whether system assert() is available]], [mhd_cv_sys_assert_avail], 8237 [ 8238 AC_LINK_IFELSE( 8239 [ 8240 AC_LANG_SOURCE([[ 8241 #include <assert.h> 8242 8243 static int pos_val(void) {return 5;} 8244 static int neg_val(void) {return -5;} 8245 int main(void) 8246 { 8247 int pos_var = pos_val(), neg_var = neg_val(); 8248 assert(neg_var > pos_var); /* Must trigger assert. */ 8249 return pos_var + neg_var; 8250 } 8251 ]]) 8252 ], 8253 [[mhd_cv_sys_assert_avail='yes']], 8254 [[mhd_cv_sys_assert_avail='no']] 8255 ) 8256 ] 8257 ) 8258 AS_VAR_IF([[mhd_cv_sys_assert_avail]], [["no"]], [], 8259 [AC_DEFINE([[HAVE_ASSERT]], [[1]], [Define if you have usable assert() and assert.h])]) 8260 ], 8261 [ 8262 AS_VAR_IF([[mhd_cv_macro_ndebug_def]], [["yes"]], [:], 8263 [ 8264 MHD_PREPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DNDEBUG=1]) 8265 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 8266 ] 8267 ) 8268 ] 8269 ) 8270 8271 AS_UNSET([enabled_sanitizers]) 8272 TESTS_ENVIRONMENT_ac="" 8273 AM_ASAN_OPTIONS="" 8274 AM_UBSAN_OPTIONS="" 8275 AM_LSAN_OPTIONS="" 8276 AS_UNSET([ASAN_OPTIONS]) 8277 AS_UNSET([UBSAN_OPTIONS]) 8278 AS_UNSET([LSAN_OPTIONS]) 8279 8280 AC_MSG_CHECKING([whether to enable run-time sanitizers]) 8281 AC_ARG_ENABLE([sanitizers], 8282 [AS_HELP_STRING([[--enable-sanitizers[=address,undefined,leak,user-poison]]], 8283 [enable run-time sanitizers, specify the list of types of sanitizers to enable, ] 8284 [leave the list empty (or set to "auto") to enable all supported and available ] 8285 [sanitizers, or specify "auto-fallback" to use sanitizers even without ] 8286 [installed sanitizer run-time library])], 8287 [], [AS_CASE([${enable_build_type}],[debug], 8288 [enable_sanitizers='auto-optional'],[enable_sanitizers='no'])] 8289 ) 8290 AS_IF([test "x${enable_sanitizers}" = "x"], [enable_sanitizers="auto"]) 8291 AS_VAR_IF([enable_sanitizers], ["yes"], [enable_sanitizers="auto"]) 8292 AS_VAR_IF([enable_sanitizers], ["autofallback"], [enable_sanitizers="auto-fallback"]) 8293 AS_VAR_IF([enable_sanitizers], ["autooptional"], [enable_sanitizers="auto-optional"]) 8294 AS_IF([test "x${enable_sanitizers}" = "xno"], 8295 [ 8296 enable_sanitizers="no" 8297 enable_san_address="no" 8298 enable_san_undef="no" 8299 enable_san_leak="no" 8300 enable_san_upoison="no" 8301 ], 8302 [test "x${enable_sanitizers}" = "xauto" || test "x${enable_sanitizers}" = "xauto-optional"], 8303 [ 8304 AS_VAR_IF([enable_compiler_hardening],["yes"], 8305 [ 8306 AS_VAR_IF([enable_sanitizers],["auto"], 8307 [AC_MSG_ERROR([sanitizers cannot be enabled with compiler hardnening])], 8308 [AC_MSG_WARN([sanitizers cannot be enabled with compiler hardnening])] 8309 ) 8310 enable_sanitizers="no" 8311 enable_san_address="no" 8312 enable_san_undef="no" 8313 enable_san_leak="no" 8314 enable_san_upoison="no" 8315 ], 8316 [ 8317 enable_san_address="auto" 8318 enable_san_undef="auto" 8319 enable_san_leak="auto" 8320 enable_san_upoison="auto" 8321 ] 8322 ) 8323 ], 8324 [test "x${enable_sanitizers}" = "xauto-fallback"], 8325 [ 8326 enable_san_address="auto" 8327 enable_san_undef="auto-fallback" 8328 enable_san_leak="auto" 8329 enable_san_upoison="auto" 8330 ], 8331 [ 8332 AS_UNSET([san]) 8333 enable_san_address="no" 8334 enable_san_undef="no" 8335 enable_san_leak="no" 8336 enable_san_upoison="no" 8337 f][or san in `AS_ECHO([${enable_sanitizers}]) | tr ',' ' '` 8338 do 8339 AS_CASE([$san], 8340 [address], [enable_san_address="yes"], 8341 [undefined], [enable_san_undef="yes"], 8342 [leak], [enable_san_leak="yes"], 8343 [user-poison|user_poison], [enable_san_upoison="yes"], 8344 [no|yes|auto|auto-fallback|autofallback], [AC_MSG_ERROR(["$san" cannot be used with other options for --enable-sanitizers=])], 8345 [AC_MSG_ERROR([Unknown parameter "$san" for --enable-sanitizers=])] 8346 ) 8347 done 8348 AS_IF([test "x${enable_san_upoison}" = "xyes" && test "x${enable_san_address}" = "xno"], 8349 [AC_MSG_ERROR([User memory poisoning cannot be used without address sanitizer])] 8350 ) 8351 enable_sanitizers="selected" 8352 ] 8353 ) 8354 AS_CASE([${enable_sanitizers}], 8355 [selected], [AC_MSG_RESULT([selected])], 8356 [auto], [AC_MSG_RESULT([yes, detect and use supported sanitizers])], 8357 [auto-fallback], [AC_MSG_RESULT([yes, detect and use supported sanitizers even without run-time lib])], 8358 [auto-optional], [AC_MSG_RESULT([yes, detect and use supported sanitizers if any])], 8359 [AC_MSG_RESULT([no])] 8360 ) 8361 AS_VAR_IF([enable_sanitizers], ["no"], [:], 8362 [ 8363 AS_UNSET([san_FLAGS]) # the sanitizer flags to be added to both CFLAGS and LDFLAGS 8364 AS_UNSET([san_CFLAGS]) # the sanitizer flags to be added to CFLAGS 8365 AC_CACHE_CHECK([whether '-fsanitize=' works for $CC], 8366 [mhd_cv_cc_sanitizer_works], 8367 [ 8368 CFLAGS="${CFLAGS_ac} -fsanitize=wrongFeatureName ${user_CFLAGS}" 8369 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])], 8370 [mhd_cv_cc_sanitizer_works=no], [mhd_cv_cc_sanitizer_works=yes]) 8371 ] 8372 ) 8373 AS_VAR_IF([mhd_cv_cc_sanitizer_works], ["yes"], 8374 [ 8375 AS_VAR_IF([enable_san_address], ["no"], [:], 8376 [ 8377 AC_CACHE_CHECK([for address sanitizer], [mhd_cv_cc_sanitizer_address], 8378 [ 8379 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=address ${user_CFLAGS}" 8380 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], 8381 [mhd_cv_cc_sanitizer_address=yes], [mhd_cv_cc_sanitizer_address=no]) 8382 ] 8383 ) 8384 AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"], 8385 [ 8386 AC_DEFINE([MHD_ASAN_ACTIVE], [1], [Define to '1' if you have address sanitizer enabled]) 8387 AX_APPEND_FLAG([-fsanitize=address], [san_FLAGS]) 8388 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }address" 8389 AS_VAR_IF([enable_san_leak], ["no"], [:], 8390 [ 8391 AC_CACHE_CHECK([whether leak detect is not rejected by address sanitizer], [mhd_cv_cc_sanitizer_address_leak], 8392 [ 8393 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${user_CFLAGS}" 8394 ASAN_OPTIONS="exitcode=88:detect_leaks=1:halt_on_error=1" 8395 export ASAN_OPTIONS 8396 AC_RUN_IFELSE([AC_LANG_PROGRAM([],[])], 8397 [mhd_cv_cc_sanitizer_address_leak=yes], [mhd_cv_cc_sanitizer_address_leak=no], 8398 [ 8399 # Cross-compiling with sanitizers? 8400 mhd_cv_cc_sanitizer_address_leak='assuming no' 8401 ] 8402 ) 8403 AS_UNSET([ASAN_OPTIONS]) 8404 ] 8405 ) 8406 ] 8407 ) 8408 AC_CACHE_CHECK([for pointer compare sanitizer], [mhd_cv_cc_sanitizer_pointer_compare], 8409 [ 8410 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-compare ${user_CFLAGS}" 8411 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], 8412 [mhd_cv_cc_sanitizer_pointer_compare=yes], [mhd_cv_cc_sanitizer_pointer_compare=no]) 8413 ] 8414 ) 8415 AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_compare],["yes"], 8416 [ 8417 AX_APPEND_FLAG([-fsanitize=pointer-compare], [san_FLAGS]) 8418 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer compare" 8419 ] 8420 ) 8421 AC_CACHE_CHECK([for pointer subtract sanitizer], [mhd_cv_cc_sanitizer_pointer_subtract], 8422 [ 8423 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-subtract ${user_CFLAGS}" 8424 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], 8425 [mhd_cv_cc_sanitizer_pointer_subtract=yes], [mhd_cv_cc_sanitizer_pointer_subtract=no]) 8426 ] 8427 ) 8428 AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_subtract],["yes"], 8429 [ 8430 AX_APPEND_FLAG([-fsanitize=pointer-subtract], [san_FLAGS]) 8431 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer subtract" 8432 ] 8433 ) 8434 AS_VAR_IF([enable_san_upoison], ["no"], [:], 8435 [ 8436 AC_CHECK_HEADERS([sanitizer/asan_interface.h], [], [], [AC_INCLUDES_DEFAULT]) 8437 AS_VAR_IF([ac_cv_header_sanitizer_asan_interface_h],["yes"], 8438 [ 8439 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}" 8440 MHD_CHECK_FUNC([__asan_address_is_poisoned],[[#include <sanitizer/asan_interface.h>]], 8441 [[int a_var=1; i][f(__asan_address_is_poisoned((void*) &a_var)) return 3;]] 8442 ) 8443 MHD_CHECK_FUNC([__asan_region_is_poisoned],[[#include <sanitizer/asan_interface.h>]], 8444 [[int a_var=1; i][f(((void*) 0) != __asan_region_is_poisoned((void*) &a_var, sizeof(a_var))) return 3;]] 8445 ) 8446 AC_CACHE_CHECK([whether special function attribute is needed for user-poison], [mhd_cv_func_u_p_attribute_needed], 8447 [ 8448 ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1" 8449 export ASAN_OPTIONS 8450 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}" 8451 AC_RUN_IFELSE( 8452 [ 8453 AC_LANG_SOURCE( 8454 [[ 8455 #include <stdint.h> 8456 #include <stdlib.h> 8457 #include <sanitizer/asan_interface.h> 8458 8459 static const size_t first_pos = 0; 8460 static const size_t mid_pos = 64; 8461 static const size_t last_pos = 128; 8462 static const size_t zone_size = 16; 8463 static const size_t buf_size = 128 + 16; 8464 8465 static int ptr_compare(void *ptr1, uint8_t *ptr2) 8466 { 8467 if ((((uintptr_t) (uint8_t *)ptr1) >= ((uintptr_t)ptr2))) 8468 return ((char *) ptr1)[0] < ((char *) ptr2)[0]; 8469 return ((char *) ptr1)[0] > ((char *) ptr2)[0]; 8470 } 8471 8472 static int ptr_subtract(void *ptr1, uint8_t *ptr2) 8473 { 8474 return ((size_t)(((uintptr_t)(uint8_t*)ptr1) - ((uintptr_t)ptr2))) <= last_pos; 8475 } 8476 8477 int main(int argc, char *argv[]) 8478 { 8479 char *buf = (char*) malloc (buf_size); 8480 char *a; 8481 char *b; 8482 int ret; 8483 8484 (void) argv; 8485 if (NULL == buf) 8486 return 10; 8487 ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size); 8488 ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size); 8489 8490 if (0 < argc) 8491 a = buf + last_pos; 8492 else 8493 a = buf + first_pos; 8494 b = buf + mid_pos; 8495 8496 *a = '0'; 8497 *b = '9'; 8498 8499 if (ptr_compare((void *)a, (uint8_t*) b)) 8500 { 8501 if (ptr_subtract((void *)a, (uint8_t*) b)) 8502 ret = 0; 8503 else 8504 ret = 10; 8505 } 8506 else 8507 ret = 5; 8508 ASAN_UNPOISON_MEMORY_REGION (buf, buf_size); 8509 free (buf); 8510 8511 return ret; 8512 } 8513 ]] 8514 ) 8515 ], 8516 [mhd_cv_func_u_p_attribute_needed="no"], [mhd_cv_func_u_p_attribute_needed="yes"], 8517 [ 8518 # Cross-compiling with sanitizers?? 8519 mhd_cv_func_up_attribute_needed='assuming no' 8520 ] 8521 ) 8522 AS_UNSET([ASAN_OPTIONS]) 8523 ] 8524 ) 8525 ] 8526 ) 8527 AS_VAR_IF([mhd_cv_func_u_p_attribute_needed],["yes"],[:], 8528 [ 8529 AC_DEFINE([FUNC_PTRCOMPARE_CAST_WORKAROUND_WORKS],[1],[Define to '1' if cast to 'uintptr_t' works for safely processing user-poisoned pointer]) 8530 ] 8531 ) 8532 AS_IF([test "x${mhd_cv_func_u_p_attribute_needed}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes"], 8533 [ 8534 AC_CACHE_CHECK([whether '__attribute__((no_sanitize("pointer-compare")))' and '__attribute__((no_sanitize("pointer-subtract")))' work], 8535 [mhd_cv_func_attribute_nosanitize_ptr], 8536 [ 8537 ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1" 8538 export ASAN_OPTIONS 8539 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}" 8540 AC_RUN_IFELSE( 8541 [ 8542 AC_LANG_SOURCE( 8543 [[ 8544 #include <stdint.h> 8545 #include <stdlib.h> 8546 #include <sanitizer/asan_interface.h> 8547 8548 static const size_t first_pos = 0; 8549 static const size_t mid_pos = 64; 8550 static const size_t last_pos = 128; 8551 static const size_t zone_size = 16; 8552 static const size_t buf_size = 128 + 16; 8553 8554 __attribute__((no_sanitize("pointer-compare"))) 8555 static int ptr_compare(void *ptr1, uint8_t *ptr2) 8556 { 8557 if ((((const uint8_t*)ptr1) >= ((const uint8_t*)ptr2))) 8558 return ((char *) ptr1)[0] < ((char *) ptr2)[0]; 8559 return ((char *) ptr1)[0] > ((char *) ptr2)[0]; 8560 } 8561 8562 __attribute__((no_sanitize("pointer-subtract"))) 8563 static int ptr_subtract(void *ptr1, uint8_t *ptr2) 8564 { 8565 return ((size_t)(((const uint8_t*)ptr1) - \ 8566 ((const uint8_t*)ptr2))) <= last_pos; 8567 } 8568 8569 int main(int argc, char *argv[]) 8570 { 8571 char *buf = (char*) malloc (buf_size); 8572 char *a; 8573 char *b; 8574 int ret; 8575 8576 (void) argv; 8577 if (NULL == buf) 8578 return 10; 8579 ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size); 8580 ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size); 8581 8582 if (0 < argc) 8583 a = buf + last_pos; 8584 else 8585 a = buf + first_pos; 8586 b = buf + mid_pos; 8587 8588 *a = '0'; 8589 *b = '9'; 8590 8591 if (ptr_compare((void *)a, (uint8_t*) b)) 8592 { 8593 if (ptr_subtract((void *)a, (uint8_t*) b)) 8594 ret = 0; 8595 else 8596 ret = 10; 8597 } 8598 else 8599 ret = 5; 8600 ASAN_UNPOISON_MEMORY_REGION (buf, buf_size); 8601 free (buf); 8602 8603 return ret; 8604 } 8605 ]] 8606 ) 8607 ], 8608 [mhd_cv_func_attribute_nosanitize_ptr=yes], [mhd_cv_func_attribute_nosanitize_ptr=no], 8609 [ 8610 # Cross-compiling with sanitizers?? 8611 mhd_cv_func_attribute_nosanitize_ptr='assuming no' 8612 ] 8613 ) 8614 AS_UNSET([ASAN_OPTIONS]) 8615 ] 8616 ) 8617 AS_VAR_IF([mhd_cv_func_attribute_nosanitize_ptr], ["yes"], 8618 [ 8619 AC_DEFINE([FUNC_ATTR_PTRCOMPARE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-compare")))' works]) 8620 AC_DEFINE([FUNC_ATTR_PTRSUBTRACT_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-subtract")))' works]) 8621 ], 8622 [ 8623 AC_CACHE_CHECK([whether '__attribute__((no_sanitize("address")))' works for pointers compare], [mhd_cv_func_attribute_nosanitize_addr], 8624 [ 8625 ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1" 8626 export ASAN_OPTIONS 8627 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}" 8628 AC_RUN_IFELSE( 8629 [ 8630 AC_LANG_SOURCE( 8631 [[ 8632 #include <stdint.h> 8633 #include <stdlib.h> 8634 #include <sanitizer/asan_interface.h> 8635 8636 static const size_t first_pos = 0; 8637 static const size_t mid_pos = 64; 8638 static const size_t last_pos = 128; 8639 static const size_t zone_size = 16; 8640 static const size_t buf_size = 128 + 16; 8641 8642 __attribute__((no_sanitize("address"))) 8643 static int ptr_compare(void *ptr1, uint8_t *ptr2) 8644 { 8645 if ((((const uint8_t*)ptr1) >= ((const uint8_t*)ptr2))) 8646 return ((char *) ptr1)[0] < ((char *) ptr2)[0]; 8647 return ((char *) ptr1)[0] > ((char *) ptr2)[0]; 8648 } 8649 8650 __attribute__((no_sanitize("address"))) 8651 static int ptr_subtract(void *ptr1, uint8_t *ptr2) 8652 { 8653 return ((size_t)(((const uint8_t*)ptr1) - \ 8654 ((const uint8_t*)ptr2))) <= last_pos; 8655 } 8656 8657 int main(int argc, char *argv[]) 8658 { 8659 char *buf = (char*) malloc (buf_size); 8660 char *a; 8661 char *b; 8662 int ret; 8663 8664 (void) argv; 8665 if (NULL == buf) 8666 return 10; 8667 ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size); 8668 ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size); 8669 8670 if (0 < argc) 8671 a = buf + last_pos; 8672 else 8673 a = buf + first_pos; 8674 b = buf + mid_pos; 8675 8676 *a = '0'; 8677 *b = '9'; 8678 8679 if (ptr_compare((void *)a, (uint8_t*) b)) 8680 { 8681 if (ptr_subtract((void *)a, (uint8_t*) b)) 8682 ret = 0; 8683 else 8684 ret = 10; 8685 } 8686 else 8687 ret = 5; 8688 ASAN_UNPOISON_MEMORY_REGION (buf, buf_size); 8689 free (buf); 8690 8691 return ret; 8692 } 8693 ]] 8694 ) 8695 ], 8696 [mhd_cv_func_attribute_nosanitize_addr=yes], [mhd_cv_func_attribute_nosanitize_addr=no], 8697 [ 8698 # Cross-compiling with sanitizers?? 8699 mhd_cv_func_attribute_nosanitize_addr='assuming no' 8700 ] 8701 ) 8702 AS_UNSET([ASAN_OPTIONS]) 8703 ] 8704 ) 8705 AS_VAR_IF([mhd_cv_func_attribute_nosanitize_addr], ["yes"], 8706 [AC_DEFINE([FUNC_ATTR_NOSANITIZE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("address")))' works for pointers compare])] 8707 ) 8708 ] 8709 ) 8710 ] 8711 ) 8712 ] 8713 ) 8714 ] 8715 ) 8716 AS_IF([test "x${enable_san_address}" = "xyes" && test "x${mhd_cv_cc_sanitizer_address}" != "xyes"], 8717 [AC_MSG_ERROR([Address sanitizer cannot be enabled])] 8718 ) 8719 enable_san_address="${mhd_cv_cc_sanitizer_address}" 8720 ] 8721 ) 8722 AS_VAR_IF([enable_san_undef], ["no"], [:], 8723 [ 8724 dnl Ensure that '#' will be processed correctly 8725 [ 8726 test_undf_prog=' 8727 #include <stdio.h> 8728 8729 static void func_out_b(char *arr) 8730 { 8731 arr[0] = 0; 8732 arr[16] = 2; 8733 } 8734 8735 static unsigned int int_deref(void *ptr) 8736 { 8737 return (*((unsigned int*)ptr)) + 2; 8738 } 8739 8740 static int func1(void) 8741 { 8742 char chr[16]; 8743 func_out_b (chr); 8744 return (int) (int_deref(chr + 1) + int_deref(chr + 2)); 8745 } 8746 8747 int main(void) 8748 { 8749 unsigned long ulvar; 8750 signed char ch1; 8751 ulvar = -1 * func1(); 8752 ch1 = ulvar * 6UL; 8753 printf("%lu\n", ulvar + ch1); 8754 return 0; 8755 } 8756 ' 8757 ] 8758 AC_CACHE_CHECK([for undefined behavior sanitizer], [mhd_cv_cc_sanitizer_undefined], 8759 [ 8760 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined ${user_CFLAGS}" 8761 AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], 8762 [mhd_cv_cc_sanitizer_undefined=yes], [mhd_cv_cc_sanitizer_undefined=no]) 8763 ] 8764 ) 8765 AS_VAR_IF([mhd_cv_cc_sanitizer_undefined],["yes"], 8766 [ 8767 AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) 8768 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" 8769 ], 8770 [ 8771 AS_CASE([${enable_san_undef}], [yes|auto-fallback], 8772 [ 8773 AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-undefined-trap-on-error'], [mhd_cv_cc_sanitizer_undefined_trap], 8774 [ 8775 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error ${user_CFLAGS}" 8776 AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], 8777 [mhd_cv_cc_sanitizer_undefined_trap=yes], [mhd_cv_cc_sanitizer_undefined_trap=no]) 8778 ] 8779 ) 8780 AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap], ["yes"], 8781 [ 8782 AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) 8783 AX_APPEND_FLAG([-fsanitize-undefined-trap-on-error], [san_FLAGS]) 8784 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" 8785 AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) 8786 ], 8787 [ 8788 AS_IF([test -z "${enabled_sanitizers}"], 8789 [ 8790 # Last resort 8791 AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-trap=all'], [mhd_cv_cc_sanitizer_undefined_trap_all], 8792 [ 8793 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all ${user_CFLAGS}" 8794 AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], 8795 [mhd_cv_cc_sanitizer_undefined_trap_all=yes], [mhd_cv_cc_sanitizer_undefined_trap_all=no]) 8796 ] 8797 ) 8798 AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap_all],["yes"], 8799 [ 8800 AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) 8801 AX_APPEND_FLAG([-fsanitize-trap=all], [san_FLAGS]) 8802 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all ${user_CFLAGS}" 8803 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" 8804 AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) 8805 ] 8806 ) 8807 ] 8808 ) 8809 ] 8810 ) 8811 AS_CASE(["$enabled_sanitizers"], [*undefined], 8812 [ 8813 AS_VAR_IF([mhd_cv_cc_sanitizer_undefined], ["yes"],[], 8814 [ 8815 # A workaround for broken clang which is trying to use UBSan lib 8816 # even when instructed to not use it 8817 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}" 8818 AX_APPEND_LINK_FLAGS([-fsanitize-trap=implicit-conversion], 8819 [san_FLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])]) 8820 ] 8821 ) 8822 ] 8823 ) 8824 ] 8825 ) 8826 ] 8827 ) 8828 AS_CASE(["$enabled_sanitizers"], [*undefined], 8829 [ 8830 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}" 8831 AX_APPEND_LINK_FLAGS([-fsanitize=bounds-strict -fsanitize=local-bounds -fsanitize=implicit-conversion -fsanitize=nullability-arg], 8832 [san_CFLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])]) 8833 ] 8834 ) 8835 AS_UNSET([test_undf_prog]) 8836 AS_CASE(["$enabled_sanitizers"], 8837 [*undefined], [enable_san_undef="yes"], 8838 [ 8839 AS_VAR_IF([enable_san_undef], [yes], [AC_MSG_ERROR([Undefined behavior sanitizer cannot be enabled])]) 8840 enable_san_undef="no" 8841 ] 8842 ) 8843 ] 8844 ) 8845 AS_VAR_IF([enable_san_leak], ["no"], [:], 8846 [ 8847 AC_CACHE_CHECK([for leak sanitizer], [mhd_cv_cc_sanitizer_leak], 8848 [ 8849 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=leak ${user_CFLAGS}" 8850 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], 8851 [mhd_cv_cc_sanitizer_leak=yes], [mhd_cv_cc_sanitizer_leak=no]) 8852 ] 8853 ) 8854 AS_VAR_IF([mhd_cv_cc_sanitizer_leak],["yes"], 8855 [ 8856 AX_APPEND_FLAG([-fsanitize=leak], [san_FLAGS]) 8857 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }leak" 8858 ] 8859 ) 8860 AS_IF([test "x${enable_san_leak}" = "xyes" && test "x${mhd_cv_cc_sanitizer_leak}" != "xyes"], 8861 [AC_MSG_ERROR([User poison cannot be enabled])] 8862 ) 8863 enable_san_leak="${mhd_cv_cc_sanitizer_leak}" 8864 ] 8865 ) 8866 AS_IF([test -z "${enabled_sanitizers}"], 8867 [ 8868 AS_VAR_IF([enable_sanitizers], ["auto-optional"], 8869 [ 8870 san_FLAGS="" 8871 san_CFLAGS="" 8872 ], 8873 [ 8874 AC_MSG_ERROR([cannot find any sanitizer supported by $CC]) 8875 ] 8876 ) 8877 ], 8878 [ 8879 AS_VAR_IF([enable_san_upoison], ["no"], [:], 8880 [ 8881 AC_MSG_CHECKING([whether to enable user memory poisoning]) 8882 AS_IF([test "x${mhd_cv_cc_sanitizer_address}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes" && \ 8883 (test "x${mhd_cv_func_u_p_attribute_needed}" != "xyes" || test "x${mhd_cv_func_attribute_nosanitize_ptr}" = "xyes" || \ 8884 test "x${mhd_cv_func_attribute_nosanitize_addr}" = "xyes")], 8885 [ 8886 AC_DEFINE([MHD_ASAN_POISON_ACTIVE], [1], [Define to '1' if user memory poison is used]) 8887 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }user-poison" 8888 enable_san_upoison="yes" 8889 AC_MSG_RESULT([yes]) 8890 ], 8891 [ 8892 AC_MSG_RESULT([no]) 8893 AS_VAR_IF([enable_san_upoison], ["yes"], 8894 [AC_MSG_ERROR([User memory poisoning cannot be enabled])]) 8895 enable_san_upoison="no" 8896 ] 8897 ) 8898 ] 8899 ) 8900 AS_VAR_IF([enable_san_address], ["yes"], 8901 [ 8902 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}" 8903 AC_CHECK_DECL([_FORTIFY_SOURCE], 8904 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-U_FORTIFY_SOURCE])], 8905 [],[/* no includes */]) 8906 AX_APPEND_FLAG([-D_FORTIFY_SOURCE=0], [san_CFLAGS]) 8907 ], 8908 [ 8909 AS_CASE([$enable_sanitizers], [auto|auto-fallback], 8910 [AC_MSG_WARN([$CC does not support address sanitizer])]) 8911 ] 8912 ) 8913 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}" 8914 # Always stop on sanitizer error 8915 AX_APPEND_COMPILE_FLAGS([-fno-sanitize-recover=all], [san_CFLAGS]) 8916 # Get a better output for sanitizers error reporting 8917 AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer -fno-optimize-sibling-calls], 8918 [san_CFLAGS]) 8919 AS_VAR_IF([enable_san_address], ["yes"], 8920 [ 8921 AM_ASAN_OPTIONS="exitcode=88:strict_string_checks=1:detect_stack_use_after_return=1" 8922 AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:check_initialization_order=1:strict_init_order=1:redzone=64" 8923 AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:max_free_fill_size=1024:detect_invalid_pointer_pairs=3" 8924 AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:handle_ioctl=1:halt_on_error=1" 8925 AS_VAR_IF([enable_san_upoison], ["yes"], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:allow_user_poisoning=1"]) 8926 AS_VAR_IF([enable_san_leak], ["yes"], 8927 [AS_VAR_IF([mhd_cv_cc_sanitizer_address_leak], ["yes"], 8928 [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=1"]) 8929 ], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=0"] 8930 ) 8931 ] 8932 ) 8933 AS_VAR_IF([enable_san_undef], [yes], 8934 [AM_UBSAN_OPTIONS="exitcode=87:print_stacktrace=1:halt_on_error=1"]) 8935 AS_VAR_IF([enable_san_leak], ["yes"], 8936 [AM_LSAN_OPTIONS="use_unaligned=1"] 8937 ) 8938 TESTS_ENVIRONMENT_ac='\ 8939 ASAN_OPTIONS="$(AM_ASAN_OPTIONS)" ; export ASAN_OPTIONS ; \ 8940 UBSAN_OPTIONS="$(AM_UBSAN_OPTIONS)" ; export UBSAN_OPTIONS ; \ 8941 LSAN_OPTIONS="$(AM_LSAN_OPTIONS)" ; export LSAN_OPTIONS ;' 8942 ] 8943 ) 8944 ] 8945 ) 8946 CFLAGS_ac="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS}" 8947 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 8948 ] 8949 ) 8950 8951 # fuzzing tests 8952 run_zzuf_tests="no" 8953 zzuf_socat_mandatory="no" 8954 AS_VAR_IF([use_heavy_tests],["yes"], 8955 [ 8956 AS_VAR_IF([enable_curl],["yes"], 8957 [ 8958 AC_PATH_PROG([ZZUF],[zzuf],[no]) 8959 AS_VAR_IF([ZZUF],["no"], 8960 [ 8961 run_zzuf_tests="no" 8962 run_zzuf_tests_MSG="no, zzuf tool not found" 8963 ], 8964 [ 8965 AC_PATH_PROG([SOCAT],[socat],[no]) 8966 AS_IF([test "x${ac_cv_func_accept4}" = "xyes" && test "x${enable_asserts}" = "xno"], 8967 [ 8968 zzuf_socat_mandatory="yes" 8969 AS_VAR_IF([SOCAT],["no"], 8970 [run_zzuf_tests_MSG="no, socat not found, but required for fuzzing tests on this platform without asserts enabled"], 8971 [ 8972 run_zzuf_tests="yes" 8973 run_zzuf_tests_MSG="yes, with zzuf and socat tools" 8974 ] 8975 ) 8976 ], 8977 [test -n "${enabled_sanitizers}"], 8978 [ 8979 zzuf_socat_mandatory="yes" 8980 AS_VAR_IF([SOCAT],["no"], 8981 [run_zzuf_tests_MSG="no, socat not found, but required for fuzzing tests when sanitizers enabled"], 8982 [ 8983 run_zzuf_tests="yes" 8984 run_zzuf_tests_MSG="yes, with zzuf and socat tools" 8985 ] 8986 ) 8987 ], 8988 [ 8989 run_zzuf_tests="yes" 8990 run_zzuf_tests_MSG="yes, with zzuf tool" 8991 ] 8992 ) 8993 ] 8994 ) 8995 ], 8996 [ 8997 run_zzuf_tests="no" 8998 run_zzuf_tests_MSG="no, tests with libcurl are not enabled" 8999 ] 9000 ) 9001 ], 9002 [ 9003 run_zzuf_tests="no" 9004 run_zzuf_tests_MSG="no, heavy tests are not enabled" 9005 ] 9006 ) 9007 AM_CONDITIONAL([RUN_ZZUF_TESTS],[test "x$run_zzuf_tests" = "xyes"]) 9008 AM_CONDITIONAL([FORCE_USE_ZZUF_SOCAT],[test "x$zzuf_socat_mandatory" = "xyes"]) 9009 9010 # Final flags that may interfere with autoconf detections 9011 AS_CASE([${enable_build_type}],[debug|debugger], 9012 [ # Debug build or build for walking with debugger 9013 CFLAGS="${user_CFLAGS}" 9014 MHD_CHECK_ADD_CC_CFLAGS([-Wextra-semi -Wextra-semi-stmt], [CFLAGS_ac]) 9015 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wleading-whitespace=spaces], [-Wleading-whitespace]) 9016 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 9017 ] 9018 ) 9019 9020 AM_CONDITIONAL([USE_SANITIZERS], 9021 [test -n "$enabled_sanitizers" && test "x$mhd_cv_cc_sanitizer_works" = "xyes"]) 9022 AC_SUBST([AM_ASAN_OPTIONS]) 9023 AC_SUBST([AM_UBSAN_OPTIONS]) 9024 AC_SUBST([AM_LSAN_OPTIONS]) 9025 AC_SUBST([TESTS_ENVIRONMENT_ac]) 9026 9027 MHD_LIB_LDFLAGS="$MHD_LIB_LDFLAGS" 9028 9029 AC_SUBST([CPU_COUNT]) 9030 AC_SUBST([HEAVY_TESTS_NOTPARALLEL]) 9031 AM_SUBST_NOTMAKE([HEAVY_TESTS_NOTPARALLEL]) 9032 AC_SUBST(MHD_LIB_CPPFLAGS) 9033 AC_SUBST(MHD_LIB_CFLAGS) 9034 AC_SUBST(MHD_LIB_LDFLAGS) 9035 AC_SUBST(MHD_LIBDEPS) 9036 AC_SUBST(MHD_TLS_LIB_CPPFLAGS) 9037 AC_SUBST(MHD_TLS_LIB_LDFLAGS) 9038 AC_SUBST(MHD_TLS_LIBDEPS) 9039 9040 # for pkg-config 9041 AC_SUBST([MHD_REQ_PRIVATE]) 9042 AC_SUBST([MHD_LIBDEPS_PKGCFG]) 9043 9044 # Restore flags as set by the user 9045 CFLAGS="${user_CFLAGS}" 9046 LDFLAGS="${user_LDFLAGS}" 9047 CPPFLAGS="${user_CPPFLAGS}" 9048 AC_SUBST([CFLAGS]) 9049 AC_SUBST([LDFLAGS]) 9050 AC_SUBST([CPPFLAGS]) 9051 AC_SUBST([LIBS]) 9052 9053 # Configure-defined flags 9054 AC_SUBST([CFLAGS_ac]) 9055 AC_SUBST([LDFLAGS_ac]) 9056 AC_SUBST([CPPFLAGS_ac]) 9057 9058 # Used for 'po' directory staff 9059 AC_SUBST([ac_configure_args]) 9060 AC_SUBST([EMPTY_VAR],[]) 9061 AC_SUBST([MHD_AUX_DIR]) 9062 AC_CONFIG_FILES([po/po-configure.ac]) 9063 AC_CONFIG_COMMANDS([po/Makefile.in], 9064 [ 9065 echo "Skipping update of po/Makefile.in" 9066 echo "Real update of po/Makefile.in for 'make dist' is performed by po-config.status" 9067 ] 9068 ) 9069 AC_CONFIG_COMMANDS([po-directories], 9070 [ 9071 echo "Skipping po-directories command." 9072 echo "Real po-directories command for 'make dist' is implemented in po-config.status" 9073 ] 9074 ) 9075 9076 # We define the paths here, because MinGW/GCC expands paths 9077 # passed through the command line ("-DDIR=..."). This would 9078 # lead to hard-coded paths ("C:\mingw\mingw\bin...") that do 9079 # not contain the actual installation. 9080 AC_DEFINE_DIR([MHD_PLUGIN_INSTALL_PREFIX], [libdir/libmicrohttpd], [tls plugins]) 9081 9082 AC_SUBST([ZZUF]) 9083 AC_SUBST([SOCAT]) 9084 9085 # should experimental code be compiled (code that may not yet compile)? 9086 AC_MSG_CHECKING(whether to compile experimental code) 9087 AC_ARG_ENABLE([experimental], 9088 [AS_HELP_STRING([--enable-experimental], [enable compiling experimental code])], 9089 [enable_experimental=${enableval}], 9090 [enable_experimental=no]) 9091 AC_MSG_RESULT($enable_experimental) 9092 AM_CONDITIONAL([HAVE_EXPERIMENTAL], [test "x$enable_experimental" = "xyes"]) 9093 9094 9095 AC_CONFIG_FILES([ 9096 src/mhd2/libmicrohttpd2.pc 9097 src/mhd2/w32_lib_res.rc 9098 w32/common/microhttpd2.rc 9099 Makefile 9100 contrib/Makefile 9101 doc/Makefile 9102 m4/Makefile 9103 src/Makefile 9104 src/incl_priv/Makefile 9105 src/incl_priv/config/Makefile 9106 src/include/Makefile 9107 src/mhd2/Makefile 9108 src/tools/Makefile 9109 src/tests/Makefile 9110 src/tests/unit/Makefile 9111 src/tests/basic/Makefile 9112 src/tests/upgrade/Makefile 9113 src/tests/raw/Makefile 9114 src/tests/client_server/Makefile 9115 src/examples2/Makefile 9116 ]) 9117 AC_OUTPUT 9118 9119 # Finally: summary 9120 # Format flags without extra spaces for visual beauty 9121 fin_CPPFLAGS="$user_CPPFLAGS" 9122 fin_CFLAGS="$user_CFLAGS" 9123 fin_LDFLAGS="$user_LDFLAGS" 9124 MHD_PREPEND_FLAG_TO_VAR([fin_CPPFLAGS],[$CPPFLAGS_ac]) 9125 MHD_PREPEND_FLAG_TO_VAR([fin_CFLAGS],[$CFLAGS_ac]) 9126 MHD_PREPEND_FLAG_TO_VAR([fin_LDFLAGS],[$LDFLAGS_ac]) 9127 fin_lib_CPPFLAGS="$user_CPPFLAGS" 9128 fin_lib_CFLAGS="$user_CFLAGS" 9129 fin_lib_LDFLAGS="$user_LDFLAGS" 9130 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CPPFLAGS],[$MHD_LIB_CPPFLAGS]) 9131 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CFLAGS],[$MHD_LIB_CFLAGS]) 9132 MHD_PREPEND_FLAG_TO_VAR([fin_lib_LDFLAGS],[$MHD_LIB_LDFLAGS]) 9133 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CPPFLAGS],[$CPPFLAGS_ac]) 9134 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CFLAGS],[$CFLAGS_ac]) 9135 MHD_PREPEND_FLAG_TO_VAR([fin_lib_LDFLAGS],[$LDFLAGS_ac]) 9136 AC_MSG_NOTICE([Toolchain settings: 9137 CC=$CC 9138 User/system/default flags: 9139 CPPFLAGS="$user_CPPFLAGS" 9140 CFLAGS= "$user_CFLAGS" 9141 LDFLAGS= "$user_LDFLAGS" 9142 Final set of the flags for tests and examples: 9143 CPPFLAGS="$fin_CPPFLAGS" 9144 CFLAGS= "$fin_CFLAGS" 9145 LDFLAGS= "$fin_LDFLAGS" 9146 Final set of the flags for ${PACKAGE_NAME} library: 9147 CPPFLAGS="$fin_lib_CPPFLAGS" 9148 CFLAGS= "$fin_lib_CFLAGS" 9149 LDFLAGS= "$fin_lib_LDFLAGS" 9150 ]) 9151 AS_UNSET([fin_CPPFLAGS]) 9152 AS_UNSET([fin_CFLAGS]) 9153 AS_UNSET([fin_LDFLAGS]) 9154 AS_UNSET([fin_lib_CPPFLAGS]) 9155 AS_UNSET([fin_lib_CFLAGS]) 9156 AS_UNSET([fin_lib_LDFLAGS]) 9157 9158 AS_VAR_IF([os_is_windows], ["yes"], 9159 [os_ver_msg=" 9160 Target W32 ver : ${mhd_w32_ver_msg}"], [AS_UNSET([[os_ver_msg]])]) 9161 9162 AC_MSG_NOTICE([[${PACKAGE_NAME} ${PACKAGE_VERSION} Configuration Summary: 9163 [ Target platform ] 9164 Target directory : ${prefix} 9165 Cross-compiling : ${cross_compiling} 9166 Operating System : ${mhd_host_os}${os_ver_msg} 9167 Threading lib : ${USE_THREADS} 9168 Shutdown of listening socket triggers select: ${mhd_cv_host_shtdwn_trgr_select} 9169 9170 [ Library features and options ] 9171 HTTP/2 support : ${enable_http2} 9172 Inter-thread comm: ${use_itc} 9173 select() support : ${enable_select} 9174 poll() support : ${enable_poll=no} 9175 epoll support : ${enable_epoll=no} 9176 sendfile() : ${found_sendfile} 9177 HTTPS support : ${MSG_HTTPS} 9178 TLS backends : ${MSG_TLS_BACKENDS} 9179 Cookie parser : ${enable_cookie} 9180 POST parser : ${enable_postparser} 9181 Basic auth. : ${enable_basic_auth} 9182 Digest auth. : ${enable_digest_auth} 9183 Digest auth. defaults: ${dauth_defs_MSG} 9184 MD5 : ${enable_md5_MSG} 9185 SHA-256 : ${enable_sha256_MSG} 9186 SHA-512/256 : ${enable_sha512_256_MSG} 9187 HTTP "Upgrade" : ${enable_httpupgrade} 9188 Logging support : ${enable_log_messages} 9189 Verbose auto replies: ${enable_http_messages} 9190 9191 [ Code build options ] 9192 Compact code : ${enable_compact_code} (${compact_code_MSG}) 9193 Use thread names : ${enable_thread_names} 9194 Use debug asserts: ${use_asserts_MSG=no} 9195 Use sanitizers : ${enabled_sanitizers:=no} 9196 9197 [ Build items ] 9198 Build static lib : ${enable_static} 9199 Build shared lib : ${enable_shared} 9200 Build docs : ${enable_doc} 9201 Build examples : ${enable_examples} 9202 Build tools : ${enable_tools} 9203 9204 [ Test-suite settings ] 9205 Test with libcurl: ${MSG_CURL} 9206 Slow tests : ${enable_slow_tests} 9207 Heavy tests : ${use_heavy_tests_MSG} 9208 Fuzzing tests : ${run_zzuf_tests_MSG=no} 9209 ]]) 9210 9211 licence_num="0" 9212 AS_VAR_IF([have_gnutls],["yes"], 9213 [AS_IF([test "2" -gt "$licence_num"],[licence_num="2"])] 9214 ) 9215 AS_VAR_IF([have_openssl],["yes"], 9216 [AS_IF([test "3" -gt "$licence_num"],[licence_num="3"])] 9217 ) 9218 AS_VAR_IF([have_mbedtls],["yes"], 9219 [AS_IF([test "3" -gt "$licence_num"],[licence_num="3"])] 9220 ) 9221 AS_CASE([$licence_num], 9222 [0],[licence_descr="LGPLv2.1+ or eCos"], 9223 [2],[licence_descr="LGPL version 2.1 or any later version"], 9224 [3],[licence_descr="LGPL version 3.0 or any later version"], 9225 [AC_MSG_ERROR(internal error: unexpected licence version)] 9226 ) 9227 9228 AC_MSG_NOTICE([[ 9229 [ Licence due to TLS backends used ] 9230 Library licence : ${licence_descr} 9231 ]]) 9232 9233 AS_IF([test "x$enable_basic_auth" != "xyes" || \ 9234 test "x$enable_digest_auth" != "xyes" || \ 9235 test "x${enable_md5}" = "xno" || \ 9236 test "x${enable_sha256}" = "xno" || \ 9237 test "x${enable_sha512_256}" = "xno" || \ 9238 test "x${USE_THREADS}" = "xnone" || \ 9239 test "x$enable_httpupgrade" != "xyes" || \ 9240 test "x$enable_cookie" != "xyes" || \ 9241 test "x$enable_httpupgrade" != "xyes" || \ 9242 test "x$enable_postparser" != "xyes"], 9243 [AC_MSG_WARN([This will be a custom build with missing symbols. Do NOT use this build in a distribution. Building with these kinds of configure options is only for custom builds for embedded systems.])] 9244 ) 9245 AS_IF([test -n "${CONF_FINAL_WARNS}"],[AC_MSG_WARN([${CONF_FINAL_WARNS}])])