gcc-plugin.m4 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # gcc-plugin.m4 -*- Autoconf -*-
  2. # Check whether GCC is able to be built with plugin support.
  3. dnl Copyright (C) 2014 Free Software Foundation, Inc.
  4. dnl This file is free software, distributed under the terms of the GNU
  5. dnl General Public License. As a special exception to the GNU General
  6. dnl Public License, this file may be distributed as part of a program
  7. dnl that contains a configuration script generated by Autoconf, under
  8. dnl the same distribution terms as the rest of that program.
  9. # Check for plugin support.
  10. # Respects --enable-plugin.
  11. # Sets the shell variables enable_plugin and pluginlibs.
  12. AC_DEFUN([GCC_ENABLE_PLUGINS],
  13. [# Check for plugin support
  14. AC_ARG_ENABLE(plugin,
  15. [AS_HELP_STRING([--enable-plugin], [enable plugin support])],
  16. enable_plugin=$enableval,
  17. enable_plugin=yes; default_plugin=yes)
  18. pluginlibs=
  19. case "${host}" in
  20. *-*-darwin*)
  21. if test x$build = x$host; then
  22. export_sym_check="nm${exeext} -g"
  23. elif test x$host = x$target; then
  24. export_sym_check="$gcc_cv_nm -g"
  25. else
  26. export_sym_check=
  27. fi
  28. ;;
  29. *)
  30. if test x$build = x$host; then
  31. export_sym_check="objdump${exeext} -T"
  32. elif test x$host = x$target; then
  33. export_sym_check="$gcc_cv_objdump -T"
  34. else
  35. export_sym_check=
  36. fi
  37. ;;
  38. esac
  39. if test x"$enable_plugin" = x"yes"; then
  40. AC_MSG_CHECKING([for exported symbols])
  41. if test "x$export_sym_check" != x; then
  42. echo "int main() {return 0;} int foobar() {return 0;}" > conftest.c
  43. ${CC} ${CFLAGS} ${LDFLAGS} conftest.c -o conftest$ac_exeext > /dev/null 2>&1
  44. if $export_sym_check conftest$ac_exeext | grep -q foobar > /dev/null; then
  45. : # No need to use a flag
  46. AC_MSG_RESULT([yes])
  47. else
  48. AC_MSG_RESULT([yes])
  49. AC_MSG_CHECKING([for -rdynamic])
  50. ${CC} ${CFLAGS} ${LDFLAGS} -rdynamic conftest.c -o conftest$ac_exeext > /dev/null 2>&1
  51. if $export_sym_check conftest$ac_exeext | grep -q foobar > /dev/null; then
  52. plugin_rdynamic=yes
  53. pluginlibs="-rdynamic"
  54. else
  55. plugin_rdynamic=no
  56. enable_plugin=no
  57. fi
  58. AC_MSG_RESULT([$plugin_rdynamic])
  59. fi
  60. else
  61. AC_MSG_RESULT([unable to check])
  62. fi
  63. # Check -ldl
  64. saved_LIBS="$LIBS"
  65. AC_SEARCH_LIBS([dlopen], [dl])
  66. if test x"$ac_cv_search_dlopen" = x"-ldl"; then
  67. pluginlibs="$pluginlibs -ldl"
  68. fi
  69. LIBS="$saved_LIBS"
  70. # Check that we can build shared objects with -fPIC -shared
  71. saved_LDFLAGS="$LDFLAGS"
  72. saved_CFLAGS="$CFLAGS"
  73. case "${host}" in
  74. *-*-darwin*)
  75. CFLAGS=`echo $CFLAGS | sed s/-mdynamic-no-pic//g`
  76. CFLAGS="$CFLAGS -fPIC"
  77. LDFLAGS="$LDFLAGS -shared -undefined dynamic_lookup"
  78. ;;
  79. *)
  80. CFLAGS="$CFLAGS -fPIC"
  81. LDFLAGS="$LDFLAGS -fPIC -shared"
  82. ;;
  83. esac
  84. AC_MSG_CHECKING([for -fPIC -shared])
  85. AC_TRY_LINK(
  86. [extern int X;],[return X == 0;],
  87. [AC_MSG_RESULT([yes]); have_pic_shared=yes],
  88. [AC_MSG_RESULT([no]); have_pic_shared=no])
  89. if test x"$have_pic_shared" != x"yes" -o x"$ac_cv_search_dlopen" = x"no"; then
  90. pluginlibs=
  91. enable_plugin=no
  92. fi
  93. LDFLAGS="$saved_LDFLAGS"
  94. CFLAGS="$saved_CFLAGS"
  95. # If plugin support had been requested but not available, fail.
  96. if test x"$enable_plugin" = x"no" ; then
  97. if test x"$default_plugin" != x"yes"; then
  98. AC_MSG_ERROR([
  99. Building GCC with plugin support requires a host that supports
  100. -fPIC, -shared, -ldl and -rdynamic.])
  101. fi
  102. fi
  103. fi
  104. ])