gcc.m4 7.4 KB

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