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) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com> 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 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 36dnl Check if FLAG in ENV-VAR is supported by compiler and append it 37dnl to WHERE-TO-APPEND variable. Note that we invert -Wno-* checks to 38dnl -W* as gcc cannot test for negated warnings. 39dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG]) 40 41AC_DEFUN([CC_CHECK_FLAG_APPEND], [ 42 AC_CACHE_CHECK([if $CC supports flag $3 in envvar $2], 43 AS_TR_SH([cc_cv_$2_$3]), 44 [eval "AS_TR_SH([cc_save_$2])='${$2}'" 45 eval "AS_TR_SH([$2])='-Werror `echo "$3" | sed 's/^-Wno-/-W/'`'" 46 AC_LINK_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; } ])], 47 [eval "AS_TR_SH([cc_cv_$2_$3])='yes'"], 48 [eval "AS_TR_SH([cc_cv_$2_$3])='no'"]) 49 eval "AS_TR_SH([$2])='$cc_save_$2'"]) 50 51 AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes], 52 [eval "$1='${$1} $3'"]) 53]) 54 55dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2]) 56AC_DEFUN([CC_CHECK_FLAGS_APPEND], [ 57 for flag in $3; do 58 CC_CHECK_FLAG_APPEND($1, $2, $flag) 59 done 60]) 61 62dnl Check if the flag is supported by linker (cacheable) 63dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) 64 65 66dnl Check if the flag is supported by linker 67dnl CC_CHECK_LDFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) 68AC_DEFUN([CC_CHECK_LDFLAGS_SILENT], [ 69 AC_CACHE_VAL(AS_TR_SH([cc_cv_ldflags_$1]), 70 [ac_save_LDFLAGS="$LDFLAGS" 71 LDFLAGS="$LDFLAGS $1" 72 AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])], 73 [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"], 74 [eval "AS_TR_SH([cc_cv_ldflags_$1])="]) 75 LDFLAGS="$ac_save_LDFLAGS" 76 ]) 77 78 AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes], 79 [$2], [$3]) 80]) 81 82dnl Check if the flag is supported by linker (cacheable) 83dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) 84 85AC_DEFUN([CC_CHECK_LDFLAGS], [ 86 AC_CACHE_CHECK([if $CC supports $1 flag], 87 AS_TR_SH([cc_cv_ldflags_$1]), 88 CC_CHECK_LDFLAGS_SILENT([$1]) dnl Don't execute actions here! 89 ) 90 91 AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes], 92 [$2], [$3]) 93]) 94 95dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for 96dnl the current linker to avoid undefined references in a shared object. 97AC_DEFUN([CC_NOUNDEFINED], [ 98 dnl We check $host for which systems to enable this for. 99 AC_REQUIRE([AC_CANONICAL_HOST]) 100 101 case $host in 102 dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads 103 dnl are requested, as different implementations are present; to avoid problems 104 dnl use -Wl,-z,defs only for those platform not behaving this way. 105 *-freebsd* | *-openbsd*) ;; 106 *) 107 dnl First of all check for the --no-undefined variant of GNU ld. This allows 108 dnl for a much more readable command line, so that people can understand what 109 dnl it does without going to look for what the heck -z defs does. 110 for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do 111 CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"]) 112 break 113 done 114 ;; 115 esac 116 117 AC_SUBST([LDFLAGS_NOUNDEFINED]) 118]) 119 120dnl Check for a -Werror flag or equivalent. -Werror is the GCC 121dnl and ICC flag that tells the compiler to treat all the warnings 122dnl as fatal. We usually need this option to make sure that some 123dnl constructs (like attributes) are not simply ignored. 124dnl 125dnl Other compilers don't support -Werror per se, but they support 126dnl an equivalent flag: 127dnl - Sun Studio compiler supports -errwarn=%all 128AC_DEFUN([CC_CHECK_WERROR], [ 129 AC_CACHE_CHECK( 130 [for $CC way to treat warnings as errors], 131 [cc_cv_werror], 132 [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror], 133 [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])]) 134 ]) 135]) 136 137AC_DEFUN([CC_CHECK_ATTRIBUTE], [ 138 AC_REQUIRE([CC_CHECK_WERROR]) 139 AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))], 140 AS_TR_SH([cc_cv_attribute_$1]), 141 [ac_save_CFLAGS="$CFLAGS" 142 CFLAGS="$CFLAGS $cc_cv_werror" 143 AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])], 144 [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"], 145 [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"]) 146 CFLAGS="$ac_save_CFLAGS" 147 ]) 148 149 AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes], 150 [AC_DEFINE( 151 AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1, 152 [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))] 153 ) 154 $4], 155 [$5]) 156]) 157 158AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [ 159 CC_CHECK_ATTRIBUTE( 160 [constructor],, 161 [void __attribute__((constructor)) ctor() { int a; }], 162 [$1], [$2]) 163]) 164 165AC_DEFUN([CC_ATTRIBUTE_FORMAT], [ 166 CC_CHECK_ATTRIBUTE( 167 [format], [format(printf, n, n)], 168 [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }], 169 [$1], [$2]) 170]) 171 172AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [ 173 CC_CHECK_ATTRIBUTE( 174 [format_arg], [format_arg(printf)], 175 [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }], 176 [$1], [$2]) 177]) 178 179AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [ 180 CC_CHECK_ATTRIBUTE( 181 [visibility_$1], [visibility("$1")], 182 [void __attribute__((visibility("$1"))) $1_function() { }], 183 [$2], [$3]) 184]) 185 186AC_DEFUN([CC_ATTRIBUTE_NONNULL], [ 187 CC_CHECK_ATTRIBUTE( 188 [nonnull], [nonnull()], 189 [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }], 190 [$1], [$2]) 191]) 192 193AC_DEFUN([CC_ATTRIBUTE_UNUSED], [ 194 CC_CHECK_ATTRIBUTE( 195 [unused], , 196 [void some_function(void *foo, __attribute__((unused)) void *bar);], 197 [$1], [$2]) 198]) 199 200AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [ 201 CC_CHECK_ATTRIBUTE( 202 [sentinel], , 203 [void some_function(void *foo, ...) __attribute__((sentinel));], 204 [$1], [$2]) 205]) 206 207AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [ 208 CC_CHECK_ATTRIBUTE( 209 [deprecated], , 210 [void some_function(void *foo, ...) __attribute__((deprecated));], 211 [$1], [$2]) 212]) 213 214AC_DEFUN([CC_ATTRIBUTE_ALIAS], [ 215 CC_CHECK_ATTRIBUTE( 216 [alias], [weak, alias], 217 [void other_function(void *foo) { } 218 void some_function(void *foo) __attribute__((weak, alias("other_function")));], 219 [$1], [$2]) 220]) 221 222AC_DEFUN([CC_ATTRIBUTE_MALLOC], [ 223 CC_CHECK_ATTRIBUTE( 224 [malloc], , 225 [void * __attribute__((malloc)) my_alloc(int n);], 226 [$1], [$2]) 227]) 228 229AC_DEFUN([CC_ATTRIBUTE_PACKED], [ 230 CC_CHECK_ATTRIBUTE( 231 [packed], , 232 [struct astructure { char a; int b; long c; void *d; } __attribute__((packed));], 233 [$1], [$2]) 234]) 235 236AC_DEFUN([CC_ATTRIBUTE_CONST], [ 237 CC_CHECK_ATTRIBUTE( 238 [const], , 239 [int __attribute__((const)) twopow(int n) { return 1 << n; } ], 240 [$1], [$2]) 241]) 242 243AC_DEFUN([CC_FLAG_VISIBILITY], [ 244 AC_REQUIRE([CC_CHECK_WERROR]) 245 AC_CACHE_CHECK([if $CC supports -fvisibility=hidden], 246 [cc_cv_flag_visibility], 247 [cc_flag_visibility_save_CFLAGS="$CFLAGS" 248 CFLAGS="$CFLAGS $cc_cv_werror" 249 CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden], 250 cc_cv_flag_visibility='yes', 251 cc_cv_flag_visibility='no') 252 CFLAGS="$cc_flag_visibility_save_CFLAGS"]) 253 254 AS_IF([test "x$cc_cv_flag_visibility" = "xyes"], 255 [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1, 256 [Define this if the compiler supports the -fvisibility flag]) 257 $1], 258 [$2]) 259]) 260 261AC_DEFUN([CC_CHECK_FUNC_BUILTIN], [ 262 m4_pushdef([UPNAME], m4_translit([$1], [-a-z], [_A-Z])) 263 AC_CACHE_CHECK([if compiler has $1 builtin function], 264 [cc_cv_have_$1], 265 [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [ 266 m4_case([$1], 267 [__builtin_clz], [$1(0)], 268 [__builtin_types_compatible_p], [$1(int, int)], 269 [__builtin_uaddl_overflow], [$1(0UL, 0UL, (void*)0)], 270 [__builtin_uaddll_overflow], [$1(0ULL, 0ULL, (void*)0)], 271 [__builtin_expect], [$1(0, 0)] 272 )])], 273 [cc_cv_have_$1=yes], 274 [cc_cv_have_$1=no])]) 275 276 AS_IF([test "x$cc_cv_have_$1" = "xyes"], 277 [AC_DEFINE([HAVE_]m4_defn([UPNAME]), 1, [Define to 1 if compiler has $1() builtin function]) 278 $2], 279 [AS_IF([test "x$3" = "x"], [AC_MSG_ERROR([*** builtin function not found: $1()])], 280 [AC_DEFINE([HAVE_]m4_defn([UPNAME]), 0) 281 $3])] 282 ) 283 m4_popdef([UPNAME]) 284]) 285 286AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [ 287 AC_REQUIRE([CC_CHECK_WERROR]) 288 AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported], 289 [cc_cv_attribute_aligned], 290 [ac_save_CFLAGS="$CFLAGS" 291 CFLAGS="$CFLAGS $cc_cv_werror" 292 for cc_attribute_align_try in 64 32 16 8 4 2; do 293 AC_COMPILE_IFELSE([AC_LANG_SOURCE([ 294 int main() { 295 static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0; 296 return c; 297 }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break]) 298 done 299 CFLAGS="$ac_save_CFLAGS" 300 ]) 301 302 if test "x$cc_cv_attribute_aligned" != "x"; then 303 AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned], 304 [Define the highest alignment supported]) 305 fi 306]) 307