commit 56b73aac7c82734294f05c9cbcf654f40a6b3224
parent c986f16bf4dee99859fa6849316112a014567d4b
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Mon, 13 Apr 2026 14:13:01 +0200
configure: moved clang detection to dedicated macro
Diffstat:
2 files changed, 52 insertions(+), 37 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -347,25 +347,7 @@ MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-fno-strict-aliasing], [-qnoansialias])
MHD_CHECK_ADD_CC_CFLAG([-qlonglong], [CFLAGS_ac])
# Set basic optimisation flags
-AS_VAR_IF([enable_build_type],["neutral"],[],
- [ # Any non-neutral build types
- AC_CACHE_CHECK([whether $CC is clang or clang-based],
- [mhd_cv_cc_clang_based],
- [
- AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
-#if ! defined(__clang__) && ! defined(__llvm__)
-#error Compiler is not clang-based
-fail test here %%%@<:@-1@:>@
-#endif
- ]]
- )
- ],
- [mhd_cv_cc_clang_based="yes"],[mhd_cv_cc_clang_based="no"]
- )
- ]
- )
- ]
-)
+MHD_CHECK_CC_IS_CLANG
AS_CASE([${enable_build_type}],[debug|debugger|trace],
[ # Debug build, build for walking with debugger or debug printing build
CFLAGS="${user_CFLAGS}"
@@ -705,24 +687,7 @@ AS_VAR_IF([enable_lto],["no"],[use_lto="no"],
lto_CFLAGS=""
lto_LDFLAGS=""
use_lto=""
- AC_CACHE_CHECK([whether $CC is clang or clang-based],
- [mhd_cv_cc_clang_based],
- [
- AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
-#if ! defined(__clang__) && ! defined(__llvm__)
-#error Compiler is not clang-based
-fail test here %%%@<:@-1@:>@
-#endif
- ]]
- )
- ],
- [mhd_cv_cc_clang_based="yes"],[mhd_cv_cc_clang_based="no"]
- )
- ]
- )
- AS_VAR_IF([mhd_cv_cc_clang_based],["yes"],
- [MHD_CHECK_ADD_CC_LDFLAG([-fuse-ld=lld],[lto_LDFLAGS])]
- )
+ MHD_CHECK_CC_IS_CLANG([MHD_CHECK_ADD_CC_LDFLAG([-fuse-ld=lld],[lto_LDFLAGS])])
LDFLAGS="${lto_LDFLAGS} ${LDFLAGS_ac} ${user_LDFLAGS}"
MHD_FIND_ADD_CC_CFLAG_IFELSE(
[
diff --git a/m4/mhd_check_cc_is_clang.m4 b/m4/mhd_check_cc_is_clang.m4
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: FSFAP
+#
+# SYNOPSIS
+#
+# MHD_CHECK_CC_IS_CLANG([ACTION-IF-CLANG], [ACTION-IF-NOT-CLANG])
+#
+# DESCRIPTION
+#
+# This macro checks whether the compiler set by $CC is actually clang or
+# llvm-based compiler.
+# The result is cached in variable mhd_cv_cc_clang_based.
+#
+# Example usage:
+#
+# MHD_CHECK_CC_IS_CLANG
+#
+#
+# LICENSE
+#
+# Copyright (c) 2022-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_CC_IS_CLANG],[dnl
+AC_PREREQ([2.64])dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_CACHE_CHECK([whether $CC is clang or llvm-based],
+[mhd_cv_cc_clang_based],
+[AS_VAR_IF([GCC],["yes"],
+[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+#if ! defined(__clang__) && ! defined(__llvm__)
+#error This compiler is not clang nor llvm-based compiler
+fail test here %%%@<:@-1@:>@
+#endif
+void test_func1(void);
+void test_func1(void) {return;}
+]])],dnl AC_LANG_SOURCE
+[mhd_cv_cc_clang_based="yes"],[mhd_cv_cc_clang_based="no"])dnl AC_COMPILE_IFELSE
+],[mhd_cv_cc_clang_based="no"])dnl AS_VAR_IF GCC
+])
+dnl AC_CACHE_CHECK
+m4_n([m4_ifnblank([$1$2],[AS_VAR_IF([mhd_cv_cc_clang_based],["yes"],[$1],[$2])])])dnl
+# Re-use result in AX_PTHREAD macro
+AS_VAR_SET_IF([ax_cv_PTHREAD_CLANG],[:],[ax_cv_PTHREAD_CLANG="$mhd_cv_cc_clang_based"])
+])dnl AC_DEFUN MHD_CHECK_ADD_CC_CFLAG