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