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