gcc.m4 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. dnl -*- Autoconf -*-
  2. dnl
  3. dnl Copyright (C) 2011, 2012, 2013 Inria
  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. save_LDFLAGS="$LDFLAGS"
  20. CPPFLAGS="-I$GCC_PLUGIN_INCLUDE_DIR"
  21. case "$host_os" in
  22. darwin*)
  23. # Darwin's linker errors out when encountering undefined
  24. # symbols, by default. Tell it to ignore them.
  25. LDFLAGS="-Wl,-undefined -Wl,dynamic_lookup";;
  26. esac
  27. $1
  28. CPPFLAGS="$save_CPPFLAGS"
  29. LDFLAGS="$save_LDFLAGS"
  30. ])
  31. dnl Set $ac_cv_starpu_gcc_for_plugin to the compiler to use to compile
  32. dnl GCC plug-ins. It's `gcc' for GCC 4.5/4.6, probably `g++' for 4.7,
  33. dnl and definitely `g++' for 4.8, because the last two build
  34. dnl themselves with `g++', leading to mangled names.
  35. dnl See <http://thread.gmane.org/gmane.comp.gcc.devel/125210> for details.
  36. AC_DEFUN([_STARPU_GCC_PLUGIN_LANGUAGE], [
  37. AC_CACHE_CHECK([which compiler to use to build GCC plug-ins],
  38. [ac_cv_starpu_gcc_for_plugin], [
  39. for GCC_FOR_PLUGIN in "$CC" "$CXX" ""
  40. do
  41. if test "x$GCC_FOR_PLUGIN" = "x"; then
  42. break;
  43. fi
  44. cat > conftest.c <<END_OF_CONFTEST
  45. #include <gcc-plugin.h>
  46. #include <plugin-version.h>
  47. #include <cpplib.h>
  48. int plugin_is_GPL_compatible;
  49. extern struct cpp_reader *parse_in; /* C-family front-ends */
  50. static void
  51. define_something (void *gcc_data, void *user_data)
  52. {
  53. cpp_define (parse_in, "CONFTEST_GCC_PLUGIN=1");
  54. }
  55. int
  56. plugin_init (struct plugin_name_args *plugin_info,
  57. struct plugin_gcc_version *version)
  58. {
  59. if (!plugin_default_version_check (version, &gcc_version))
  60. return 1;
  61. register_callback ("conftest", PLUGIN_START_UNIT,
  62. define_something, NULL);
  63. return 0;
  64. }
  65. END_OF_CONFTEST
  66. # Build the plug-in.
  67. rm -f conftest.so
  68. _STARPU_WITH_GCC_PLUGIN_API([
  69. _AC_DO(["$GCC_FOR_PLUGIN" "$CPPFLAGS" -fPIC -shared conftest.c -o conftest.so]) || {
  70. AC_MSG_ERROR([failed to build a GCC plug-in with `$GCC_FOR_PLUGIN'])
  71. }
  72. ])
  73. # Attempt to use it.
  74. save_CFLAGS="$CFLAGS"
  75. CFLAGS="-fplugin=$PWD/conftest.so"
  76. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  77. #ifndef CONFTEST_GCC_PLUGIN
  78. # error plug-in not loaded
  79. #endif]], [])],
  80. [ac_cv_starpu_gcc_for_plugin="$GCC_FOR_PLUGIN"], [:])
  81. CFLAGS="$save_CFLAGS"
  82. rm -f conftest.so conftest.c
  83. if test "x$ac_cv_starpu_gcc_for_plugin" != "x"; then
  84. # We're done.
  85. break
  86. fi
  87. done
  88. if test "x$ac_cv_starpu_gcc_for_plugin" = "x"; then
  89. AC_MSG_RESULT([none])
  90. AC_MSG_ERROR([could not find a suitable compiler for GCC plug-ins])
  91. fi
  92. ])
  93. $1="$ac_cv_starpu_gcc_for_plugin"
  94. ])
  95. dnl Check whether GCC plug-in support is available (GCC 4.5+).
  96. AC_DEFUN([STARPU_GCC_PLUGIN_SUPPORT], [
  97. AC_REQUIRE([AC_PROG_CC])
  98. AC_REQUIRE([AC_PROG_CXX]) dnl for GCC 4.7+
  99. AC_CACHE_CHECK([whether GCC supports plug-ins], [ac_cv_have_gcc_plugins], [
  100. if test "x$GCC" = xyes; then
  101. # ICC 12.1.0 and Clang 3.1 (among others) support `--version',
  102. # define `__GNUC__', and provide a `-print-file-name=plugin'
  103. # that returns GCC's valid header directory. This makes them
  104. # hardly distinguishable from GCC. Actually, ICC 12.1.0 is able
  105. # to compile our plug-in, but silently ignores `-fplugin', leading
  106. # to obvious build failures; thus, it is explicitly excluded below.
  107. _STARPU_WITH_GCC_PLUGIN_API([
  108. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gcc-plugin.h>
  109. #include <tree.h>
  110. #include <gimple.h>
  111. #if defined __INTEL_COMPILER || defined __ICC
  112. Beware, this compiler is a fake. Don't use it.
  113. #endif
  114. tree fndecl; gimple call;]],
  115. [[/* Clang 3.1 doesn't support nested functions, so try to
  116. discriminate it this way. */
  117. tree foo (void)
  118. {
  119. return lookup_name (get_identifier ("puts"));
  120. }
  121. fndecl = foo ();
  122. call = gimple_build_call (fndecl, 0);]])],
  123. [ac_cv_have_gcc_plugins="yes"],
  124. [ac_cv_have_gcc_plugins="no"])
  125. ])
  126. else
  127. ac_cv_have_gcc_plugins="no"
  128. fi
  129. ])
  130. if test "x$ac_cv_have_gcc_plugins" = "xyes"; then
  131. dnl Check for specific features.
  132. dnl
  133. dnl Reason:
  134. dnl build_call_expr_loc_array -- not in GCC 4.5.x; appears in 4.6
  135. dnl build_call_expr_loc_vec -- likewise
  136. dnl build_array_ref -- present but undeclared in 4.6.1
  137. dnl build_zero_cst -- not in GCC 4.5.x; appears in 4.6
  138. dnl builtin_decl_explicit -- new in 4.7, replaces `built_in_decls'
  139. dnl ptr_derefs_may_alias_p -- new in 4.6, nothing equivalent in 4.5
  140. dnl .affects_type_identity -- new field in 4.7
  141. _STARPU_WITH_GCC_PLUGIN_API([
  142. AC_CHECK_DECLS([build_call_expr_loc_array, build_call_expr_loc_vec,
  143. build_array_ref, build_zero_cst,
  144. builtin_decl_explicit,
  145. ptr_derefs_may_alias_p],
  146. [], [], [#include <gcc-plugin.h>
  147. #include <tree.h>
  148. #include <tree-ssa-alias.h>])
  149. dnl Work around header naming issues introduced upstream and in Debian
  150. dnl (see <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=631082>).
  151. AC_CHECK_HEADERS([c-common.h c-pragma.h c-family/c-common.h c-family/c-pragma.h],
  152. [], [], [#include <gcc-plugin.h>
  153. #include <tree.h>])
  154. AC_CHECK_MEMBER([struct attribute_spec.affects_type_identity],
  155. [AC_DEFINE([HAVE_ATTRIBUTE_SPEC_AFFECTS_TYPE_IDENTITY], [1],
  156. [Define to 1 when `struct attribute_spec' has the `affects_type_identity' field.])],
  157. [],
  158. [#include <gcc-plugin.h>
  159. #include <tree.h>])
  160. ])
  161. AC_DEFINE_UNQUOTED([STARPU_INCLUDE_DIR],
  162. ["`test "x$prefix" = xNONE && prefix=$ac_default_prefix ; eval "echo $includedir"`/starpu/$STARPU_EFFECTIVE_VERSION"],
  163. [Define to the directory where StarPU's headers are installed.])
  164. dnl Now, `gcc' or `g++'?
  165. _STARPU_GCC_PLUGIN_LANGUAGE([GCC_FOR_PLUGIN])
  166. AC_SUBST([GCC_FOR_PLUGIN])
  167. dnl Determine the corresponding Libtool tag.
  168. if test "$GCC_FOR_PLUGIN" = "$CXX"; then
  169. GCC_FOR_PLUGIN_LIBTOOL_TAG="CXX"
  170. # Require C++11, for lambdas and `auto'.
  171. GCC_FOR_PLUGIN="$GCC_FOR_PLUGIN -std=c++11"
  172. else
  173. GCC_FOR_PLUGIN_LIBTOOL_TAG="CC"
  174. fi
  175. AC_SUBST([GCC_FOR_PLUGIN_LIBTOOL_TAG])
  176. fi
  177. AC_SUBST([GCC_PLUGIN_INCLUDE_DIR])
  178. ])
  179. dnl Substitute `STARPU_GCC_VERSION_MAJOR' and `STARPU_GCC_VERSION_MINOR'.
  180. AC_DEFUN([STARPU_GCC_VERSION], [
  181. AC_COMPUTE_INT([STARPU_GCC_VERSION_MAJOR], [__GNUC__])
  182. AC_COMPUTE_INT([STARPU_GCC_VERSION_MINOR], [__GNUC_MINOR__])
  183. AC_SUBST([STARPU_GCC_VERSION_MAJOR])
  184. AC_SUBST([STARPU_GCC_VERSION_MINOR])
  185. ])