libmicrohttpd2

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

commit 7f329a7ad1d011e1cd6250417c862d767106c58f
parent ef32f7143a07ca700ba94173f8d89bf6b6a3e7b0
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Mon, 13 Apr 2026 14:49:01 +0200

configure: added detection of LTO-optimised binary tools

Diffstat:
Mconfigure.ac | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Am4/mhd_check_prog_abs.m4 | 38++++++++++++++++++++++++++++++++++++++
Am4/mhd_check_prog_path.m4 | 33+++++++++++++++++++++++++++++++++
Am4/mhd_is_file_exec.m4 | 45+++++++++++++++++++++++++++++++++++++++++++++
Am4/mhd_print_first_word.m4 | 40++++++++++++++++++++++++++++++++++++++++
5 files changed, 259 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -175,8 +175,111 @@ CFLAGS_ac="" LDFLAGS_ac="" CPPFLAGS_ac="" +CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" +CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" +LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" +AC_CACHE_CHECK([whether to look f][or compiler-specific binary tools], + [mhd_cv_check_cc_special_bin_tools], + [ + AS_IF([test "X$enable_lto" = "Xno"], + [mhd_cv_check_cc_special_bin_tools="no (LTO handling not needed)"], + [test "X${GCC}" != "Xyes"], + [mhd_cv_check_cc_special_bin_tools="no (compiler is not GCC nor clang)"], + [AS_VAR_TEST_SET([NM]) && AS_VAR_TEST_SET([OBJDUMP]) && \ + AS_VAR_TEST_SET([DLLTOOL]) && AS_VAR_TEST_SET([RANLIB]) && \ + AS_VAR_TEST_SET([AR]) && AS_VAR_TEST_SET([STRIP]) && \ + AS_VAR_TEST_SET([RC])] + [mhd_cv_check_cc_special_bin_tools="no (all binary tools are predefined)"], + [ + AS_CASE([$CC], + [*gcc*],[mhd_cv_check_cc_special_bin_tools="yes"], + [*clang*],[mhd_cv_check_cc_special_bin_tools="yes"], + [mhd_cv_check_cc_special_bin_tools="no (compiler binary name is not suitable)"] + ) + ] + ) + ] +) +AS_VAR_IF([mhd_cv_check_cc_special_bin_tools],["yes"], + [ + MHD_CHECK_CC_IS_CLANG + mhd_CC_bin_name=`MHD_PRINT_FIRST_WORD([$CC])` + mhd_bin_tools_prfx="" + mhd_bin_tools_sufx="" + AS_CASE([${mhd_CC_bin_name}], + [[gcc|*[\\/]gcc|*-gcc|clang|*[\\/]clang|*-clang]], + [mhd_bin_tools_prfx="${mhd_CC_bin_name}"], + [[gcc-[0-9]|*[\\/]gcc-[0-9]|*-gcc-[0-9]|clang-[0-9]|*[\\/]clang-[0-9]|*-clang-[0-9]]], + [[ + mhd_bin_tools_prfx=`$as_expr "X${mhd_CC_bin_name}" : 'X\(.*\)-[0-9]'` + mhd_bin_tools_sufx=`$as_expr "X${mhd_CC_bin_name}" : 'X.*\(-[0-9]\)'` + test -n "${mhd_bin_tools_sufx}" || mhd_bin_tools_prfx="" + ]], + [[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]]], + [[ + mhd_bin_tools_prfx=`$as_expr "X${mhd_CC_bin_name}" : 'X\(.*\)-[0-9][0-9]'` + mhd_bin_tools_sufx=`$as_expr "X${mhd_CC_bin_name}" : 'X.*\(-[0-9][0-9]\)'` + test -n "${mhd_bin_tools_sufx}" || mhd_bin_tools_prfx="" + ]], + [[gcc[0-9]|*[\\/]gcc[0-9]|*-gcc[0-9]|clang[0-9]|*[\\/]clang[0-9]|*-clang[0-9]]], + [[ + mhd_bin_tools_prfx=`$as_expr "X${mhd_CC_bin_name}" : 'X\(.*\)[0-9]'` + mhd_bin_tools_sufx=`$as_expr "X${mhd_CC_bin_name}" : 'X.*\([0-9]\)'` + test -n "${mhd_bin_tools_sufx}" || mhd_bin_tools_prfx="" + ]], + [[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]]], + [[ + mhd_bin_tools_prfx=`$as_expr "X${mhd_CC_bin_name}" : 'X\(.*\)[0-9][0-9]'` + mhd_bin_tools_sufx=`$as_expr "X${mhd_CC_bin_name}" : 'X.*\([0-9][0-9]\)'` + test -n "${mhd_bin_tools_sufx}" || mhd_bin_tools_prfx="" + ]] + ) + AS_CASE([${mhd_bin_tools_prfx}], + [*gcc],[AS_VAR_IF([mhd_cv_cc_clang_based],["no"],[:],[mhd_bin_tools_prfx=""])], + [*clang], + [ + AS_VAR_IF([mhd_cv_cc_clang_based],["yes"], + [ + mhd_bin_tools_prfx=`$as_expr "X${mhd_bin_tools_prfx}" : 'X\(.*\)clang'` + mhd_bin_tools_prfx="${mhd_bin_tools_prfx}llvm" + ], + [mhd_bin_tools_prfx=""] + ) + ] + ) + AS_CASE([${mhd_bin_tools_prfx}], + [[/*|[A-Za-z]:[\\/]*]], + [ + # Simplified detection of absolute path + MHD_CHECK_PROG_ABS([NM],["${mhd_bin_tools_prfx}-nm${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_ABS([OBJDUMP],["${mhd_bin_tools_prfx}-objdump${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_ABS([DLLTOOL],["${mhd_bin_tools_prfx}-dlltool${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_ABS([RANLIB],["${mhd_bin_tools_prfx}-ranlib${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_ABS([AR],["${mhd_bin_tools_prfx}-ar${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_ABS([STRIP],["${mhd_bin_tools_prfx}-strip${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_ABS([RC],["${mhd_bin_tools_prfx}-windres${mhd_bin_tools_sufx}"]) + ], + [*/*], + [ + # Relative paths are ambiguous, do not handle them + mhd_bin_tools_prfx="" + ], + [ + MHD_CHECK_PROG_PATH([NM],["${mhd_bin_tools_prfx}-nm${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_PATH([OBJDUMP],["${mhd_bin_tools_prfx}-objdump${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_PATH([DLLTOOL],["${mhd_bin_tools_prfx}-dlltool${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_PATH([RANLIB],["${mhd_bin_tools_prfx}-ranlib${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_PATH([AR],["${mhd_bin_tools_prfx}-ar${mhd_bin_tools_sufx}"]) + MHD_CHECK_PROG_PATH([RC],["${mhd_bin_tools_prfx}-windres${mhd_bin_tools_sufx}"]) + ] + ) + ] +) + + MHD_SYS_EXT([CPPFLAGS_ac]) CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}" + m4_version_prereq([2.72], [ AC_SYS_YEAR2038 diff --git a/m4/mhd_check_prog_abs.m4 b/m4/mhd_check_prog_abs.m4 @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: FSFAP +# +# SYNOPSIS +# +# MHD_CHECK_PROG_ABS([VAR],[ABS_FILENAME]) +# +# DESCRIPTION +# +# If VAR is NOT already set, check whether ABS_FILENAME is executable +# tool. On success set VAR to ABS_FILENAME. +# +# Example usage: +# +# MHD_CHECK_TOOL_ABS([NM],["/usr/bin/special-nm"]) +# +# LICENSE +# +# Copyright (c) 2026 Karlson2k (Evgeny Grin) <k2k@drgrin.dev> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +AC_DEFUN([MHD_CHECK_PROG_ABS],[dnl +m4_newline([[# Expansion of $0 macro starts here]]) +AS_VAR_SET_IF([$1],[], + [ + mhd_check_prog_abs_tool_check=$2 + AC_MSG_CHECKING([fo][r tool ${mhd_check_prog_abs_tool_check}]) + AS_IF([MHD_IS_FILE_EXEC([$2])],[$1=$2]) + AS_VAR_SET_IF([$1],[AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])]) + ] +) +m4_newline([[# Expansion of $0 macro ends here]]) +])dnl AC_DEFUN MHD_CHECK_TOOL_ABS diff --git a/m4/mhd_check_prog_path.m4 b/m4/mhd_check_prog_path.m4 @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: FSFAP +# +# SYNOPSIS +# +# MHD_CHECK_PROG_PATH([VAR],[FILENAME]) +# +# DESCRIPTION +# +# If VAR is NOT already set, check whether FILENAME is executable tool +# in the $PATH. On success set VAR to FILENAME. +# +# Example usage: +# +# MHD_CHECK_TOOL_PATH}([NM],["special-nm"]) +# +# LICENSE +# +# Copyright (c) 2026 Karlson2k (Evgeny Grin) <k2k@drgrin.dev> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +AC_DEFUN([MHD_CHECK_PROG_PATH],[dnl +m4_newline([[# Expansion of $0 macro starts here]]) +AS_VAR_SET_IF([$1],[], + [AC_CHECK_PROG([$1],[$2],[$2])] +) +m4_newline([[# Expansion of $0 macro ends here]]) +])dnl AC_DEFUN MHD_CHECK_TOOL_ABS diff --git a/m4/mhd_is_file_exec.m4 b/m4/mhd_is_file_exec.m4 @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: FSFAP +# +# SYNOPSIS +# +# MHD_IS_FILE_EXEC([pathname]) +# +# DESCRIPTION +# +# This produces zero shell status code if specified file is executable or +# non-zero shell status code if specified file does not exist, is not +# executable or is a directory. +# On platform, where the system may automatically add executable +# suffix (extension) when command is called, this macro checks also +# pathname combined with automatic suffix. +# To avoid possible word splitting, put parameter in shell quotes. +# +# Example usage: +# +# AS_IF([MHD_IS_FILE_EXEC(["/usr/bin/sometool"])], +# [AC_MSG_WARNING([/usr/bin/sometool not available])]) +# +# LICENSE +# +# Copyright (c) 2026 Karlson2k (Evgeny Grin) <k2k@drgrin.dev> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +AC_DEFUN([MHD_IS_FILE_EXEC],[dnl +AC_REQUIRE([_MHD_IS_FILE_EXEC_BODY])dnl +mhd_fn_is_file_exec $1])dnl AC_DEFUN MHD_IS_FILE_EXEC + + +AC_DEFUN([_MHD_IS_FILE_EXEC_BODY], [m4_divert_text([SHELL_FN],[dnl +mhd_fn_is_file_exec () { + for mhd_test_exec_ext in "" $ac_executable_extensions ; do + AS_IF([AS_EXECUTABLE_P(["${1}${mhd_test_exec_ext}"])],[return 0]) + done + return 1 +} # _mhd_fn_print_first_word +])])dnl AC_DEFUN _MHD_PRINT_FIRST_WORD_BODY diff --git a/m4/mhd_print_first_word.m4 b/m4/mhd_print_first_word.m4 @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: FSFAP +# +# SYNOPSIS +# +# MHD_PRINT_FIRST_WORD([some string or $variable]) +# +# DESCRIPTION +# +# This macro prints the first word from the first parameter after +# performing shell variable expansion and word-splitting. +# +# Example usage: +# +# cc_cmd=`MHD_PRINT_FIRST_WORD([$CC])` +# +# If CC is set to "gcc -std=c11' then just cc_cmd will be set to "gcc". +# +# LICENSE +# +# Copyright (c) 2026 Karlson2k (Evgeny Grin) <k2k@drgrin.dev> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 1 + +AC_DEFUN([MHD_PRINT_FIRST_WORD],[dnl +AC_REQUIRE([_MHD_PRINT_FIRST_WORD_BODY])dnl +m4_bmatch([$1], ["], [m4_fatal([$0: First macro argument must not contain double quote char '"'])])dnl +mhd_fn_print_first_word "$1"])dnl AC_DEFUN MHD_PRINT_FIRST_WORD + + +AC_DEFUN([_MHD_PRINT_FIRST_WORD_BODY], [m4_divert_text([SHELL_FN],[dnl +mhd_fn_print_first_word () { + set dummy $[]1 + AS_ECHO_N(["$[]2"]) +} # _mhd_fn_print_first_word +])])dnl AC_DEFUN _MHD_PRINT_FIRST_WORD_BODY