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