]> git.ipfire.org Git - thirdparty/kmod.git/blame - m4/attributes.m4
testsuite: port detect-loop test to module-playground
[thirdparty/kmod.git] / m4 / attributes.m4
CommitLineData
822ce234
GSB
1dnl Macros to check the presence of generic (non-typed) symbols.
2dnl Copyright (c) 2006-2008 Diego Pettenò <flameeyes@gmail.com>
3dnl Copyright (c) 2006-2008 xine project
e48f3765 4dnl Copyright (c) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com>
822ce234
GSB
5dnl
6dnl This program is free software; you can redistribute it and/or modify
7dnl it under the terms of the GNU General Public License as published by
8dnl the Free Software Foundation; either version 2, or (at your option)
9dnl any later version.
10dnl
11dnl This program is distributed in the hope that it will be useful,
12dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14dnl GNU General Public License for more details.
15dnl
16dnl You should have received a copy of the GNU General Public License
17dnl along with this program; if not, write to the Free Software
18dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19dnl 02110-1301, USA.
20dnl
21dnl As a special exception, the copyright owners of the
22dnl macro gives unlimited permission to copy, distribute and modify the
23dnl configure scripts that are the output of Autoconf when processing the
24dnl Macro. You need not follow the terms of the GNU General Public
25dnl License when using or distributing such scripts, even though portions
26dnl of the text of the Macro appear in them. The GNU General Public
27dnl License (GPL) does govern all other use of the material that
28dnl constitutes the Autoconf Macro.
29dnl
30dnl This special exception to the GPL applies to versions of the
31dnl Autoconf Macro released by this project. When you make and
32dnl distribute a modified version of the Autoconf Macro, you may extend
33dnl this special exception to the GPL to apply to your modified version as
34dnl well.
35
e48f3765
LDM
36dnl Check if flag in a envvar is supported by compiler and append
37dnl "backup" variable
38dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG])
39AC_DEFUN([CC_CHECK_FLAG_APPEND], [
40 AC_CACHE_CHECK([if $CC supports flag $3 in envvar $2],
41 AS_TR_SH([cc_cv_$2_$3]),
42 [eval "AS_TR_SH([cc_save_$2])='${$2}'"
7812d88c 43 eval "AS_TR_SH([$2])='-Werror $3'"
e48f3765
LDM
44 AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a = 0; int main(void) { return a; } ])],
45 [eval "AS_TR_SH([cc_cv_$2_$3])='yes'"],
46 [eval "AS_TR_SH([cc_cv_$2_$3])='no'"])
47 eval "AS_TR_SH([$2])='$cc_save_$2'"])
48
49 AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes],
50 [eval "$1='${$1} $3'"])
822ce234
GSB
51])
52
e48f3765
LDM
53dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2])
54AC_DEFUN([CC_CHECK_FLAGS_APPEND], [
55 for flag in $3; do
56 CC_CHECK_FLAG_APPEND($1, $2, $flag)
57 done
822ce234
GSB
58])
59
822ce234 60
822ce234 61
00ff5766
RW
62dnl Check if the flag is supported by linker
63dnl CC_CHECK_LDFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
00ff5766
RW
64AC_DEFUN([CC_CHECK_LDFLAGS_SILENT], [
65 AC_CACHE_VAL(AS_TR_SH([cc_cv_ldflags_$1]),
822ce234
GSB
66 [ac_save_LDFLAGS="$LDFLAGS"
67 LDFLAGS="$LDFLAGS $1"
00ff5766 68 AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])],
822ce234
GSB
69 [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
70 [eval "AS_TR_SH([cc_cv_ldflags_$1])="])
71 LDFLAGS="$ac_save_LDFLAGS"
72 ])
73
74 AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
75 [$2], [$3])
76])
77
00ff5766
RW
78dnl Check if the flag is supported by linker (cacheable)
79dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
80
81AC_DEFUN([CC_CHECK_LDFLAGS], [
82 AC_CACHE_CHECK([if $CC supports $1 flag],
83 AS_TR_SH([cc_cv_ldflags_$1]),
84 CC_CHECK_LDFLAGS_SILENT([$1]) dnl Don't execute actions here!
85 )
86
87 AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
88 [$2], [$3])
89])
90
822ce234
GSB
91dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for
92dnl the current linker to avoid undefined references in a shared object.
93AC_DEFUN([CC_NOUNDEFINED], [
94 dnl We check $host for which systems to enable this for.
95 AC_REQUIRE([AC_CANONICAL_HOST])
96
97 case $host in
98 dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads
99 dnl are requested, as different implementations are present; to avoid problems
100 dnl use -Wl,-z,defs only for those platform not behaving this way.
101 *-freebsd* | *-openbsd*) ;;
102 *)
103 dnl First of all check for the --no-undefined variant of GNU ld. This allows
104 dnl for a much more readable commandline, so that people can understand what
105 dnl it does without going to look for what the heck -z defs does.
106 for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do
107 CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"])
108 break
109 done
110 ;;
111 esac
112
113 AC_SUBST([LDFLAGS_NOUNDEFINED])
114])
115
116dnl Check for a -Werror flag or equivalent. -Werror is the GCC
117dnl and ICC flag that tells the compiler to treat all the warnings
118dnl as fatal. We usually need this option to make sure that some
119dnl constructs (like attributes) are not simply ignored.
120dnl
121dnl Other compilers don't support -Werror per se, but they support
122dnl an equivalent flag:
123dnl - Sun Studio compiler supports -errwarn=%all
124AC_DEFUN([CC_CHECK_WERROR], [
125 AC_CACHE_CHECK(
126 [for $CC way to treat warnings as errors],
127 [cc_cv_werror],
128 [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror],
129 [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])])
130 ])
131])
132
133AC_DEFUN([CC_CHECK_ATTRIBUTE], [
134 AC_REQUIRE([CC_CHECK_WERROR])
135 AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))],
136 AS_TR_SH([cc_cv_attribute_$1]),
137 [ac_save_CFLAGS="$CFLAGS"
138 CFLAGS="$CFLAGS $cc_cv_werror"
139 AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])],
140 [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"],
141 [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"])
142 CFLAGS="$ac_save_CFLAGS"
143 ])
144
145 AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes],
146 [AC_DEFINE(
147 AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1,
148 [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))]
149 )
150 $4],
151 [$5])
152])
153
154AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
155 CC_CHECK_ATTRIBUTE(
156 [constructor],,
157 [void __attribute__((constructor)) ctor() { int a; }],
158 [$1], [$2])
159])
160
161AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
162 CC_CHECK_ATTRIBUTE(
163 [format], [format(printf, n, n)],
164 [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }],
165 [$1], [$2])
166])
167
168AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [
169 CC_CHECK_ATTRIBUTE(
170 [format_arg], [format_arg(printf)],
171 [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }],
172 [$1], [$2])
173])
174
175AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
176 CC_CHECK_ATTRIBUTE(
177 [visibility_$1], [visibility("$1")],
178 [void __attribute__((visibility("$1"))) $1_function() { }],
179 [$2], [$3])
180])
181
182AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
183 CC_CHECK_ATTRIBUTE(
184 [nonnull], [nonnull()],
185 [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }],
186 [$1], [$2])
187])
188
189AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
190 CC_CHECK_ATTRIBUTE(
191 [unused], ,
192 [void some_function(void *foo, __attribute__((unused)) void *bar);],
193 [$1], [$2])
194])
195
196AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [
197 CC_CHECK_ATTRIBUTE(
198 [sentinel], ,
199 [void some_function(void *foo, ...) __attribute__((sentinel));],
200 [$1], [$2])
201])
202
203AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [
204 CC_CHECK_ATTRIBUTE(
205 [deprecated], ,
206 [void some_function(void *foo, ...) __attribute__((deprecated));],
207 [$1], [$2])
208])
209
210AC_DEFUN([CC_ATTRIBUTE_ALIAS], [
211 CC_CHECK_ATTRIBUTE(
212 [alias], [weak, alias],
213 [void other_function(void *foo) { }
214 void some_function(void *foo) __attribute__((weak, alias("other_function")));],
215 [$1], [$2])
216])
217
218AC_DEFUN([CC_ATTRIBUTE_MALLOC], [
219 CC_CHECK_ATTRIBUTE(
220 [malloc], ,
221 [void * __attribute__((malloc)) my_alloc(int n);],
222 [$1], [$2])
223])
224
225AC_DEFUN([CC_ATTRIBUTE_PACKED], [
226 CC_CHECK_ATTRIBUTE(
227 [packed], ,
228 [struct astructure { char a; int b; long c; void *d; } __attribute__((packed));],
229 [$1], [$2])
230])
231
232AC_DEFUN([CC_ATTRIBUTE_CONST], [
233 CC_CHECK_ATTRIBUTE(
234 [const], ,
235 [int __attribute__((const)) twopow(int n) { return 1 << n; } ],
236 [$1], [$2])
237])
238
239AC_DEFUN([CC_FLAG_VISIBILITY], [
240 AC_REQUIRE([CC_CHECK_WERROR])
241 AC_CACHE_CHECK([if $CC supports -fvisibility=hidden],
242 [cc_cv_flag_visibility],
243 [cc_flag_visibility_save_CFLAGS="$CFLAGS"
244 CFLAGS="$CFLAGS $cc_cv_werror"
245 CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden],
246 cc_cv_flag_visibility='yes',
247 cc_cv_flag_visibility='no')
248 CFLAGS="$cc_flag_visibility_save_CFLAGS"])
249
250 AS_IF([test "x$cc_cv_flag_visibility" = "xyes"],
251 [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1,
252 [Define this if the compiler supports the -fvisibility flag])
253 $1],
254 [$2])
255])
256
257AC_DEFUN([CC_FUNC_EXPECT], [
258 AC_REQUIRE([CC_CHECK_WERROR])
259 AC_CACHE_CHECK([if compiler has __builtin_expect function],
260 [cc_cv_func_expect],
261 [ac_save_CFLAGS="$CFLAGS"
262 CFLAGS="$CFLAGS $cc_cv_werror"
263 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
264 [int some_function() {
265 int a = 3;
266 return (int)__builtin_expect(a, 3);
267 }])],
268 [cc_cv_func_expect=yes],
269 [cc_cv_func_expect=no])
270 CFLAGS="$ac_save_CFLAGS"
271 ])
272
273 AS_IF([test "x$cc_cv_func_expect" = "xyes"],
274 [AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1,
275 [Define this if the compiler supports __builtin_expect() function])
276 $1],
277 [$2])
278])
279
280AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
281 AC_REQUIRE([CC_CHECK_WERROR])
282 AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported],
283 [cc_cv_attribute_aligned],
284 [ac_save_CFLAGS="$CFLAGS"
285 CFLAGS="$CFLAGS $cc_cv_werror"
286 for cc_attribute_align_try in 64 32 16 8 4 2; do
287 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
288 int main() {
289 static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0;
290 return c;
291 }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
292 done
293 CFLAGS="$ac_save_CFLAGS"
294 ])
295
296 if test "x$cc_cv_attribute_aligned" != "x"; then
297 AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned],
298 [Define the highest alignment supported])
299 fi
300])