attributes.m4 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. dnl Macros to check the presence of generic (non-typed) symbols.
  2. dnl Copyright (c) 2006-2007 Diego Pettenò <flameeyes@gmail.com>
  3. dnl Copyright (c) 2006-2007 xine project
  4. dnl
  5. dnl This program is free software; you can redistribute it and/or modify
  6. dnl it under the terms of the GNU General Public License as published by
  7. dnl the Free Software Foundation; either version 2, or (at your option)
  8. dnl any later version.
  9. dnl
  10. dnl This program is distributed in the hope that it will be useful,
  11. dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. dnl GNU General Public License for more details.
  14. dnl
  15. dnl You should have received a copy of the GNU General Public License
  16. dnl along with this program; if not, write to the Free Software
  17. dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. dnl 02110-1301, USA.
  19. dnl
  20. dnl As a special exception, the copyright owners of the
  21. dnl macro gives unlimited permission to copy, distribute and modify the
  22. dnl configure scripts that are the output of Autoconf when processing the
  23. dnl Macro. You need not follow the terms of the GNU General Public
  24. dnl License when using or distributing such scripts, even though portions
  25. dnl of the text of the Macro appear in them. The GNU General Public
  26. dnl License (GPL) does govern all other use of the material that
  27. dnl constitutes the Autoconf Macro.
  28. dnl
  29. dnl This special exception to the GPL applies to versions of the
  30. dnl Autoconf Macro released by this project. When you make and
  31. dnl distribute a modified version of the Autoconf Macro, you may extend
  32. dnl this special exception to the GPL to apply to your modified version as
  33. dnl well.
  34. AC_DEFUN([CC_CHECK_CFLAGS_SILENT], [
  35. AC_CACHE_VAL(AS_TR_SH([cc_cv_cflags_$1]),
  36. [ac_save_CFLAGS="$CFLAGS"
  37. CFLAGS="$CFLAGS $1"
  38. AC_COMPILE_IFELSE([int a;],
  39. [eval "AS_TR_SH([cc_cv_cflags_$1])='yes'"],
  40. [eval "AS_TR_SH([cc_cv_cflags_$1])='no'"])
  41. CFLAGS="$ac_save_CFLAGS"
  42. ])
  43. AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
  44. [$2], [$3])
  45. ])
  46. AC_DEFUN([CC_CHECK_CFLAGS], [
  47. AC_CACHE_CHECK([if $CC supports $1 flag],
  48. AS_TR_SH([cc_cv_cflags_$1]),
  49. CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here!
  50. )
  51. AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
  52. [$2], [$3])
  53. ])
  54. AC_DEFUN([CC_CHECK_LDFLAGS], [
  55. AC_CACHE_CHECK([if $CC supports $1 flag],
  56. AS_TR_SH([cc_cv_ldflags_$1]),
  57. [ac_save_LDFLAGS="$LDFLAGS"
  58. LDFLAGS="$LDFLAGS $1"
  59. AC_LINK_IFELSE([int main() { return 1; }],
  60. [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
  61. [eval "AS_TR_SH([cc_cv_ldflags_$1])="])
  62. LDFLAGS="$ac_save_LDFLAGS"
  63. ])
  64. AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
  65. [$2], [$3])
  66. ])
  67. dnl Check for a -Werror flag or equivalent. -Werror is the GCC
  68. dnl and ICC flag that tells the compiler to treat all the warnings
  69. dnl as fatal. We usually need this option to make sure that some
  70. dnl constructs (like attributes) are not simply ignored.
  71. dnl
  72. dnl Other compilers don't support -Werror per se, but they support
  73. dnl an equivalent flag:
  74. dnl - Sun Studio compiler supports -errwarn=%all
  75. AC_DEFUN([CC_CHECK_WERROR], [
  76. AC_CACHE_CHECK(
  77. [for $CC way to treat warnings as errors],
  78. [cc_cv_werror],
  79. [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror],
  80. [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])])
  81. ])
  82. ])
  83. AC_DEFUN([CC_CHECK_ATTRIBUTE], [
  84. AC_REQUIRE([CC_CHECK_WERROR])
  85. AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))],
  86. AS_TR_SH([cc_cv_attribute_$1]),
  87. [ac_save_CFLAGS="$CFLAGS"
  88. CFLAGS="$CFLAGS $cc_cv_werror"
  89. AC_COMPILE_IFELSE([$3],
  90. [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"],
  91. [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"])
  92. CFLAGS="$ac_save_CFLAGS"
  93. ])
  94. AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes],
  95. [AC_DEFINE(
  96. AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1,
  97. [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))]
  98. )
  99. $4],
  100. [$5])
  101. ])
  102. AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
  103. CC_CHECK_ATTRIBUTE(
  104. [constructor],,
  105. [void __attribute__((constructor)) ctor() { int a; }],
  106. [$1], [$2])
  107. ])
  108. AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
  109. CC_CHECK_ATTRIBUTE(
  110. [format], [format(printf, n, n)],
  111. [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }],
  112. [$1], [$2])
  113. ])
  114. AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [
  115. CC_CHECK_ATTRIBUTE(
  116. [format_arg], [format_arg(printf)],
  117. [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }],
  118. [$1], [$2])
  119. ])
  120. AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
  121. CC_CHECK_ATTRIBUTE(
  122. [visibility_$1], [visibility("$1")],
  123. [void __attribute__((visibility("$1"))) $1_function() { }],
  124. [$2], [$3])
  125. ])
  126. AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
  127. CC_CHECK_ATTRIBUTE(
  128. [nonnull], [nonnull()],
  129. [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }],
  130. [$1], [$2])
  131. ])
  132. AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
  133. CC_CHECK_ATTRIBUTE(
  134. [unused], ,
  135. [void some_function(void *foo, __attribute__((unused)) void *bar);],
  136. [$1], [$2])
  137. ])
  138. AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [
  139. CC_CHECK_ATTRIBUTE(
  140. [sentinel], ,
  141. [void some_function(void *foo, ...) __attribute__((sentinel));],
  142. [$1], [$2])
  143. ])
  144. AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [
  145. CC_CHECK_ATTRIBUTE(
  146. [deprecated], ,
  147. [void some_function(void *foo, ...) __attribute__((deprecated));],
  148. [$1], [$2])
  149. ])
  150. AC_DEFUN([CC_ATTRIBUTE_ALIAS], [
  151. CC_CHECK_ATTRIBUTE(
  152. [alias], [weak, alias],
  153. [void other_function(void *foo) { }
  154. void some_function(void *foo) __attribute__((weak, alias("other_function")));],
  155. [$1], [$2])
  156. ])
  157. AC_DEFUN([CC_ATTRIBUTE_MALLOC], [
  158. CC_CHECK_ATTRIBUTE(
  159. [malloc], ,
  160. [void * __attribute__((malloc)) my_alloc(int n);],
  161. [$1], [$2])
  162. ])
  163. AC_DEFUN([CC_ATTRIBUTE_PACKED], [
  164. CC_CHECK_ATTRIBUTE(
  165. [packed], ,
  166. [struct astructure { char a; int b; long c; void *d; } __attribute__((packed));],
  167. [$1], [$2])
  168. ])
  169. AC_DEFUN([CC_ATTRIBUTE_CONST], [
  170. CC_CHECK_ATTRIBUTE(
  171. [const], ,
  172. [int __attribute__((const)) twopow(int n) { return 1 << n; } ],
  173. [$1], [$2])
  174. ])
  175. AC_DEFUN([CC_FLAG_VISIBILITY], [
  176. AC_REQUIRE([CC_CHECK_WERROR])
  177. AC_CACHE_CHECK([if $CC supports -fvisibility=hidden],
  178. [cc_cv_flag_visibility],
  179. [cc_flag_visibility_save_CFLAGS="$CFLAGS"
  180. CFLAGS="$CFLAGS $cc_cv_werror"
  181. CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden],
  182. cc_cv_flag_visibility='yes',
  183. cc_cv_flag_visibility='no')
  184. CFLAGS="$cc_flag_visibility_save_CFLAGS"])
  185. AS_IF([test "x$cc_cv_flag_visibility" = "xyes"],
  186. [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1,
  187. [Define this if the compiler supports the -fvisibility flag])
  188. $1],
  189. [$2])
  190. ])
  191. AC_DEFUN([CC_FUNC_EXPECT], [
  192. AC_REQUIRE([CC_CHECK_WERROR])
  193. AC_CACHE_CHECK([if compiler has __builtin_expect function],
  194. [cc_cv_func_expect],
  195. [ac_save_CFLAGS="$CFLAGS"
  196. CFLAGS="$CFLAGS $cc_cv_werror"
  197. AC_COMPILE_IFELSE(
  198. [int some_function() {
  199. int a = 3;
  200. return (int)__builtin_expect(a, 3);
  201. }],
  202. [cc_cv_func_expect=yes],
  203. [cc_cv_func_expect=no])
  204. CFLAGS="$ac_save_CFLAGS"
  205. ])
  206. AS_IF([test "x$cc_cv_func_expect" = "xyes"],
  207. [AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1,
  208. [Define this if the compiler supports __builtin_expect() function])
  209. $1],
  210. [$2])
  211. ])
  212. AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
  213. AC_REQUIRE([CC_CHECK_WERROR])
  214. AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported],
  215. [cc_cv_attribute_aligned],
  216. [ac_save_CFLAGS="$CFLAGS"
  217. CFLAGS="$CFLAGS $cc_cv_werror"
  218. for cc_attribute_align_try in 64 32 16 8 4 2; do
  219. AC_COMPILE_IFELSE([
  220. int main() {
  221. static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0;
  222. return c;
  223. }], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
  224. done
  225. CFLAGS="$ac_save_CFLAGS"
  226. ])
  227. if test "x$cc_cv_attribute_aligned" != "x"; then
  228. AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned],
  229. [Define the highest alignment supported])
  230. fi
  231. ])