libmicrohttpd2

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

configure.ac (327437B)


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