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