Cygwin: try to avoid recalling offline files
[newlib-cygwin.git] / config / gcc-plugin.m4
blob23c95be278e5aea5fd6baf4d256c26b5698ce097
1 # gcc-plugin.m4 -*- Autoconf -*-
2 # Check whether GCC is able to be built with plugin support.
4 dnl Copyright (C) 2014 Free Software Foundation, Inc.
5 dnl This file is free software, distributed under the terms of the GNU
6 dnl General Public License.  As a special exception to the GNU General
7 dnl Public License, this file may be distributed as part of a program
8 dnl that contains a configuration script generated by Autoconf, under
9 dnl the same distribution terms as the rest of that program.
11 # Check for plugin support.
12 # Respects --enable-plugin.
13 # Sets the shell variables enable_plugin and pluginlibs.
14 AC_DEFUN([GCC_ENABLE_PLUGINS],
15   [# Check for plugin support
16    AC_ARG_ENABLE(plugin,
17    [AS_HELP_STRING([--enable-plugin], [enable plugin support])],
18    enable_plugin=$enableval,
19    enable_plugin=yes; default_plugin=yes)
21    pluginlibs=
23    case "${host}" in
24      *-*-darwin*)
25        if test x$build = x$host; then
26          export_sym_check="nm${exeext} -g"
27        elif test x$host = x$target; then
28          export_sym_check="$gcc_cv_nm -g"
29        else
30          export_sym_check=
31        fi
32      ;;
33      *)
34        if test x$build = x$host; then
35          export_sym_check="objdump${exeext} -T"
36        elif test x$host = x$target; then
37          export_sym_check="$gcc_cv_objdump -T"
38        else
39          export_sym_check=
40        fi
41      ;;
42    esac
44    if test x"$enable_plugin" = x"yes"; then
46      AC_MSG_CHECKING([for exported symbols])
47      if test "x$export_sym_check" != x; then
48        echo "int main() {return 0;} int foobar() {return 0;}" > conftest.c
49        ${CC} ${CFLAGS} ${LDFLAGS} conftest.c -o conftest$ac_exeext > /dev/null 2>&1
50        if $export_sym_check conftest$ac_exeext | grep -q foobar > /dev/null; then
51          : # No need to use a flag
52          AC_MSG_RESULT([yes])
53        else
54          AC_MSG_RESULT([yes])
55          AC_MSG_CHECKING([for -rdynamic])
56          ${CC} ${CFLAGS} ${LDFLAGS} -rdynamic conftest.c -o conftest$ac_exeext > /dev/null 2>&1
57          if $export_sym_check conftest$ac_exeext | grep -q foobar > /dev/null; then
58            plugin_rdynamic=yes
59            pluginlibs="-rdynamic"
60          else
61            plugin_rdynamic=no
62            enable_plugin=no
63          fi
64          AC_MSG_RESULT([$plugin_rdynamic])
65        fi
66      else
67        AC_MSG_RESULT([unable to check])
68      fi
70      # Check -ldl
71      saved_LIBS="$LIBS"
72      AC_SEARCH_LIBS([dlopen], [dl])
73      if test x"$ac_cv_search_dlopen" = x"-ldl"; then
74        pluginlibs="$pluginlibs -ldl"
75      fi
76      LIBS="$saved_LIBS"
78      # Check that we can build shared objects with -fPIC -shared
79      saved_LDFLAGS="$LDFLAGS"
80      saved_CFLAGS="$CFLAGS"
81      case "${host}" in
82        *-*-darwin*)
83          CFLAGS=`echo $CFLAGS | sed s/-mdynamic-no-pic//g`
84          CFLAGS="$CFLAGS -fPIC"
85          LDFLAGS="$LDFLAGS -shared -undefined dynamic_lookup"
86        ;;
87        *)
88          CFLAGS="$CFLAGS -fPIC"
89          LDFLAGS="$LDFLAGS -fPIC -shared"
90        ;;
91      esac
92      AC_MSG_CHECKING([for -fPIC -shared])
93      AC_TRY_LINK(
94        [extern int X;],[return X == 0;],
95        [AC_MSG_RESULT([yes]); have_pic_shared=yes],
96        [AC_MSG_RESULT([no]); have_pic_shared=no])
97      if test x"$have_pic_shared" != x"yes" -o x"$ac_cv_search_dlopen" = x"no"; then
98        pluginlibs=
99        enable_plugin=no
100      fi
101      LDFLAGS="$saved_LDFLAGS"
102      CFLAGS="$saved_CFLAGS"
104      # If plugin support had been requested but not available, fail.
105      if test x"$enable_plugin" = x"no" ; then
106        if test x"$default_plugin" != x"yes"; then
107          AC_MSG_ERROR([
108    Building GCC with plugin support requires a host that supports
109    -fPIC, -shared, -ldl and -rdynamic.])
110        fi
111      fi
112    fi
117 dnl GCC_PLUGIN_OPTION
118 dnl    (SHELL-CODE_HANDLER)
120 AC_DEFUN([GCC_PLUGIN_OPTION],[dnl
121 AC_MSG_CHECKING([for -plugin option])
123 plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll"
124 plugin_option=
125 for plugin in $plugin_names; do
126   plugin_so=`${CC} ${CFLAGS} --print-prog-name $plugin`
127   if test x$plugin_so = x$plugin; then
128     plugin_so=`${CC} ${CFLAGS} --print-file-name $plugin`
129   fi
130   if test x$plugin_so != x$plugin; then
131     plugin_option="--plugin $plugin_so"
132     break
133   fi
134 done
135 dnl Check if ${AR} $plugin_option rc works.
136 AC_CHECK_TOOL(AR, ar)
137 if test "${AR}" = "" ; then
138   AC_MSG_ERROR([Required archive tool 'ar' not found on PATH.])
140 touch conftest.c
141 ${AR} $plugin_option rc conftest.a conftest.c
142 if test "$?" != 0; then
143   AC_MSG_WARN([Failed: $AR $plugin_option rc])
144   plugin_option=
146 rm -f conftest.*
147 if test -n "$plugin_option"; then
148   $1="$plugin_option"
149   AC_MSG_RESULT($plugin_option)
150 else
151   AC_MSG_RESULT([no])