gcc.m4 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. dnl -*- Autoconf -*-
  2. dnl
  3. dnl Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
  4. dnl
  5. dnl StarPU is free software; you can redistribute it and/or modify
  6. dnl it under the terms of the GNU Lesser General Public License as published by
  7. dnl the Free Software Foundation; either version 2.1 of the License, or (at
  8. dnl your option) any later version.
  9. dnl
  10. dnl StarPU is distributed in the hope that it will be useful, but
  11. dnl WITHOUT ANY WARRANTY; without even the implied warranty of
  12. dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. dnl
  14. dnl See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. dnl Run its argument with CPPFLAGS pointing to GCC's plug-in API.
  16. AC_DEFUN([_STARPU_WITH_GCC_PLUGIN_API], [
  17. GCC_PLUGIN_INCLUDE_DIR="`"$CC" -print-file-name=plugin`/include"
  18. save_CPPFLAGS="$CPPFLAGS"
  19. CPPFLAGS="-I$GCC_PLUGIN_INCLUDE_DIR"
  20. $1
  21. CPPFLAGS="$save_CPPFLAGS"
  22. ])
  23. dnl Set $ac_cv_starpu_gcc_for_plugin to the compiler to use to compile
  24. dnl GCC plug-ins. It's `gcc' for GCC 4.5/4.6, probably `g++' for 4.7,
  25. dnl and definitely `g++' for 4.8, because the last two build
  26. dnl themselves with `g++', leading to mangled names.
  27. dnl See <http://thread.gmane.org/gmane.comp.gcc.devel/125210> for details.
  28. AC_DEFUN([_STARPU_GCC_PLUGIN_LANGUAGE], [
  29. AC_CACHE_CHECK([which compiler to use to build GCC plug-ins],
  30. [ac_cv_starpu_gcc_for_plugin], [
  31. for GCC_FOR_PLUGIN in "$CC" "$CXX" ""
  32. do
  33. if test "x$GCC_FOR_PLUGIN" = "x"; then
  34. break;
  35. fi
  36. cat > conftest.c <<END_OF_CONFTEST
  37. #include <gcc-plugin.h>
  38. #include <plugin-version.h>
  39. #include <cpplib.h>
  40. int plugin_is_GPL_compatible;
  41. extern struct cpp_reader *parse_in; /* C-family front-ends */
  42. static void
  43. define_something (void *gcc_data, void *user_data)
  44. {
  45. cpp_define (parse_in, "CONFTEST_GCC_PLUGIN=1");
  46. }
  47. int
  48. plugin_init (struct plugin_name_args *plugin_info,
  49. struct plugin_gcc_version *version)
  50. {
  51. if (!plugin_default_version_check (version, &gcc_version))
  52. return 1;
  53. register_callback ("conftest", PLUGIN_START_UNIT,
  54. define_something, NULL);
  55. return 0;
  56. }
  57. END_OF_CONFTEST
  58. # Build the plug-in.
  59. rm -f conftest.so
  60. _STARPU_WITH_GCC_PLUGIN_API([
  61. _AC_DO(["$GCC_FOR_PLUGIN" "$CPPFLAGS" -fPIC -shared conftest.c -o conftest.so]) || {
  62. AC_MSG_ERROR([failed to build a GCC plug-in with `$GCC_FOR_PLUGIN'])
  63. }
  64. ])
  65. # Attempt to use it.
  66. save_CFLAGS="$CFLAGS"
  67. CFLAGS="-fplugin=$PWD/conftest.so"
  68. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  69. #ifndef CONFTEST_GCC_PLUGIN
  70. # error plug-in not loaded
  71. #endif]], [])],
  72. [ac_cv_starpu_gcc_for_plugin="$GCC_FOR_PLUGIN"], [:])
  73. CFLAGS="$save_CFLAGS"
  74. rm -f conftest.so conftest.c
  75. if test "x$ac_cv_starpu_gcc_for_plugin" != "x"; then
  76. # We're done.
  77. break
  78. fi
  79. done
  80. if test "x$ac_cv_starpu_gcc_for_plugin" = "x"; then
  81. AC_MSG_RESULT([none])
  82. AC_MSG_ERROR([could not find a suitable compiler for GCC plug-ins])
  83. fi
  84. ])
  85. $1="$ac_cv_starpu_gcc_for_plugin"
  86. ])
  87. dnl Check whether GCC plug-in support is available (GCC 4.5+).
  88. AC_DEFUN([STARPU_GCC_PLUGIN_SUPPORT], [
  89. AC_REQUIRE([AC_PROG_CC])
  90. AC_REQUIRE([AC_PROG_CXX]) dnl for GCC 4.7+
  91. AC_CACHE_CHECK([whether GCC supports plug-ins], [ac_cv_have_gcc_plugins], [
  92. if test "x$GCC" = xyes; then
  93. # ICC 12.1.0 and Clang 3.1 (among others) support `--version',
  94. # define `__GNUC__', and provide a `-print-file-name=plugin'
  95. # that returns GCC's valid header directory. This makes them
  96. # hardly distinguishable from GCC. Actually, ICC 12.1.0 is able
  97. # to compile our plug-in, but silently ignores `-fplugin', leading
  98. # to obvious build failures; thus, it is explicitly excluded below.
  99. _STARPU_WITH_GCC_PLUGIN_API([
  100. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gcc-plugin.h>
  101. #include <tree.h>
  102. #include <gimple.h>
  103. #if defined __INTEL_COMPILER || defined __ICC
  104. Beware, this compiler is a fake. Don't use it.
  105. #endif
  106. tree fndecl; gimple call;]],
  107. [[/* Clang 3.1 doesn't support nested functions, so try to
  108. discriminate it this way. */
  109. tree foo (void)
  110. {
  111. return lookup_name (get_identifier ("puts"));
  112. }
  113. fndecl = foo ();
  114. call = gimple_build_call (fndecl, 0);]])],
  115. [ac_cv_have_gcc_plugins="yes"],
  116. [ac_cv_have_gcc_plugins="no"])
  117. ])
  118. else
  119. ac_cv_have_gcc_plugins="no"
  120. fi
  121. ])
  122. if test "x$ac_cv_have_gcc_plugins" = "xyes"; then
  123. dnl Check for specific features.
  124. dnl
  125. dnl Reason:
  126. dnl build_call_expr_loc_array -- not in GCC 4.5.x; appears in 4.6
  127. dnl build_call_expr_loc_vec -- likewise
  128. dnl build_array_ref -- present but undeclared in 4.6.1
  129. dnl build_zero_cst -- not in GCC 4.5.x; appears in 4.6
  130. dnl builtin_decl_explicit -- new in 4.7, replaces `built_in_decls'
  131. _STARPU_WITH_GCC_PLUGIN_API([
  132. AC_CHECK_DECLS([build_call_expr_loc_array, build_call_expr_loc_vec,
  133. build_array_ref, build_zero_cst,
  134. builtin_decl_explicit],
  135. [], [], [#include <gcc-plugin.h>
  136. #include <tree.h>])
  137. dnl Work around header naming issues introduced upstream and in Debian
  138. dnl (see <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=631082>).
  139. AC_CHECK_HEADERS([c-common.h c-pragma.h c-family/c-common.h c-family/c-pragma.h],
  140. [], [], [#include <gcc-plugin.h>
  141. #include <tree.h>])
  142. ])
  143. AC_DEFINE_UNQUOTED([STARPU_INCLUDE_DIR],
  144. ["`eval "echo $includedir"`/starpu/$STARPU_EFFECTIVE_VERSION"],
  145. [Define to the directory where StarPU's headers are installed.])
  146. dnl Now, `gcc' or `g++'?
  147. _STARPU_GCC_PLUGIN_LANGUAGE([GCC_FOR_PLUGIN])
  148. AC_SUBST([GCC_FOR_PLUGIN])
  149. dnl Determine the corresponding Libtool tag.
  150. if test "$GCC_FOR_PLUGIN" = "$CXX"; then
  151. GCC_FOR_PLUGIN_LIBTOOL_TAG="CXX"
  152. else
  153. GCC_FOR_PLUGIN_LIBTOOL_TAG="CC"
  154. fi
  155. AC_SUBST([GCC_FOR_PLUGIN_LIBTOOL_TAG])
  156. fi
  157. AC_SUBST([GCC_PLUGIN_INCLUDE_DIR])
  158. ])
  159. dnl Substitute `STARPU_GCC_VERSION_MAJOR' and `STARPU_GCC_VERSION_MINOR'.
  160. AC_DEFUN([STARPU_GCC_VERSION], [
  161. AC_COMPUTE_INT([STARPU_GCC_VERSION_MAJOR], [__GNUC__])
  162. AC_COMPUTE_INT([STARPU_GCC_VERSION_MINOR], [__GNUC_MINOR__])
  163. AC_SUBST([STARPU_GCC_VERSION_MAJOR])
  164. AC_SUBST([STARPU_GCC_VERSION_MINOR])
  165. ])