libmicrohttpd2

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

configure.ac (317522B)


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