File: clang-plugin.m4

package info (click to toggle)
binutils 2.46-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 417,664 kB
  • sloc: ansic: 1,487,508; asm: 829,455; cpp: 216,692; exp: 80,524; makefile: 73,157; sh: 24,213; yacc: 15,060; lisp: 13,632; perl: 13,404; lex: 1,714; ada: 1,681; pascal: 1,446; cs: 879; python: 637; java: 478; sed: 191; xml: 95; awk: 25
file content (109 lines) | stat: -rw-r--r-- 3,049 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# 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"
])