gcc-plugin.m4 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. plugin_check=yes
  20. case "${host}" in
  21. *-*-mingw*)
  22. # Since plugin support under MinGW is not as straightforward as on
  23. # other platforms (e.g., we have to link import library, etc), we
  24. # only enable it if explicitly requested.
  25. if test x"$default_plugin" = x"yes"; then
  26. enable_plugin=no
  27. elif test x"$enable_plugin" = x"yes"; then
  28. # Use make's target variable to derive import library name.
  29. pluginlibs='-Wl,--export-all-symbols -Wl,--out-implib=[$]@.a'
  30. plugin_check=no
  31. fi
  32. ;;
  33. *-*-darwin*)
  34. if test x$build = x$host; then
  35. export_sym_check="nm${exeext} -g"
  36. elif test x$host = x$target; then
  37. export_sym_check="$gcc_cv_nm -g"
  38. else
  39. export_sym_check=
  40. fi
  41. ;;
  42. *)
  43. if test x$build = x$host; then
  44. export_sym_check="objdump${exeext} -T"
  45. elif test x$host = x$target; then
  46. export_sym_check="$gcc_cv_objdump -T"
  47. else
  48. export_sym_check=
  49. fi
  50. ;;
  51. esac
  52. if test x"$enable_plugin" = x"yes" -a x"$plugin_check" = x"yes"; then
  53. AC_MSG_CHECKING([for exported symbols])
  54. if test "x$export_sym_check" != x; then
  55. echo "int main() {return 0;} int foobar() {return 0;}" > conftest.c
  56. ${CC} ${CFLAGS} ${LDFLAGS} conftest.c -o conftest$ac_exeext > /dev/null 2>&1
  57. if $export_sym_check conftest$ac_exeext | grep foobar > /dev/null; then
  58. : # No need to use a flag
  59. AC_MSG_RESULT([yes])
  60. else
  61. AC_MSG_RESULT([yes])
  62. AC_MSG_CHECKING([for -rdynamic])
  63. ${CC} ${CFLAGS} ${LDFLAGS} -rdynamic conftest.c -o conftest$ac_exeext > /dev/null 2>&1
  64. if $export_sym_check conftest$ac_exeext | grep foobar > /dev/null; then
  65. plugin_rdynamic=yes
  66. pluginlibs="-rdynamic"
  67. else
  68. plugin_rdynamic=no
  69. enable_plugin=no
  70. fi
  71. AC_MSG_RESULT([$plugin_rdynamic])
  72. fi
  73. else
  74. AC_MSG_RESULT([unable to check])
  75. fi
  76. # Check -ldl
  77. saved_LIBS="$LIBS"
  78. AC_SEARCH_LIBS([dlopen], [dl])
  79. if test x"$ac_cv_search_dlopen" = x"-ldl"; then
  80. pluginlibs="$pluginlibs -ldl"
  81. fi
  82. LIBS="$saved_LIBS"
  83. # Check that we can build shared objects with -fPIC -shared
  84. saved_LDFLAGS="$LDFLAGS"
  85. saved_CFLAGS="$CFLAGS"
  86. case "${host}" in
  87. *-*-darwin*)
  88. CFLAGS=`echo $CFLAGS | sed s/-mdynamic-no-pic//g`
  89. CFLAGS="$CFLAGS -fPIC"
  90. LDFLAGS="$LDFLAGS -shared -undefined dynamic_lookup"
  91. ;;
  92. *)
  93. CFLAGS="$CFLAGS -fPIC"
  94. LDFLAGS="$LDFLAGS -fPIC -shared"
  95. ;;
  96. esac
  97. AC_MSG_CHECKING([for -fPIC -shared])
  98. AC_TRY_LINK(
  99. [extern int X;],[return X == 0;],
  100. [AC_MSG_RESULT([yes]); have_pic_shared=yes],
  101. [AC_MSG_RESULT([no]); have_pic_shared=no])
  102. if test x"$have_pic_shared" != x"yes" -o x"$ac_cv_search_dlopen" = x"no"; then
  103. pluginlibs=
  104. enable_plugin=no
  105. fi
  106. LDFLAGS="$saved_LDFLAGS"
  107. CFLAGS="$saved_CFLAGS"
  108. # If plugin support had been requested but not available, fail.
  109. if test x"$enable_plugin" = x"no" ; then
  110. if test x"$default_plugin" != x"yes"; then
  111. AC_MSG_ERROR([
  112. Building GCC with plugin support requires a host that supports
  113. -fPIC, -shared, -ldl and -rdynamic.])
  114. fi
  115. fi
  116. fi
  117. ])
  118. dnl
  119. dnl
  120. dnl GCC_PLUGIN_OPTION
  121. dnl (SHELL-CODE_HANDLER)
  122. dnl
  123. AC_DEFUN([GCC_PLUGIN_OPTION],[dnl
  124. AC_MSG_CHECKING([for -plugin option])
  125. plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll"
  126. plugin_option=
  127. for plugin in $plugin_names; do
  128. plugin_so=`${CC} ${CFLAGS} --print-prog-name $plugin`
  129. if test x$plugin_so = x$plugin; then
  130. plugin_so=`${CC} ${CFLAGS} --print-file-name $plugin`
  131. fi
  132. if test x$plugin_so != x$plugin; then
  133. plugin_option="--plugin $plugin_so"
  134. break
  135. fi
  136. done
  137. dnl Check if ${AR} $plugin_option rc works.
  138. AC_CHECK_TOOL(AR, ar)
  139. if test "${AR}" = "" ; then
  140. AC_MSG_ERROR([Required archive tool 'ar' not found on PATH.])
  141. fi
  142. touch conftest.c
  143. ${AR} $plugin_option rc conftest.a conftest.c
  144. if test "$?" != 0; then
  145. AC_MSG_WARN([Failed: $AR $plugin_option rc])
  146. plugin_option=
  147. fi
  148. rm -f conftest.*
  149. if test -n "$plugin_option"; then
  150. $1="$plugin_option"
  151. AC_MSG_RESULT($plugin_option)
  152. else
  153. AC_MSG_RESULT([no])
  154. fi
  155. ])