Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.7KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_gcc_var_attribute.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_GCC_VAR_ATTRIBUTE(ATTRIBUTE)
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro checks if the compiler supports one of GCC's variable
  12. # attributes; many other compilers also provide variable attributes with
  13. # the same syntax. Compiler warnings are used to detect supported
  14. # attributes as unsupported ones are ignored by default so quieting
  15. # warnings when using this macro will yield false positives.
  16. #
  17. # The ATTRIBUTE parameter holds the name of the attribute to be checked.
  18. #
  19. # If ATTRIBUTE is supported define HAVE_VAR_ATTRIBUTE_<ATTRIBUTE>.
  20. #
  21. # The macro caches its result in the ax_cv_have_var_attribute_<attribute>
  22. # variable.
  23. #
  24. # The macro currently supports the following variable attributes:
  25. #
  26. # aligned
  27. # cleanup
  28. # common
  29. # nocommon
  30. # deprecated
  31. # mode
  32. # packed
  33. # tls_model
  34. # unused
  35. # used
  36. # vector_size
  37. # weak
  38. # dllimport
  39. # dllexport
  40. # init_priority
  41. #
  42. # Unsupported variable attributes will be tested against a global integer
  43. # variable and without any arguments given to the attribute itself; the
  44. # result of this check might be wrong or meaningless so use with care.
  45. #
  46. # LICENSE
  47. #
  48. # Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
  49. #
  50. # Copying and distribution of this file, with or without modification, are
  51. # permitted in any medium without royalty provided the copyright notice
  52. # and this notice are preserved. This file is offered as-is, without any
  53. # warranty.
  54. #serial 5
  55. AC_DEFUN([AX_GCC_VAR_ATTRIBUTE], [
  56. AS_VAR_PUSHDEF([ac_var], [ax_cv_have_var_attribute_$1])
  57. AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
  58. AC_LINK_IFELSE([AC_LANG_PROGRAM([
  59. m4_case([$1],
  60. [aligned], [
  61. int foo __attribute__(($1(32)));
  62. ],
  63. [cleanup], [
  64. int bar(int *t) { return *t; };
  65. ],
  66. [common], [
  67. int foo __attribute__(($1));
  68. ],
  69. [nocommon], [
  70. int foo __attribute__(($1));
  71. ],
  72. [deprecated], [
  73. int foo __attribute__(($1)) = 0;
  74. ],
  75. [mode], [
  76. long foo __attribute__(($1(word)));
  77. ],
  78. [packed], [
  79. struct bar {
  80. int baz __attribute__(($1));
  81. };
  82. ],
  83. [tls_model], [
  84. __thread int bar1 __attribute__(($1("global-dynamic")));
  85. __thread int bar2 __attribute__(($1("local-dynamic")));
  86. __thread int bar3 __attribute__(($1("initial-exec")));
  87. __thread int bar4 __attribute__(($1("local-exec")));
  88. ],
  89. [unused], [
  90. int foo __attribute__(($1));
  91. ],
  92. [used], [
  93. int foo __attribute__(($1));
  94. ],
  95. [vector_size], [
  96. int foo __attribute__(($1(16)));
  97. ],
  98. [weak], [
  99. int foo __attribute__(($1));
  100. ],
  101. [dllimport], [
  102. int foo __attribute__(($1));
  103. ],
  104. [dllexport], [
  105. int foo __attribute__(($1));
  106. ],
  107. [init_priority], [
  108. struct bar { bar() {} ~bar() {} };
  109. bar b __attribute__(($1(65535/2)));
  110. ],
  111. [
  112. m4_warn([syntax], [Unsupported attribute $1, the test may fail])
  113. int foo __attribute__(($1));
  114. ]
  115. )], [
  116. m4_case([$1],
  117. [cleanup], [
  118. int foo __attribute__(($1(bar))) = 0;
  119. foo = foo + 1;
  120. ],
  121. []
  122. )])
  123. ],
  124. dnl GCC doesn't exit with an error if an unknown attribute is
  125. dnl provided but only outputs a warning, so accept the attribute
  126. dnl only if no warning were issued.
  127. [AS_IF([test -s conftest.err],
  128. [AS_VAR_SET([ac_var], [no])],
  129. [AS_VAR_SET([ac_var], [yes])])],
  130. [AS_VAR_SET([ac_var], [no])])
  131. ])
  132. AS_IF([test yes = AS_VAR_GET([ac_var])],
  133. [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_VAR_ATTRIBUTE_$1), 1,
  134. [Define to 1 if the system has the `$1' variable attribute])], [])
  135. AS_VAR_POPDEF([ac_var])
  136. ])