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
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)
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.
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
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.
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
35 dnl Check if the flag is supported by compiler
36 dnl CC_CHECK_CFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
38 AC_DEFUN([CC_CHECK_CFLAGS_SILENT], [
39 AC_CACHE_VAL(AS_TR_SH([cc_cv_cflags_$1]),
40 [ac_save_CFLAGS="$CFLAGS"
42 AC_COMPILE_IFELSE([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"
48 AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
52 dnl Check if the flag is supported by compiler (cacheable)
53 dnl CC_CHECK_CFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
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!
61 AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
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!
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])
77 dnl CC_CHECK_CFLAGS_APPEND([FLAG1 FLAG2], [action-if-found], [action-if-not])
78 AC_DEFUN([CC_CHECK_CFLAGS_APPEND], [
80 CC_CHECK_CFLAG_APPEND($flag, [$2], [$3])
84 dnl Check if the flag is supported by linker (cacheable)
85 dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
87 AC_DEFUN([CC_CHECK_LDFLAGS], [
88 AC_CACHE_CHECK([if $CC supports $1 flag],
89 AS_TR_SH([cc_cv_ldflags_$1]),
90 [ac_save_LDFLAGS="$LDFLAGS"
92 AC_LINK_IFELSE([int main() { return 1; }],
93 [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
94 [eval "AS_TR_SH([cc_cv_ldflags_$1])="])
95 LDFLAGS="$ac_save_LDFLAGS"
98 AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
102 dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for
103 dnl the current linker to avoid undefined references in a shared object.
104 AC_DEFUN([CC_NOUNDEFINED], [
105 dnl We check $host for which systems to enable this for.
106 AC_REQUIRE([AC_CANONICAL_HOST])
109 dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads
110 dnl are requested, as different implementations are present; to avoid problems
111 dnl use -Wl,-z,defs only for those platform not behaving this way.
112 *-freebsd* | *-openbsd*) ;;
114 dnl First of all check for the --no-undefined variant of GNU ld. This allows
115 dnl for a much more readable commandline, so that people can understand what
116 dnl it does without going to look for what the heck -z defs does.
117 for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do
118 CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"])
124 AC_SUBST([LDFLAGS_NOUNDEFINED])
127 dnl Check for a -Werror flag or equivalent. -Werror is the GCC
128 dnl and ICC flag that tells the compiler to treat all the warnings
129 dnl as fatal. We usually need this option to make sure that some
130 dnl constructs (like attributes) are not simply ignored.
132 dnl Other compilers don't support -Werror per se, but they support
133 dnl an equivalent flag:
134 dnl - Sun Studio compiler supports -errwarn=%all
135 AC_DEFUN([CC_CHECK_WERROR], [
137 [for $CC way to treat warnings as errors],
139 [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror],
140 [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])])
144 AC_DEFUN([CC_CHECK_ATTRIBUTE], [
145 AC_REQUIRE([CC_CHECK_WERROR])
146 AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))],
147 AS_TR_SH([cc_cv_attribute_$1]),
148 [ac_save_CFLAGS="$CFLAGS"
149 CFLAGS="$CFLAGS $cc_cv_werror"
150 AC_COMPILE_IFELSE([$3],
151 [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"],
152 [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"])
153 CFLAGS="$ac_save_CFLAGS"
156 AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes],
158 AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1,
159 [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))]
165 AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
168 [void __attribute__((constructor)) ctor() { int a; }],
172 AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
174 [format], [format(printf, n, n)],
175 [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }],
179 AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [
181 [format_arg], [format_arg(printf)],
182 [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }],
186 AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
188 [visibility_$1], [visibility("$1")],
189 [void __attribute__((visibility("$1"))) $1_function() { }],
193 AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
195 [nonnull], [nonnull()],
196 [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }],
200 AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
203 [void some_function(void *foo, __attribute__((unused)) void *bar);],
207 AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [
210 [void some_function(void *foo, ...) __attribute__((sentinel));],
214 AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [
217 [void some_function(void *foo, ...) __attribute__((deprecated));],
221 AC_DEFUN([CC_ATTRIBUTE_ALIAS], [
223 [alias], [weak, alias],
224 [void other_function(void *foo) { }
225 void some_function(void *foo) __attribute__((weak, alias("other_function")));],
229 AC_DEFUN([CC_ATTRIBUTE_MALLOC], [
232 [void * __attribute__((malloc)) my_alloc(int n);],
236 AC_DEFUN([CC_ATTRIBUTE_PACKED], [
239 [struct astructure { char a; int b; long c; void *d; } __attribute__((packed));],
243 AC_DEFUN([CC_ATTRIBUTE_CONST], [
246 [int __attribute__((const)) twopow(int n) { return 1 << n; } ],
250 AC_DEFUN([CC_FLAG_VISIBILITY], [
251 AC_REQUIRE([CC_CHECK_WERROR])
252 AC_CACHE_CHECK([if $CC supports -fvisibility=hidden],
253 [cc_cv_flag_visibility],
254 [cc_flag_visibility_save_CFLAGS="$CFLAGS"
255 CFLAGS="$CFLAGS $cc_cv_werror"
256 CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden],
257 cc_cv_flag_visibility='yes',
258 cc_cv_flag_visibility='no')
259 CFLAGS="$cc_flag_visibility_save_CFLAGS"])
261 AS_IF([test "x$cc_cv_flag_visibility" = "xyes"],
262 [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1,
263 [Define this if the compiler supports the -fvisibility flag])
268 AC_DEFUN([CC_FUNC_EXPECT], [
269 AC_REQUIRE([CC_CHECK_WERROR])
270 AC_CACHE_CHECK([if compiler has __builtin_expect function],
272 [ac_save_CFLAGS="$CFLAGS"
273 CFLAGS="$CFLAGS $cc_cv_werror"
275 [int some_function() {
277 return (int)__builtin_expect(a, 3);
279 [cc_cv_func_expect=yes],
280 [cc_cv_func_expect=no])
281 CFLAGS="$ac_save_CFLAGS"
284 AS_IF([test "x$cc_cv_func_expect" = "xyes"],
285 [AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1,
286 [Define this if the compiler supports __builtin_expect() function])
291 AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
292 AC_REQUIRE([CC_CHECK_WERROR])
293 AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported],
294 [cc_cv_attribute_aligned],
295 [ac_save_CFLAGS="$CFLAGS"
296 CFLAGS="$CFLAGS $cc_cv_werror"
297 for cc_attribute_align_try in 64 32 16 8 4 2; do
300 static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0;
302 }], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
304 CFLAGS="$ac_save_CFLAGS"
307 if test "x$cc_cv_attribute_aligned" != "x"; then
308 AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned],
309 [Define the highest alignment supported])