libmicrohttpd2

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

configure.ac (326733B)


      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__ ((access (read_only,NUM)))],[mhd_cv_cc_attr_access_read],
   5570   [
   5571     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5572 static __attribute__ ((access (read_only,1))) int
   5573 test_func(int *p) {return 0 == *p;}
   5574 
   5575 int main(void) {
   5576   int i = 0;
   5577   return test_func(&i) ? 0 : 5;
   5578 }
   5579           ]])
   5580       ],
   5581       [mhd_cv_cc_attr_access_read="yes"],[mhd_cv_cc_attr_access_read="no"]
   5582     )
   5583   ]
   5584 )
   5585 AS_VAR_IF([mhd_cv_cc_attr_access_read],["yes"],
   5586   [
   5587     AC_DEFINE([HAVE_ATTR_ACCESS_READ],[1],
   5588       [Define to '1' if your compiler supports __attribute__ ((access (read_only,NUM)))]
   5589     )
   5590   ]
   5591 )
   5592 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (write_only,NUM)))],[mhd_cv_cc_attr_access_write],
   5593   [
   5594     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5595 static __attribute__ ((access (write_only,1))) void
   5596 test_func(int *p) {*p = 0;}
   5597 
   5598 int main(void) {
   5599   int i = 1;
   5600   test_func(&i);
   5601   return i;
   5602 }
   5603           ]])
   5604       ],
   5605       [mhd_cv_cc_attr_access_write="yes"],[mhd_cv_cc_attr_access_write="no"]
   5606     )
   5607   ]
   5608 )
   5609 AS_VAR_IF([mhd_cv_cc_attr_access_write],["yes"],
   5610   [
   5611     AC_DEFINE([HAVE_ATTR_ACCESS_WRITE],[1],
   5612       [Define to '1' if your compiler supports __attribute__ ((access (write_only,NUM)))]
   5613     )
   5614   ]
   5615 )
   5616 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (read_write,NUM)))],[mhd_cv_cc_attr_access_read_write],
   5617   [
   5618     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5619 static __attribute__ ((access (read_write,1))) void
   5620 test_func(int *p) {*p = *p - 1;}
   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_read_write="yes"],[mhd_cv_cc_attr_access_read_write="no"]
   5630     )
   5631   ]
   5632 )
   5633 AS_VAR_IF([mhd_cv_cc_attr_access_read_write],["yes"],
   5634   [
   5635     AC_DEFINE([HAVE_ATTR_ACCESS_READ_WRITE],[1],
   5636       [Define to '1' if your compiler supports __attribute__ ((access (read_write,NUM)))]
   5637     )
   5638   ]
   5639 )
   5640 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (read_only,NUM,NUM_SIZE)))],[mhd_cv_cc_attr_access_read_size],
   5641   [
   5642     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5643 static __attribute__ ((access (read_only,2,1))) int
   5644 test_func(unsigned int num, int *arr) {return 2 == arr[num - 1];}
   5645 
   5646 int main(void) {
   5647   int arr[4] = {5, 4, 3, 2};
   5648   return test_func(4, arr) ? 0 : 5;
   5649 }
   5650           ]])
   5651       ],
   5652       [mhd_cv_cc_attr_access_read_size="yes"],[mhd_cv_cc_attr_access_read_size="no"]
   5653     )
   5654   ]
   5655 )
   5656 AS_VAR_IF([mhd_cv_cc_attr_access_read_size],["yes"],
   5657   [
   5658     AC_DEFINE([HAVE_ATTR_ACCESS_READ_SIZE],[1],
   5659       [Define to '1' if your compiler supports __attribute__ ((access (read_only,NUM,NUM_SIZE)))]
   5660     )
   5661   ]
   5662 )
   5663 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (write_only,NUM,NUM_SIZE)))],[mhd_cv_cc_attr_access_write_size],
   5664   [
   5665     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5666 static __attribute__ ((access (write_only,2,1))) void
   5667 test_func(unsigned int num, int *arr) {arr[num-1] = 0;}
   5668 
   5669 int main(void) {
   5670   int arr[4] = {5, 4, 3, 2};
   5671   test_func(4, arr);
   5672   return arr[3];
   5673 }
   5674           ]])
   5675       ],
   5676       [mhd_cv_cc_attr_access_write_size="yes"],[mhd_cv_cc_attr_access_write_size="no"]
   5677     )
   5678   ]
   5679 )
   5680 AS_VAR_IF([mhd_cv_cc_attr_access_write_size],["yes"],
   5681   [
   5682     AC_DEFINE([HAVE_ATTR_ACCESS_WRITE_SIZE],[1],
   5683       [Define to '1' if your compiler supports __attribute__ ((access (write_only,NUM,NUM_SIZE)))]
   5684     )
   5685   ]
   5686 )
   5687 AC_CACHE_CHECK([whether $CC supports __attribute__ ((access (read_write,NUM,NUM_SIZE)))],[mhd_cv_cc_attr_access_read_write_size],
   5688   [
   5689     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5690 static __attribute__ ((access (read_write,2,1))) void
   5691 test_func(unsigned int num, int *arr) {arr[num-1] = arr[1] - 4;}
   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_read_write_size="yes"],[mhd_cv_cc_attr_access_read_write_size="no"]
   5701     )
   5702   ]
   5703 )
   5704 AS_VAR_IF([mhd_cv_cc_attr_access_read_write_size],["yes"],
   5705   [
   5706     AC_DEFINE([HAVE_ATTR_ACCESS_READ_WRITE_SIZE],[1],
   5707       [Define to '1' if your compiler supports __attribute__ ((access (read_write,NUM,NUM_SIZE)))]
   5708     )
   5709   ]
   5710 )
   5711 AC_CACHE_CHECK([whether $CC supports __attribute__ ((fd_arg_read (NUM)))],[mhd_cv_cc_attr_fd_arg_read],
   5712   [
   5713     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5714 #ifndef _CRT_NONSTDC_NO_WARNINGS
   5715 #define _CRT_NONSTDC_NO_WARNINGS 1
   5716 #endif
   5717 #ifdef HAVE_SYS_TYPES_H
   5718 #include <sys/types.h>
   5719 #endif
   5720 #include <stdio.h>
   5721 #ifdef HAVE_IO_H
   5722 #include <io.h>
   5723 #endif
   5724 #ifdef HAVE_STDLIB_H
   5725 #include <stdlib.h>
   5726 #endif
   5727 #include <fcntl.h>
   5728 #ifdef HAVE_UNISTD_H
   5729 #include <unistd.h>
   5730 #endif
   5731 
   5732 static __attribute__ ((fd_arg_read (1))) int
   5733 test_func(int fd)
   5734 {
   5735   int data_in;
   5736   int read_size;
   5737   read_size = (int) read(fd, &data_in, sizeof(data_in));
   5738   if (read_size < (int) sizeof(data_in)) return 4;
   5739   return data_in;
   5740 }
   5741 
   5742 int main(void) {
   5743   int fd = open("test.txt", O_RDONLY);
   5744   int res = test_func(fd);
   5745   close (fd);
   5746   return res;
   5747 }
   5748           ]])
   5749       ],
   5750       [mhd_cv_cc_attr_fd_arg_read="yes"],[mhd_cv_cc_attr_fd_arg_read="no"]
   5751     )
   5752   ]
   5753 )
   5754 AS_VAR_IF([mhd_cv_cc_attr_fd_arg_read],["yes"],
   5755   [
   5756     AC_DEFINE([HAVE_ATTR_FD_ARG_READ],[1],
   5757       [Define to '1' if your compiler supports __attribute__ ((fd_arg_read (NUM)))]
   5758     )
   5759   ]
   5760 )
   5761 AC_CACHE_CHECK([whether $CC supports __attribute__ ((null_terminated_string_arg (NUM)))],[mhd_cv_cc_attr_null_term_str],
   5762   [
   5763     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5764 static __attribute__ ((null_terminated_string_arg (1))) int
   5765 test_func(const char *str) {return (0 == str[0]) ? 5 : 0;}
   5766 
   5767 int main(void) {
   5768   return test_func("test");
   5769 }
   5770           ]])
   5771       ],
   5772       [mhd_cv_cc_attr_null_term_str="yes"],[mhd_cv_cc_attr_null_term_str="no"]
   5773     )
   5774   ]
   5775 )
   5776 AS_VAR_IF([mhd_cv_cc_attr_null_term_str],["yes"],
   5777   [
   5778     AC_DEFINE([HAVE_ATTR_NULL_TERM_STR],[1],
   5779       [Define to '1' if your compiler supports __attribute__ ((null_terminated_string_arg (NUM)))]
   5780     )
   5781   ]
   5782 )
   5783 AC_CACHE_CHECK([whether $CC supports __attribute__((enum_extensibility (closed)))],[mhd_cv_cc_attr_enum_extns_closed],
   5784   [
   5785     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5786 enum __attribute__((enum_extensibility (closed))) Test_Enum
   5787 {Val_A = 0, Val_B = 3};
   5788 
   5789 int main(void)
   5790 {
   5791   enum Test_Enum var = Val_A;
   5792   return (var != Val_B) ? 0 : 3;
   5793 }
   5794           ]])
   5795       ],
   5796       [mhd_cv_cc_attr_enum_extns_closed="yes"],[mhd_cv_cc_attr_enum_extns_closed="no"]
   5797     )
   5798   ]
   5799 )
   5800 AS_VAR_IF([mhd_cv_cc_attr_enum_extns_closed],["yes"],
   5801   [
   5802     AC_DEFINE([HAVE_ATTR_ENUM_EXTNS_CLOSED],[1],
   5803       [Define to '1' if your compiler supports __attribute__((enum_extensibility (closed)))]
   5804     )
   5805   ]
   5806 )
   5807 AC_CACHE_CHECK([whether $CC supports __attribute__((flag_enum))],[mhd_cv_cc_attr_flag_enum],
   5808   [
   5809     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5810 #ifdef HAVE_ATTR_ENUM_EXTNS_CLOSED
   5811 #define ATTR_EXTNS_CLOSED_IF_SUPPORTED __attribute__((enum_extensibility (closed)))
   5812 #else
   5813 #define ATTR_EXTNS_CLOSED_IF_SUPPORTED /* empty */
   5814 #endif
   5815 enum ATTR_EXTNS_CLOSED_IF_SUPPORTED __attribute__((flag_enum)) Test_Enum
   5816 {Flag_A = 1 << 0, Flag_B = 1 << 1, Flag_C = 1 << 2, Flag_D = 1 << 3};
   5817 
   5818 int main(void)
   5819 {
   5820   enum Test_Enum var = Flag_A;
   5821   var |= Flag_C;
   5822   var = var | Flag_D | Flag_A;
   5823   return (var != Flag_B) ? 0 : 3;
   5824 }
   5825           ]])
   5826       ],
   5827       [mhd_cv_cc_attr_flag_enum="yes"],[mhd_cv_cc_attr_flag_enum="no"]
   5828     )
   5829   ]
   5830 )
   5831 AS_VAR_IF([mhd_cv_cc_attr_flag_enum],["yes"],
   5832   [
   5833     AC_DEFINE([HAVE_ATTR_FLAG_ENUM],[1],
   5834       [Define to '1' if your compiler supports __attribute__((flag_enum))]
   5835     )
   5836   ]
   5837 )
   5838 ac_c_werror_flag=""
   5839 AC_CACHE_CHECK([[whether $CC supports array[static N] with fixed N as a function parameter]],[mhd_cv_cc_func_param_arr_static_fixed],
   5840   [
   5841     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5842 static int
   5843 test_func(int arr[static 4]) { return arr[2] - 4; }
   5844 
   5845 int main(void) {
   5846   int arr[4] = {5, 4, 3, 2};
   5847   return test_func(arr);
   5848 }
   5849           ]])
   5850       ],
   5851       [mhd_cv_cc_func_param_arr_static_fixed="yes"],[mhd_cv_cc_func_param_arr_static_fixed="no"]
   5852     )
   5853   ]
   5854 )
   5855 AS_VAR_IF([mhd_cv_cc_func_param_arr_static_fixed],["yes"],
   5856   [
   5857     AC_DEFINE([HAVE_FUNC_PARAM_ARR_STATIC_FIXED],[1],
   5858       [Define to '1' if your compiler supports 'array[static N]' with fixed N as function parameter]
   5859     )
   5860   ]
   5861 )
   5862 AC_CACHE_CHECK([[whether $CC supports array[static N] with variable N as a function parameter]],[mhd_cv_cc_func_param_arr_static_var],
   5863   [
   5864     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
   5865 static int
   5866 test_func(int num, int arr[static num]) { return arr[num-2] - 4; }
   5867 
   5868 int main(void) {
   5869   int arr[4] = {5, 4, 3, 2};
   5870   return test_func(4, arr);
   5871 }
   5872           ]])
   5873       ],
   5874       [mhd_cv_cc_func_param_arr_static_var="yes"],[mhd_cv_cc_func_param_arr_static_var="no"]
   5875     )
   5876   ]
   5877 )
   5878 AS_VAR_IF([mhd_cv_cc_func_param_arr_static_var],["yes"],
   5879   [
   5880     AC_DEFINE([HAVE_FUNC_PARAM_ARR_STATIC_VAR],[1],
   5881       [Define to '1' if your compiler supports 'array[static N]' with variable N as a function parameter]
   5882     )
   5883   ]
   5884 )
   5885 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   5886 
   5887 # libcurl (required for testing)
   5888 AC_ARG_ENABLE([curl],
   5889   [AS_HELP_STRING([--disable-curl],[disable cURL based testcases])],
   5890   [enable_curl=${enableval}])
   5891 curl=0
   5892 AS_IF([test "$enable_curl" != "no"],
   5893  [LIBCURL_CHECK_CONFIG([yes],[7.16.4],[enable_curl=yes],
   5894     [
   5895       AS_IF([test "x$enable_curl" = "xyes"],
   5896        [AC_MSG_WARN([[cURL-based tests cannot be enabled because libcurl is missing]])])
   5897       enable_curl=no
   5898     ])
   5899 ])
   5900 AM_CONDITIONAL([RUN_LIBCURL_TESTS], [test "x$enable_curl" = "xyes"])
   5901 AS_IF([test "x$enable_curl" = "xyes"],
   5902   [MSG_CURL="yes"],
   5903   [MSG_CURL="no, many unit tests will not run"]
   5904 )
   5905 
   5906 MHD_CHECK_FUNC([magic_open],
   5907   [[
   5908 #include <magic.h>
   5909   ]],
   5910   [[
   5911     char var_data[256];
   5912     const char *var_mime;
   5913     magic_t var_magic = magic_open (MAGIC_MIME_TYPE);
   5914     (void)magic_load (var_magic, "filename");
   5915     var_data[0] = 0;
   5916     var_mime = magic_buffer (var_magic, var_data, 1);
   5917     i][f (! var_mime)
   5918       return 1;
   5919     magic_close (var_magic);
   5920   ]],
   5921   [AC_DEFINE([MHD_HAVE_LIBMAGIC], [1], [Define to 1 if you have suitable libmagic.])],
   5922   [],
   5923   [-lmagic]
   5924 )
   5925 AM_CONDITIONAL([MHD_HAVE_LIBMAGIC], [[test "x$mhd_cv_have_func_magic_open" = "xyes"]])
   5926 
   5927 # large file support (> 4 GB)
   5928 MHD_CHECK_FUNC([lseek64],
   5929   [[
   5930 #ifndef _LARGEFILE64_SOURCE
   5931 #  define _LARGEFILE64_SOURCE 1
   5932 #endif
   5933 #if defined(HAVE_SYS_TYPES_H)
   5934 #  include <sys/types.h>
   5935 #endif
   5936 #include <stdlib.h>
   5937 #ifdef HAVE_UNISTD_H
   5938 #  include <unistd.h>
   5939 #endif
   5940   ]],
   5941   [[
   5942   i][f (((off64_t) -1) == lseek64(0, (off64_t) 0, SEEK_SET))
   5943     return 3;
   5944   ]]
   5945 )
   5946 MHD_CHECK_FUNC([pread64],
   5947   [[
   5948 #ifndef _LARGEFILE64_SOURCE
   5949 #  define _LARGEFILE64_SOURCE 1
   5950 #endif
   5951 #if defined(HAVE_SYS_TYPES_H)
   5952 #  include <sys/types.h>
   5953 #endif
   5954 #include <stdlib.h>
   5955 #ifdef HAVE_UNISTD_H
   5956 #  include <unistd.h>
   5957 #endif
   5958   ]],
   5959   [[
   5960   char buf[5];
   5961   i][f (0 > pread64(0, (void *) buf, 1, (off64_t) 0))
   5962     return 3;
   5963   ]]
   5964 )
   5965 MHD_CHECK_FUNC([pread],
   5966   [[
   5967 #if defined(HAVE_SYS_TYPES_H)
   5968 #  include <sys/types.h>
   5969 #endif
   5970 #include <stdlib.h>
   5971 #ifdef HAVE_UNISTD_H
   5972 #  include <unistd.h>
   5973 #endif
   5974   ]],
   5975   [[
   5976   char buf[5];
   5977   i][f (0 > pread(0, (void *) buf, 1, 0))
   5978     return 3;
   5979   ]]
   5980 )
   5981 
   5982 AS_VAR_IF([have_poll],["yes"],[MHD_CHECK_POLL_QUIRKS()])
   5983 
   5984 # check for various sendfile functions
   5985 AC_ARG_ENABLE([sendfile],
   5986    [AS_HELP_STRING([--disable-sendfile],
   5987                [disable usage of sendfile() for HTTP connections [auto]])],
   5988    [],
   5989    [enable_sendfile="auto"])
   5990 AS_CASE([$enable_sendfile],
   5991   [[auto | yes]],[[found_sendfile="no"]],
   5992   [[no]],[[found_sendfile="disabled"]],
   5993   [AC_MSG_ERROR([[unknown value specified: --enable-sendfile=$enable_sendfile]])]
   5994 )
   5995 AS_VAR_IF([[found_sendfile]], [["no"]],
   5996   [
   5997     AC_MSG_CHECKING([[for Linux-style sendfile(2)]])
   5998     AC_LINK_IFELSE(
   5999       [AC_LANG_PROGRAM(
   6000         [[
   6001 #include <sys/sendfile.h>
   6002 
   6003 static void empty_func(void)
   6004 {
   6005 /* Check for declaration */
   6006 #ifndef sendfile
   6007   (void)sendfile;
   6008 #endif
   6009 }
   6010         ]],
   6011         [[
   6012           int fd1=0, fd2=2;
   6013           off_t o = 0;
   6014           size_t s = 5;
   6015           ssize_t r;
   6016           r = sendfile (fd1, fd2, &o, s);
   6017           if (r)
   6018             empty_func();
   6019         ]]
   6020        )
   6021       ],
   6022       [
   6023         AC_DEFINE([HAVE_LINUX_SENDFILE], [1], [Define to 1 if you have linux-style sendfile(2).])
   6024         found_sendfile="yes, Linux-style"
   6025         AC_MSG_RESULT([[yes]])
   6026         MHD_CHECK_FUNC([sendfile64],
   6027           [[
   6028 #ifndef _LARGEFILE64_SOURCE
   6029 #  define _LARGEFILE64_SOURCE 1
   6030 #endif
   6031 #include <sys/sendfile.h>
   6032           ]],
   6033           [[
   6034   off64_t f_offset = (off64_t) 0;
   6035   if (0 > sendfile64 (0, 1, &f_offset, 1))
   6036     return 3;
   6037           ]]
   6038         )
   6039       ],
   6040       [AC_MSG_RESULT([[no]])
   6041       ]
   6042     )
   6043   ]
   6044 )
   6045 AS_VAR_IF([[found_sendfile]], [["no"]],
   6046   [
   6047    AC_MSG_CHECKING([[for FreeBSD-style sendfile(2)]])
   6048    AC_LINK_IFELSE(
   6049      [AC_LANG_PROGRAM(
   6050        [[
   6051 #ifdef HAVE_SYS_TYPES_H
   6052 #include <sys/types.h>
   6053 #endif
   6054 #ifdef HAVE_UNISTD_H
   6055 #include <unistd.h>
   6056 #endif
   6057 #ifdef HAVE_SYS_SOCKET_H
   6058 #include <sys/socket.h>
   6059 #endif
   6060 #include <sys/uio.h>
   6061 
   6062 static void empty_func(void)
   6063 {
   6064 /* Check for declaration */
   6065 #ifndef sendfile
   6066   (void)sendfile;
   6067 #endif
   6068 }
   6069        ]],
   6070        [[
   6071          int fd1=0, fd2=1;
   6072          off_t o = 0;
   6073          size_t s = 5;
   6074          off_t r1;
   6075          int r2;
   6076          r2 = sendfile (fd1, fd2, o, s, (struct sf_hdtr *)0, &r1, 0);
   6077          if (r2)
   6078            empty_func();
   6079        ]]
   6080       )
   6081      ],
   6082      [
   6083        AC_DEFINE([HAVE_FREEBSD_SENDFILE], [1], [Define to 1 if you have FreeBSD-style sendfile(2).])
   6084        found_sendfile="yes, FreeBSD-style"
   6085        AC_MSG_RESULT([[yes]])
   6086      ],
   6087      [AC_MSG_RESULT([[no]])
   6088      ]
   6089    )
   6090   ]
   6091 )
   6092 AS_VAR_IF([[found_sendfile]], [["no"]],
   6093   [
   6094    AC_MSG_CHECKING([[for Darwin-style sendfile(2)]])
   6095    AC_LINK_IFELSE(
   6096      [AC_LANG_PROGRAM(
   6097        [[
   6098 #ifdef HAVE_SYS_TYPES_H
   6099 #include <sys/types.h>
   6100 #endif
   6101 #ifdef HAVE_UNISTD_H
   6102 #include <unistd.h>
   6103 #endif
   6104 #ifdef HAVE_SYS_SOCKET_H
   6105 #include <sys/socket.h>
   6106 #endif
   6107 #include <sys/uio.h>
   6108 
   6109 static void empty_func(void)
   6110 {
   6111 /* Check for declaration */
   6112 #ifndef sendfile
   6113   (void)sendfile;
   6114 #endif
   6115 }
   6116        ]],
   6117        [[
   6118          int fd=0, s=1;
   6119          off_t o = 0;
   6120          off_t l = 5;
   6121          int r;
   6122          r = sendfile (fd, s, o, &l, (struct sf_hdtr *)0, 0);
   6123          if (r)
   6124            empty_func();
   6125        ]]
   6126       )
   6127      ],
   6128      [
   6129        AC_DEFINE([HAVE_DARWIN_SENDFILE], [1], [Define to 1 if you have Darwin-style sendfile(2).])
   6130        found_sendfile="yes, Darwin-style"
   6131        AC_MSG_RESULT([[yes]])
   6132      ],
   6133      [AC_MSG_RESULT([[no]])
   6134      ]
   6135    )
   6136   ]
   6137 )
   6138 
   6139 AS_VAR_IF([[found_sendfile]], [["no"]],
   6140   [
   6141    AC_MSG_CHECKING([[for old Solaris-style sendfile(3)]])
   6142    SAVE_LIBS="$LIBS"
   6143    LIBS="-lsendfile $LIBS"
   6144    AC_LINK_IFELSE(
   6145      [AC_LANG_PROGRAM(
   6146        [[
   6147 #ifdef HAVE_SYS_TYPES_H
   6148 #include <sys/types.h>
   6149 #endif
   6150 #ifdef HAVE_UNISTD_H
   6151 #include <unistd.h>
   6152 #endif
   6153 #ifdef HAVE_SYS_SOCKET_H
   6154 #include <sys/socket.h>
   6155 #endif
   6156 #include <sys/sendfile.h>
   6157 
   6158 static void empty_func(void)
   6159 {
   6160 /* Check for declaration */
   6161 #ifndef sendfile
   6162   (void)sendfile;
   6163 #endif
   6164 }
   6165        ]],
   6166        [[
   6167          int fd1=0, fd2=1;
   6168          off_t o = 0;
   6169          size_t l = 5;
   6170          ssize_t r;
   6171          r = sendfile (fd1, fd2, &o, l);
   6172          if (r)
   6173            empty_func();
   6174        ]]
   6175       )
   6176      ],
   6177      [
   6178        # Solaris uses the same format as GNU/Linux. Old versions need libsendfile.
   6179        AC_DEFINE([HAVE_LINUX_SENDFILE], [1], [Define to 1 if you have linux-style sendfile(2).])
   6180        found_sendfile="yes, Solaris-style"
   6181        MHD_LIBDEPS="-lsendfile $MHD_LIBDEPS"
   6182        MHD_LIBDEPS_PKGCFG="-lsendfile $MHD_LIBDEPS_PKGCFG"
   6183        AC_MSG_RESULT([[yes]])
   6184        MHD_CHECK_FUNC([sendfile64],
   6185          [[
   6186 #ifdef HAVE_SYS_TYPES_H
   6187 #include <sys/types.h>
   6188 #endif
   6189 #ifdef HAVE_UNISTD_H
   6190 #include <unistd.h>
   6191 #endif
   6192 #ifdef HAVE_SYS_SOCKET_H
   6193 #include <sys/socket.h>
   6194 #endif
   6195 #include <sys/sendfile.h>
   6196          ]],
   6197          [[
   6198   off64_t f_offset = (off64_t) 0;
   6199 #ifndef sendfile64
   6200   (void)sendfile64;
   6201 #endif
   6202   if (0 > sendfile64 (0, 1, &f_offset, 1))
   6203     return 3;
   6204          ]]
   6205        )
   6206      ],
   6207      [AC_MSG_RESULT([[no]])
   6208      ]
   6209    )
   6210    LIBS="$SAVE_LIBS"
   6211   ]
   6212 )
   6213 AS_IF([[test "x$found_sendfile" = "xno" && test "x$enable_sendfile" = "xyes"]],
   6214   [AC_MSG_ERROR([[sendfile() usage was requested by configure parameter, but no usable sendfile() function is detected]])]
   6215 )
   6216 
   6217 # optional: disable log and HTTP automatic messages
   6218 AC_ARG_ENABLE([messages],
   6219   [AS_HELP_STRING([--disable-messages],
   6220       [disable log messages and text bodies for ]
   6221       [automatic HTTP responses (to reduce the binary size)]
   6222     )
   6223   ],
   6224   [],[enable_messages="yes"]
   6225 )
   6226 
   6227 AC_MSG_CHECKING([[whether to support internal logging functionality and build messages for log]])
   6228 AC_ARG_ENABLE([log-messages],
   6229   [AS_HELP_STRING([--disable-log-messages],
   6230       [disable logger functionality and exclude log mesages from binary]
   6231     )
   6232   ],
   6233   [],[enable_log_messages="$enable_messages"]
   6234 )
   6235 AS_VAR_IF([enable_log_messages],["yes"],
   6236   [AC_DEFINE([MHD_SUPPORT_LOG_FUNCTIONALITY],[1],[Define to '1' to enable internal logging and log messages.])],
   6237   [enable_log_messages="no"]
   6238 )
   6239 AC_MSG_RESULT([[$enable_log_messages]])
   6240 AM_CONDITIONAL([MHD_SUPPORT_LOG_FUNCTIONALITY], [test "x$enable_log_messages" != "xno"])
   6241 
   6242 AC_MSG_CHECKING([[whether to build text bodies for automatic HTTP response messages]])
   6243 AC_ARG_ENABLE([http-messages],
   6244   [AS_HELP_STRING([--disable-http-messages],
   6245       [use empty bodies for automatic HTTP responses (less verbose for clients)]
   6246     )
   6247   ],
   6248   [],[enable_http_messages="$enable_messages"]
   6249 )
   6250 AS_VAR_IF([enable_http_messages],["yes"],
   6251   [AC_DEFINE([MHD_ENABLE_AUTO_MESSAGES_BODIES],[1],[Define to '1' to enable verbose text bodies for automatic HTTP replies.])],
   6252   [enable_http_messages="no"]
   6253 )
   6254 AC_MSG_RESULT([[$enable_http_messages]])
   6255 AM_CONDITIONAL([MHD_ENABLE_AUTO_MESSAGES_BODIES], [test "x$enable_http_messages" != "xno"])
   6256 
   6257 
   6258 # optional: have postprocessor?
   6259 AC_MSG_CHECKING([[whether to enable POST parser]])
   6260 AC_ARG_ENABLE([postparser],
   6261    [AS_HELP_STRING([--disable-postparser],
   6262                [disable MHD POST parser functionality])],
   6263    [enable_postparser=${enableval}],
   6264    [enable_postparser=yes])
   6265 AS_IF([[test "x$enable_postparser" != "xno"]],
   6266   [ enable_postparser=yes
   6267     AC_DEFINE([MHD_SUPPORT_POST_PARSER],[1],[Define to 1 if libmicrohttpd is compiled with POST parser support.]) ])
   6268 AM_CONDITIONAL([MHD_SUPPORT_POST_PARSER], [test "x$enable_postparser" != "xno"])
   6269 AC_MSG_RESULT([[$enable_postparser]])
   6270 
   6271 have_gnutls=no
   6272 have_gnutls_pkgcfg=no
   6273 have_openssl=no
   6274 have_openssl_pkgcfg=no
   6275 have_mbedtls=no
   6276 have_mbedtls_pkgcfg=no
   6277 multiple_tls="no"
   6278 AS_UNSET([MHD_TLS_LIB_CPPFLAGS])
   6279 AS_UNSET([MHD_TLS_LIB_LDFLAGS])
   6280 AS_UNSET([MHD_TLS_LIBDEPS])
   6281 MSG_TLS_BACKENDS="none"
   6282 
   6283 AC_ARG_ENABLE([http2],
   6284    [AS_HELP_STRING([--disable-http2], [disable HTTP/2 support])],
   6285    [
   6286      AS_CASE([${enableval}],
   6287        [yes],[:],
   6288        [no],[:],
   6289        [AC_MSG_ERROR([wrong parameter value --enable-http2=${enableval}])]
   6290      )
   6291    ],
   6292    [enable_http2="yes"]
   6293 )
   6294 AS_VAR_IF([enable_http2],["yes"],
   6295   [AC_DEFINE([MHD_SUPPORT_HTTP2],[1],[Define to '1' to enable support for HTTP/2 protocol])]
   6296 )
   6297 AM_CONDITIONAL([MHD_SUPPORT_HTTP2], [test "x$enable_http2" = "xyes"])
   6298 
   6299 # optional: HTTPS support.  Enabled if GnuTLS is available.
   6300 PKG_PROG_PKG_CONFIG
   6301 AS_UNSET([GNUTLS_MOD_VERSION])
   6302 AS_UNSET([OPENSSL_MOD_VERSION])
   6303 AS_UNSET([MBEDTLS_MOD_VERSION])
   6304 AC_ARG_ENABLE([https],
   6305    [AS_HELP_STRING([--enable-https],
   6306                [enable HTTPS support (yes, no, auto)[auto]])],
   6307    [enable_https=${enableval}])
   6308 AS_IF([test "x$enable_https" != "xno"],
   6309   [
   6310     have_gnutls_pkgcfg=no
   6311     AC_MSG_CHECKING([[how to find GnuTLS library]])
   6312     AC_ARG_WITH([[gnutls]],
   6313       [AS_HELP_STRING([[--with-gnutls[=PRFX]]],
   6314           [use GnuTLS for HTTPS support, optional PRFX overrides pkg-config data for GnuTLS headers (PRFX/include) and libs (PRFX/lib)])],
   6315       [
   6316         AS_CASE([$with_gnutls],
   6317           [no],[
   6318             have_gnutls="no"
   6319             AS_UNSET([GNUTLS_CPPFLAGS])
   6320             AS_UNSET([GNUTLS_CFLAGS])
   6321             AS_UNSET([GNUTLS_LDFLAGS])
   6322             AS_UNSET([GNUTLS_LIBS])
   6323             AC_MSG_RESULT([[GnuTLS disabled]])
   6324           ],
   6325           [yes],[
   6326             AC_MSG_RESULT([[automatically, forced]])
   6327           ],
   6328           [
   6329             AC_MSG_RESULT([[-I$with_gnutls/include -L$with_gnutls/lib -lgnutls]])
   6330             LDFLAGS="${LDFLAGS_ac} -L$with_gnutls/lib ${user_LDFLAGS}"
   6331             CPPFLAGS="${CPPFLAGS_ac} -I$with_gnutls/include ${user_CPPFLAGS}"
   6332             have_gnutls_pkgcfg=no
   6333             # A simple check for the working header and the library
   6334             MHD_CHECK_FUNC([gnutls_check_version],
   6335               [[
   6336 ]AC_INCLUDES_DEFAULT[
   6337 #include <gnutls/gnutls.h>
   6338               ]],
   6339               [
   6340                if(!gnutls_check_version("3.0.0"))
   6341                  return 3;
   6342               ],
   6343               [
   6344                 have_gnutls=yes
   6345                 GNUTLS_CPPFLAGS="-I$with_gnutls/include"
   6346                 AS_UNSET([GNUTLS_CFLAGS])
   6347                 GNUTLS_LDFLAGS="-L$with_gnutls/lib"
   6348                 GNUTLS_LIBS="-lgnutls"
   6349               ],
   6350               [AC_MSG_ERROR([cannot find usable libgnutls at specified prefix $with_gnutls])],
   6351               [-lgnutls]
   6352             )
   6353             CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   6354             CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   6355             LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   6356           ])
   6357        ],
   6358        [AC_MSG_RESULT([[automatically]])]
   6359     )
   6360 
   6361     AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"],
   6362       [
   6363         PKG_CHECK_MODULES([GNUTLS], [[gnutls]],
   6364           [
   6365             CPPFLAGS="${CPPFLAGS_ac} $GNUTLS_CFLAGS ${user_CPPFLAGS}"
   6366             # A simple check for the working header and the library
   6367             MHD_CHECK_FUNC([gnutls_check_version],
   6368               [[
   6369 ]AC_INCLUDES_DEFAULT[
   6370 #include <gnutls/gnutls.h>
   6371               ]],
   6372               [
   6373                if(!gnutls_check_version("3.0.0"))
   6374                  return 3;
   6375               ],
   6376               [
   6377                 have_gnutls="yes"
   6378                 have_gnutls_pkgcfg="yes"
   6379                 # GNUTLS_CFLAGS is actually CPPFLAGS
   6380                 GNUTLS_CPPFLAGS="$GNUTLS_CFLAGS"
   6381                 AS_UNSET([GNUTLS_CFLAGS])
   6382                 # GNUTLS_LIBS is a combination of LDFLAGS and LIBS
   6383                 AS_UNSET([GNUTLS_LDFLAGS])
   6384               ],
   6385               [
   6386                 AS_VAR_IF([with_gnutls],["yes"],
   6387                   [AC_MSG_ERROR([cannot find usable libgnutls])]
   6388                 )
   6389                 AC_MSG_WARN([pkg-config reports that GnuTLS is present, but GnuTLS cannot be used])
   6390                 AS_UNSET([GNUTLS_CPPFLAGS])
   6391                 AS_UNSET([GNUTLS_CFLAGS])
   6392                 AS_UNSET([GNUTLS_LDFLAGS])
   6393                 AS_UNSET([GNUTLS_LIBS])
   6394               ],
   6395               [$GNUTLS_LIBS]
   6396             )
   6397           ],
   6398           [
   6399             # check for GnuTLS at default paths
   6400             have_gnutls_pkgcfg="no"
   6401             # A simple check for the working header and the library
   6402             MHD_CHECK_FUNC([gnutls_check_version],
   6403               [[
   6404 ]AC_INCLUDES_DEFAULT[
   6405 #include <gnutls/gnutls.h>
   6406               ]],
   6407               [
   6408                if(!gnutls_check_version("3.0.0"))
   6409                  return 3;
   6410               ],
   6411               [
   6412                 have_gnutls=yes
   6413                 AS_UNSET([GNUTLS_CPPFLAGS])
   6414                 AS_UNSET([GNUTLS_CFLAGS])
   6415                 AS_UNSET([GNUTLS_LDFLAGS])
   6416                 GNUTLS_LIBS="-lgnutls"
   6417               ],
   6418               [
   6419                 AS_VAR_IF([with_gnutls],["yes"],
   6420                   [AC_MSG_ERROR([cannot find usable libgnutls])]
   6421                 )
   6422                 AS_UNSET([GNUTLS_CPPFLAGS])
   6423                 AS_UNSET([GNUTLS_CFLAGS])
   6424                 AS_UNSET([GNUTLS_LDFLAGS])
   6425                 AS_UNSET([GNUTLS_LIBS])
   6426               ],
   6427               [-lgnutls]
   6428             )
   6429           ]
   6430         )
   6431       ]
   6432     )
   6433     AS_VAR_IF([have_gnutls],["yes"],
   6434       [
   6435         AC_CACHE_CHECK([[whether GnuTLS is modern enough]], [mhd_cv_gnutls_ver_ok],
   6436           [
   6437             CPPFLAGS="${CPPFLAGS_ac} ${GNUTLS_CPPFLAGS} ${user_CPPFLAGS}"
   6438             AC_COMPILE_IFELSE(
   6439               [
   6440                 AC_LANG_PROGRAM(
   6441                   [[
   6442 ]AC_INCLUDES_DEFAULT[
   6443 #include <gnutls/gnutls.h>
   6444                   ]],
   6445                   [[
   6446 #if !defined(GNUTLS_VERSION_NUMBER) || GNUTLS_VERSION_NUMBER+0 <= 0x020c14
   6447 #error Too old version of GnuTLS that requires libgcript initialisation
   6448 fail test here %%%@<:@-1@:>@
   6449 #endif
   6450                   ]]
   6451                 )
   6452               ],
   6453               [[mhd_cv_gnutls_ver_ok="yes"]], [[mhd_cv_gnutls_ver_ok="no"]]
   6454             )
   6455             CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   6456           ]
   6457         )
   6458         AS_VAR_IF([mhd_cv_gnutls_ver_ok],["yes"],[:],
   6459           [
   6460             have_gnutls="no"
   6461             AS_VAR_IF([with_gnutls],["yes"],
   6462               [AC_MSG_ERROR([cannot find usable libgnutls])]
   6463             )
   6464           ]
   6465         )
   6466       ]
   6467     )
   6468 
   6469     AS_VAR_IF([have_gnutls],["yes"],
   6470       [
   6471         AS_VAR_IF([have_gnutls_pkgcfg],["yes"],
   6472           [
   6473             MHD_PKG_CONF_MODULE_VERSION([GNUTLS],[],[],[GNUTLS_MOD_VERSION='0'])
   6474           ],[GNUTLS_MOD_VERSION='0']
   6475         )
   6476         CPPFLAGS="${CPPFLAGS_ac} ${GNUTLS_CPPFLAGS} ${user_CPPFLAGS}"
   6477         LDFLAGS="${LDFLAGS_ac} ${GNUTLS_LDFLAGS} ${user_LDFLAGS}"
   6478 
   6479         # Check only for modern (>= 3.4.0) form of gnutls_handshake_set_hook_function()
   6480         MHD_CHECK_FUNC([gnutls_handshake_set_hook_function],
   6481           [[
   6482 #if defined(HAVE_STDDEF_H)
   6483 #  include <stddef.h> /* NULL */
   6484 #elif defined(HAVE_STDLIB_H)
   6485 #  include <stdlib.h> /* should provide NULL */
   6486 #else
   6487 #  include <stdio.h> /* should provide NULL */
   6488 #endif
   6489 #include <gnutls/gnutls.h>
   6490 
   6491 int
   6492 test_hook_f (gnutls_session_t session,
   6493              unsigned int htype,
   6494              unsigned when,
   6495              unsigned int incoming,
   6496              const gnutls_datum_t *msg);
   6497 
   6498 int
   6499 test_hook_f (gnutls_session_t session,
   6500              unsigned int htype,
   6501              unsigned when,
   6502              unsigned int incoming,
   6503              const gnutls_datum_t *msg)
   6504 {
   6505   (void) session; (void) htype; (void) when; (void) incoming;
   6506   return (NULL == msg) ? 0 : 1;
   6507 }
   6508 
   6509               ]],
   6510               [[
   6511   gnutls_handshake_hook_func hook = &test_hook_f;
   6512   gnutls_session_t sess = (gnutls_session_t) NULL;
   6513   gnutls_datum_t dat;
   6514 
   6515   dat.data = (unsigned char *) NULL;
   6516   dat.size = 0u;
   6517 
   6518   /* Match only modern (>= 3.4.0) form of gnutls_handshake_set_hook_function() */
   6519   gnutls_handshake_set_hook_function (sess, GNUTLS_HANDSHAKE_CLIENT_HELLO,
   6520                                       GNUTLS_HOOK_PRE, hook);
   6521   /* Strong check f][or a real typedef match. */
   6522   i][f (! hook (sess, GNUTLS_HANDSHAKE_CLIENT_HELLO, GNUTLS_HOOK_PRE,
   6523               1, &dat))
   6524     return 1;
   6525               ]],
   6526               [],[],
   6527               [[$GNUTLS_LIBS]]
   6528             )
   6529 
   6530             MHD_CHECK_FUNC([gnutls_ext_raw_parse],
   6531               [[
   6532 #if defined(HAVE_STDDEF_H)
   6533 #  include <stddef.h> /* NULL */
   6534 #elif defined(HAVE_STDLIB_H)
   6535 #  include <stdlib.h> /* should provide NULL */
   6536 #else
   6537 #  include <stdio.h> /* should provide NULL */
   6538 #endif
   6539 #include <gnutls/gnutls.h>
   6540 
   6541 int
   6542 test_ext_cb (void *ctx,
   6543              unsigned tls_id,
   6544              const unsigned char *data,
   6545              unsigned data_size);
   6546 
   6547 int
   6548 test_ext_cb (void *ctx,
   6549              unsigned tls_id,
   6550              const unsigned char *data,
   6551              unsigned data_size)
   6552 {
   6553   (void) ctx; (void) tls_id; (void) data_size;
   6554   return (NULL == data) ? 0 : 1;
   6555 }
   6556 
   6557               ]],
   6558               [[
   6559   gnutls_ext_raw_process_func cb = &test_ext_cb;
   6560   gnutls_datum_t dat;
   6561   unsigned char buf[2] = {0u, 0u};
   6562 
   6563   dat.data = (unsigned char *) buf;
   6564   dat.size = 1u;
   6565   i][f (! gnutls_ext_raw_parse ((void *) buf, cb, &dat,
   6566                               GNUTLS_EXT_RAW_FLAG_TLS_CLIENT_HELLO))
   6567     return 1;
   6568           ]],
   6569           [],[],
   6570           [[$GNUTLS_LIBS]]
   6571         )
   6572 
   6573         LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   6574         CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   6575       ],
   6576       [
   6577         have_gnutls="no"
   6578         have_gnutls_pkgcfg="no"
   6579         GNUTLS_MOD_VERSION="no"
   6580         AS_UNSET([GNUTLS_CPPFLAGS])
   6581         AS_UNSET([GNUTLS_CFLAGS])
   6582         AS_UNSET([GNUTLS_LDFLAGS])
   6583         AS_UNSET([GNUTLS_LIBS])
   6584       ]
   6585     )
   6586     AC_SUBST([GNUTLS_LIB_VERSION],[${GNUTLS_MOD_VERSION}])
   6587     AM_SUBST_NOTMAKE([GNUTLS_LIB_VERSION])
   6588 
   6589     AC_MSG_CHECKING([[how to find OpenSSL library]])
   6590     AC_ARG_WITH([[openssl]],
   6591       [AS_HELP_STRING([[--with-openssl[=PRFX]]],
   6592           [use OpenSSL for HTTPS support, optional PRFX overrides pkg-config data for OpenSSL headers (PRFX/include) and libs (PRFX/lib)])],
   6593       [
   6594         AS_CASE([$with_openssl],
   6595           [no],[
   6596             have_openssl="no"
   6597             AC_MSG_RESULT([[OpenSSL disabled]])
   6598             AS_UNSET([OPENSSL_CPPFLAGS])
   6599             AS_UNSET([OPENSSL_CFLAGS])
   6600             AS_UNSET([OPENSSL_LDFLAGS])
   6601             AS_UNSET([OPENSSL_LIBS])
   6602           ],
   6603           [yes],[
   6604             AC_MSG_RESULT([[automatically, forced]])
   6605           ],
   6606           [
   6607             AC_MSG_RESULT([[-I$with_openssl/include -L$with_openssl/lib -lssl -lcrypto]])
   6608             LDFLAGS="${LDFLAGS_ac} -L$with_openssl/lib ${user_LDFLAGS}"
   6609             CPPFLAGS="${CPPFLAGS_ac} -I$with_openssl/include ${user_CPPFLAGS}"
   6610             have_openssl_pkgcfg="no"
   6611             # A simple check for the working header and the library
   6612             MHD_CHECK_FUNC([SSL_CTX_new],
   6613               [[
   6614 #include <openssl/ssl.h>
   6615               ]],
   6616               [[
   6617                SSL_CTX_free(SSL_CTX_new(TLS_server_method()));
   6618               ]],
   6619               [
   6620                 have_openssl="yes"
   6621                 OPENSSL_CPPFLAGS="-I$with_openssl/include"
   6622                 AS_UNSET([OPENSSL_CFLAGS])
   6623                 OPENSSL_LDFLAGS="-L$with_openssl/lib"
   6624                 OPENSSL_LIBS="-lssl -lcrypto"
   6625               ],
   6626               [AC_MSG_ERROR([cannot find usable OpenSSL library at specified prefix $with_openssl])],
   6627               [-lssl -lcrypto]
   6628             )
   6629             CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   6630             CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   6631             LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   6632           ])
   6633        ],
   6634        [AC_MSG_RESULT([[automatically]])]
   6635     )
   6636 
   6637     AS_IF([test "x$with_openssl" != "xno" && test "x$have_openssl" != "xyes"],
   6638       [
   6639         PKG_CHECK_MODULES([OPENSSL], [[openssl >= 3.0]],
   6640           [
   6641             CPPFLAGS="${CPPFLAGS_ac} $OPENSSL_CFLAGS ${user_CPPFLAGS}"
   6642             # A simple check for the working header and the library
   6643             MHD_CHECK_FUNC([SSL_CTX_new],
   6644               [[
   6645 #include <openssl/ssl.h>
   6646               ]],
   6647               [[
   6648                SSL_CTX_free(SSL_CTX_new(TLS_server_method()));
   6649               ]],
   6650               [
   6651                 have_openssl=yes
   6652                 have_openssl_pkgcfg='yes'
   6653                 # OPENSSL_CFLAGS is actually CPPFLAGS
   6654                 OPENSSL_CPPFLAGS="$OPENSSL_CFLAGS"
   6655                 AS_UNSET([OPENSSL_CFLAGS])
   6656                 # OPENSSL_LIBS is a combination of LDFLAGS and LIBS
   6657                 AS_UNSET([OPENSSL_LDFLAGS])
   6658               ],
   6659               [
   6660                 AS_VAR_IF([with_openssl],["yes"],
   6661                   [AC_MSG_ERROR([cannot find usable OpenSSL library])]
   6662                 )
   6663                 AC_MSG_WARN([pkg-config reports that OpenSSL is present, but OpenSSL cannot be used])
   6664                 AS_UNSET([OPENSSL_CPPFLAGS])
   6665                 AS_UNSET([OPENSSL_CFLAGS])
   6666                 AS_UNSET([OPENSSL_LDFLAGS])
   6667                 AS_UNSET([OPENSSL_LIBS])
   6668               ],
   6669               [$OPENSSL_LIBS]
   6670             )
   6671           ],
   6672           [
   6673             # check for OpenSSL at default paths
   6674             have_openssl_pkgcfg="no"
   6675             # A simple check for the working header and the library
   6676             MHD_CHECK_FUNC([SSL_CTX_new],
   6677               [[
   6678 #include <openssl/ssl.h>
   6679               ]],
   6680               [[
   6681                SSL_CTX_free(SSL_CTX_new(TLS_server_method()));
   6682               ]],
   6683               [
   6684                 have_openssl="yes"
   6685                 AS_UNSET([OPENSSL_CPPFLAGS])
   6686                 AS_UNSET([OPENSSL_CFLAGS])
   6687                 AS_UNSET([OPENSSL_LDFLAGS])
   6688                 OPENSSL_LIBS="-lssl -lcrypto"
   6689               ],
   6690               [
   6691                 AS_VAR_IF([with_openssl],["yes"],
   6692                   [AC_MSG_ERROR([cannot find usable OpenSSL library])]
   6693                 )
   6694                 AS_UNSET([OPENSSL_CPPFLAGS])
   6695                 AS_UNSET([OPENSSL_CFLAGS])
   6696                 AS_UNSET([OPENSSL_LDFLAGS])
   6697                 AS_UNSET([OPENSSL_LIBS])
   6698               ],
   6699               [-lssl -lcrypto]
   6700             )
   6701           ]
   6702         )
   6703       ]
   6704     )
   6705     AS_VAR_IF([have_openssl],["yes"],
   6706       [
   6707         AC_CACHE_CHECK([[whether OpenSSL is modern enough]], [mhd_cv_openssl_ver_ok],
   6708           [
   6709             CPPFLAGS="${CPPFLAGS_ac} ${OPENSSL_CPPFLAGS} ${user_CPPFLAGS}"
   6710             AC_COMPILE_IFELSE(
   6711               [
   6712                 AC_LANG_PROGRAM(
   6713                   [[
   6714 #include <openssl/opensslv.h>
   6715                   ]],
   6716                   [[
   6717 #ifndef OPENSSL_VERSION_PREREQ
   6718 #error OPENSSL_VERSION_PREREQ is not defined. OpenSSL is too old.
   6719 fail test here %%%@<:@-1@:>@
   6720 #endif
   6721 #if !OPENSSL_VERSION_PREREQ(3,0)
   6722 #error OpenSSL version is too old and not suitable.
   6723 fail test here %%%@<:@-1@:>@
   6724 #endif
   6725                   ]]
   6726                 )
   6727               ],
   6728               [[mhd_cv_openssl_ver_ok="yes"]], [[mhd_cv_openssl_ver_ok="no"]]
   6729             )
   6730             CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   6731           ]
   6732         )
   6733         AS_VAR_IF([mhd_cv_openssl_ver_ok],["yes"],[:],
   6734           [
   6735             have_openssl="no"
   6736             AS_VAR_IF([with_openssl],["yes"],
   6737               [AC_MSG_ERROR([cannot find usable OpenSSL library])]
   6738             )
   6739           ]
   6740         )
   6741       ]
   6742     )
   6743 
   6744     AS_VAR_IF([have_openssl],["yes"],
   6745       [
   6746         AS_VAR_IF([have_openssl_pkgcfg],["yes"],
   6747           [
   6748             MHD_PKG_CONF_MODULE_VERSION([OPENSSL],[openssl >= 3.0],[],[OPENSSL_MOD_VERSION='0'])
   6749           ],[OPENSSL_MOD_VERSION='0']
   6750         )
   6751       ],
   6752       [
   6753         have_openssl="no"
   6754         have_openssl_pkgcfg="no"
   6755         OPENSSL_MOD_VERSION="no"
   6756         AS_UNSET([OPENSSL_CPPFLAGS])
   6757         AS_UNSET([OPENSSL_CFLAGS])
   6758         AS_UNSET([OPENSSL_LDFLAGS])
   6759         AS_UNSET([OPENSSL_LIBS])
   6760       ]
   6761     )
   6762     AC_SUBST([OPENSSL_LIB_VERSION],[${OPENSSL_MOD_VERSION}])
   6763     AM_SUBST_NOTMAKE([OPENSSL_LIB_VERSION])
   6764 
   6765     AC_MSG_CHECKING([[how to find MbedTLS library]])
   6766     mhd_mbedtls_pkgspec=''
   6767     AC_ARG_WITH([[mbedtls]],
   6768       [AS_HELP_STRING([[--with-mbedtls[=PRFX]]],
   6769           [use MbedTLS for HTTPS support, optional PRFX overrides pkg-config data for MbedTLS headers (PRFX/include) and libs (PRFX/lib)])],
   6770       [
   6771         AS_CASE([$with_mbedtls],
   6772           [no],[
   6773             have_mbedtls="no"
   6774             have_mbedtls_pkgcfg="no"
   6775             AC_MSG_RESULT([[MbedTLS disabled]])
   6776           ],
   6777           [yes],[
   6778             have_mbedtls="find"
   6779             have_mbedtls_pkgcfg="auto"
   6780             AC_MSG_RESULT([[automatically, forced]])
   6781           ],
   6782           [
   6783             AC_MSG_RESULT([[-I$with_mbedtls/include -L$with_mbedtls/lib]])
   6784             
   6785             AS_UNSET([MBEDTLS_FULL_CPPFLAGS])
   6786             AS_UNSET([MBEDTLS_FULL_CFLAGS])
   6787             AS_UNSET([MBEDTLS_FULL_LDFLAGS])
   6788             AS_UNSET([MBEDTLS_FULL_LIBS])
   6789             AS_UNSET([MBEDTLS_CRYPTO_CPPFLAGS])
   6790             AS_UNSET([MBEDTLS_CRYPTO_CFLAGS])
   6791             AS_UNSET([MBEDTLS_CRYPTO_LDFLAGS])
   6792             AS_UNSET([MBEDTLS_CRYPTO_LIBS])
   6793             AS_UNSET([MBEDTLS_X509_CPPFLAGS])
   6794             AS_UNSET([MBEDTLS_X509_CFLAGS])
   6795             AS_UNSET([MBEDTLS_X509_LDFLAGS])
   6796             AS_UNSET([MBEDTLS_X509_LIBS])
   6797             AS_UNSET([MBEDTLS_TLS_CPPFLAGS])
   6798             AS_UNSET([MBEDTLS_TLS_CFLAGS])
   6799             AS_UNSET([MBEDTLS_TLS_LDFLAGS])
   6800             AS_UNSET([MBEDTLS_TLS_LIBS])
   6801             have_mbedtls="find"
   6802             have_mbedtls_pkgcfg="no"
   6803           ]
   6804         )
   6805       ],
   6806       [
   6807         have_mbedtls_pkgcfg="auto"
   6808         with_mbedtls=""
   6809         AC_MSG_RESULT([[automatically]])
   6810       ]
   6811     )
   6812 
   6813     AS_IF([test "x$with_mbedtls" != "xno" && test "x$have_mbedtls" != "xyes"],
   6814       [
   6815         AS_VAR_SET_IF([MBEDTLS_CRYPTO_CFLAGS],
   6816           [have_user_MBEDTLS_CRYPTO_CFLAGS="yes"],
   6817           [have_user_MBEDTLS_CRYPTO_CFLAGS="no"]
   6818         )
   6819         AS_VAR_SET_IF([MBEDTLS_CRYPTO_LIBS],
   6820           [have_user_MBEDTLS_CRYPTO_LIBS="yes"],
   6821           [have_user_MBEDTLS_CRYPTO_LIBS="no"]
   6822         )
   6823         AS_VAR_SET_IF([MBEDTLS_X509_CFLAGS],
   6824           [have_user_MBEDTLS_X509_CFLAGS="yes"],
   6825           [have_user_MBEDTLS_X509_CFLAGS="no"]
   6826         )
   6827         AS_VAR_SET_IF([MBEDTLS_X509_LIBS],
   6828           [have_user_MBEDTLS_X509_LIBS="yes"],
   6829           [have_user_MBEDTLS_X509_LIBS="no"]
   6830         )
   6831         AS_VAR_SET_IF([MBEDTLS_TLS_CFLAGS],
   6832           [have_user_MBEDTLS_TLS_CFLAGS="yes"],
   6833           [have_user_MBEDTLS_TLS_CFLAGS="no"]
   6834         )
   6835         AS_VAR_SET_IF([MBEDTLS_TLS_LIBS],
   6836           [have_user_MBEDTLS_TLS_LIBS="yes"],
   6837           [have_user_MBEDTLS_TLS_LIBS="no"]
   6838         )
   6839         AS_IF([test "x$have_mbedtls" != "xyes" && test "x${have_mbedtls_pkgcfg}" != "xno"],
   6840           [
   6841             mbedtsl_min_ver="3.0"
   6842             PKG_CHECK_MODULES([MBEDTLS_CRYPTO], [[mbedcrypto-4 >= 4.0]],
   6843               [
   6844                 mbedtsl_min_ver="4.0"
   6845                 mbedtls_modules="mbedcrypto-4"
   6846                 PKG_CHECK_MODULES([MBEDTLS_X509], [[mbedx509-4 >= ${mbedtsl_min_ver}]],
   6847                   [
   6848                     mbedtls_modules="${mbedtls_modules}, mbedx509-4"
   6849                     PKG_CHECK_MODULES([MBEDTLS_TLS], [[mbedtls-4 >= ${mbedtsl_min_ver}]],
   6850                       [
   6851                         mbedtls_modules="${mbedtls_modules} and mbedtls-4"
   6852                         have_mbedtls_pkgcfg="yes"
   6853                         have_mbedtls="yes"
   6854                         mhd_mbedtls_pkgspec="mbedtls-4 >= ${mbedtsl_min_ver}"
   6855                       ],[]
   6856                     )
   6857                   ],[]
   6858                 )
   6859               ],[]
   6860             )
   6861             AS_VAR_IF([have_mbedtls],["yes"],[:],
   6862               [
   6863                 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_CFLAGS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_CFLAGS])])
   6864                 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_LIBS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_LIBS])])
   6865                 AS_VAR_IF([have_user_MBEDTLS_X509_CFLAGS],["no"],[AS_UNSET([MBEDTLS_X509_CFLAGS])])
   6866                 AS_VAR_IF([have_user_MBEDTLS_X509_LIBS],["no"],[AS_UNSET([MBEDTLS_X509_LIBS])])
   6867                 AS_VAR_IF([have_user_MBEDTLS_TLS_CFLAGS],["no"],[AS_UNSET([MBEDTLS_TLS_CFLAGS])])
   6868                 AS_VAR_IF([have_user_MBEDTLS_TLS_LIBS],["no"],[AS_UNSET([MBEDTLS_TLS_LIBS])])
   6869                 PKG_CHECK_MODULES([MBEDTLS_CRYPTO], [[mbedcrypto-3 >= ${mbedtsl_min_ver}]],
   6870                   [
   6871                     mbedtls_modules="mbedcrypto-3"
   6872                     PKG_CHECK_MODULES([MBEDTLS_X509], [[mbedx509-3 >= ${mbedtsl_min_ver}]],
   6873                       [
   6874                         mbedtls_modules="${mbedtls_modules}, mbedx509-3"
   6875                         PKG_CHECK_MODULES([MBEDTLS_TLS], [[mbedtls-3 >= ${mbedtsl_min_ver}]],
   6876                           [
   6877                             mbedtls_modules="${mbedtls_modules} and mbedtls-3"
   6878                             have_mbedtls_pkgcfg="yes"
   6879                             have_mbedtls="yes"
   6880                             mhd_mbedtls_pkgspec="mbedtls-3 >= ${mbedtsl_min_ver}"
   6881                           ],[]
   6882                         )
   6883                       ],[]
   6884                     )
   6885                   ],[]
   6886                 )
   6887               ]
   6888             )
   6889             AS_VAR_IF([have_mbedtls],["yes"],[:],
   6890               [
   6891                 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_CFLAGS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_CFLAGS])])
   6892                 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_LIBS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_LIBS])])
   6893                 AS_VAR_IF([have_user_MBEDTLS_X509_CFLAGS],["no"],[AS_UNSET([MBEDTLS_X509_CFLAGS])])
   6894                 AS_VAR_IF([have_user_MBEDTLS_X509_LIBS],["no"],[AS_UNSET([MBEDTLS_X509_LIBS])])
   6895                 AS_VAR_IF([have_user_MBEDTLS_TLS_CFLAGS],["no"],[AS_UNSET([MBEDTLS_TLS_CFLAGS])])
   6896                 AS_VAR_IF([have_user_MBEDTLS_TLS_LIBS],["no"],[AS_UNSET([MBEDTLS_TLS_LIBS])])
   6897                 PKG_CHECK_MODULES([MBEDTLS_CRYPTO], [[mbedcrypto >= ${mbedtsl_min_ver}]],
   6898                   [
   6899                     mbedtls_modules="mbedcrypto"
   6900                     PKG_CHECK_MODULES([MBEDTLS_X509], [[mbedx509 >= ${mbedtsl_min_ver}]],
   6901                       [
   6902                         mbedtls_modules="${mbedtls_modules}, mbedx509"
   6903                         PKG_CHECK_MODULES([MBEDTLS_TLS], [[mbedtls >= ${mbedtsl_min_ver}]],
   6904                           [
   6905                             mbedtls_modules="${mbedtls_modules} and mbedtls"
   6906                             have_mbedtls_pkgcfg="yes"
   6907                             have_mbedtls="yes"
   6908                             mhd_mbedtls_pkgspec="mbedtls >= ${mbedtsl_min_ver}"
   6909                           ],[]
   6910                         )
   6911                       ],[]
   6912                     )
   6913                   ],[]
   6914                 )
   6915               ]
   6916             )
   6917             AS_VAR_IF([have_mbedtls],["yes"],
   6918               [
   6919                 AS_UNSET([MBEDTLS_FULL_CPPFLAGS])
   6920                 AS_UNSET([MBEDTLS_FULL_CFLAGS])
   6921                 AS_UNSET([MBEDTLS_FULL_LDFLAGS])
   6922                 AS_UNSET([MBEDTLS_FULL_LIBS])
   6923                 # pkg-config's *_CFLAGS are actually *_CPPFLAGS
   6924                 MBEDTLS_CRYPTO_CPPFLAGS="${MBEDTLS_CRYPTO_CFLAGS}"
   6925                 MBEDTLS_X509_CPPFLAGS="${MBEDTLS_X509_CFLAGS}"
   6926                 MBEDTLS_TLS_CPPFLAGS="${MBEDTLS_TLS_CFLAGS}"
   6927                 AS_UNSET([MBEDTLS_CRYPTO_CFLAGS])
   6928                 AS_UNSET([MBEDTLS_X509_CFLAGS])
   6929                 AS_UNSET([MBEDTLS_TLS_CFLAGS])
   6930                 # pkg-config's  *_LIBS are combinations of *_LDFLAGS and *_LIBS
   6931                 AS_UNSET([MBEDTLS_CRYPTO_LDFLAGS])
   6932                 AS_UNSET([MBEDTLS_X509_LDFLAGS])
   6933                 AS_UNSET([MBEDTLS_TLS_LDFLAGS])
   6934                 
   6935                 # Smart-combine three libraries flags
   6936                 MBEDTLS_FULL_CPPFLAGS="${MBEDTLS_CRYPTO_CPPFLAGS}"
   6937                 AS_CASE([" ${MBEDTLS_X509_CPPFLAGS} "],
   6938                   [*" ${MBEDTLS_FULL_CPPFLAGS} "*],[:],
   6939                   [
   6940                     AS_CASE([" ${MBEDTLS_FULL_CPPFLAGS} "],
   6941                       [*" ${MBEDTLS_X509_CPPFLAGS} "*],[MBEDTLS_FULL_CPPFLAGS="${MBEDTLS_X509_CPPFLAGS}"],
   6942                       [MBEDTLS_FULL_CPPFLAGS="${MBEDTLS_FULL_CPPFLAGS} ${MBEDTLS_X509_CPPFLAGS}"]
   6943                     )
   6944                   ]
   6945                 )
   6946                 AS_CASE([" ${MBEDTLS_TLS_CPPFLAGS} "],
   6947                   [*" ${MBEDTLS_FULL_CPPFLAGS} "*],[:],
   6948                   [
   6949                     AS_CASE([" ${MBEDTLS_FULL_CPPFLAGS} "],
   6950                       [*" ${MBEDTLS_TLS_CPPFLAGS} "*],[MBEDTLS_FULL_CPPFLAGS="${MBEDTLS_TLS_CPPFLAGS}"],
   6951                       [MBEDTLS_FULL_CPPFLAGS="${MBEDTLS_FULL_CPPFLAGS} ${MBEDTLS_TLS_CPPFLAGS}"]
   6952                     )
   6953                   ]
   6954                 )
   6955                 MBEDTLS_FULL_LIBS="${MBEDTLS_CRYPTO_LIBS}"
   6956                 AS_CASE([" ${MBEDTLS_X509_LIBS} "],
   6957                   [*" ${MBEDTLS_FULL_LIBS} "*],[:],
   6958                   [
   6959                     AS_CASE([" ${MBEDTLS_FULL_LIBS} "],
   6960                       [*" ${MBEDTLS_X509_LIBS} "*],[MBEDTLS_FULL_LIBS="${MBEDTLS_X509_LIBS}"],
   6961                       [MBEDTLS_FULL_LIBS="${MBEDTLS_X509_LIBS} ${MBEDTLS_FULL_LIBS}"]
   6962                     )
   6963                   ]
   6964                 )
   6965                 AS_CASE([" ${MBEDTLS_TLS_LIBS} "],
   6966                   [*" ${MBEDTLS_FULL_LIBS} "*],[:],
   6967                   [
   6968                     AS_CASE([" ${MBEDTLS_FULL_LIBS} "],
   6969                       [*" ${MBEDTLS_TLS_LIBS} "*],[MBEDTLS_FULL_LIBS="${MBEDTLS_TLS_LIBS}"],
   6970                       [MBEDTLS_FULL_LIBS="${MBEDTLS_TLS_LIBS} ${MBEDTLS_FULL_LIBS}"]
   6971                     )
   6972                   ]
   6973                 )
   6974                 
   6975                 CPPFLAGS="${CPPFLAGS_ac} ${MBEDTLS_FULL_CPPFLAGS} ${user_CPPFLAGS}"
   6976                 
   6977                 MHD_CHECK_FUNC([mbedtls_ssl_init],[[#include <mbedtls/ssl.h>]],
   6978                   [[
   6979                     mbedtls_ssl_context ssl;
   6980                     mbedtls_ssl_init (&ssl);
   6981                     mbedtls_ssl_free (&ssl);
   6982                   ]],
   6983                   [],
   6984                   [AC_MSG_ERROR([pkg-config reports that $mbedtls_modules modules are present, but MbedTLS cannot be used])],
   6985                   ["${MBEDTLS_FULL_LIBS}"]
   6986                 )
   6987                 
   6988                 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   6989               ],
   6990               [
   6991                 AS_UNSET([mbedtls_modules])
   6992                 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_CFLAGS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_CFLAGS])])
   6993                 AS_VAR_IF([have_user_MBEDTLS_CRYPTO_LIBS],["no"],[AS_UNSET([MBEDTLS_CRYPTO_LIBS])])
   6994                 AS_VAR_IF([have_user_MBEDTLS_X509_CFLAGS],["no"],[AS_UNSET([MBEDTLS_X509_CFLAGS])])
   6995                 AS_VAR_IF([have_user_MBEDTLS_X509_LIBS],["no"],[AS_UNSET([MBEDTLS_X509_LIBS])])
   6996                 AS_VAR_IF([have_user_MBEDTLS_TLS_CFLAGS],["no"],[AS_UNSET([MBEDTLS_TLS_CFLAGS])])
   6997                 AS_VAR_IF([have_user_MBEDTLS_TLS_LIBS],["no"],[AS_UNSET([MBEDTLS_TLS_LIBS])])
   6998               ]
   6999             )
   7000             AS_UNSET([have_user_MBEDTLS_CRYPTO_CFLAGS])
   7001             AS_UNSET([have_user_MBEDTLS_CRYPTO_LIBS])
   7002             AS_UNSET([have_user_MBEDTLS_X509_CFLAGS])
   7003             AS_UNSET([have_user_MBEDTLS_X509_LIBS])
   7004             AS_UNSET([have_user_MBEDTLS_TLS_CFLAGS])
   7005             AS_UNSET([have_user_MBEDTLS_TLS_LIBS])
   7006           ]
   7007         )
   7008 
   7009         AS_VAR_IF([have_mbedtls],["yes"],[:],
   7010           [
   7011             have_mbedtls_pkgcfg="no"
   7012             AS_CASE(["x${with_mbedtls}"],
   7013               ["xyes"],[
   7014                 MBEDTLS_FULL_CPPFLAGS=""
   7015                 MBEDTLS_FULL_LDFLAGS=""
   7016                 ],
   7017               ["x"],[
   7018                 MBEDTLS_FULL_CPPFLAGS=""
   7019                 MBEDTLS_FULL_LDFLAGS=""
   7020                 ],
   7021               [
   7022                 MBEDTLS_FULL_CPPFLAGS="-I$with_mbedtls/include"
   7023                 MBEDTLS_FULL_LDFLAGS="-L$with_mbedtls/lib"
   7024               ]
   7025             )
   7026             CPPFLAGS="${CPPFLAGS_ac} ${MBEDTLS_FULL_CPPFLAGS} ${user_CPPFLAGS}"
   7027             LDFLAGS="${LDFLAGS_ac} ${MBEDTLS_FULL_LDFLAGS} ${user_LDFLAGS}"
   7028 
   7029             MHD_FIND_LIB([mbedtls_md_init],[[#include <mbedtls/md.h>]],
   7030               [[
   7031                 /* These functions must be enabled i][f TLS is built */
   7032                 mbedtls_md_context_t ctx;
   7033                 mbedtls_md_init (&ctx);
   7034                 mbedtls_md_free (&ctx);
   7035               ]],
   7036               [tfpsacrypto-4 tfpsacrypto mbedcrypto-3 mbedcrypto],
   7037               [
   7038                 AS_CASE([${MBEDTLS_CRYPTO_LIBS}],
   7039                   [*-4],[check_names_x509="mbedx509-4"
   7040                          check_names_tls="mbedtls-4"],
   7041                   [*-3],[check_names_x509="mbedx509-3"
   7042                          check_names_tls="mbedtls-3"],
   7043                   [*crypto],[check_names_x509="mbedx509"
   7044                              check_names_tls="mbedtls"],
   7045                   [check_names_x509="mbedx509-4 mbedx509-3 mbedx509"
   7046                    check_names_tls="mbedtls-4 mbedtls-3 mbedtls"]
   7047                 )
   7048                 MHD_FIND_LIB([mbedtls_x509_crt_init],[[#include <mbedtls/x509_crt.h>]],
   7049                   [[
   7050                     /* These functions must be enabled i][f TLS based on X509 certificates is built */
   7051                     mbedtls_x509_crt crt;
   7052                     mbedtls_x509_crt_init(&crt);
   7053                     mbedtls_x509_crt_free(&crt);
   7054                   ]],
   7055                   [${check_names_x509}],
   7056                   [
   7057                     AS_CASE([${MBEDTLS_X509_LIBS}],
   7058                       [*-4],[check_names_tls="mbedtls-4"],
   7059                       [*-3],[check_names_tls="mbedtls-3"],
   7060                       [*x509],[check_names_tls="mbedtls"]
   7061                     )
   7062                     MHD_FIND_LIB([mbedtls_ssl_init],[[#include <mbedtls/ssl.h>]],
   7063                       [[
   7064                         mbedtls_ssl_context ssl;
   7065                         mbedtls_ssl_init (&ssl);
   7066                         mbedtls_ssl_free (&ssl);
   7067                       ]],
   7068                       [${check_names_tls}],
   7069                       [
   7070                         have_mbedtls="yes"
   7071                         MBEDTLS_FULL_LIBS="${MBEDTLS_TLS_LIBS} ${MBEDTLS_X509_LIBS} ${MBEDTLS_CRYPTO_LIBS}"
   7072                         MBEDTLS_CRYPTO_CPPFLAGS="${MBEDTLS_FULL_CPPFLAGS}"
   7073                         MBEDTLS_CRYPTO_LDFLAGS="${MBEDTLS_FULL_LDFLAGS}"
   7074                         MBEDTLS_X509_CPPFLAGS="${MBEDTLS_FULL_CPPFLAGS}"
   7075                         MBEDTLS_X509_LDFLAGS="${MBEDTLS_FULL_LDFLAGS}"
   7076                         MBEDTLS_TLS_CPPFLAGS="${MBEDTLS_FULL_CPPFLAGS}"
   7077                         MBEDTLS_TLS_LDFLAGS="${MBEDTLS_FULL_LDFLAGS}"
   7078                       ],[],
   7079                       [MBEDTLS_TLS_LIBS],[${MBEDTLS_X509_LIBS} ${MBEDTLS_CRYPTO_LIBS}]
   7080                     )
   7081                   ],[],
   7082                   [MBEDTLS_X509_LIBS],[${MBEDTLS_CRYPTO_LIBS}]
   7083                 )
   7084                 AS_UNSET([check_names_tls])
   7085                 AS_UNSET([check_names_x509])
   7086               ],[],
   7087               [MBEDTLS_CRYPTO_LIBS]
   7088             )
   7089             CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   7090             LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   7091           ]
   7092         )
   7093       ]
   7094     )
   7095 
   7096     AS_VAR_IF([have_mbedtls],["yes"],
   7097       [
   7098         AS_IF([test -n "${mhd_mbedtls_pkgspec}"],
   7099           [
   7100             MHD_PKG_CONF_MODULE_VERSION([MBEDTLS],[${mhd_mbedtls_pkgspec}],[],[MBEDTLS_MOD_VERSION='0'])
   7101           ],[MBEDTLS_MOD_VERSION='0']
   7102         )
   7103       ],
   7104       [
   7105         have_mbedtls="no"
   7106         AS_CASE(["x$with_mbedtls"],
   7107           ["xyes"],[AC_MSG_ERROR([connot find usable MbedTLS library])],
   7108           ["x"],[with_mbedtls="no"],
   7109           ["no"],[:]
   7110           [AC_MSG_ERROR([cannot find usable MbedTLS library at specified prefix $with_mbedtls])]
   7111         )
   7112         MBEDTLS_MOD_VERSION="no"
   7113         AS_UNSET([MBEDTLS_FULL_CPPFLAGS])
   7114         AS_UNSET([MBEDTLS_FULL_CFLAGS])
   7115         AS_UNSET([MBEDTLS_FULL_LDFLAGS])
   7116         AS_UNSET([MBEDTLS_FULL_LIBS])
   7117         AS_UNSET([MBEDTLS_CRYPTO_CPPFLAGS])
   7118         AS_UNSET([MBEDTLS_CRYPTO_CFLAGS])
   7119         AS_UNSET([MBEDTLS_CRYPTO_LDFLAGS])
   7120         AS_UNSET([MBEDTLS_CRYPTO_LIBS])
   7121         AS_UNSET([MBEDTLS_X509_CPPFLAGS])
   7122         AS_UNSET([MBEDTLS_X509_CFLAGS])
   7123         AS_UNSET([MBEDTLS_X509_LDFLAGS])
   7124         AS_UNSET([MBEDTLS_X509_LIBS])
   7125         AS_UNSET([MBEDTLS_TLS_CPPFLAGS])
   7126         AS_UNSET([MBEDTLS_TLS_CFLAGS])
   7127         AS_UNSET([MBEDTLS_TLS_LDFLAGS])
   7128         AS_UNSET([MBEDTLS_TLS_LIBS])
   7129       ]
   7130     )
   7131     AS_UNSET([mhd_mbedtls_pkgspec])
   7132     AC_SUBST([MBEDTLS_LIB_VERSION],[${MBEDTLS_MOD_VERSION}])
   7133     AM_SUBST_NOTMAKE([MBEDTLS_LIB_VERSION])
   7134 
   7135     AS_IF([test "x$have_gnutls" = "xyes" || test "x$have_openssl" = "xyes" || test "x$have_mbedtls" = "xyes"],
   7136       [
   7137         enable_https="yes"
   7138         multiple_tls="no"
   7139         MSG_TLS_BACKENDS=""
   7140 
   7141         AS_VAR_IF([have_gnutls],["yes"],
   7142           [
   7143             AS_IF([test -n "${MSG_TLS_BACKENDS}"],
   7144               [
   7145                 MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}, "
   7146                 multiple_tls="yes"
   7147               ]
   7148             )
   7149             AC_DEFINE([MHD_SUPPORT_GNUTLS],[1],[Define to '1' i][f GnuTLS library should be used])
   7150             MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}GnuTLS"
   7151             MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_CPPFLAGS],[$GNUTLS_CPPFLAGS])
   7152             MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_LDFLAGS],[$GNUTLS_LDFLAGS])
   7153             MHD_PREPEND_FLAG_TO_VAR([MHD_TLS_LIBDEPS],[$GNUTLS_LIBS])
   7154           ]
   7155         )
   7156         AS_VAR_IF([have_openssl],["yes"],
   7157           [
   7158             AS_IF([test -n "${MSG_TLS_BACKENDS}"],
   7159               [
   7160                 MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}, "
   7161                 multiple_tls="yes"
   7162               ]
   7163             )
   7164             AC_DEFINE([MHD_SUPPORT_OPENSSL],[1],[Define to '1' i][f OpenSSL library should be used])
   7165             MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}OpenSSL"
   7166             MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_CPPFLAGS],[$OPENSSL_CPPFLAGS])
   7167             MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_LDFLAGS],[$OPENSSL_LDFLAGS])
   7168             MHD_PREPEND_FLAG_TO_VAR([MHD_TLS_LIBDEPS],[$OPENSSL_LIBS])
   7169           ]
   7170         )
   7171         AS_VAR_IF([have_mbedtls],["yes"],
   7172           [
   7173             AS_IF([test -n "${MSG_TLS_BACKENDS}"],
   7174               [
   7175                 MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}, "
   7176                 multiple_tls="yes"
   7177               ]
   7178             )
   7179             AC_DEFINE([MHD_SUPPORT_MBEDTLS],[1],[Define to '1' i][f MbedTLS library should be used])
   7180             MSG_TLS_BACKENDS="${MSG_TLS_BACKENDS}MbedTLS"
   7181             MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_CPPFLAGS],[$MBEDTLS_FULL_CPPFLAGS])
   7182             MHD_APPEND_FLAG_TO_VAR([MHD_TLS_LIB_LDFLAGS],[$MBEDTLS_FULL_LDFLAGS])
   7183             MHD_PREPEND_FLAG_TO_VAR([MHD_TLS_LIBDEPS],[$MBEDTLS_FULL_LIBS])
   7184           ]
   7185         )
   7186         AS_VAR_IF([multiple_tls],["yes"],
   7187           [
   7188             MSG_HTTPS="yes (multiple backends)"
   7189             AC_DEFINE([mhd_HAVE_SEVERAL_TLS_BACKENDS],[1],[Define to '1' if several TLS backend are linked])
   7190           ],
   7191           [MSG_HTTPS="yes (single backend)"]
   7192         )
   7193         AS_IF([test -z "$MSG_TLS_BACKENDS"],[AC_MSG_FAILURE([configure internal error: no TLS backends])])
   7194         AC_DEFINE([MHD_SUPPORT_HTTPS],[1],[Define to '1' i][f HTTPS protocol should be supported])
   7195       ],
   7196       [
   7197         AS_VAR_IF([enable_https],["yes"],
   7198           [AC_MSG_ERROR([no suitable TLS lib found, HTTPS cannot be enabled])]
   7199         )
   7200         enable_https="no"
   7201         MSG_HTTPS="no (no suitable TLS lib found)"
   7202         MSG_TLS_BACKENDS="none"
   7203       ]
   7204     )
   7205   ],
   7206   [
   7207     enable_https="no"
   7208     MSG_HTTPS="no (disabled)"
   7209   ]
   7210 )
   7211 
   7212 AC_MSG_CHECKING(whether to support HTTPS)
   7213 AS_VAR_IF([enable_https],["yes"],
   7214   [
   7215     AS_CASE([$MSG_HTTPS],[yes*],[:],
   7216       [AC_MSG_FAILURE([configure internal error: wrong MSG_HTTPS])]
   7217     )
   7218   ],
   7219   [
   7220     enable_https="no"
   7221     MSG_TLS_BACKENDS="none"
   7222     AS_UNSET([MHD_TLS_LIB_CPPFLAGS])
   7223     AS_UNSET([MHD_TLS_LIB_LDFLAGS])
   7224     AS_UNSET([MHD_TLS_LIBDEPS])
   7225     AS_CASE([$MSG_HTTPS],[no*],[:],
   7226       [AC_MSG_FAILURE([configure internal error: wrong MSG_HTTPS])]
   7227     )
   7228   ]
   7229 )
   7230 AC_MSG_RESULT([$MSG_HTTPS])
   7231 
   7232 AM_CONDITIONAL([MHD_SUPPORT_GNUTLS], [[test "x$have_gnutls" = "xyes"]])
   7233 AC_SUBST([GNUTLS_CPPFLAGS])
   7234 AC_SUBST([GNUTLS_LDFLAGS])
   7235 AC_SUBST([GNUTLS_LIBS])
   7236 AM_CONDITIONAL([MHD_SUPPORT_OPENSSL], [[test "x$have_openssl" = "xyes"]])
   7237 AC_SUBST([OPENSSL_CPPFLAGS])
   7238 AC_SUBST([OPENSSL_LDFLAGS])
   7239 AC_SUBST([OPENSSL_LIBS])
   7240 AM_CONDITIONAL([MHD_SUPPORT_MBEDTLS], [[test "x$have_mbedtls" = "xyes"]])
   7241 AC_SUBST([MBEDTLS_CRYPTO_CPPFLAGS])
   7242 AC_SUBST([MBEDTLS_CRYPTO_LDFLAGS])
   7243 AC_SUBST([MBEDTLS_CRYPTO_LIBS])
   7244 AC_SUBST([MBEDTLS_FULL_CPPFLAGS])
   7245 AC_SUBST([MBEDTLS_FULL_LDFLAGS])
   7246 AC_SUBST([MBEDTLS_FULL_LIBS])
   7247 AM_CONDITIONAL([MHD_ENABLE_MULTITLS], [test "x$multiple_tls" = "xyes"])
   7248 AM_CONDITIONAL([MHD_SUPPORT_HTTPS], [test "x$enable_https" = "xyes"])
   7249 
   7250 AS_VAR_IF([have_gnutls], ["yes"],
   7251   [
   7252     AC_CACHE_CHECK([for GnuTLS quirks], [mhd_cv_gnutls_mthread_broken],
   7253       [
   7254         mhd_cv_gnutls_mthread_broken="no"
   7255         AS_IF([test -r /etc/redhat-release],
   7256           [
   7257             AS_IF([$FGREP ' release 6.' /etc/redhat-release >/dev/null || $FGREP '(Santiago)' /etc/redhat-release >/dev/null],
   7258               [mhd_cv_gnutls_mthread_broken="found"],
   7259             )
   7260           ]
   7261         )
   7262         AS_VAR_IF([mhd_cv_gnutls_mthread_broken], ["no"],
   7263           [
   7264             AS_IF([command -v rpm >/dev/null],
   7265               [
   7266                 AS_IF([test "r`rpm -E '%{rhel}' 2>/dev/null`" = "r6"],
   7267                   [mhd_cv_gnutls_mthread_broken="found"],
   7268                 )
   7269               ]
   7270             )
   7271           ]
   7272         )
   7273       ]
   7274     )
   7275     AC_CACHE_CHECK([for gnutls-cli binary], [mhd_cv_gnutls_cli],
   7276       [
   7277         mhd_cv_gnutls_cli="no"
   7278         AS_IF([command -v gnutls-cli >/dev/null 2>&1],
   7279           [AS_IF([AC_RUN_LOG([gnutls-cli --version >&2])], [mhd_cv_gnutls_cli="yes"])]
   7280         )
   7281       ]
   7282     )
   7283   ]
   7284 )
   7285 AM_CONDITIONAL([HAVE_GNUTLS_MTHREAD_BROKEN], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xfound"]])
   7286 AM_CONDITIONAL([USE_UPGRADE_TLS_TESTS], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xno" || test "x${mhd_cv_gnutls_cli}" = "xyes"]])
   7287 
   7288 # optional: HTTP Basic Auth support. Enabled by default
   7289 AC_MSG_CHECKING([[whether to support HTTP Basic authentication]])
   7290 AC_ARG_ENABLE([basic-auth],
   7291   [AS_HELP_STRING([--disable-basic-auth],[disable HTTP Basic Authentication support])],
   7292   [],
   7293   [enable_basic_auth="yes"]
   7294 )
   7295 AS_IF([[test "x$enable_basic_auth" != "xno"]],
   7296   [
   7297     enable_basic_auth="yes"
   7298     AC_DEFINE([MHD_SUPPORT_AUTH_BASIC],[1],[Define to '1' if libmicrohttpd should be compiled with Basic Auth support.])
   7299   ]
   7300 )
   7301 AM_CONDITIONAL([MHD_SUPPORT_AUTH_BASIC], [test "x$enable_basic_auth" = "xyes"])
   7302 AC_MSG_RESULT([[$enable_basic_auth]])
   7303 
   7304 # optional: HTTP Digest Auth support. Enabled by default
   7305 AC_MSG_CHECKING([[whether to support HTTP Digest authentication]])
   7306 AC_ARG_ENABLE([digest-auth],
   7307   [AS_HELP_STRING([--disable-digest-auth], [disable HTTP Digest Authentication support])],
   7308   [],
   7309   [enable_digest_auth="yes"]
   7310 )
   7311 AS_IF([[test "x$enable_digest_auth" != "xno"]],
   7312   [ enable_digest_auth=yes
   7313     AC_DEFINE([MHD_SUPPORT_AUTH_DIGEST],[1],[Define to 1 if libmicrohttpd is compiled with Digest Auth support.]) ])
   7314 AM_CONDITIONAL([MHD_SUPPORT_AUTH_DIGEST], [test "x$enable_digest_auth" != "xno"])
   7315 AC_MSG_RESULT([[$enable_digest_auth]])
   7316 
   7317 AS_VAR_IF([enable_digest_auth], ["yes"],
   7318   [
   7319     AC_MSG_CHECKING([[for Digest Authentication default nonce timeout value]])
   7320     AC_ARG_ENABLE([digest-auth-def-timeout],
   7321       [AS_HELP_STRING([--enable-digest-auth-def-timeout=NNN],
   7322                       [set default Digest Auth nonce validity time to NNN seconds])],
   7323       [],
   7324       [enable_digest_auth_def_timeout=""]
   7325     )
   7326     AS_VAR_IF([enable_digest_auth_def_timeout], ["no"],
   7327       [
   7328         AC_MSG_WARN([Default Diget Auth nonce validity time cannot be disabled, --disable-digest-auth-def-timeout parameter is ignored])
   7329         enable_digest_auth_def_timeout=""
   7330       ]
   7331     )
   7332     AS_IF([test -z "${enable_digest_auth_def_timeout}"],
   7333       [
   7334         enable_digest_auth_def_timeout="90"
   7335         enable_dauth_def_timeout_MSG="${enable_digest_auth_def_timeout} seconds (default)"
   7336       ],
   7337       [
   7338         AS_IF([[test "x${enable_digest_auth_def_timeout}" = "x`echo ${enable_digest_auth_def_timeout}|${SED-sed} 's/[^0-9]//g'`" && \
   7339                 test "${enable_digest_auth_def_timeout}" -ge "0" 2>/dev/null ]],[:],
   7340           [AC_MSG_ERROR([Invalid parameter --enable-digest-auth-def-timeout=${enable_digest_auth_def_timeout}. Timeout value must be a positive integer.])
   7341           ]
   7342         )
   7343         AC_COMPILE_IFELSE(
   7344           [
   7345             AC_LANG_PROGRAM([],
   7346               [[
   7347   static int arr[((int) 2) - 4 * (int)(${enable_digest_auth_def_timeout} != ((unsigned int)${enable_digest_auth_def_timeout}))];
   7348   (void) arr;
   7349               ]]
   7350             )
   7351           ],
   7352           [],
   7353           [AC_MSG_ERROR([The value specified by --enable-digest-auth-def-timeout=${enable_digest_auth_def_timeout} is too large.])]
   7354         )
   7355         enable_dauth_def_timeout_MSG="${enable_digest_auth_def_timeout} seconds (set by parameter)"
   7356       ]
   7357     )
   7358     AC_DEFINE_UNQUOTED([MHD_AUTH_DIGEST_DEF_TIMEOUT],[${enable_digest_auth_def_timeout}],
   7359         [The default HTTP Digest Auth default nonce timeout value (in seconds)])
   7360     AC_MSG_RESULT([[${enable_dauth_def_timeout_MSG}]])
   7361 
   7362     AC_MSG_CHECKING([[for Digest Authentication default maximum nc value]])
   7363     AC_ARG_ENABLE([digest-auth-def-max-nc],
   7364       [AS_HELP_STRING([--enable-digest-auth-def-max-nc=NNN],
   7365                       [set default Digest Auth maximum nc (nonce count) value to NNN])],
   7366       [],
   7367       [enable_digest_auth_def_max_nc=""]
   7368     )
   7369     AS_VAR_IF([enable_digest_auth_def_max_nc], ["no"],
   7370       [
   7371         AC_MSG_WARN([Default Diget Auth maximum nc cannot be disabled, --disable-digest-auth-def-max-nc parameter is ignored])
   7372         enable_digest_auth_def_max_nc=""
   7373       ]
   7374     )
   7375     AS_IF([test -z "${enable_digest_auth_def_max_nc}"],
   7376       [
   7377         enable_digest_auth_def_max_nc="1000"
   7378         enable_dauth_def_max_nc_MSG="${enable_digest_auth_def_max_nc} (default)"
   7379       ],
   7380       [
   7381         AS_IF([[test "x${enable_digest_auth_def_max_nc}" = "x`echo ${enable_digest_auth_def_max_nc}|${SED-sed} 's/[^0-9]//g'`" && \
   7382                 test "${enable_digest_auth_def_max_nc}" -ge "0" 2>/dev/null ]],[:],
   7383           [AC_MSG_ERROR([Invalid parameter --enable-digest-auth-def-max-nc=${enable_digest_auth_def_max_nc}. The value must be a positive integer.])
   7384           ]
   7385         )
   7386         AC_COMPILE_IFELSE(
   7387           [
   7388             AC_LANG_PROGRAM(
   7389               [[
   7390 #include <stdint.h>
   7391               ]],
   7392               [[
   7393   static int arr[((int) 2) - 4 * (int)(${enable_digest_auth_def_max_nc} != ((uint_fast32_t)${enable_digest_auth_def_max_nc}))];
   7394   (void) arr;
   7395               ]]
   7396             )
   7397           ],
   7398           [],
   7399           [AC_MSG_ERROR([The value specified by --enable-digest-auth-def-max-nc=${enable_digest_auth_def_max_nc} is too large.])]
   7400         )
   7401         enable_dauth_def_max_nc_MSG="${enable_digest_auth_def_max_nc} (set by parameter)"
   7402       ]
   7403     )
   7404     AC_DEFINE_UNQUOTED([MHD_AUTH_DIGEST_DEF_MAX_NC],[${enable_digest_auth_def_max_nc}],
   7405         [The default HTTP Digest Auth default maximum nc (nonce count) value])
   7406     AC_MSG_RESULT([[${enable_dauth_def_max_nc_MSG}]])
   7407 
   7408     dauth_defs_MSG="timeout: ${enable_dauth_def_timeout_MSG}, max nc: ${enable_dauth_def_max_nc_MSG}"
   7409   ],
   7410   [
   7411     dauth_defs_MSG="N/A"
   7412   ]
   7413 )
   7414 
   7415 AM_CONDITIONAL([MHD_SUPPORT_AUTH],[test "x$enable_basic_auth" != "xno" || test "x$enable_digest_auth" != "xno"])
   7416 
   7417 # optional: HTTP "Upgrade" support. Enabled by default
   7418 AC_MSG_CHECKING([[whether to support HTTP "Upgrade"]])
   7419 AC_ARG_ENABLE([[httpupgrade]],
   7420     [AS_HELP_STRING([[--disable-httpupgrade]], [disable HTTP "Upgrade" support])],
   7421     [AS_VAR_IF([[enable_httpupgrade]],[["no"]],[],[[enable_httpupgrade='yes']])],
   7422     [[enable_httpupgrade='yes']])
   7423 AS_VAR_IF([[enable_httpupgrade]],[["yes"]],
   7424   [
   7425    AC_DEFINE([[MHD_SUPPORT_UPGRADE]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP Upgrade support.]) ])
   7426 AM_CONDITIONAL([MHD_SUPPORT_UPGRADE], [[test "x$enable_httpupgrade" = "xyes"]])
   7427 AC_MSG_RESULT([[$enable_httpupgrade]])
   7428 
   7429 # optional: HTTP cookie parsing support. Enabled by default
   7430 AC_MSG_CHECKING([[whether to support HTTP cookie parsing]])
   7431 AC_ARG_ENABLE([[cookie]],
   7432     [AS_HELP_STRING([[--disable-cookie]], [disable HTTP cookie parser support])],
   7433     [AS_VAR_IF([[enable_cookie]],[["no"]],[],[[enable_cookie='yes']])],
   7434     [[enable_cookie='yes']])
   7435 AS_VAR_IF([[enable_cookie]],[["yes"]],
   7436   [
   7437    AC_DEFINE([[MHD_SUPPORT_COOKIES]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP cookie parsing support.]) ])
   7438 AM_CONDITIONAL([MHD_SUPPORT_COOKIES], [[test "x$enable_cookie" = "xyes"]])
   7439 AC_MSG_RESULT([[$enable_cookie]])
   7440 
   7441 # optional: ACME support. Enabled by default
   7442 AC_MSG_CHECKING([[whether to enable ACME functions]])
   7443 AC_ARG_ENABLE([[acme]],
   7444     [AS_HELP_STRING([[--disable-acme]], [disable ACME functions])],
   7445     [AS_VAR_IF([[enable_acme]],[["no"]],[],[[enable_acme='yes']])],
   7446     [[enable_acme='yes']])
   7447 AS_VAR_IF([[enable_acme]],[["yes"]],
   7448   [
   7449    AC_DEFINE([[MHD_SUPPORT_ACME]],[[1]],[Define to 1 if libmicrohttpd is compiled with ACME functions support.]) ])
   7450 AM_CONDITIONAL([MHD_SUPPORT_ACME], [[test "X$enable_acme" = "Xyes"]])
   7451 AC_MSG_RESULT([[$enable_acme]])
   7452 
   7453 # optional: MD5 support for Digest Auth. Enabled by default.
   7454 AC_ARG_ENABLE([[md5]],
   7455   [AS_HELP_STRING([[--enable-md5=TYPE]],
   7456     [enable TYPE of MD5 hashing code (yes, no, builtin, tlslib, gnutls, openssl, mbedtls) [yes if dauth enabled]])],
   7457   [
   7458     AS_IF([test "X${enable_digest_auth}" != "Xyes" && test "X${enable_md5}" != "Xno"],
   7459       [
   7460         AC_MSG_WARN([The parameter --enable-md5=${enable_md5} is ignored as Digest Authentication is disabled])
   7461         enable_md5='no'
   7462       ]
   7463     )
   7464     AS_CASE([$enable_md5],
   7465       [internal],[enable_md5='builtin'],
   7466       [built-in],[enable_md5='builtin'],
   7467       [yes|no|builtin|tlslib|gnutls|openssl|mbedtls],[:],
   7468       AC_MSG_ERROR([unrecognized parameter --enable-md5=${enable_md5}])
   7469     )
   7470   ], [[enable_md5="${enable_digest_auth}"]]
   7471 )
   7472 
   7473 AS_CASE([${enable_md5}],
   7474   [builtin],[use_md5_backend='builtin'],
   7475   [no],[use_md5_backend='no'],
   7476   [AS_UNSET([use_md5_backend])]
   7477 )
   7478 AS_CASE([${enable_md5}],[yes|tlslib|gnutls|openssl|mbedtls],
   7479   [
   7480     AS_IF([test -z "${use_md5_backend}" && test "X${have_gnutls}" = "Xyes"],
   7481       [
   7482         AS_CASE([${enable_md5}],[yes|tlslib|gnutls],
   7483           [
   7484             AC_CACHE_CHECK([whether GnuTLS supports MD5 hashing],[mhd_cv_gnutls_md5],
   7485               [
   7486                 CPPFLAGS="${CPPFLAGS_ac} ${GNUTLS_CPPFLAGS} ${user_CPPFLAGS}"
   7487                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7488                 LDFLAGS="${LDFLAGS_ac} ${GNUTLS_LDFLAGS} ${user_LDFLAGS}"
   7489                 save_LIBS="$LIBS"
   7490                 LIBS="${GNUTLS_LIBS} ${LIBS}"
   7491                 AC_LINK_IFELSE(
   7492                   [
   7493                     AC_LANG_PROGRAM(
   7494                       [[
   7495 #include <gnutls/crypto.h>
   7496                       ]],
   7497                       [[
   7498     gnutls_hash_hd_t hash_handle;
   7499     unsigned char digest[16];
   7500     int exit_code;
   7501 
   7502     if (0 == gnutls_hash_init(&hash_handle, GNUTLS_DIG_MD5))
   7503     {
   7504       if (0 == gnutls_hash(hash_handle, "", 1))
   7505       {
   7506         gnutls_hash_output(hash_handle, digest);
   7507         if (0x93 == digest[0])
   7508           exit_code = 0;
   7509         else
   7510           exit_code = 7;
   7511       }
   7512       else
   7513         exit_code = 5;
   7514       gnutls_hash_deinit(hash_handle, (void *)0);
   7515     }
   7516     else
   7517       exit_code = 2;
   7518     return exit_code;
   7519                       ]]
   7520                     )
   7521                   ],
   7522                   [mhd_cv_gnutls_md5='yes'],[mhd_cv_gnutls_md5='no']
   7523                 )
   7524                 LIBS="${save_LIBS}"
   7525                 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   7526                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7527                 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   7528               ]
   7529             )
   7530             AS_VAR_IF([mhd_cv_gnutls_md5],["no"],
   7531               [AC_MSG_WARN([GnuTLS MD5 implementation is not available])],
   7532               [use_md5_backend='gnutls']
   7533             )
   7534           ]
   7535         )
   7536       ]
   7537     ) # end GnuTLS check
   7538 
   7539     # Check OpenSSL
   7540     AS_IF([test -z "${use_md5_backend}" && test "X${have_openssl}" = "Xyes"],
   7541       [
   7542         AS_CASE([${enable_md5}],[yes|tlslib|openssl],
   7543            [
   7544             AC_CACHE_CHECK([whether OpenSSL supports MD5 hashing],[mhd_cv_openssl_md5],
   7545               [
   7546                 CPPFLAGS="${CPPFLAGS_ac} ${OPENSSL_CPPFLAGS} ${user_CPPFLAGS}"
   7547                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7548                 LDFLAGS="${LDFLAGS_ac} ${OPENSSL_LDFLAGS} ${user_LDFLAGS}"
   7549                 save_LIBS="$LIBS"
   7550                 LIBS="${OPENSSL_LIBS} ${LIBS}"
   7551                 AC_LINK_IFELSE(
   7552                   [
   7553                     AC_LANG_PROGRAM(
   7554                       [[
   7555 #include <openssl/evp.h>
   7556                       ]],
   7557                       [[
   7558     EVP_MD_CTX *ctx = EVP_MD_CTX_new();
   7559     unsigned char digest[16];
   7560     unsigned int len;
   7561     if (ctx) {
   7562       EVP_DigestInit_ex(ctx, EVP_md5(), NULL);
   7563       EVP_DigestUpdate(ctx, "", 1);
   7564       EVP_DigestFinal_ex(ctx, digest, &len);
   7565       EVP_MD_CTX_free(ctx);
   7566     }
   7567                       ]]
   7568                     )
   7569                   ],
   7570                   [mhd_cv_openssl_md5='yes'],[mhd_cv_openssl_md5='no']
   7571                 )
   7572                 LIBS="${save_LIBS}"
   7573                 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   7574                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7575                 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   7576               ]
   7577             )
   7578             AS_VAR_IF([mhd_cv_openssl_md5],["no"],
   7579               [AC_MSG_WARN([OpenSSL MD5 implementation is not available])],
   7580               [use_md5_backend="openssl"]
   7581             )
   7582           ]
   7583         )
   7584       ]
   7585     ) # end OpenSSL check
   7586 
   7587     # Check MbedTLS
   7588     AS_IF([test -z "${use_md5_backend}" && test "X${have_mbedtls}" = "Xyes"],
   7589       [
   7590         AS_CASE([${enable_md5}],[yes|tlslib|mbedtls],
   7591           [
   7592             AC_CACHE_CHECK([whether MbedTLS supports MD5 hashing],[mhd_cv_mbedtls_md5],
   7593               [
   7594                 CPPFLAGS="${CPPFLAGS_ac} ${MBEDTLS_CRYPTO_CPPFLAGS} ${user_CPPFLAGS}"
   7595                 CFLAGS="${CFLAGS_ac} ${MBEDTLS_CRYPTO_CFLAGS} ${user_CFLAGS}"
   7596                 LDFLAGS="${LDFLAGS_ac} ${MBEDTLS_CRYPTO_LDFLAGS} ${user_LDFLAGS}"
   7597                 save_LIBS="$LIBS"
   7598                 LIBS="${MBEDTLS_CRYPTO_LIBS} ${LIBS}"
   7599                 AC_LINK_IFELSE(
   7600                   [
   7601                     AC_LANG_PROGRAM(
   7602                       [[
   7603 #include <mbedtls/md5.h>
   7604                       ]],
   7605                       [[
   7606     mbedtls_md5_context ctx;
   7607     unsigned char digest[16];
   7608     mbedtls_md5_init(&ctx);
   7609     mbedtls_md5_starts(&ctx);
   7610     mbedtls_md5_update(&ctx, (const unsigned char *)"", 1);
   7611     mbedtls_md5_finish(&ctx, digest);
   7612     mbedtls_md5_free(&ctx);
   7613                       ]]
   7614                     )
   7615                   ],
   7616                   [mhd_cv_mbedtls_md5='yes'],[mhd_cv_mbedtls_md5='no']
   7617                 )
   7618                 LIBS="${save_LIBS}"
   7619                 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   7620                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7621                 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   7622               ]
   7623             )
   7624             AS_VAR_IF([mhd_cv_mbedtls_md5],["no"],
   7625               [AC_MSG_WARN([MbedTLS MD5 implementation is not available])],
   7626               [use_md5_backend="mbedtls"]
   7627             )
   7628           ]
   7629         )
   7630       ]
   7631     ) # end mbedtls check
   7632 
   7633     AS_IF([test -z "${use_md5_backend}"],
   7634       [
   7635         AS_CASE([${enable_md5}],[tlslib|gnutls|openssl|mbedtls],
   7636           [AC_MSG_ERROR([selected MD5 backend (${enable_md5}) is not available])]
   7637         )
   7638       ]
   7639     )
   7640   ]
   7641 ) # end "enable_md5 in yes|tlslib|gnutls|openssl|mbedtls"
   7642 
   7643 AC_MSG_CHECKING([[for MD5 backend to use]])
   7644 AS_UNSET([enable_md5_MSG])
   7645 AS_IF([test -z "${use_md5_backend}"],
   7646   [
   7647     AS_CASE([${enable_md5}],
   7648       [yes],[use_md5_backend='builtin'],
   7649       [AC_MSG_FAILURE([configure internal error: unexpected variable value \$enable_md5=${enable_md5}])]
   7650     )
   7651   ]
   7652 )
   7653 AS_IF([test "X${enable_md5}" != "X${use_md5_backend}" && test "X${enable_md5}" != "Xyes" && test "X${enable_md5}" != "Xtlslib"],
   7654   [AC_MSG_FAILURE([configure internal error: unexpected variables values \$enable_md5=${enable_md5}; \$use_md5_backend=${use_md5_backend}])]
   7655 )
   7656 AS_IF([test "X${use_md5_backend}" != "Xno"],
   7657   [AC_DEFINE([[MHD_SUPPORT_MD5]],[[1]],
   7658       [Define to 1 if libmicrohttpd is compiled with MD5 hashing support.])])
   7659 AM_CONDITIONAL([MHD_SUPPORT_MD5], [[test "X${use_md5_backend}" != "Xno"]])
   7660 AS_IF([test "X${use_md5_backend}" = "Xbuiltin"],
   7661   [AC_DEFINE([[MHD_MD5_BUILTIN]],[[1]],
   7662       [Define to 1 if libmicrohttpd is compiled with MD5 hashing by internal code.])])
   7663 AM_CONDITIONAL([MHD_MD5_BUILTIN], [[test "X${use_md5_backend}" = "Xbuiltin"]])
   7664 AS_IF([test "X${use_md5_backend}" = "Xgnutls"],
   7665   [AC_DEFINE([[MHD_MD5_GNUTLS]],[[1]],
   7666       [Define to 1 if libmicrohttpd is compiled with MD5 hashing by GnuTLS.])])
   7667 AM_CONDITIONAL([MHD_MD5_GNUTLS],[test "X${use_md5_backend}" = "Xgnutls"])
   7668 AS_IF([test "X${use_md5_backend}" = "Xopenssl"],
   7669   [AC_DEFINE([[MHD_MD5_OPENSSL]],[[1]],
   7670       [Define to 1 if libmicrohttpd is compiled with MD5 hashing by OpenSSL.])])
   7671 AM_CONDITIONAL([MHD_MD5_OPENSSL],[test "X${use_md5_backend}" = "Xopenssl"])
   7672 AS_IF([test "X${use_md5_backend}" = "Xmbedtls"],
   7673   [AC_DEFINE([[MHD_MD5_MBEDTLS]],[[1]],
   7674       [Define to 1 if libmicrohttpd is compiled with MD5 hashing by MbedTLS.])])
   7675 AM_CONDITIONAL([MHD_MD5_MBEDTLS],[test "X${use_md5_backend}" = "Xmbedtls"])
   7676 AS_CASE([${use_md5_backend}],
   7677   [no],[enable_md5_MSG="no (disabled)"],
   7678   [builtin],[enable_md5_MSG='built-in (internal implementation)'],
   7679   [gnutls],[enable_md5_MSG='GnuTLS'],
   7680   [openssl],[enable_md5_MSG='OpenSSL'],
   7681   [mbedtls],[enable_md5_MSG='MbedTLS'],
   7682   [AC_MSG_FAILURE([configure internal error: unexpected variable value \$use_md5_backend=${use_md5_backend}])]
   7683 )
   7684 AC_MSG_RESULT([[${enable_md5_MSG}]])
   7685 
   7686 # optional: SHA-256 support for Digest Auth. Enabled by default.
   7687 AC_ARG_ENABLE([[sha256]],
   7688   [AS_HELP_STRING([[--enable-sha256=TYPE]],
   7689     [enable TYPE of SHA-256 hashing code (yes, no, builtin, tlslib, gnutls, openssl, mbedtls) [yes if dauth enabled]])],
   7690   [
   7691     AS_IF([test "X${enable_digest_auth}" != "Xyes" && test "X${enable_sha256}" != "Xno"],
   7692       [
   7693         AC_MSG_WARN([The parameter --enable-sha256=${enable_sha256} is ignored as Digest Authentication is disabled])
   7694         enable_sha256='no'
   7695       ]
   7696     )
   7697     AS_CASE([$enable_sha256],
   7698       [internal],[enable_sha256='builtin'],
   7699       [built-in],[enable_sha256='builtin'],
   7700       [yes|no|builtin|tlslib|gnutls|openssl|mbedtls],[:],
   7701       AC_MSG_ERROR([unrecognized parameter --enable-sha256=${enable_sha256}])
   7702     )
   7703   ], [[enable_sha256="${enable_digest_auth}"]]
   7704 )
   7705 
   7706 AS_CASE([${enable_sha256}],
   7707   [builtin],[use_sha256_backend='builtin'],
   7708   [no],[use_sha256_backend='no'],
   7709   [AS_UNSET([use_sha256_backend])]
   7710 )
   7711 AS_CASE([${enable_sha256}],[yes|tlslib|gnutls|openssl|mbedtls],
   7712   [
   7713     AS_IF([test -z "${use_sha256_backend}" && test "X${have_gnutls}" = "Xyes"],
   7714       [
   7715         AS_CASE([${enable_sha256}],[yes|tlslib|gnutls],
   7716           [
   7717             AC_CACHE_CHECK([whether GnuTLS supports SHA-256 hashing],[mhd_cv_gnutls_sha256],
   7718               [
   7719                 CPPFLAGS="${CPPFLAGS_ac} ${GNUTLS_CPPFLAGS} ${user_CPPFLAGS}"
   7720                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7721                 LDFLAGS="${LDFLAGS_ac} ${GNUTLS_LDFLAGS} ${user_LDFLAGS}"
   7722                 save_LIBS="$LIBS"
   7723                 LIBS="${GNUTLS_LIBS} ${LIBS}"
   7724                 AC_LINK_IFELSE(
   7725                   [
   7726                     AC_LANG_PROGRAM(
   7727                       [[
   7728 #include <gnutls/crypto.h>
   7729                       ]],
   7730                       [[
   7731     gnutls_hash_hd_t hash_handle;
   7732     unsigned char digest[32];
   7733     int exit_code;
   7734 
   7735     if (0 == gnutls_hash_init(&hash_handle, GNUTLS_DIG_SHA256))
   7736     {
   7737       if (0 == gnutls_hash(hash_handle, "", 1))
   7738       {
   7739         gnutls_hash_output(hash_handle, digest);
   7740         if (0x6e == digest[0])
   7741           exit_code = 0;
   7742         else
   7743           exit_code = 7;
   7744       }
   7745       else
   7746         exit_code = 5;
   7747       gnutls_hash_deinit(hash_handle, (void *)0);
   7748     }
   7749     else
   7750       exit_code = 2;
   7751     return exit_code;
   7752                       ]]
   7753                     )
   7754                   ],
   7755                   [mhd_cv_gnutls_sha256='yes'],[mhd_cv_gnutls_sha256='no']
   7756                 )
   7757                 LIBS="${save_LIBS}"
   7758                 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   7759                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7760                 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   7761               ]
   7762             )
   7763             AS_VAR_IF([mhd_cv_gnutls_sha256],["no"],
   7764               [AC_MSG_WARN([GnuTLS SHA-256 implementation is not available])],
   7765               [use_sha256_backend='gnutls']
   7766             )
   7767           ]
   7768         )
   7769       ]
   7770     ) # end GnuTLS check
   7771 
   7772     # Check OpenSSL
   7773     AS_IF([test -z "${use_sha256_backend}" && test "X${have_openssl}" = "Xyes"],
   7774       [
   7775         AS_CASE([${enable_sha256}],[yes|tlslib|openssl],
   7776            [
   7777             AC_CACHE_CHECK([whether OpenSSL supports SHA-256 hashing],[mhd_cv_openssl_sha256],
   7778               [
   7779                 CPPFLAGS="${CPPFLAGS_ac} ${OPENSSL_CPPFLAGS} ${user_CPPFLAGS}"
   7780                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7781                 LDFLAGS="${LDFLAGS_ac} ${OPENSSL_LDFLAGS} ${user_LDFLAGS}"
   7782                 save_LIBS="$LIBS"
   7783                 LIBS="${OPENSSL_LIBS} ${LIBS}"
   7784                 AC_LINK_IFELSE(
   7785                   [
   7786                     AC_LANG_PROGRAM(
   7787                       [[
   7788 #include <openssl/evp.h>
   7789                       ]],
   7790                       [[
   7791     EVP_MD_CTX *ctx = EVP_MD_CTX_new();
   7792     unsigned char digest[32];
   7793     unsigned int len;
   7794     if (ctx) {
   7795       EVP_DigestInit_ex(ctx, EVP_sha256(), NULL);
   7796       EVP_DigestUpdate(ctx, "", 1);
   7797       EVP_DigestFinal_ex(ctx, digest, &len);
   7798       EVP_MD_CTX_free(ctx);
   7799     }
   7800                       ]]
   7801                     )
   7802                   ],
   7803                   [mhd_cv_openssl_sha256='yes'],[mhd_cv_openssl_sha256='no']
   7804                 )
   7805                 LIBS="${save_LIBS}"
   7806                 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   7807                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7808                 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   7809               ]
   7810             )
   7811             AS_VAR_IF([mhd_cv_openssl_sha256],["no"],
   7812               [AC_MSG_WARN([OpenSSL SHA-256 implementation is not available])],
   7813               [use_sha256_backend="openssl"]
   7814             )
   7815           ]
   7816         )
   7817       ]
   7818     ) # end OpenSSL check
   7819 
   7820     # Check MbedTLS
   7821     AS_IF([test -z "${use_sha256_backend}" && test "X${have_mbedtls}" = "Xyes"],
   7822       [
   7823         AS_CASE([${enable_sha256}],[yes|tlslib|mbedtls],
   7824           [
   7825             AC_CACHE_CHECK([whether MbedTLS supports SHA-256 hashing],[mhd_cv_mbedtls_sha256],
   7826               [
   7827                 CPPFLAGS="${CPPFLAGS_ac} ${MBEDTLS_CRYPTO_CPPFLAGS} ${user_CPPFLAGS}"
   7828                 CFLAGS="${CFLAGS_ac} ${MBEDTLS_CRYPTO_CFLAGS} ${user_CFLAGS}"
   7829                 LDFLAGS="${LDFLAGS_ac} ${MBEDTLS_CRYPTO_LDFLAGS} ${user_LDFLAGS}"
   7830                 save_LIBS="$LIBS"
   7831                 LIBS="${MBEDTLS_CRYPTO_LIBS} ${LIBS}"
   7832                 AC_LINK_IFELSE(
   7833                   [
   7834                     AC_LANG_PROGRAM(
   7835                       [[
   7836 #include <mbedtls/sha256.h>
   7837                       ]],
   7838                       [[
   7839     mbedtls_sha256_context ctx;
   7840     unsigned char digest[32];
   7841     mbedtls_sha256_init(&ctx);
   7842     mbedtls_sha256_starts(&ctx, 0);
   7843     mbedtls_sha256_update(&ctx, (const unsigned char *)"", 1);
   7844     mbedtls_sha256_finish(&ctx, digest);
   7845     mbedtls_sha256_free(&ctx);
   7846                       ]]
   7847                     )
   7848                   ],
   7849                   [mhd_cv_mbedtls_sha256='yes'],[mhd_cv_mbedtls_sha256='no']
   7850                 )
   7851                 LIBS="${save_LIBS}"
   7852                 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   7853                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7854                 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   7855               ]
   7856             )
   7857             AS_VAR_IF([mhd_cv_mbedtls_sha256],["no"],
   7858               [AC_MSG_WARN([MbedTLS SHA-256 implementation is not available])],
   7859               [use_sha256_backend="mbedtls"]
   7860             )
   7861           ]
   7862         )
   7863       ]
   7864     ) # end mbedtls check
   7865 
   7866     AS_IF([test -z "${use_sha256_backend}"],
   7867       [
   7868         AS_CASE([${enable_sha256}],[tlslib|gnutls|openssl|mbedtls],
   7869           [AC_MSG_ERROR([selected SHA-256 backend (${enable_sha256}) is not available])]
   7870         )
   7871       ]
   7872     )
   7873   ]
   7874 ) # end "enable_sha256 in yes|tlslib|gnutls|openssl|mbedtls"
   7875 
   7876 AC_MSG_CHECKING([[for SHA-256 backend to use]])
   7877 AS_UNSET([enable_sha256_MSG])
   7878 AS_IF([test -z "${use_sha256_backend}"],
   7879   [
   7880     AS_CASE([${enable_sha256}],
   7881       [yes],[use_sha256_backend='builtin'],
   7882       [AC_MSG_FAILURE([configure internal error: unexpected variable value \$enable_sha256=${enable_sha256}])]
   7883     )
   7884   ]
   7885 )
   7886 AS_IF([test "X${enable_sha256}" != "X${use_sha256_backend}" && test "X${enable_sha256}" != "Xyes" && test "X${enable_sha256}" != "Xtlslib"],
   7887   [AC_MSG_FAILURE([configure internal error: unexpected variables values \$enable_sha256=${enable_sha256}; \$use_sha256_backend=${use_sha256_backend}])]
   7888 )
   7889 AS_IF([test "X${use_sha256_backend}" != "Xno"],
   7890   [AC_DEFINE([[MHD_SUPPORT_SHA256]],[[1]],
   7891       [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing support.])])
   7892 AM_CONDITIONAL([MHD_SUPPORT_SHA256], [[test "X${use_sha256_backend}" != "Xno"]])
   7893 AS_IF([test "X${use_sha256_backend}" = "Xbuiltin"],
   7894   [AC_DEFINE([[MHD_SHA256_BUILTIN]],[[1]],
   7895       [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing by internal code.])])
   7896 AM_CONDITIONAL([MHD_SHA256_BUILTIN], [[test "X${use_sha256_backend}" = "Xbuiltin"]])
   7897 AS_IF([test "X${use_sha256_backend}" = "Xgnutls"],
   7898   [AC_DEFINE([[MHD_SHA256_GNUTLS]],[[1]],
   7899       [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing by GnuTLS.])])
   7900 AM_CONDITIONAL([MHD_SHA256_GNUTLS],[test "X${use_sha256_backend}" = "Xgnutls"])
   7901 AS_IF([test "X${use_sha256_backend}" = "Xopenssl"],
   7902   [AC_DEFINE([[MHD_SHA256_OPENSSL]],[[1]],
   7903       [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing by OpenSSL.])])
   7904 AM_CONDITIONAL([MHD_SHA256_OPENSSL],[test "X${use_sha256_backend}" = "Xopenssl"])
   7905 AS_IF([test "X${use_sha256_backend}" = "Xmbedtls"],
   7906   [AC_DEFINE([[MHD_SHA256_MBEDTLS]],[[1]],
   7907       [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing by MbedTLS.])])
   7908 AM_CONDITIONAL([MHD_SHA256_MBEDTLS],[test "X${use_sha256_backend}" = "Xmbedtls"])
   7909 AS_CASE([${use_sha256_backend}],
   7910   [no],[enable_sha256_MSG="no (disabled)"],
   7911   [builtin],[enable_sha256_MSG='built-in (internal implementation)'],
   7912   [gnutls],[enable_sha256_MSG='GnuTLS'],
   7913   [openssl],[enable_sha256_MSG='OpenSSL'],
   7914   [mbedtls],[enable_sha256_MSG='MbedTLS'],
   7915   [AC_MSG_FAILURE([configure internal error: unexpected variable value \$use_sha256_backend=${use_sha256_backend}])]
   7916 )
   7917 AC_MSG_RESULT([[${enable_sha256_MSG}]])
   7918 
   7919 # optional: SHA-512/256 support for Digest Auth. Enabled by default.
   7920 AC_ARG_ENABLE([[sha512-256]],
   7921   [AS_HELP_STRING([[--enable-sha512-256=TYPE]],
   7922     [enable TYPE of SHA-512/256 hashing code (yes, no, builtin, tlslib, openssl, mbedtls) [yes if dauth enabled]])],
   7923   [
   7924     AS_IF([test "X${enable_digest_auth}" != "Xyes" && test "X${enable_sha512_256}" != "Xno"],
   7925       [
   7926         AC_MSG_WARN([The parameter --enable-sha512-256=${enable_sha512_256} is ignored as Digest Authentication is disabled])
   7927         enable_sha512_256='no'
   7928       ]
   7929     )
   7930     AS_CASE([$enable_sha512_256],
   7931       [internal],[enable_sha512_256='builtin'],
   7932       [built-in],[enable_sha512_256='builtin'],
   7933       [yes|no|builtin|tlslib|openssl|mbedtls],[:],
   7934       AC_MSG_ERROR([unrecognized parameter --enable-sha512-256=${enable_sha512_256}])
   7935     )
   7936   ], [[enable_sha512_256="${enable_digest_auth}"]]
   7937 )
   7938 
   7939 AS_CASE([${enable_sha512_256}],
   7940   [builtin],[use_sha512_256_backend='builtin'],
   7941   [no],[use_sha512_256_backend='no'],
   7942   [AS_UNSET([use_sha512_256_backend])]
   7943 )
   7944 AS_CASE([${enable_sha512_256}],[yes|tlslib|openssl|mbedtls],
   7945   [
   7946     AS_IF([test -z "${use_sha512_256_backend}" && test "X${have_openssl}" = "Xyes"],
   7947       [
   7948         AS_CASE([${enable_sha512_256}],[yes|tlslib|openssl],
   7949           [
   7950             AC_CACHE_CHECK([whether OpenSSL supports SHA-512/256 hashing],[mhd_cv_openssl_sha512_256],
   7951               [
   7952                 CPPFLAGS="${CPPFLAGS_ac} ${OPENSSL_CPPFLAGS} ${user_CPPFLAGS}"
   7953                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7954                 LDFLAGS="${LDFLAGS_ac} ${OPENSSL_LDFLAGS} ${user_LDFLAGS}"
   7955                 save_LIBS="$LIBS"
   7956                 LIBS="${OPENSSL_LIBS} ${LIBS}"
   7957                 AC_LINK_IFELSE(
   7958                   [
   7959                     AC_LANG_PROGRAM(
   7960                       [[
   7961 #include <openssl/evp.h>
   7962                       ]],
   7963                       [[
   7964     EVP_MD_CTX *ctx = EVP_MD_CTX_new();
   7965     unsigned char digest[32];
   7966     unsigned int len;
   7967     if (ctx) {
   7968       EVP_DigestInit_ex(ctx, EVP_sha512_256(), NULL);
   7969       EVP_DigestUpdate(ctx, "", 1);
   7970       EVP_DigestFinal_ex(ctx, digest, &len);
   7971       EVP_MD_CTX_free(ctx);
   7972     }
   7973                       ]]
   7974                     )
   7975                   ],
   7976                   [mhd_cv_openssl_sha512_256='yes'],[mhd_cv_openssl_sha512_256='no']
   7977                 )
   7978                 LIBS="${save_LIBS}"
   7979                 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   7980                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   7981                 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   7982               ]
   7983             )
   7984             AS_VAR_IF([mhd_cv_openssl_sha512_256],["no"],
   7985               [AC_MSG_WARN([OpenSSL SHA-512/256 implementation is not available])],
   7986               [use_sha512_256_backend="openssl"]
   7987             )
   7988           ]
   7989         )
   7990       ]
   7991     ) # end OpenSSL check
   7992 
   7993     # Check MbedTLS - the backend uses the SHA-512 implementation (with the
   7994     # SHA-512/256 initial values) and requires direct access to the internal
   7995     # state member, so the test checks exactly that.
   7996     AS_IF([test -z "${use_sha512_256_backend}" && test "X${have_mbedtls}" = "Xyes"],
   7997       [
   7998         AS_CASE([${enable_sha512_256}],[yes|tlslib|mbedtls],
   7999           [
   8000             AC_CACHE_CHECK([whether MbedTLS supports SHA-512 hashing for SHA-512/256],[mhd_cv_mbedtls_sha512],
   8001               [
   8002                 CPPFLAGS="${CPPFLAGS_ac} ${MBEDTLS_CRYPTO_CPPFLAGS} ${user_CPPFLAGS}"
   8003                 CFLAGS="${CFLAGS_ac} ${MBEDTLS_CRYPTO_CFLAGS} ${user_CFLAGS}"
   8004                 LDFLAGS="${LDFLAGS_ac} ${MBEDTLS_CRYPTO_LDFLAGS} ${user_LDFLAGS}"
   8005                 save_LIBS="$LIBS"
   8006                 LIBS="${MBEDTLS_CRYPTO_LIBS} ${LIBS}"
   8007                 AC_LINK_IFELSE(
   8008                   [
   8009                     AC_LANG_PROGRAM(
   8010                       [[
   8011 #define MBEDTLS_ALLOW_PRIVATE_ACCESS 1
   8012 #include <mbedtls/sha512.h>
   8013                       ]],
   8014                       [[
   8015     mbedtls_sha512_context ctx;
   8016     unsigned char digest[64];
   8017     /* Check whether the required internal member is really accessible */
   8018     if (sizeof(ctx.state) != 64u)
   8019       return 3;
   8020     mbedtls_sha512_init(&ctx);
   8021     mbedtls_sha512_starts(&ctx, 0);
   8022     mbedtls_sha512_update(&ctx, (const unsigned char *)"", 1);
   8023     mbedtls_sha512_finish(&ctx, digest);
   8024     mbedtls_sha512_free(&ctx);
   8025                       ]]
   8026                     )
   8027                   ],
   8028                   [mhd_cv_mbedtls_sha512='yes'],[mhd_cv_mbedtls_sha512='no']
   8029                 )
   8030                 LIBS="${save_LIBS}"
   8031                 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   8032                 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   8033                 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   8034               ]
   8035             )
   8036             AS_VAR_IF([mhd_cv_mbedtls_sha512],["no"],
   8037               [AC_MSG_WARN([MbedTLS SHA-512 implementation (for SHA-512/256) is not available])],
   8038               [use_sha512_256_backend="mbedtls"]
   8039             )
   8040           ]
   8041         )
   8042       ]
   8043     ) # end mbedtls check
   8044 
   8045     AS_IF([test -z "${use_sha512_256_backend}"],
   8046       [
   8047         AS_CASE([${enable_sha512_256}],[tlslib|openssl|mbedtls],
   8048           [AC_MSG_ERROR([selected SHA-512/256 backend (${enable_sha512_256}) is not available])]
   8049         )
   8050       ]
   8051     )
   8052   ]
   8053 ) # end "enable_sha512_256 in yes|tlslib|openssl|mbedtls"
   8054 
   8055 AC_MSG_CHECKING([[for SHA-512/256 backend to use]])
   8056 AS_UNSET([enable_sha512_256_MSG])
   8057 AS_IF([test -z "${use_sha512_256_backend}"],
   8058   [
   8059     AS_CASE([${enable_sha512_256}],
   8060       [yes],[use_sha512_256_backend='builtin'],
   8061       [AC_MSG_FAILURE([configure internal error: unexpected variable value \$enable_sha512_256=${enable_sha512_256}])]
   8062     )
   8063   ]
   8064 )
   8065 AS_IF([test "X${enable_sha512_256}" != "X${use_sha512_256_backend}" && test "X${enable_sha512_256}" != "Xyes" && test "X${enable_sha512_256}" != "Xtlslib"],
   8066   [AC_MSG_FAILURE([configure internal error: unexpected variables values \$enable_sha512_256=${enable_sha512_256}; \$use_sha512_256_backend=${use_sha512_256_backend}])]
   8067 )
   8068 AS_IF([test "X${use_sha512_256_backend}" != "Xno"],
   8069   [AC_DEFINE([[MHD_SUPPORT_SHA512_256]],[[1]],
   8070       [Define to 1 if libmicrohttpd is compiled with SHA-512/256 hashing support.])])
   8071 AM_CONDITIONAL([MHD_SUPPORT_SHA512_256], [[test "X${use_sha512_256_backend}" != "Xno"]])
   8072 AS_IF([test "X${use_sha512_256_backend}" = "Xbuiltin"],
   8073   [AC_DEFINE([[MHD_SHA512_256_BUILTIN]],[[1]],
   8074       [Define to 1 if libmicrohttpd is compiled with SHA-512/256 hashing by internal code.])])
   8075 AM_CONDITIONAL([MHD_SHA512_256_BUILTIN], [[test "X${use_sha512_256_backend}" = "Xbuiltin"]])
   8076 AS_IF([test "X${use_sha512_256_backend}" = "Xopenssl"],
   8077   [AC_DEFINE([[MHD_SHA512_256_OPENSSL]],[[1]],
   8078       [Define to 1 if libmicrohttpd is compiled with SHA-512/256 hashing by OpenSSL.])])
   8079 AM_CONDITIONAL([MHD_SHA512_256_OPENSSL],[test "X${use_sha512_256_backend}" = "Xopenssl"])
   8080 AS_IF([test "X${use_sha512_256_backend}" = "Xmbedtls"],
   8081   [AC_DEFINE([[MHD_SHA512_X_MBEDTLS]],[[1]],
   8082       [Define to 1 if libmicrohttpd is compiled with SHA-512/256 hashing by MbedTLS (using its SHA-512 implementation).])])
   8083 AM_CONDITIONAL([MHD_SHA512_X_MBEDTLS],[test "X${use_sha512_256_backend}" = "Xmbedtls"])
   8084 AS_CASE([${use_sha512_256_backend}],
   8085   [no],[enable_sha512_256_MSG="no (disabled)"],
   8086   [builtin],[enable_sha512_256_MSG='built-in (internal implementation)'],
   8087   [openssl],[enable_sha512_256_MSG='OpenSSL'],
   8088   [mbedtls],[enable_sha512_256_MSG='MbedTLS (via SHA-512)'],
   8089   [AC_MSG_FAILURE([configure internal error: unexpected variable value \$use_sha512_256_backend=${use_sha512_256_backend}])]
   8090 )
   8091 AC_MSG_RESULT([[${enable_sha512_256_MSG}]])
   8092 
   8093 
   8094 # Check if digest auth can be enabled, requires at least one hash algo
   8095 AS_IF([test "x$enable_digest_auth" != "xno"],
   8096   [
   8097     AS_IF([test "x${enable_md5}" = "xno" &&  test "x${enable_sha256}" = "xno" && test "x${enable_sha512_256}" != "xyes"],
   8098       [AC_MSG_ERROR([At least one hashing algorithm must be enabled if Digest Auth is enabled])]
   8099     )
   8100   ]
   8101 )
   8102 
   8103 
   8104 AC_CACHE_CHECK([[for calloc()]], [[mhd_cv_have_func_calloc]],
   8105   [
   8106    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
   8107 #ifdef HAVE_STDLIB_H
   8108 #include <stdlib.h>
   8109 #elif defined(HAVE_MALLOC_H)
   8110 #include <malloc.h>
   8111 #else
   8112 #include <unistd.h>
   8113 #endif
   8114        ]],[[void * ptr = calloc(1, 2); if (ptr) return 1;]])
   8115      ],
   8116      [[mhd_cv_have_func_calloc='yes']],
   8117      [[mhd_cv_have_func_calloc='no']]
   8118    )
   8119   ]
   8120 )
   8121 AS_VAR_IF([[mhd_cv_have_func_calloc]], [["yes"]],
   8122   [AC_DEFINE([[HAVE_CALLOC]], [[1]], [Define to 1 if you have the usable `calloc' function.])])
   8123 AM_CONDITIONAL([HAVE_SYS_CALLOC], [[test "x${mhd_cv_have_func_calloc}" = "xyes"]])
   8124 
   8125 # Some systems have IPv6 disabled in kernel at run-time
   8126 AS_IF([[test "x${mhd_cv_have_inet6}" = "xyes" && test "x${cross_compiling}" = "xno"]],
   8127  [
   8128    AC_CACHE_CHECK([whether IPv6 could be used for testing],[mhd_cv_ipv6_for_testing],
   8129      [
   8130        AC_RUN_IFELSE(
   8131          [
   8132            AC_LANG_SOURCE([[
   8133 #ifdef HAVE_UNISTD_H
   8134 #include <unistd.h>
   8135 #endif
   8136 #ifdef HAVE_SYS_TYPES_H
   8137 #include <sys/types.h>
   8138 #endif
   8139 #ifdef HAVE_SYS_SOCKET_H
   8140 #include <sys/socket.h>
   8141 #endif
   8142 #ifdef HAVE_WINSOCK2_H
   8143 #include <winsock2.h>
   8144 #endif
   8145 #ifdef HAVE_WS2TCPIP_H
   8146 #include <ws2tcpip.h>
   8147 #endif
   8148 #ifdef HAVE_NETINET_IN_H
   8149 #include <netinet/in.h>
   8150 #endif
   8151 #ifdef HAVE_NETINET_IP_H
   8152 #include <netinet/ip.h>
   8153 #endif
   8154 #ifdef HAVE_ARPA_INET_H
   8155 #include <arpa/inet.h>
   8156 #endif
   8157 #ifdef HAVE_NETINET_TCP_H
   8158 #include <netinet/tcp.h>
   8159 #endif
   8160 
   8161 static void zr_mem(void *ptr, socklen_t size)
   8162 { char *mem = ptr; while(size--) {mem[0] = 0; mem++;} }
   8163 
   8164 int main(void)
   8165 {
   8166   int ret = 30;
   8167   struct sockaddr_in6 sa;
   8168 #if !defined(_WIN32) || defined(__CYGWIN__)
   8169   int sckt;
   8170   const int invld_sckt = -1;
   8171 #else
   8172   SOCKET sckt;
   8173   const SOCKET invld_sckt = INVALID_SOCKET;
   8174   WSADATA wsa_data;
   8175 
   8176   WSAStartup(MAKEWORD(2, 2), &wsa_data);
   8177 #endif
   8178   zr_mem(&sa, sizeof(sa));
   8179   sa.sin6_family = AF_INET6;
   8180   sa.sin6_port = 0;
   8181   sa.sin6_addr = in6addr_loopback;
   8182 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
   8183   sa.sin6_len = sizeof(sa);
   8184 #endif
   8185   sckt = socket (PF_INET6, SOCK_STREAM, 0);
   8186   if (invld_sckt != sckt)
   8187   {
   8188     if (0 == bind (sckt, (struct sockaddr *)&sa, sizeof(sa)))
   8189     {
   8190       if (0 == listen (sckt, 1))
   8191         ret = 0;
   8192       else
   8193         ret = 1; /* listen() failed */
   8194     } else ret = 2; /* bind() failed */
   8195 #if !defined(_WIN32) || defined(__CYGWIN__)
   8196     close (sckt);
   8197 #else
   8198     closesocket (sckt);
   8199 #endif
   8200   } else ret = 3; /* socket() failed */
   8201 #if defined(_WIN32) && !defined(__CYGWIN__)
   8202   WSACleanup();
   8203 #endif
   8204   return ret;
   8205 }
   8206            ]])
   8207          ], [[mhd_cv_ipv6_for_testing="yes"]], [[mhd_cv_ipv6_for_testing="no"]], [[mhd_cv_ipv6_for_testing="no"]]
   8208        )
   8209      ]
   8210    )
   8211  ]
   8212 )
   8213 AS_VAR_IF([mhd_cv_ipv6_for_testing],["yes"],
   8214 	[AC_DEFINE([[USE_IPV6_TESTING]], [[1]], [Define to 1 if your kernel supports IPv6 and IPv6 is enabled and useful for testing.])]
   8215 )
   8216 AM_CONDITIONAL([USE_IPV6_TESTING], [[test "x$mhd_cv_ipv6_for_testing" = "xyes"]])
   8217 
   8218 
   8219 AS_VAR_IF([enable_tools],["yes"],
   8220   [
   8221     AC_CHECK_HEADERS([features.h sys/pstat.h vxCpuLib.h],[],[],[AC_INCLUDES_DEFAULT])
   8222     MHD_CHECK_DECLS([_SC_NPROCESSORS_ONLN _SC_NPROC_ONLN _SC_CRAY_NCPU _SC_NPROCESSORS_CONF \
   8223                      CTL_HW HW_NCPUONLINE HW_NCPU HW_AVAILCPU],
   8224       [[
   8225 #ifdef HAVE_SYS_TYPES_H
   8226 #include <sys/types.h>
   8227 #endif /* HAVE_SYS_TYPES_H */
   8228 #ifdef HAVE_SYS_PARAM_H
   8229 #include <sys/param.h>
   8230 #endif /* HAVE_SYS_PARAM_H */
   8231 #ifdef HAVE_SYS_SYSCTL_H
   8232 #include <sys/sysctl.h>
   8233 #endif /* HAVE_SYS_SYSCTL_H */
   8234 #ifdef HAVE_UNISTD_H
   8235 #include <unistd.h>
   8236 #endif /* HAVE_UNISTD_H */
   8237       ]]
   8238     )
   8239     MHD_CHECK_FUNC([pstat_getdynamic],[[
   8240 #include <sys/param.h>
   8241 #include <sys/pstat.h>
   8242       ]],
   8243       [[
   8244         struct pst_dynamic psd_data;
   8245         i][f (1 != pstat_getdynamic(&psd_data, sizeof(psd_data), (size_t)1, 0))
   8246           return 2;
   8247         i][f (0 >= psd_data.psd_proc_cnt)
   8248           return 3;
   8249       ]]
   8250     )
   8251     MHD_CHECK_FUNC([vxCpuEnabledGet],[[#include <vxCpuLib.h>]],
   8252       [[
   8253         cpuset_t enb_set;
   8254         enb_set = vxCpuEnabledGet();
   8255         (void) enb_set;
   8256       ]]
   8257     )
   8258     AC_CHECK_HEADERS([sched.h sys/_cpuset.h sys/cpuset.h],[],[],[AC_INCLUDES_DEFAULT])
   8259     # glibc / Linux kernel
   8260     MHD_CHECK_FUNC([getpid],[[
   8261 #ifdef HAVE_SYS_TYPES_H
   8262 #include <sys/types.h>
   8263 #endif /* HAVE_SYS_TYPES_H */
   8264 #include <unistd.h>
   8265       ]],
   8266       [[
   8267         pid_t cur_pid;
   8268         cur_pid = getpid();
   8269         (void) &cur_pid; /* Mute possible warning */
   8270       ]],
   8271       [
   8272         MHD_CHECK_FUNC([sched_getaffinity],[[
   8273 #ifdef HAVE_SYS_TYPES_H
   8274 #include <sys/types.h>
   8275 #endif /* HAVE_SYS_TYPES_H */
   8276 #include <unistd.h>
   8277 #include <sched.h>
   8278           ]],
   8279           [[
   8280             cpu_set_t cur_set;
   8281             i][f (0 != sched_getaffinity(getpid(), sizeof(cur_set), &cur_set))
   8282               return 2;
   8283             i][f (0 == CPU_SET (0, &cur_set))
   8284               return 3; /* Actually this could be a valid result */
   8285           ]],
   8286           [
   8287             MHD_CHECK_FUNC([CPU_COUNT],[[
   8288 #include <stddef.h>
   8289 #include <sched.h>
   8290               ]],
   8291               [[
   8292                 cpu_set_t cur_set;
   8293                 CPU_ZERO(&cur_set);
   8294                 i][f (0 != CPU_COUNT(&cur_set))
   8295                   return 2;
   8296               ]],
   8297               [
   8298                 MHD_CHECK_FUNC([CPU_COUNT_S],[[
   8299 #include <stddef.h>
   8300 #include <sched.h>
   8301                   ]],
   8302                   [[
   8303                     static const unsigned int set_size_cpus = 2048u;
   8304                     const size_t set_size_bytes = (size_t) CPU_ALLOC_SIZE(set_size_cpus);
   8305                     cpu_set_t *p_set;
   8306                     p_set = CPU_ALLOC(set_size_cpus);
   8307                     i][f (!p_set)
   8308                      return 2;
   8309                     CPU_ZERO_S(set_size_bytes, p_set);
   8310                     i][f (0 != CPU_COUNT_S(set_size_bytes, p_set))
   8311                     {
   8312                       CPU_FREE(p_set);
   8313                       return 3;
   8314                     }
   8315                     CPU_FREE(p_set);
   8316                   ]],
   8317                   [MHD_CHECK_DECLS([CPU_SETSIZE],[],[],[#include <sched.h>])]
   8318                 )
   8319               ]
   8320             )
   8321           ]
   8322         )
   8323         # NetBSD
   8324         # Should work only with -lrt, but actually works without it.
   8325         MHD_CHECK_FUNC([sched_getaffinity_np],[[
   8326 #ifdef HAVE_SYS_TYPES_H
   8327 #include <sys/types.h>
   8328 #endif /* HAVE_SYS_TYPES_H */
   8329 #include <unistd.h>
   8330 #include <sched.h>
   8331           ]],
   8332           [[
   8333             cpuset_t *cpuset_ptr;
   8334             cpuid_t cpu_num = 0;
   8335             cpuset_ptr = cpuset_create();
   8336             i][f (!cpuset_ptr)
   8337               return 2;
   8338             i][f (0 != sched_getaffinity_np(getpid(), cpuset_size(cpuset_ptr), cpuset_ptr))
   8339             {
   8340               cpuset_destroy(cpuset_ptr);
   8341               return 3;
   8342             }
   8343             i][f (0 >= cpuset_isset(cpu_num, cpuset_ptr))
   8344             {
   8345               cpuset_destroy(cpuset_ptr);
   8346               return 4; /* Actually this could be a valid result */
   8347             }
   8348             cpuset_destroy(cpuset_ptr);
   8349           ]]
   8350         )
   8351       ]
   8352     )
   8353     # FreeBSD
   8354     MHD_CHECK_FUNC([cpuset_getaffinity],[[
   8355 #ifdef HAVE_SYS_PARAM_H
   8356 #include <sys/param.h>
   8357 #endif /* HAVE_SYS_PARAM_H */
   8358 #include <sys/cpuset.h>
   8359       ]],
   8360       [[
   8361         cpuset_t cur_mask;
   8362         i][f (0 != cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1, sizeof(cur_mask), &cur_mask))
   8363           return 2;
   8364       ]],
   8365       [
   8366         MHD_CHECK_FUNC([CPU_COUNT],[[
   8367 #ifdef HAVE_SYS_PARAM_H
   8368 #include <sys/param.h>
   8369 #endif /* HAVE_SYS_PARAM_H */
   8370 #ifdef HAVE_SYS__CPUSET_H
   8371 #include <sys/_cpuset.h>
   8372 #endif /* HAVE_SYS_PARAM_H */
   8373 #include <sys/cpuset.h>
   8374           ]],
   8375           [[
   8376             cpuset_t test_mask;
   8377             CPU_ZERO(&test_mask);
   8378             i][f (0 !=  CPU_COUNT(&test_mask))
   8379               return 2;
   8380           ]],
   8381           [
   8382             MHD_CHECK_FUNC([CPU_COUNT_S],[[
   8383 #ifdef HAVE_SYS_PARAM_H
   8384 #include <sys/param.h>
   8385 #endif /* HAVE_SYS_PARAM_H */
   8386 #ifdef HAVE_SYS__CPUSET_H
   8387 #include <sys/_cpuset.h>
   8388 #endif /* HAVE_SYS_PARAM_H */
   8389 #include <sys/cpuset.h>
   8390               ]],
   8391               [[
   8392                 static const unsigned int max_cpu_num = 2048u;
   8393                 cpuset_t *mask_ptr;
   8394                 mask_ptr = CPU_ALLOC(max_cpu_num);
   8395                 i][f (! mask_ptr)
   8396                   return 2;
   8397                 i][f (0 != cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1,
   8398                                               CPU_ALLOC_SIZE(max_cpu_num), mask_ptr))
   8399                 {
   8400                   CPU_FREE(mask_ptr);
   8401                   return 3;
   8402                 }
   8403                 i][f (0 == CPU_COUNT_S(CPU_ALLOC_SIZE(max_cpu_num), &test_mask))
   8404                 {
   8405                   CPU_FREE(mask_ptr);
   8406                   return 4;
   8407                 }
   8408                 CPU_FREE(mask_ptr);
   8409               ]]
   8410             )
   8411           ]
   8412         )
   8413       ]
   8414     )
   8415     AS_VAR_IF([mhd_cv_have_func_CPU_COUNT_S],["yes"],
   8416       [
   8417         AC_CACHE_CHECK([whether CPU_COUNT_S() expects max CPU number as 'size' parameter],[mhd_cv_func_cpu_count_s_cpus],
   8418           [
   8419             AS_VAR_IF([cross-compiling],["yes"],[mhd_cv_func_cpu_count_s_cpus="assuming no"],
   8420               [
   8421                 AC_LINK_IFELSE(
   8422                   [
   8423                     AC_LANG_PROGRAM([[
   8424 #ifdef HAVE_SYS_TYPES_H
   8425 #include <sys/types.h>
   8426 #endif /* HAVE_SYS_TYPES_H */
   8427 #ifdef HAVE_SYS_PARAM_H
   8428 #include <sys/param.h>
   8429 #endif /* HAVE_SYS_PARAM_H */
   8430 #ifdef HAVE_SYS__CPUSET_H
   8431 #include <sys/_cpuset.h>
   8432 #endif /* HAVE_SYS_PARAM_H */
   8433 #ifdef HAVE_SYS_CPUSET_H
   8434 #include <sys/cpuset.h>
   8435 #endif /* HAVE_SYS_CPUSET_H */
   8436 #ifdef HAVE_STDDEF_H
   8437 #include <stddef.h>
   8438 #endif /* HAVE_STDDEF_H */
   8439 #ifdef HAVE_UNISTD_H
   8440 #include <unistd.h>
   8441 #endif /* HAVE_UNISTD_H */
   8442 #ifdef HAVE_SCHED_H
   8443 #include <sched.h>
   8444 #endif /* HAVE_SCHED_H */
   8445 #include <stdio.h>
   8446 
   8447 #ifdef HAVE_SCHED_GETAFFINITY
   8448 #define TEST_CPUSET_TYPE cpu_set_t
   8449 #else  /* ! HAVE_SCHED_GETAFFINITY */
   8450 #define TEST_CPUSET_TYPE cpuset_t
   8451 #endif /* ! HAVE_SCHED_GETAFFINITY */
   8452                       ]],
   8453                       [[
   8454   TEST_CPUSET_TYPE *p_testset;
   8455   /* The size of the cpuset that is larger then the test cpuset (in CPUs) */
   8456   static const unsigned int testset_size_oversized_cpus = (8 * sizeof(long)) * 1024;
   8457   const size_t testset_size_oversized_bytes = CPU_ALLOC_SIZE(testset_size_oversized_cpus);
   8458   /* The size of the test cpuset in number of CPUs */
   8459   const unsigned int testset_size_cpus = (unsigned int) testset_size_oversized_bytes;
   8460   /* The size of the test cpuset in bytes */
   8461   const size_t testset_size_bytes = CPU_ALLOC_SIZE(testset_size_cpus);
   8462   /* The last one CPU in the test set */
   8463   const unsigned int test_cpu_num1 = testset_size_cpus - 1;
   8464   /* The penultimate CPU in the test set */
   8465   const unsigned int test_cpu_num2 = testset_size_cpus - 2;
   8466   /* The CPU numbers that should be cleared */
   8467   const unsigned int test_cpu_clear1 = testset_size_cpus - 3;
   8468   const unsigned int test_cpu_clear2 = testset_size_cpus - 4;
   8469   unsigned int count_res;
   8470   int ret = 0;
   8471 
   8472   /* Allocate oversize area to ensure that memory outside the buffer is not used */
   8473   p_testset = CPU_ALLOC(testset_size_oversized_cpus);
   8474   if (! p_testset)
   8475   {
   8476     fprintf (stderr, "Error allocating memory.\n");
   8477     return 99;
   8478   }
   8479   /* Set the some CPU numbers and then clear them */
   8480   CPU_SET_S(test_cpu_clear1, testset_size_bytes, p_testset);
   8481   CPU_SET_S(test_cpu_clear2, testset_size_bytes, p_testset);
   8482   CPU_ZERO_S(testset_size_bytes, p_testset);
   8483   /* Set two CPUs on */
   8484   CPU_SET_S(test_cpu_num1, testset_size_bytes, p_testset);
   8485   CPU_SET_S(test_cpu_num2, testset_size_bytes, p_testset);
   8486   count_res = (unsigned int) CPU_COUNT_S(testset_size_bytes, p_testset);
   8487   if (0 == count_res)
   8488   {
   8489     fprintf (stderr, "Full cpuset cannot be read by CPU_COUNT_S() when using the number of bytes as the size parameter.\n");
   8490     /* Set the some CPU numbers and then clear them */
   8491     CPU_SET_S(test_cpu_clear1, testset_size_cpus, p_testset);
   8492     CPU_SET_S(test_cpu_clear2, testset_size_cpus, p_testset);
   8493     CPU_ZERO_S(testset_size_cpus, p_testset);
   8494     /* Set two CPUs on */
   8495     CPU_SET_S(test_cpu_num1, testset_size_cpus, p_testset);
   8496     CPU_SET_S(test_cpu_num2, testset_size_cpus, p_testset);
   8497     count_res = (unsigned int) CPU_COUNT_S(testset_size_cpus, p_testset);
   8498     if (2 == count_res)
   8499     {
   8500       fprintf (stderr, "Full cpuset is read by CPU_COUNT_S() only when using the maximum CPU number as the size parameter.\n");
   8501       ret = 3;
   8502     }
   8503     else
   8504     {
   8505       fprintf (stderr, "Wrong result returned by CPU_COUNT_S() when using the maximum CPU number as the size parameter.\n");
   8506       fprintf (stderr, "Number of 'enabled' CPUs: 2\n");
   8507       fprintf (stderr, "Number of counted CPUs:   %u\n", count_res);
   8508       fprintf (stderr, "CPU_COUNT_S() could be unreliable.\n");
   8509       ret = 70;
   8510     }
   8511   }
   8512   else if (2 == count_res)
   8513   {
   8514     fprintf (stderr, "Full cpuset is read by CPU_COUNT_S() when using the number of bytes as the size parameter.\n");
   8515   }
   8516   else
   8517   {
   8518     fprintf (stderr, "Wrong result returned by CPU_COUNT_S() when using the number of bytes as the size parameter.\n");
   8519     fprintf (stderr, "Number of 'enabled' CPUs: 2\n");
   8520     fprintf (stderr, "Number of counted CPUs:   %u\n", count_res);
   8521     fprintf (stderr, "CPU_COUNT_S() could be unreliable.\n");
   8522     ret = 71;
   8523   }
   8524   CPU_FREE(p_testset);
   8525   if (0 != ret)
   8526     return ret;
   8527                       ]]
   8528                     )
   8529                   ],
   8530                   [
   8531                     AM_RUN_LOG([./conftest$EXEEXT])
   8532                     count_test_res=$?
   8533                     AS_IF([test $count_test_res -eq 0],[mhd_cv_func_cpu_count_s_cpus="no"],
   8534                       [test $count_test_res -eq 3],[mhd_cv_func_cpu_count_s_cpus="yes"],
   8535                       [
   8536                         AC_MSG_WARN([Unexpected value returned by CPU_COUNT_S() test program. Please report to ${PACKAGE_BUGREPORT}])
   8537                         mhd_cv_func_cpu_count_s_cpus="assuming no"
   8538                       ]
   8539                     )
   8540                   ],
   8541                   [
   8542                     AC_MSG_WARN([Cannot build CPU_COUNT_S() test program. Please report to ${PACKAGE_BUGREPORT}])
   8543                     mhd_cv_func_cpu_count_s_cpus="assuming no"
   8544                   ]
   8545                 )
   8546               ]
   8547             )
   8548           ]
   8549         )
   8550         AS_VAR_IF([mhd_cv_func_cpu_count_s_cpus],["yes"],
   8551           [AC_DEFINE([MHD_FUNC_CPU_COUNT_S_GETS_CPUS],[1],
   8552              [Define to '1' if CPU_COUNT_S() function expects max CPU number as 'size' parameter])
   8553           ]
   8554         )
   8555       ]
   8556     )
   8557   ]
   8558 )
   8559 
   8560 # Check for fork() and waitpid(). They are used for tests.
   8561 AC_MSG_CHECKING([[for fork()]])
   8562 mhd_have_fork_waitpid='no'
   8563 AC_LINK_IFELSE(
   8564   [
   8565    AC_LANG_PROGRAM(
   8566      [[
   8567 #ifdef HAVE_SYS_TYPES_H
   8568 #include <sys/types.h>
   8569 #endif
   8570 #ifdef HAVE_UNISTD_H
   8571 #include <unistd.h>
   8572 #endif
   8573      ]], [[
   8574   pid_t p = fork ();
   8575   if (0 == p)
   8576     return 1;
   8577      ]])
   8578   ], [
   8579    AC_DEFINE([[HAVE_FORK]], [[1]], [Define to 1 if you have the usable `fork' function.])
   8580    AC_MSG_RESULT([[yes]])
   8581 
   8582    AC_MSG_CHECKING([[for waitpid()]])
   8583    AC_LINK_IFELSE(
   8584      [
   8585       AC_LANG_PROGRAM(
   8586         [[
   8587 #ifdef HAVE_SYS_TYPES_H
   8588 #include <sys/types.h>
   8589 #endif
   8590 #ifdef HAVE_UNISTD_H
   8591 #include <unistd.h>
   8592 #endif
   8593 #include <sys/wait.h>
   8594         ]], [[
   8595      pid_t p = fork ();
   8596      if (0 == p)
   8597        return 1;
   8598      waitpid (p, (void*)0, 0)
   8599         ]])
   8600      ], [
   8601       AC_DEFINE([[HAVE_WAITPID]], [[1]], [Define to 1 if you have the usable `waitpid' function.])
   8602       AC_MSG_RESULT([[yes]])
   8603       mhd_have_fork_waitpid='yes'
   8604     ],[
   8605        AC_MSG_RESULT([[no]])
   8606     ])
   8607 ],[
   8608    AC_MSG_RESULT([[no]])
   8609 ])
   8610 
   8611 AM_CONDITIONAL([HAVE_FORK_WAITPID], [test "x$mhd_have_fork_waitpid" = "xyes"])
   8612 
   8613 
   8614 # Other stuff used in testing
   8615 
   8616 MHD_CHECK_FUNC([mkostemp],
   8617   [[
   8618 #if defined(HAVE_STDLIB_H)
   8619 #  include <stdlib.h>
   8620 #endif
   8621 #if defined(HAVE_UNISTD_H)
   8622 /* On Darwin mkostemp() is declared in unistd.h */
   8623 #  include <unistd.h>
   8624 #endif
   8625 #include <fcntl.h>
   8626   ]],
   8627   [[
   8628   char tmp_fname[] = "/tmp/mhd-test-XXXXXX";
   8629   int tmp_fd = mkostemp(tmp_fname, 0);
   8630   i][f (0 > tmp_fd)
   8631     return 3;
   8632   close(tmp_fd);
   8633   ]],
   8634   [],
   8635   [
   8636     MHD_CHECK_FUNC([mkstemp],
   8637       [[
   8638 #if defined(HAVE_STDLIB_H)
   8639 #  include <stdlib.h>
   8640 #endif
   8641 #if defined(HAVE_UNISTD_H)
   8642 #  include <unistd.h>
   8643 #endif
   8644       ]],
   8645       [[
   8646   char tmp_fname[] = "/tmp/mhd-test-XXXXXX";
   8647   int tmp_fd = mkstemp(tmp_fname);
   8648   i][f (0 > tmp_fd)
   8649     return 3;
   8650   close(tmp_fd);
   8651       ]]
   8652     )
   8653   ]
   8654 )
   8655 
   8656 # gcov compilation
   8657 AC_MSG_CHECKING(whether to compile with support for code coverage analysis)
   8658 AC_ARG_ENABLE([coverage],
   8659               AS_HELP_STRING([--enable-coverage],
   8660                              [compile the library with code coverage support]),
   8661               [use_gcov=${enableval}],
   8662               [use_gcov=no])
   8663 AC_MSG_RESULT($use_gcov)
   8664 AM_CONDITIONAL([USE_COVERAGE], [test "x$use_gcov" = "xyes"])
   8665 
   8666 AX_COUNT_CPUS
   8667 AC_SUBST([MHD_REAL_CPU_COUNT],[${CPU_COUNT}])
   8668 AM_SUBST_NOTMAKE([MHD_REAL_CPU_COUNT])
   8669 AC_MSG_CHECKING([for number of CPU cores to use in tests])
   8670 AS_VAR_IF([use_heavy_tests], ["yes"],
   8671   [
   8672     # Enable usage of many core if heavy tests are enabled
   8673     AS_IF([[test "$CPU_COUNT" -gt "32"]], [[CPU_COUNT="32"]])dnl Limit resource usage
   8674   ],
   8675   [
   8676     # Limit usage to just a few cores if heavy tests are not enabled
   8677     AS_IF([[test "$CPU_COUNT" -gt "6"]], [[CPU_COUNT="6"]])
   8678     AS_IF([[test "$CPU_COUNT" -lt "2"]], [[CPU_COUNT="2"]])
   8679   ]
   8680 )
   8681 AC_MSG_RESULT([$CPU_COUNT])
   8682 
   8683 
   8684 AC_ARG_ENABLE([[asserts]],
   8685   [AS_HELP_STRING([[--enable-asserts]],
   8686     [enable test build with debug asserts])],
   8687   [],
   8688   [enable_asserts='auto']
   8689 )
   8690 AS_UNSET([use_asserts_MSG])
   8691 AC_CACHE_CHECK([[whether NDEBUG macro is defined]], [mhd_cv_macro_ndebug_def],
   8692   [
   8693     AC_LINK_IFELSE(
   8694       [
   8695         AC_LANG_SOURCE([[
   8696 #ifndef NDEBUG
   8697 #error NDEBUG is NOT defined
   8698 chome me now
   8699 #endif
   8700 
   8701 int main(void)
   8702 {
   8703   return 0;
   8704 }
   8705           ]]
   8706         )
   8707       ],
   8708       [[mhd_cv_macro_ndebug_def='yes']],
   8709       [[mhd_cv_macro_ndebug_def='no']]
   8710     )
   8711   ]
   8712 )
   8713 AS_VAR_IF([enable_asserts],["yes"],
   8714   [
   8715     AS_VAR_IF([mhd_cv_macro_ndebug_def],["yes"],
   8716       [
   8717         AC_MSG_FAILURE([Parameter --enable-asserts is specified, but NDEBUG macro is defined as well])
   8718       ]
   8719     )
   8720     use_asserts_MSG="yes, enabled by configure parameter"
   8721   ]
   8722 )
   8723 AC_CACHE_CHECK([[whether _DEBUG macro is defined]], [mhd_cv_macro__debug_def],
   8724   [
   8725     AC_LINK_IFELSE(
   8726       [
   8727         AC_LANG_SOURCE([[
   8728 #ifndef _DEBUG
   8729 #error _DEBUG is NOT defined
   8730 chome me now
   8731 #endif
   8732 
   8733 int main(void)
   8734 {
   8735   return 0;
   8736 }
   8737           ]]
   8738         )
   8739       ],
   8740       [[mhd_cv_macro__debug_def='yes']],
   8741       [[mhd_cv_macro__debug_def='no']]
   8742     )
   8743   ]
   8744 )
   8745 AS_VAR_IF([enable_asserts],["no"],
   8746   [
   8747     AS_VAR_IF([mhd_cv_macro__debug_def],["yes"],
   8748       [
   8749         AC_MSG_FAILURE([Parameter --disable-asserts is specified, but _DEBUG macro is defined as well])
   8750       ]
   8751     )
   8752     use_asserts_MSG="no, set by configure parameter"
   8753   ]
   8754 )
   8755 AS_IF([test "x${mhd_cv_macro_ndebug_def}" = "xyes" && test "x${mhd_cv_macro__debug_def}" = "xyes"],
   8756   [AC_MSG_FAILURE([Both NDEBUG and _DEBUG macros are defined])]
   8757 )
   8758 AS_VAR_IF([enable_asserts],["auto"],
   8759   [
   8760     AS_VAR_IF([mhd_cv_macro_ndebug_def],["yes"],
   8761       [
   8762         enable_asserts="no"
   8763         use_asserts_MSG="no, set by NDEBUG preprocessor macro"
   8764       ]
   8765     )
   8766   ]
   8767 )
   8768 AS_VAR_IF([enable_asserts],["auto"],
   8769   [
   8770     AS_VAR_IF([mhd_cv_macro__debug_def],["yes"],
   8771       [
   8772         enable_asserts="yes"
   8773         use_asserts_MSG="yes, enabled by _DEBUG preprocessor macro"
   8774       ]
   8775     )
   8776   ]
   8777 )
   8778 AS_VAR_IF([enable_asserts],["auto"],
   8779   [
   8780     AC_CACHE_CHECK([[whether DEBUG macro is defined]], [mhd_cv_macro_debug_def],
   8781       [
   8782         AC_LINK_IFELSE(
   8783           [
   8784             AC_LANG_SOURCE([[
   8785 #ifndef DEBUG
   8786 #error DEBUG is NOT defined
   8787 chome me now
   8788 #endif
   8789 
   8790 int main(void)
   8791 {
   8792   return 0;
   8793 }
   8794               ]]
   8795             )
   8796           ],
   8797           [[mhd_cv_macro_debug_def='yes']],
   8798           [[mhd_cv_macro_debug_def='no']]
   8799         )
   8800       ]
   8801     )
   8802     AS_VAR_IF([mhd_cv_macro_debug_def],["yes"],
   8803       [
   8804         enable_asserts="yes"
   8805         use_asserts_MSG="yes, enabled by DEBUG preprocessor macro"
   8806       ]
   8807     )
   8808   ]
   8809 )
   8810 AC_MSG_CHECKING([[whether to enable debug asserts]])
   8811 AS_VAR_IF([enable_asserts],["auto"],
   8812   [
   8813     AS_CASE([${enable_build_type}],
   8814       [debug|debugger|trace],
   8815       [
   8816         enable_asserts="yes"
   8817         use_asserts_MSG="yes, enabled by --enable-bulid-type=${enable_build_type}"
   8818       ],
   8819       [
   8820         enable_asserts="no"
   8821         use_asserts_MSG="no"
   8822       ]
   8823     )
   8824   ]
   8825 )
   8826 AS_CASE([[$enable_asserts]], [[yes]], [[:]], [[no]], [[:]], [[enable_asserts='no']])
   8827 AC_MSG_RESULT([[${use_asserts_MSG=no}]])
   8828 
   8829 AS_VAR_IF([[enable_asserts]], [["yes"]],
   8830   [
   8831     AS_VAR_IF([[mhd_cv_macro__debug_def]], [["yes"]], [:],
   8832       [
   8833         MHD_PREPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-D_DEBUG=1])
   8834         CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   8835       ]
   8836     )
   8837     AC_CACHE_CHECK([[whether system assert() is available]], [mhd_cv_sys_assert_avail],
   8838       [
   8839         AC_LINK_IFELSE(
   8840           [
   8841             AC_LANG_SOURCE([[
   8842 #include <assert.h>
   8843 
   8844 static int pos_val(void) {return 5;}
   8845 static int neg_val(void) {return -5;}
   8846 int main(void)
   8847 {
   8848   int pos_var = pos_val(), neg_var = neg_val();
   8849   assert(neg_var > pos_var); /* Must trigger assert. */
   8850   return pos_var + neg_var;
   8851 }
   8852             ]])
   8853           ],
   8854           [[mhd_cv_sys_assert_avail='yes']],
   8855           [[mhd_cv_sys_assert_avail='no']]
   8856         )
   8857       ]
   8858     )
   8859     AS_VAR_IF([[mhd_cv_sys_assert_avail]], [["no"]], [],
   8860       [AC_DEFINE([[HAVE_ASSERT]], [[1]], [Define if you have usable assert() and assert.h])])
   8861   ],
   8862   [
   8863     AS_VAR_IF([[mhd_cv_macro_ndebug_def]], [["yes"]], [:],
   8864       [
   8865         MHD_PREPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DNDEBUG=1])
   8866         CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
   8867       ]
   8868     )
   8869   ]
   8870 )
   8871 
   8872 AC_ARG_ENABLE([[trace-fds-polling]],
   8873   [AS_HELP_STRING([[--enable-trace-fds-polling]],
   8874     [enable test build with debug printing of FDs polling])],
   8875   [
   8876     AS_CASE([${enable_trace_fds_polling}],
   8877       [yes|no],[:],
   8878       [AC_MSG_ERROR([wrong parameter --enable-trace-fds-polling=${enable_trace_fds_polling}])]
   8879     )
   8880   ],
   8881   [enable_trace_fds_polling='auto']
   8882 )
   8883 AS_UNSET([use_trace_fds_polling_MSG])
   8884 AS_UNSET([use_trace_fds_polling])
   8885 AC_CACHE_CHECK([[whether MHD_USE_TRACE_POLLING_FDS macro is defined]], [mhd_cv_macro_trace_polling_fds_def],
   8886   [
   8887     AC_LINK_IFELSE(
   8888       [
   8889         AC_LANG_SOURCE([[
   8890 #ifndef MHD_USE_TRACE_POLLING_FDS
   8891 #error MHD_USE_TRACE_POLLING_FDS is NOT defined
   8892 chome me now
   8893 #endif
   8894 
   8895 int main(void)
   8896 { return 0; }
   8897           ]]
   8898         )
   8899       ],
   8900       [[mhd_cv_macro_trace_polling_fds_def='yes']],
   8901       [[mhd_cv_macro_trace_polling_fds_def='no']]
   8902     )
   8903   ]
   8904 )
   8905 AC_MSG_CHECKING([whether to enable debug-print of FDs polling])
   8906 AS_VAR_IF([mhd_cv_macro_trace_polling_fds_def],["yes"],
   8907   [
   8908     use_trace_fds_polling="yes"
   8909     use_trace_fds_polling_MSG="yes, forced by MHD_USE_TRACE_POLLING_FDS macro"
   8910   ]
   8911 )
   8912 AS_VAR_SET_IF([use_trace_fds_polling],[:],
   8913   [
   8914     AS_CASE([${enable_trace_fds_polling}],
   8915       [yes],[
   8916         use_trace_fds_polling="yes"
   8917         use_trace_fds_polling_MSG="yes, enabled by --enable-trace-fds-polling"
   8918       ],
   8919       [no],[
   8920         use_trace_fds_polling="no"
   8921         use_trace_fds_polling_MSG="no, disabled by --disable-trace-fds-polling"
   8922       ],
   8923       [auto],[
   8924         AS_CASE([${enable_build_type}],
   8925           [trace],[
   8926             use_trace_fds_polling="yes"
   8927             use_trace_fds_polling_MSG="yes, enabled by --enable-bulid-type=${enable_build_type}"
   8928           ],
   8929           [
   8930             use_trace_fds_polling="no"
   8931             use_trace_fds_polling_MSG="no"
   8932           ]
   8933         )
   8934       ],
   8935       [AC_MSG_FAILURE([configure is broken])]
   8936     )
   8937   ]
   8938 )
   8939 AS_IF([test "X${use_trace_fds_polling}" = "Xyes" && test "X${mhd_cv_macro_trace_polling_fds_def}" != "Xyes"],
   8940   [AC_DEFINE([[MHD_USE_TRACE_POLLING_FDS]], [[1]], [Define to enable debug-print of FDs polling])]
   8941 )
   8942 test -n "${use_trace_fds_polling_MSG}" || use_trace_fds_polling_MSG}="${use_trace_fds_polling}"
   8943 AC_MSG_RESULT([${use_trace_fds_polling_MSG}])
   8944 
   8945 AC_ARG_ENABLE([[trace-conn-add-close]],
   8946   [AS_HELP_STRING([[--enable-trace-conn-add-close]],
   8947     [enable test build with debug printing of connections adding and closing])],
   8948   [
   8949     AS_CASE([${enable_trace_conn_add_close}],
   8950       [yes|no],[:],
   8951       [AC_MSG_ERROR([wrong parameter --enable-trace-conn-add-close=${enable_trace_conn_add_close}])]
   8952     )
   8953   ],
   8954   [enable_trace_conn_add_close='auto']
   8955 )
   8956 AS_UNSET([use_trace_conn_add_close_MSG])
   8957 AS_UNSET([use_trace_conn_add_close])
   8958 AC_CACHE_CHECK([[whether MHD_USE_TRACE_CONN_ADD_CLOSE macro is defined]],
   8959   [mhd_cv_macro_trace_conn_add_close_def],
   8960   [
   8961     AC_LINK_IFELSE(
   8962       [
   8963         AC_LANG_SOURCE([[
   8964 #ifndef MHD_USE_TRACE_CONN_ADD_CLOSE
   8965 #error MHD_USE_TRACE_CONN_ADD_CLOSE is NOT defined
   8966 chome me now
   8967 #endif
   8968 
   8969 int main(void)
   8970 { return 0; }
   8971           ]]
   8972         )
   8973       ],
   8974       [[mhd_cv_macro_trace_conn_add_close_def='yes']],
   8975       [[mhd_cv_macro_trace_conn_add_close_def='no']]
   8976     )
   8977   ]
   8978 )
   8979 AC_MSG_CHECKING([whether to enable debug-print of of connections adding and closing])
   8980 AS_VAR_IF([mhd_cv_macro_trace_conn_add_close_def],["yes"],
   8981   [
   8982     use_trace_conn_add_close="yes"
   8983     use_trace_conn_add_close_MSG="yes, forced by MHD_USE_TRACE_CONN_ADD_CLOSE macro"
   8984   ]
   8985 )
   8986 AS_VAR_SET_IF([use_trace_conn_add_close],[:],
   8987   [
   8988     AS_CASE([${enable_trace_conn_add_close}],
   8989       [yes],[
   8990         use_trace_conn_add_close="yes"
   8991         use_trace_conn_add_close_MSG="yes, enabled by --enable-trace-conn-add-close"
   8992       ],
   8993       [no],[
   8994         use_trace_conn_add_close="no"
   8995         use_trace_conn_add_close_MSG="no, disabled by --disable-trace-conn-add-close"
   8996       ],
   8997       [auto],[
   8998         AS_CASE([${enable_build_type}],
   8999           [trace],[
   9000             use_trace_conn_add_close="yes"
   9001             use_trace_conn_add_close_MSG="yes, enabled by --enable-bulid-type=${enable_build_type}"
   9002           ],
   9003           [
   9004             use_trace_conn_add_close="no"
   9005             use_trace_conn_add_close_MSG="no"
   9006           ]
   9007         )
   9008       ],
   9009       [AC_MSG_FAILURE([configure is broken])]
   9010     )
   9011   ]
   9012 )
   9013 AS_IF([test "X${use_trace_conn_add_close}" = "Xyes" && test "X${mhd_cv_macro_trace_conn_add_close_def}" != "Xyes"],
   9014   [AC_DEFINE([[MHD_USE_TRACE_CONN_ADD_CLOSE]], [[1]], [Define to enable debug-print of connection adding and closing])]
   9015 )
   9016 test -n "${use_trace_conn_add_close_MSG}" || use_trace_conn_add_close_MSG="${use_trace_conn_add_close}"
   9017 AC_MSG_RESULT([${use_trace_conn_add_close_MSG}])
   9018 
   9019 AC_ARG_ENABLE([[trace-suspend-resume]],
   9020   [AS_HELP_STRING([[--enable-trace-suspend-resume]],
   9021     [enable test build with debug printing of requests suspending and resuming])],
   9022   [
   9023     AS_CASE([${enable_trace_suspend_resume}],
   9024       [yes|no],[:],
   9025       [AC_MSG_ERROR([wrong parameter --enable-trace-suspend-resume=${enable_trace_suspend_resume}])]
   9026     )
   9027   ],
   9028   [enable_trace_suspend_resume='auto']
   9029 )
   9030 AS_UNSET([use_trace_suspend_resume_MSG])
   9031 AS_UNSET([use_trace_suspend_resume])
   9032 AC_CACHE_CHECK([[whether MHD_USE_TRACE_SUSPEND_RESUME macro is defined]],
   9033   [mhd_cv_macro_trace_suspend_resume_def],
   9034   [
   9035     AC_LINK_IFELSE(
   9036       [
   9037         AC_LANG_SOURCE([[
   9038 #ifndef MHD_USE_TRACE_SUSPEND_RESUME
   9039 #error MHD_USE_TRACE_SUSPEND_RESUME is NOT defined
   9040 chome me now
   9041 #endif
   9042 
   9043 int main(void)
   9044 { return 0; }
   9045           ]]
   9046         )
   9047       ],
   9048       [[mhd_cv_macro_trace_suspend_resume_def='yes']],
   9049       [[mhd_cv_macro_trace_suspend_resume_def='no']]
   9050     )
   9051   ]
   9052 )
   9053 AC_MSG_CHECKING([whether to enable debug-print of of requests suspending and resuming])
   9054 AS_VAR_IF([mhd_cv_macro_trace_suspend_resume_def],["yes"],
   9055   [
   9056     use_trace_suspend_resume="yes"
   9057     use_trace_suspend_resume_MSG="yes, forced by MHD_USE_TRACE_SUSPEND_RESUME macro"
   9058   ]
   9059 )
   9060 AS_VAR_SET_IF([use_trace_suspend_resume],[:],
   9061   [
   9062     AS_CASE([${enable_trace_suspend_resume}],
   9063       [yes],[
   9064         use_trace_suspend_resume="yes"
   9065         use_trace_suspend_resume_MSG="yes, enabled by --enable-trace-suspend-resume"
   9066       ],
   9067       [no],[
   9068         use_trace_suspend_resume="no"
   9069         use_trace_suspend_resume_MSG="no, disabled by --disable-trace-suspend-resume"
   9070       ],
   9071       [auto],[
   9072         AS_CASE([${enable_build_type}],
   9073           [trace],[
   9074             use_trace_suspend_resume="yes"
   9075             use_trace_suspend_resume_MSG="yes, enabled by --enable-bulid-type=${enable_build_type}"
   9076           ],
   9077           [
   9078             use_trace_suspend_resume="no"
   9079             use_trace_suspend_resume_MSG="no"
   9080           ]
   9081         )
   9082       ],
   9083       [AC_MSG_FAILURE([configure is broken])]
   9084     )
   9085   ]
   9086 )
   9087 AS_IF([test "X${use_trace_suspend_resume}" = "Xyes" && test "X${mhd_cv_macro_trace_suspend_resume_def}" != "Xyes"],
   9088   [AC_DEFINE([[MHD_USE_TRACE_SUSPEND_RESUME]], [[1]], [Define to enable debug-print of requests suspending and resuming])]
   9089 )
   9090 test -n "${use_trace_suspend_resume_MSG}" || use_trace_suspend_resume_MSG="${use_trace_suspend_resume}"
   9091 AC_MSG_RESULT([${use_trace_suspend_resume_MSG}])
   9092 
   9093 AS_UNSET([enabled_sanitizers])
   9094 TESTS_ENVIRONMENT_ac=""
   9095 AM_ASAN_OPTIONS=""
   9096 AM_UBSAN_OPTIONS=""
   9097 AM_LSAN_OPTIONS=""
   9098 AS_UNSET([ASAN_OPTIONS])
   9099 AS_UNSET([UBSAN_OPTIONS])
   9100 AS_UNSET([LSAN_OPTIONS])
   9101 
   9102 AC_MSG_CHECKING([whether to enable run-time sanitizers])
   9103 AC_ARG_ENABLE([sanitizers],
   9104   [AS_HELP_STRING([[--enable-sanitizers[=address,undefined,leak,user-poison]]],
   9105   [enable run-time sanitizers, specify the list of types of sanitizers to enable, ]
   9106   [leave the list empty (or set to "auto") to enable all supported and available ]
   9107   [sanitizers, or specify "auto-fallback" to use sanitizers even without ]
   9108   [installed sanitizer run-time library])],
   9109   [], [AS_CASE([${enable_build_type}],[debug],
   9110     [enable_sanitizers='auto-optional'],[enable_sanitizers='no'])]
   9111 )
   9112 AS_IF([test "x${enable_sanitizers}" = "x"], [enable_sanitizers="auto"])
   9113 AS_VAR_IF([enable_sanitizers], ["yes"], [enable_sanitizers="auto"])
   9114 AS_VAR_IF([enable_sanitizers], ["autofallback"], [enable_sanitizers="auto-fallback"])
   9115 AS_VAR_IF([enable_sanitizers], ["autooptional"], [enable_sanitizers="auto-optional"])
   9116 AS_IF([test "x${enable_sanitizers}" = "xno"],
   9117   [
   9118     enable_sanitizers="no"
   9119     enable_san_address="no"
   9120     enable_san_undef="no"
   9121     enable_san_leak="no"
   9122     enable_san_upoison="no"
   9123   ],
   9124   [test "x${enable_sanitizers}" = "xauto" || test "x${enable_sanitizers}" = "xauto-optional"],
   9125   [
   9126     AS_VAR_IF([enable_compiler_hardening],["yes"],
   9127       [
   9128         AS_VAR_IF([enable_sanitizers],["auto"],
   9129           [AC_MSG_ERROR([sanitizers cannot be enabled with compiler hardening])],
   9130           [AC_MSG_WARN([sanitizers cannot be enabled with compiler hardening])]
   9131         )
   9132         enable_sanitizers="no"
   9133         enable_san_address="no"
   9134         enable_san_undef="no"
   9135         enable_san_leak="no"
   9136         enable_san_upoison="no"
   9137       ],
   9138       [
   9139         enable_san_address="auto"
   9140         enable_san_undef="auto"
   9141         enable_san_leak="auto"
   9142         enable_san_upoison="auto"
   9143       ]
   9144     )
   9145   ],
   9146   [test "x${enable_sanitizers}" = "xauto-fallback"],
   9147   [
   9148     enable_san_address="auto"
   9149     enable_san_undef="auto-fallback"
   9150     enable_san_leak="auto"
   9151     enable_san_upoison="auto"
   9152   ],
   9153   [
   9154     AS_UNSET([san])
   9155     enable_san_address="no"
   9156     enable_san_undef="no"
   9157     enable_san_leak="no"
   9158     enable_san_upoison="no"
   9159     f][or san in `AS_ECHO([${enable_sanitizers}]) | tr ',' ' '`
   9160     do
   9161       AS_CASE([$san],
   9162         [address], [enable_san_address="yes"],
   9163         [undefined], [enable_san_undef="yes"],
   9164         [leak], [enable_san_leak="yes"],
   9165         [user-poison|user_poison], [enable_san_upoison="yes"],
   9166         [no|yes|auto|auto-fallback|autofallback], [AC_MSG_ERROR(["$san" cannot be used with other options for --enable-sanitizers=])],
   9167         [AC_MSG_ERROR([Unknown parameter "$san" for --enable-sanitizers=])]
   9168       )
   9169     done
   9170     AS_IF([test "x${enable_san_upoison}" = "xyes" && test "x${enable_san_address}" = "xno"],
   9171       [AC_MSG_ERROR([User memory poisoning cannot be used without address sanitizer])]
   9172     )
   9173     enable_sanitizers="selected"
   9174   ]
   9175 )
   9176 AS_CASE([${enable_sanitizers}],
   9177   [selected], [AC_MSG_RESULT([selected])],
   9178   [auto], [AC_MSG_RESULT([yes, detect and use supported sanitizers])],
   9179   [auto-fallback], [AC_MSG_RESULT([yes, detect and use supported sanitizers even without run-time lib])],
   9180   [auto-optional], [AC_MSG_RESULT([yes, detect and use supported sanitizers if any])],
   9181   [AC_MSG_RESULT([no])]
   9182 )
   9183 AS_VAR_IF([enable_sanitizers], ["no"], [:],
   9184  [
   9185    AS_UNSET([san_FLAGS]) # the sanitizer flags to be added to both CFLAGS and LDFLAGS
   9186    AS_UNSET([san_CFLAGS]) # the sanitizer flags to be added to CFLAGS
   9187    AC_CACHE_CHECK([whether '-fsanitize=' works for $CC],
   9188      [mhd_cv_cc_sanitizer_works],
   9189      [
   9190        CFLAGS="${CFLAGS_ac} -fsanitize=wrongFeatureName ${user_CFLAGS}"
   9191        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
   9192          [mhd_cv_cc_sanitizer_works=no], [mhd_cv_cc_sanitizer_works=yes])
   9193      ]
   9194    )
   9195    AS_VAR_IF([mhd_cv_cc_sanitizer_works], ["yes"],
   9196      [
   9197        AS_VAR_IF([enable_san_address], ["no"], [:],
   9198          [
   9199            AC_CACHE_CHECK([for address sanitizer], [mhd_cv_cc_sanitizer_address],
   9200              [
   9201                CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=address ${user_CFLAGS}"
   9202                AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
   9203                 [mhd_cv_cc_sanitizer_address=yes], [mhd_cv_cc_sanitizer_address=no])
   9204              ]
   9205            )
   9206            AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"],
   9207              [
   9208                AC_DEFINE([MHD_ASAN_ACTIVE], [1], [Define to '1' if you have address sanitizer enabled])
   9209                AX_APPEND_FLAG([-fsanitize=address], [san_FLAGS])
   9210                enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }address"
   9211                AS_VAR_IF([enable_san_leak], ["no"], [:],
   9212                  [
   9213                    AC_CACHE_CHECK([whether leak detect is not rejected by address sanitizer], [mhd_cv_cc_sanitizer_address_leak],
   9214                      [
   9215                        CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${user_CFLAGS}"
   9216                        ASAN_OPTIONS="exitcode=88:detect_leaks=1:halt_on_error=1"
   9217                        export ASAN_OPTIONS
   9218                        AC_RUN_IFELSE([AC_LANG_PROGRAM([],[])],
   9219                          [mhd_cv_cc_sanitizer_address_leak=yes], [mhd_cv_cc_sanitizer_address_leak=no],
   9220                          [
   9221                            # Cross-compiling with sanitizers?
   9222                            mhd_cv_cc_sanitizer_address_leak='assuming no'
   9223                          ]
   9224                        )
   9225                        AS_UNSET([ASAN_OPTIONS])
   9226                      ]
   9227                    )
   9228                  ]
   9229                )
   9230                AC_CACHE_CHECK([for pointer compare sanitizer], [mhd_cv_cc_sanitizer_pointer_compare],
   9231                  [
   9232                    CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-compare ${user_CFLAGS}"
   9233                    AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
   9234                     [mhd_cv_cc_sanitizer_pointer_compare=yes], [mhd_cv_cc_sanitizer_pointer_compare=no])
   9235                  ]
   9236                )
   9237                AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_compare],["yes"],
   9238                  [
   9239                    AX_APPEND_FLAG([-fsanitize=pointer-compare], [san_FLAGS])
   9240                    enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer compare"
   9241                  ]
   9242                )
   9243                AC_CACHE_CHECK([for pointer subtract sanitizer], [mhd_cv_cc_sanitizer_pointer_subtract],
   9244                  [
   9245                    CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-subtract ${user_CFLAGS}"
   9246                    AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
   9247                     [mhd_cv_cc_sanitizer_pointer_subtract=yes], [mhd_cv_cc_sanitizer_pointer_subtract=no])
   9248                  ]
   9249                )
   9250                AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_subtract],["yes"],
   9251                  [
   9252                    AX_APPEND_FLAG([-fsanitize=pointer-subtract], [san_FLAGS])
   9253                    enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer subtract"
   9254                  ]
   9255                )
   9256                AS_VAR_IF([enable_san_upoison], ["no"], [:],
   9257                  [
   9258                    AC_CHECK_HEADERS([sanitizer/asan_interface.h], [], [], [AC_INCLUDES_DEFAULT])
   9259                    AS_VAR_IF([ac_cv_header_sanitizer_asan_interface_h],["yes"],
   9260                      [
   9261                        CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
   9262                        MHD_CHECK_FUNC([__asan_address_is_poisoned],[[#include <sanitizer/asan_interface.h>]],
   9263                          [[int a_var=1; i][f(__asan_address_is_poisoned((void*) &a_var)) return 3;]]
   9264                        )
   9265                        MHD_CHECK_FUNC([__asan_region_is_poisoned],[[#include <sanitizer/asan_interface.h>]],
   9266                          [[int a_var=1; i][f(((void*) 0) != __asan_region_is_poisoned((void*) &a_var, sizeof(a_var))) return 3;]]
   9267                        )
   9268                        AC_CACHE_CHECK([whether special function attribute is needed for user-poison], [mhd_cv_func_u_p_attribute_needed],
   9269                          [
   9270                            ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
   9271                            export ASAN_OPTIONS
   9272                            CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
   9273                            AC_RUN_IFELSE(
   9274                              [
   9275                                AC_LANG_SOURCE(
   9276                                  [[
   9277 #include <stdint.h>
   9278 #include <stdlib.h>
   9279 #include <sanitizer/asan_interface.h>
   9280 
   9281 static const size_t first_pos = 0;
   9282 static const size_t mid_pos = 64;
   9283 static const size_t last_pos = 128;
   9284 static const size_t zone_size = 16;
   9285 static const size_t buf_size = 128 + 16;
   9286 
   9287 static int ptr_compare(void *ptr1, uint8_t *ptr2)
   9288 {
   9289   if ((((uintptr_t) (uint8_t *)ptr1) >= ((uintptr_t)ptr2)))
   9290     return ((char *) ptr1)[0] < ((char *) ptr2)[0];
   9291   return ((char *) ptr1)[0] > ((char *) ptr2)[0];
   9292 }
   9293 
   9294 static int ptr_subtract(void *ptr1, uint8_t *ptr2)
   9295 {
   9296   return ((size_t)(((uintptr_t)(uint8_t*)ptr1) - ((uintptr_t)ptr2))) <= last_pos;
   9297 }
   9298 
   9299 int main(int argc, char *argv[])
   9300 {
   9301   char *buf = (char*) malloc (buf_size);
   9302   char *a;
   9303   char *b;
   9304   int ret;
   9305 
   9306   (void) argv;
   9307   if (NULL == buf)
   9308     return 10;
   9309   ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size);
   9310   ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size);
   9311 
   9312   if (0 < argc)
   9313     a = buf + last_pos;
   9314   else
   9315     a = buf + first_pos;
   9316   b = buf + mid_pos;
   9317 
   9318   *a = '0';
   9319   *b = '9';
   9320 
   9321   if (ptr_compare((void *)a, (uint8_t*) b))
   9322   {
   9323     if (ptr_subtract((void *)a, (uint8_t*) b))
   9324       ret = 0;
   9325     else
   9326       ret = 10;
   9327   }
   9328   else
   9329     ret = 5;
   9330   ASAN_UNPOISON_MEMORY_REGION (buf, buf_size);
   9331   free (buf);
   9332 
   9333   return ret;
   9334 }
   9335                                  ]]
   9336                                )
   9337                              ],
   9338                              [mhd_cv_func_u_p_attribute_needed="no"], [mhd_cv_func_u_p_attribute_needed="yes"],
   9339                              [
   9340                                # Cross-compiling with sanitizers??
   9341                                mhd_cv_func_up_attribute_needed='assuming no'
   9342                              ]
   9343                            )
   9344                            AS_UNSET([ASAN_OPTIONS])
   9345                          ]
   9346                        )
   9347                      ]
   9348                    )
   9349                    AS_VAR_IF([mhd_cv_func_u_p_attribute_needed],["yes"],[:],
   9350                      [
   9351                        AC_DEFINE([FUNC_PTRCOMPARE_CAST_WORKAROUND_WORKS],[1],[Define to '1' if cast to 'uintptr_t' works for safely processing user-poisoned pointer])
   9352                      ]
   9353                    )
   9354                    AS_IF([test "x${mhd_cv_func_u_p_attribute_needed}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes"],
   9355                      [
   9356                        AC_CACHE_CHECK([whether '__attribute__((no_sanitize("pointer-compare")))' and '__attribute__((no_sanitize("pointer-subtract")))' work],
   9357                          [mhd_cv_func_attribute_nosanitize_ptr],
   9358                          [
   9359                            ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
   9360                            export ASAN_OPTIONS
   9361                            CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
   9362                            AC_RUN_IFELSE(
   9363                              [
   9364                                AC_LANG_SOURCE(
   9365                                  [[
   9366 #include <stdint.h>
   9367 #include <stdlib.h>
   9368 #include <sanitizer/asan_interface.h>
   9369 
   9370 static const size_t first_pos = 0;
   9371 static const size_t mid_pos = 64;
   9372 static const size_t last_pos = 128;
   9373 static const size_t zone_size = 16;
   9374 static const size_t buf_size = 128 + 16;
   9375 
   9376 __attribute__((no_sanitize("pointer-compare")))
   9377 static int ptr_compare(void *ptr1, uint8_t *ptr2)
   9378 {
   9379   if ((((const uint8_t*)ptr1) >= ((const uint8_t*)ptr2)))
   9380     return ((char *) ptr1)[0] < ((char *) ptr2)[0];
   9381   return ((char *) ptr1)[0] > ((char *) ptr2)[0];
   9382 }
   9383 
   9384 __attribute__((no_sanitize("pointer-subtract")))
   9385 static int ptr_subtract(void *ptr1, uint8_t *ptr2)
   9386 {
   9387   return ((size_t)(((const uint8_t*)ptr1) - \
   9388           ((const uint8_t*)ptr2))) <= last_pos;
   9389 }
   9390 
   9391 int main(int argc, char *argv[])
   9392 {
   9393   char *buf = (char*) malloc (buf_size);
   9394   char *a;
   9395   char *b;
   9396   int ret;
   9397 
   9398   (void) argv;
   9399   if (NULL == buf)
   9400     return 10;
   9401   ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size);
   9402   ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size);
   9403 
   9404   if (0 < argc)
   9405     a = buf + last_pos;
   9406   else
   9407     a = buf + first_pos;
   9408   b = buf + mid_pos;
   9409 
   9410   *a = '0';
   9411   *b = '9';
   9412 
   9413   if (ptr_compare((void *)a, (uint8_t*) b))
   9414   {
   9415     if (ptr_subtract((void *)a, (uint8_t*) b))
   9416       ret = 0;
   9417     else
   9418       ret = 10;
   9419   }
   9420   else
   9421     ret = 5;
   9422   ASAN_UNPOISON_MEMORY_REGION (buf, buf_size);
   9423   free (buf);
   9424 
   9425   return ret;
   9426 }
   9427                                  ]]
   9428                                )
   9429                              ],
   9430                              [mhd_cv_func_attribute_nosanitize_ptr=yes], [mhd_cv_func_attribute_nosanitize_ptr=no],
   9431                              [
   9432                                # Cross-compiling with sanitizers??
   9433                                mhd_cv_func_attribute_nosanitize_ptr='assuming no'
   9434                              ]
   9435                            )
   9436                            AS_UNSET([ASAN_OPTIONS])
   9437                          ]
   9438                        )
   9439                        AS_VAR_IF([mhd_cv_func_attribute_nosanitize_ptr], ["yes"],
   9440                          [
   9441                            AC_DEFINE([FUNC_ATTR_PTRCOMPARE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-compare")))' works])
   9442                            AC_DEFINE([FUNC_ATTR_PTRSUBTRACT_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-subtract")))' works])
   9443                          ],
   9444                          [
   9445                            AC_CACHE_CHECK([whether '__attribute__((no_sanitize("address")))' works for pointers compare], [mhd_cv_func_attribute_nosanitize_addr],
   9446                              [
   9447                                ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
   9448                                export ASAN_OPTIONS
   9449                                CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
   9450                                AC_RUN_IFELSE(
   9451                                  [
   9452                                    AC_LANG_SOURCE(
   9453                                      [[
   9454 #include <stdint.h>
   9455 #include <stdlib.h>
   9456 #include <sanitizer/asan_interface.h>
   9457 
   9458 static const size_t first_pos = 0;
   9459 static const size_t mid_pos = 64;
   9460 static const size_t last_pos = 128;
   9461 static const size_t zone_size = 16;
   9462 static const size_t buf_size = 128 + 16;
   9463 
   9464 __attribute__((no_sanitize("address")))
   9465 static int ptr_compare(void *ptr1, uint8_t *ptr2)
   9466 {
   9467   if ((((const uint8_t*)ptr1) >= ((const uint8_t*)ptr2)))
   9468     return ((char *) ptr1)[0] < ((char *) ptr2)[0];
   9469   return ((char *) ptr1)[0] > ((char *) ptr2)[0];
   9470 }
   9471 
   9472 __attribute__((no_sanitize("address")))
   9473 static int ptr_subtract(void *ptr1, uint8_t *ptr2)
   9474 {
   9475   return ((size_t)(((const uint8_t*)ptr1) - \
   9476           ((const uint8_t*)ptr2))) <= last_pos;
   9477 }
   9478 
   9479 int main(int argc, char *argv[])
   9480 {
   9481   char *buf = (char*) malloc (buf_size);
   9482   char *a;
   9483   char *b;
   9484   int ret;
   9485 
   9486   (void) argv;
   9487   if (NULL == buf)
   9488     return 10;
   9489   ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size);
   9490   ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size);
   9491 
   9492   if (0 < argc)
   9493     a = buf + last_pos;
   9494   else
   9495     a = buf + first_pos;
   9496   b = buf + mid_pos;
   9497 
   9498   *a = '0';
   9499   *b = '9';
   9500 
   9501   if (ptr_compare((void *)a, (uint8_t*) b))
   9502   {
   9503     if (ptr_subtract((void *)a, (uint8_t*) b))
   9504       ret = 0;
   9505     else
   9506       ret = 10;
   9507   }
   9508   else
   9509     ret = 5;
   9510   ASAN_UNPOISON_MEMORY_REGION (buf, buf_size);
   9511   free (buf);
   9512 
   9513   return ret;
   9514 }
   9515                                      ]]
   9516                                    )
   9517                                  ],
   9518                                  [mhd_cv_func_attribute_nosanitize_addr=yes], [mhd_cv_func_attribute_nosanitize_addr=no],
   9519                                  [
   9520                                    # Cross-compiling with sanitizers??
   9521                                    mhd_cv_func_attribute_nosanitize_addr='assuming no'
   9522                                  ]
   9523                                )
   9524                                AS_UNSET([ASAN_OPTIONS])
   9525                              ]
   9526                            )
   9527                            AS_VAR_IF([mhd_cv_func_attribute_nosanitize_addr], ["yes"],
   9528                              [AC_DEFINE([FUNC_ATTR_NOSANITIZE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("address")))' works for pointers compare])]
   9529                            )
   9530                          ]
   9531                        )
   9532                      ]
   9533                    )
   9534                  ]
   9535                )
   9536              ]
   9537            )
   9538            AS_IF([test "x${enable_san_address}" = "xyes" && test "x${mhd_cv_cc_sanitizer_address}" != "xyes"],
   9539              [AC_MSG_ERROR([Address sanitizer cannot be enabled])]
   9540            )
   9541            enable_san_address="${mhd_cv_cc_sanitizer_address}"
   9542          ]
   9543        )
   9544        AS_VAR_IF([enable_san_undef], ["no"], [:],
   9545          [
   9546            dnl Ensure that '#' will be processed correctly
   9547            [
   9548             test_undf_prog='
   9549 #include <stdio.h>
   9550 
   9551 static void func_out_b(char *arr)
   9552 {
   9553   arr[0] = 0;
   9554   arr[16] = 2;
   9555 }
   9556 
   9557 static unsigned int int_deref(void *ptr)
   9558 {
   9559   return (*((unsigned int*)ptr)) + 2;
   9560 }
   9561 
   9562 static int func1(void)
   9563 {
   9564   char chr[16];
   9565   func_out_b (chr);
   9566   return (int) (int_deref(chr + 1) + int_deref(chr + 2));
   9567 }
   9568 
   9569 int main(void)
   9570 {
   9571   unsigned long ulvar;
   9572   signed char ch1;
   9573   ulvar = -1 * func1();
   9574   ch1 = ulvar * 6UL;
   9575   printf("%lu\n", ulvar + ch1);
   9576   return 0;
   9577 }
   9578             '
   9579            ]
   9580            AC_CACHE_CHECK([for undefined behavior sanitizer], [mhd_cv_cc_sanitizer_undefined],
   9581              [
   9582                CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined ${user_CFLAGS}"
   9583                AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
   9584                 [mhd_cv_cc_sanitizer_undefined=yes], [mhd_cv_cc_sanitizer_undefined=no])
   9585              ]
   9586            )
   9587            AS_VAR_IF([mhd_cv_cc_sanitizer_undefined],["yes"],
   9588              [
   9589                AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
   9590                enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
   9591              ],
   9592              [
   9593                AS_CASE([${enable_san_undef}], [yes|auto-fallback],
   9594                  [
   9595                    AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-undefined-trap-on-error'], [mhd_cv_cc_sanitizer_undefined_trap],
   9596                      [
   9597                        CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error ${user_CFLAGS}"
   9598                        AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
   9599                         [mhd_cv_cc_sanitizer_undefined_trap=yes], [mhd_cv_cc_sanitizer_undefined_trap=no])
   9600                      ]
   9601                    )
   9602                    AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap], ["yes"],
   9603                      [
   9604                        AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
   9605                        AX_APPEND_FLAG([-fsanitize-undefined-trap-on-error], [san_FLAGS])
   9606                        enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
   9607                        AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited])
   9608                      ],
   9609                      [
   9610                        AS_IF([test -z "${enabled_sanitizers}"],
   9611                          [
   9612                            # Last resort
   9613                            AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-trap=all'], [mhd_cv_cc_sanitizer_undefined_trap_all],
   9614                              [
   9615                                CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all ${user_CFLAGS}"
   9616                                AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
   9617                                 [mhd_cv_cc_sanitizer_undefined_trap_all=yes], [mhd_cv_cc_sanitizer_undefined_trap_all=no])
   9618                              ]
   9619                            )
   9620                            AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap_all],["yes"],
   9621                              [
   9622                                AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
   9623                                AX_APPEND_FLAG([-fsanitize-trap=all], [san_FLAGS])
   9624                                CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all ${user_CFLAGS}"
   9625                                enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
   9626                                AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited])
   9627                              ]
   9628                            )
   9629                          ]
   9630                        )
   9631                      ]
   9632                    )
   9633                    AS_CASE(["$enabled_sanitizers"], [*undefined],
   9634                      [
   9635                        AS_VAR_IF([mhd_cv_cc_sanitizer_undefined], ["yes"],[],
   9636                          [
   9637                            # A workaround for broken clang which is trying to use UBSan lib
   9638                            # even when instructed to not use it
   9639                            CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
   9640                            AX_APPEND_LINK_FLAGS([-fsanitize-trap=implicit-conversion],
   9641                              [san_FLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])])
   9642                          ]
   9643                        )
   9644                      ]
   9645                    )
   9646                  ]
   9647                )
   9648              ]
   9649            )
   9650            AS_CASE(["$enabled_sanitizers"], [*undefined],
   9651              [
   9652                CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
   9653                AX_APPEND_LINK_FLAGS([-fsanitize=bounds-strict -fsanitize=local-bounds -fsanitize=implicit-conversion -fsanitize=nullability-arg],
   9654                  [san_CFLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])])
   9655              ]
   9656            )
   9657            AS_UNSET([test_undf_prog])
   9658            AS_CASE(["$enabled_sanitizers"],
   9659              [*undefined], [enable_san_undef="yes"],
   9660              [
   9661                AS_VAR_IF([enable_san_undef], [yes], [AC_MSG_ERROR([Undefined behavior sanitizer cannot be enabled])])
   9662                enable_san_undef="no"
   9663              ]
   9664            )
   9665          ]
   9666        )
   9667        AS_VAR_IF([enable_san_leak], ["no"], [:],
   9668          [
   9669            AC_CACHE_CHECK([for leak sanitizer], [mhd_cv_cc_sanitizer_leak],
   9670              [
   9671                CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=leak ${user_CFLAGS}"
   9672                AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
   9673                 [mhd_cv_cc_sanitizer_leak=yes], [mhd_cv_cc_sanitizer_leak=no])
   9674              ]
   9675            )
   9676            AS_VAR_IF([mhd_cv_cc_sanitizer_leak],["yes"],
   9677              [
   9678                AX_APPEND_FLAG([-fsanitize=leak], [san_FLAGS])
   9679                enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }leak"
   9680              ]
   9681            )
   9682            AS_IF([test "x${enable_san_leak}" = "xyes" && test "x${mhd_cv_cc_sanitizer_leak}" != "xyes"],
   9683              [AC_MSG_ERROR([User poison cannot be enabled])]
   9684            )
   9685            enable_san_leak="${mhd_cv_cc_sanitizer_leak}"
   9686          ]
   9687        )
   9688        AS_IF([test -z "${enabled_sanitizers}"],
   9689          [
   9690            AS_VAR_IF([enable_sanitizers], ["auto-optional"],
   9691              [
   9692                san_FLAGS=""
   9693                san_CFLAGS=""
   9694              ],
   9695              [
   9696                AC_MSG_ERROR([cannot find any sanitizer supported by $CC])
   9697              ]
   9698            )
   9699          ],
   9700          [
   9701            AS_VAR_IF([enable_san_upoison], ["no"], [:],
   9702              [
   9703                AC_MSG_CHECKING([whether to enable user memory poisoning])
   9704                AS_IF([test "x${mhd_cv_cc_sanitizer_address}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes" && \
   9705                  (test "x${mhd_cv_func_u_p_attribute_needed}" != "xyes" || test "x${mhd_cv_func_attribute_nosanitize_ptr}" = "xyes" || \
   9706                   test "x${mhd_cv_func_attribute_nosanitize_addr}" = "xyes")],
   9707                  [
   9708                    AC_DEFINE([MHD_ASAN_POISON_ACTIVE], [1], [Define to '1' if user memory poison is used])
   9709                    enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }user-poison"
   9710                    enable_san_upoison="yes"
   9711                    AC_MSG_RESULT([yes])
   9712                  ],
   9713                  [
   9714                    AC_MSG_RESULT([no])
   9715                    AS_VAR_IF([enable_san_upoison], ["yes"],
   9716                      [AC_MSG_ERROR([User memory poisoning cannot be enabled])])
   9717                    enable_san_upoison="no"
   9718                  ]
   9719                )
   9720              ]
   9721            )
   9722            AS_VAR_IF([enable_san_address], ["yes"],
   9723              [
   9724                CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
   9725                AC_CHECK_DECL([_FORTIFY_SOURCE],
   9726                  [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-U_FORTIFY_SOURCE])],
   9727                  [],[/* no includes */])
   9728                AX_APPEND_FLAG([-D_FORTIFY_SOURCE=0], [san_CFLAGS])
   9729              ],
   9730              [
   9731                AS_CASE([$enable_sanitizers], [auto|auto-fallback],
   9732                  [AC_MSG_WARN([$CC does not support address sanitizer])])
   9733              ]
   9734            )
   9735            CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
   9736            # Always stop on sanitizer error
   9737            AX_APPEND_COMPILE_FLAGS([-fno-sanitize-recover=all], [san_CFLAGS])
   9738            # Get a better output for sanitizers error reporting
   9739            AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer -fno-optimize-sibling-calls],
   9740              [san_CFLAGS])
   9741            AS_VAR_IF([enable_san_address], ["yes"],
   9742              [
   9743                AM_ASAN_OPTIONS="exitcode=88:strict_string_checks=1:detect_stack_use_after_return=1"
   9744                AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:check_initialization_order=1:strict_init_order=1:redzone=64"
   9745                AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:max_free_fill_size=1024:detect_invalid_pointer_pairs=3"
   9746                AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:handle_ioctl=1:halt_on_error=1"
   9747                AS_VAR_IF([enable_san_upoison], ["yes"], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:allow_user_poisoning=1"])
   9748                AS_VAR_IF([enable_san_leak], ["yes"],
   9749                  [AS_VAR_IF([mhd_cv_cc_sanitizer_address_leak], ["yes"],
   9750                    [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=1"])
   9751                  ], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=0"]
   9752                )
   9753              ]
   9754            )
   9755            AS_VAR_IF([enable_san_undef], [yes],
   9756              [AM_UBSAN_OPTIONS="exitcode=87:print_stacktrace=1:halt_on_error=1"])
   9757            AS_VAR_IF([enable_san_leak], ["yes"],
   9758              [AM_LSAN_OPTIONS="use_unaligned=1"]
   9759            )
   9760            TESTS_ENVIRONMENT_ac='\
   9761     ASAN_OPTIONS="$(AM_ASAN_OPTIONS)" ; export ASAN_OPTIONS ; \
   9762     UBSAN_OPTIONS="$(AM_UBSAN_OPTIONS)" ; export UBSAN_OPTIONS ; \
   9763     LSAN_OPTIONS="$(AM_LSAN_OPTIONS)" ; export LSAN_OPTIONS ;'
   9764          ]
   9765        )
   9766      ]
   9767    )
   9768    CFLAGS_ac="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS}"
   9769    CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   9770  ]
   9771 )
   9772 
   9773 # fuzzing tests
   9774 run_zzuf_tests="no"
   9775 zzuf_socat_mandatory="no"
   9776 AS_VAR_IF([use_heavy_tests],["yes"],
   9777   [
   9778     AS_VAR_IF([enable_curl],["yes"],
   9779       [
   9780         AC_PATH_PROG([ZZUF],[zzuf],[no])
   9781         AS_VAR_IF([ZZUF],["no"],
   9782           [
   9783             run_zzuf_tests="no"
   9784             run_zzuf_tests_MSG="no, zzuf tool not found"
   9785           ],
   9786           [
   9787 	        AC_PATH_PROG([SOCAT],[socat],[no])
   9788             AS_IF([test "x${ac_cv_func_accept4}" = "xyes" && test "x${enable_asserts}" = "xno"],
   9789               [
   9790                 zzuf_socat_mandatory="yes"
   9791 		        AS_VAR_IF([SOCAT],["no"],
   9792                   [run_zzuf_tests_MSG="no, socat not found, but required for fuzzing tests on this platform without asserts enabled"],
   9793                   [
   9794 		            run_zzuf_tests="yes"
   9795 		            run_zzuf_tests_MSG="yes, with zzuf and socat tools"
   9796                   ]
   9797                 )
   9798               ],
   9799               [test -n "${enabled_sanitizers}"],
   9800               [
   9801                 zzuf_socat_mandatory="yes"
   9802 		        AS_VAR_IF([SOCAT],["no"],
   9803                   [run_zzuf_tests_MSG="no, socat not found, but required for fuzzing tests when sanitizers enabled"],
   9804                   [
   9805 		            run_zzuf_tests="yes"
   9806 		            run_zzuf_tests_MSG="yes, with zzuf and socat tools"
   9807                   ]
   9808                 )
   9809               ],
   9810               [
   9811                 run_zzuf_tests="yes"
   9812                 run_zzuf_tests_MSG="yes, with zzuf tool"
   9813               ]
   9814             )
   9815           ]
   9816         )
   9817       ],
   9818       [
   9819         run_zzuf_tests="no"
   9820         run_zzuf_tests_MSG="no, tests with libcurl are not enabled"
   9821       ]
   9822     )
   9823   ],
   9824   [
   9825     run_zzuf_tests="no"
   9826     run_zzuf_tests_MSG="no, heavy tests are not enabled"
   9827   ]
   9828 )
   9829 AM_CONDITIONAL([RUN_ZZUF_TESTS],[test "x$run_zzuf_tests" = "xyes"])
   9830 AM_CONDITIONAL([FORCE_USE_ZZUF_SOCAT],[test "x$zzuf_socat_mandatory" = "xyes"])
   9831 
   9832 # Final flags that may interfere with autoconf detections
   9833 AS_VAR_IF([enable_build_type],["neutral"],[],
   9834   [ # Any non-neutral build types
   9835     CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
   9836     LDFLAGS="${user_LDFLAGS}"
   9837     MHD_CHECK_ADD_CC_LDFLAG([-Wl,--warn-common], [LDFLAGS_ac])
   9838     LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
   9839   ]
   9840 )
   9841 MHD_APPEND_FLAG_TO_VAR([CFLAGS_ac],[$CFLAGS_last])
   9842 
   9843 AM_CONDITIONAL([USE_SANITIZERS],
   9844   [test -n "$enabled_sanitizers" && test "x$mhd_cv_cc_sanitizer_works" = "xyes"])
   9845 AC_SUBST([AM_ASAN_OPTIONS])
   9846 AC_SUBST([AM_UBSAN_OPTIONS])
   9847 AC_SUBST([AM_LSAN_OPTIONS])
   9848 AC_SUBST([TESTS_ENVIRONMENT_ac])
   9849 
   9850 MHD_LIB_LDFLAGS="$MHD_LIB_LDFLAGS"
   9851 
   9852 AC_SUBST([CPU_COUNT])
   9853 AC_SUBST([HEAVY_TESTS_NOTPARALLEL])
   9854 AM_SUBST_NOTMAKE([HEAVY_TESTS_NOTPARALLEL])
   9855 AC_SUBST(MHD_LIB_CPPFLAGS)
   9856 AC_SUBST(MHD_LIB_CFLAGS)
   9857 AC_SUBST(MHD_LIB_LDFLAGS)
   9858 AC_SUBST(MHD_LIBDEPS)
   9859 AC_SUBST(MHD_TLS_LIB_CPPFLAGS)
   9860 AC_SUBST(MHD_TLS_LIB_LDFLAGS)
   9861 AC_SUBST(MHD_TLS_LIBDEPS)
   9862 
   9863 # for pkg-config
   9864 AC_SUBST([MHD_REQ_PRIVATE])
   9865 AC_SUBST([MHD_LIBDEPS_PKGCFG])
   9866 
   9867 # Restore flags as set by the user
   9868 CFLAGS="${user_CFLAGS}"
   9869 LDFLAGS="${user_LDFLAGS}"
   9870 CPPFLAGS="${user_CPPFLAGS}"
   9871 AC_SUBST([CFLAGS])
   9872 AC_SUBST([LDFLAGS])
   9873 AC_SUBST([CPPFLAGS])
   9874 AC_SUBST([LIBS])
   9875 
   9876 # Configure-defined flags
   9877 AC_SUBST([CFLAGS_ac])
   9878 AC_SUBST([LDFLAGS_ac])
   9879 AC_SUBST([CPPFLAGS_ac])
   9880 
   9881 # Used for 'po' directory staff
   9882 AC_SUBST([ac_configure_args])
   9883 AC_SUBST([EMPTY_VAR],[])
   9884 AC_SUBST([MHD_AUX_DIR])
   9885 AC_CONFIG_FILES([po/po-configure.ac])
   9886 AC_CONFIG_COMMANDS([po/Makefile.in],
   9887   [
   9888     echo "Skipping update of po/Makefile.in"
   9889     echo "Real update of po/Makefile.in for 'make dist' is performed by po-config.status"
   9890   ]
   9891 )
   9892 AC_CONFIG_COMMANDS([po-directories],
   9893   [
   9894     echo "Skipping po-directories command."
   9895     echo "Real po-directories command for 'make dist' is implemented in po-config.status"
   9896   ]
   9897 )
   9898 
   9899 AC_SUBST([ZZUF])
   9900 AC_SUBST([SOCAT])
   9901 
   9902 # SBOMs
   9903 AC_MSG_CHECKING([fo][r the effective library licence])
   9904 AS_UNSET([licence_SPDX])
   9905 AS_UNSET([licence_descr])
   9906 licence_num="0"
   9907 AS_VAR_IF([have_gnutls],["yes"],
   9908   [AS_IF([test "2" -gt "$licence_num"],[licence_num="2"])]
   9909 )
   9910 AS_VAR_IF([have_openssl],["yes"],
   9911   [AS_IF([test "3" -gt "$licence_num"],[licence_num="3"])]
   9912 )
   9913 AS_VAR_IF([have_mbedtls],["yes"],
   9914   [AS_IF([test "3" -gt "$licence_num"],[licence_num="3"])]
   9915 )
   9916 AS_CASE([$licence_num],
   9917   [0],
   9918   [
   9919     licence_SPDX="LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0)"
   9920     licence_descr="LGPLv2.1+ or GPLv2+ with eCos exception"
   9921   ],
   9922   [2],
   9923   [
   9924     licence_SPDX="LGPL-2.1-or-later"
   9925     licence_descr="LGPL version 2.1 or any later version"
   9926   ],
   9927   [3],
   9928   [
   9929     licence_SPDX="LGPL-3.0-or-later"
   9930     licence_descr="LGPL version 3.0 or any later version"
   9931   ],
   9932   [AC_MSG_ERROR([internal error: unexpected licence selector value: ${licence_num}])]
   9933 )
   9934 AC_MSG_RESULT([${licence_descr}])
   9935 AC_SUBST([MHD_LICENSE_SPDX],[${licence_SPDX}])
   9936 AM_SUBST_NOTMAKE([MHD_LICENSE_SPDX])
   9937 
   9938 AC_ARG_ENABLE([sboms],
   9939 [AS_HELP_STRING([[--enable-sboms[=TYPEs]]],[enable SBOMs generation (all,spdx,cdx) [all]])],
   9940 [
   9941   AS_CASE([${enable_sboms}],
   9942     [yes|no|all|cdx|spdx|cdx,spdx|spdx,cdx],[],
   9943     [AC_MSG_ERROR([Unknown parameter value: --enable-sboms=${enable_sboms}])]
   9944   )
   9945 ],[enable_sboms="yes"]
   9946 )
   9947 
   9948 use_sbom_spdx="no"
   9949 AS_CASE([${enable_sboms}],
   9950   [yes|all|spdx|*,spdx|spdx,*|*,spdx,*],[use_sbom_spdx="yes"]
   9951 )
   9952 use_sbom_cdx="no"
   9953 AS_CASE([${enable_sboms}],
   9954   [yes|all|cdx|*,cdx|cdx,*|*,cdx,*],[use_sbom_cdx="yes"]
   9955 )
   9956 AM_CONDITIONAL([ENABLE_SBOM_SPDX],[test "X${use_sbom_spdx}" = "Xyes"])
   9957 AM_CONDITIONAL([ENABLE_SBOM_CDX],[test "X${use_sbom_cdx}" = "Xyes"])
   9958 
   9959 # should experimental code be compiled (code that may not yet compile)?
   9960 AC_MSG_CHECKING(whether to compile experimental code)
   9961 AC_ARG_ENABLE([experimental],
   9962    [AS_HELP_STRING([--enable-experimental], [enable compiling experimental code])],
   9963    [enable_experimental=${enableval}],
   9964    [enable_experimental=no])
   9965 AC_MSG_RESULT($enable_experimental)
   9966 AM_CONDITIONAL([HAVE_EXPERIMENTAL], [test "x$enable_experimental" = "xyes"])
   9967 
   9968 
   9969 AC_CONFIG_FILES([
   9970 src/mhd2/libmicrohttpd2.pc
   9971 src/mhd2/w32_lib_res.rc
   9972 w32/common/microhttpd2.rc
   9973 Makefile
   9974 contrib/Makefile
   9975 doc/Makefile
   9976 m4/Makefile
   9977 src/Makefile
   9978 src/incl_priv/Makefile
   9979 src/incl_priv/config/Makefile
   9980 src/include/Makefile
   9981 src/mhd2/Makefile
   9982 src/tools/Makefile
   9983 src/tests/Makefile
   9984 src/tests/unit/Makefile
   9985 src/tests/basic/Makefile
   9986 src/tests/upgrade/Makefile
   9987 src/tests/raw/Makefile
   9988 src/tests/acme/Makefile
   9989 src/tests/client_server/Makefile
   9990 src/examples2/Makefile
   9991 src/examples2/acme/Makefile
   9992 ])
   9993 AC_OUTPUT
   9994 
   9995 # Finally: summary
   9996 # Format flags without extra spaces for visual beauty
   9997 fin_CPPFLAGS="$user_CPPFLAGS"
   9998 fin_CFLAGS="$user_CFLAGS"
   9999 fin_LDFLAGS="$user_LDFLAGS"
  10000 MHD_PREPEND_FLAG_TO_VAR([fin_CPPFLAGS],[$CPPFLAGS_ac])
  10001 MHD_PREPEND_FLAG_TO_VAR([fin_CFLAGS],[$CFLAGS_ac])
  10002 MHD_PREPEND_FLAG_TO_VAR([fin_LDFLAGS],[$LDFLAGS_ac])
  10003 fin_lib_CPPFLAGS="$user_CPPFLAGS"
  10004 fin_lib_CFLAGS="$user_CFLAGS"
  10005 fin_lib_LDFLAGS="$user_LDFLAGS"
  10006 fin_lib_LIBS="${MHD_LIBDEPS}"
  10007 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CPPFLAGS],[$MHD_LIB_CPPFLAGS])
  10008 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CFLAGS],[$MHD_LIB_CFLAGS])
  10009 MHD_PREPEND_FLAG_TO_VAR([fin_lib_LDFLAGS],[$MHD_LIB_LDFLAGS])
  10010 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CPPFLAGS],[$CPPFLAGS_ac])
  10011 MHD_PREPEND_FLAG_TO_VAR([fin_lib_CFLAGS],[$CFLAGS_ac])
  10012 MHD_PREPEND_FLAG_TO_VAR([fin_lib_LDFLAGS],[$LDFLAGS_ac])
  10013 MHD_PREPEND_FLAG_TO_VAR([fin_lib_LIBS],[${MHD_TLS_LIBDEPS}])
  10014 AC_MSG_NOTICE([Toolchain settings:
  10015   CC=$CC
  10016   User/system/default flags:
  10017     CPPFLAGS="$user_CPPFLAGS"
  10018     CFLAGS=  "$user_CFLAGS"
  10019     LDFLAGS= "$user_LDFLAGS"
  10020   Final set of the flags for tests and examples:
  10021     CPPFLAGS="$fin_CPPFLAGS"
  10022     CFLAGS=  "$fin_CFLAGS"
  10023     LDFLAGS= "$fin_LDFLAGS"
  10024     LIBS=    "$LIBS"
  10025   Final set of the flags for ${PACKAGE_NAME} library:
  10026     CPPFLAGS="$fin_lib_CPPFLAGS"
  10027     CFLAGS=  "$fin_lib_CFLAGS"
  10028     LDFLAGS= "$fin_lib_LDFLAGS"
  10029     LIBS=    "$fin_lib_LIBS"
  10030 ])
  10031 
  10032 AS_UNSET([fin_CPPFLAGS])
  10033 AS_UNSET([fin_CFLAGS])
  10034 AS_UNSET([fin_LDFLAGS])
  10035 AS_UNSET([fin_lib_CPPFLAGS])
  10036 AS_UNSET([fin_lib_CFLAGS])
  10037 AS_UNSET([fin_lib_LDFLAGS])
  10038 
  10039 AS_VAR_IF([os_is_windows], ["yes"],
  10040   [os_ver_msg="
  10041   Target W32 ver   : ${mhd_w32_ver_msg}"], [AS_UNSET([[os_ver_msg]])])
  10042 
  10043 AC_MSG_NOTICE([[${PACKAGE_NAME} ${PACKAGE_VERSION} Configuration Summary:
  10044   [ Target platform ]
  10045   Target directory : ${prefix}
  10046   Cross-compiling  : ${cross_compiling}
  10047   Operating System : ${mhd_host_os}${os_ver_msg}
  10048   Threading lib    : ${USE_THREADS}
  10049   Shutdown of listening socket triggers select: ${mhd_cv_host_shtdwn_trgr_select}
  10050 
  10051   [ Library features and options ]
  10052   HTTP/2 support   : ${enable_http2}
  10053   Inter-thread comm: ${use_itc}
  10054   select() support : ${enable_select}
  10055   poll() support   : ${enable_poll=no}
  10056   epoll support    : ${enable_epoll=no}
  10057   kqueue support   : ${enable_kqueue=no}
  10058   sendfile()       : ${found_sendfile}
  10059   HTTPS support    : ${MSG_HTTPS}
  10060   TLS backends     : ${MSG_TLS_BACKENDS}
  10061   Cookie parser    : ${enable_cookie}
  10062   POST parser      : ${enable_postparser}
  10063   Basic auth.      : ${enable_basic_auth}
  10064   Digest auth.     : ${enable_digest_auth}
  10065   Digest auth. defaults: ${dauth_defs_MSG}
  10066   MD5              : ${enable_md5_MSG}
  10067   SHA-256          : ${enable_sha256_MSG}
  10068   SHA-512/256      : ${enable_sha512_256_MSG}
  10069   HTTP "Upgrade"   : ${enable_httpupgrade}
  10070   ACME functions   : ${enable_acme}
  10071   Logging support  : ${enable_log_messages}
  10072   Verbose auto replies: ${enable_http_messages}
  10073 
  10074   [ Code build options ]
  10075   Compact code     : ${enable_compact_code} (${compact_code_MSG})
  10076   LTO flags        : ${use_lto}
  10077   Use thread names : ${enable_thread_names}
  10078   Use debug asserts: ${use_asserts_MSG=no}
  10079   Use sanitizers   : ${enabled_sanitizers:=no}
  10080   
  10081   [ Tracing debug prints ]
  10082   Trace FDs polling: ${use_trace_fds_polling_MSG}
  10083   Conns add/close  : ${use_trace_conn_add_close_MSG}
  10084   Suspend/resume   : ${use_trace_suspend_resume_MSG}
  10085 
  10086   [ Build items ]
  10087   Build static lib : ${enable_static}
  10088   Build shared lib : ${enable_shared}
  10089   Build docs       : ${enable_doc}
  10090   Build examples   : ${enable_examples}
  10091   Build tools      : ${enable_tools}
  10092 
  10093   [ Test-suite settings ]
  10094   Test with libcurl: ${MSG_CURL}
  10095   Slow tests       : ${enable_slow_tests}
  10096   Heavy tests      : ${use_heavy_tests_MSG}
  10097   Fuzzing tests    : ${run_zzuf_tests_MSG=no}
  10098 ]])
  10099 
  10100 AC_MSG_NOTICE([[
  10101   [ Licence due to TLS backends used ]
  10102   Library licence  : ${licence_descr}
  10103 ]])
  10104 
  10105 AS_IF([test "x$enable_basic_auth" != "xyes" || \
  10106    test "x$enable_digest_auth" != "xyes" || \
  10107    test "x${enable_md5}" = "xno" || \
  10108    test "x${enable_sha256}" = "xno" || \
  10109    test "x${enable_sha512_256}" = "xno" || \
  10110    test "x${USE_THREADS}" = "xnone" || \
  10111    test "x$enable_https" != "xyes" || \
  10112    test "x$enable_cookie" != "xyes" || \
  10113    test "x$enable_httpupgrade" != "xyes" || \
  10114    test "X$enable_acme" != "Xyes" || \
  10115    test "x$enable_postparser" != "xyes"],
  10116    [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.])]
  10117 )
  10118 AS_IF([test -n "${CONF_FINAL_WARNS}"],[AC_MSG_WARN([${CONF_FINAL_WARNS}])])