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