blob: ab4b785a0f3b04939fe41e85b614f47f6d5f70e6 [file] [log] [blame]
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -02001dnl 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
Lucas De Marchie48f3762012-03-17 15:12:44 -03004dnl Copyright (c) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com>
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -02005dnl
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 2, 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
Lucas De Marchic619d892015-02-24 22:29:04 -030036dnl Check if FLAG in ENV-VAR is supported by compiler and append it
37dnl to WHERE-TO-APPEND variable
Lucas De Marchie48f3762012-03-17 15:12:44 -030038dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG])
Lucas De Marchic619d892015-02-24 22:29:04 -030039
Lucas De Marchie48f3762012-03-17 15:12:44 -030040AC_DEFUN([CC_CHECK_FLAG_APPEND], [
41 AC_CACHE_CHECK([if $CC supports flag $3 in envvar $2],
42 AS_TR_SH([cc_cv_$2_$3]),
Lucas De Marchic619d892015-02-24 22:29:04 -030043 [eval "AS_TR_SH([cc_save_$2])='${$2}'"
44 eval "AS_TR_SH([$2])='-Werror $3'"
Zbigniew Jędrzejewski-Szmeka8f3aae2014-08-02 23:50:22 -040045 AC_LINK_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; } ])],
David Herrmann779729c2013-09-13 12:42:12 +020046 [eval "AS_TR_SH([cc_cv_$2_$3])='yes'"],
47 [eval "AS_TR_SH([cc_cv_$2_$3])='no'"])
Lucas De Marchic619d892015-02-24 22:29:04 -030048 eval "AS_TR_SH([$2])='$cc_save_$2'"])
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -020049
Lucas De Marchie48f3762012-03-17 15:12:44 -030050 AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes],
51 [eval "$1='${$1} $3'"])
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -020052])
53
Lucas De Marchie48f3762012-03-17 15:12:44 -030054dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2])
55AC_DEFUN([CC_CHECK_FLAGS_APPEND], [
56 for flag in $3; do
57 CC_CHECK_FLAG_APPEND($1, $2, $flag)
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -020058 done
59])
60
Lucas De Marchic619d892015-02-24 22:29:04 -030061dnl Check if the flag is supported by linker (cacheable)
62dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
Lucas De Marchie48f3762012-03-17 15:12:44 -030063
64
Randy Witt00ff5762012-03-16 01:01:17 -040065dnl Check if the flag is supported by linker
66dnl CC_CHECK_LDFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
Randy Witt00ff5762012-03-16 01:01:17 -040067AC_DEFUN([CC_CHECK_LDFLAGS_SILENT], [
68 AC_CACHE_VAL(AS_TR_SH([cc_cv_ldflags_$1]),
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -020069 [ac_save_LDFLAGS="$LDFLAGS"
70 LDFLAGS="$LDFLAGS $1"
Randy Witt00ff5762012-03-16 01:01:17 -040071 AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])],
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -020072 [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
73 [eval "AS_TR_SH([cc_cv_ldflags_$1])="])
74 LDFLAGS="$ac_save_LDFLAGS"
75 ])
76
77 AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
78 [$2], [$3])
79])
80
Randy Witt00ff5762012-03-16 01:01:17 -040081dnl Check if the flag is supported by linker (cacheable)
82dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
83
84AC_DEFUN([CC_CHECK_LDFLAGS], [
85 AC_CACHE_CHECK([if $CC supports $1 flag],
86 AS_TR_SH([cc_cv_ldflags_$1]),
87 CC_CHECK_LDFLAGS_SILENT([$1]) dnl Don't execute actions here!
88 )
89
90 AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
91 [$2], [$3])
92])
93
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -020094dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for
95dnl the current linker to avoid undefined references in a shared object.
96AC_DEFUN([CC_NOUNDEFINED], [
97 dnl We check $host for which systems to enable this for.
98 AC_REQUIRE([AC_CANONICAL_HOST])
99
100 case $host in
101 dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads
102 dnl are requested, as different implementations are present; to avoid problems
103 dnl use -Wl,-z,defs only for those platform not behaving this way.
104 *-freebsd* | *-openbsd*) ;;
105 *)
106 dnl First of all check for the --no-undefined variant of GNU ld. This allows
Lucas De Marchic619d892015-02-24 22:29:04 -0300107 dnl for a much more readable command line, so that people can understand what
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -0200108 dnl it does without going to look for what the heck -z defs does.
109 for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do
110 CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"])
Lucas De Marchic619d892015-02-24 22:29:04 -0300111 break
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -0200112 done
Lucas De Marchic619d892015-02-24 22:29:04 -0300113 ;;
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -0200114 esac
115
116 AC_SUBST([LDFLAGS_NOUNDEFINED])
117])
118
119dnl Check for a -Werror flag or equivalent. -Werror is the GCC
120dnl and ICC flag that tells the compiler to treat all the warnings
121dnl as fatal. We usually need this option to make sure that some
122dnl constructs (like attributes) are not simply ignored.
123dnl
124dnl Other compilers don't support -Werror per se, but they support
125dnl an equivalent flag:
126dnl - Sun Studio compiler supports -errwarn=%all
127AC_DEFUN([CC_CHECK_WERROR], [
128 AC_CACHE_CHECK(
129 [for $CC way to treat warnings as errors],
130 [cc_cv_werror],
131 [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror],
132 [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])])
133 ])
134])
135
136AC_DEFUN([CC_CHECK_ATTRIBUTE], [
137 AC_REQUIRE([CC_CHECK_WERROR])
138 AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))],
139 AS_TR_SH([cc_cv_attribute_$1]),
140 [ac_save_CFLAGS="$CFLAGS"
141 CFLAGS="$CFLAGS $cc_cv_werror"
142 AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])],
143 [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"],
144 [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"])
145 CFLAGS="$ac_save_CFLAGS"
146 ])
147
148 AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes],
149 [AC_DEFINE(
150 AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1,
151 [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))]
152 )
153 $4],
154 [$5])
155])
156
157AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
158 CC_CHECK_ATTRIBUTE(
159 [constructor],,
160 [void __attribute__((constructor)) ctor() { int a; }],
161 [$1], [$2])
162])
163
164AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
165 CC_CHECK_ATTRIBUTE(
166 [format], [format(printf, n, n)],
167 [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }],
168 [$1], [$2])
169])
170
171AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [
172 CC_CHECK_ATTRIBUTE(
173 [format_arg], [format_arg(printf)],
174 [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }],
175 [$1], [$2])
176])
177
178AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
179 CC_CHECK_ATTRIBUTE(
180 [visibility_$1], [visibility("$1")],
181 [void __attribute__((visibility("$1"))) $1_function() { }],
182 [$2], [$3])
183])
184
185AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
186 CC_CHECK_ATTRIBUTE(
187 [nonnull], [nonnull()],
188 [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }],
189 [$1], [$2])
190])
191
192AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
193 CC_CHECK_ATTRIBUTE(
194 [unused], ,
195 [void some_function(void *foo, __attribute__((unused)) void *bar);],
196 [$1], [$2])
197])
198
199AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [
200 CC_CHECK_ATTRIBUTE(
201 [sentinel], ,
202 [void some_function(void *foo, ...) __attribute__((sentinel));],
203 [$1], [$2])
204])
205
206AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [
207 CC_CHECK_ATTRIBUTE(
208 [deprecated], ,
209 [void some_function(void *foo, ...) __attribute__((deprecated));],
210 [$1], [$2])
211])
212
213AC_DEFUN([CC_ATTRIBUTE_ALIAS], [
214 CC_CHECK_ATTRIBUTE(
215 [alias], [weak, alias],
216 [void other_function(void *foo) { }
217 void some_function(void *foo) __attribute__((weak, alias("other_function")));],
218 [$1], [$2])
219])
220
221AC_DEFUN([CC_ATTRIBUTE_MALLOC], [
222 CC_CHECK_ATTRIBUTE(
223 [malloc], ,
224 [void * __attribute__((malloc)) my_alloc(int n);],
225 [$1], [$2])
226])
227
228AC_DEFUN([CC_ATTRIBUTE_PACKED], [
229 CC_CHECK_ATTRIBUTE(
230 [packed], ,
231 [struct astructure { char a; int b; long c; void *d; } __attribute__((packed));],
232 [$1], [$2])
233])
234
235AC_DEFUN([CC_ATTRIBUTE_CONST], [
236 CC_CHECK_ATTRIBUTE(
237 [const], ,
238 [int __attribute__((const)) twopow(int n) { return 1 << n; } ],
239 [$1], [$2])
240])
241
242AC_DEFUN([CC_FLAG_VISIBILITY], [
243 AC_REQUIRE([CC_CHECK_WERROR])
244 AC_CACHE_CHECK([if $CC supports -fvisibility=hidden],
245 [cc_cv_flag_visibility],
246 [cc_flag_visibility_save_CFLAGS="$CFLAGS"
247 CFLAGS="$CFLAGS $cc_cv_werror"
248 CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden],
Lucas De Marchic619d892015-02-24 22:29:04 -0300249 cc_cv_flag_visibility='yes',
250 cc_cv_flag_visibility='no')
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -0200251 CFLAGS="$cc_flag_visibility_save_CFLAGS"])
252
253 AS_IF([test "x$cc_cv_flag_visibility" = "xyes"],
254 [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1,
255 [Define this if the compiler supports the -fvisibility flag])
256 $1],
257 [$2])
258])
259
Lucas De Marchiba52c772015-02-10 00:31:08 -0200260AC_DEFUN([CC_CHECK_FUNC_BUILTIN], [
261 m4_pushdef([UPNAME], m4_translit([$1], [-a-z], [_A-Z]))
Lucas De Marchi14c32442015-02-10 10:32:10 -0200262 AC_CACHE_CHECK([if compiler has $1 builtin function],
Lucas De Marchiba52c772015-02-10 00:31:08 -0200263 [cc_cv_have_$1],
264 [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [
265 m4_case([$1],
Lucas De Marchie6307202015-02-10 00:45:11 -0200266 [__builtin_clz], [$1(0)],
267 [__builtin_types_compatible_p], [$1(int, int)],
Lucas De Marchiaac5f452015-02-10 10:41:47 -0200268 [__builtin_uaddl_overflow], [$1(0UL, 0UL, (void*)0)],
269 [__builtin_uaddll_overflow], [$1(0ULL, 0ULL, (void*)0)],
Lucas De Marchiba52c772015-02-10 00:31:08 -0200270 [__builtin_expect], [$1(0, 0)]
271 )])],
272 [cc_cv_have_$1=yes],
273 [cc_cv_have_$1=no])])
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -0200274
Lucas De Marchiba52c772015-02-10 00:31:08 -0200275 AS_IF([test "x$cc_cv_have_$1" = "xyes"],
Lucas De Marchi14c32442015-02-10 10:32:10 -0200276 [AC_DEFINE([HAVE_]m4_defn([UPNAME]), 1, [Define to 1 if compiler has $1() builtin function])
Lucas De Marchie6307202015-02-10 00:45:11 -0200277 $2],
Lucas De Marchi14c32442015-02-10 10:32:10 -0200278 [AS_IF([test "x$3" = "x"], [AC_MSG_ERROR([*** builtin function not found: $1()])],
279 [AC_DEFINE([HAVE_]m4_defn([UPNAME]), 0)
Lucas De Marchic619d892015-02-24 22:29:04 -0300280 $3])]
Lucas De Marchie6307202015-02-10 00:45:11 -0200281 )
Lucas De Marchiba52c772015-02-10 00:31:08 -0200282 m4_popdef([UPNAME])
Gustavo Sverzut Barbieri822ce232011-12-10 22:26:40 -0200283])
284
285AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
286 AC_REQUIRE([CC_CHECK_WERROR])
287 AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported],
288 [cc_cv_attribute_aligned],
289 [ac_save_CFLAGS="$CFLAGS"
290 CFLAGS="$CFLAGS $cc_cv_werror"
291 for cc_attribute_align_try in 64 32 16 8 4 2; do
292 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
293 int main() {
294 static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0;
295 return c;
296 }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
297 done
298 CFLAGS="$ac_save_CFLAGS"
299 ])
300
301 if test "x$cc_cv_attribute_aligned" != "x"; then
302 AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned],
303 [Define the highest alignment supported])
304 fi
305])