]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Check if clang and clang++ are used to test glibc
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 17 Dec 2024 19:25:09 +0000 (03:25 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 18 Dec 2024 10:50:18 +0000 (18:50 +0800)
Set have-test-clang to yes if clang is used to test glibc.  Set
have-test-clangxx to yes if clang++ is used to test glibc.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
aclocal.m4
configure
configure.ac

index 88ed3a6b71f1349eb39f9c7f48b6ab2b5c5ce321..fb4c1ef1c485d3f9c16f08e9836970a7488394c6 100644 (file)
@@ -326,6 +326,16 @@ CC="$TEST_CC"
 CC="$saved_CC"
 ])
 
+dnl Run a test with TEST_CXX.
+dnl LIBC_CHECK_TEST_CXX([commands])
+AC_DEFUN([LIBC_CHECK_TEST_CXX],
+[
+saved_CXX="$CXX"
+CXX="$TEST_CXX"
+[$1]
+CXX="$saved_CXX"
+])
+
 dnl Test a CC and TEST_CC compiler option or options with an empty input
 dnl file.
 dnl LIBC_TRY_CC_AND_TEST_CC_OPTION([message], [options],
@@ -398,3 +408,42 @@ else
   )
 fi
 ])
+
+dnl Test a TEST_CC compiler option or options with an input file.
+dnl LIBC_TRY_TEST_CC_COMMAND([message], [code], [options],
+dnl   [TEST_CC-cache-id], [TEST_CC-action-if-true], [TEST_CC-action-if-false])
+AC_DEFUN([LIBC_TRY_TEST_CC_COMMAND],
+[
+cat > conftest.c <<EOF
+$2
+EOF
+LIBC_CHECK_TEST_CC(
+  AC_CACHE_CHECK([$1 in testing], $4, [dnl
+    if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $3 conftest.c -o conftest 1>&AS_MESSAGE_LOG_FD])
+    then
+      [$5]
+    else
+      [$6]
+    fi])
+)
+rm -f conftest*])
+
+dnl Test a TEST_CXX compiler option or options with an input file.
+dnl LIBC_TRY_TEST_CXX_COMMAND([message], [code], [options],
+dnl   [TEST_CXX-cache-id], [TEST_CXX-action-if-true],
+dnl   [TEST_CXX-action-if-false])
+AC_DEFUN([LIBC_TRY_TEST_CXX_COMMAND],
+[
+cat > conftest.cc <<EOF
+$2
+EOF
+LIBC_CHECK_TEST_CXX(
+  AC_CACHE_CHECK([$1 in testing], $4, [dnl
+    if AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS $3 conftest.cc -o conftest 1>&AS_MESSAGE_LOG_FD])
+    then
+      [$5]
+    else
+      [$6]
+    fi])
+)
+rm -f conftest*])
index 2c2b19f9a6a26558eca356aa7af680ae3dedf02c..e9c18316fed358cdaf9b7ee2f7402a868cae3c59 100755 (executable)
--- a/configure
+++ b/configure
@@ -5993,6 +5993,82 @@ fi
 printf "%s\n" "$libc_cv_with_fp" >&6; }
 
 
+conftest_code="
+#ifndef __clang__
+#error Not Clang!
+#endif
+"
+
+
+cat > conftest.c <<EOF
+$conftest_code
+EOF
+
+saved_CC="$CC"
+CC="$TEST_CC"
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for clang in testing" >&5
+printf %s "checking for clang in testing... " >&6; }
+if test ${libc_cv_test_clang+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e)     if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c -o conftest 1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+    then
+      libc_cv_test_clang=yes
+    else
+      libc_cv_test_clang=no
+    fi ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_clang" >&5
+printf "%s\n" "$libc_cv_test_clang" >&6; }
+
+CC="$saved_CC"
+
+rm -f conftest*
+config_vars="$config_vars
+have-test-clang = $libc_cv_test_clang"
+
+
+cat > conftest.cc <<EOF
+$conftest_code
+EOF
+
+saved_CXX="$CXX"
+CXX="$TEST_CXX"
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for clang++ in testing" >&5
+printf %s "checking for clang++ in testing... " >&6; }
+if test ${libc_cv_test_clangxx+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e)     if { ac_try='${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc -o conftest 1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+    then
+      libc_cv_test_clangxx=yes
+    else
+      libc_cv_test_clangxx=no
+    fi ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_clangxx" >&5
+printf "%s\n" "$libc_cv_test_clangxx" >&6; }
+
+CXX="$saved_CXX"
+
+rm -f conftest*
+config_vars="$config_vars
+have-test-clangxx = $libc_cv_test_clangxx"
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -fstack-protector" >&5
 printf %s "checking for -fstack-protector... " >&6; }
 if test ${libc_cv_ssp+y}
index 1de79bd729597250c2f462812c88b137ae6a2a06..85c92e5083b0016e0c419b1c86ea3b66eae47844 100644 (file)
@@ -641,6 +641,30 @@ fi
 rm -f conftest*])
 AC_SUBST(libc_cv_with_fp)
 
+conftest_code="
+#ifndef __clang__
+#error Not Clang!
+#endif
+"
+
+dnl Check if clang is used to test glibc.
+LIBC_TRY_TEST_CC_COMMAND([for clang],
+  [$conftest_code],
+  [-c],
+  libc_cv_test_clang,
+  [libc_cv_test_clang=yes], [libc_cv_test_clang=no],
+)
+LIBC_CONFIG_VAR([have-test-clang], [$libc_cv_test_clang])
+
+dnl Check if clang++ is used to test glibc.
+LIBC_TRY_TEST_CXX_COMMAND([for clang++],
+  [$conftest_code],
+  [-c],
+  libc_cv_test_clangxx,
+  [libc_cv_test_clangxx=yes], [libc_cv_test_clangxx=no],
+)
+LIBC_CONFIG_VAR([have-test-clangxx], [$libc_cv_test_clangxx])
+
 AC_CACHE_CHECK(for -fstack-protector, libc_cv_ssp, [dnl
 LIBC_TRY_CC_OPTION([$CFLAGS $CPPFLAGS -Werror -fstack-protector],
                   [libc_cv_ssp=yes],