libmicrohttpd2

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

configure.ac (313894B)


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