Merge branch 'emacs-25' of git.sv.gnu.org:/srv/git/emacs into emacs-25
[emacs.git] / m4 / ax_gcc_var_attribute.m4
blobd12fce8934eb9f44dc42c96ec6751d262b949367
1 # ===========================================================================
2 #   http://www.gnu.org/software/autoconf-archive/ax_gcc_var_attribute.html
3 # ===========================================================================
5 # SYNOPSIS
7 #   AX_GCC_VAR_ATTRIBUTE(ATTRIBUTE)
9 # DESCRIPTION
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.
17 #   The ATTRIBUTE parameter holds the name of the attribute to be checked.
19 #   If ATTRIBUTE is supported define HAVE_VAR_ATTRIBUTE_<ATTRIBUTE>.
21 #   The macro caches its result in the ax_cv_have_var_attribute_<attribute>
22 #   variable.
24 #   The macro currently supports the following variable attributes:
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
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.
46 # LICENSE
48 #   Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
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.
55 #serial 3
57 AC_DEFUN([AX_GCC_VAR_ATTRIBUTE], [
58     AS_VAR_PUSHDEF([ac_var], [ax_cv_have_var_attribute_$1])
60     AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
61         AC_LINK_IFELSE([AC_LANG_PROGRAM([
62             m4_case([$1],
63                 [aligned], [
64                     int foo __attribute__(($1(32)));
65                 ],
66                 [cleanup], [
67                     int bar(int *t) { return *t; };
68                 ],
69                 [common], [
70                     int foo __attribute__(($1));
71                 ],
72                 [nocommon], [
73                     int foo __attribute__(($1));
74                 ],
75                 [deprecated], [
76                     int foo __attribute__(($1)) = 0;
77                 ],
78                 [mode], [
79                     long foo __attribute__(($1(word)));
80                 ],
81                 [packed], [
82                     struct bar {
83                         int baz __attribute__(($1));
84                     };
85                 ],
86                 [tls_model], [
87                     __thread int bar1 __attribute__(($1("global-dynamic")));
88                     __thread int bar2 __attribute__(($1("local-dynamic")));
89                     __thread int bar3 __attribute__(($1("initial-exec")));
90                     __thread int bar4 __attribute__(($1("local-exec")));
91                 ],
92                 [unused], [
93                     int foo __attribute__(($1));
94                 ],
95                 [used], [
96                     int foo __attribute__(($1));
97                 ],
98                 [vector_size], [
99                     int foo __attribute__(($1(16)));
100                 ],
101                 [weak], [
102                     int foo __attribute__(($1));
103                 ],
104                 [dllimport], [
105                     int foo __attribute__(($1));
106                 ],
107                 [dllexport], [
108                     int foo __attribute__(($1));
109                 ],
110                 [init_priority], [
111                     struct bar { bar() {} ~bar() {} };
112                     bar b __attribute__(($1(65535/2)));
113                 ],
114                 [
115                  m4_warn([syntax], [Unsupported attribute $1, the test may fail])
116                  int foo __attribute__(($1));
117                 ]
118             )], [
119             m4_case([$1],
120                 [cleanup], [
121                     int foo __attribute__(($1(bar))) = 0;
122                     foo = foo + 1;
123                 ],
124                 []
125             )])
126             ],
127             dnl GCC doesn't exit with an error if an unknown attribute is
128             dnl provided but only outputs a warning, so accept the attribute
129             dnl only if no warning were issued.
130             [AS_IF([test -s conftest.err],
131                 [AS_VAR_SET([ac_var], [no])],
132                 [AS_VAR_SET([ac_var], [yes])])],
133             [AS_VAR_SET([ac_var], [no])])
134     ])
136     AS_IF([test yes = AS_VAR_GET([ac_var])],
137         [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_VAR_ATTRIBUTE_$1), 1,
138             [Define to 1 if the system has the `$1' variable attribute])], [])
140     AS_VAR_POPDEF([ac_var])