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 Copyright (c) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com>
6 dnl This program is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 2, or (at your option)
11 dnl This program is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 dnl GNU General Public License for more details.
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program; if not, write to the Free Software
18 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 dnl As a special exception, the copyright owners of the
22 dnl macro gives unlimited permission to copy, distribute and modify the
23 dnl configure scripts that are the output of Autoconf when processing the
24 dnl Macro. You need not follow the terms of the GNU General Public
25 dnl License when using or distributing such scripts, even though portions
26 dnl of the text of the Macro appear in them. The GNU General Public
27 dnl License (GPL) does govern all other use of the material that
28 dnl constitutes the Autoconf Macro.
30 dnl This special exception to the GPL applies to versions of the
31 dnl Autoconf Macro released by this project. When you make and
32 dnl distribute a modified version of the Autoconf Macro, you may extend
33 dnl this special exception to the GPL to apply to your modified version as
36 dnl Check if flag in a envvar is supported by compiler and append
38 dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG])
39 AC_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}'"
43 eval "AS_TR_SH([$2])='-Werror $3'"
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'"])
49 AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes],
50 [eval "$1='${$1} $3'"])
53 dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2])
54 AC_DEFUN([CC_CHECK_FLAGS_APPEND], [
56 CC_CHECK_FLAG_APPEND($1, $2, $flag)
62 dnl Check if the flag is supported by linker
63 dnl CC_CHECK_LDFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
64 AC_DEFUN([CC_CHECK_LDFLAGS_SILENT], [
65 AC_CACHE_VAL(AS_TR_SH([cc_cv_ldflags_$1]),
66 [ac_save_LDFLAGS="$LDFLAGS"
68 AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])],
69 [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
70 [eval "AS_TR_SH([cc_cv_ldflags_$1])="])
71 LDFLAGS="$ac_save_LDFLAGS"
74 AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
78 dnl Check if the flag is supported by linker (cacheable)
79 dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
81 AC_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!
87 AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
91 dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for
92 dnl the current linker to avoid undefined references in a shared object.
93 AC_DEFUN([CC_NOUNDEFINED], [
94 dnl We check $host for which systems to enable this for.
95 AC_REQUIRE([AC_CANONICAL_HOST])
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*) ;;
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"])
113 AC_SUBST([LDFLAGS_NOUNDEFINED])
116 dnl Check for a -Werror flag or equivalent. -Werror is the GCC
117 dnl and ICC flag that tells the compiler to treat all the warnings
118 dnl as fatal. We usually need this option to make sure that some
119 dnl constructs (like attributes) are not simply ignored.
121 dnl Other compilers don't support -Werror per se, but they support
122 dnl an equivalent flag:
123 dnl - Sun Studio compiler supports -errwarn=%all
124 AC_DEFUN([CC_CHECK_WERROR], [
126 [for $CC way to treat warnings as errors],
128 [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror],
129 [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])])
133 AC_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"
145 AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes],
147 AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1,
148 [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))]
154 AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
157 [void __attribute__((constructor)) ctor() { int a; }],
161 AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
163 [format], [format(printf, n, n)],
164 [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }],
168 AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [
170 [format_arg], [format_arg(printf)],
171 [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }],
175 AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
177 [visibility_$1], [visibility("$1")],
178 [void __attribute__((visibility("$1"))) $1_function() { }],
182 AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
184 [nonnull], [nonnull()],
185 [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }],
189 AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
192 [void some_function(void *foo, __attribute__((unused)) void *bar);],
196 AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [
199 [void some_function(void *foo, ...) __attribute__((sentinel));],
203 AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [
206 [void some_function(void *foo, ...) __attribute__((deprecated));],
210 AC_DEFUN([CC_ATTRIBUTE_ALIAS], [
212 [alias], [weak, alias],
213 [void other_function(void *foo) { }
214 void some_function(void *foo) __attribute__((weak, alias("other_function")));],
218 AC_DEFUN([CC_ATTRIBUTE_MALLOC], [
221 [void * __attribute__((malloc)) my_alloc(int n);],
225 AC_DEFUN([CC_ATTRIBUTE_PACKED], [
228 [struct astructure { char a; int b; long c; void *d; } __attribute__((packed));],
232 AC_DEFUN([CC_ATTRIBUTE_CONST], [
235 [int __attribute__((const)) twopow(int n) { return 1 << n; } ],
239 AC_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"])
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])
257 AC_DEFUN([CC_CHECK_FUNC_BUILTIN], [
258 m4_pushdef([UPNAME], m4_translit([$1], [-a-z], [_A-Z]))
259 AC_CACHE_CHECK([if compiler has $1 function],
261 [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [
263 [__builtin_clz], [$1(0)],
264 [__builtin_types_compatible_p], [$1(int, int)],
265 [__builtin_expect], [$1(0, 0)]
268 [cc_cv_have_$1=no])])
270 AS_IF([test "x$cc_cv_have_$1" = "xyes"],
271 [AC_DEFINE([HAVE_]m4_defn([UPNAME]), 1, [Define this if the compiler supports $1() function])
273 [AS_IF([test "x$3" = "x"], [AC_MSG_ERROR([*** builtin function not found: $1()])], [$3])]
278 AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
279 AC_REQUIRE([CC_CHECK_WERROR])
280 AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported],
281 [cc_cv_attribute_aligned],
282 [ac_save_CFLAGS="$CFLAGS"
283 CFLAGS="$CFLAGS $cc_cv_werror"
284 for cc_attribute_align_try in 64 32 16 8 4 2; do
285 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
287 static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0;
289 }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
291 CFLAGS="$ac_save_CFLAGS"
294 if test "x$cc_cv_attribute_aligned" != "x"; then
295 AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned],
296 [Define the highest alignment supported])