]> git.ipfire.org Git - thirdparty/systemd.git/blame - m4/attributes.m4
remove gudev and gtk-doc
[thirdparty/systemd.git] / m4 / attributes.m4
CommitLineData
47be870b
LP
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
eb2e280f 4dnl Copyright (c) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com>
47be870b
LP
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
eb2e280f 36dnl Check if FLAG in ENV-VAR is supported by compiler and append it
43bbf1ac
DH
37dnl to WHERE-TO-APPEND variable. Note that we invert -Wno-* checks to
38dnl -W* as gcc cannot test for negated warnings.
eb2e280f 39dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG])
47be870b 40
eb2e280f
LDM
41AC_DEFUN([CC_CHECK_FLAG_APPEND], [
42 AC_CACHE_CHECK([if $CC supports flag $3 in envvar $2],
43 AS_TR_SH([cc_cv_$2_$3]),
e9c1ea9d 44 [eval "AS_TR_SH([cc_save_$2])='${$2}'"
43bbf1ac 45 eval "AS_TR_SH([$2])='-Werror `echo "$3" | sed 's/^-Wno-/-W/'`'"
0943f4b7 46 AC_LINK_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; } ])],
d8c8508b
DH
47 [eval "AS_TR_SH([cc_cv_$2_$3])='yes'"],
48 [eval "AS_TR_SH([cc_cv_$2_$3])='no'"])
e9c1ea9d 49 eval "AS_TR_SH([$2])='$cc_save_$2'"])
47be870b 50
eb2e280f
LDM
51 AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes],
52 [eval "$1='${$1} $3'"])
47be870b
LP
53])
54
eb2e280f
LDM
55dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2])
56AC_DEFUN([CC_CHECK_FLAGS_APPEND], [
57 for flag in $3; do
58 CC_CHECK_FLAG_APPEND($1, $2, $flag)
47be870b
LP
59 done
60])
61
62dnl Check if the flag is supported by linker (cacheable)
63dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
64
65AC_DEFUN([CC_CHECK_LDFLAGS], [
66 AC_CACHE_CHECK([if $CC supports $1 flag],
67 AS_TR_SH([cc_cv_ldflags_$1]),
68 [ac_save_LDFLAGS="$LDFLAGS"
69 LDFLAGS="$LDFLAGS $1"
70 AC_LINK_IFELSE([int main() { return 1; }],
71 [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
72 [eval "AS_TR_SH([cc_cv_ldflags_$1])="])
73 LDFLAGS="$ac_save_LDFLAGS"
74 ])
75
76 AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
77 [$2], [$3])
78])
79
80dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for
81dnl the current linker to avoid undefined references in a shared object.
82AC_DEFUN([CC_NOUNDEFINED], [
83 dnl We check $host for which systems to enable this for.
84 AC_REQUIRE([AC_CANONICAL_HOST])
85
86 case $host in
87 dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads
88 dnl are requested, as different implementations are present; to avoid problems
89 dnl use -Wl,-z,defs only for those platform not behaving this way.
90 *-freebsd* | *-openbsd*) ;;
91 *)
92 dnl First of all check for the --no-undefined variant of GNU ld. This allows
3f85ef0f 93 dnl for a much more readable command line, so that people can understand what
47be870b
LP
94 dnl it does without going to look for what the heck -z defs does.
95 for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do
e9c1ea9d
JSJ
96 CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"])
97 break
47be870b 98 done
e9c1ea9d 99 ;;
47be870b
LP
100 esac
101
102 AC_SUBST([LDFLAGS_NOUNDEFINED])
103])
104
105dnl Check for a -Werror flag or equivalent. -Werror is the GCC
106dnl and ICC flag that tells the compiler to treat all the warnings
107dnl as fatal. We usually need this option to make sure that some
108dnl constructs (like attributes) are not simply ignored.
109dnl
110dnl Other compilers don't support -Werror per se, but they support
111dnl an equivalent flag:
112dnl - Sun Studio compiler supports -errwarn=%all
113AC_DEFUN([CC_CHECK_WERROR], [
114 AC_CACHE_CHECK(
115 [for $CC way to treat warnings as errors],
116 [cc_cv_werror],
117 [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror],
118 [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])])
119 ])
120])
121
122AC_DEFUN([CC_CHECK_ATTRIBUTE], [
123 AC_REQUIRE([CC_CHECK_WERROR])
124 AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))],
125 AS_TR_SH([cc_cv_attribute_$1]),
126 [ac_save_CFLAGS="$CFLAGS"
127 CFLAGS="$CFLAGS $cc_cv_werror"
c1851444 128 AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])],
47be870b
LP
129 [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"],
130 [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"])
131 CFLAGS="$ac_save_CFLAGS"
132 ])
133
134 AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes],
135 [AC_DEFINE(
136 AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1,
137 [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))]
138 )
139 $4],
140 [$5])
141])
142
143AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
144 CC_CHECK_ATTRIBUTE(
145 [constructor],,
146 [void __attribute__((constructor)) ctor() { int a; }],
147 [$1], [$2])
148])
149
150AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
151 CC_CHECK_ATTRIBUTE(
152 [format], [format(printf, n, n)],
153 [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }],
154 [$1], [$2])
155])
156
157AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [
158 CC_CHECK_ATTRIBUTE(
159 [format_arg], [format_arg(printf)],
160 [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }],
161 [$1], [$2])
162])
163
164AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
165 CC_CHECK_ATTRIBUTE(
166 [visibility_$1], [visibility("$1")],
167 [void __attribute__((visibility("$1"))) $1_function() { }],
168 [$2], [$3])
169])
170
171AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
172 CC_CHECK_ATTRIBUTE(
173 [nonnull], [nonnull()],
174 [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }],
175 [$1], [$2])
176])
177
178AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
179 CC_CHECK_ATTRIBUTE(
180 [unused], ,
181 [void some_function(void *foo, __attribute__((unused)) void *bar);],
182 [$1], [$2])
183])
184
185AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [
186 CC_CHECK_ATTRIBUTE(
187 [sentinel], ,
188 [void some_function(void *foo, ...) __attribute__((sentinel));],
189 [$1], [$2])
190])
191
192AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [
193 CC_CHECK_ATTRIBUTE(
194 [deprecated], ,
195 [void some_function(void *foo, ...) __attribute__((deprecated));],
196 [$1], [$2])
197])
198
199AC_DEFUN([CC_ATTRIBUTE_ALIAS], [
200 CC_CHECK_ATTRIBUTE(
201 [alias], [weak, alias],
202 [void other_function(void *foo) { }
203 void some_function(void *foo) __attribute__((weak, alias("other_function")));],
204 [$1], [$2])
205])
206
207AC_DEFUN([CC_ATTRIBUTE_MALLOC], [
208 CC_CHECK_ATTRIBUTE(
209 [malloc], ,
210 [void * __attribute__((malloc)) my_alloc(int n);],
211 [$1], [$2])
212])
213
214AC_DEFUN([CC_ATTRIBUTE_PACKED], [
215 CC_CHECK_ATTRIBUTE(
216 [packed], ,
217 [struct astructure { char a; int b; long c; void *d; } __attribute__((packed));],
218 [$1], [$2])
219])
220
221AC_DEFUN([CC_ATTRIBUTE_CONST], [
222 CC_CHECK_ATTRIBUTE(
223 [const], ,
224 [int __attribute__((const)) twopow(int n) { return 1 << n; } ],
225 [$1], [$2])
226])
227
228AC_DEFUN([CC_FLAG_VISIBILITY], [
229 AC_REQUIRE([CC_CHECK_WERROR])
230 AC_CACHE_CHECK([if $CC supports -fvisibility=hidden],
231 [cc_cv_flag_visibility],
232 [cc_flag_visibility_save_CFLAGS="$CFLAGS"
233 CFLAGS="$CFLAGS $cc_cv_werror"
234 CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden],
e9c1ea9d
JSJ
235 cc_cv_flag_visibility='yes',
236 cc_cv_flag_visibility='no')
47be870b
LP
237 CFLAGS="$cc_flag_visibility_save_CFLAGS"])
238
239 AS_IF([test "x$cc_cv_flag_visibility" = "xyes"],
240 [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1,
241 [Define this if the compiler supports the -fvisibility flag])
242 $1],
243 [$2])
244])
245
246AC_DEFUN([CC_FUNC_EXPECT], [
247 AC_REQUIRE([CC_CHECK_WERROR])
248 AC_CACHE_CHECK([if compiler has __builtin_expect function],
249 [cc_cv_func_expect],
250 [ac_save_CFLAGS="$CFLAGS"
251 CFLAGS="$CFLAGS $cc_cv_werror"
c1851444 252 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
47be870b
LP
253 [int some_function() {
254 int a = 3;
255 return (int)__builtin_expect(a, 3);
e9c1ea9d 256 }])],
47be870b
LP
257 [cc_cv_func_expect=yes],
258 [cc_cv_func_expect=no])
259 CFLAGS="$ac_save_CFLAGS"
260 ])
261
262 AS_IF([test "x$cc_cv_func_expect" = "xyes"],
263 [AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1,
264 [Define this if the compiler supports __builtin_expect() function])
265 $1],
266 [$2])
267])
268
269AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
270 AC_REQUIRE([CC_CHECK_WERROR])
271 AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported],
272 [cc_cv_attribute_aligned],
273 [ac_save_CFLAGS="$CFLAGS"
274 CFLAGS="$CFLAGS $cc_cv_werror"
275 for cc_attribute_align_try in 64 32 16 8 4 2; do
c1851444 276 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
47be870b
LP
277 int main() {
278 static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0;
279 return c;
c1851444 280 }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
47be870b
LP
281 done
282 CFLAGS="$ac_save_CFLAGS"
283 ])
284
285 if test "x$cc_cv_attribute_aligned" != "x"; then
286 AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned],
287 [Define the highest alignment supported])
288 fi
289])