configure.ac (196548B)
1 # This file is part of libmicrohttpd. 2 # (C) 2006-2021 Christian Grothoff (and other contributing authors) 3 # (C) 2014-2024 Evgeny Grin (Karlson2k) 4 # 5 # libmicrohttpd is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published 7 # by the Free Software Foundation; either version 3, or (at your 8 # option) any later version. 9 # 10 # libmicrohttpd is distributed in the hope that it will be useful, but 11 # WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 # General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with libmicrohttpd; see the file COPYING. If not, write to the 17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 # Boston, MA 02110-1301, USA. 19 # 20 # 21 # Process this file with autoconf to produce a configure script. 22 # 23 # 24 AC_PREREQ([2.64]) 25 LT_PREREQ([2.4.0]) 26 AC_INIT([GNU libmicrohttpd],[1.0.2],[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([MHD_config.h]) 30 AC_CONFIG_MACRO_DIR([m4]) 31 m4_pattern_forbid([^_?MHD_[A-Z_]+_CC_])dnl 32 33 LIB_VERSION_CURRENT=74 34 LIB_VERSION_REVISION=2 35 LIB_VERSION_AGE=62 36 AC_SUBST([LIB_VERSION_CURRENT]) 37 AC_SUBST([LIB_VERSION_REVISION]) 38 AC_SUBST([LIB_VERSION_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_VERSION_CURRENT - $LIB_VERSION_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 AC_CONFIG_FILES([src/microhttpd/microhttpd_dll_res.rc]) 50 51 CONF_FINAL_WARNS="" 52 53 MHD_LIB_CPPFLAGS="" 54 MHD_LIB_CFLAGS="" 55 MHD_LIB_LDFLAGS="" 56 MHD_LIBDEPS="" 57 # for pkg-config 58 MHD_REQ_PRIVATE='' 59 MHD_LIBDEPS_PKGCFG='' 60 61 AS_IF([test -z "$CC" && test -z "$CPP"], [ 62 AC_MSG_CHECKING([[whether z/OS special settings are required]]) 63 AS_IF([test `uname -s` = "OS/390"], 64 [ 65 # configure binaries for z/OS 66 AS_IF([test -z "$CC"], 67 [CC=`pwd`"/contrib/xcc" 68 chmod +x $CC || true]) 69 AS_IF([test -z "$CPP"], 70 CPP="c89 -E") 71 AC_MSG_RESULT([[yes]]) 72 ], 73 [AC_MSG_RESULT([[no]])] 74 ) 75 ]) 76 77 78 AC_MSG_CHECKING([for build type]) 79 AC_ARG_ENABLE([build-type], 80 [AS_HELP_STRING([[--enable-build-type=TYPE]], 81 [enable build TYPE, a set of configuration parameters; individual settings ] 82 [(asserts, sanitizers, compiler and linker flags) can be overridden by ] 83 [additional configure parameters (debug, debugger, neutral, release, release-compact, ] 84 [release-hardened) [neutral]])], 85 [], [enable_build_type=neutral]) 86 AS_IF([test "x${enable_build_type}" = "x"], [enable_build_type="neutral"]) 87 AS_VAR_IF([enable_build_type], ["no"], [enable_build_type="neutral"]) 88 AS_VAR_IF([enable_build_type], ["yes"], [AC_MSG_ERROR([[Missing TYPE for --enable-build-type=]])]) 89 AS_CASE([${enable_build_type}], 90 [debug], [AC_MSG_RESULT([debug. Defaults: enable asserts, sanitizers (if any supported), debug information, compiler optimisation for debugging])], 91 [debugger], [AC_MSG_RESULT([debugger. Defaults: enable asserts, disable sanitizers, debug information, no compiler optimisation, static lib])], 92 [neutral], [AC_MSG_RESULT([neutral. Defaults: use only user-specified compiler and linker flags])], 93 [release], [AC_MSG_RESULT([release. Defaults: disable asserts, enable compiler optimisations])], 94 [release-compact], [AC_MSG_RESULT([release-compact. Defaults: disable asserts, enable compiler optimisations for size, enable compact code])], 95 [release-hardened], [AC_MSG_RESULT([release-hardened. Defaults: disable asserts, enable compiler optimisations, enable linker and compiler hardening])], 96 [AC_MSG_ERROR([[Unknown build type: ${enable_build_type}]])] 97 ) 98 AS_VAR_IF([enable_build_type], ["neutral"], [:], 99 [ 100 # For all non-neutral build types do not use automatic "-g -O2" for CFLAGS 101 AS_IF([test -z "${CFLAGS}"], [CFLAGS=""]) 102 ] 103 ) 104 AS_VAR_IF([enable_build_type], ["debugger"], 105 [ # Build only static version unless something else is specified by the user 106 AS_IF([test -z "${enable_static}" || test "x${enable_static}" = "xyes"], 107 [ 108 AS_IF([test -z "${enable_shared}"], 109 [ 110 enable_shared="no" 111 enable_static="yes" 112 ] 113 ) 114 ], 115 [ 116 AS_CASE([${enable_static}],[*libmicrohttpd*], 117 [AS_IF([test -z "${enable_shared}"], [enable_shared="no"])], 118 ) 119 ] 120 ) 121 ] 122 ) 123 AS_CASE([${enable_build_type}],[debug|debugger], 124 [ AS_IF([test -z "${enable_silent_rules}"], [ enable_silent_rules="yes" ])] 125 ) 126 127 AM_INIT_AUTOMAKE([gnu] [check-news] [filename-length-max=99] [tar-v7] [silent-rules] [subdir-objects]) 128 129 # Checks for programs. 130 AC_PROG_AWK 131 AC_PROG_GREP 132 AC_PROG_FGREP 133 AC_PROG_INSTALL 134 AC_PROG_LN_S 135 AC_PROG_MAKE_SET 136 AC_CANONICAL_HOST 137 m4_version_prereq([2.70], 138 [ 139 # Find C compiler and compiler options to support 140 # the latest C standard (C11). Fallback to C99 and C89 141 # if later C versions are not supported. 142 AC_PROG_CC 143 ], 144 [ 145 # Find C compiler and compiler options to support 146 # the latest C standard (C99). Fallback to C89 147 # if later C versions are not supported. 148 AC_PROG_CC_STDC 149 ] 150 ) 151 152 # Workaround for libgcrypt 153 AS_IF([[test "x$lt_sysroot" != "x" && test "x$SYSROOT" = "x"]], [[SYSROOT="$lt_sysroot"]]) 154 user_CFLAGS="$CFLAGS" 155 user_LDFLAGS="$LDFLAGS" 156 user_CPPFLAGS="$CPPFLAGS" 157 158 CFLAGS_ac="" 159 LDFLAGS_ac="" 160 CPPFLAGS_ac="" 161 162 MHD_SYS_EXT([CPPFLAGS_ac]) 163 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 164 m4_version_prereq([2.72], 165 [ 166 AC_SYS_YEAR2038 167 ], 168 [ 169 AC_SYS_LARGEFILE 170 ] 171 ) 172 AC_FUNC_FSEEKO 173 LT_INIT([win32-dll]) 174 LT_LANG([Windows Resource]) 175 lt_prog_compiler_pic_RC="$lt_prog_compiler_pic_RC -DDLL_EXPORT" # Used only on W32 176 177 AC_ARG_ENABLE([compact-code], 178 [AS_HELP_STRING([[--enable-compact-code]], 179 [enable use of a reduced size version of the code, resulting in smaller ] 180 [binaries with a slight performance hit [auto]])], 181 [], [enable_compact_code=auto]) 182 AS_IF([test "x${enable_compact_code}" = "x"], [enable_compact_code="auto"]) 183 AH_TEMPLATE([[MHD_FAVOR_SMALL_CODE]], [Define to '1' to use compact code version]) 184 AH_TEMPLATE([[MHD_FAVOR_FAST_CODE]], [Define to '1' to use fast (and larger) code version]) 185 AS_UNSET([compact_code_MSG]) 186 AS_CASE([${enable_compact_code}], [auto], 187 [ 188 # Parameter not set. 189 # Check preprocessor macros 190 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE], 191 [ 192 enable_compact_code="yes" 193 compact_code_MSG="enabled by preprocessor macro" 194 ], 195 [],[/* no includes */] 196 ) 197 AC_CHECK_DECL([MHD_FAVOR_FAST_CODE], 198 [ 199 AS_VAR_IF([enable_compact_code],["yes"], 200 [AC_MSG_ERROR([Both MHD_FAVOR_SMALL_CODE and MHD_FAVOR_FAST_CODE macros are defined])] 201 ) 202 enable_compact_code="no" 203 compact_code_MSG="set by preprocessor macro" 204 ],[],[/* no includes */] 205 ) 206 207 AS_VAR_IF([enable_compact_code], ["auto"], 208 [ 209 # No preference by preprocessor macros 210 AC_CACHE_CHECK([whether compiler is configured to optimize for size], 211 [mhd_cv_cc_optim_size], 212 [ 213 AC_COMPILE_IFELSE( 214 [ 215 AC_LANG_PROGRAM([[ 216 #ifndef __OPTIMIZE_SIZE__ 217 #error Looks like compiler does not optimize for size 218 choke me now 219 #endif 220 ]],[]) 221 ], 222 [mhd_cv_cc_optim_size="yes"],[mhd_cv_cc_optim_size="no"] 223 ) 224 ] 225 ) 226 AS_VAR_IF([mhd_cv_cc_optim_size], ["yes"], 227 [ 228 enable_compact_code="yes" 229 compact_code_MSG="enabled automatically as compiler optimizes for size" 230 AC_DEFINE([MHD_FAVOR_SMALL_CODE],[1]) 231 ] 232 ) 233 ] 234 ) 235 236 AS_VAR_IF([enable_compact_code], ["auto"], 237 [ 238 # No preference by preprocessor macros and compiler flags 239 AS_CASE([${enable_build_type}],[*-compact], 240 [ 241 enable_compact_code="yes" 242 compact_code_MSG="enabled by --enable-build-type=${enable_build_type}" 243 AC_DEFINE([MHD_FAVOR_SMALL_CODE],[1]) 244 ] 245 ) 246 ] 247 ) 248 249 AS_VAR_IF([enable_compact_code], ["auto"], 250 [ 251 # No preference 252 enable_compact_code="no" 253 compact_code_MSG="by default" 254 AC_DEFINE([MHD_FAVOR_FAST_CODE],[1]) 255 ] 256 ) 257 ], 258 [yes], 259 [ 260 compact_code_MSG="enabled by configure parameter" 261 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE], 262 [], 263 [AC_DEFINE([MHD_FAVOR_SMALL_CODE],[1])],[/* no includes */] 264 ) 265 AC_CHECK_DECL([MHD_FAVOR_FAST_CODE], 266 [AC_MSG_ERROR([MHD_FAVOR_FAST_CODE macro is defined, --enable-compact-code could not be used]) 267 ], 268 [],[/* no includes */] 269 ) 270 ], 271 [no], 272 [ 273 compact_code_MSG="disabled by configure parameter" 274 AC_CHECK_DECL([MHD_FAVOR_FAST_CODE], 275 [], 276 [AC_DEFINE([MHD_FAVOR_FAST_CODE],[1])],[/* no includes */] 277 ) 278 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE], 279 [AC_MSG_ERROR([MHD_FAVOR_SMALL_CODE macro is defined, --disable-compact-code could not be used]) 280 ], 281 [],[/* no includes */] 282 ) 283 ], 284 [AC_MSG_ERROR([[Unknown parameter value: --enable-compact-code=${enable_compact_code}]])] 285 ) 286 287 AC_MSG_CHECKING([whether to use a reduced size version of the code]) 288 AC_MSG_RESULT([${enable_compact_code} (${compact_code_MSG})]) 289 290 291 CFLAGS="${user_CFLAGS}" 292 # Compiler options to always enable (if supported) 293 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-fno-strict-aliasing], [-qnoansialias]) 294 # '-qlonglong' is XLC option for C89, not used with C99 or later 295 MHD_CHECK_ADD_CC_CFLAG([-qlonglong], [CFLAGS_ac]) 296 297 # Set basic optimisation flags 298 AS_VAR_IF([enable_build_type],["neutral"],[], 299 [ # Any non-neutral build types 300 AC_CACHE_CHECK([whether workarounds for clang or clang-based compiler are required], 301 [mhd_cv_cc_clang_based], 302 [ 303 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 304 #if ! defined(__clang__) && ! defined(__llvm__) 305 #error Compiler is not clang-based 306 choke me now 307 #endif 308 ]] 309 ) 310 ], 311 [mhd_cv_cc_clang_based="yes"],[mhd_cv_cc_clang_based="no"] 312 ) 313 ] 314 ) 315 ] 316 ) 317 AS_CASE([${enable_build_type}],[debug|debugger], 318 [ # Debug build or build for walking with debugger 319 CFLAGS="${user_CFLAGS}" 320 AS_VAR_IF([enable_build_type],["debug"], 321 [ 322 # Clang has ASAN (pointer compare) broken when '-Og' optimisations are used 323 AS_IF([test "x${enable_sanitizers}" != "xno" && test "x${mhd_cv_cc_clang_based}" = "xyes"], 324 [MHD_CHECK_ADD_CC_CFLAG([-O0], [CFLAGS_ac])], 325 [MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Og], [-O0])] 326 ) 327 ], 328 [MHD_CHECK_ADD_CC_CFLAG([-O0], [CFLAGS_ac])] 329 ) 330 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 331 ] 332 ) 333 AS_CASE([${enable_build_type}],[release|release-*], 334 [ # All release types 335 AS_VAR_IF([enable_build_type],["release-compact"], 336 [ 337 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 338 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],[], 339 [AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],[], 340 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DMHD_FAVOR_SMALL_CODE=1])], 341 [/* no includes */])],[/* no includes */]) 342 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 343 CFLAGS="${user_CFLAGS}" 344 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Oz], [-Os], [-O]) 345 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 346 ], 347 [ # All non-compact release types 348 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 349 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],[], 350 [AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],[], 351 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DMHD_FAVOR_FAST_CODE=1])], 352 [/* no includes */])],[/* no includes */]) 353 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 354 CFLAGS="${user_CFLAGS}" 355 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-O2], [-O]) 356 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 357 ] 358 ) 359 ] 360 ) 361 362 AS_VAR_IF([enable_build_type],["neutral"],[], 363 [ # Any non-neutral build types 364 MHD_CHECK_ADD_CC_CFLAGS([-Wall -Wnull-dereference], [CFLAGS_ac]) 365 MHD_CHECK_ADD_CC_CFLAGS([-Wdeclaration-after-statement -Wimplicit -Wnested-externs], [CFLAGS_ac]) 366 MHD_CHECK_ADD_CC_CFLAGS([-Wredundant-decls -Wtrampolines -Wunsafe-loop-optimizations], [CFLAGS_ac]) 367 MHD_CHECK_ADD_CC_CFLAGS([-Wpoison-system-directories], [CFLAGS_ac]) 368 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 369 LDFLAGS="${user_LDFLAGS}" 370 MHD_CHECK_ADD_CC_LDFLAG([-Wl,--warn-common], [LDFLAGS_ac]) 371 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 372 ] 373 ) 374 AS_CASE([${enable_build_type}],[debug|debugger], 375 [ # Debug build or build for walking with debugger 376 CFLAGS="${user_CFLAGS}" 377 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-ggdb3], [-g3], [-ggdb], [-g]) 378 MHD_CHECK_ADD_CC_CFLAGS([-Wextra -Wdouble-promotion], [CFLAGS_ac]) 379 MHD_FIND_ADD_CC_CFLAG_IFELSE( 380 [ 381 # clang produce warning when string pointer is used as a format specifier for v*printf() function 382 AS_VAR_IF([mhd_cv_cc_clang_based],["yes"],[MHD_CHECK_ADD_CC_CFLAG([-Wno-format-nonliteral], [CFLAGS_ac])]) 383 ],[], 384 [CFLAGS_ac], [-Wformat=2], [-Wformat] 385 ) 386 MHD_CHECK_ADD_CC_CFLAGS([-Wformat-overflow -Wformat-truncation -Wformat-security -Wformat-signedness], [CFLAGS_ac]) 387 MHD_CHECK_ADD_CC_CFLAGS([-Wmissing-include-dirs -Wshift-overflow=2 -Wstringop-overflow=4 -Walloc-zero], [CFLAGS_ac]) 388 MHD_CHECK_ADD_CC_CFLAGS([-Wduplicated-branches -Wduplicated-cond -Wfloat-equal -Wshadow -Wpointer-arith], [CFLAGS_ac]) 389 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wshadow-all], [-Wshadow]) 390 MHD_CHECK_ADD_CC_CFLAGS([-Wbad-function-cast -Wcast-qual -Wwrite-strings -Wconversion], [CFLAGS_ac]) 391 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wcast-align=strict], [-Wcast-align]) 392 MHD_CHECK_ADD_CC_CFLAGS([-Wjump-misses-init -Wlogical-op -Waggregate-return -Wstrict-prototypes], [CFLAGS_ac]) 393 MHD_CHECK_ADD_CC_CFLAGS([-Wold-style-definition -Wmissing-declarations -Wmissing-prototypes], [CFLAGS_ac]) 394 MHD_CHECK_ADD_CC_CFLAGS([-Wuninitialized -Winit-self -Wshift-negative-value -Wswitch-enum], [CFLAGS_ac]) 395 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wstrict-overflow=4], [-Wstrict-overflow]) 396 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wnormalized=nfkc], [-Wnormalized]) 397 MHD_CHECK_ADD_CC_CFLAGS([-Walloca -Wbidi-chars=any -Warray-bounds -Wpacked -Wvariadic-macros], [CFLAGS_ac]) 398 MHD_CHECK_ADD_CC_CFLAGS([-Wundef], [CFLAGS_ac]) 399 400 MHD_CHECK_ADD_CC_CFLAGS([-Wanon-enum-enum-conversion -Warray-bounds-pointer-arithmetic -Wassign-enum], [CFLAGS_ac]) 401 MHD_CHECK_ADD_CC_CFLAGS([-Wbit-int-extension -Wbitfield-enum-conversion -Wparentheses -Wbool-operation], [CFLAGS_ac]) 402 MHD_CHECK_ADD_CC_CFLAGS([-Wcast-function-type -Wcomma -Wcomment -Wcompound-token-split], [CFLAGS_ac]) 403 MHD_CHECK_ADD_CC_CFLAGS([-Wconditional-uninitialized -Wdeprecated], [CFLAGS_ac]) 404 MHD_CHECK_ADD_CC_CFLAGS([-Wdocumentation-pedantic -Wempty-init-stmt -Wenum-conversion -Wexpansion-to-defined], [CFLAGS_ac]) 405 MHD_CHECK_ADD_CC_CFLAGS([-Wflexible-array-extensions -Wloop-analysis -Wformat-pedantic], [CFLAGS_ac]) 406 MHD_CHECK_ADD_CC_CFLAGS([-Wformat-type-confusion -Wfour-char-constants], [CFLAGS_ac]) 407 MHD_CHECK_ADD_CC_CFLAGS([-Wgcc-compat -Wgnu-anonymous-struct -Wgnu-compound-literal-initializer], [CFLAGS_ac]) 408 MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-conditional-omitted-operand -Wgnu-designator -Wgnu-empty-initializer], [CFLAGS_ac]) 409 MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-empty-struct -Wgnu-flexible-array-initializer -Wgnu-folding-constant], [CFLAGS_ac]) 410 MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-null-pointer-arithmetic -Wgnu-pointer-arith -Wgnu-redeclared-enum], [CFLAGS_ac]) 411 MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-union-cast -Wgnu-variable-sized-type-not-at-end -Widiomatic-parentheses], [CFLAGS_ac]) 412 MHD_CHECK_ADD_CC_CFLAGS([-Wmissing-noreturn -Wmissing-variable-declarations -Wnested-anon-types], [CFLAGS_ac]) 413 MHD_CHECK_ADD_CC_CFLAGS([-Wnewline-eof -Wover-aligned -Wredundant-parens], [CFLAGS_ac]) 414 MHD_CHECK_ADD_CC_CFLAGS([-Wshift-sign-overflow -Wtautological-compare -Wunaligned-access], [CFLAGS_ac]) 415 MHD_CHECK_ADD_CC_CFLAGS([-Wunused -Wzero-as-null-pointer-constant -Wzero-length-array], [CFLAGS_ac]) 416 MHD_CHECK_CC_CFLAG([-Wused-but-marked-unused],[CFLAGS_ac], 417 [ 418 AC_CACHE_CHECK([whether $[]CC -Wused-but-marked-unused works with system headers], 419 [mhd_cv_wused_but_marked_unused_sys_header], 420 [ 421 SAVE_ac_c_werror_flag="$ac_c_werror_flag" 422 ac_c_werror_flag="yes" 423 CFLAGS="${CFLAGS_ac} -Wused-but-marked-unused ${user_CFLAGS}" 424 AC_COMPILE_IFELSE( 425 [ 426 AC_LANG_SOURCE([[ 427 #include <stdio.h> 428 429 int main(void) 430 { 431 char buf[16]; 432 return (int) snprintf(buf, 16, "test"); 433 } 434 ]] 435 ) 436 ], 437 [mhd_cv_wused_but_marked_unused_sys_header="yes"], 438 [mhd_cv_wused_but_marked_unused_sys_header="no"] 439 ) 440 ac_c_werror_flag="$SAVE_ac_c_werror_flag" 441 ] 442 ) 443 AS_VAR_IF([mhd_cv_wused_but_marked_unused_sys_header],["yes"], 444 [MHD_APPEND_FLAG_TO_VAR([CFLAGS_ac],[-Wused-but-marked-unused])] 445 ) 446 ] 447 ) 448 # 449 # Removed flags: 450 # 451 # -Wdisabled-macro-expansion - warns about macros from system headers 452 453 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 454 LDFLAGS="${user_LDFLAGS}" 455 MHD_CHECK_ADD_CC_LDFLAG([-Wl,--enable-long-section-names], [LDFLAGS_ac]) 456 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 457 ] 458 ) 459 AS_CASE([${enable_build_type}],[release|release-*], 460 [ # All release types 461 CFLAGS="${user_CFLAGS}" 462 AS_VAR_IF([enable_build_type],["release-compact"], 463 [], 464 [ # All non-compact release types 465 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 466 MHD_CHECK_ADD_CC_CFLAGS([-ftree-partial-pre -fgcse-after-reload -fipa-pta], [CFLAGS_ac]) 467 MHD_CHECK_ADD_CC_CFLAGS([-fisolate-erroneous-paths-attribute -ffinite-loops -floop-nest-optimize], [CFLAGS_ac]) 468 MHD_CHECK_ADD_CC_CFLAGS([-fpredictive-commoning -frename-registers], [CFLAGS_ac]) 469 MHD_CHECK_ADD_CC_CFLAGS([-ftree-loop-distribute-patterns -fpeel-loops -fsplit-loops -ftree-vectorize], [CFLAGS_ac]) 470 ] 471 ) 472 473 AS_VAR_IF([enable_build_type],["release-hardened"], 474 [ 475 MHD_CHECK_ADD_CC_CFLAGS([-Wformat-security -Wstack-protector], [CFLAGS_ac]) 476 MHD_CHECK_ADD_CC_CFLAGS([-Wuninitialized -Winit-self -Walloc-zero -Wbidi-chars=any], [CFLAGS_ac]) 477 ] 478 ) 479 AS_VAR_IF([enable_build_type],["release"], 480 [ # Flags are not suitable for 'compact' and for 'hardened' 481 MHD_CHECK_ADD_CC_CFLAGS([-ffast-math -fno-trapping-math], [CFLAGS_ac]) 482 ] 483 ) 484 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 485 # W32-specific 486 LDFLAGS="${user_LDFLAGS}" 487 MHD_CHECK_ADD_CC_LDFLAG([-Wl,--disable-long-section-names], [LDFLAGS_ac]) 488 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 489 ] 490 ) 491 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 492 # Additional flags are checked and added at the end of 'configure' 493 494 # Check for headers that are ALWAYS required 495 AC_CHECK_HEADERS_ONCE([stdio.h string.h stdint.h errno.h limits.h fcntl.h], [], 496 [AC_MSG_ERROR([Compiling libmicrohttpd requires standard POSIX headers files])], [AC_INCLUDES_DEFAULT]) 497 498 # Check for basic optional headers 499 AC_CHECK_HEADERS([stddef.h stdlib.h inttypes.h sys/types.h sys/stat.h unistd.h \ 500 sys/uio.h], [], [], [AC_INCLUDES_DEFAULT]) 501 502 # Check for clock-specific optional headers 503 AC_CHECK_HEADERS([sys/time.h time.h], [], [], [AC_INCLUDES_DEFAULT]) 504 505 # Check for system information and parameters optional headers 506 AC_CHECK_HEADERS([endian.h machine/endian.h sys/endian.h sys/byteorder.h \ 507 sys/machine.h machine/param.h sys/param.h sys/isa_defs.h \ 508 sys/ioctl.h], [], [], [AC_INCLUDES_DEFAULT]) 509 510 # Check for network and sockets optional headers 511 AC_CHECK_HEADERS([sys/socket.h sys/select.h netinet/in_systm.h netinet/in.h \ 512 arpa/inet.h netinet/ip.h netinet/tcp.h net/if.h \ 513 netdb.h sockLib.h inetLib.h], [], [], 514 [AC_INCLUDES_DEFAULT 515 [ 516 #ifdef HAVE_SYS_TYPES_H 517 #include <sys/types.h> 518 #endif /* HAVE_SYS_TYPES_H */ 519 #ifdef HAVE_INTTYPES_H 520 #include <inttypes.h> 521 #endif /* HAVE_INTTYPES_H */ 522 #ifdef HAVE_SYS_SOCKET_H 523 #include <sys/socket.h> 524 #endif /* HAVE_SYS_SOCKET_H */ 525 #ifdef HAVE_NETINET_IN_SYSTM_H 526 #include <netinet/in_systm.h> 527 #endif /* HAVE_NETINET_IN_SYSTM_H */ 528 #ifdef HAVE_NETINET_IN_H 529 #include <netinet/in.h> 530 #endif /* HAVE_NETINET_IN_H */ 531 #ifdef HAVE_NETINET_IP_H 532 #include <netinet/ip.h> 533 #endif /* HAVE_NETINET_IP_H */ 534 #ifdef HAVE_NETINET_TCP_H 535 #include <netinet/tcp.h> 536 #endif /* HAVE_NETINET_TCP_H */ 537 ]] 538 ) 539 540 # Check for other optional headers 541 AC_CHECK_HEADERS([sys/msg.h sys/mman.h signal.h], [], [], [AC_INCLUDES_DEFAULT]) 542 543 AC_CHECK_HEADER([[search.h]], 544 [ 545 MHD_CHECK_LINK_RUN([[for proper tsearch(), tfind() and tdelete()]],[[mhd_cv_sys_tsearch_usable]], 546 [ 547 AS_CASE([$host_os], 548 [openbsd*], 549 [[ # Some OpenBSD versions have wrong return value for tdelete() 550 mhd_cv_sys_tsearch_usable='assuming no' 551 ]], 552 [netbsd*], 553 [[ # NetBSD had leaked root node for years 554 mhd_cv_sys_tsearch_usable='assuming no' 555 ]], 556 [[mhd_cv_sys_tsearch_usable='assuming yes']] 557 ) 558 ], 559 [ 560 AC_LANG_SOURCE( 561 [[ 562 #ifdef HAVE_STDDEF_H 563 #include <stddef.h> 564 #endif /* HAVE_STDDEF_H */ 565 #ifdef HAVE_STDLIB_H 566 #include <stdlib.h> 567 #endif /* HAVE_STDLIB_H */ 568 569 #include <stdio.h> 570 #include <search.h> 571 572 static int cmp_func(const void *p1, const void *p2) 573 { 574 return (*((const int *)p1)) - (*((const int *)p2)); 575 } 576 577 int main(void) 578 { 579 int ret = 0; 580 void *root_ptr = NULL; 581 int element1 = 1; 582 int **element_ptr_ptr1; 583 int **element_ptr_ptr2; 584 585 element_ptr_ptr1 = 586 (int **) tsearch ((void*) &element1, &root_ptr, &cmp_func); 587 if (NULL == element_ptr_ptr1) 588 { 589 fprintf (stderr, "NULL pointer has been returned when tsearch() called for the first time.\n"); 590 return ++ret; 591 } 592 if (*element_ptr_ptr1 != &element1) 593 { 594 fprintf (stderr, "Wrong pointer has been returned when tsearch() called for the first time.\n"); 595 return ++ret; 596 } 597 if (NULL == root_ptr) 598 { 599 fprintf (stderr, "Root pointer has not been set by tsearch().\n"); 600 return ++ret; 601 } 602 603 element_ptr_ptr2 = 604 (int **) tsearch ((void*) &element1, &root_ptr, &cmp_func); 605 if (NULL == element_ptr_ptr2) 606 { 607 fprintf (stderr, "NULL pointer has been returned when tsearch() called for the second time.\n"); 608 return ++ret; 609 } 610 if (*element_ptr_ptr2 != &element1) 611 { 612 fprintf (stderr, "Wrong pointer has been returned when tsearch() called for the second time.\n"); 613 ++ret; 614 } 615 if (element_ptr_ptr2 != element_ptr_ptr1) 616 { 617 fprintf (stderr, "Wrong element has been returned when tsearch() called for the second time.\n"); 618 ++ret; 619 } 620 621 element_ptr_ptr2 = 622 (int **) tfind ((void*) &element1, &root_ptr, &cmp_func); 623 if (NULL == element_ptr_ptr2) 624 { 625 fprintf (stderr, "NULL pointer has been returned by tfind().\n"); 626 ++ret; 627 } 628 if (*element_ptr_ptr2 != &element1) 629 { 630 fprintf (stderr, "Wrong pointer has been returned when by tfind().\n"); 631 ++ret; 632 } 633 if (element_ptr_ptr2 != element_ptr_ptr1) 634 { 635 fprintf (stderr, "Wrong element has been returned when tsearch() called for the second time.\n"); 636 ++ret; 637 } 638 639 element_ptr_ptr1 = 640 (int **) tdelete ((void*) &element1, &root_ptr, &cmp_func); 641 if (NULL == element_ptr_ptr1) 642 { 643 fprintf (stderr, "NULL pointer has been returned by tdelete().\n"); 644 ++ret; 645 } 646 if (NULL != root_ptr) 647 { 648 fprintf (stderr, "Root pointer has not been set to NULL by tdelete().\n"); 649 ++ret; 650 } 651 652 return ret; 653 } 654 ]] 655 ) 656 ], 657 [AC_DEFINE([[MHD_USE_SYS_TSEARCH]], [[1]], [Define to 1 if you have properly working tsearch(), tfind() and tdelete() functions.])] 658 ) 659 ], 660 [], [AC_INCLUDES_DEFAULT] 661 ) 662 AM_CONDITIONAL([MHD_USE_SYS_TSEARCH], [[test "x$mhd_cv_sys_tsearch_usable" = "xyes" || test "x$mhd_cv_sys_tsearch_usable" = "xassuming yes"]]) 663 664 # Optional headers used for tests 665 AC_CHECK_HEADERS([sys/sysctl.h netinet/ip_icmp.h netinet/icmp_var.h], [], [], 666 [[ 667 #ifdef HAVE_SYS_TYPES_H 668 #include <sys/types.h> 669 #endif /* HAVE_SYS_TYPES_H */ 670 #ifdef HAVE_SYS_SYSCTL_H 671 #include <sys/sysctl.h> 672 #endif /* HAVE_SYS_SYSCTL_H */ 673 #ifdef HAVE_SYS_SOCKET_H 674 #include <sys/socket.h> 675 #endif /* HAVE_SYS_SOCKET_H */ 676 #ifdef HAVE_NETINET_IN_SYSTM_H 677 #include <netinet/in_systm.h> 678 #endif /* HAVE_NETINET_IN_SYSTM_H */ 679 #ifdef HAVE_NETINET_IN_H 680 #include <netinet/in.h> 681 #endif /* HAVE_NETINET_IN_H */ 682 #ifdef HAVE_NETINET_IP_H 683 #include <netinet/ip.h> 684 #endif /* HAVE_NETINET_IP_H */ 685 #ifdef HAVE_NETINET_IP_ICMP_H 686 #include <netinet/ip_icmp.h> 687 #endif /* HAVE_NETINET_IP_ICMP_H */ 688 ]] 689 ) 690 691 AC_ARG_ENABLE([compiler-hardening], 692 [AS_HELP_STRING([--enable-compiler-hardening], [enable compiler security checks])], 693 [], 694 [AS_CASE([${enable_build_type}],[*-hardened], 695 [enable_compiler_hardening='yes'],[enable_compiler_hardening='no'])] 696 ) 697 AS_VAR_IF([enable_compiler_hardening],["yes"], 698 [ 699 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 700 AC_CHECK_DECL([_FORTIFY_SOURCE], 701 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-U_FORTIFY_SOURCE])], 702 [],[/* no includes */]) 703 MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-D_FORTIFY_SOURCE=2]) 704 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 705 CFLAGS="${user_CFLAGS}" 706 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac],[-fstack-protector-strong],[-fstack-protector-all],[-fstack-protector]) 707 MHD_CHECK_ADD_CC_CFLAGS([-fstack-clash-protection],[CFLAGS_ac]) 708 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac],[-ftrivial-auto-var-init=pattern],[-ftrivial-auto-var-init=zero]) 709 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 710 AS_IF([test "x${enable_static}" = "xyes" && test "x${pic_mode}" != "xyes"], 711 [ 712 # PIE static lib can be used within non-PIE application, but 713 # PIE static lib cannot be used in non-PIE shared lib. Let's assume 714 # that static lib will not be used in shared lib 715 # All "pie" flags will be used automatically by libtool only 716 # for static library objects. 717 CFLAGS="${user_CFLAGS}" 718 # Perform tests here with "-pie" enabled 719 LDFLAGS="${LDFLAGS_ac} -pie ${user_LDFLAGS}" 720 MHD_CHECK_ADD_CC_CFLAG([-fPIE],[CFLAGS_ac], 721 [ 722 MHD_APPEND_FLAG_TO_VAR([LDFLAGS_ac],[-pie]) 723 ], 724 [ 725 MHD_CHECK_ADD_CC_CFLAG([-fpie],[CFLAGS_ac], 726 [ 727 MHD_APPEND_FLAG_TO_VAR([LDFLAGS_ac],[-pie]) 728 ] 729 ) 730 ] 731 ) 732 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 733 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 734 ] 735 ) 736 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 737 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 738 ] 739 ) 740 741 # Linker hardening options 742 # Currently these options are ELF specific, they don't work on Darwin and W32 743 AC_ARG_ENABLE([linker-hardening], 744 [AS_HELP_STRING([--enable-linker-hardening], [enable linker security fixups])], 745 [], 746 [AS_CASE([${enable_build_type}],[*-hardened], 747 [enable_linker_hardening='yes'],[enable_linker_hardening='no'])] 748 ) 749 AS_VAR_IF([enable_linker_hardening],["yes"], 750 [ 751 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 752 LDFLAGS="${user_LDFLAGS}" 753 MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,relro],[LDFLAGS_ac], 754 [MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,now],[LDFLAGS_ac])]) 755 # Actually should be "noexec" by default, but let's try to enforce it. 756 MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,noexecstack],[LDFLAGS_ac]) 757 # W32-specific. Some are enabled by default, but they will be enfored to be sure. 758 MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--large-address-aware -Wl,--enable-auto-image-base],[LDFLAGS_ac]) 759 MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va],[LDFLAGS_ac]) 760 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 761 ] 762 ) 763 764 MHD_BOOL 765 766 AC_C_INLINE 767 AS_UNSET([errattr_CFLAGS]) 768 CFLAGS="${user_CFLAGS}" 769 MHD_CHECK_CC_CFLAG([-Werror=attributes],[CFLAGS_ac], 770 [ 771 AC_CACHE_CHECK([whether -Werror=attributes actually works],[mhd_cv_cflag_werror_attr_works], 772 [ 773 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} -Werror=attributes" 774 AC_COMPILE_IFELSE([ 775 AC_LANG_PROGRAM( 776 [[__attribute__((non_existing_attrb_dummy)) static int SimpleFunc(void) {return 3;}]], 777 [[int r = SimpleFunc(); if (r) return r;]] 778 ) 779 ], 780 [mhd_cv_cflag_werror_attr_works="no"], 781 [mhd_cv_cflag_werror_attr_works="yes"] 782 ) 783 ] 784 ) 785 AS_VAR_IF([mhd_cv_cflag_werror_attr_works],["yes"], 786 [errattr_CFLAGS="-Werror=attributes"] 787 ) 788 ] 789 ) 790 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 791 AS_IF([test "x$ac_cv_c_inline" != "xno"], 792 [ 793 AC_DEFINE([HAVE_INLINE_FUNCS],[1],[Define to 1 if your C compiler supports inline functions.]) 794 AC_CACHE_CHECK([for function force inline keywords supported by $CC],[mhd_cv_cc_kwd_forceinline], 795 [ 796 MHD_SAVED_ac_c_werror_flag="$ac_c_werror_flag" 797 ac_c_werror_flag=yes 798 mhd_cv_cc_kwd_forceinline="none" 799 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} $errattr_CFLAGS" 800 for keyword_chk in "inline __attribute__((always_inline))" __forceinline 801 do 802 AS_CASE([${keyword_chk}], 803 [*attribute*], 804 [AS_IF([test "x$errattr_CFLAGS" = "x"],[continue])] 805 ) 806 AC_LINK_IFELSE([ 807 AC_LANG_SOURCE([[ 808 #ifdef HAVE_STDBOOL_H 809 #include <stdbool.h> 810 #endif 811 static ${keyword_chk} bool cmpfn(int x, int y) 812 { return x > y; } 813 static ${keyword_chk} int sumfn(int x, int y) 814 { return x + y; } 815 816 int main(void) 817 { 818 int a = 1, b = 100, c; 819 if (cmpfn(a, b)) 820 c = sumfn(a, b); 821 else 822 c = 0 - sumfn(a, b); 823 return (cmpfn(0, c) ? 0 : 5); 824 } 825 ]] 826 ) 827 ], 828 [mhd_cv_cc_kwd_forceinline="${keyword_chk}"] 829 ) 830 test "x${mhd_cv_cc_kwd_forceinline}" != "xnone" && break 831 done 832 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 833 ac_c_werror_flag="$MHD_SAVED_ac_c_werror_flag" 834 AS_UNSET([MHD_SAVED_ac_c_werror_flag]) 835 ] 836 ) 837 ] 838 ) 839 AS_IF([test "x$ac_cv_c_inline" != "xno" && test "x${mhd_cv_cc_kwd_forceinline}" != "xnone"], 840 [AC_DEFINE_UNQUOTED([_MHD_static_inline],[static $mhd_cv_cc_kwd_forceinline],[Define to prefix which will be used with MHD static inline functions.])] 841 , 842 [AC_DEFINE([_MHD_static_inline],[static inline],[Define to prefix which will be used with MHD static inline functions.])] 843 ) 844 845 AC_CHECK_HEADERS([stdalign.h], [], [], [AC_INCLUDES_DEFAULT]) 846 AC_CACHE_CHECK([[for C11 'alignof()' support]], [[mhd_cv_c_alignof]], 847 [AC_COMPILE_IFELSE( 848 [AC_LANG_PROGRAM( 849 [[ 850 #ifdef HAVE_STDALIGN_H 851 #include <stdalign.h> 852 #endif 853 ]], [[ 854 int var1[(alignof(int) >= 2) ? 1 : -1]; 855 int var2[alignof(unsigned int) - 1]; 856 int var3[(alignof(char) > 0) ? 1 : -1]; 857 int var4[(alignof(long) >= 4) ? 1 : -1]; 858 859 /* Mute compiler warnings */ 860 var1[0] = var2[0] = var3[0] = 0; 861 var4[0] = 1; 862 if (var1[0] + var2[0] + var3[0] == var4[0]) 863 return 1; 864 ]]) 865 ], [ 866 AC_COMPILE_IFELSE( 867 [AC_LANG_PROGRAM( 868 [[ 869 #ifdef HAVE_STDALIGN_H 870 #include <stdalign.h> 871 #endif 872 ]], [[ 873 /* Should fail if 'alignof()' works */ 874 int var1[alignof(nonexisting_type) - 1]; 875 876 /* Mute compiler warnings */ 877 var1[0] = 1; 878 if (var1[0] + 1 == 1) 879 return 1; 880 ]]) 881 ], [[mhd_cv_c_alignof='no']], [[mhd_cv_c_alignof='yes']]) 882 ], [[mhd_cv_c_alignof='no']]) 883 ]) 884 AS_VAR_IF([mhd_cv_c_alignof], ["yes"], 885 [AC_DEFINE([[HAVE_C_ALIGNOF]], [1], [Define to 1 if your compiler supports 'alignof()'])]) 886 887 888 # Check system type 889 AC_MSG_CHECKING([[for target host OS]]) 890 os_is_windows="no" 891 os_is_native_w32="no" 892 AS_CASE(["$host_os"], 893 [*darwin* | *rhapsody* | *macosx*], 894 [AC_DEFINE([OSX],[1],[This is an OS X system]) 895 mhd_host_os='Darwin' 896 AC_MSG_RESULT([[$mhd_host_os]])], 897 [kfreebsd*-gnu], 898 [AC_DEFINE([SOMEBSD],[1],[This is a BSD system]) 899 AC_DEFINE([FREEBSD],[1],[This is a FreeBSD system]) 900 mhd_host_os='FreeBSD kernel with GNU userland' 901 AC_MSG_RESULT([[$mhd_host_os]])], 902 [freebsd*], 903 [AC_DEFINE([SOMEBSD],[1],[This is a BSD system]) 904 AC_DEFINE([FREEBSD],[1],[This is a FreeBSD system]) 905 mhd_host_os='FreeBSD' 906 AC_MSG_RESULT([[$mhd_host_os]])], 907 [openbsd*], 908 [AC_DEFINE([SOMEBSD],[1],[This is a BSD system]) 909 AC_DEFINE([OPENBSD],[1],[This is an OpenBSD system]) 910 mhd_host_os='OpenBSD' 911 AC_MSG_RESULT([[$mhd_host_os]])], 912 [netbsd*], 913 [AC_DEFINE([SOMEBSD],[1],[This is a BSD system]) 914 AC_DEFINE([NETBSD],[1],[This is a NetBSD system]) 915 mhd_host_os='NetBSD' 916 AC_MSG_RESULT([[$mhd_host_os]])], 917 [*solaris*], 918 [AC_DEFINE([SOLARIS],[1],[This is a Solaris system]) 919 AC_DEFINE([_REENTRANT],[1],[Need with solaris or errno does not work]) 920 mhd_host_os='Solaris' 921 AC_MSG_RESULT([[$mhd_host_os]])], 922 [linux-gnu], 923 [AC_DEFINE([LINUX],[1],[This is a Linux kernel]) 924 mhd_host_os='GNU/Linux' 925 AC_MSG_RESULT([[$mhd_host_os]])], 926 [linux-android*], 927 [AC_DEFINE([LINUX],[1],[This is a Linux kernel]) 928 mhd_host_os='Android' 929 AC_MSG_RESULT([[$mhd_host_os]])], 930 [*linux*], 931 [AC_DEFINE([LINUX],[1],[This is a Linux kernel]) 932 mhd_host_os='Linux' 933 AC_MSG_RESULT([[$mhd_host_os]])], 934 [*cygwin*], 935 [AC_DEFINE([CYGWIN],[1],[This is a Cygwin system]) 936 mhd_host_os='Windows/Cygwin' 937 AC_MSG_RESULT([[$mhd_host_os]]) 938 os_is_windows="yes"], 939 [*mingw*], 940 [ 941 AC_DEFINE([MINGW],[1],[This is a MinGW system]) 942 AC_DEFINE([WINDOWS],[1],[This is a Windows system]) 943 mhd_host_os='Windows/MinGW' 944 AC_MSG_RESULT([[$mhd_host_os]]) 945 AC_CHECK_HEADERS([winsock2.h ws2tcpip.h], [], [AC_MSG_ERROR([[Winsock2 headers are required for W32]])], [AC_INCLUDES_DEFAULT]) 946 AC_CACHE_CHECK([for MS lib utility], [ac_cv_use_ms_lib_tool], 947 [mslibcheck=`lib 2>&1` 948 AS_IF([echo "$mslibcheck" | $GREP -e '^Microsoft (R) Library Manager' - >/dev/null], 949 [ac_cv_use_ms_lib_tool=yes], 950 [ac_cv_use_ms_lib_tool=no]) 951 ]) 952 AS_IF([test "x$ac_cv_use_ms_lib_tool" = "xyes"], 953 [AC_SUBST([MS_LIB_TOOL], [[lib]])]) 954 AC_SUBST([lt_cv_objdir]) 955 os_is_windows="yes" 956 os_is_native_w32="yes" 957 ], 958 [*openedition*], 959 [AC_DEFINE([OS390],[1],[This is a OS/390 system]) 960 mhd_host_os='OS/390' 961 AC_MSG_RESULT([[$mhd_host_os]])], 962 [gnu*], 963 [AC_DEFINE([[GNU_HURD]], [[1]], [Define to `1' if host machine runs on GNU Hurd.]) 964 mhd_host_os='GNU Hurd' 965 AC_MSG_RESULT([[$mhd_host_os]]) 966 ], 967 [ 968 AC_MSG_RESULT([unrecognised OS]) 969 mhd_host_os="${host_os}" 970 AC_MSG_WARN([Unrecognised OS $host_os]) 971 AC_DEFINE([OTHEROS],1,[Some strange OS]) 972 ]) 973 974 AM_CONDITIONAL([CYGWIN_TARGET], [[test "x$os_is_windows" = "xyes" && \ 975 test "x${os_is_native_w32}" != "xyes"]]) 976 977 AS_VAR_IF([os_is_windows], ["yes"], 978 [ 979 AC_MSG_CHECKING([[whether target W32 version is specified by precompiler defines]]) 980 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 981 /* Note: check logic is reversed for easy log reading */ 982 #ifdef WINVER 983 #error WINVER is defined 984 choke me now; 985 #endif 986 #ifdef _WIN32_WINNT 987 #error _WIN32_WINNT is defined 988 choke me now; 989 #endif 990 #ifdef NTDDI 991 #error NTDDI is defined 992 choke me now; 993 #endif 994 ]],[[(void)0]]) 995 ], [[mhd_w32_ver_preselect=no]], [[mhd_w32_ver_preselect=yes]] 996 ) 997 AC_MSG_RESULT([[${mhd_w32_ver_preselect}]]) 998 AC_CHECK_HEADERS([windows.h sdkddkver.h], [], [], [AC_INCLUDES_DEFAULT]) 999 AS_VAR_IF([mhd_w32_ver_preselect],["yes"], 1000 [ 1001 AC_MSG_CHECKING([[for specified target W32 version]]) 1002 AS_UNSET([[mhd_w32_ver]]) 1003 AS_UNSET([[mhd_w32_ver_msg]]) 1004 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 1005 #if _WIN32_WINNT+0 < 0x0501 1006 /* Check before headers inclusion */ 1007 #error _WIN32_WINNT is less than 0x0501 1008 choke me now; 1009 #endif 1010 1011 #ifdef HAVE_SDKDDKVER_H 1012 #include <sdkddkver.h> 1013 #endif 1014 #ifdef HAVE_WINDOWS_H 1015 #include <windows.h> 1016 #endif 1017 1018 #if _WIN32_WINNT+0 < 0x0501 1019 #error _WIN32_WINNT is less than 0x0501 1020 choke me now; 1021 #endif 1022 ]],[[(void)0]]) 1023 ], [], [ 1024 AC_MSG_RESULT([[pre-WinXP]]) 1025 AC_MSG_ERROR([[libmicrohttpd cannot be compiled for Windows version before Windows XP]]) 1026 ] 1027 ) 1028 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 1029 #ifdef HAVE_SDKDDKVER_H 1030 #include <sdkddkver.h> 1031 #endif 1032 #ifdef HAVE_WINDOWS_H 1033 #include <windows.h> 1034 #endif 1035 1036 #if _WIN32_WINNT+0 == 0x0501 1037 #error _WIN32_WINNT is 0x0501 1038 choke me now; 1039 #endif 1040 #if _WIN32_WINNT+0 == 0x0502 1041 #error _WIN32_WINNT is 0x0502 1042 choke me now; 1043 #endif 1044 ]],[[(void)0]]) 1045 ], [], [ 1046 mhd_w32_ver="WinXP" 1047 mhd_w32_ver_msg="WinXP (selected by precompiler flags)" 1048 ] 1049 ) 1050 AS_VAR_SET_IF([mhd_w32_ver], [], 1051 [ 1052 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 1053 #ifdef HAVE_SDKDDKVER_H 1054 #include <sdkddkver.h> 1055 #endif 1056 #ifdef HAVE_WINDOWS_H 1057 #include <windows.h> 1058 #endif 1059 1060 #if _WIN32_WINNT+0 < 0x0600 1061 #error _WIN32_WINNT is less than 0x0600 but greater than 0x0502 1062 choke me now; 1063 #endif 1064 ]],[[(void)0]]) 1065 ], [], [ 1066 AC_MSG_ERROR([[_WIN32_WINNT value is wrong (less than 0x0600 but greater than 0x0502)]]) 1067 ] 1068 ) 1069 1070 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 1071 #ifdef HAVE_SDKDDKVER_H 1072 #include <sdkddkver.h> 1073 #endif 1074 #ifdef HAVE_WINDOWS_H 1075 #include <windows.h> 1076 #endif 1077 1078 #if _WIN32_WINNT+0 == 0x0600 1079 #error _WIN32_WINNT is 0x0600 1080 choke me now; 1081 #endif 1082 ]],[[(void)0]]) 1083 ], [], [ 1084 mhd_w32_ver="Vista" 1085 mhd_w32_ver_msg="Vista (selected by precompiler flags)" 1086 ] 1087 ) 1088 ] 1089 ) 1090 1091 AS_VAR_SET_IF([mhd_w32_ver], [], 1092 [ 1093 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 1094 #ifdef HAVE_SDKDDKVER_H 1095 #include <sdkddkver.h> 1096 #endif 1097 #ifdef HAVE_WINDOWS_H 1098 #include <windows.h> 1099 #endif 1100 1101 #if _WIN32_WINNT+0 > 0x0600 1102 #error _WIN32_WINNT is greater than 0x0600 1103 choke me now; 1104 #endif 1105 ]],[[(void)0]]) 1106 ], [ 1107 mhd_w32_ver="unknown" 1108 mhd_w32_ver_msg="unknown (cannot be detected)" 1109 ], [ 1110 mhd_w32_ver="newer than Vista" 1111 mhd_w32_ver_msg="newer than Vista (selected by precompiler flags)" 1112 ] 1113 ) 1114 ] 1115 ) 1116 AC_MSG_RESULT([[${mhd_w32_ver}]]) 1117 ], [ 1118 mhd_w32_ver="Vista" 1119 mhd_w32_ver_msg="Vista (default, override by CPPFLAGS=-D_WIN32_WINNT=0xNNNN)" 1120 CPPFLAGS_ac="${CPPFLAGS_ac} -D_WIN32_WINNT=0x0600" 1121 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 1122 AC_MSG_CHECKING([[whether headers accept _WIN32_WINNT=0x0600]]) 1123 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 1124 #ifdef HAVE_SDKDDKVER_H 1125 #include <sdkddkver.h> 1126 #endif 1127 #ifdef HAVE_WINDOWS_H 1128 #include <windows.h> 1129 #endif 1130 #include <stdio.h> 1131 ]],[[(void)0]]) 1132 ], [ 1133 AC_MSG_RESULT([[yes]]) 1134 ], [ 1135 AC_MSG_RESULT([[no]]) 1136 AC_MSG_ERROR([Headers do not accept _WIN32_WINNT=0x0600. Consider override target W32 version by CPPFLAGS=-D_WIN32_WINNT=0xNNNN]) 1137 ] 1138 ) 1139 ] 1140 ) 1141 ] 1142 ) 1143 1144 AS_IF([test "x${os_is_windows}" = "xyes" && test "x${os_is_native_w32}" = "xyes"], 1145 [ 1146 AC_CACHE_CHECK([W32 run-time library type], [mhd_cv_wctr_type], 1147 [ 1148 AC_EGREP_CPP([MHDMARKER: UCRT run-time library in use!], [ 1149 #include <stdio.h> 1150 #if defined(_UCRT) 1151 #define CRT_STR "MHDMARKER: UCRT run-time library in use!" 1152 #endif 1153 #if defined(__MSVCRT_VERSION__) 1154 #if (__MSVCRT_VERSION__ >= 0xE00) && (__MSVCRT_VERSION__ < 0x1000) 1155 #define CRT_STR "MHDMARKER: UCRT run-time library in use!" 1156 #endif 1157 #if (__MSVCRT_VERSION__ > 0x1400) 1158 #define CRT_STR "MHDMARKER: UCRT run-time library in use!" 1159 #endif 1160 #endif 1161 1162 #ifndef CRT_STR 1163 #define CRT_STR "MHDMARKER: MSVCRT run-time library in use!" 1164 #endif 1165 1166 int main(void) 1167 { 1168 printf ("%\n", CRT_STR); 1169 return 0; 1170 } 1171 ], 1172 [mhd_cv_wctr_type="ucrt"], [mhd_cv_wctr_type="msvcrt"]) 1173 ] 1174 ) 1175 mhd_host_os="${mhd_host_os}-${mhd_cv_wctr_type}" 1176 AS_VAR_IF([mhd_cv_wctr_type], ["msvcrt"], 1177 [ 1178 # Use CFLAGS here to override user-supplied wrong CPPFLAGS. Durty trick, but choice is limited. 1179 AX_APPEND_COMPILE_FLAGS([-U__USE_MINGW_ANSI_STDIO -D__USE_MINGW_ANSI_STDIO=0], [CFLAGS_ac]) 1180 AC_SUBST([W32CRT], [MSVCRT]) 1181 ], [AC_SUBST([W32CRT], [UCRT])] 1182 ) 1183 1184 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1185 LDFLAGS="${user_LDFLAGS}" 1186 AS_CASE([$mhd_w32_ver], 1187 [WinXP], 1188 [MHD_CHECK_ADD_CC_LDFLAG([-Wl,--major-subsystem-version,5,--minor-subsystem-version,1],[LDFLAGS_ac])], 1189 [Vista], 1190 [MHD_CHECK_ADD_CC_LDFLAG([-Wl,--major-subsystem-version,6,--minor-subsystem-version,0],[LDFLAGS_ac])] 1191 ) 1192 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 1193 ] 1194 ) 1195 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1196 1197 1198 AC_ARG_WITH([threads], 1199 [AS_HELP_STRING([--with-threads=LIB],[choose threading library (posix, w32, auto, none) [auto]])], 1200 [], [with_threads='auto']) 1201 AS_CASE([[$with_threads]], 1202 [[win32]], [[with_threads='w32']], 1203 [[pthreads]], [[with_threads='posix']], 1204 [[posix]], [[:]], 1205 [[w32]], [[:]], 1206 [[none]], [[with_threads='none']], 1207 [[no]], [[with_threads='none']], 1208 [[auto]], [[:]], 1209 [AC_MSG_ERROR([[incorrect parameter "$with_threads" specified for --with-threads]])] 1210 ) 1211 1212 # Check for posix threads support. 1213 # As the testsuite uses only posix threads, the checks are required even 1214 # if the library does not use posit threads. 1215 AX_PTHREAD( 1216 [ 1217 mhd_have_posix_threads='yes' 1218 AC_DEFINE([[HAVE_PTHREAD_H]],[[1]],[Define to 1 if you have the <pthread.h> header file.]) 1219 CFLAGS="${CFLAGS_ac} ${PTHREAD_CFLAGS} ${user_CFLAGS}" 1220 MHD_CHECK_FUNC([pthread_sigmask], 1221 [[ 1222 #include <pthread.h> 1223 #include <signal.h> 1224 ]], 1225 [[ 1226 sigset_t nset, oset; 1227 sigemptyset (&nset); 1228 sigaddset (&nset, SIGPIPE); 1229 i][f (0 != pthread_sigmask(SIG_BLOCK, &nset, &oset)) return 1; 1230 ]], 1231 [AC_DEFINE([[HAVE_PTHREAD_SIGMASK]],[[1]],[Define to 1 if you have the pthread_sigmask(3) function.])] 1232 ) 1233 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1234 ],[[mhd_have_posix_threads='no']]) 1235 AM_CONDITIONAL([HAVE_POSIX_THREADS],[test "x$mhd_have_posix_threads" = "xyes"]) 1236 1237 mhd_have_w32_threads='no' 1238 AS_IF([[test "x$with_threads" = "xauto"]], 1239 [ 1240 AS_IF([[test "x$os_is_windows" = "xyes"]], 1241 [ 1242 AC_MSG_CHECKING([[for W32 threads]]) 1243 AC_LINK_IFELSE( 1244 [AC_LANG_PROGRAM([[ 1245 #include <windows.h> 1246 ]], [ HANDLE h = CreateThread(NULL, 0, NULL, NULL, 0, NULL);])] 1247 , [[mhd_have_w32_threads='yes']], [[mhd_have_w32_threads='no']] 1248 ) 1249 AC_MSG_RESULT([[$mhd_have_w32_threads]]) 1250 ]) 1251 ] 1252 ) 1253 1254 AC_MSG_CHECKING([[for threading lib to use with libmicrohttpd ($with_threads)]]) 1255 AS_IF([test "x$with_threads" = "xposix"], 1256 [ # forced posix threads 1257 AS_IF([test "x$mhd_have_posix_threads" = "xyes"], [USE_THREADS='posix'], 1258 [ AS_IF([[test "x$os_is_windows" = "xyes"]] , 1259 [ AC_MSG_ERROR([[Posix threads are not available. Try to configure --with-threads=auto]])], 1260 [ AC_MSG_ERROR([[No threading lib is available. Consider installing pthreads]])] ) 1261 ]) 1262 ]) 1263 AS_IF([test "x$with_threads" = "xw32"], 1264 [ # forced w32 threads 1265 AS_IF([[test "x$mhd_have_w32_threads" = "xyes"]], 1266 [[ USE_THREADS='w32' ]], 1267 [ AC_MSG_ERROR([[W32 threads are not available. Try to configure --with-threads=auto]])]) 1268 ]) 1269 AS_IF([test "x$with_threads" = "xauto"], 1270 [# automatic threads lib selection 1271 AS_IF([[test "x$os_is_native_w32" = "xyes" && test "x$mhd_have_w32_threads" = "xyes"]] , 1272 [[ USE_THREADS='w32' ]] , 1273 [[ test "x$mhd_have_posix_threads" = "xyes" ]], [[ USE_THREADS='posix' ]], 1274 [[ test "x$mhd_have_w32_threads" = "xyes" ]], [[ USE_THREADS='w32' ]], 1275 [ AC_MSG_ERROR([[No threading lib is available. Consider installing pthreads]]) ] 1276 )]) 1277 AS_IF([test "x$with_threads" = "xnone"], 1278 [USE_THREADS='none']) 1279 1280 AS_IF([test "x$USE_THREADS" = "xposix"], 1281 [CC="$PTHREAD_CC" 1282 AC_DEFINE([MHD_USE_POSIX_THREADS],[1],[define to use pthreads]) 1283 MHD_LIB_CFLAGS="$MHD_LIB_CFLAGS $PTHREAD_CFLAGS" 1284 MHD_LIBDEPS="$PTHREAD_LIBS $MHD_LIBDEPS" 1285 MHD_LIBDEPS_PKGCFG="$PTHREAD_LIBS $MHD_LIBDEPS_PKGCFG"], 1286 [AS_IF([test "x$USE_THREADS" = "xw32"], 1287 [AC_DEFINE([MHD_USE_W32_THREADS],[1],[define to use W32 threads])])]) 1288 AM_CONDITIONAL([USE_POSIX_THREADS], [test "x$USE_THREADS" = "xposix"]) 1289 AM_CONDITIONAL([USE_W32_THREADS], [test "x$USE_THREADS" = "xw32"]) 1290 AM_CONDITIONAL([USE_THREADS], [test "x$USE_THREADS" != "xnone"]) 1291 AM_CONDITIONAL([DISABLE_THREADS], [test "x$USE_THREADS" = "xnone"]) 1292 AC_MSG_RESULT([$USE_THREADS]) 1293 1294 AC_ARG_ENABLE([[thread-names]], 1295 [AS_HELP_STRING([--disable-thread-names],[do not set names on MHD generated threads [auto]])], 1296 [], [enable_thread_names='auto']) 1297 1298 AS_IF([test "x$enable_thread_names" != "xno" && test "x$USE_THREADS" = "xposix"],[ 1299 # Check for thread name function 1300 HAVE_THREAD_NAME_FUNC="no" 1301 SAVE_LIBS="$LIBS" 1302 LIBS="$PTHREAD_LIBS $LIBS" 1303 CFLAGS="${CFLAGS_ac} $PTHREAD_CFLAGS ${user_CFLAGS}" 1304 AC_CHECK_HEADERS([pthread_np.h],[],[], 1305 [ 1306 AC_INCLUDES_DEFAULT 1307 [ 1308 #include <pthread.h> 1309 ] 1310 ]) 1311 1312 # Try to find how to set thread name by thread attributes. 1313 # If pthread_attr_setname_np(3) is not declared, it's not possible to detect 1314 # form of pthread_attr_setname_np(3) due to C "feature" "implicit declaration". 1315 AC_CHECK_DECL([[pthread_attr_setname_np]],[],[],[[ 1316 #include <pthread.h> 1317 #ifdef HAVE_PTHREAD_NP_H 1318 #include <pthread_np.h> 1319 #endif 1320 ]]) 1321 1322 AS_IF([[test "x$ac_cv_have_decl_pthread_attr_setname_np" = "xyes"]], 1323 [AC_MSG_CHECKING([[for pthread_attr_setname_np(3) in NetBSD or OSF1 form]]) 1324 AC_LINK_IFELSE( 1325 [AC_LANG_PROGRAM([[ 1326 #include <pthread.h> 1327 #ifdef HAVE_PTHREAD_NP_H 1328 #include <pthread_np.h> 1329 #endif 1330 ]], [[ 1331 pthread_attr_t thr_attr; 1332 pthread_attr_init(&thr_attr); 1333 pthread_attr_setname_np(&thr_attr, "name", 0); 1334 pthread_attr_destroy(&thr_attr); 1335 ]])], 1336 [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.]) 1337 HAVE_THREAD_NAME_FUNC="yes" 1338 AC_MSG_RESULT([[yes]])], 1339 [AC_MSG_RESULT([[no]])] 1340 ) 1341 ]) 1342 1343 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_attr_setname_np" = "xyes"]], 1344 [AC_MSG_CHECKING([[for pthread_attr_setname_np(3) in IBM i or Solaris form]]) 1345 AC_LINK_IFELSE( 1346 [AC_LANG_PROGRAM([[ 1347 #include <pthread.h> 1348 #ifdef HAVE_PTHREAD_NP_H 1349 #include <pthread_np.h> 1350 #endif 1351 ]], [[ 1352 pthread_attr_t thr_attr; 1353 pthread_attr_init(&thr_attr); 1354 pthread_attr_setname_np(&thr_attr, "name"); 1355 pthread_attr_destroy(&thr_attr); 1356 ]])], 1357 [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.]) 1358 HAVE_THREAD_NAME_FUNC="yes" 1359 AC_MSG_RESULT([[yes]])], 1360 [AC_MSG_RESULT([[no]])] 1361 ) 1362 ]) 1363 1364 # Try to find how to set thread name for started thread - less convenient 1365 # than setting name by attributes. 1366 # If pthread_setname_np(3) is not declared, it's not possible to detect 1367 # form of pthread_setname_np(3) due to C "feature" "implicit declaration". 1368 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes"]], 1369 [AC_CHECK_DECL([[pthread_setname_np]],[],[],[[ 1370 #include <pthread.h> 1371 #ifdef HAVE_PTHREAD_NP_H 1372 #include <pthread_np.h> 1373 #endif 1374 ]]) 1375 ]) 1376 1377 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]], 1378 [AC_MSG_CHECKING([[for pthread_setname_np(3) in NetBSD or OSF1 form]]) 1379 AC_LINK_IFELSE( 1380 [AC_LANG_PROGRAM([[ 1381 #include <pthread.h> 1382 #ifdef HAVE_PTHREAD_NP_H 1383 #include <pthread_np.h> 1384 #endif 1385 ]], [[int res = pthread_setname_np(pthread_self(), "name", 0); if (res) return res;]])], 1386 [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_NETBSD]], [[1]], [Define if you have NetBSD form (or OSF1 form) of pthread_setname_np(3) function.]) 1387 HAVE_THREAD_NAME_FUNC="yes" 1388 AC_MSG_RESULT([[yes]])], 1389 [AC_MSG_RESULT([[no]])] 1390 ) 1391 ]) 1392 1393 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]], 1394 [AC_MSG_CHECKING([[for pthread_setname_np(3) in GNU/Linux form]]) 1395 AC_LINK_IFELSE( 1396 [AC_LANG_PROGRAM([[ 1397 #include <pthread.h> 1398 #ifdef HAVE_PTHREAD_NP_H 1399 #include <pthread_np.h> 1400 #endif 1401 ]], [[int res = pthread_setname_np(pthread_self(), "name"); if (res) return res;]])], 1402 [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_GNU]], [[1]], [Define if you have GNU/Linux form of pthread_setname_np(3) function.]) 1403 HAVE_THREAD_NAME_FUNC="yes" 1404 AC_MSG_RESULT([[yes]])], 1405 [AC_MSG_RESULT([[no]])] 1406 ) 1407 ]) 1408 1409 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]], 1410 [AC_MSG_CHECKING([[for pthread_setname_np(3) in Darwin form]]) 1411 AC_LINK_IFELSE( 1412 [AC_LANG_PROGRAM([[ 1413 #include <pthread.h> 1414 #ifdef HAVE_PTHREAD_NP_H 1415 #include <pthread_np.h> 1416 #endif 1417 ]], [[int res = pthread_setname_np("name"); if (res) return res;]])], 1418 [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_DARWIN]], [[1]], [Define if you have Darwin form of pthread_setname_np(3) function.]) 1419 HAVE_THREAD_NAME_FUNC="yes" 1420 AC_MSG_RESULT([[yes]])], 1421 [AC_MSG_RESULT([[no]])] 1422 ) 1423 ]) 1424 1425 AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes"]], 1426 [ 1427 AC_CHECK_DECL([[pthread_set_name_np]], 1428 [ 1429 AC_MSG_CHECKING([[for pthread_set_name_np(3) in FreeBSD form]]) 1430 AC_LINK_IFELSE( 1431 [AC_LANG_PROGRAM([[ 1432 #include <pthread.h> 1433 #ifdef HAVE_PTHREAD_NP_H 1434 #include <pthread_np.h> 1435 #endif 1436 ]], [[pthread_set_name_np(pthread_self(), "name");]])], 1437 [AC_DEFINE([[HAVE_PTHREAD_SET_NAME_NP_FREEBSD]], [[1]], [Define if you have FreeBSD form of pthread_set_name_np(3) function.]) 1438 HAVE_THREAD_NAME_FUNC="yes" 1439 AC_MSG_RESULT([[yes]])], 1440 [AC_MSG_RESULT([[no]])] 1441 ) 1442 ],[],[[ 1443 #include <pthread.h> 1444 #ifdef HAVE_PTHREAD_NP_H 1445 #include <pthread_np.h> 1446 #endif 1447 ]] 1448 ) 1449 ]) 1450 1451 LIBS="$SAVE_LIBS" 1452 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1453 ]) 1454 1455 AS_IF([[test "x$enable_thread_names" != "xno"]], 1456 [ 1457 AC_MSG_CHECKING([[whether to enable thread names]]) 1458 AC_COMPILE_IFELSE( 1459 [AC_LANG_PROGRAM([], [[ 1460 #ifdef MHD_NO_THREAD_NAMES 1461 #error Thread names are disabled. 1462 choke me 1463 #endif 1464 1465 /* Keep in sync with mhd_threads.h */ 1466 #if defined(MHD_USE_POSIX_THREADS) && (defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) || \ 1467 defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || \ 1468 defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) ) 1469 (void) 0; /* no-op */ 1470 #elif defined(MHD_USE_W32_THREADS) && defined(_MSC_FULL_VER) 1471 (void) 0; /* no-op */ 1472 #else 1473 #error No thread name function is available. 1474 choke me 1475 #endif 1476 ]]) 1477 ], [ 1478 enable_thread_names='yes' 1479 ], [ 1480 AS_IF([[test "x$enable_thread_names" = "xyes"]], 1481 [ 1482 AC_MSG_RESULT([[no]]) 1483 AC_MSG_ERROR([[thread names was explicitly requested, but thread name function is not available]]) 1484 ]) 1485 enable_thread_names='no' 1486 ]) 1487 AC_MSG_RESULT([[$enable_thread_names]]) 1488 ]) 1489 1490 AS_IF([[test "x$enable_thread_names" = "xno"]], 1491 [AC_DEFINE([[MHD_NO_THREAD_NAMES]], [[1]], [Define to 1 to disable setting name on generated threads])]) 1492 1493 AM_CONDITIONAL(HAVE_W32, [test "x$os_is_native_w32" = "xyes"]) 1494 w32_shared_lib_exp=no 1495 AS_IF([test "x$enable_shared" = "xyes" && test "x$os_is_native_w32" = "xyes"], 1496 [ 1497 AS_IF([test "x$ac_cv_use_ms_lib_tool" = "xyes" || test -n "$DLLTOOL"], 1498 [ 1499 w32_shared_lib_exp=yes 1500 use_expfile="no" 1501 AS_VAR_IF([ac_cv_use_ms_lib_tool], ["yes"], [use_expfile="yes"], 1502 [ 1503 AC_CACHE_CHECK([whether $DLLTOOL supports export file generation], [mhd_cv_dlltool_expfile], 1504 [ 1505 AS_IF([AC_RUN_LOG([$DLLTOOL -e conftest.exp >&2 ])], 1506 [ 1507 AS_IF([test -f conftest.exp], [mhd_cv_dlltool_expfile="yes"], [mhd_cv_dlltool_expfile="no"]) 1508 ], [mhd_cv_dlltool_expfile="no"] 1509 ) 1510 rm -f conftest.exp 1511 ] 1512 ) 1513 use_expfile="${mhd_cv_dlltool_expfile}" 1514 ] 1515 ) 1516 ], 1517 [ 1518 AC_MSG_WARN([[GNU dlltool or MS lib.exe is required for creating shared library export on W32]]) 1519 AC_MSG_WARN([[Export library libmicrohttpd.lib will not be created]]) 1520 ] 1521 ) 1522 ] 1523 ) 1524 AM_CONDITIONAL([W32_SHARED_LIB_EXP], [test "x$w32_shared_lib_exp" = "xyes"]) 1525 AM_CONDITIONAL([USE_MS_LIB_TOOL], [test "x$ac_cv_use_ms_lib_tool" = "xyes"]) 1526 AM_CONDITIONAL([USE_EXPORT_FILE], [test "x$use_expfile" = "xyes"]) 1527 1528 dnl gethostbyname() is not really needed 1529 dnl AC_SEARCH_LIBS([gethostbyname], [nsl]) 1530 MHD_FIND_LIB([socket], 1531 [[ 1532 #ifdef HAVE_SYS_TYPES_H 1533 #include <sys/types.h> 1534 #endif 1535 #ifdef HAVE_SYS_SOCKET_H 1536 #include <sys/socket.h> 1537 #endif 1538 #ifdef HAVE_SOCKLIB_H 1539 #include <sockLib.h> 1540 #endif 1541 #if defined(_WIN32) && ! defined(__CYGWIN__) 1542 #include <winsock2.h> 1543 #endif 1544 ]], 1545 [(void)socket(0, 0, 0);], 1546 [socket ws2_32 xnet], 1547 [ 1548 AS_VAR_IF([[mhd_cv_find_lib_socket]],[["none required"]], [], 1549 [ 1550 MHD_LIBDEPS_PKGCFG="${mhd_cv_find_lib_socket} $MHD_LIBDEPS_PKGCFG" 1551 ] 1552 ) 1553 ], 1554 [AC_MSG_ERROR([[cannot find header or library required for function socket()]])] 1555 ) 1556 1557 MHD_CHECK_SOCKET_SHUTDOWN_TRIGGER([AC_DEFINE([HAVE_LISTEN_SHUTDOWN],[1],[can use shutdown on listen sockets])]) 1558 AM_CONDITIONAL([HAVE_LISTEN_SHUTDOWN], [test "x$mhd_cv_host_shtdwn_trgr_select" = "xyes"]) 1559 1560 AC_CACHE_CHECK([fo][r system default FD_SETSIZE value],[mhd_cv_sys_fd_setsize_value], 1561 [ 1562 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} -UFD_SETSIZE" 1563 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS} -UFD_SETSIZE" 1564 AC_COMPUTE_INT([mhd_cv_sys_fd_setsize_value],[FD_SETSIZE],dnl 1565 [[ 1566 #ifdef HAVE_SYS_TIME_H 1567 #include <sys/time.h> 1568 #endif 1569 #ifdef HAVE_SYS_TYPES_H 1570 #include <sys/types.h> 1571 #endif 1572 #ifdef HAVE_UNISTD_H 1573 #include <unistd.h> 1574 #endif 1575 #ifdef HAVE_SYS_SOCKET_H 1576 #include <sys/socket.h> 1577 #endif 1578 #ifdef HAVE_SOCKLIB_H 1579 #include <sockLib.h> 1580 #endif 1581 #if defined(_WIN32) && ! defined(__CYGWIN__) 1582 #include <winsock2.h> 1583 #endif 1584 #ifdef HAVE_SYS_SELECT_H 1585 #include <sys/select.h> 1586 #endif 1587 ]], [mhd_cv_sys_fd_setsize_value="unknown"] 1588 ) 1589 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1590 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 1591 AS_IF([test "x${mhd_cv_sys_fd_setsize_value}" != "xunknown" && \ 1592 test "${mhd_cv_sys_fd_setsize_value}" -eq "0" \ 1593 ], [mhd_cv_sys_fd_setsize_value="unknown"] 1594 ) 1595 ] 1596 ) 1597 AS_VAR_IF([mhd_cv_sys_fd_setsize_value],["unknown"],[:], 1598 [ 1599 AC_DEFINE_UNQUOTED([MHD_SYS_FD_SETSIZE_],[${mhd_cv_sys_fd_setsize_value}], 1600 [Define to system default value of FD_SETSIZE macro] 1601 ) 1602 ] 1603 ) 1604 AM_CONDITIONAL([NEED_SYS_FD_SET_SIZE_VALUE],[test "x${mhd_cv_sys_fd_setsize_value}" = "xunknown"]) 1605 1606 AC_CACHE_CHECK([fo][r current FD_SETSIZE value],[mhd_cv_fd_setsize_value], 1607 [ 1608 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1609 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 1610 AS_IF([test "x${cross_compiling}" != "xno" && test "x${mhd_cv_sys_fd_setsize_value}" != "xunknown"], 1611 [ 1612 AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 1613 [[ 1614 #ifdef HAVE_SYS_TIME_H 1615 #include <sys/time.h> 1616 #endif 1617 #ifdef HAVE_SYS_TYPES_H 1618 #include <sys/types.h> 1619 #endif 1620 #ifdef HAVE_UNISTD_H 1621 #include <unistd.h> 1622 #endif 1623 #ifdef HAVE_SYS_SOCKET_H 1624 #include <sys/socket.h> 1625 #endif 1626 #ifdef HAVE_SOCKLIB_H 1627 #include <sockLib.h> 1628 #endif 1629 #if defined(_WIN32) && ! defined(__CYGWIN__) 1630 #include <winsock2.h> 1631 #endif 1632 #ifdef HAVE_SYS_SELECT_H 1633 #include <sys/select.h> 1634 #endif 1635 1636 #define DETECTED_FD_SETZIE_VALUE ${mhd_cv_sys_fd_setsize_value} 1637 1638 #if (FD_SETSIZE) != (DETECTED_FD_SETZIE_VALUE) 1639 #error The current default FD_SETSIZE value is different from ${mhd_cv_sys_fd_setsize_value} 1640 choke me here now 1641 #endif /* (FD_SETSIZE) != (DETECTED_FD_SETZIE_VALUE) */ 1642 1643 #if (FD_SETSIZE) != (${mhd_cv_sys_fd_setsize_value}) 1644 #error The current default FD_SETSIZE value is different from ${mhd_cv_sys_fd_setsize_value} 1645 choke me here now 1646 #endif /* (FD_SETSIZE) != (${mhd_cv_sys_fd_setsize_value}) */ 1647 ]],[] 1648 ) 1649 ], 1650 [mhd_cv_fd_setsize_value="${mhd_cv_sys_fd_setsize_value}"] 1651 ) 1652 ] 1653 ) 1654 AS_VAR_SET_IF([mhd_cv_fd_setsize_value],[:], 1655 [ 1656 AC_COMPUTE_INT([mhd_cv_fd_setsize_value],[FD_SETSIZE],dnl 1657 [[ 1658 #ifdef HAVE_SYS_TIME_H 1659 #include <sys/time.h> 1660 #endif 1661 #ifdef HAVE_SYS_TYPES_H 1662 #include <sys/types.h> 1663 #endif 1664 #ifdef HAVE_UNISTD_H 1665 #include <unistd.h> 1666 #endif 1667 #ifdef HAVE_SYS_SOCKET_H 1668 #include <sys/socket.h> 1669 #endif 1670 #ifdef HAVE_SOCKLIB_H 1671 #include <sockLib.h> 1672 #endif 1673 #if defined(_WIN32) && ! defined(__CYGWIN__) 1674 #include <winsock2.h> 1675 #endif 1676 #ifdef HAVE_SYS_SELECT_H 1677 #include <sys/select.h> 1678 #endif 1679 ]], [mhd_cv_fd_setsize_value="unknown"] 1680 ) 1681 ] 1682 ) 1683 AS_IF([test "x${mhd_cv_fd_setsize_value}" != "xunknown" && \ 1684 test "${mhd_cv_fd_setsize_value}" -eq "0"], 1685 [mhd_cv_fd_setsize_value="unknown"] 1686 ) 1687 ] 1688 ) 1689 1690 1691 AC_CACHE_CHECK([whether FD_SETSIZE is overridable],[mhd_cv_fd_setsize_overridable], 1692 [ 1693 AS_VAR_IF([mhd_cv_fd_setsize_value],["unknown"], 1694 [ 1695 AS_VAR_IF([mhd_cv_sys_fd_setsize_value],["unknown"], 1696 [ 1697 # Assume the most popular FD_SETSIZE value 1698 base_fd_setsize=1024 1699 ], 1700 [base_fd_setsize="${mhd_cv_sys_fd_setsize_value}"] 1701 ) 1702 base_min_fd_setsize="${base_fd_setsize}" 1703 ], 1704 [ 1705 AS_VAR_IF([mhd_cv_sys_fd_setsize_value],["unknown"], 1706 [ 1707 base_fd_setsize="${mhd_cv_fd_setsize_value}" 1708 base_min_fd_setsize="${base_fd_setsize}" 1709 ], 1710 [ 1711 AS_IF([test "${mhd_cv_fd_setsize_value}" -ge "${mhd_cv_sys_fd_setsize_value}"], 1712 [ 1713 base_fd_setsize="${mhd_cv_fd_setsize_value}" 1714 base_min_fd_setsize="${mhd_cv_sys_fd_setsize_value}" 1715 ], 1716 [ 1717 base_fd_setsize="${mhd_cv_sys_fd_setsize_value}" 1718 base_min_fd_setsize="${mhd_cv_fd_setsize_value}" 1719 ] 1720 ) 1721 ] 1722 ) 1723 ] 1724 ) 1725 # Use two times larger FD_SETSIZE value for test 1726 AS_VAR_ARITH([test_fd_setsize],[${base_fd_setsize} '+' ${base_fd_setsize}]) 1727 AS_IF([test "${test_fd_setsize}" -lt "128"],[test_fd_setsize=128]) 1728 test_type_fd_setsize="larger" 1729 1730 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 1731 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 1732 1733 _AS_ECHO_LOG([testing whether FD_SETSIZE test value (${test_fd_setsize}) is suitable for 'int' type]) 1734 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], 1735 [[ 1736 static int test_arr1[(((long long)${test_fd_setsize}) != ((int)${test_fd_setsize})) ? -1 : 1]; 1737 static int test_arr2[(0 > ((int)${test_fd_setsize})) ? -1 : 1]; 1738 test_arr1[0] = 0; 1739 test_arr2[0] = 0; 1740 i][f (test_arr1[0] != test_arr2[0]) return 1; 1741 ]] 1742 ) 1743 ],[], 1744 [ 1745 _AS_ECHO_LOG([The selected test FD_SETSIZE value (${test_fd_setsize}) is too large for 'int' type]) 1746 AS_VAR_ARITH([test_fd_setsize],[${base_min_fd_setsize} '/' '2']) 1747 test_type_fd_setsize="smaller" 1748 ] 1749 ) 1750 1751 _AS_ECHO_LOG([will try ${test_fd_setsize} as FD_SETSIZE value]) 1752 1753 AS_IF([test "x${cross_compiling}" = "xno" && test "x${test_type_fd_setsize}" = "xlarger"], 1754 [ 1755 _AS_ECHO_LOG([will try ${test_fd_setsize} as FD_SETSIZE value with run test]) 1756 AC_RUN_IFELSE( 1757 [ 1758 AC_LANG_SOURCE( 1759 [[ 1760 #ifdef FD_SETSIZE 1761 #undef FD_SETSIZE 1762 #endif /* FD_SETSIZE */ 1763 1764 #define FD_SETSIZE ${test_fd_setsize} 1765 #define MY_TEST_FD_SETSIZE ${test_fd_setsize} 1766 1767 #ifdef HAVE_SYS_TIME_H 1768 #include <sys/time.h> 1769 #endif 1770 #ifdef HAVE_SYS_TYPES_H 1771 #include <sys/types.h> 1772 #endif 1773 #ifdef HAVE_UNISTD_H 1774 #include <unistd.h> 1775 #endif 1776 #ifdef HAVE_SYS_SOCKET_H 1777 #include <sys/socket.h> 1778 #endif 1779 #ifdef HAVE_SOCKLIB_H 1780 #include <sockLib.h> 1781 #endif 1782 #if defined(_WIN32) && ! defined(__CYGWIN__) 1783 #include <winsock2.h> 1784 #define MHD_TEST_SOCKET_TYPE SOCKET 1785 #else 1786 #define MHD_TEST_SOCKET_TYPE int 1787 #endif 1788 #ifdef HAVE_SYS_SELECT_H 1789 #include <sys/select.h> 1790 #endif 1791 1792 #include <string.h> 1793 #include <stdio.h> 1794 1795 /* Test fo][r mismatch by macro check */ 1796 #if (FD_SETSIZE) != (MY_TEST_FD_SETSIZE) 1797 #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize} 1798 choke me here now; 1799 #endif /* (FD_SETSIZE) != (MY_TEST_FD_SETSIZE) */ 1800 1801 /* Additional test fo][r mismatch by macro check */ 1802 #if (FD_SETSIZE) != (${test_fd_setsize}) 1803 #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize} 1804 choke me here now; 1805 #endif /* (FD_SETSIZE) != (${test_fd_setsize}) */ 1806 1807 static unsigned long var_fd_setsize_value = FD_SETSIZE; 1808 static unsigned long var_my_test_fd_setsize_value = MY_TEST_FD_SETSIZE; 1809 1810 int main(void) 1811 { 1812 fd_set fds_num_one_copy; 1813 fd_set fds_num_three_copy; 1814 fd_set test_fdsets[6]; 1815 int i; 1816 int ret = 0; 1817 #if defined(_WIN32) && ! defined(__CYGWIN__) 1818 WSADATA wsa_data; 1819 1820 if (0 != WSAStartup(MAKEWORD(2, 2), &wsa_data)) 1821 return 21; 1822 if (MAKEWORD(2, 2) != wsa_data.wVersion) 1823 { 1824 WSACleanup(); 1825 return 22; 1826 } 1827 #endif /* _WIN32 && ! __CYGWIN__ */ 1828 1829 /* Init with zeros to make sure that slack areas are equal */ 1830 memset(test_fdsets, 0, sizeof(test_fdsets)); 1831 1832 /* Correctly init fd_sets */ 1833 for (i = 0; i < 6; ++i) 1834 FD_ZERO(test_fdsets + i); 1835 1836 /* Make copies of zero-inited fd_sets */ 1837 memcpy(&fds_num_one_copy, test_fdsets + 1, sizeof(fd_set)); 1838 memcpy(&fds_num_three_copy, test_fdsets + 3, sizeof(fd_set)); 1839 1840 if (var_fd_setsize_value != var_my_test_fd_setsize_value) 1841 { 1842 fprintf (stderr, "System headers redefined FD_SETSIZE to another value (%lu).\n", 1843 (unsigned long) FD_SETSIZE); 1844 ret = 2; 1845 } 1846 else 1847 { 1848 /* Set (almost) all FDs in test_fdset[2] */ 1849 for (i = 1; i < FD_SETSIZE; ++i) 1850 FD_SET((MHD_TEST_SOCKET_TYPE)i, test_fdsets + 2); 1851 1852 if (! FD_ISSET((MHD_TEST_SOCKET_TYPE)1, test_fdsets + 2)) 1853 { 1854 fprintf (stderr, "FD number one in original fd_set is unset, while should be set.\n"); 1855 ret |= 3; 1856 } 1857 if (! FD_ISSET((MHD_TEST_SOCKET_TYPE)(FD_SETSIZE - 1), test_fdsets + 2)) 1858 { 1859 fprintf (stderr, "FD number %lu in original fd_set is unset, while should be set.\n", 1860 (unsigned long) FD_SETSIZE); 1861 ret |= 3; 1862 } 1863 1864 if (FD_ISSET((MHD_TEST_SOCKET_TYPE)1, test_fdsets + 1)) 1865 { 1866 fprintf (stderr, "FD number one in the first fd_set is unset, while should be set.\n"); 1867 ret |= 4; 1868 } 1869 if (FD_ISSET((MHD_TEST_SOCKET_TYPE)(FD_SETSIZE - 1), test_fdsets + 1)) 1870 { 1871 fprintf (stderr, "FD number %lu in the first fd_set is unset, while should be set.\n", 1872 (unsigned long) FD_SETSIZE); 1873 ret |= 4; 1874 } 1875 if (0 != memcmp (&fds_num_one_copy, test_fdsets + 1, sizeof(fd_set))) 1876 { 1877 fprintf (stderr, "The first fd_set has been altered.\n"); 1878 ret |= 4; 1879 } 1880 1881 if (FD_ISSET((MHD_TEST_SOCKET_TYPE)1, test_fdsets + 3)) 1882 { 1883 fprintf (stderr, "FD number one in the third fd_set is unset, while should be set.\n"); 1884 ret |= 8; 1885 } 1886 if (FD_ISSET((MHD_TEST_SOCKET_TYPE)(FD_SETSIZE - 1), test_fdsets + 3)) 1887 { 1888 fprintf (stderr, "FD number %lu in the third fd_set is unset, while should be set.\n", 1889 (unsigned long) FD_SETSIZE); 1890 ret |= 8; 1891 } 1892 if (0 != memcmp (&fds_num_three_copy, test_fdsets + 3, sizeof(fd_set))) 1893 { 1894 fprintf (stderr, "The third fd_set has been altered.\n"); 1895 ret |= 8; 1896 } 1897 } 1898 #if defined(_WIN32) && ! defined(__CYGWIN__) 1899 WSACleanup(); 1900 #endif /* _WIN32 && ! __CYGWIN__ */ 1901 return ret; 1902 } 1903 ]] 1904 ) 1905 ], 1906 [mhd_cv_fd_setsize_overridable="yes"], 1907 [mhd_cv_fd_setsize_overridable="no"], 1908 [[# Not used when cross-compiling ]] 1909 ) 1910 ], 1911 [ 1912 _AS_ECHO_LOG([will try ${test_fd_setsize} as FD_SETSIZE with simple compile test]) 1913 AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 1914 [[ 1915 #ifdef FD_SETSIZE 1916 #undef FD_SETSIZE 1917 #endif /* FD_SETSIZE */ 1918 1919 #define FD_SETSIZE ${test_fd_setsize} 1920 #define MY_TEST_FD_SETSIZE ${test_fd_setsize} 1921 1922 #ifdef HAVE_SYS_TIME_H 1923 #include <sys/time.h> 1924 #endif 1925 #ifdef HAVE_SYS_TYPES_H 1926 #include <sys/types.h> 1927 #endif 1928 #ifdef HAVE_UNISTD_H 1929 #include <unistd.h> 1930 #endif 1931 #ifdef HAVE_SYS_SOCKET_H 1932 #include <sys/socket.h> 1933 #endif 1934 #ifdef HAVE_SOCKLIB_H 1935 #include <sockLib.h> 1936 #endif 1937 #if defined(_WIN32) && ! defined(__CYGWIN__) 1938 #include <winsock2.h> 1939 #endif 1940 #ifdef HAVE_SYS_SELECT_H 1941 #include <sys/select.h> 1942 #endif 1943 1944 /* Test fo][r mismatch by macro check */ 1945 #if (FD_SETSIZE) != (MY_TEST_FD_SETSIZE) 1946 #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize} 1947 choke me here now 1948 #endif /* (FD_SETSIZE) != (MY_TEST_FD_SETSIZE) */ 1949 1950 /* Additional test fo][r mismatch by macro check */ 1951 #if (FD_SETSIZE) != (${test_fd_setsize}) 1952 #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize} 1953 choke me here now 1954 #endif /* (FD_SETSIZE) != (${test_fd_setsize}) */ 1955 ]],[] 1956 ) 1957 ], 1958 [ 1959 _AS_ECHO_LOG([comple test succeed, will check whether another FD_SETSIZE value changes the size of 'fd_set']) 1960 1961 # Check current size of fd_set 1962 _AS_ECHO_LOG([find the sizeof(fd_setsize) with current default (${mhd_cv_fd_setsize_value}) FD_SETSIZE value]) 1963 AC_COMPUTE_INT([sizeof_cur_fd_set],[sizeof(fd_set)],dnl 1964 [[ 1965 #ifdef HAVE_SYS_TIME_H 1966 #include <sys/time.h> 1967 #endif 1968 #ifdef HAVE_SYS_TYPES_H 1969 #include <sys/types.h> 1970 #endif 1971 #ifdef HAVE_UNISTD_H 1972 #include <unistd.h> 1973 #endif 1974 #ifdef HAVE_SYS_SOCKET_H 1975 #include <sys/socket.h> 1976 #endif 1977 #ifdef HAVE_SOCKLIB_H 1978 #include <sockLib.h> 1979 #endif 1980 #if defined(_WIN32) && ! defined(__CYGWIN__) 1981 #include <winsock2.h> 1982 #endif 1983 #ifdef HAVE_SYS_SELECT_H 1984 #include <sys/select.h> 1985 #endif 1986 ]], [sizeof_cur_fd_set="unknown"] 1987 ) 1988 _AS_ECHO_LOG([the sizeof(fd_setsize) with current default (${mhd_cv_fd_setsize_value}) FD_SETSIZE value is ${sizeof_cur_fd_set}]) 1989 1990 # Check the size of fd_set with redefined FD_SETSIZE 1991 _AS_ECHO_LOG([find the sizeof(fd_setsize) with redefined (${test_fd_setsize}) FD_SETSIZE value]) 1992 AC_COMPUTE_INT([sizeof_mod_fd_set],[sizeof(fd_set)],dnl 1993 [[ 1994 #ifdef FD_SETSIZE 1995 #undef FD_SETSIZE 1996 #endif /* FD_SETSIZE */ 1997 1998 #define FD_SETSIZE ${test_fd_setsize} 1999 2000 #ifdef HAVE_SYS_TIME_H 2001 #include <sys/time.h> 2002 #endif 2003 #ifdef HAVE_SYS_TYPES_H 2004 #include <sys/types.h> 2005 #endif 2006 #ifdef HAVE_UNISTD_H 2007 #include <unistd.h> 2008 #endif 2009 #ifdef HAVE_SYS_SOCKET_H 2010 #include <sys/socket.h> 2011 #endif 2012 #ifdef HAVE_SOCKLIB_H 2013 #include <sockLib.h> 2014 #endif 2015 #if defined(_WIN32) && ! defined(__CYGWIN__) 2016 #include <winsock2.h> 2017 #endif 2018 #ifdef HAVE_SYS_SELECT_H 2019 #include <sys/select.h> 2020 #endif 2021 ]], [sizeof_mod_fd_set="unknown"] 2022 ) 2023 _AS_ECHO_LOG([the sizeof(fd_setsize) with redefined (${test_fd_setsize}) FD_SETSIZE value is ${sizeof_mod_fd_set}]) 2024 _AS_ECHO_LOG([detected sizes of 'fd_set': '${sizeof_cur_fd_set}' (by default), '${sizeof_mod_fd_set}' with modified FD_SETSIZE]) 2025 AS_IF([test "x${sizeof_cur_fd_set}" != "x${sizeof_mod_fd_set}"], 2026 [mhd_cv_fd_setsize_overridable="yes"], 2027 [mhd_cv_fd_setsize_overridable="no"] 2028 ) 2029 AS_UNSET([sizeof_mod_fd_set]) 2030 AS_UNSET([sizeof_cur_fd_set]) 2031 ], 2032 [mhd_cv_fd_setsize_overridable="no"] 2033 ) 2034 ] 2035 ) 2036 AS_UNSET([test_type_fd_setsize]) 2037 AS_UNSET([test_fd_setsize]) 2038 AS_UNSET([base_min_fd_setsize]) 2039 AS_UNSET([base_fd_setsize]) 2040 ] 2041 ) 2042 2043 AS_VAR_IF([mhd_cv_fd_setsize_overridable],["no"], 2044 [ 2045 AS_VAR_IF([os_is_native_w32],["yes"], 2046 [AC_MSG_ERROR([Non-overridable FD_SETSIZE detected for native W32 build. FD_SETSIZE is overridable on W32.])] 2047 ) 2048 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}"], 2049 [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})])] 2050 ) 2051 ], 2052 [AC_DEFINE([HAS_FD_SETSIZE_OVERRIDABLE],[1],[Define to 1 i][f your system allow overriding the value of FD_SETSIZE macro])] 2053 ) 2054 2055 AC_CACHE_CHECK([whether socket value is a signed type],[mhd_cv_socket_signed], 2056 [ 2057 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 2058 #ifdef HAVE_SYS_TIME_H 2059 #include <sys/time.h> 2060 #endif 2061 #ifdef HAVE_SYS_TYPES_H 2062 #include <sys/types.h> 2063 #endif 2064 #ifdef HAVE_UNISTD_H 2065 #include <unistd.h> 2066 #endif 2067 #ifdef HAVE_SYS_SOCKET_H 2068 #include <sys/socket.h> 2069 #endif 2070 #ifdef HAVE_SOCKLIB_H 2071 #include <sockLib.h> 2072 #endif 2073 #if defined(_WIN32) && ! defined(__CYGWIN__) 2074 #include <winsock2.h> 2075 #endif 2076 #ifdef HAVE_SYS_SELECT_H 2077 #include <sys/select.h> 2078 #endif 2079 2080 /* Keep in sync with microhttpd.h */ 2081 #if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET) 2082 typedef int MHD_socket; 2083 #else /* defined(_WIN32) && ! defined(_SYS_TYPES_FD_SET) */ 2084 typedef SOCKET MHD_socket; 2085 #endif /* defined(_WIN32) && ! defined(_SYS_TYPES_FD_SET) */ 2086 2087 int main(void) 2088 { 2089 int test_arr[2 - 5*(!!(0 < ((MHD_socket)-1)))]; 2090 test_arr[1] = 0; 2091 return test_arr[1]; 2092 } 2093 ]] 2094 ) 2095 ], 2096 [mhd_cv_socket_signed="yes"], 2097 [mhd_cv_socket_signed="no"] 2098 ) 2099 ] 2100 ) 2101 AS_VAR_IF([mhd_cv_socket_signed],["yes"], 2102 [AC_DEFINE([HAS_SIGNED_SOCKET],[1],[Define to 1 i][f your socket type is signed])] 2103 ) 2104 2105 MHD_CHECK_FUNC([writev], 2106 [[#include <sys/uio.h>]], 2107 [[ 2108 struct iovec iov[2]; 2109 char some_str[4] = "OK\n"; 2110 iov[0].iov_base = (void *) some_str; 2111 iov[0].iov_len = 3; 2112 i][f (0 > writev(1, iov, 1)) 2113 return 2; 2114 ]] 2115 ) 2116 MHD_FIND_LIB([sendmsg], 2117 [[ 2118 #ifdef HAVE_SYS_TYPES_H 2119 #include <sys/types.h> 2120 #endif 2121 #ifdef HAVE_SYS_SOCKET_H 2122 #include <sys/socket.h> 2123 #endif 2124 #ifdef HAVE_SOCKLIB_H 2125 #include <sockLib.h> 2126 #endif 2127 #ifdef HAVE_SYS_UIO_H 2128 #include <sys/uio.h> 2129 #endif 2130 ]], 2131 [[ 2132 struct msghdr msg; 2133 struct iovec iov; 2134 unsigned int i; 2135 char some_str[5] = "test"; 2136 2137 iov.iov_base = (void*)some_str; 2138 iov.iov_len = 4; 2139 2140 for (i = 0; i < (unsigned int) sizeof(msg); i++) 2141 { 2142 *(((unsigned char *)&msg) + i) = 0; 2143 } 2144 msg.msg_iov = &iov; 2145 msg.msg_iovlen = 1; 2146 2147 i][f (0 > sendmsg(1, &msg, 0)) 2148 return -1; 2149 ]], 2150 [socket], 2151 [ 2152 AC_DEFINE([HAVE_SENDMSG],[1],[Define to '1' if your have sendmsg() function]) 2153 AS_VAR_IF([[mhd_cv_find_lib_sendmsg]],[["none required"]], [], 2154 [ 2155 MHD_LIBDEPS_PKGCFG="${mhd_cv_find_lib_sendmsg} $MHD_LIBDEPS_PKGCFG" 2156 ] 2157 ) 2158 ],[], 2159 [MHD_LIBDEPS] 2160 ) 2161 2162 AC_C_BIGENDIAN 2163 AC_C_VARARRAYS 2164 2165 AC_CACHE_CHECK([[whether __func__ magic-macro is available]], 2166 [[mhd_cv_macro___func___avail]], [dnl 2167 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[const char *funcname = __func__ ; if (!funcname) return 1;]])], 2168 [[mhd_cv_macro___func___avail="yes"]],[[mhd_cv_macro___func___avail="no"]]) 2169 ]) 2170 AS_VAR_IF([mhd_cv_macro___func___avail], ["yes"], 2171 [AC_DEFINE([HAVE___FUNC__], [1], [Define to 1 if your compiler supports __func__ magic-macro.])], 2172 [ 2173 AC_CACHE_CHECK([[whether __FUNCTION__ magic-macro is available]], 2174 [[mhd_cv_macro___function___avail]], [dnl 2175 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[const char *funcname = __FUNCTION__ ; if (!funcname) return 1;]])], 2176 [[mhd_cv_macro___function___avail="yes"]],[[mhd_cv_macro___function___avail="no"]]) 2177 ]) 2178 AS_VAR_IF([mhd_cv_macro___function___avail], ["yes"], 2179 [AC_DEFINE([HAVE___FUNCTION__], [1], [Define to 1 if your compiler supports __FUNCTION__ magic-macro.])], 2180 [ 2181 AC_CACHE_CHECK([[whether __PRETTY_FUNCTION__ magic-macro is available]], 2182 [[mhd_cv_macro___pretty_function___avail]], [dnl 2183 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[const char *funcname = __PRETTY_FUNCTION__ ; if (!funcname) return 1;]])], 2184 [[mhd_cv_macro___pretty_function___avail="yes"]],[[mhd_cv_macro___pretty_function___avail="no"]]) 2185 ]) 2186 AS_VAR_IF([mhd_cv_macro___pretty_function___avail], ["yes"], 2187 [AC_DEFINE([HAVE___PRETTY_FUNCTION__], [1], [Define to 1 if your compiler supports __PRETTY_FUNCTION__ magic-macro.])], 2188 ) 2189 ] 2190 ) 2191 ] 2192 ) 2193 AC_CACHE_CHECK([[whether __builtin_bswap32() is available]], 2194 [[mhd_cv_func___builtin_bswap32_avail]], [dnl 2195 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include<stdint.h>]], [[uint32_t a = 1; uint32_t b = __builtin_bswap32(a); a = b; (void) a;]])], 2196 [[mhd_cv_func___builtin_bswap32_avail="yes"]],[[mhd_cv_func___builtin_bswap32_avail="no"]]) 2197 ]) 2198 AS_IF([[test "x$mhd_cv_func___builtin_bswap32_avail" = "xyes"]], 2199 [AC_DEFINE([[MHD_HAVE___BUILTIN_BSWAP32]], [[1]], [Define to 1 if you have __builtin_bswap32() builtin function])]) 2200 AC_CACHE_CHECK([[whether __builtin_bswap64() is available]], 2201 [[mhd_cv_func___builtin_bswap64_avail]], [dnl 2202 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include<stdint.h>]], [[uint64_t a = 1; uint64_t b = __builtin_bswap64(a); a = b; (void) a;]])], 2203 [[mhd_cv_func___builtin_bswap64_avail="yes"]], [[mhd_cv_func___builtin_bswap64_avail="no"]]) 2204 ]) 2205 AS_IF([[test "x$mhd_cv_func___builtin_bswap64_avail" = "xyes"]], 2206 [AC_DEFINE([[MHD_HAVE___BUILTIN_BSWAP64]], [[1]], [Define to 1 if you have __builtin_bswap64() builtin function])]) 2207 2208 AC_CHECK_PROG([HAVE_CURL_BINARY],[curl],[yes],[no]) 2209 AM_CONDITIONAL([HAVE_CURL_BINARY],[test "x$HAVE_CURL_BINARY" = "xyes"]) 2210 AC_CHECK_PROG([HAVE_MAKEINFO_BINARY],[makeinfo],[yes],[no]) 2211 AM_CONDITIONAL([HAVE_MAKEINFO_BINARY],[test "x$HAVE_MAKEINFO_BINARY" = "xyes"]) 2212 AM_CONDITIONAL(W32_STATIC_LIB, [test "x$os_is_native_w32" = "xyes" && test "x$enable_static" = "xyes"]) 2213 2214 2215 AC_ARG_ENABLE([[doc]], 2216 [AS_HELP_STRING([[--disable-doc]], [do not build any documentation])], , 2217 [enable_doc=yes]) 2218 test "x$enable_doc" = "xno" || enable_doc=yes 2219 AM_CONDITIONAL([BUILD_DOC], [test "x$enable_doc" = "xyes"]) 2220 2221 AC_ARG_ENABLE([[examples]], 2222 [AS_HELP_STRING([[--disable-examples]], [do not build any examples])], , 2223 [enable_examples=yes]) 2224 test "x$enable_examples" = "xno" || enable_examples=yes 2225 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" = "xyes"]) 2226 2227 AC_ARG_ENABLE([[tools]], 2228 [AS_HELP_STRING([[--disable-tools]], [do not build testing and demo tools])], , 2229 [enable_tools=yes]) 2230 test "x$enable_tools" = "xyes" || enable_tools=no 2231 AM_CONDITIONAL([BUILD_TOOLS], [test "x$enable_tools" = "xyes"]) 2232 2233 AC_ARG_ENABLE([[heavy-tests]], 2234 [AS_HELP_STRING([[--enable-heavy-tests[=SCOPE]]], [use SCOPE of heavy tests in test-suite. WARNING:] 2235 [a dedicated host with minimal number of background processes and no network] 2236 [activity is recommended to enable. (basic, full)])], [], 2237 [enable_heavy_tests=no]) 2238 use_heavy_tests="no" 2239 use_vheavy_tests="no" 2240 use_heavy_tests_MSG="no" 2241 AS_CASE([${enable_heavy_tests}], 2242 [yes|basic], 2243 [ 2244 enable_heavy_tests="basic" 2245 use_heavy_tests="yes" 2246 use_vheavy_tests="no" 2247 use_heavy_tests_MSG="yes, basic heavy tests (a dedicated host is recommended)" 2248 ], 2249 [all|full], 2250 [ 2251 enable_heavy_tests="full" 2252 use_heavy_tests="yes" 2253 use_vheavy_tests="yes" 2254 use_heavy_tests_MSG="yes, full set of heavy tests (a dedicated host is recommended)" 2255 ], 2256 [no], 2257 [ 2258 use_heavy_tests="no" 2259 use_vheavy_tests="no" 2260 use_heavy_tests_MSG="no" 2261 ], 2262 [AC_MSG_ERROR([[Unknown parameter value: --enable-heavy-tests=${enable_heavy_tests}]])] 2263 ) 2264 AS_VAR_IF([use_heavy_tests], ["yes"], 2265 [ 2266 HEAVY_TESTS_NOTPARALLEL='.NOTPARALLEL:' 2267 AC_DEFINE([_MHD_HEAVY_TESTS], [1], [Define to 1 to enable "heavy" test paths.]) 2268 AS_VAR_IF([use_vheavy_tests], ["yes"], 2269 [AC_DEFINE([_MHD_VHEAVY_TESTS], [1], [Define to 1 to enable "very heavy" test paths.])] 2270 ) 2271 ], 2272 [ 2273 HEAVY_TESTS_NOTPARALLEL=" " 2274 ] 2275 ) 2276 AM_CONDITIONAL([HEAVY_TESTS],[test "x$use_heavy_tests" = "xyes"]) 2277 AM_CONDITIONAL([VHEAVY_TESTS],[test "x$use_vheavy_tests" = "xyes"]) 2278 AM_CONDITIONAL([TESTS_STRESS_OS],[false]) 2279 2280 AC_ARG_ENABLE([[poll]], 2281 [AS_HELP_STRING([[--enable-poll[=ARG]]], [enable poll support (yes, no, auto) [auto]])], 2282 [enable_poll=${enableval}], 2283 [enable_poll='auto'] 2284 ) 2285 2286 AS_IF([test "$enable_poll" != "no"], 2287 [ 2288 AS_IF([test "$os_is_native_w32" != "yes"], 2289 [ 2290 AC_CHECK_HEADERS([poll.h], 2291 [ 2292 MHD_CHECK_FUNC([poll], 2293 [[ 2294 #include <poll.h> 2295 ]], 2296 [[ 2297 struct pollfd fds[2]; 2298 2299 fds[0].fd = 0; 2300 fds[0].events = POLLIN; 2301 if (0 > poll(fds, 1, 0)) 2302 return 2; 2303 ]], 2304 [have_poll='yes'], [have_poll='no'] 2305 ) 2306 ], [], [AC_INCLUDES_DEFAULT] 2307 ) 2308 ], 2309 [ 2310 MHD_CHECK_FUNC([WSAPoll], 2311 [[ 2312 #include <winsock2.h> 2313 ]], 2314 [[ 2315 WSAPOLLFD fda[2]; 2316 WSAPoll(fda, 2, 0); 2317 ]], 2318 [ 2319 have_poll='yes' 2320 AC_DEFINE([HAVE_POLL],[1]) 2321 ], 2322 [have_poll='no'] 2323 ) 2324 ] 2325 ) 2326 AS_IF([test "$enable_poll" = "yes" && test "$have_poll" != "yes"], 2327 [AC_MSG_ERROR([[Support for poll was explicitly requested but cannot be enabled on this platform.]])]) 2328 enable_poll="$have_poll" 2329 ] 2330 ) 2331 2332 AC_ARG_ENABLE([[epoll]], 2333 [AS_HELP_STRING([[--enable-epoll[=ARG]]], [enable epoll support (yes, no, auto) [auto]])], 2334 [enable_epoll=${enableval}], 2335 [enable_epoll='auto'] 2336 ) 2337 2338 AS_IF([test "$enable_epoll" != "no"], 2339 [ 2340 MHD_CHECK_FUNC_RUN([epoll_create], 2341 [[ 2342 #include <sys/epoll.h> 2343 #include <unistd.h> 2344 ]], 2345 [[ 2346 int epfd = epoll_create(64); 2347 i][f (0 > epfd) return -epfd; 2348 (void) close(epfd); 2349 return 0; 2350 ]], 2351 [cacheVar="assuming yes"], 2352 [ 2353 AC_DEFINE([[EPOLL_SUPPORT]],[[1]],[Define to 1 to enable epoll support]) 2354 enable_epoll='yes' 2355 ], 2356 [ 2357 AS_IF([test "$enable_epoll" = "yes"], 2358 [AC_MSG_ERROR([[Support for epoll was explicitly requested but cannot be enabled on this platform.]])] 2359 ) 2360 enable_epoll='no' 2361 ] 2362 ) 2363 AS_UNSET([warn_msg]) 2364 AS_VAR_IF([mhd_cv_works_func_epoll_create],["assuming yes"], 2365 [[warn_msg="When cross-compiling it is not possible to check whether 'epoll_create()' really works on the host (final) platform. 2366 'epoll' is enabled as most probably the host kernel supports it (CONFIG_EPOLL option enabled in case of Linux kernel). 2367 Use './configure mhd_cv_works_func_epoll_create=yes' to mute this warning."]] 2368 ) 2369 AS_VAR_SET_IF([warn_msg],[AC_MSG_WARN([$warn_msg]) 2370 AS_IF([test -n "${CONF_FINAL_WARNS}" ], 2371 [ 2372 CONF_FINAL_WARNS="${CONF_FINAL_WARNS} 2373 2374 WARNING: " 2375 ] 2376 ) 2377 CONF_FINAL_WARNS="${CONF_FINAL_WARNS}${warn_msg}" 2378 ] 2379 ) 2380 ] 2381 ) 2382 2383 AM_CONDITIONAL([MHD_HAVE_EPOLL], [[test "x$enable_epoll" = xyes]]) 2384 2385 AS_IF([test "x$enable_epoll" = "xyes"], 2386 [ 2387 MHD_CHECK_FUNC([epoll_create1], 2388 [[ 2389 #include <sys/epoll.h> 2390 ]], 2391 [[ 2392 i][f (0 > epoll_create1(EPOLL_CLOEXEC)) 2393 return 3; 2394 ]] 2395 ) 2396 ] 2397 ) 2398 2399 AC_CACHE_CHECK([for supported 'noreturn' keyword], [mhd_cv_decl_noreturn], 2400 [ 2401 mhd_cv_decl_noreturn="none" 2402 CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}" 2403 MHD_SAVED_ac_c_werror_flag="$ac_c_werror_flag" 2404 ac_c_werror_flag=yes 2405 for decl_noret in ['[[noreturn]]'] '_Noreturn' '__attribute__((__noreturn__))' '__declspec(noreturn)' 2406 do 2407 AC_LINK_IFELSE([AC_LANG_SOURCE( 2408 [[ 2409 #ifdef HAVE_STDLIB_H 2410 #include <stdlib.h> 2411 #endif 2412 2413 ${decl_noret} static void myexitfunc(int code) 2414 { 2415 #ifdef HAVE_STDLIB_H 2416 exit (code); 2417 #else 2418 (void)code; 2419 #endif 2420 } 2421 2422 int main (int argc, char *const *argv) 2423 { 2424 (void) argv; 2425 if (argc > 2) 2426 myexitfunc (2); 2427 return 0; 2428 } 2429 ]] 2430 )], [mhd_cv_decl_noreturn="${decl_noret}"] 2431 ) 2432 AS_IF([test "x${mhd_cv_decl_noreturn}" != "xnone"], [break]) 2433 done 2434 ac_c_werror_flag="$MHD_SAVED_ac_c_werror_flag" 2435 AS_UNSET([MHD_SAVED_ac_c_werror_flag]) 2436 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 2437 ] 2438 ) 2439 AS_VAR_IF([mhd_cv_decl_noreturn], ["none"], 2440 [AC_DEFINE([_MHD_NORETURN], [], [Define to supported 'noreturn' function declaration])], 2441 [AC_DEFINE_UNQUOTED([_MHD_NORETURN], [${mhd_cv_decl_noreturn}], [Define to supported 'noreturn' function declaration])] 2442 ) 2443 2444 # Check for types sizes 2445 # Types sizes are used as an indirect indication of maximum allowed values for types 2446 # which is used to exclude by preprocessor some compiler checks for values clips 2447 # Assuming no staffing or uniform staffing for integer types 2448 AC_CACHE_CHECK([size of tv_sec member of struct timeval], [mhd_cv_size_timeval_tv_sec], 2449 [ 2450 AC_COMPUTE_INT([mhd_cv_size_timeval_tv_sec], [((long int)sizeof(test_var.tv_sec))], 2451 [[ 2452 #ifdef HAVE_SYS_TIME_H 2453 #include <sys/time.h> 2454 #endif /* HAVE_SYS_TIME_H */ 2455 #ifdef HAVE_TIME_H 2456 #include <time.h> 2457 #endif /* HAVE_TIME_H */ 2458 #if HAVE_SYS_TYPES_H 2459 #include <sys/types.h> 2460 #endif /* HAVE_SYS_TYPES_H */ 2461 extern struct timeval test_var; /* Declaration */ 2462 struct timeval test_var = {0, 0}; /* Definition */ 2463 ]], 2464 [ 2465 # The size is used only to exclude additional checks/comparison in code 2466 # to avoid compiler warnings. With larger size MHD code will use 2467 # additional checks which ensure that value will fit but it may produce 2468 # a harmless compiler warning. 2469 AC_MSG_WARN([The size cannot be determined, assuming 8.]) 2470 mhd_cv_size_timeval_tv_sec=8 2471 ] 2472 ) 2473 ] 2474 ) 2475 AC_DEFINE_UNQUOTED([SIZEOF_STRUCT_TIMEVAL_TV_SEC], [$mhd_cv_size_timeval_tv_sec], 2476 [The size of `tv_sec' member of `struct timeval', as computed by sizeof]) 2477 AC_CHECK_SIZEOF([int64_t], [], [[#include <stdint.h>]]) 2478 AC_CHECK_SIZEOF([uint64_t], [], [[#include <stdint.h>]]) 2479 AC_CHECK_SIZEOF([int], [], [[#include <stdint.h>]]) 2480 AC_CHECK_SIZEOF([unsigned int], [], [[#include <stdint.h>]]) 2481 AC_CHECK_SIZEOF([unsigned long long], [], [[#include <stdint.h>]]) 2482 AC_CHECK_SIZEOF([size_t], [], 2483 [[ 2484 #ifdef HAVE_STDLIB_H 2485 #include <stdlib.h> 2486 #endif /* HAVE_STDLIB_H */ 2487 #ifdef HAVE_STDDEF_H 2488 #include <stddef.h> 2489 #endif /* HAVE_STDDEF_H */ 2490 #include <stdio.h> 2491 ]] 2492 ) 2493 2494 AC_CHECK_HEADERS([dlfcn.h],[have_tlsplugin=yes],[have_tlsplugin=no], [AC_INCLUDES_DEFAULT]) 2495 AM_CONDITIONAL([MHD_HAVE_TLS_PLUGIN], [[test "x$have_tlsplugin" = xyes]]) 2496 2497 AC_CHECK_HEADERS([zlib.h],[have_zlib=yes],[have_zlib=no], [AC_INCLUDES_DEFAULT]) 2498 AM_CONDITIONAL([HAVE_ZLIB], [[test "x$have_zlib" = xyes]]) 2499 2500 AC_CHECK_HEADERS([jansson.h],[have_json=yes],[have_json=no], [AC_INCLUDES_DEFAULT]) 2501 AM_CONDITIONAL([HAVE_JANSSON], [[test "x$have_json" = xyes]]) 2502 2503 # Check for generic functions 2504 MHD_CHECK_FUNC([random], 2505 [ 2506 AC_INCLUDES_DEFAULT 2507 [#include <stdlib.h> 2508 ]], 2509 [[long int r = random(); (void)r;]], 2510 [], 2511 [ 2512 MHD_CHECK_FUNC([rand], 2513 [ 2514 AC_INCLUDES_DEFAULT 2515 [#include <stdlib.h> 2516 ]], 2517 [[int r = rand(); (void)r;]], 2518 ) 2519 ] 2520 ) 2521 2522 AC_CHECK_MEMBERS([struct sockaddr.sa_len, struct sockaddr_storage.ss_len, 2523 struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], 2524 [], [], 2525 [ 2526 #ifdef HAVE_SYS_TYPES_H 2527 #include <sys/types.h> 2528 #endif 2529 #ifdef HAVE_SYS_SOCKET_H 2530 #include <sys/socket.h> 2531 #endif 2532 #ifdef HAVE_NETINET_IN_H 2533 #include <netinet/in.h> 2534 #endif 2535 #ifdef HAVE_WINSOCK2_H 2536 #include <winsock2.h> 2537 #endif 2538 #ifdef HAVE_WS2TCPIP_H 2539 #include <ws2tcpip.h> 2540 #endif 2541 ]) 2542 2543 MHD_CHECK_FUNC_RUN([getsockname], 2544 [[ 2545 #ifdef HAVE_SYS_TYPES_H 2546 #include <sys/types.h> 2547 #endif 2548 #include <string.h> 2549 #ifdef HAVE_SYS_SOCKET_H 2550 #include <sys/socket.h> 2551 #endif 2552 #ifdef HAVE_UNISTD_H 2553 #include <unistd.h> 2554 #endif 2555 #ifdef HAVE_WINSOCK2_H 2556 #include <winsock2.h> 2557 #endif 2558 #ifdef HAVE_WS2TCPIP_H 2559 #include <ws2tcpip.h> 2560 #endif 2561 #ifdef HAVE_NETINET_IN_H 2562 #include <netinet/in.h> 2563 #endif 2564 #ifdef HAVE_NETINET_IP_H 2565 #include <netinet/ip.h> 2566 #endif 2567 #ifdef HAVE_ARPA_INET_H 2568 #include <arpa/inet.h> 2569 #endif 2570 2571 ]], 2572 [[ 2573 const socklen_t c_addr_size = (socklen_t)sizeof(struct sockaddr_in); 2574 struct sockaddr_in sa; 2575 socklen_t addr_size; 2576 int ret = 1; 2577 #if !defined(_WIN32) || defined(__CYGWIN__) 2578 int sckt; 2579 const int invld_sckt = -1; 2580 #else 2581 SOCKET sckt; 2582 const SOCKET invld_sckt = INVALID_SOCKET; 2583 WSADATA wsa_data; 2584 2585 i][f (0 != WSAStartup(MAKEWORD(2, 2), &wsa_data) || MAKEWORD(2, 2) != wsa_data.wVersion) 2586 return 20; 2587 #endif 2588 2589 sckt = socket (PF_INET, SOCK_STREAM, 0); 2590 i][f (invld_sckt != sckt) 2591 { 2592 memset(&sa, 0, c_addr_size); 2593 sa.sin_family = AF_INET; 2594 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN 2595 sa.sin_len = c_addr_size; 2596 #endif 2597 i][f (0 == bind (sckt, (struct sockaddr *)&sa, c_addr_size)) 2598 { 2599 i][f (0 == listen (sckt, 1)) 2600 { 2601 addr_size = c_addr_size; 2602 i][f (0 == getsockname (sckt, (struct sockaddr *)&sa, &addr_size)) 2603 { 2604 i][f (c_addr_size >= addr_size) 2605 { 2606 i][f (0 != ntohs(sa.sin_port)) 2607 { ret = 0; 2608 } el][se ret = 7; 2609 } el][se ret = 6; 2610 } el][se ret = 5; 2611 } el][se ret = 4; 2612 } el][se ret = 3; 2613 } el][se ret = 2; 2614 #if !defined(_WIN32) || defined(__CYGWIN__) 2615 close (sckt); 2616 #else 2617 closesocket (sckt); 2618 WSACleanup(); 2619 #endif 2620 return ret; 2621 ]], 2622 [cacheVar='assuming yes'], 2623 [AC_DEFINE([[MHD_USE_GETSOCKNAME]], [[1]], [Define if you have usable `getsockname' function.])] 2624 ) 2625 2626 AC_CACHE_CHECK([for usable PAGESIZE macro], [mhd_cv_macro_pagesize_usable], 2627 [ 2628 AC_LINK_IFELSE( 2629 [ 2630 AC_LANG_PROGRAM( 2631 [[ 2632 #ifdef HAVE_UNISTD_H 2633 #include <unistd.h> 2634 #endif 2635 #ifdef HAVE_LIMITS_H 2636 #include <limits.h> 2637 #endif 2638 #ifdef HAVE_SYS_PARAM_H 2639 #include <sys/param.h> 2640 #endif 2641 #ifndef PAGESIZE 2642 #error No PAGESIZE macro defined 2643 choke me now 2644 #endif 2645 ]], 2646 [[ 2647 long pgsz = PAGESIZE + 0; 2648 if (1 > pgsz) return 1; 2649 ]] 2650 ) 2651 ], 2652 [[mhd_cv_macro_pagesize_usable="yes"]], [[mhd_cv_macro_pagesize_usable="no"]] 2653 ) 2654 ] 2655 ) 2656 AS_VAR_IF([[mhd_cv_macro_pagesize_usable]], [["yes"]], 2657 [ 2658 AC_DEFINE([[MHD_USE_PAGESIZE_MACRO]],[[1]],[Define if you have usable PAGESIZE macro]) 2659 AC_CACHE_CHECK([whether PAGESIZE macro could be used for static init], [mhd_cv_macro_pagesize_usable_static], 2660 [ 2661 AC_LINK_IFELSE( 2662 [ 2663 AC_LANG_PROGRAM( 2664 [[ 2665 #ifdef HAVE_UNISTD_H 2666 #include <unistd.h> 2667 #endif 2668 #ifdef HAVE_LIMITS_H 2669 #include <limits.h> 2670 #endif 2671 #ifdef HAVE_SYS_PARAM_H 2672 #include <sys/param.h> 2673 #endif 2674 #ifndef PAGESIZE 2675 #error No PAGESIZE macro defined 2676 choke me now 2677 #endif 2678 static long ac_pgsz = PAGESIZE + 0; 2679 ]], 2680 [[ 2681 if (1 > ac_pgsz) return 1; 2682 ]] 2683 ) 2684 ], 2685 [[mhd_cv_macro_pagesize_usable_static="yes"]], [[mhd_cv_macro_pagesize_usable_static="no"]] 2686 ) 2687 ] 2688 ) 2689 AS_VAR_IF([[mhd_cv_macro_pagesize_usable_static]], [["yes"]], 2690 [AC_DEFINE([[MHD_USE_PAGESIZE_MACRO_STATIC]],[[1]],[Define if you have PAGESIZE macro usable for static init])] 2691 ) 2692 ], 2693 [ 2694 AC_CACHE_CHECK([for usable PAGE_SIZE macro], [mhd_cv_macro_page_size_usable], 2695 [ 2696 AC_LINK_IFELSE( 2697 [ 2698 AC_LANG_PROGRAM( 2699 [[ 2700 #ifdef HAVE_UNISTD_H 2701 #include <unistd.h> 2702 #endif 2703 #ifdef HAVE_LIMITS_H 2704 #include <limits.h> 2705 #endif 2706 #ifdef HAVE_SYS_PARAM_H 2707 #include <sys/param.h> 2708 #endif 2709 #ifndef PAGE_SIZE 2710 #error No PAGE_SIZE macro defined 2711 choke me now 2712 #endif 2713 ]], 2714 [[ 2715 long pgsz = PAGE_SIZE + 0; 2716 if (1 > pgsz) return 1; 2717 ]] 2718 ) 2719 ], 2720 [[mhd_cv_macro_page_size_usable="yes"]], [[mhd_cv_macro_page_size_usable="no"]] 2721 ) 2722 ] 2723 ) 2724 AS_VAR_IF([[mhd_cv_macro_page_size_usable]], [["yes"]], 2725 [ 2726 AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO]],[[1]],[Define if you have usable PAGE_SIZE macro]) 2727 AC_CACHE_CHECK([whether PAGE_SIZE macro could be used for static init], [mhd_cv_macro_page_size_usable_static], 2728 [ 2729 AC_LINK_IFELSE( 2730 [ 2731 AC_LANG_PROGRAM( 2732 [[ 2733 #ifdef HAVE_UNISTD_H 2734 #include <unistd.h> 2735 #endif 2736 #ifdef HAVE_LIMITS_H 2737 #include <limits.h> 2738 #endif 2739 #ifdef HAVE_SYS_PARAM_H 2740 #include <sys/param.h> 2741 #endif 2742 #ifndef PAGE_SIZE 2743 #error No PAGE_SIZE macro defined 2744 choke me now 2745 #endif 2746 static long ac_pgsz = PAGE_SIZE + 0; 2747 ]], 2748 [[ 2749 if (1 > ac_pgsz) return 1; 2750 ]] 2751 ) 2752 ], 2753 [[mhd_cv_macro_page_size_usable_static="yes"]], [[mhd_cv_macro_page_size_usable_static="no"]] 2754 ) 2755 ] 2756 ) 2757 AS_VAR_IF([[mhd_cv_macro_page_size_usable_static]], [["yes"]], 2758 [AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO_STATIC]],[[1]],[Define if you have PAGE_SIZE macro usable for static init])] 2759 ) 2760 ] 2761 ) 2762 ] 2763 ) 2764 2765 # Check for inter-thread signaling type 2766 AC_ARG_ENABLE([[itc]], 2767 [AS_HELP_STRING([[--enable-itc=TYPE]], [use TYPE of inter-thread communication (pipe, socketpair, eventfd) [auto]])], [], 2768 [[enable_itc='auto']] 2769 ) 2770 2771 AS_CASE([[$enable_itc]], 2772 [[pipe]], [[:]], 2773 [[socketpair]], [[:]], 2774 [[eventfd]], [[:]], 2775 [[auto]], [AS_VAR_IF([[os_is_windows]], [["yes"]], [[enable_itc='socketpair']])], 2776 [[eventFD]], [[enable_itc='eventfd']], 2777 [[socket]], [[enable_itc='socketpair']], 2778 [[no]], [AC_MSG_ERROR([[inter-thread communication cannot be disabled]])], 2779 [AC_MSG_ERROR([[unrecognized type "$enable_itc" of inter-thread communication specified by "--enable-itc=$enable_itc"]])] 2780 ) 2781 AS_UNSET([[use_itc]]) 2782 2783 AS_IF([[test "x$enable_itc" = "xeventfd" || test "x$enable_itc" = "xauto"]], 2784 [ 2785 MHD_CHECK_FUNC_RUN([eventfd],[[ 2786 #include <sys/eventfd.h> 2787 #include <unistd.h> 2788 ]], 2789 [[ 2790 static unsigned char buf[8]; 2791 int ret; 2792 int efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); 2793 i][f (0 > efd) 2794 return 2; 2795 ret = 0; 2796 buf[3] = 1; 2797 i][f (8 != write(efd, buf, 8)) 2798 ret = 3; 2799 el][se 2800 { 2801 i][f (8 != read(efd, buf, 8)) 2802 ret = 4; 2803 } 2804 close(efd); 2805 return ret; 2806 ]], 2807 [ 2808 AS_VAR_IF([enable_itc],["eventfd"], 2809 [cacheVar="assuming yes"],[cacheVar="assuming no"] 2810 ) 2811 ], 2812 [ 2813 use_itc='eventfd' 2814 enable_itc="$use_itc" 2815 AC_DEFINE([[_MHD_ITC_EVENTFD]], [[1]], [Define to use eventFD f][or inter-thread communication]) 2816 ] 2817 ) 2818 AS_UNSET([warn_msg]) 2819 AS_VAR_IF([mhd_cv_works_func_eventfd],["assuming yes"], 2820 [[warn_msg="When cross-compiling it is not possible to check whether 'eventfd()' really works on the host (final) platform. 2821 'eventfd' is enabled as requested by configure parameters. 2822 Use './configure mhd_cv_works_func_eventfd=yes' to mute this warning."]] 2823 ) 2824 AS_VAR_IF([mhd_cv_works_func_eventfd],["assuming no"], 2825 [[warn_msg="When cross-compiling it is not possible to check whether 'eventfd()' really works on the host (final) platform. 2826 'eventfd()' is disabled. If it is available use './configure mhd_cv_works_func_eventfd=yes' to enable. 2827 Use './configure mhd_cv_works_func_eventfd=no' to mute this warning."]] 2828 ) 2829 AS_VAR_SET_IF([warn_msg],[AC_MSG_WARN([$warn_msg]) 2830 AS_IF([test -n "${CONF_FINAL_WARNS}" ], 2831 [ 2832 CONF_FINAL_WARNS="${CONF_FINAL_WARNS} 2833 2834 WARNING: " 2835 ] 2836 ) 2837 CONF_FINAL_WARNS="${CONF_FINAL_WARNS}${warn_msg}" 2838 ] 2839 ) 2840 ] 2841 ) 2842 2843 AS_IF([[test "x$enable_itc" = "xpipe" || test "x$enable_itc" = "xauto"]], [ 2844 AS_VAR_IF([[os_is_native_w32]], [["yes"]], [], [ 2845 AC_CACHE_CHECK([[whether pipe(3) is usable]], [[mhd_cv_pipe_usable]], [ 2846 AC_LINK_IFELSE([ 2847 AC_LANG_PROGRAM([ 2848 AC_INCLUDES_DEFAULT 2849 #ifdef HAVE_UNISTD_H 2850 #include <unistd.h> 2851 #endif 2852 ], [[ 2853 int arr[2]; 2854 int res; 2855 res = pipe(arr); 2856 if (res != 0) return 33; 2857 close (arr[0]); 2858 close (arr[1]); 2859 ]]) 2860 ], [[mhd_cv_pipe_usable='yes']], [[mhd_cv_pipe_usable='no']]) 2861 ]) 2862 AS_VAR_IF([[mhd_cv_pipe_usable]], [["yes"]], [ 2863 use_itc='pipe' 2864 enable_itc="$use_itc" 2865 AC_DEFINE([[_MHD_ITC_PIPE]], [[1]], [Define to use pipe for inter-thread communication]) 2866 MHD_CHECK_FUNC_RUN([pipe2],[ 2867 AC_INCLUDES_DEFAULT 2868 [ 2869 #ifdef HAVE_FCNTL_H 2870 #include <fcntl.h> 2871 #endif 2872 #ifdef HAVE_UNISTD_H 2873 #include <unistd.h> 2874 #endif 2875 ]],[[ 2876 int arr[2]; 2877 int res; 2878 res = pipe2(arr, O_CLOEXEC | O_NONBLOCK); 2879 i][f (res != 0) return 33; 2880 close (arr[0]); 2881 close (arr[1]); 2882 return 0; 2883 ]],[ 2884 # Cross-compiling 2885 AS_CASE([${host_os}], [kfreebsd*-gnu], [cacheVar='assuming no'], 2886 [cacheVar='assuming yes']) 2887 ], 2888 [AC_DEFINE([[HAVE_PIPE2_FUNC]], [[1]], [Define i][f you have usable pipe2(2) function])], 2889 ) 2890 ], [ 2891 AS_VAR_IF([[enable_itc]], [["pipe"]], [AC_MSG_ERROR([[pipe(3) is not usable, consider using other type of inter-thread communication]])]) 2892 ]) 2893 ]) 2894 ]) 2895 2896 AS_IF([[test "x$enable_itc" = "xsocketpair" || test "x$enable_itc" = "xauto"]], [ 2897 AS_VAR_IF([[os_is_native_w32]], [["yes"]], [[mhd_cv_socketpair_usable='yes']], [ 2898 AC_CACHE_CHECK([[whether socketpair(3) is usable]], [[mhd_cv_socketpair_usable]], [ 2899 AC_LINK_IFELSE([ 2900 AC_LANG_PROGRAM([ 2901 AC_INCLUDES_DEFAULT 2902 #ifdef HAVE_SYS_TYPES_H 2903 #include <sys/types.h> 2904 #endif 2905 #ifdef HAVE_SYS_SOCKET_H 2906 #include <sys/socket.h> 2907 #endif 2908 ], [[ 2909 int arr[2]; 2910 int res; 2911 #if defined(AF_LOCAL) 2912 res = socketpair(AF_LOCAL, SOCK_STREAM, 0, arr); 2913 #elif defined(AF_UNIX) 2914 res = socketpair(AF_UNIX, SOCK_STREAM, 0, arr); 2915 #else 2916 #error AF_LOCAL and AF_UNIX are both undefined 2917 choke me now; 2918 #endif 2919 if (res != 0) return 1 2920 ]]) 2921 ], [[mhd_cv_socketpair_usable='yes']], [[mhd_cv_socketpair_usable='no']]) 2922 ]) 2923 ]) 2924 AS_VAR_IF([[mhd_cv_socketpair_usable]], [["yes"]], [ 2925 use_itc='socketpair' 2926 enable_itc="$use_itc" 2927 AC_DEFINE([[_MHD_ITC_SOCKETPAIR]], [[1]], [Define to use socketpair for inter-thread communication]) 2928 ], [ 2929 AS_VAR_IF([[enable_itc]], [["socketpair"]], [AC_MSG_ERROR([[socketpair(3) is not usable, consider using other type of inter-thread communication]])]) 2930 ]) 2931 ]) 2932 2933 AS_IF([[test -z "$use_itc"]], [AC_MSG_ERROR([[cannot find usable type of inter-thread communication]])]) 2934 2935 2936 MHD_CHECK_FUNC([accept4], 2937 [[ 2938 #if defined(HAVE_SYS_TYPES_H) 2939 # include <sys/types.h> 2940 #endif 2941 #include <sys/socket.h> 2942 ]], 2943 [[ 2944 struct sockaddr sk_addr; 2945 socklen_t addr_size; 2946 i][f (0 > accept4(0, &sk_addr, &addr_size, 0)) 2947 return 3; 2948 ]] 2949 ) 2950 MHD_CHECK_FUNC([gmtime_r], 2951 [[ 2952 #if defined(HAVE_SYS_TYPES_H) 2953 # include <sys/types.h> 2954 #endif 2955 #include <time.h> 2956 ]], 2957 [[ 2958 time_t timer = (time_t) 0; 2959 struct tm res; 2960 2961 i][f (&res != gmtime_r(&timer, &res)) 2962 return 3; 2963 ]] 2964 ) 2965 MHD_CHECK_FUNC([memmem], 2966 [[ 2967 #if defined(HAVE_STDDEF_H) 2968 # include <stddef.h> 2969 #elif defined(HAVE_STDLIB_H) 2970 # include <stdlib.h> 2971 #endif /* HAVE_STDLIB_H */ 2972 #include <string.h> 2973 ]], 2974 [[ 2975 const char *haystack = "abc"; 2976 size_t hslen = 3; 2977 const char *needle = "b"; 2978 size_t needlelen = 1; 2979 2980 i][f ((haystack + 1) != memmem(haystack, hslen, needle, needlelen)) 2981 return 3; 2982 ]] 2983 ) 2984 MHD_CHECK_FUNC([snprintf], 2985 [[ 2986 #include <stdio.h> 2987 ]], 2988 [[ 2989 char buf[2]; 2990 2991 i][f (1 != snprintf(buf, 2, "a")) 2992 return 3; 2993 /* Do not use the next check to avoid compiler warning */ 2994 /* i][f (4 != snprintf(buf, 2, "abcd")) 2995 return 4; */ 2996 ]] 2997 ) 2998 AC_CHECK_DECL([gmtime_s], 2999 [ 3000 AC_MSG_CHECKING([[whether gmtime_s is in C11 form]]) 3001 AC_LINK_IFELSE( 3002 [ AC_LANG_PROGRAM( 3003 [[ 3004 #define __STDC_WANT_LIB_EXT1__ 1 3005 #include <time.h> 3006 #ifdef __cplusplus 3007 extern "C" 3008 #endif 3009 struct tm* gmtime_s(const time_t* time, struct tm* result); 3010 ]], [[ 3011 static struct tm res; 3012 static time_t t = 0; 3013 gmtime_s (&t, &res); 3014 ]]) 3015 ], 3016 [ 3017 AC_DEFINE([HAVE_C11_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in C11 form.]) 3018 AC_MSG_RESULT([[yes]]) 3019 ], 3020 [ 3021 AC_MSG_RESULT([[no]]) 3022 AC_MSG_CHECKING([[whether gmtime_s is in W32 form]]) 3023 AC_LINK_IFELSE( 3024 [ AC_LANG_PROGRAM( 3025 [[ 3026 #include <time.h> 3027 #ifdef __cplusplus 3028 extern "C" 3029 #endif 3030 errno_t gmtime_s(struct tm* _tm, const time_t* time); 3031 ]], [[ 3032 static struct tm res; 3033 static time_t t = 0; 3034 gmtime_s (&res, &t); 3035 ]]) 3036 ], 3037 [ 3038 AC_DEFINE([HAVE_W32_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in W32 form.]) 3039 AC_MSG_RESULT([[yes]]) 3040 ], 3041 [AC_MSG_RESULT([[no]]) 3042 ]) 3043 ]) 3044 ], [], 3045 [[#define __STDC_WANT_LIB_EXT1__ 1 3046 #include <time.h>]]) 3047 3048 3049 AC_CHECK_DECL([SOCK_NONBLOCK], [AC_DEFINE([HAVE_SOCK_NONBLOCK], [1], [SOCK_NONBLOCK is defined in a socket header])], [], 3050 [[ 3051 #if defined(HAVE_SYS_TYPES_H) 3052 # include <sys/types.h> 3053 #endif 3054 #if defined(HAVE_SYS_SOCKET_H) 3055 # include <sys/socket.h> 3056 #elif defined(HAVE_WINSOCK2_H) 3057 # include <winsock2.h> 3058 #endif 3059 ]] 3060 ) 3061 3062 MHD_FIND_LIB([clock_gettime],[[#include <time.h>]], 3063 [[ 3064 struct timespec tp; 3065 i][f (0 > clock_gettime(CLOCK_REALTIME, &tp)) 3066 return 3; 3067 ]], 3068 [rt], 3069 [ 3070 AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define to '1' if you have clock_gettime() function]) 3071 AS_VAR_IF([[mhd_cv_find_lib_clock_gettime]],[["none required"]], [], 3072 [ 3073 MHD_LIBDEPS_PKGCFG="${mhd_cv_find_lib_clock_gettime} $MHD_LIBDEPS_PKGCFG" 3074 ] 3075 ) 3076 ],[], 3077 [MHD_LIBDEPS] 3078 ) 3079 3080 MHD_CHECK_FUNC([clock_get_time], 3081 [[ 3082 #include <mach/clock.h> 3083 #include <mach/mach.h> 3084 ]], 3085 [[ 3086 clock_serv_t cs; 3087 mach_timespec_t mt; 3088 host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cs); 3089 clock_get_time(cs, &mt); 3090 mach_port_deallocate(mach_task_self(), cs); 3091 ]] 3092 ) 3093 3094 MHD_CHECK_FUNC([gethrtime], 3095 [[ 3096 #ifdef HAVE_SYS_TIME_H 3097 /* Solaris define gethrtime() in sys/time.h */ 3098 #include <sys/time.h> 3099 #endif /* HAVE_SYS_TIME_H */ 3100 #ifdef HAVE_TIME_H 3101 /* HP-UX define gethrtime() in time.h */ 3102 #include <time.h> 3103 #endif /* HAVE_TIME_H */ 3104 ]], 3105 [[ 3106 hrtime_t hrt = gethrtime(); 3107 i][f (0 == hrt) 3108 return 3; 3109 ]] 3110 ) 3111 3112 AS_VAR_IF([ac_cv_header_time_h], ["yes"], 3113 [ 3114 MHD_CHECK_FUNC([timespec_get], 3115 [[ 3116 #include <time.h> 3117 3118 #ifndef TIME_UTC 3119 #error TIME_UTC must be defined to use timespec_get() 3120 choke me now 3121 #endif 3122 ]], 3123 [[ 3124 struct timespec ts; 3125 i][f (TIME_UTC != timespec_get (&ts, TIME_UTC)) 3126 return 3; 3127 ]] 3128 ) 3129 ] 3130 ) 3131 3132 MHD_CHECK_FUNC_GETTIMEOFDAY 3133 3134 # IPv6 3135 AC_CACHE_CHECK([for IPv6],[mhd_cv_have_inet6], 3136 [ 3137 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 3138 #include <stdio.h> 3139 #ifdef HAVE_NETINET_IN_H 3140 #include <netinet/in.h> 3141 #endif 3142 #ifdef HAVE_SYS_SOCKET_H 3143 #include <sys/socket.h> 3144 #endif 3145 #ifdef HAVE_WINSOCK2_H 3146 #include <winsock2.h> 3147 #endif 3148 #ifdef HAVE_WS2TCPIP_H 3149 #include <ws2tcpip.h> 3150 #endif 3151 ]], [[ 3152 int af=AF_INET6; 3153 int pf=PF_INET6; 3154 struct sockaddr_in6 sa; 3155 printf("%d %d %p\n", af, pf, (void*) &sa); 3156 ]] 3157 ) 3158 ], 3159 [AS_VAR_SET([mhd_cv_have_inet6],["yes"])], 3160 [AS_VAR_SET([mhd_cv_have_inet6],["no"])] 3161 ) 3162 ] 3163 ) 3164 AS_VAR_IF([mhd_cv_have_inet6],["yes"], 3165 [AC_DEFINE([HAVE_INET6], [1], [Define to '1' if you have IPv6 headers])] 3166 ) 3167 3168 MHD_CHECK_FUNC([[sysconf]], [[#include <unistd.h>]], [[long a = sysconf(0); if (a) return 1;]]) 3169 3170 MHD_CHECK_FUNC([[sysctl]], [[ 3171 #ifdef HAVE_SYS_TYPES_H 3172 #include <sys/types.h> 3173 #endif 3174 #ifdef HAVE_SYS_SYSCTL_H 3175 #include <sys/sysctl.h> 3176 #endif 3177 #if defined(HAVE_STDDEF_H) 3178 #include <stddef.h> 3179 #elif defined(HAVE_STDLIB_H) 3180 #include <stdlib.h> 3181 #endif 3182 ]], [[ 3183 int mib[2] = {0, 0}; /* Avoid any platform-specific values */ 3184 i][f (sysctl(mib, 2, NULL, NULL, NULL, 0)) return 1; 3185 ]], 3186 [ 3187 AC_CHECK_DECLS([CTL_NET,PF_INET,IPPROTO_ICMP,ICMPCTL_ICMPLIM],[],[], 3188 [[ 3189 #ifdef HAVE_SYS_TYPES_H 3190 #include <sys/types.h> 3191 #endif /* HAVE_SYS_TYPES_H */ 3192 #ifdef HAVE_SYS_SYSCTL_H 3193 #include <sys/sysctl.h> 3194 #endif /* HAVE_SYS_SYSCTL_H */ 3195 #ifdef HAVE_SYS_SYSCTL_H 3196 #include <sys/sysctl.h> 3197 #endif /* HAVE_SYS_SYSCTL_H */ 3198 #ifdef HAVE_SYS_SOCKET_H 3199 #include <sys/socket.h> 3200 #endif /* HAVE_SYS_SOCKET_H */ 3201 #ifdef HAVE_NETINET_IN_SYSTM_H 3202 #include <netinet/in_systm.h> 3203 #endif /* HAVE_NETINET_IN_SYSTM_H */ 3204 #ifdef HAVE_NETINET_IN_H 3205 #include <netinet/in.h> 3206 #endif /* HAVE_NETINET_IN_H */ 3207 #ifdef HAVE_NETINET_IP_H 3208 #include <netinet/ip.h> 3209 #endif /* HAVE_NETINET_IP_H */ 3210 #ifdef HAVE_NETINET_IP_ICMP_H 3211 #include <netinet/ip_icmp.h> 3212 #endif /* HAVE_NETINET_IP_ICMP_H */ 3213 #ifdef HAVE_NETINET_ICMP_VAR_H 3214 #include <netinet/icmp_var.h> 3215 #endif /* HAVE_NETINET_ICMP_VAR_H */ 3216 ]] 3217 ) 3218 ] 3219 ) 3220 3221 MHD_CHECK_FUNC([[sysctlbyname]], [[ 3222 #ifdef HAVE_SYS_TYPES_H 3223 #include <sys/types.h> 3224 #endif 3225 #ifdef HAVE_SYS_SYSCTL_H 3226 #include <sys/sysctl.h> 3227 #endif 3228 #if defined(HAVE_STDDEF_H) 3229 #include <stddef.h> 3230 #elif defined(HAVE_STDLIB_H) 3231 #include <stdlib.h> 3232 #endif 3233 ]], [[sysctlbyname("test", NULL, NULL, NULL, 0);]] 3234 ) 3235 3236 MHD_CHECK_FUNC([[usleep]], [[#include <unistd.h>]], [[usleep(100000);]]) 3237 MHD_CHECK_FUNC([[nanosleep]], [[#include <time.h>]], [[struct timespec ts2, ts1 = {0, 0}; nanosleep(&ts1, &ts2);]]) 3238 3239 HIDDEN_VISIBILITY_CFLAGS="" 3240 AH_TEMPLATE([_MHD_EXTERN],[defines how to decorate public symbols w][hile building the library]) 3241 CFLAGS="${user_CFLAGS}" 3242 MHD_CHECK_CC_CFLAG([-fvisibility=hidden],[CFLAGS_ac], 3243 [ 3244 # NOTE: require setting of errattr_CFLAGS above 3245 CFLAGS="${CFLAGS_ac} -fvisibility=hidden ${user_CFLAGS} ${errattr_CFLAGS}" 3246 AC_CACHE_CHECK([whether $CC supports __attribute__((visibility("default")))],[mhd_cv_cc_attr_visibility], 3247 [ 3248 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 3249 extern __attribute__((visibility("default"))) int test_extrn_func(void); 3250 3251 int test_extrn_func(void) {return 0;} 3252 ]]) 3253 ], 3254 [mhd_cv_cc_attr_visibility="yes"],[mhd_cv_cc_attr_visibility="no"] 3255 ) 3256 ] 3257 ) 3258 AS_VAR_IF([mhd_cv_cc_attr_visibility],["yes"], 3259 [ 3260 HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden" 3261 AS_IF([test "x$os_is_native_w32" = "xyes" && test "x$enable_shared" = "xyes"], 3262 [AC_DEFINE([_MHD_EXTERN], [__attribute__((visibility("default"))) __declspec(dllexport) extern])], 3263 [AC_DEFINE([_MHD_EXTERN], [__attribute__((visibility("default"))) extern])] 3264 ) 3265 ], 3266 [ 3267 AC_MSG_WARN([$CC supports -fvisibility, but does not support __attribute__((visibility("default"))). Check compiler and compiler flags.]) 3268 AC_DEFINE([_MHD_EXTERN], [extern]) 3269 ] 3270 ) 3271 ],[AC_DEFINE([_MHD_EXTERN], [extern])] 3272 ) 3273 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 3274 AC_SUBST([HIDDEN_VISIBILITY_CFLAGS]) 3275 3276 # libcurl (required for testing) 3277 AC_ARG_ENABLE([curl], 3278 [AS_HELP_STRING([--disable-curl],[disable cURL based testcases])], 3279 [enable_curl=${enableval}]) 3280 curl=0 3281 AS_IF([test "$enable_curl" != "no"], 3282 [LIBCURL_CHECK_CONFIG([yes],[7.16.4],[enable_curl=yes], 3283 [ 3284 AS_IF([test "x$enable_curl" = "xyes"], 3285 [AC_MSG_WARN([[cURL-based tests cannot be enabled because libcurl is missing]])]) 3286 enable_curl=no 3287 ]) 3288 ]) 3289 AM_CONDITIONAL([RUN_LIBCURL_TESTS], [test "x$enable_curl" = "xyes"]) 3290 AS_IF([test "x$enable_curl" = "xyes"], 3291 [MSG_CURL="yes"], 3292 [MSG_CURL="no, many unit tests will not run"] 3293 ) 3294 3295 MHD_CHECK_FUNC([magic_open], 3296 [[ 3297 #include <magic.h> 3298 ]], 3299 [[ 3300 char var_data[256]; 3301 const char *var_mime; 3302 magic_t var_magic = magic_open (MAGIC_MIME_TYPE); 3303 (void)magic_load (var_magic, "filename"); 3304 var_data[0] = 0; 3305 var_mime = magic_buffer (var_magic, var_data, 1); 3306 i][f (! var_mime) 3307 return 1; 3308 magic_close (var_magic); 3309 ]], 3310 [AC_DEFINE([MHD_HAVE_LIBMAGIC], [1], [Define to 1 if you have suitable libmagic.])], 3311 [], 3312 [-lmagic] 3313 ) 3314 AM_CONDITIONAL([MHD_HAVE_LIBMAGIC], [[test "x$mhd_cv_have_func_magic_open" = "xyes"]]) 3315 3316 # large file support (> 4 GB) 3317 MHD_CHECK_FUNC([lseek64], 3318 [[ 3319 #if defined(HAVE_SYS_TYPES_H) 3320 # include <sys/types.h> 3321 #endif 3322 #include <unistd.h> 3323 ]], 3324 [[ 3325 i][f (((off64_t) -1) == lseek64(0, (off64_t) 0, SEEK_SET)) 3326 return 3; 3327 ]] 3328 ) 3329 MHD_CHECK_FUNC([pread64], 3330 [[ 3331 #if defined(HAVE_SYS_TYPES_H) 3332 # include <sys/types.h> 3333 #endif 3334 #include <unistd.h> 3335 ]], 3336 [[ 3337 char buf[5]; 3338 i][f (0 > pread64(0, (void *) buf, 1, (off64_t) 0)) 3339 return 3; 3340 ]] 3341 ) 3342 MHD_CHECK_FUNC([pread], 3343 [[ 3344 #if defined(HAVE_SYS_TYPES_H) 3345 # include <sys/types.h> 3346 #endif 3347 #include <unistd.h> 3348 ]], 3349 [[ 3350 char buf[5]; 3351 i][f (0 > pread(0, (void *) buf, 1, 0)) 3352 return 3; 3353 ]] 3354 ) 3355 3356 3357 # check for various sendfile functions 3358 AC_ARG_ENABLE([sendfile], 3359 [AS_HELP_STRING([--disable-sendfile], 3360 [disable usage of sendfile() for HTTP connections [auto]])], 3361 [], 3362 [enable_sendfile="auto"]) 3363 AS_CASE([$enable_sendfile], 3364 [[auto | yes]],[[found_sendfile="no"]], 3365 [[no]],[[found_sendfile="disabled"]], 3366 [AC_MSG_ERROR([[unknown value specified: --enable-sendfile=$enable_sendfile]])] 3367 ) 3368 AS_VAR_IF([[found_sendfile]], [["no"]], 3369 [ 3370 AC_MSG_CHECKING([[for Linux-style sendfile(2)]]) 3371 AC_LINK_IFELSE( 3372 [AC_LANG_PROGRAM( 3373 [[ 3374 #include <sys/sendfile.h> 3375 3376 static void empty_func(void) 3377 { 3378 /* Check for declaration */ 3379 (void)sendfile; 3380 } 3381 /* Declare again to check form match */ 3382 ssize_t sendfile(int, int, off_t*, size_t); 3383 ]], 3384 [[ 3385 int fd1=0, fd2=2; 3386 off_t o = 0; 3387 size_t s = 5; 3388 ssize_t r; 3389 r = sendfile (fd1, fd2, &o, s); 3390 if (r) 3391 empty_func(); 3392 ]] 3393 ) 3394 ], 3395 [ 3396 AC_DEFINE([HAVE_LINUX_SENDFILE], [1], [Define to 1 if you have linux-style sendfile(2).]) 3397 found_sendfile="yes, Linux-style" 3398 AC_MSG_RESULT([[yes]]) 3399 MHD_CHECK_FUNC([sendfile64], 3400 [[ 3401 #include <sys/sendfile.h> 3402 ]], 3403 [[ 3404 off64_t f_offset = (off64_t) 0; 3405 if (0 > sendfile64 (0, 1, &f_offset, 1)) 3406 return 3; 3407 ]] 3408 ) 3409 ], 3410 [AC_MSG_RESULT([[no]]) 3411 ] 3412 ) 3413 ] 3414 ) 3415 AS_VAR_IF([[found_sendfile]], [["no"]], 3416 [ 3417 AC_MSG_CHECKING([[for FreeBSD-style sendfile(2)]]) 3418 AC_LINK_IFELSE( 3419 [AC_LANG_PROGRAM( 3420 [[ 3421 #include <sys/types.h> 3422 #include <sys/socket.h> 3423 #include <sys/uio.h> 3424 3425 static void empty_func(void) 3426 { 3427 /* Check for declaration */ 3428 (void)sendfile; 3429 } 3430 /* Declare again to check form match */ 3431 int sendfile(int, int, off_t, size_t, 3432 struct sf_hdtr*, off_t*, int); 3433 ]], 3434 [[ 3435 int fd1=0, fd2=1; 3436 off_t o = 0; 3437 size_t s = 5; 3438 off_t r1; 3439 int r2; 3440 r2 = sendfile (fd1, fd2, o, s, (void*)0, &r1, 0); 3441 if (r2) 3442 empty_func(); 3443 ]] 3444 ) 3445 ], 3446 [ 3447 AC_DEFINE([HAVE_FREEBSD_SENDFILE], [1], [Define to 1 if you have FreeBSD-style sendfile(2).]) 3448 found_sendfile="yes, FreeBSD-style" 3449 AC_MSG_RESULT([[yes]]) 3450 ], 3451 [AC_MSG_RESULT([[no]]) 3452 ] 3453 ) 3454 ] 3455 ) 3456 AS_VAR_IF([[found_sendfile]], [["no"]], 3457 [ 3458 AC_MSG_CHECKING([[for Darwin-style sendfile(2)]]) 3459 AC_LINK_IFELSE( 3460 [AC_LANG_PROGRAM( 3461 [[ 3462 #include <sys/types.h> 3463 #include <sys/socket.h> 3464 #include <sys/uio.h> 3465 3466 static void empty_func(void) 3467 { 3468 /* Check for declaration */ 3469 (void)sendfile; 3470 } 3471 /* Declare again to check form match */ 3472 int sendfile(int, int, off_t, off_t*, 3473 struct sf_hdtr *, int); 3474 ]], 3475 [[ 3476 int fd=0, s=1; 3477 off_t o = 0; 3478 off_t l = 5; 3479 int r; 3480 r = sendfile (fd, s, o, &l, (void*)0, 0); 3481 if (r) 3482 empty_func(); 3483 ]] 3484 ) 3485 ], 3486 [ 3487 AC_DEFINE([HAVE_DARWIN_SENDFILE], [1], [Define to 1 if you have Darwin-style sendfile(2).]) 3488 found_sendfile="yes, Darwin-style" 3489 AC_MSG_RESULT([[yes]]) 3490 ], 3491 [AC_MSG_RESULT([[no]]) 3492 ] 3493 ) 3494 ] 3495 ) 3496 3497 AS_VAR_IF([[found_sendfile]], [["no"]], 3498 [ 3499 AC_MSG_CHECKING([[for Solaris-style sendfile(3)]]) 3500 SAVE_LIBS="$LIBS" 3501 LIBS="-lsendfile $LIBS" 3502 AC_LINK_IFELSE( 3503 [AC_LANG_PROGRAM( 3504 [[ 3505 #include <sys/types.h> 3506 #include <sys/socket.h> 3507 #include <sys/sendfile.h> 3508 3509 static void empty_func(void) 3510 { 3511 /* Check for declaration */ 3512 (void)sendfile; 3513 } 3514 /* Declare again to check form match */ 3515 ssize_t sendfile(int out_fd, int in_fd, 3516 off_t *off, size_t len); 3517 ]], 3518 [[ 3519 int fd1=0, fd2=1; 3520 off_t o = 0; 3521 size_t l = 5; 3522 ssize_t r; 3523 r = sendfile (fd1, fd2, &o, l); 3524 if (r) 3525 empty_func(); 3526 ]] 3527 ) 3528 ], 3529 [ 3530 AC_DEFINE([HAVE_SOLARIS_SENDFILE], [1], [Define to 1 if you have Solaris-style sendfile(3).]) 3531 found_sendfile="yes, Solaris-style" 3532 MHD_LIBDEPS="-lsendfile $MHD_LIBDEPS" 3533 MHD_LIBDEPS_PKGCFG="-lsendfile $MHD_LIBDEPS_PKGCFG" 3534 AC_MSG_RESULT([[yes]]) 3535 MHD_CHECK_FUNC([sendfile64], 3536 [[ 3537 #include <sys/types.h> 3538 #include <sys/socket.h> 3539 #include <sys/sendfile.h> 3540 ]], 3541 [[ 3542 off64_t f_offset = (off64_t) 0; 3543 if (0 > sendfile64 (0, 1, &f_offset, 1)) 3544 return 3; 3545 ]] 3546 ) 3547 ], 3548 [AC_MSG_RESULT([[no]]) 3549 ] 3550 ) 3551 LIBS="$SAVE_LIBS" 3552 ] 3553 ) 3554 AS_IF([[test "x$found_sendfile" = "xno" && test "x$enable_sendfile" = "xyes"]], 3555 [AC_MSG_ERROR([[sendfile() usage was requested by configure parameter, but no usable sendfile() function is detected]])] 3556 ) 3557 3558 # optional: enable error and informational messages 3559 AC_MSG_CHECKING([[whether to generate text messages]]) 3560 AC_ARG_ENABLE([messages], 3561 [AS_HELP_STRING([--disable-messages], 3562 [disable error, warning messages and text bodies for ] 3563 [automatic HTTP responses (to reduce the binary size)])], 3564 [enable_messages=${enableval}], 3565 [enable_messages=yes]) 3566 AS_IF([[test "x$enable_messages" = "xyes"]], 3567 [ AC_DEFINE([HAVE_MESSAGES],[1],[Define to 1 to enable support for text messages.]) ], 3568 [[ enable_messages=no ]]) 3569 AC_MSG_RESULT([[$enable_messages]]) 3570 AM_CONDITIONAL([HAVE_MESSAGES], [test "x$enable_messages" != "xno"]) 3571 3572 3573 # optional: have postprocessor? 3574 AC_MSG_CHECKING([[whether to enable postprocessor]]) 3575 AC_ARG_ENABLE([postprocessor], 3576 [AS_HELP_STRING([--disable-postprocessor], 3577 [disable MHD PostProcessor functionality])], 3578 [enable_postprocessor=${enableval}], 3579 [enable_postprocessor=yes]) 3580 AS_IF([[test "x$enable_postprocessor" != "xno"]], 3581 [ enable_postprocessor=yes 3582 AC_DEFINE([HAVE_POSTPROCESSOR],[1],[Define to 1 if libmicrohttpd is compiled with postprocessor support.]) ]) 3583 AM_CONDITIONAL([HAVE_POSTPROCESSOR], [test "x$enable_postprocessor" != "xno"]) 3584 AC_MSG_RESULT([[$enable_postprocessor]]) 3585 3586 have_gnutls=no 3587 have_gnutls_sni=no 3588 have_gcrypt=no 3589 AS_UNSET([GNUTLS_CPPFLAGS]) 3590 AS_UNSET([GNUTLS_LDFLAGS]) 3591 3592 # optional: HTTPS support. Enabled by default 3593 AC_ARG_ENABLE([https], 3594 [AS_HELP_STRING([--enable-https], 3595 [enable HTTPS support (yes, no, auto)[auto]])], 3596 [enable_https=${enableval}]) 3597 AS_IF([test "x$enable_https" != "xno"],[ 3598 # 3599 # Next block is large unindented block 3600 # 3601 3602 # gnutls 3603 have_gnutls_pkgcfg=no 3604 AC_MSG_CHECKING([[how to find GnuTLS library]]) 3605 AC_ARG_WITH([[gnutls]], 3606 [AS_HELP_STRING([[--with-gnutls[=PFX]]],[use GnuTLS for HTTPS support, optional PFX overrides pkg-config data for GnuTLS headers (PFX/include) and libs (PFX/lib)])], 3607 [ 3608 AS_CASE([$with_gnutls], 3609 [no],[ 3610 AC_MSG_RESULT([[GnuTLS disabled]]) 3611 AS_UNSET([GNUTLS_CPPFLAGS]) 3612 AS_UNSET([GNUTLS_CFLAGS]) 3613 AS_UNSET([GNUTLS_LDFLAGS]) 3614 AS_UNSET([GNUTLS_LIBS]) 3615 ], 3616 [yes],[ 3617 AC_MSG_RESULT([[automatically, forced]]) 3618 ], 3619 [ 3620 AC_MSG_RESULT([[-I$with_gnutls/include -L$with_gnutls/lib -lgnutls]]) 3621 SAVE_LIBS="$LIBS" 3622 LDFLAGS="${LDFLAGS_ac} -L$with_gnutls/lib ${user_LDFLAGS}" 3623 CPPFLAGS="${CPPFLAGS_ac} -I$with_gnutls/include ${user_CPPFLAGS}" 3624 have_gnutls_pkgcfg=no 3625 MHD_CHECK_FUNC([gnutls_check_version],[[#include <gnutls/gnutls.h>]], 3626 [ 3627 if(!gnutls_check_version("2.0.0")) 3628 return 3; 3629 ], 3630 [ 3631 GNUTLS_CPPFLAGS="-I$with_gnutls/include" 3632 GNUTLS_LDFLAGS="-L$with_gnutls/lib" 3633 GNUTLS_LIBS="-lgnutls" 3634 have_gnutls=yes 3635 ], 3636 [AC_MSG_ERROR([can't find usable libgnutls at specified prefix $with_gnutls])], 3637 [-lgnutls] 3638 ) 3639 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 3640 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 3641 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 3642 LIBS="$SAVE_LIBS" 3643 ]) 3644 ], 3645 [AC_MSG_RESULT([[automatically]]) 3646 ]) 3647 3648 AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"], 3649 [ 3650 PKG_CHECK_MODULES(GNUTLS, [[gnutls]], 3651 [ 3652 have_gnutls_pkgcfg='yes' 3653 SAVE_LIBS="$LIBS" 3654 CFLAGS="${CFLAGS_ac} $GNUTLS_CFLAGS ${user_CFLAGS}" 3655 LIBS="$GNUTLS_LIBS $LIBS" 3656 AC_MSG_CHECKING([[whether GnuTLS is usable]]) 3657 AC_LINK_IFELSE([ 3658 AC_LANG_PROGRAM([[ 3659 #include <gnutls/gnutls.h> 3660 ]], [[ 3661 gnutls_session_t session; 3662 gnutls_priority_t priorities; 3663 gnutls_global_init(); 3664 gnutls_priority_init(&priorities, "NORMAL", NULL); 3665 gnutls_init(&session, GNUTLS_SERVER); 3666 gnutls_priority_set(session, priorities); 3667 ]])], 3668 [ 3669 AC_MSG_RESULT([[yes]]) 3670 have_gnutls=yes 3671 # GNUTLS_CFLAGS is actually CPPFLAGS 3672 GNUTLS_CPPFLAGS="$GNUTLS_CFLAGS" 3673 # GNUTLS_LDFLAGS is a combination of LDFLAGS and LIBS 3674 GNUTLS_LDFLAGS="$GNUTLS_LIBS" 3675 ], 3676 [ 3677 AC_MSG_RESULT([[no]]) 3678 have_gnutls=no 3679 ]) 3680 3681 AS_IF([test "x$have_gnutls" != "xyes"], 3682 [ 3683 AC_MSG_WARN([pkg-config reports that GnuTLS is present, but GnuTLS can't be used]) 3684 AS_UNSET([GNUTLS_CPPFLAGS]) 3685 AS_UNSET([GNUTLS_CFLAGS]) 3686 AS_UNSET([GNUTLS_LDFLAGS]) 3687 AS_UNSET([GNUTLS_LIBS]) 3688 ] 3689 ) 3690 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 3691 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 3692 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 3693 LIBS="$SAVE_LIBS" 3694 ], 3695 [ 3696 # check for GnuTLS at default paths 3697 have_gnutls_pkgcfg='no' 3698 AC_CHECK_HEADERS([gnutls/gnutls.h], 3699 [AC_CHECK_LIB([gnutls], [gnutls_priority_set], 3700 [ 3701 GNUTLS_LIBS="-lgnutls" 3702 have_gnutls=yes 3703 ])], [], [AC_INCLUDES_DEFAULT]) 3704 ]) 3705 ]) 3706 3707 have_gcrypt='unknown' 3708 AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"], 3709 [ 3710 AM_PATH_LIBGCRYPT([1.2.2], [have_gcrypt=yes], [have_gcrypt=no]) 3711 AS_IF([[test "x$have_gcrypt" = "xyes"]], 3712 [ 3713 SAVE_LIBS="$LIBS" 3714 CFLAGS="${CFLAGS_ac} $LIBGCRYPT_CFLAGS ${user_CFLAGS}" 3715 # LIBGCRYPT_CFLAGS can be actually a CPPFLAGS, so check them both 3716 CPPFLAGS="${CPPFLAGS_ac} $LIBGCRYPT_CFLAGS ${user_CPPFLAGS}" 3717 AC_CHECK_HEADERS([gcrypt.h], [], [have_gcrypt=no], [AC_INCLUDES_DEFAULT]) 3718 # Check for GnuTLS with gcrypt flags 3719 LDFLAGS="${LDFLAGS_ac} ${LIBGCRYPT_LIBS} ${user_LDFLAGS}" 3720 # A bit of hack: unset cache variable to force recheck 3721 AS_UNSET([ac_cv_header_gnutls_gnutls_h]) 3722 AC_CHECK_HEADERS([gnutls/gnutls.h], 3723 [AS_UNSET([ac_cv_lib_gnutls_gnutls_priority_set]) # A bit of hack: unset cache variable to force recheck 3724 AC_CHECK_LIB([gnutls], [gnutls_priority_set], 3725 [ 3726 GNUTLS_CPPFLAGS="$LIBGCRYPT_CFLAGS" 3727 GNUTLS_CFLAGS="$LIBGCRYPT_CFLAGS" 3728 GNUTLS_LDFLAGS="$LIBGCRYPT_LIBS" 3729 GNUTLS_LIBS="-lgnutls" 3730 have_gnutls=yes 3731 ])], [], [AC_INCLUDES_DEFAULT]) 3732 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 3733 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 3734 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 3735 LIBS="$SAVE_LIBS" 3736 ] 3737 ) 3738 ] 3739 ) 3740 AS_IF([test "x$have_gnutls" != "xyes" && test "x$with_gnutls" = "xyes"], 3741 [AC_MSG_ERROR([[can't find usable libgnutls]])]) 3742 3743 AS_IF([test "x$have_gnutls" = "xyes"], 3744 [ 3745 SAVE_LIBS="$LIBS" 3746 CPPFLAGS="${CPPFLAGS_ac} ${GNUTLS_CPPFLAGS} ${user_CPPFLAGS}" 3747 CFLAGS="${CFLAGS_ac} ${GNUTLS_CFLAGS} ${user_CFLAGS}" 3748 LDFLAGS="${LDFLAGS_ac} ${GNUTLS_LDFLAGS} ${user_LDFLAGS}" 3749 LIBS="$GNUTLS_LIBS $LIBS" 3750 AC_MSG_CHECKING([[for gnutls_privkey_import_x509_raw()]]) 3751 AC_LINK_IFELSE([ 3752 AC_LANG_PROGRAM([[ 3753 #include <gnutls/gnutls.h> 3754 #include <gnutls/abstract.h> 3755 ]], [[ 3756 gnutls_datum_t data; 3757 gnutls_privkey_t key = 0; 3758 #ifndef gnutls_load_file 3759 (void)gnutls_load_file; /* Check for declaration. */ 3760 #endif 3761 #ifndef gnutls_privkey_import_x509_raw 3762 (void)gnutls_privkey_import_x509_raw; /* Check for declaration. */ 3763 #endif 3764 gnutls_load_file("key.pem", &data); 3765 gnutls_privkey_import_x509_raw(key, &data, GNUTLS_X509_FMT_PEM, NULL, 0); 3766 gnutls_free(data.data); 3767 ]])], [[have_gnutls_sni=yes]], [[have_gnutls_sni=no]]) 3768 AC_MSG_RESULT([[$have_gnutls_sni]]) 3769 AC_CACHE_CHECK([[whether GnuTLS require libgcrypt initialisation]], [mhd_cv_gcrypt_required], 3770 [ 3771 AC_COMPILE_IFELSE( 3772 [ 3773 AC_LANG_PROGRAM( 3774 [ 3775 #include <gnutls/gnutls.h> 3776 ], 3777 [ 3778 #if !defined(GNUTLS_VERSION_NUMBER) || GNUTLS_VERSION_NUMBER+0 <= 0x020c14 3779 #error Old versions of GnuTLS require libgcript initialisation 3780 choke me now 3781 #endif 3782 ] 3783 ) 3784 ], 3785 [[mhd_cv_gcrypt_required='no']], [[mhd_cv_gcrypt_required='yes']] 3786 ) 3787 ] 3788 ) 3789 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 3790 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 3791 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 3792 LIBS="$SAVE_LIBS" 3793 ], 3794 [ 3795 AS_UNSET([GNUTLS_CPPFLAGS]) 3796 AS_UNSET([GNUTLS_LDFLAGS]) 3797 ] 3798 ) 3799 3800 AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes" && test "x$have_gcrypt" = "xunknown"]], 3801 [ 3802 AM_PATH_LIBGCRYPT([1.2.2], [have_gcrypt=yes], [have_gcrypt=no]) 3803 AS_IF([[test "x$have_gcrypt" = "xyes"]], 3804 [ 3805 CFLAGS="${CFLAGS_ac} ${LIBGCRYPT_CFLAGS} ${user_CFLAGS}" 3806 # LIBGCRYPT_CFLAGS can be actually a CPPFLAGS, so check them both 3807 CPPFLAGS="${CPPFLAGS_ac} ${LIBGCRYPT_CFLAGS} ${user_CPPFLAGS}" 3808 AC_CHECK_HEADERS([gcrypt.h], [], [have_gcrypt=no], [AC_INCLUDES_DEFAULT]) 3809 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 3810 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 3811 ] 3812 ) 3813 ] 3814 ) 3815 3816 AS_UNSET([[crypt_missing]]) 3817 AS_IF([[test "x$have_gnutls" = "xyes"]], 3818 [ 3819 AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes" && test "x$have_gcrypt" != "xyes"]], 3820 [ 3821 crypt_missing="required libgcrypt" 3822 AS_IF([[test "x$enable_https" = "xyes" ]], [AC_MSG_ERROR([[HTTPS support cannot be enabled without $crypt_missing.]])]) 3823 enable_https=no 3824 MSG_HTTPS="no (lacking $crypt_missing)" 3825 AS_UNSET([LIBGCRYPT_CFLAGS]) 3826 AS_UNSET([LIBGCRYPT_LIBS]) 3827 AS_UNSET([GNUTLS_CPPFLAGS]) 3828 AS_UNSET([GNUTLS_CFLAGS]) 3829 AS_UNSET([GNUTLS_LDFLAGS]) 3830 AS_UNSET([GNUTLS_LIBS]) 3831 ], 3832 [ 3833 AC_DEFINE([[HTTPS_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTPS support.]) 3834 enable_https=yes 3835 AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]], 3836 [ 3837 MSG_HTTPS="yes (using libgnutls and libgcrypt)" 3838 MHD_TLS_LIB_CPPFLAGS="$LIBGCRYPT_CFLAGS $GNUTLS_CPPFLAGS" 3839 MHD_TLS_LIB_CFLAGS="$LIBGCRYPT_CFLAGS $GNUTLS_CFLAGS" 3840 MHD_TLS_LIB_LDFLAGS="$GNUTLS_LDFLAGS" 3841 MHD_TLS_LIBDEPS="$GNUTLS_LIBS $LIBGCRYPT_LIBS" 3842 AC_DEFINE([[MHD_HTTPS_REQUIRE_GCRYPT]], [[1]], [Define to `1' if HTTPS require initialisation of libgcrypt]) 3843 ], 3844 [ 3845 MSG_HTTPS="yes (using libgnutls)" 3846 AS_UNSET([LIBGCRYPT_CFLAGS]) 3847 AS_UNSET([LIBGCRYPT_LIBS]) 3848 MHD_TLS_LIB_CPPFLAGS="$GNUTLS_CPPFLAGS" 3849 MHD_TLS_LIB_CFLAGS="$GNUTLS_CFLAGS" 3850 MHD_TLS_LIB_LDFLAGS="$GNUTLS_LDFLAGS" 3851 MHD_TLS_LIBDEPS="$GNUTLS_LIBS" 3852 ] 3853 ) 3854 AS_IF([[ test "x$have_gnutls_pkgcfg" = "xyes" ]], 3855 [ # remove GnuTLS from private libs in .pc file as it defined in Requires.private 3856 MHD_REQ_PRIVATE='gnutls' 3857 AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]], 3858 [[MHD_LIBDEPS_PKGCFG="$LIBGCRYPT_LIBS $MHD_LIBDEPS_PKGCFG"]] 3859 ) 3860 ], 3861 [ 3862 MHD_REQ_PRIVATE='' 3863 AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]], 3864 [[MHD_LIBDEPS_PKGCFG="$LIBGCRYPT_LIBS $MHD_LIBDEPS_PKGCFG"]] 3865 ) 3866 MHD_LIBDEPS_PKGCFG="$GNUTLS_LIBS $MHD_LIBDEPS_PKGCFG" 3867 ]) 3868 ] 3869 ) 3870 ], 3871 [ 3872 crypt_missing="libgnutls" 3873 AS_IF([[test "x$enable_https" = "xyes" ]], [AC_MSG_ERROR([[HTTPS support cannot be enabled without $crypt_missing.]])]) 3874 enable_https=no 3875 MSG_HTTPS="no (lacking $crypt_missing)" 3876 AS_UNSET([LIBGCRYPT_CFLAGS]) 3877 AS_UNSET([LIBGCRYPT_LIBS]) 3878 AS_UNSET([GNUTLS_CPPFLAGS]) 3879 AS_UNSET([GNUTLS_CFLAGS]) 3880 AS_UNSET([GNUTLS_LDFLAGS]) 3881 AS_UNSET([GNUTLS_LIBS]) 3882 ] 3883 ) 3884 ],[ 3885 MSG_HTTPS="no (disabled)" 3886 ]) 3887 3888 # 3889 # End of large unindented block 3890 # 3891 3892 3893 AC_MSG_CHECKING(whether to support HTTPS) 3894 AC_MSG_RESULT([$MSG_HTTPS]) 3895 3896 AM_CONDITIONAL([HAVE_GNUTLS], [[test "x$have_gnutls" = "xyes"]]) 3897 AM_CONDITIONAL([HAVE_GNUTLS_SNI], [[test "x$have_gnutls_sni" = "xyes"]]) 3898 AM_CONDITIONAL([ENABLE_HTTPS], [test "x$enable_https" = "xyes"]) 3899 AM_CONDITIONAL([HTTPS_REQUIRE_GCRYPT], [[test "x$enable_https" = "xyes" && test "x$mhd_cv_gcrypt_required" = "xyes"]]) 3900 AC_SUBST([GNUTLS_CPPFLAGS]) 3901 AC_SUBST([GNUTLS_CFLAGS]) 3902 AC_SUBST([GNUTLS_LDFLAGS]) 3903 AC_SUBST([GNUTLS_LIBS]) 3904 3905 AS_VAR_IF([have_gnutls], ["yes"], 3906 [ 3907 AC_CACHE_CHECK([for GnuTLS quirks], [mhd_cv_gnutls_mthread_broken], 3908 [ 3909 mhd_cv_gnutls_mthread_broken="no" 3910 AS_IF([test -r /etc/redhat-release], 3911 [ 3912 AS_IF([$FGREP ' release 6.' /etc/redhat-release >/dev/null || $FGREP '(Santiago)' /etc/redhat-release >/dev/null], 3913 [mhd_cv_gnutls_mthread_broken="found"], 3914 ) 3915 ] 3916 ) 3917 AS_VAR_IF([mhd_cv_gnutls_mthread_broken], ["no"], 3918 [ 3919 AS_IF([command -v rpm >/dev/null], 3920 [ 3921 AS_IF([test "r`rpm -E '%{rhel}' 2>/dev/null`" = "r6"], 3922 [mhd_cv_gnutls_mthread_broken="found"], 3923 ) 3924 ] 3925 ) 3926 ] 3927 ) 3928 ] 3929 ) 3930 AC_CACHE_CHECK([for gnutls-cli binary], [mhd_cv_gnutls_cli], 3931 [ 3932 mhd_cv_gnutls_cli="no" 3933 AS_IF([command -v gnutls-cli >/dev/null 2>&1], 3934 [AS_IF([AC_RUN_LOG([gnutls-cli --version >&2])], [mhd_cv_gnutls_cli="yes"])] 3935 ) 3936 ] 3937 ) 3938 ] 3939 ) 3940 AM_CONDITIONAL([HAVE_GNUTLS_MTHREAD_BROKEN], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xfound"]]) 3941 AM_CONDITIONAL([USE_UPGRADE_TLS_TESTS], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xno" || test "x${mhd_cv_gnutls_cli}" = "xyes"]]) 3942 3943 # optional: HTTP Basic Auth support. Enabled by default 3944 AC_MSG_CHECKING([[whether to support HTTP Basic authentication]]) 3945 AC_ARG_ENABLE([bauth], 3946 [AS_HELP_STRING([--disable-bauth],[disable HTTP Basic Authentication support])], 3947 [enable_bauth=${enableval}], 3948 [enable_bauth=yes]) 3949 AS_IF([[test "x$enable_bauth" != "xno"]], 3950 [ enable_bauth=yes 3951 AC_DEFINE([BAUTH_SUPPORT],[1],[Define to 1 if libmicrohttpd is compiled with Basic Auth support.]) ]) 3952 AM_CONDITIONAL([ENABLE_BAUTH], [test "x$enable_bauth" != "xno"]) 3953 AC_MSG_RESULT([[$enable_bauth]]) 3954 3955 # optional: HTTP Digest Auth support. Enabled by default 3956 AC_MSG_CHECKING([[whether to support HTTP Digest authentication]]) 3957 AC_ARG_ENABLE([dauth], 3958 [AS_HELP_STRING([--disable-dauth], [disable HTTP Digest Authentication support])], 3959 [enable_dauth="${enableval}"], 3960 [enable_dauth="yes"]) 3961 AS_IF([[test "x$enable_dauth" != "xno"]], 3962 [ enable_dauth=yes 3963 AC_DEFINE([DAUTH_SUPPORT],[1],[Define to 1 if libmicrohttpd is compiled with Digest Auth support.]) ]) 3964 AM_CONDITIONAL([ENABLE_DAUTH], [test "x$enable_dauth" != "xno"]) 3965 AC_MSG_RESULT([[$enable_dauth]]) 3966 3967 AS_VAR_IF([enable_dauth], ["yes"], 3968 [ 3969 AC_MSG_CHECKING([[for Digest Authentication default nonce timeout value]]) 3970 AC_ARG_ENABLE([dauth-def-timeout], 3971 [AS_HELP_STRING([--enable-dauth-def-timeout=NNN], 3972 [set default Digest Auth nonce validity time to NNN seconds [90]])], 3973 [enable_dauth_def_timeout="${enableval}"], 3974 [enable_dauth_def_timeout=""] 3975 ) 3976 AS_VAR_IF([enable_dauth_def_timeout], ["no"], 3977 [ 3978 AC_MSG_WARN([Default Diget Auth nonce validity time cannot be disabled, --disable-dauth-def-timeout parameter is ignored]) 3979 enable_dauth_def_timeout="" 3980 ] 3981 ) 3982 AS_IF([test -z "${enable_dauth_def_timeout}"], 3983 [ 3984 enable_dauth_def_timeout="90" 3985 enable_dauth_def_timeout_MSG="${enable_dauth_def_timeout} seconds (default)" 3986 ], 3987 [ 3988 AS_IF([[test "x${enable_dauth_def_timeout}" = "x`echo ${enable_dauth_def_timeout}|${SED-sed} 's/[^0-9]//g'`" && \ 3989 test "${enable_dauth_def_timeout}" -ge "0" 2>/dev/null ]],[:], 3990 [AC_MSG_ERROR([Invalid parameter --enable-dauth-def-timeout=${enable_dauth_def_timeout}. Timeout value must be a positive integer.]) 3991 ] 3992 ) 3993 AC_COMPILE_IFELSE( 3994 [ 3995 AC_LANG_PROGRAM([], 3996 [[ 3997 static int arr[((int) 2) - 4 * (int)(${enable_dauth_def_timeout} != ((unsigned int)${enable_dauth_def_timeout}))]; 3998 (void) arr; 3999 ]] 4000 ) 4001 ], 4002 [], 4003 [AC_MSG_ERROR([The value specified by --enable-dauth-def-timeout=${enable_dauth_def_timeout} is too large.])] 4004 ) 4005 enable_dauth_def_timeout_MSG="${enable_dauth_def_timeout} seconds (set by parameter)" 4006 ] 4007 ) 4008 AC_DEFINE_UNQUOTED([MHD_DAUTH_DEF_TIMEOUT_],[${enable_dauth_def_timeout}], 4009 [The default HTTP Digest Auth default nonce timeout value (in seconds)]) 4010 AC_MSG_RESULT([[${enable_dauth_def_timeout_MSG}]]) 4011 4012 AC_MSG_CHECKING([[for Digest Authentication default maximum nc value]]) 4013 AC_ARG_ENABLE([dauth-def-max-nc], 4014 [AS_HELP_STRING([--enable-dauth-def-max-nc=NNN], 4015 [set default Digest Auth maximum nc (nonce count) value to NNN [1000]])], 4016 [enable_dauth_def_max_nc="${enableval}"], 4017 [enable_dauth_def_max_nc=""] 4018 ) 4019 AS_VAR_IF([enable_dauth_def_max_nc], ["no"], 4020 [ 4021 AC_MSG_WARN([Default Diget Auth maximum nc cannot be disabled, --disable-dauth-def-max-nc parameter is ignored]) 4022 enable_dauth_def_max_nc="" 4023 ] 4024 ) 4025 AS_IF([test -z "${enable_dauth_def_max_nc}"], 4026 [ 4027 enable_dauth_def_max_nc="1000" 4028 enable_dauth_def_max_nc_MSG="${enable_dauth_def_max_nc} (default)" 4029 ], 4030 [ 4031 AS_IF([[test "x${enable_dauth_def_max_nc}" = "x`echo ${enable_dauth_def_max_nc}|${SED-sed} 's/[^0-9]//g'`" && \ 4032 test "${enable_dauth_def_max_nc}" -ge "0" 2>/dev/null ]],[:], 4033 [AC_MSG_ERROR([Invalid parameter --enable-dauth-def-max-nc=${enable_dauth_def_max_nc}. The value must be a positive integer.]) 4034 ] 4035 ) 4036 AC_COMPILE_IFELSE( 4037 [ 4038 AC_LANG_PROGRAM( 4039 [[ 4040 #include <stdint.h> 4041 ]], 4042 [[ 4043 static int arr[((int) 2) - 4 * (int)(${enable_dauth_def_max_nc} != ((uint32_t)${enable_dauth_def_max_nc}))]; 4044 (void) arr; 4045 ]] 4046 ) 4047 ], 4048 [], 4049 [AC_MSG_ERROR([The value specified by --enable-dauth-def-max-nc=${enable_dauth_def_max_nc} is too large.])] 4050 ) 4051 enable_dauth_def_max_nc_MSG="${enable_dauth_def_max_nc} (set by parameter)" 4052 ] 4053 ) 4054 AC_DEFINE_UNQUOTED([MHD_DAUTH_DEF_MAX_NC_],[${enable_dauth_def_max_nc}], 4055 [The default HTTP Digest Auth default maximum nc (nonce count) value]) 4056 AC_MSG_RESULT([[${enable_dauth_def_max_nc_MSG}]]) 4057 4058 dauth_defs_MSG="timeout: ${enable_dauth_def_timeout_MSG}, max nc: ${enable_dauth_def_max_nc_MSG}" 4059 ], 4060 [ 4061 dauth_defs_MSG="N/A" 4062 ] 4063 ) 4064 4065 AM_CONDITIONAL([HAVE_ANYAUTH],[test "x$enable_bauth" != "xno" || test "x$enable_dauth" != "xno"]) 4066 4067 # optional: HTTP "Upgrade" support. Enabled by default 4068 AC_MSG_CHECKING([[whether to support HTTP "Upgrade"]]) 4069 AC_ARG_ENABLE([[httpupgrade]], 4070 [AS_HELP_STRING([[--disable-httpupgrade]], [disable HTTP "Upgrade" support])], 4071 [AS_VAR_IF([[enable_httpupgrade]],[["no"]],[],[[enable_httpupgrade='yes']])], 4072 [[enable_httpupgrade='yes']]) 4073 AS_VAR_IF([[enable_httpupgrade]],[["yes"]], 4074 [ 4075 AC_DEFINE([[UPGRADE_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP Upgrade support.]) ]) 4076 AM_CONDITIONAL([ENABLE_UPGRADE], [[test "x$enable_httpupgrade" = "xyes"]]) 4077 AC_MSG_RESULT([[$enable_httpupgrade]]) 4078 4079 # optional: HTTP cookie parsing support. Enabled by default 4080 AC_MSG_CHECKING([[whether to support HTTP cookie parsing]]) 4081 AC_ARG_ENABLE([[cookie]], 4082 [AS_HELP_STRING([[--disable-cookie]], [disable HTTP cookie parsing support])], 4083 [AS_VAR_IF([[enable_cookie]],[["no"]],[],[[enable_cookie='yes']])], 4084 [[enable_cookie='yes']]) 4085 AS_VAR_IF([[enable_cookie]],[["yes"]], 4086 [ 4087 AC_DEFINE([[COOKIE_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP cookie parsing support.]) ]) 4088 AM_CONDITIONAL([ENABLE_COOKIE], [[test "x$enable_cookie" = "xyes"]]) 4089 AC_MSG_RESULT([[$enable_cookie]]) 4090 4091 # optional: MD5 support for Digest Auth. Enabled by default. 4092 AC_ARG_ENABLE([[md5]], 4093 [AS_HELP_STRING([[--enable-md5=TYPE]], 4094 [enable TYPE of MD5 hashing code (yes, no, builtin, tlslib) [yes if dauth enabled]])], 4095 [ 4096 AS_VAR_IF([enable_md5],["internal"],[enable_md5='builtin']) 4097 AS_VAR_IF([enable_md5],["built-in"],[enable_md5='builtin']) 4098 AS_VAR_IF([enable_dauth],["yes"],[], 4099 [ 4100 AS_VAR_IF([enable_md5],["no"],[], 4101 [ 4102 AC_MSG_WARN([The parameter --enable-md5=${enable_md5} is ignored as Digest Authentication is disabled]) 4103 enable_md5='no' 4104 ] 4105 ) 4106 ] 4107 ) 4108 ], [[enable_md5="${enable_dauth}"]] 4109 ) 4110 AS_CASE([${enable_md5}],[yes|tlslib], 4111 [ 4112 AS_IF([test "x${enable_compact_code}" != "xno" || test "x$enable_md5" = "xtlslib"], 4113 [ 4114 AS_IF([test "x$enable_https" = "xyes"], 4115 [ 4116 AC_CACHE_CHECK([whether GnuTLS supports MD5 hashing],[mhd_cv_gnutls_md5], 4117 [ 4118 CFLAGS="${CFLAGS_ac} ${GNUTLS_CFLAGS} ${user_CFLAGS}" 4119 CPPFLAGS="${CPPFLAGS_ac} ${MHD_TLS_LIB_CPPFLAGS} ${user_CPPFLAGS}" 4120 CFLAGS="${CFLAGS_ac} ${MHD_TLS_LIB_CFLAGS} ${user_CFLAGS}" 4121 LDFLAGS="${LDFLAGS_ac} ${MHD_TLS_LIB_LDFLAGS} ${user_LDFLAGS}" 4122 save_LIBS="$LIBS" 4123 LIBS="${MHD_TLS_LIBDEPS} ${LIBS}" 4124 AC_LINK_IFELSE( 4125 [ 4126 AC_LANG_PROGRAM( 4127 [[ 4128 #include <gnutls/crypto.h> 4129 ]], 4130 [[ 4131 gnutls_hash_hd_t hash_handle; 4132 unsigned char digest[16]; 4133 int exit_code; 4134 4135 if (0 == gnutls_hash_init(&hash_handle, GNUTLS_DIG_MD5)) 4136 { 4137 if (0 == gnutls_hash(hash_handle, "", 1)) 4138 { 4139 gnutls_hash_output(hash_handle, digest); 4140 if (0x93 == digest[0]) 4141 exit_code = 0; 4142 else 4143 exit_code = 7; 4144 } 4145 else 4146 exit_code = 5; 4147 gnutls_hash_deinit(hash_handle, (void *)0); 4148 } 4149 else 4150 exit_code = 2; 4151 if (exit_code) 4152 return exit_code; 4153 ]] 4154 ) 4155 ], 4156 [mhd_cv_gnutls_md5='yes'],[mhd_cv_gnutls_md5='no'] 4157 ) 4158 LIBS="${save_LIBS}" 4159 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 4160 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 4161 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 4162 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 4163 ] 4164 ) 4165 AS_VAR_IF([mhd_cv_gnutls_md5],["no"], 4166 [ 4167 AS_VAR_IF([enable_md5],["tlslib"], 4168 [AC_MSG_FAILURE([TLS library MD5 implementation is not available])] 4169 ) 4170 enable_md5="builtin" 4171 ], 4172 [enable_md5="tlslib"] 4173 ) 4174 ], 4175 [ 4176 AS_VAR_IF([enable_md5],["tlslib"], 4177 [AC_MSG_ERROR([HTTPS is not enabled, TLS library MD5 implementation cannot be used])] 4178 ) 4179 enable_md5="builtin" 4180 ] 4181 ) 4182 ], 4183 [ 4184 enable_md5="builtin" 4185 ] 4186 ) 4187 ] 4188 ) 4189 AC_MSG_CHECKING([[whether to support MD5]]) 4190 AS_UNSET([enable_md5_MSG]) 4191 AS_CASE([${enable_md5}], 4192 [builtin],[enable_md5_MSG='yes, built-in'], 4193 [tlslib],[enable_md5_MSG='yes, external (TLS library)'], 4194 [no],[enable_md5_MSG='no'], 4195 [yes],[AC_MSG_ERROR([configure internal error: unexpected variable value])], 4196 [AC_MSG_ERROR([Unrecognized parameter --enable-md5=${enable_md5}])] 4197 ) 4198 AS_IF([test "x${enable_md5}" = "xbuiltin" || test "x${enable_md5}" = "xtlslib" ], 4199 [ 4200 AC_DEFINE([[MHD_MD5_SUPPORT]],[[1]], 4201 [Define to 1 if libmicrohttpd is compiled with MD5 hashing support.]) 4202 ] 4203 ) 4204 AS_IF([test "x${enable_md5}" = "xtlslib" ], 4205 [ 4206 AC_DEFINE([[MHD_MD5_TLSLIB]],[[1]], 4207 [Define to 1 if libmicrohttpd is compiled with MD5 hashing by TLS library.]) 4208 ] 4209 ) 4210 AM_CONDITIONAL([ENABLE_MD5], [[test "x${enable_md5}" = "xbuiltin" || test "x${enable_md5}" = "xtlslib" ]]) 4211 AM_CONDITIONAL([ENABLE_MD5_EXT], [[test "x${enable_md5}" = "xtlslib" ]]) 4212 AC_MSG_RESULT([[${enable_md5_MSG}]]) 4213 4214 # optional: SHA-256 support for Digest Auth. Enabled by default. 4215 AC_ARG_ENABLE([[sha256]], 4216 [AS_HELP_STRING([[--enable-sha256=TYPE]], 4217 [enable TYPE of SHA-256 hashing code (yes, no, builtin, tlslib) [yes if dauth enabled]])], 4218 [ 4219 AS_VAR_IF([enable_sha256],["internal"],[enable_sha256='builtin']) 4220 AS_VAR_IF([enable_sha256],["built-in"],[enable_sha256='builtin']) 4221 AS_VAR_IF([enable_dauth],["yes"],[], 4222 [ 4223 AS_VAR_IF([enable_sha256],["no"],[], 4224 [ 4225 AC_MSG_WARN([The parameter --enable-sha256=${enable_sha256} is ignored as Digest Authentication is disabled]) 4226 enable_sha256='no' 4227 ] 4228 ) 4229 ] 4230 ) 4231 ], [[enable_sha256="${enable_dauth}"]] 4232 ) 4233 AS_CASE([${enable_sha256}],[yes|tlslib], 4234 [ 4235 AS_IF([test "x${enable_compact_code}" != "xno" || test "x$enable_sha256" = "xtlslib"], 4236 [ 4237 AS_IF([test "x$enable_https" = "xyes"], 4238 [ 4239 AC_CACHE_CHECK([whether GnuTLS supports sha256 hashing],[mhd_cv_gnutls_sha256], 4240 [ 4241 CFLAGS="${CFLAGS_ac} ${GNUTLS_CFLAGS} ${user_CFLAGS}" 4242 CPPFLAGS="${CPPFLAGS_ac} ${MHD_TLS_LIB_CPPFLAGS} ${user_CPPFLAGS}" 4243 CFLAGS="${CFLAGS_ac} ${MHD_TLS_LIB_CFLAGS} ${user_CFLAGS}" 4244 LDFLAGS="${LDFLAGS_ac} ${MHD_TLS_LIB_LDFLAGS} ${user_LDFLAGS}" 4245 save_LIBS="$LIBS" 4246 LIBS="${MHD_TLS_LIBDEPS} ${LIBS}" 4247 AC_LINK_IFELSE( 4248 [ 4249 AC_LANG_PROGRAM( 4250 [[ 4251 #include <gnutls/crypto.h> 4252 ]], 4253 [[ 4254 gnutls_hash_hd_t hash_handle; 4255 unsigned char digest[32]; 4256 int exit_code; 4257 4258 if (0 == gnutls_hash_init(&hash_handle, GNUTLS_DIG_SHA256)) 4259 { 4260 if (0 == gnutls_hash(hash_handle, "", 1)) 4261 { 4262 gnutls_hash_output(hash_handle, digest); 4263 if (0x6e == digest[0]) 4264 exit_code = 0; 4265 else 4266 exit_code = 7; 4267 } 4268 else 4269 exit_code = 5; 4270 gnutls_hash_deinit(hash_handle, (void *)0); 4271 } 4272 else 4273 exit_code = 2; 4274 if (exit_code) 4275 return exit_code; 4276 ]] 4277 ) 4278 ], 4279 [mhd_cv_gnutls_sha256='yes'],[mhd_cv_gnutls_sha256='no'] 4280 ) 4281 LIBS="${save_LIBS}" 4282 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 4283 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 4284 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 4285 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 4286 ] 4287 ) 4288 AS_VAR_IF([mhd_cv_gnutls_sha256],["no"], 4289 [ 4290 AS_VAR_IF([enable_sha256],["tlslib"], 4291 [AC_MSG_FAILURE([TLS library SHA-256 implementation is not available])] 4292 ) 4293 enable_sha256="builtin" 4294 ], 4295 [enable_sha256="tlslib"] 4296 ) 4297 ], 4298 [ 4299 AS_VAR_IF([enable_sha256],["tlslib"], 4300 [AC_MSG_ERROR([HTTPS is not enabled, TLS library SHA-256 implementation cannot be used])] 4301 ) 4302 enable_sha256="builtin" 4303 ] 4304 ) 4305 ], 4306 [ 4307 enable_sha256="builtin" 4308 ] 4309 ) 4310 ] 4311 ) 4312 AC_MSG_CHECKING([[whether to support SHA-256]]) 4313 AS_UNSET([enable_sha256_MSG]) 4314 AS_CASE([${enable_sha256}], 4315 [builtin],[enable_sha256_MSG='yes, built-in'], 4316 [tlslib],[enable_sha256_MSG='yes, external (TLS library)'], 4317 [no],[enable_sha256_MSG='no'], 4318 [yes],[AC_MSG_ERROR([configure internal error: unexpected variable value])], 4319 [AC_MSG_ERROR([Unrecognized parameter --enable-sha256=${enable_sha256}])] 4320 ) 4321 AS_IF([test "x${enable_sha256}" = "xbuiltin" || test "x${enable_sha256}" = "xtlslib" ], 4322 [ 4323 AC_DEFINE([[MHD_SHA256_SUPPORT]],[[1]], 4324 [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing support.]) 4325 ] 4326 ) 4327 AS_IF([test "x${enable_sha256}" = "xtlslib" ], 4328 [ 4329 AC_DEFINE([[MHD_SHA256_TLSLIB]],[[1]], 4330 [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing by TLS library.]) 4331 ] 4332 ) 4333 AM_CONDITIONAL([ENABLE_SHA256], [[test "x${enable_sha256}" = "xbuiltin" || test "x${enable_sha256}" = "xtlslib" ]]) 4334 AM_CONDITIONAL([ENABLE_SHA256_EXT], [[test "x${enable_sha256}" = "xtlslib" ]]) 4335 AC_MSG_RESULT([[${enable_sha256_MSG}]]) 4336 4337 # optional: SHA-512/256 support for Digest Auth. Enabled by default. 4338 AC_ARG_ENABLE([[sha512-256]], 4339 [AS_HELP_STRING([[--disable-sha512-256]], 4340 [disable SHA-512/256 hashing support for Digest Authentication])], 4341 [ 4342 AS_VAR_IF([[enable_sha512_256]],[["yes"]], 4343 [ 4344 AS_VAR_IF([enable_dauth],["yes"],[], 4345 [ 4346 AC_MSG_WARN([The parameter --enable-sha512-256 is ignored as Digest Authentication is disabled]) 4347 enable_sha512_256='no' 4348 ] 4349 ) 4350 ],[[enable_sha512_256='no']] 4351 ) 4352 ], [[enable_sha512_256="${enable_dauth}"]] 4353 ) 4354 AC_MSG_CHECKING([[whether to support SHA-512/256]]) 4355 AS_UNSET([enable_sha512_256_MSG]) 4356 AS_CASE([${enable_sha512_256}], 4357 [yes],[enable_sha512_256_MSG='yes, built-in'], 4358 [no],[enable_sha512_256_MSG='no'], 4359 [AC_MSG_ERROR([Unrecognized parameter --enable-sha512-256=${enable_sha512_256}])] 4360 ) 4361 AS_VAR_IF([[enable_sha512_256]],[["yes"]], 4362 [ 4363 AC_DEFINE([[MHD_SHA512_256_SUPPORT]],[[1]], 4364 [Define to 1 if libmicrohttpd is compiled with SHA-512/256 hashing support.]) 4365 ] 4366 ) 4367 AM_CONDITIONAL([ENABLE_SHA512_256], [[test "x${enable_sha512_256}" = "xyes"]]) 4368 AC_MSG_RESULT([[${enable_sha512_256_MSG}]]) 4369 4370 AS_IF([test "x$enable_dauth" != "xno"], 4371 [ 4372 AS_IF([test "x${enable_md5}" = "xno" && test "x${enable_sha256}" = "xno" && test "x${enable_sha512_256}" != "xyes"], 4373 [AC_MSG_ERROR([At least one hashing algorithm must be enabled if Digest Auth is enabled])] 4374 ) 4375 ] 4376 ) 4377 4378 4379 AC_CACHE_CHECK([[for calloc()]], [[mhd_cv_have_func_calloc]], 4380 [ 4381 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 4382 #include <stdlib.h> 4383 ]],[[void * ptr = calloc(1, 2); if (ptr) return 1;]]) 4384 ], 4385 [[mhd_cv_have_func_calloc='yes']], 4386 [[mhd_cv_have_func_calloc='no']] 4387 ) 4388 ] 4389 ) 4390 AS_VAR_IF([[mhd_cv_have_func_calloc]], [["yes"]], 4391 [AC_DEFINE([[HAVE_CALLOC]], [[1]], [Define to 1 if you have the usable `calloc' function.])]) 4392 4393 # Some systems have IPv6 disabled in kernel at run-time 4394 AS_IF([[test "x${mhd_cv_have_inet6}" = "xyes" && test "x${cross_compiling}" = "xno"]], 4395 [ 4396 AC_CACHE_CHECK([whether IPv6 could be used for testing],[mhd_cv_ipv6_for_testing], 4397 [ 4398 AC_RUN_IFELSE( 4399 [ 4400 AC_LANG_SOURCE([[ 4401 #ifdef HAVE_UNISTD_H 4402 #include <unistd.h> 4403 #endif 4404 #ifdef HAVE_SYS_TYPES_H 4405 #include <sys/types.h> 4406 #endif 4407 #ifdef HAVE_SYS_SOCKET_H 4408 #include <sys/socket.h> 4409 #endif 4410 #ifdef HAVE_WINSOCK2_H 4411 #include <winsock2.h> 4412 #endif 4413 #ifdef HAVE_WS2TCPIP_H 4414 #include <ws2tcpip.h> 4415 #endif 4416 #ifdef HAVE_NETINET_IN_H 4417 #include <netinet/in.h> 4418 #endif 4419 #ifdef HAVE_NETINET_IP_H 4420 #include <netinet/ip.h> 4421 #endif 4422 #ifdef HAVE_ARPA_INET_H 4423 #include <arpa/inet.h> 4424 #endif 4425 #ifdef HAVE_NETINET_TCP_H 4426 #include <netinet/tcp.h> 4427 #endif 4428 4429 static void zr_mem(void *ptr, socklen_t size) 4430 { char *mem = ptr; while(size--) {mem[0] = 0; mem++;} } 4431 4432 int main(void) 4433 { 4434 int ret = 30; 4435 struct sockaddr_in6 sa; 4436 #if !defined(_WIN32) || defined(__CYGWIN__) 4437 int sckt; 4438 const int invld_sckt = -1; 4439 #else 4440 SOCKET sckt; 4441 const SOCKET invld_sckt = INVALID_SOCKET; 4442 WSADATA wsa_data; 4443 4444 WSAStartup(MAKEWORD(2, 2), &wsa_data); 4445 #endif 4446 zr_mem(&sa, sizeof(sa)); 4447 sa.sin6_family = AF_INET6; 4448 sa.sin6_port = 0; 4449 sa.sin6_addr = in6addr_loopback; 4450 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN 4451 sa.sin6_len = sizeof(sa); 4452 #endif 4453 sckt = socket (PF_INET6, SOCK_STREAM, 0); 4454 if (invld_sckt != sckt) 4455 { 4456 if (0 == bind (sckt, (struct sockaddr *)&sa, sizeof(sa))) 4457 { 4458 if (0 == listen (sckt, 1)) 4459 ret = 0; 4460 else 4461 ret = 1; /* listen() failed */ 4462 } else ret = 2; /* bind() failed */ 4463 #if !defined(_WIN32) || defined(__CYGWIN__) 4464 close (sckt); 4465 #else 4466 closesocket (sckt); 4467 #endif 4468 } else ret = 3; /* socket() failed */ 4469 #if defined(_WIN32) && !defined(__CYGWIN__) 4470 WSACleanup(); 4471 #endif 4472 return ret; 4473 } 4474 ]]) 4475 ], [[mhd_cv_ipv6_for_testing="yes"]], [[mhd_cv_ipv6_for_testing="no"]], [[mhd_cv_ipv6_for_testing="no"]] 4476 ) 4477 ] 4478 ) 4479 ] 4480 ) 4481 AS_VAR_IF([mhd_cv_ipv6_for_testing],["yes"], 4482 [AC_DEFINE([[USE_IPV6_TESTING]], [[1]], [Define to 1 if your kernel supports IPv6 and IPv6 is enabled and useful for testing.])] 4483 ) 4484 4485 AS_VAR_IF([enable_tools],["yes"], 4486 [ 4487 AC_CHECK_HEADERS([features.h sys/pstat.h vxCpuLib.h],[],[],[AC_INCLUDES_DEFAULT]) 4488 AC_CHECK_DECLS( 4489 [_SC_NPROCESSORS_ONLN,_SC_NPROC_ONLN,_SC_CRAY_NCPU,_SC_NPROCESSORS_CONF,CTL_HW,HW_NCPUONLINE,HW_NCPU,HW_AVAILCPU], 4490 [],[], 4491 [[ 4492 #ifdef HAVE_SYS_TYPES_H 4493 #include <sys/types.h> 4494 #endif /* HAVE_SYS_TYPES_H */ 4495 #ifdef HAVE_SYS_PARAM_H 4496 #include <sys/param.h> 4497 #endif /* HAVE_SYS_PARAM_H */ 4498 #ifdef HAVE_SYS_SYSCTL_H 4499 #include <sys/sysctl.h> 4500 #endif /* HAVE_SYS_SYSCTL_H */ 4501 #ifdef HAVE_UNISTD_H 4502 #include <unistd.h> 4503 #endif /* HAVE_UNISTD_H */ 4504 ]] 4505 ) 4506 MHD_CHECK_FUNC([pstat_getdynamic],[[ 4507 #include <sys/param.h> 4508 #include <sys/pstat.h> 4509 ]], 4510 [[ 4511 struct pst_dynamic psd_data; 4512 i][f (1 != pstat_getdynamic(&psd_data, sizeof(psd_data), (size_t)1, 0)) 4513 return 2; 4514 i][f (0 >= psd_data.psd_proc_cnt) 4515 return 3; 4516 ]] 4517 ) 4518 MHD_CHECK_FUNC([vxCpuEnabledGet],[[#include <vxCpuLib.h>]], 4519 [[ 4520 cpuset_t enb_set; 4521 enb_set = vxCpuEnabledGet(); 4522 (void) enb_set; 4523 ]] 4524 ) 4525 AC_CHECK_HEADERS([sched.h sys/_cpuset.h sys/cpuset.h],[],[],[AC_INCLUDES_DEFAULT]) 4526 # glibc / Linux kernel 4527 MHD_CHECK_FUNC([getpid],[[ 4528 #ifdef HAVE_SYS_TYPES_H 4529 #include <sys/types.h> 4530 #endif /* HAVE_SYS_TYPES_H */ 4531 #include <unistd.h> 4532 ]], 4533 [[ 4534 pid_t cur_pid; 4535 cur_pid = getpid(); 4536 (void) &cur_pid; /* Mute possible warning */ 4537 ]], 4538 [ 4539 MHD_CHECK_FUNC([sched_getaffinity],[[ 4540 #ifdef HAVE_SYS_TYPES_H 4541 #include <sys/types.h> 4542 #endif /* HAVE_SYS_TYPES_H */ 4543 #include <unistd.h> 4544 #include <sched.h> 4545 ]], 4546 [[ 4547 cpu_set_t cur_set; 4548 i][f (0 != sched_getaffinity(getpid(), sizeof(cur_set), &cur_set)) 4549 return 2; 4550 i][f (0 == CPU_SET (0, &cur_set)) 4551 return 3; /* Actually this could be a valid result */ 4552 ]], 4553 [ 4554 MHD_CHECK_FUNC([CPU_COUNT],[[ 4555 #include <stddef.h> 4556 #include <sched.h> 4557 ]], 4558 [[ 4559 cpu_set_t cur_set; 4560 CPU_ZERO(&cur_set); 4561 i][f (0 != CPU_COUNT(&cur_set)) 4562 return 2; 4563 ]], 4564 [ 4565 MHD_CHECK_FUNC([CPU_COUNT_S],[[ 4566 #include <stddef.h> 4567 #include <sched.h> 4568 ]], 4569 [[ 4570 static const unsigned int set_size_cpus = 2048u; 4571 const size_t set_size_bytes = (size_t) CPU_ALLOC_SIZE(set_size_cpus); 4572 cpu_set_t *p_set; 4573 p_set = CPU_ALLOC(set_size_cpus); 4574 i][f (!p_set) 4575 return 2; 4576 CPU_ZERO_S(set_size_bytes, p_set); 4577 i][f (0 != CPU_COUNT_S(set_size_bytes, p_set)) 4578 { 4579 CPU_FREE(p_set); 4580 return 3; 4581 } 4582 CPU_FREE(p_set); 4583 ]], 4584 [AC_CHECK_DECLS([CPU_SETSIZE],[],[],[#include <sched.h>])] 4585 ) 4586 ] 4587 ) 4588 ] 4589 ) 4590 # NetBSD 4591 # Should work only with -lrt, but actually works without it. 4592 MHD_CHECK_FUNC([sched_getaffinity_np],[[ 4593 #ifdef HAVE_SYS_TYPES_H 4594 #include <sys/types.h> 4595 #endif /* HAVE_SYS_TYPES_H */ 4596 #include <unistd.h> 4597 #include <sched.h> 4598 ]], 4599 [[ 4600 cpuset_t *cpuset_ptr; 4601 cpuid_t cpu_num = 0; 4602 cpuset_ptr = cpuset_create(); 4603 i][f (!cpuset_ptr) 4604 return 2; 4605 i][f (0 != sched_getaffinity_np(getpid(), cpuset_size(cpuset_ptr), cpuset_ptr)) 4606 { 4607 cpuset_destroy(cpuset_ptr); 4608 return 3; 4609 } 4610 i][f (0 >= cpuset_isset(cpu_num, cpuset_ptr)) 4611 { 4612 cpuset_destroy(cpuset_ptr); 4613 return 4; /* Actually this could be a valid result */ 4614 } 4615 cpuset_destroy(cpuset_ptr); 4616 ]] 4617 ) 4618 ] 4619 ) 4620 # FreeBSD 4621 MHD_CHECK_FUNC([cpuset_getaffinity],[[ 4622 #ifdef HAVE_SYS_PARAM_H 4623 #include <sys/param.h> 4624 #endif /* HAVE_SYS_PARAM_H */ 4625 #include <sys/cpuset.h> 4626 ]], 4627 [[ 4628 cpuset_t cur_mask; 4629 i][f (0 != cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1, sizeof(cur_mask), &cur_mask)) 4630 return 2; 4631 ]], 4632 [ 4633 MHD_CHECK_FUNC([CPU_COUNT],[[ 4634 #ifdef HAVE_SYS_PARAM_H 4635 #include <sys/param.h> 4636 #endif /* HAVE_SYS_PARAM_H */ 4637 #ifdef HAVE_SYS__CPUSET_H 4638 #include <sys/_cpuset.h> 4639 #endif /* HAVE_SYS_PARAM_H */ 4640 #include <sys/cpuset.h> 4641 ]], 4642 [[ 4643 cpuset_t test_mask; 4644 CPU_ZERO(&test_mask); 4645 i][f (0 != CPU_COUNT(&test_mask)) 4646 return 2; 4647 ]], 4648 [ 4649 MHD_CHECK_FUNC([CPU_COUNT_S],[[ 4650 #ifdef HAVE_SYS_PARAM_H 4651 #include <sys/param.h> 4652 #endif /* HAVE_SYS_PARAM_H */ 4653 #ifdef HAVE_SYS__CPUSET_H 4654 #include <sys/_cpuset.h> 4655 #endif /* HAVE_SYS_PARAM_H */ 4656 #include <sys/cpuset.h> 4657 ]], 4658 [[ 4659 static const unsigned int max_cpu_num = 2048u; 4660 cpuset_t *mask_ptr; 4661 mask_ptr = CPU_ALLOC(max_cpu_num); 4662 i][f (! mask_ptr) 4663 return 2; 4664 i][f (0 != cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1, 4665 CPU_ALLOC_SIZE(max_cpu_num), mask_ptr)) 4666 { 4667 CPU_FREE(mask_ptr); 4668 return 3; 4669 } 4670 i][f (0 == CPU_COUNT_S(CPU_ALLOC_SIZE(max_cpu_num), &test_mask)) 4671 { 4672 CPU_FREE(mask_ptr); 4673 return 4; 4674 } 4675 CPU_FREE(mask_ptr); 4676 ]] 4677 ) 4678 ] 4679 ) 4680 ] 4681 ) 4682 AS_VAR_IF([mhd_cv_have_func_CPU_COUNT_S],["yes"], 4683 [ 4684 AC_CACHE_CHECK([whether CPU_COUNT_S() expects max CPU number as 'size' parameter],[mhd_cv_func_cpu_count_s_cpus], 4685 [ 4686 AS_VAR_IF([cross-compiling],["yes"],[mhd_cv_func_cpu_count_s_cpus="assuming no"], 4687 [ 4688 AC_LINK_IFELSE( 4689 [ 4690 AC_LANG_PROGRAM([[ 4691 #ifdef HAVE_SYS_TYPES_H 4692 #include <sys/types.h> 4693 #endif /* HAVE_SYS_TYPES_H */ 4694 #ifdef HAVE_SYS_PARAM_H 4695 #include <sys/param.h> 4696 #endif /* HAVE_SYS_PARAM_H */ 4697 #ifdef HAVE_SYS__CPUSET_H 4698 #include <sys/_cpuset.h> 4699 #endif /* HAVE_SYS_PARAM_H */ 4700 #ifdef HAVE_SYS_CPUSET_H 4701 #include <sys/cpuset.h> 4702 #endif /* HAVE_SYS_CPUSET_H */ 4703 #ifdef HAVE_STDDEF_H 4704 #include <stddef.h> 4705 #endif /* HAVE_STDDEF_H */ 4706 #ifdef HAVE_UNISTD_H 4707 #include <unistd.h> 4708 #endif /* HAVE_UNISTD_H */ 4709 #ifdef HAVE_SCHED_H 4710 #include <sched.h> 4711 #endif /* HAVE_SCHED_H */ 4712 #include <stdio.h> 4713 4714 #ifdef HAVE_SCHED_GETAFFINITY 4715 #define TEST_CPUSET_TYPE cpu_set_t 4716 #else /* ! HAVE_SCHED_GETAFFINITY */ 4717 #define TEST_CPUSET_TYPE cpuset_t 4718 #endif /* ! HAVE_SCHED_GETAFFINITY */ 4719 ]], 4720 [[ 4721 TEST_CPUSET_TYPE *p_testset; 4722 /* The size of the cpuset that is larger then the test cpuset (in CPUs) */ 4723 static const unsigned int testset_size_oversized_cpus = (8 * sizeof(long)) * 1024; 4724 const size_t testset_size_oversized_bytes = CPU_ALLOC_SIZE(testset_size_oversized_cpus); 4725 /* The size of the test cpuset in number of CPUs */ 4726 const unsigned int testset_size_cpus = (unsigned int) testset_size_oversized_bytes; 4727 /* The size of the test cpuset in bytes */ 4728 const size_t testset_size_bytes = CPU_ALLOC_SIZE(testset_size_cpus); 4729 /* The last one CPU in the test set */ 4730 const unsigned int test_cpu_num1 = testset_size_cpus - 1; 4731 /* The penultimate CPU in the test set */ 4732 const unsigned int test_cpu_num2 = testset_size_cpus - 2; 4733 /* The CPU numbers that should be cleared */ 4734 const unsigned int test_cpu_clear1 = testset_size_cpus - 3; 4735 const unsigned int test_cpu_clear2 = testset_size_cpus - 4; 4736 unsigned int count_res; 4737 int ret = 0; 4738 4739 /* Allocate oversize area to ensure that memory outside the buffer is not used */ 4740 p_testset = CPU_ALLOC(testset_size_oversized_cpus); 4741 if (! p_testset) 4742 { 4743 fprintf (stderr, "Error allocating memory.\n"); 4744 return 99; 4745 } 4746 /* Set the some CPU numbers and then clear them */ 4747 CPU_SET_S(test_cpu_clear1, testset_size_bytes, p_testset); 4748 CPU_SET_S(test_cpu_clear2, testset_size_bytes, p_testset); 4749 CPU_ZERO_S(testset_size_bytes, p_testset); 4750 /* Set two CPUs on */ 4751 CPU_SET_S(test_cpu_num1, testset_size_bytes, p_testset); 4752 CPU_SET_S(test_cpu_num2, testset_size_bytes, p_testset); 4753 count_res = (unsigned int) CPU_COUNT_S(testset_size_bytes, p_testset); 4754 if (0 == count_res) 4755 { 4756 fprintf (stderr, "Full cpuset cannot be read by CPU_COUNT_S() when using the number of bytes as the size parameter.\n"); 4757 /* Set the some CPU numbers and then clear them */ 4758 CPU_SET_S(test_cpu_clear1, testset_size_cpus, p_testset); 4759 CPU_SET_S(test_cpu_clear2, testset_size_cpus, p_testset); 4760 CPU_ZERO_S(testset_size_cpus, p_testset); 4761 /* Set two CPUs on */ 4762 CPU_SET_S(test_cpu_num1, testset_size_cpus, p_testset); 4763 CPU_SET_S(test_cpu_num2, testset_size_cpus, p_testset); 4764 count_res = (unsigned int) CPU_COUNT_S(testset_size_cpus, p_testset); 4765 if (2 == count_res) 4766 { 4767 fprintf (stderr, "Full cpuset is read by CPU_COUNT_S() only when using the maximum CPU number as the size parameter.\n"); 4768 ret = 3; 4769 } 4770 else 4771 { 4772 fprintf (stderr, "Wrong result returned by CPU_COUNT_S() when using the maximum CPU number as the size parameter.\n"); 4773 fprintf (stderr, "Number of 'enabled' CPUs: 2\n"); 4774 fprintf (stderr, "Number of counted CPUs: %u\n", count_res); 4775 fprintf (stderr, "CPU_COUNT_S() could be unreliable.\n"); 4776 ret = 70; 4777 } 4778 } 4779 else if (2 == count_res) 4780 { 4781 fprintf (stderr, "Full cpuset is read by CPU_COUNT_S() when using the number of bytes as the size parameter.\n"); 4782 } 4783 else 4784 { 4785 fprintf (stderr, "Wrong result returned by CPU_COUNT_S() when using the number of bytes as the size parameter.\n"); 4786 fprintf (stderr, "Number of 'enabled' CPUs: 2\n"); 4787 fprintf (stderr, "Number of counted CPUs: %u\n", count_res); 4788 fprintf (stderr, "CPU_COUNT_S() could be unreliable.\n"); 4789 ret = 71; 4790 } 4791 CPU_FREE(p_testset); 4792 if (0 != ret) 4793 return ret; 4794 ]] 4795 ) 4796 ], 4797 [ 4798 AM_RUN_LOG([./conftest$EXEEXT]) 4799 count_test_res=$? 4800 AS_IF([test $count_test_res -eq 0],[mhd_cv_func_cpu_count_s_cpus="no"], 4801 [test $count_test_res -eq 3],[mhd_cv_func_cpu_count_s_cpus="yes"], 4802 [ 4803 AC_MSG_WARN([Unexpected value returned by CPU_COUNT_S() test program. Please report to ${PACKAGE_BUGREPORT}]) 4804 mhd_cv_func_cpu_count_s_cpus="assuming no" 4805 ] 4806 ) 4807 ], 4808 [ 4809 AC_MSG_WARN([Cannot build CPU_COUNT_S() test program. Please report to ${PACKAGE_BUGREPORT}]) 4810 mhd_cv_func_cpu_count_s_cpus="assuming no" 4811 ] 4812 ) 4813 ] 4814 ) 4815 ] 4816 ) 4817 AS_VAR_IF([mhd_cv_func_cpu_count_s_cpus],["yes"], 4818 [AC_DEFINE([MHD_FUNC_CPU_COUNT_S_GETS_CPUS],[1], 4819 [Define to '1' if CPU_COUNT_S() function expects max CPU number as 'size' parameter]) 4820 ] 4821 ) 4822 ] 4823 ) 4824 ] 4825 ) 4826 4827 # Check for fork() and waitpid(). They are used for tests. 4828 AC_MSG_CHECKING([[for fork()]]) 4829 mhd_have_fork_waitpid='no' 4830 AC_LINK_IFELSE( 4831 [ 4832 AC_LANG_PROGRAM( 4833 [[ 4834 #ifdef HAVE_SYS_TYPES_H 4835 #include <sys/types.h> 4836 #endif 4837 #ifdef HAVE_UNISTD_H 4838 #include <unistd.h> 4839 #endif 4840 ]], [[ 4841 pid_t p = fork (); 4842 if (0 == p) 4843 return 1; 4844 ]]) 4845 ], [ 4846 AC_DEFINE([[HAVE_FORK]], [[1]], [Define to 1 if you have the usable `fork' function.]) 4847 AC_MSG_RESULT([[yes]]) 4848 4849 AC_MSG_CHECKING([[for waitpid()]]) 4850 AC_LINK_IFELSE( 4851 [ 4852 AC_LANG_PROGRAM( 4853 [[ 4854 #ifdef HAVE_SYS_TYPES_H 4855 #include <sys/types.h> 4856 #endif 4857 #ifdef HAVE_UNISTD_H 4858 #include <unistd.h> 4859 #endif 4860 #include <sys/wait.h> 4861 ]], [[ 4862 pid_t p = fork (); 4863 if (0 == p) 4864 return 1; 4865 waitpid (p, (void*)0, 0) 4866 ]]) 4867 ], [ 4868 AC_DEFINE([[HAVE_WAITPID]], [[1]], [Define to 1 if you have the usable `waitpid' function.]) 4869 AC_MSG_RESULT([[yes]]) 4870 mhd_have_fork_waitpid='yes' 4871 ],[ 4872 AC_MSG_RESULT([[no]]) 4873 ]) 4874 ],[ 4875 AC_MSG_RESULT([[no]]) 4876 ]) 4877 4878 AM_CONDITIONAL([HAVE_FORK_WAITPID], [test "x$mhd_have_fork_waitpid" = "xyes"]) 4879 4880 # gcov compilation 4881 AC_MSG_CHECKING(whether to compile with support for code coverage analysis) 4882 AC_ARG_ENABLE([coverage], 4883 AS_HELP_STRING([--enable-coverage], 4884 [compile the library with code coverage support]), 4885 [use_gcov=${enableval}], 4886 [use_gcov=no]) 4887 AC_MSG_RESULT($use_gcov) 4888 AM_CONDITIONAL([USE_COVERAGE], [test "x$use_gcov" = "xyes"]) 4889 4890 AX_COUNT_CPUS 4891 AC_SUBST([MHD_REAL_CPU_COUNT],[${CPU_COUNT}]) 4892 AM_SUBST_NOTMAKE([MHD_REAL_CPU_COUNT]) 4893 AC_MSG_CHECKING([for number of CPU cores to use in tests]) 4894 AS_VAR_IF([use_heavy_tests], ["yes"], 4895 [ 4896 # Enable usage of many core if heavy tests are enabled 4897 AS_IF([[test "$CPU_COUNT" -gt "32"]], [[CPU_COUNT="32"]])dnl Limit resource usage 4898 ], 4899 [ 4900 # Limit usage to just a few cores if heavy tests are not enabled 4901 AS_IF([[test "$CPU_COUNT" -gt "6"]], [[CPU_COUNT="6"]]) 4902 AS_IF([[test "$CPU_COUNT" -lt "2"]], [[CPU_COUNT="2"]]) 4903 ] 4904 ) 4905 AC_MSG_RESULT([$CPU_COUNT]) 4906 4907 4908 AC_ARG_ENABLE([[asserts]], 4909 [AS_HELP_STRING([[--enable-asserts]], 4910 [enable test build with debug asserts])], 4911 [], 4912 [enable_asserts='auto'] 4913 ) 4914 AS_UNSET([use_asserts_MSG]) 4915 AC_CACHE_CHECK([[whether NDEBUG macro is defined]], [mhd_cv_macro_ndebug_def], 4916 [ 4917 AC_LINK_IFELSE( 4918 [ 4919 AC_LANG_SOURCE([[ 4920 #ifndef NDEBUG 4921 #error NDEBUG is NOT defined 4922 chome me now 4923 #endif 4924 4925 int main(void) 4926 { 4927 return 0; 4928 } 4929 ]] 4930 ) 4931 ], 4932 [[mhd_cv_macro_ndebug_def='yes']], 4933 [[mhd_cv_macro_ndebug_def='no']] 4934 ) 4935 ] 4936 ) 4937 AS_VAR_IF([enable_asserts],["yes"], 4938 [ 4939 AS_VAR_IF([mhd_cv_macro_ndebug_def],["yes"], 4940 [ 4941 AC_MSG_FAILURE([Parameter --enable-asserts is specified, but NDEBUG macro is defined as well]) 4942 ] 4943 ) 4944 use_asserts_MSG="yes, enabled by configure parameter" 4945 ] 4946 ) 4947 AC_CACHE_CHECK([[whether _DEBUG macro is defined]], [mhd_cv_macro__debug_def], 4948 [ 4949 AC_LINK_IFELSE( 4950 [ 4951 AC_LANG_SOURCE([[ 4952 #ifndef _DEBUG 4953 #error _DEBUG is NOT defined 4954 chome me now 4955 #endif 4956 4957 int main(void) 4958 { 4959 return 0; 4960 } 4961 ]] 4962 ) 4963 ], 4964 [[mhd_cv_macro__debug_def='yes']], 4965 [[mhd_cv_macro__debug_def='no']] 4966 ) 4967 ] 4968 ) 4969 AS_VAR_IF([enable_asserts],["no"], 4970 [ 4971 AS_VAR_IF([mhd_cv_macro__debug_def],["yes"], 4972 [ 4973 AC_MSG_FAILURE([Parameter --disable-asserts is specified, but _DEBUG macro is defined as well]) 4974 ] 4975 ) 4976 use_asserts_MSG="no, set by configure parameter" 4977 ] 4978 ) 4979 AS_IF([test "x${mhd_cv_macro_ndebug_def}" = "xyes" && test "x${mhd_cv_macro__debug_def}" = "xyes"], 4980 [AC_MSG_FAILURE([Both NDEBUG and _DEBUG macros are defined])] 4981 ) 4982 AS_VAR_IF([enable_asserts],["auto"], 4983 [ 4984 AS_VAR_IF([mhd_cv_macro_ndebug_def],["yes"], 4985 [ 4986 enable_asserts="no" 4987 use_asserts_MSG="no, set by NDEBUG preprocessor macro" 4988 ] 4989 ) 4990 ] 4991 ) 4992 AS_VAR_IF([enable_asserts],["auto"], 4993 [ 4994 AS_VAR_IF([mhd_cv_macro__debug_def],["yes"], 4995 [ 4996 enable_asserts="yes" 4997 use_asserts_MSG="yes, enabled by _DEBUG preprocessor macro" 4998 ] 4999 ) 5000 ] 5001 ) 5002 AS_VAR_IF([enable_asserts],["auto"], 5003 [ 5004 AC_CACHE_CHECK([[whether DEBUG macro is defined]], [mhd_cv_macro_debug_def], 5005 [ 5006 AC_LINK_IFELSE( 5007 [ 5008 AC_LANG_SOURCE([[ 5009 #ifndef DEBUG 5010 #error DEBUG is NOT defined 5011 chome me now 5012 #endif 5013 5014 int main(void) 5015 { 5016 return 0; 5017 } 5018 ]] 5019 ) 5020 ], 5021 [[mhd_cv_macro_debug_def='yes']], 5022 [[mhd_cv_macro_debug_def='no']] 5023 ) 5024 ] 5025 ) 5026 AS_VAR_IF([mhd_cv_macro_debug_def],["yes"], 5027 [ 5028 enable_asserts="yes" 5029 use_asserts_MSG="yes, enabled by DEBUG preprocessor macro" 5030 ] 5031 ) 5032 ] 5033 ) 5034 AC_MSG_CHECKING([[whether to enable debug asserts]]) 5035 AS_VAR_IF([enable_asserts],["auto"], 5036 [ 5037 AS_CASE([${enable_build_type}], 5038 [debug|debugger], 5039 [ 5040 enable_asserts="yes" 5041 use_asserts_MSG="yes, enabled by --enable-bulid-type=${enable_build_type}" 5042 ], 5043 [ 5044 enable_asserts="no" 5045 use_asserts_MSG="no" 5046 ] 5047 ) 5048 ] 5049 ) 5050 AS_CASE([[$enable_asserts]], [[yes]], [[:]], [[no]], [[:]], [[enable_asserts='no']]) 5051 AC_MSG_RESULT([[${use_asserts_MSG=no}]]) 5052 5053 AS_VAR_IF([[enable_asserts]], [["yes"]], 5054 [ 5055 AS_VAR_IF([[mhd_cv_macro__debug_def]], [["yes"]], [:], 5056 [ 5057 MHD_PREPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-D_DEBUG=1]) 5058 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 5059 ] 5060 ) 5061 AC_CACHE_CHECK([[whether system assert() is available]], [mhd_cv_sys_assert_avail], 5062 [ 5063 AC_LINK_IFELSE( 5064 [ 5065 AC_LANG_SOURCE([[ 5066 #include <assert.h> 5067 5068 static int pos_val(void) {return 5;} 5069 static int neg_val(void) {return -5;} 5070 int main(void) 5071 { 5072 int pos_var = pos_val(), neg_var = neg_val(); 5073 assert(neg_var > pos_var); /* Must trigger assert. */ 5074 return pos_var + neg_var; 5075 } 5076 ]]) 5077 ], 5078 [[mhd_cv_sys_assert_avail='yes']], 5079 [[mhd_cv_sys_assert_avail='no']] 5080 ) 5081 ] 5082 ) 5083 AS_VAR_IF([[mhd_cv_sys_assert_avail]], [["no"]], [], 5084 [AC_DEFINE([[HAVE_ASSERT]], [[1]], [Define if you have usable assert() and assert.h])]) 5085 ], 5086 [ 5087 AS_VAR_IF([[mhd_cv_macro_ndebug_def]], [["yes"]], [:], 5088 [ 5089 MHD_PREPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DNDEBUG=1]) 5090 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" 5091 ] 5092 ) 5093 ] 5094 ) 5095 5096 AS_UNSET([enabled_sanitizers]) 5097 TESTS_ENVIRONMENT_ac="" 5098 AM_ASAN_OPTIONS="" 5099 AM_UBSAN_OPTIONS="" 5100 AM_LSAN_OPTIONS="" 5101 AS_UNSET([ASAN_OPTIONS]) 5102 AS_UNSET([UBSAN_OPTIONS]) 5103 AS_UNSET([LSAN_OPTIONS]) 5104 5105 AC_MSG_CHECKING([whether to enable run-time sanitizers]) 5106 AC_ARG_ENABLE([sanitizers], 5107 [AS_HELP_STRING([[--enable-sanitizers[=address,undefined,leak,user-poison]]], 5108 [enable run-time sanitizers, specify the list of types of sanitizers to enable, ] 5109 [leave the list empty (or set to "auto") to enable all supported and available ] 5110 [sanitizers, or specify "auto-fallback" to use sanitizers even without ] 5111 [installed sanitizer run-time library])], 5112 [], [AS_CASE([${enable_build_type}],[debug], 5113 [enable_sanitizers='auto-optional'],[enable_sanitizers='no'])] 5114 ) 5115 AS_IF([test "x${enable_sanitizers}" = "x"], [enable_sanitizers="auto"]) 5116 AS_VAR_IF([enable_sanitizers], ["yes"], [enable_sanitizers="auto"]) 5117 AS_VAR_IF([enable_sanitizers], ["autofallback"], [enable_sanitizers="auto-fallback"]) 5118 AS_VAR_IF([enable_sanitizers], ["autooptional"], [enable_sanitizers="auto-optional"]) 5119 AS_IF([test "x${enable_sanitizers}" = "xno"], 5120 [ 5121 enable_sanitizers="no" 5122 enable_san_address="no" 5123 enable_san_undef="no" 5124 enable_san_leak="no" 5125 enable_san_upoison="no" 5126 ], 5127 [test "x${enable_sanitizers}" = "xauto" || test "x${enable_sanitizers}" = "xauto-optional"], 5128 [ 5129 AS_VAR_IF([enable_compiler_hardening],["yes"], 5130 [ 5131 AS_VAR_IF([enable_sanitizers],["auto"], 5132 [AC_MSG_ERROR([sanitizers cannot be enabled with compiler hardnening])], 5133 [AC_MSG_WARN([sanitizers cannot be enabled with compiler hardnening])] 5134 ) 5135 enable_sanitizers="no" 5136 enable_san_address="no" 5137 enable_san_undef="no" 5138 enable_san_leak="no" 5139 enable_san_upoison="no" 5140 ], 5141 [ 5142 enable_san_address="auto" 5143 enable_san_undef="auto" 5144 enable_san_leak="auto" 5145 enable_san_upoison="auto" 5146 ] 5147 ) 5148 ], 5149 [test "x${enable_sanitizers}" = "xauto-fallback"], 5150 [ 5151 enable_san_address="auto" 5152 enable_san_undef="auto-fallback" 5153 enable_san_leak="auto" 5154 enable_san_upoison="auto" 5155 ], 5156 [ 5157 AS_UNSET([san]) 5158 enable_san_address="no" 5159 enable_san_undef="no" 5160 enable_san_leak="no" 5161 enable_san_upoison="no" 5162 f][or san in `AS_ECHO([${enable_sanitizers}]) | tr ',' ' '` 5163 do 5164 AS_CASE([$san], 5165 [address], [enable_san_address="yes"], 5166 [undefined], [enable_san_undef="yes"], 5167 [leak], [enable_san_leak="yes"], 5168 [user-poison|user_poison], [enable_san_upoison="yes"], 5169 [no|yes|auto|auto-fallback|autofallback], [AC_MSG_ERROR(["$san" cannot be used with other options for --enable-sanitizers=])], 5170 [AC_MSG_ERROR([Unknown parameter "$san" for --enable-sanitizers=])] 5171 ) 5172 done 5173 AS_IF([test "x${enable_san_upoison}" = "xyes" && test "x${enable_san_address}" = "xno"], 5174 [AC_MSG_ERROR([User memory poisoning cannot be used without address sanitizer])] 5175 ) 5176 enable_sanitizers="selected" 5177 ] 5178 ) 5179 AS_CASE([${enable_sanitizers}], 5180 [selected], [AC_MSG_RESULT([selected])], 5181 [auto], [AC_MSG_RESULT([yes, detect and use supported sanitizers])], 5182 [auto-fallback], [AC_MSG_RESULT([yes, detect and use supported sanitizers even without run-time lib])], 5183 [auto-optional], [AC_MSG_RESULT([yes, detect and use supported sanitizers if any])], 5184 [AC_MSG_RESULT([no])] 5185 ) 5186 AS_VAR_IF([enable_sanitizers], ["no"], [:], 5187 [ 5188 AS_UNSET([san_FLAGS]) # the sanitizer flags to be added to both CFLAGS and LDFLAGS 5189 AS_UNSET([san_CFLAGS]) # the sanitizer flags to be added to CFLAGS 5190 AC_CACHE_CHECK([whether '-fsanitize=' works for $CC], 5191 [mhd_cv_cc_sanitizer_works], 5192 [ 5193 CFLAGS="${CFLAGS_ac} -fsanitize=wrongFeatureName ${user_CFLAGS}" 5194 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])], 5195 [mhd_cv_cc_sanitizer_works=no], [mhd_cv_cc_sanitizer_works=yes]) 5196 ] 5197 ) 5198 AS_VAR_IF([mhd_cv_cc_sanitizer_works], ["yes"], 5199 [ 5200 AS_VAR_IF([enable_san_address], ["no"], [:], 5201 [ 5202 AC_CACHE_CHECK([for address sanitizer], [mhd_cv_cc_sanitizer_address], 5203 [ 5204 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=address ${user_CFLAGS}" 5205 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], 5206 [mhd_cv_cc_sanitizer_address=yes], [mhd_cv_cc_sanitizer_address=no]) 5207 ] 5208 ) 5209 AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"], 5210 [ 5211 AC_DEFINE([MHD_ASAN_ACTIVE], [1], [Define to '1' if you have address sanitizer enabled]) 5212 AX_APPEND_FLAG([-fsanitize=address], [san_FLAGS]) 5213 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }address" 5214 AS_VAR_IF([enable_san_leak], ["no"], [:], 5215 [ 5216 AC_CACHE_CHECK([whether leak detect is not rejected by address sanitizer], [mhd_cv_cc_sanitizer_address_leak], 5217 [ 5218 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${user_CFLAGS}" 5219 ASAN_OPTIONS="exitcode=88:detect_leaks=1:halt_on_error=1" 5220 export ASAN_OPTIONS 5221 AC_RUN_IFELSE([AC_LANG_PROGRAM([],[])], 5222 [mhd_cv_cc_sanitizer_address_leak=yes], [mhd_cv_cc_sanitizer_address_leak=no], 5223 [ 5224 # Cross-compiling with sanitizers? 5225 mhd_cv_cc_sanitizer_address_leak='assuming no' 5226 ] 5227 ) 5228 AS_UNSET([ASAN_OPTIONS]) 5229 ] 5230 ) 5231 ] 5232 ) 5233 AC_CACHE_CHECK([for pointer compare sanitizer], [mhd_cv_cc_sanitizer_pointer_compare], 5234 [ 5235 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-compare ${user_CFLAGS}" 5236 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], 5237 [mhd_cv_cc_sanitizer_pointer_compare=yes], [mhd_cv_cc_sanitizer_pointer_compare=no]) 5238 ] 5239 ) 5240 AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_compare],["yes"], 5241 [ 5242 AX_APPEND_FLAG([-fsanitize=pointer-compare], [san_FLAGS]) 5243 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer compare" 5244 ] 5245 ) 5246 AC_CACHE_CHECK([for pointer subtract sanitizer], [mhd_cv_cc_sanitizer_pointer_subtract], 5247 [ 5248 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-subtract ${user_CFLAGS}" 5249 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], 5250 [mhd_cv_cc_sanitizer_pointer_subtract=yes], [mhd_cv_cc_sanitizer_pointer_subtract=no]) 5251 ] 5252 ) 5253 AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_subtract],["yes"], 5254 [ 5255 AX_APPEND_FLAG([-fsanitize=pointer-subtract], [san_FLAGS]) 5256 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer subtract" 5257 ] 5258 ) 5259 AS_VAR_IF([enable_san_upoison], ["no"], [:], 5260 [ 5261 AC_CHECK_HEADERS([sanitizer/asan_interface.h], [], [], [AC_INCLUDES_DEFAULT]) 5262 AS_VAR_IF([ac_cv_header_sanitizer_asan_interface_h],["yes"], 5263 [ 5264 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}" 5265 MHD_CHECK_FUNC([__asan_address_is_poisoned],[[#include <sanitizer/asan_interface.h>]], 5266 [[int a_var=1; i][f(__asan_address_is_poisoned((void*) &a_var)) return 3;]] 5267 ) 5268 MHD_CHECK_FUNC([__asan_region_is_poisoned],[[#include <sanitizer/asan_interface.h>]], 5269 [[int a_var=1; i][f(((void*) 0) != __asan_region_is_poisoned((void*) &a_var, sizeof(a_var))) return 3;]] 5270 ) 5271 AC_CACHE_CHECK([whether special function attribute is needed for user-poison], [mhd_cv_func_u_p_attribute_needed], 5272 [ 5273 ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1" 5274 export ASAN_OPTIONS 5275 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}" 5276 AC_RUN_IFELSE( 5277 [ 5278 AC_LANG_SOURCE( 5279 [[ 5280 #include <stdint.h> 5281 #include <stdlib.h> 5282 #include <sanitizer/asan_interface.h> 5283 5284 static const size_t first_pos = 0; 5285 static const size_t mid_pos = 64; 5286 static const size_t last_pos = 128; 5287 static const size_t zone_size = 16; 5288 static const size_t buf_size = 128 + 16; 5289 5290 static int ptr_compare(void *ptr1, uint8_t *ptr2) 5291 { 5292 if ((((uintptr_t) (uint8_t *)ptr1) >= ((uintptr_t)ptr2))) 5293 return ((char *) ptr1)[0] < ((char *) ptr2)[0]; 5294 return ((char *) ptr1)[0] > ((char *) ptr2)[0]; 5295 } 5296 5297 static int ptr_subtract(void *ptr1, uint8_t *ptr2) 5298 { 5299 return ((size_t)(((uintptr_t)(uint8_t*)ptr1) - ((uintptr_t)ptr2))) <= last_pos; 5300 } 5301 5302 int main(int argc, char *argv[]) 5303 { 5304 char *buf = (char*) malloc (buf_size); 5305 char *a; 5306 char *b; 5307 int ret; 5308 5309 (void) argv; 5310 if (NULL == buf) 5311 return 10; 5312 ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size); 5313 ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size); 5314 5315 if (0 < argc) 5316 a = buf + last_pos; 5317 else 5318 a = buf + first_pos; 5319 b = buf + mid_pos; 5320 5321 *a = '0'; 5322 *b = '9'; 5323 5324 if (ptr_compare((void *)a, (uint8_t*) b)) 5325 { 5326 if (ptr_subtract((void *)a, (uint8_t*) b)) 5327 ret = 0; 5328 else 5329 ret = 10; 5330 } 5331 else 5332 ret = 5; 5333 ASAN_UNPOISON_MEMORY_REGION (buf, buf_size); 5334 free (buf); 5335 5336 return ret; 5337 } 5338 ]] 5339 ) 5340 ], 5341 [mhd_cv_func_u_p_attribute_needed="no"], [mhd_cv_func_u_p_attribute_needed="yes"], 5342 [ 5343 # Cross-compiling with sanitizers?? 5344 mhd_cv_func_up_attribute_needed='assuming no' 5345 ] 5346 ) 5347 AS_UNSET([ASAN_OPTIONS]) 5348 ] 5349 ) 5350 ] 5351 ) 5352 AS_VAR_IF([mhd_cv_func_u_p_attribute_needed],["yes"],[:], 5353 [ 5354 AC_DEFINE([FUNC_PTRCOMPARE_CAST_WORKAROUND_WORKS],[1],[Define to '1' if cast to 'uintptr_t' works for safely processing user-poisoned pointer]) 5355 ] 5356 ) 5357 AS_IF([test "x${mhd_cv_func_u_p_attribute_needed}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes"], 5358 [ 5359 AC_CACHE_CHECK([whether '__attribute__((no_sanitize("pointer-compare")))' and '__attribute__((no_sanitize("pointer-subtract")))' work], 5360 [mhd_cv_func_attribute_nosanitize_ptr], 5361 [ 5362 ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1" 5363 export ASAN_OPTIONS 5364 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}" 5365 AC_RUN_IFELSE( 5366 [ 5367 AC_LANG_SOURCE( 5368 [[ 5369 #include <stdint.h> 5370 #include <stdlib.h> 5371 #include <sanitizer/asan_interface.h> 5372 5373 static const size_t first_pos = 0; 5374 static const size_t mid_pos = 64; 5375 static const size_t last_pos = 128; 5376 static const size_t zone_size = 16; 5377 static const size_t buf_size = 128 + 16; 5378 5379 __attribute__((no_sanitize("pointer-compare"))) 5380 static int ptr_compare(void *ptr1, uint8_t *ptr2) 5381 { 5382 if ((((const uint8_t*)ptr1) >= ((const uint8_t*)ptr2))) 5383 return ((char *) ptr1)[0] < ((char *) ptr2)[0]; 5384 return ((char *) ptr1)[0] > ((char *) ptr2)[0]; 5385 } 5386 5387 __attribute__((no_sanitize("pointer-subtract"))) 5388 static int ptr_subtract(void *ptr1, uint8_t *ptr2) 5389 { 5390 return ((size_t)(((const uint8_t*)ptr1) - \ 5391 ((const uint8_t*)ptr2))) <= last_pos; 5392 } 5393 5394 int main(int argc, char *argv[]) 5395 { 5396 char *buf = (char*) malloc (buf_size); 5397 char *a; 5398 char *b; 5399 int ret; 5400 5401 (void) argv; 5402 if (NULL == buf) 5403 return 10; 5404 ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size); 5405 ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size); 5406 5407 if (0 < argc) 5408 a = buf + last_pos; 5409 else 5410 a = buf + first_pos; 5411 b = buf + mid_pos; 5412 5413 *a = '0'; 5414 *b = '9'; 5415 5416 if (ptr_compare((void *)a, (uint8_t*) b)) 5417 { 5418 if (ptr_subtract((void *)a, (uint8_t*) b)) 5419 ret = 0; 5420 else 5421 ret = 10; 5422 } 5423 else 5424 ret = 5; 5425 ASAN_UNPOISON_MEMORY_REGION (buf, buf_size); 5426 free (buf); 5427 5428 return ret; 5429 } 5430 ]] 5431 ) 5432 ], 5433 [mhd_cv_func_attribute_nosanitize_ptr=yes], [mhd_cv_func_attribute_nosanitize_ptr=no], 5434 [ 5435 # Cross-compiling with sanitizers?? 5436 mhd_cv_func_attribute_nosanitize_ptr='assuming no' 5437 ] 5438 ) 5439 AS_UNSET([ASAN_OPTIONS]) 5440 ] 5441 ) 5442 AS_VAR_IF([mhd_cv_func_attribute_nosanitize_ptr], ["yes"], 5443 [ 5444 AC_DEFINE([FUNC_ATTR_PTRCOMPARE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-compare")))' works]) 5445 AC_DEFINE([FUNC_ATTR_PTRSUBTRACT_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-subtract")))' works]) 5446 ], 5447 [ 5448 AC_CACHE_CHECK([whether '__attribute__((no_sanitize("address")))' works for pointers compare], [mhd_cv_func_attribute_nosanitize_addr], 5449 [ 5450 ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1" 5451 export ASAN_OPTIONS 5452 CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}" 5453 AC_RUN_IFELSE( 5454 [ 5455 AC_LANG_SOURCE( 5456 [[ 5457 #include <stdint.h> 5458 #include <stdlib.h> 5459 #include <sanitizer/asan_interface.h> 5460 5461 static const size_t first_pos = 0; 5462 static const size_t mid_pos = 64; 5463 static const size_t last_pos = 128; 5464 static const size_t zone_size = 16; 5465 static const size_t buf_size = 128 + 16; 5466 5467 __attribute__((no_sanitize("address"))) 5468 static int ptr_compare(void *ptr1, uint8_t *ptr2) 5469 { 5470 if ((((const uint8_t*)ptr1) >= ((const uint8_t*)ptr2))) 5471 return ((char *) ptr1)[0] < ((char *) ptr2)[0]; 5472 return ((char *) ptr1)[0] > ((char *) ptr2)[0]; 5473 } 5474 5475 __attribute__((no_sanitize("address"))) 5476 static int ptr_subtract(void *ptr1, uint8_t *ptr2) 5477 { 5478 return ((size_t)(((const uint8_t*)ptr1) - \ 5479 ((const uint8_t*)ptr2))) <= last_pos; 5480 } 5481 5482 int main(int argc, char *argv[]) 5483 { 5484 char *buf = (char*) malloc (buf_size); 5485 char *a; 5486 char *b; 5487 int ret; 5488 5489 (void) argv; 5490 if (NULL == buf) 5491 return 10; 5492 ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size); 5493 ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size); 5494 5495 if (0 < argc) 5496 a = buf + last_pos; 5497 else 5498 a = buf + first_pos; 5499 b = buf + mid_pos; 5500 5501 *a = '0'; 5502 *b = '9'; 5503 5504 if (ptr_compare((void *)a, (uint8_t*) b)) 5505 { 5506 if (ptr_subtract((void *)a, (uint8_t*) b)) 5507 ret = 0; 5508 else 5509 ret = 10; 5510 } 5511 else 5512 ret = 5; 5513 ASAN_UNPOISON_MEMORY_REGION (buf, buf_size); 5514 free (buf); 5515 5516 return ret; 5517 } 5518 ]] 5519 ) 5520 ], 5521 [mhd_cv_func_attribute_nosanitize_addr=yes], [mhd_cv_func_attribute_nosanitize_addr=no], 5522 [ 5523 # Cross-compiling with sanitizers?? 5524 mhd_cv_func_attribute_nosanitize_addr='assuming no' 5525 ] 5526 ) 5527 AS_UNSET([ASAN_OPTIONS]) 5528 ] 5529 ) 5530 AS_VAR_IF([mhd_cv_func_attribute_nosanitize_addr], ["yes"], 5531 [AC_DEFINE([FUNC_ATTR_NOSANITIZE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("address")))' works for pointers compare])] 5532 ) 5533 ] 5534 ) 5535 ] 5536 ) 5537 ] 5538 ) 5539 ] 5540 ) 5541 AS_IF([test "x${enable_san_address}" = "xyes" && test "x${mhd_cv_cc_sanitizer_address}" != "xyes"], 5542 [AC_MSG_ERROR([Address sanitizer cannot be enabled])] 5543 ) 5544 enable_san_address="${mhd_cv_cc_sanitizer_address}" 5545 ] 5546 ) 5547 AS_VAR_IF([enable_san_undef], ["no"], [:], 5548 [ 5549 dnl Ensure that '#' will be processed correctly 5550 [ 5551 test_undf_prog=' 5552 #include <stdio.h> 5553 5554 static void func_out_b(char *arr) 5555 { 5556 arr[0] = 0; 5557 arr[16] = 2; 5558 } 5559 5560 static unsigned int int_deref(void *ptr) 5561 { 5562 return (*((unsigned int*)ptr)) + 2; 5563 } 5564 5565 static int func1(void) 5566 { 5567 char chr[16]; 5568 func_out_b (chr); 5569 return (int) (int_deref(chr + 1) + int_deref(chr + 2)); 5570 } 5571 5572 int main(void) 5573 { 5574 unsigned long ulvar; 5575 signed char ch1; 5576 ulvar = -1 * func1(); 5577 ch1 = ulvar * 6UL; 5578 printf("%lu\n", ulvar + ch1); 5579 return 0; 5580 } 5581 ' 5582 ] 5583 AC_CACHE_CHECK([for undefined behavior sanitizer], [mhd_cv_cc_sanitizer_undefined], 5584 [ 5585 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined ${user_CFLAGS}" 5586 AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], 5587 [mhd_cv_cc_sanitizer_undefined=yes], [mhd_cv_cc_sanitizer_undefined=no]) 5588 ] 5589 ) 5590 AS_VAR_IF([mhd_cv_cc_sanitizer_undefined],["yes"], 5591 [ 5592 AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) 5593 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" 5594 ], 5595 [ 5596 AS_CASE([${enable_san_undef}], [yes|auto-fallback], 5597 [ 5598 AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-undefined-trap-on-error'], [mhd_cv_cc_sanitizer_undefined_trap], 5599 [ 5600 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error ${user_CFLAGS}" 5601 AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], 5602 [mhd_cv_cc_sanitizer_undefined_trap=yes], [mhd_cv_cc_sanitizer_undefined_trap=no]) 5603 ] 5604 ) 5605 AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap], ["yes"], 5606 [ 5607 AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) 5608 AX_APPEND_FLAG([-fsanitize-undefined-trap-on-error], [san_FLAGS]) 5609 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" 5610 AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) 5611 ], 5612 [ 5613 AS_IF([test -z "${enabled_sanitizers}"], 5614 [ 5615 # Last resort 5616 AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-trap=all'], [mhd_cv_cc_sanitizer_undefined_trap_all], 5617 [ 5618 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all ${user_CFLAGS}" 5619 AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], 5620 [mhd_cv_cc_sanitizer_undefined_trap_all=yes], [mhd_cv_cc_sanitizer_undefined_trap_all=no]) 5621 ] 5622 ) 5623 AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap_all],["yes"], 5624 [ 5625 AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) 5626 AX_APPEND_FLAG([-fsanitize-trap=all], [san_FLAGS]) 5627 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all ${user_CFLAGS}" 5628 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" 5629 AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) 5630 ] 5631 ) 5632 ] 5633 ) 5634 ] 5635 ) 5636 AS_CASE(["$enabled_sanitizers"], [*undefined], 5637 [ 5638 AS_VAR_IF([mhd_cv_cc_sanitizer_undefined], ["yes"],[], 5639 [ 5640 # A workaround for broken clang which is trying to use UBSan lib 5641 # even when instructed to not use it 5642 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}" 5643 AX_APPEND_LINK_FLAGS([-fsanitize-trap=implicit-conversion], 5644 [san_FLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])]) 5645 ] 5646 ) 5647 ] 5648 ) 5649 ] 5650 ) 5651 ] 5652 ) 5653 AS_CASE(["$enabled_sanitizers"], [*undefined], 5654 [ 5655 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}" 5656 AX_APPEND_LINK_FLAGS([-fsanitize=bounds-strict -fsanitize=local-bounds -fsanitize=implicit-conversion -fsanitize=nullability-arg], 5657 [san_CFLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])]) 5658 ] 5659 ) 5660 AS_UNSET([test_undf_prog]) 5661 AS_CASE(["$enabled_sanitizers"], 5662 [*undefined], [enable_san_undef="yes"], 5663 [ 5664 AS_VAR_IF([enable_san_undef], [yes], [AC_MSG_ERROR([Undefined behavior sanitizer cannot be enabled])]) 5665 enable_san_undef="no" 5666 ] 5667 ) 5668 ] 5669 ) 5670 AS_VAR_IF([enable_san_leak], ["no"], [:], 5671 [ 5672 AC_CACHE_CHECK([for leak sanitizer], [mhd_cv_cc_sanitizer_leak], 5673 [ 5674 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=leak ${user_CFLAGS}" 5675 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], 5676 [mhd_cv_cc_sanitizer_leak=yes], [mhd_cv_cc_sanitizer_leak=no]) 5677 ] 5678 ) 5679 AS_VAR_IF([mhd_cv_cc_sanitizer_leak],["yes"], 5680 [ 5681 AX_APPEND_FLAG([-fsanitize=leak], [san_FLAGS]) 5682 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }leak" 5683 ] 5684 ) 5685 AS_IF([test "x${enable_san_leak}" = "xyes" && test "x${mhd_cv_cc_sanitizer_leak}" != "xyes"], 5686 [AC_MSG_ERROR([User poison cannot be enabled])] 5687 ) 5688 enable_san_leak="${mhd_cv_cc_sanitizer_leak}" 5689 ] 5690 ) 5691 AS_IF([test -z "${enabled_sanitizers}"], 5692 [ 5693 AS_VAR_IF([enable_sanitizers], ["auto-optional"], 5694 [ 5695 san_FLAGS="" 5696 san_CFLAGS="" 5697 ], 5698 [ 5699 AC_MSG_ERROR([cannot find any sanitizer supported by $CC]) 5700 ] 5701 ) 5702 ], 5703 [ 5704 AS_VAR_IF([enable_san_upoison], ["no"], [:], 5705 [ 5706 AC_MSG_CHECKING([whether to enable user memory poisoning]) 5707 AS_IF([test "x${mhd_cv_cc_sanitizer_address}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes" && \ 5708 (test "x${mhd_cv_func_u_p_attribute_needed}" != "xyes" || test "x${mhd_cv_func_attribute_nosanitize_ptr}" = "xyes" || \ 5709 test "x${mhd_cv_func_attribute_nosanitize_addr}" = "xyes")], 5710 [ 5711 AC_DEFINE([MHD_ASAN_POISON_ACTIVE], [1], [Define to '1' if user memory poison is used]) 5712 enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }user-poison" 5713 enable_san_upoison="yes" 5714 AC_MSG_RESULT([yes]) 5715 ], 5716 [ 5717 AC_MSG_RESULT([no]) 5718 AS_VAR_IF([enable_san_upoison], ["yes"], 5719 [AC_MSG_ERROR([User memory poisoning cannot be enabled])]) 5720 enable_san_upoison="no" 5721 ] 5722 ) 5723 ] 5724 ) 5725 AS_VAR_IF([enable_san_address], ["yes"], 5726 [ 5727 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}" 5728 AC_CHECK_DECL([_FORTIFY_SOURCE], 5729 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-U_FORTIFY_SOURCE])], 5730 [],[/* no includes */]) 5731 AX_APPEND_FLAG([-D_FORTIFY_SOURCE=0], [san_CFLAGS]) 5732 ], 5733 [ 5734 AS_CASE([$enable_sanitizers], [auto|auto-fallback], 5735 [AC_MSG_WARN([$CC does not support address sanitizer])]) 5736 ] 5737 ) 5738 CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}" 5739 # Always stop on sanitizer error 5740 AX_APPEND_COMPILE_FLAGS([-fno-sanitize-recover=all], [san_CFLAGS]) 5741 # Get a better output for sanitizers error reporting 5742 AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer -fno-optimize-sibling-calls], 5743 [san_CFLAGS]) 5744 AS_VAR_IF([enable_san_address], ["yes"], 5745 [ 5746 AM_ASAN_OPTIONS="exitcode=88:strict_string_checks=1:detect_stack_use_after_return=1" 5747 AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:check_initialization_order=1:strict_init_order=1:redzone=64" 5748 AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:max_free_fill_size=1024:detect_invalid_pointer_pairs=3" 5749 AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:handle_ioctl=1:halt_on_error=1" 5750 AS_VAR_IF([enable_san_upoison], ["yes"], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:allow_user_poisoning=1"]) 5751 AS_VAR_IF([enable_san_leak], ["yes"], 5752 [AS_VAR_IF([mhd_cv_cc_sanitizer_address_leak], ["yes"], 5753 [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=1"]) 5754 ], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=0"] 5755 ) 5756 ] 5757 ) 5758 AS_VAR_IF([enable_san_undef], [yes], 5759 [AM_UBSAN_OPTIONS="exitcode=87:print_stacktrace=1:halt_on_error=1"]) 5760 AS_VAR_IF([enable_san_leak], ["yes"], 5761 [AM_LSAN_OPTIONS="use_unaligned=1"] 5762 ) 5763 TESTS_ENVIRONMENT_ac='\ 5764 ASAN_OPTIONS="$(AM_ASAN_OPTIONS)" ; export ASAN_OPTIONS ; \ 5765 UBSAN_OPTIONS="$(AM_UBSAN_OPTIONS)" ; export UBSAN_OPTIONS ; \ 5766 LSAN_OPTIONS="$(AM_LSAN_OPTIONS)" ; export LSAN_OPTIONS ;' 5767 ] 5768 ) 5769 ] 5770 ) 5771 CFLAGS_ac="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS}" 5772 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 5773 ] 5774 ) 5775 5776 # fuzzing tests 5777 run_zzuf_tests="no" 5778 zzuf_socat_mandatory="no" 5779 AS_VAR_IF([use_heavy_tests],["yes"], 5780 [ 5781 AS_VAR_IF([enable_curl],["yes"], 5782 [ 5783 AC_PATH_PROG([ZZUF],[zzuf],[no]) 5784 AS_VAR_IF([ZZUF],["no"], 5785 [ 5786 run_zzuf_tests="no" 5787 run_zzuf_tests_MSG="no, zzuf tool not found" 5788 ], 5789 [ 5790 AC_PATH_PROG([SOCAT],[socat],[no]) 5791 AS_IF([test "x${ac_cv_func_accept4}" = "xyes" && test "x${enable_asserts}" = "xno"], 5792 [ 5793 zzuf_socat_mandatory="yes" 5794 AS_VAR_IF([SOCAT],["no"], 5795 [run_zzuf_tests_MSG="no, socat not found, but required for fuzzing tests on this platform without asserts enabled"], 5796 [ 5797 run_zzuf_tests="yes" 5798 run_zzuf_tests_MSG="yes, with zzuf and socat tools" 5799 ] 5800 ) 5801 ], 5802 [test -n "${enabled_sanitizers}"], 5803 [ 5804 zzuf_socat_mandatory="yes" 5805 AS_VAR_IF([SOCAT],["no"], 5806 [run_zzuf_tests_MSG="no, socat not found, but required for fuzzing tests when sanitizers enabled"], 5807 [ 5808 run_zzuf_tests="yes" 5809 run_zzuf_tests_MSG="yes, with zzuf and socat tools" 5810 ] 5811 ) 5812 ], 5813 [ 5814 run_zzuf_tests="yes" 5815 run_zzuf_tests_MSG="yes, with zzuf tool" 5816 ] 5817 ) 5818 ] 5819 ) 5820 ], 5821 [ 5822 run_zzuf_tests="no" 5823 run_zzuf_tests_MSG="no, tests with libcurl are not enabled" 5824 ] 5825 ) 5826 ], 5827 [ 5828 run_zzuf_tests="no" 5829 run_zzuf_tests_MSG="no, heavy tests are not enabled" 5830 ] 5831 ) 5832 AM_CONDITIONAL([RUN_ZZUF_TESTS],[test "x$run_zzuf_tests" = "xyes"]) 5833 AM_CONDITIONAL([FORCE_USE_ZZUF_SOCAT],[test "x$zzuf_socat_mandatory" = "xyes"]) 5834 5835 # Final flags that may interfere with autoconf detections 5836 AS_CASE([${enable_build_type}],[debug|debugger], 5837 [ # Debug build or build for walking with debugger 5838 CFLAGS="${user_CFLAGS}" 5839 MHD_CHECK_ADD_CC_CFLAGS([-Wextra-semi -Wextra-semi-stmt], [CFLAGS_ac]) 5840 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 5841 ] 5842 ) 5843 5844 AM_CONDITIONAL([USE_SANITIZERS], 5845 [test -n "$enabled_sanitizers" && test "x$mhd_cv_cc_sanitizer_works" = "xyes"]) 5846 AC_SUBST([AM_ASAN_OPTIONS]) 5847 AC_SUBST([AM_UBSAN_OPTIONS]) 5848 AC_SUBST([AM_LSAN_OPTIONS]) 5849 AC_SUBST([TESTS_ENVIRONMENT_ac]) 5850 5851 MHD_LIB_LDFLAGS="$MHD_LIB_LDFLAGS" 5852 5853 AC_SUBST([CPU_COUNT]) 5854 AC_SUBST([HEAVY_TESTS_NOTPARALLEL]) 5855 AM_SUBST_NOTMAKE([HEAVY_TESTS_NOTPARALLEL]) 5856 AC_SUBST(MHD_LIB_CPPFLAGS) 5857 AC_SUBST(MHD_LIB_CFLAGS) 5858 AC_SUBST(MHD_LIB_LDFLAGS) 5859 AC_SUBST(MHD_LIBDEPS) 5860 AC_SUBST(MHD_TLS_LIB_CPPFLAGS) 5861 AC_SUBST(MHD_TLS_LIB_CFLAGS) 5862 AC_SUBST(MHD_TLS_LIB_LDFLAGS) 5863 AC_SUBST(MHD_TLS_LIBDEPS) 5864 5865 # for pkg-config 5866 AC_SUBST([MHD_REQ_PRIVATE]) 5867 AC_SUBST([MHD_LIBDEPS_PKGCFG]) 5868 5869 # Restore flags as set by the user 5870 CFLAGS="${user_CFLAGS}" 5871 LDFLAGS="${user_LDFLAGS}" 5872 CPPFLAGS="${user_CPPFLAGS}" 5873 AC_SUBST([CFLAGS]) 5874 AC_SUBST([LDFLAGS]) 5875 AC_SUBST([CPPFLAGS]) 5876 AC_SUBST([LIBS]) 5877 5878 # Configure-defined flags 5879 AC_SUBST([CFLAGS_ac]) 5880 AC_SUBST([LDFLAGS_ac]) 5881 AC_SUBST([CPPFLAGS_ac]) 5882 5883 # Used for 'po' directory staff 5884 AC_SUBST([ac_configure_args]) 5885 AC_SUBST([EMPTY_VAR],[]) 5886 AC_SUBST([MHD_AUX_DIR]) 5887 AC_CONFIG_FILES([po/po-configure.ac]) 5888 AC_CONFIG_COMMANDS([po/Makefile.in], 5889 [ 5890 echo "Skipping update of po/Makefile.in" 5891 echo "Real update of po/Makefile.in for 'make dist' is performed by po-config.status" 5892 ] 5893 ) 5894 AC_CONFIG_COMMANDS([po-directories], 5895 [ 5896 echo "Skipping po-directories command." 5897 echo "Real po-directories command for 'make dist' is implemented in po-config.status" 5898 ] 5899 ) 5900 5901 # We define the paths here, because MinGW/GCC expands paths 5902 # passed through the command line ("-DDIR=..."). This would 5903 # lead to hard-coded paths ("C:\mingw\mingw\bin...") that do 5904 # not contain the actual installation. 5905 AC_DEFINE_DIR([MHD_PLUGIN_INSTALL_PREFIX], [libdir/libmicrohttpd], [tls plugins]) 5906 5907 AC_SUBST([ZZUF]) 5908 AC_SUBST([SOCAT]) 5909 5910 # should experimental code be compiled (code that may not yet compile)? 5911 AC_MSG_CHECKING(whether to compile experimental code) 5912 AC_ARG_ENABLE([experimental], 5913 [AS_HELP_STRING([--enable-experimental], [enable compiling experimental code])], 5914 [enable_experimental=${enableval}], 5915 [enable_experimental=no]) 5916 AC_MSG_RESULT($enable_experimental) 5917 AM_CONDITIONAL([HAVE_EXPERIMENTAL], [test "x$enable_experimental" = "xyes"]) 5918 5919 5920 AC_CONFIG_FILES([libmicrohttpd.pc 5921 w32/common/microhttpd_dll_res_vc.rc 5922 Makefile 5923 contrib/Makefile 5924 doc/Makefile 5925 doc/doxygen/libmicrohttpd.doxy 5926 doc/doxygen/Makefile 5927 doc/examples/Makefile 5928 m4/Makefile 5929 src/Makefile 5930 src/include/Makefile 5931 src/microhttpd/Makefile 5932 src/examples/Makefile 5933 src/tools/Makefile 5934 src/testcurl/Makefile 5935 src/testcurl/https/Makefile 5936 src/testzzuf/Makefile]) 5937 AC_OUTPUT 5938 5939 # Finally: summary 5940 # Format flags without extra spaces for visual beauty 5941 fin_CPPFLAGS="$user_CPPFLAGS" 5942 fin_CFLAGS="$user_CFLAGS" 5943 fin_LDFLAGS="$user_LDFLAGS" 5944 MHD_PREPEND_FLAG_TO_VAR([fin_CPPFLAGS],[$CPPFLAGS_ac]) 5945 MHD_PREPEND_FLAG_TO_VAR([fin_CFLAGS],[$CFLAGS_ac]) 5946 MHD_PREPEND_FLAG_TO_VAR([fin_LDFLAGS],[$LDFLAGS_ac]) 5947 fin_lib_CPPFLAGS="$user_CPPFLAGS" 5948 fin_lib_CFLAGS="$user_CFLAGS" 5949 fin_lib_LDFLAGS="$user_LDFLAGS" 5950 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CPPFLAGS],[$MHD_LIB_CPPFLAGS]) 5951 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CFLAGS],[$MHD_LIB_CFLAGS]) 5952 MHD_PREPEND_FLAG_TO_VAR([fin_lib_LDFLAGS],[$MHD_LIB_LDFLAGS]) 5953 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CPPFLAGS],[$CPPFLAGS_ac]) 5954 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CFLAGS],[$CFLAGS_ac]) 5955 MHD_PREPEND_FLAG_TO_VAR([fin_lib_LDFLAGS],[$LDFLAGS_ac]) 5956 AC_MSG_NOTICE([Toolchain settings: 5957 CC=$CC 5958 User/system/default flags: 5959 CPPFLAGS="$user_CPPFLAGS" 5960 CFLAGS= "$user_CFLAGS" 5961 LDFLAGS= "$user_LDFLAGS" 5962 Final set of the flags for tests and examples: 5963 CPPFLAGS="$fin_CPPFLAGS" 5964 CFLAGS= "$fin_CFLAGS" 5965 LDFLAGS= "$fin_LDFLAGS" 5966 Final set of the flags for ${PACKAGE_NAME} library: 5967 CPPFLAGS="$fin_lib_CPPFLAGS" 5968 CFLAGS= "$fin_lib_CFLAGS" 5969 LDFLAGS= "$fin_lib_LDFLAGS" 5970 ]) 5971 AS_UNSET([fin_CPPFLAGS]) 5972 AS_UNSET([fin_CFLAGS]) 5973 AS_UNSET([fin_LDFLAGS]) 5974 AS_UNSET([fin_lib_CPPFLAGS]) 5975 AS_UNSET([fin_lib_CFLAGS]) 5976 AS_UNSET([fin_lib_LDFLAGS]) 5977 5978 AS_VAR_IF([os_is_windows], ["yes"], 5979 [os_ver_msg=" 5980 Target W32 ver: ${mhd_w32_ver_msg}"], [AS_UNSET([[os_ver_msg]])]) 5981 5982 5983 AC_MSG_NOTICE([GNU libmicrohttpd ${PACKAGE_VERSION} Configuration Summary: 5984 Target directory: ${prefix} 5985 Cross-compiling: ${cross_compiling} 5986 Operating System: ${mhd_host_os}${os_ver_msg} 5987 Threading lib: ${USE_THREADS} 5988 Inter-thread comm: ${use_itc} 5989 Shutdown of listening socket triggers select: ${mhd_cv_host_shtdwn_trgr_select} 5990 poll support: ${enable_poll=no} 5991 epoll support: ${enable_epoll=no} 5992 sendfile used: ${found_sendfile} 5993 HTTPS support: ${MSG_HTTPS} 5994 Messages: ${enable_messages} 5995 Cookie parsing: ${enable_cookie} 5996 Postproc: ${enable_postprocessor} 5997 Basic auth.: ${enable_bauth} 5998 Digest auth.: ${enable_dauth} 5999 Digest auth. defaults: ${dauth_defs_MSG} 6000 MD5: ${enable_md5_MSG} 6001 SHA-256: ${enable_sha256_MSG} 6002 SHA-512/256: ${enable_sha512_256_MSG} 6003 HTTP "Upgrade": ${enable_httpupgrade} 6004 Compact code: ${enable_compact_code} (${compact_code_MSG}) 6005 Use thread names: ${enable_thread_names} 6006 Use debug asserts: ${use_asserts_MSG=no} 6007 Use sanitizers: ${enabled_sanitizers:=no} 6008 Build static lib: ${enable_static} 6009 Build shared lib: ${enable_shared} 6010 Build docs: ${enable_doc} 6011 Build examples: ${enable_examples} 6012 Build tools: ${enable_tools} 6013 Test with libcurl: ${MSG_CURL} 6014 Heavy tests: ${use_heavy_tests_MSG} 6015 Fuzzing tests: ${run_zzuf_tests_MSG=no} 6016 ]) 6017 6018 AS_IF([test "x$enable_https" = "xyes"], 6019 [AC_MSG_NOTICE([HTTPS subsystem configuration: 6020 License : LGPL version 2.1 or any later version 6021 ])], 6022 [AC_MSG_NOTICE([ 6023 License : LGPLv2.1+ or eCos 6024 ])]) 6025 6026 AS_IF([test "x$enable_bauth" != "xyes" || \ 6027 test "x$enable_dauth" != "xyes" || \ 6028 test "x${enable_md5}" = "xno" || \ 6029 test "x${enable_sha256}" = "xno" || \ 6030 test "x${enable_sha512_256}" != "xyes" || \ 6031 test "x${USE_THREADS}" = "xnone" || \ 6032 test "x$enable_httpupgrade" != "xyes" || \ 6033 test "x$enable_cookie" != "xyes" || \ 6034 test "x$enable_httpupgrade" != "xyes" || \ 6035 test "x$enable_postprocessor" != "xyes"], 6036 [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.])] 6037 ) 6038 AS_IF([test -n "${CONF_FINAL_WARNS}"],[AC_MSG_WARN([${CONF_FINAL_WARNS}])])