libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

configure.ac (294231B)


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