1dnl Macros to check the presence of generic (non-typed) symbols. 2dnl Copyright (c) 2006-2007 Diego Pettenò <flameeyes@gmail.com> 3dnl Copyright (c) 2006-2007 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_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])], 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"; $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 *-freebsd* | *-openbsd*) ;; 113 *) 114 dnl First of all check for the --no-undefined variant of GNU ld. This allows 115 dnl for a much more readable commandline, so that people can understand what 116 dnl it does without going to look for what the heck -z defs does. 117 for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do 118 CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"]) 119 break 120 done 121 ;; 122 esac 123 124 AC_SUBST([LDFLAGS_NOUNDEFINED]) 125]) 126 127dnl Check for a -Werror flag or equivalent. -Werror is the GCC 128dnl and ICC flag that tells the compiler to treat all the warnings 129dnl as fatal. We usually need this option to make sure that some 130dnl constructs (like attributes) are not simply ignored. 131dnl 132dnl Other compilers don't support -Werror per se, but they support 133dnl an equivalent flag: 134dnl - Sun Studio compiler supports -errwarn=%all 135AC_DEFUN([CC_CHECK_WERROR], [ 136 AC_CACHE_CHECK( 137 [for $CC way to treat warnings as errors], 138 [cc_cv_werror], 139 [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror], 140 [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])]) 141 ]) 142]) 143 144AC_DEFUN([CC_CHECK_ATTRIBUTE], [ 145 AC_REQUIRE([CC_CHECK_WERROR]) 146 AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))], 147 AS_TR_SH([cc_cv_attribute_$1]), 148 [ac_save_CFLAGS="$CFLAGS" 149 CFLAGS="$CFLAGS $cc_cv_werror" 150 AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])], 151 [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"], 152 [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"]) 153 CFLAGS="$ac_save_CFLAGS" 154 ]) 155 156 AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes], 157 [AC_DEFINE( 158 AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1, 159 [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))] 160 ) 161 $4], 162 [$5]) 163]) 164 165AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [ 166 CC_CHECK_ATTRIBUTE( 167 [constructor],, 168 [extern void foo(); 169 void __attribute__((constructor)) ctor() { foo(); }], 170 [$1], [$2]) 171]) 172 173AC_DEFUN([CC_ATTRIBUTE_DESTRUCTOR], [ 174 CC_CHECK_ATTRIBUTE( 175 [destructor],, 176 [extern void foo(); 177 void __attribute__((destructor)) dtor() { foo(); }], 178 [$1], [$2]) 179]) 180 181AC_DEFUN([CC_ATTRIBUTE_FORMAT], [ 182 CC_CHECK_ATTRIBUTE( 183 [format], [format(printf, n, n)], 184 [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }], 185 [$1], [$2]) 186]) 187 188AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [ 189 CC_CHECK_ATTRIBUTE( 190 [format_arg], [format_arg(printf)], 191 [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }], 192 [$1], [$2]) 193]) 194 195AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [ 196 CC_CHECK_ATTRIBUTE( 197 [visibility_$1], [visibility("$1")], 198 [void __attribute__((visibility("$1"))) $1_function() { }], 199 [$2], [$3]) 200]) 201 202AC_DEFUN([CC_ATTRIBUTE_NONNULL], [ 203 CC_CHECK_ATTRIBUTE( 204 [nonnull], [nonnull()], 205 [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }], 206 [$1], [$2]) 207]) 208 209AC_DEFUN([CC_ATTRIBUTE_UNUSED], [ 210 CC_CHECK_ATTRIBUTE( 211 [unused], , 212 [void some_function(void *foo, __attribute__((unused)) void *bar);], 213 [$1], [$2]) 214]) 215 216AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [ 217 CC_CHECK_ATTRIBUTE( 218 [sentinel], , 219 [void some_function(void *foo, ...) __attribute__((sentinel));], 220 [$1], [$2]) 221]) 222 223AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [ 224 CC_CHECK_ATTRIBUTE( 225 [deprecated], , 226 [void some_function(void *foo, ...) __attribute__((deprecated));], 227 [$1], [$2]) 228]) 229 230AC_DEFUN([CC_ATTRIBUTE_ALIAS], [ 231 CC_CHECK_ATTRIBUTE( 232 [alias], [weak, alias], 233 [void other_function(void *foo) { } 234 void some_function(void *foo) __attribute__((weak, alias("other_function")));], 235 [$1], [$2]) 236]) 237 238AC_DEFUN([CC_ATTRIBUTE_MALLOC], [ 239 CC_CHECK_ATTRIBUTE( 240 [malloc], , 241 [void * __attribute__((malloc)) my_alloc(int n);], 242 [$1], [$2]) 243]) 244 245AC_DEFUN([CC_ATTRIBUTE_PACKED], [ 246 CC_CHECK_ATTRIBUTE( 247 [packed], , 248 [struct astructure { char a; int b; long c; void *d; } __attribute__((packed)); 249 char assert@<:@(sizeof(struct astructure) == (sizeof(char)+sizeof(int)+sizeof(long)+sizeof(void*)))-1@:>@;], 250 [$1], [$2]) 251]) 252 253AC_DEFUN([CC_ATTRIBUTE_CONST], [ 254 CC_CHECK_ATTRIBUTE( 255 [const], , 256 [int __attribute__((const)) twopow(int n) { return 1 << n; } ], 257 [$1], [$2]) 258]) 259 260AC_DEFUN([CC_FLAG_VISIBILITY], [ 261 AC_REQUIRE([CC_CHECK_WERROR]) 262 AC_CACHE_CHECK([if $CC supports -fvisibility=hidden], 263 [cc_cv_flag_visibility], 264 [cc_flag_visibility_save_CFLAGS="$CFLAGS" 265 CFLAGS="$CFLAGS $cc_cv_werror" 266 CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden], 267 cc_cv_flag_visibility='yes', 268 cc_cv_flag_visibility='no') 269 CFLAGS="$cc_flag_visibility_save_CFLAGS"]) 270 271 AS_IF([test "x$cc_cv_flag_visibility" = "xyes"], 272 [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1, 273 [Define this if the compiler supports the -fvisibility flag]) 274 $1], 275 [$2]) 276]) 277 278AC_DEFUN([CC_FUNC_EXPECT], [ 279 AC_REQUIRE([CC_CHECK_WERROR]) 280 AC_CACHE_CHECK([if compiler has __builtin_expect function], 281 [cc_cv_func_expect], 282 [ac_save_CFLAGS="$CFLAGS" 283 CFLAGS="$CFLAGS $cc_cv_werror" 284 AC_COMPILE_IFELSE([AC_LANG_SOURCE( 285 [int some_function() { 286 int a = 3; 287 return (int)__builtin_expect(a, 3); 288 }])], 289 [cc_cv_func_expect=yes], 290 [cc_cv_func_expect=no]) 291 CFLAGS="$ac_save_CFLAGS" 292 ]) 293 294 AS_IF([test "x$cc_cv_func_expect" = "xyes"], 295 [AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1, 296 [Define this if the compiler supports __builtin_expect() function]) 297 $1], 298 [$2]) 299]) 300 301AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [ 302 AC_REQUIRE([CC_CHECK_WERROR]) 303 AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported], 304 [cc_cv_attribute_aligned], 305 [ac_save_CFLAGS="$CFLAGS" 306 CFLAGS="$CFLAGS $cc_cv_werror" 307 for cc_attribute_align_try in 64 32 16 8 4 2; do 308 AC_COMPILE_IFELSE([AC_LANG_SOURCE([ 309 int main() { 310 static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0; 311 return c; 312 }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break]) 313 done 314 CFLAGS="$ac_save_CFLAGS" 315 ]) 316 317 if test "x$cc_cv_attribute_aligned" != "x"; then 318 AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned], 319 [Define the highest alignment supported]) 320 fi 321]) 322