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