Files
binutils-gdb/config/clang-plugin.m4
Alan Modra 87b6078fc2 tidy m4 plugin config support
In CLANG_PLUGIN_FILE it is possible for plugin_file to be non-NULL
when LLVMgold.so does not exist.

configure output is messy, with results not printed against their
  "checking.." line, eg.
checking for clang... (cached) yes
checking for clang plugin file... checking for x86_64-pc-linux-gnu-ar... (cached) ar --plugin /usr/lib/llvm-20/lib/clang/20/../../LLVMgold.so
/usr/lib/llvm-20/lib/clang/20/../../LLVMgold.so

This patch fixes those problems, and a similar interposition of other
configure output between AC_MSG_CHECKING and AC_MSG_RESULT in
gcc-plugin.m4.  It also tidies some of the message text, and makes
similar code in gcc-plugin.m4 and clang-plugin.m4 a little more
consistent.

config/
	* clang-plugin.m4 (CLANG_PLUGIN_FILE): Don't place checks for
	tools (llvm-config, ar) inside AC_MSG_CHECKING..AC_MSG_RESULT
	for clang plugin file.  Clear plugin_file before loop exit.
	(CLANG_PLUGIN_FILE_FOR_TARGET): Similarly.
	* gcc-plugin.m4 (GCC_PLUGIN_OPTION): Similarly.
	(GCC_PLUGIN_OPTION_FOR_TARGET): Correct AC_MSG_CHECKING.  Tidy
	return code.
binutils/
	* testsuite/lib/binutils-common.exp <llvm_plug_opt>: Set for
	non-native.
	* configure: Regenerate.
/
	* configure: Regenerate.
bfd/
	* configure: Regenerate.
gas/
	* configure: Regenerate.
gdb/
	* configure: Regenerate.
gprof/
	* configure: Regenerate.
gprofng/
	* configure: Regenerate.
	* libcollector/configure: Regenerate.
ld/
	* configure: Regenerate.
libbacktrace/
	* configure: Regenerate.
libctf/
	* configure: Regenerate.
libiberty/
	* configure: Regenerate.
libsframe/
	* configure: Regenerate.
opcodes/
	* configure: Regenerate.
sim/
	* configure: Regenerate.
zlib/
	* configure: Regenerate.
2025-11-03 10:59:50 +10:30

110 lines
3.0 KiB
Plaintext

# clang-plugin.m4 -*- Autoconf -*-
# Check clang plugin file.
dnl Copyright (C) 2025 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.
dnl
dnl
dnl CLANG_PLUGIN_FILE
dnl (SHELL-CODE_HANDLER)
dnl
AC_DEFUN([CLANG_PLUGIN_FILE],[dnl
AC_CACHE_CHECK([for clang], clang_cv_is_clang, [
AC_EGREP_CPP(yes, [
#ifdef __clang__
yes
#endif
], clang_cv_is_clang=yes, clang_cv_is_clang=no)])
AC_CHECK_TOOL(LLVM_CONFIG, llvm-config)
plugin_file=
if test $clang_cv_is_clang = yes; then
AC_MSG_CHECKING([for clang plugin file])
plugin_names="LLVMgold.so"
for plugin in $plugin_names; do
plugin_file=`${CC} ${CFLAGS} --print-file-name $plugin`
if test "$plugin_file" != "$plugin"; then
break;
fi
if test -n "${LLVM_CONFIG}"; then
plugin_file=`${LLVM_CONFIG} --libdir`/$plugin
if test -f "$plugin_file"; then
break;
fi
fi
plugin_file=
done
if test -z "$plugin_file"; then
AC_MSG_RESULT([no])
else
AC_MSG_RESULT($plugin_file)
dnl Check if ${AR} $plugin_option rc works.
AC_CHECK_TOOL(AR, ar)
if test -z "${AR}"; then
AC_MSG_ERROR([Required archive tool 'ar' not found on PATH.])
fi
plugin_option="--plugin $plugin_file"
touch conftest.c
${AR} $plugin_option rc conftest.a conftest.c
if test "$?" != 0; then
AC_MSG_WARN([Failed: $AR $plugin_option rc])
plugin_file=
fi
rm -f conftest.*
fi
fi
$1="$plugin_file"
])
dnl
dnl
dnl CLANG_PLUGIN_FILE_FOR_TARGET
dnl (SHELL-CODE_HANDLER)
dnl
AC_DEFUN([CLANG_PLUGIN_FILE_FOR_TARGET],[dnl
COMPILER_FOR_TARGET="${CC_FOR_TARGET}"
if test x"${COMPILER_FOR_TARGET}" = x"\$(CC)"; then
COMPILER_FOR_TARGET="$CC"
fi
saved_CC="$CC"
CC="$COMPILER_FOR_TARGET"
AC_CACHE_CHECK([for clang for target], clang_target_cv_working, [
AC_TRY_COMPILE([
#ifndef __clang__
#error Not clang
#endif
],
[],
clang_target_cv_working=yes, clang_target_cv_working=no)])
CC="$saved_CC"
plugin_file=
if test $clang_target_cv_working = yes; then
GCC_TARGET_TOOL(llvm-config, LLVM_CONFIG_FOR_TARGET, LLVM_CONFIG)
AC_MSG_CHECKING([for clang plugin file for target])
plugin_names="LLVMgold.so"
for plugin in $plugin_names; do
plugin_file=`${COMPILER_FOR_TARGET} ${CFLAGS_FOR_TARGET} --print-file-name $plugin`
if test "$plugin_file" != "$plugin"; then
break;
fi
if test -n "${LLVM_CONFIG_FOR_TARGET}"; then
plugin_file=`${LLVM_CONFIG_FOR_TARGET} --libdir`/$plugin
if test -f "$plugin_file"; then
break;
fi
fi
plugin_file=
done
if test -z "$plugin_file"; then
AC_MSG_RESULT([no])
else
AC_MSG_RESULT($plugin_file)
fi
fi
$1="$plugin_file"
])