cannam@154: dnl Macros to check the presence of generic (non-typed) symbols. cannam@154: dnl Copyright (c) 2006-2007 Diego Pettenò cannam@154: dnl Copyright (c) 2006-2007 xine project cannam@154: dnl cannam@154: dnl This program is free software; you can redistribute it and/or modify cannam@154: dnl it under the terms of the GNU General Public License as published by cannam@154: dnl the Free Software Foundation; either version 2, or (at your option) cannam@154: dnl any later version. cannam@154: dnl cannam@154: dnl This program is distributed in the hope that it will be useful, cannam@154: dnl but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@154: dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@154: dnl GNU General Public License for more details. cannam@154: dnl cannam@154: dnl You should have received a copy of the GNU General Public License cannam@154: dnl along with this program; if not, write to the Free Software cannam@154: dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA cannam@154: dnl 02110-1301, USA. cannam@154: dnl cannam@154: dnl As a special exception, the copyright owners of the cannam@154: dnl macro gives unlimited permission to copy, distribute and modify the cannam@154: dnl configure scripts that are the output of Autoconf when processing the cannam@154: dnl Macro. You need not follow the terms of the GNU General Public cannam@154: dnl License when using or distributing such scripts, even though portions cannam@154: dnl of the text of the Macro appear in them. The GNU General Public cannam@154: dnl License (GPL) does govern all other use of the material that cannam@154: dnl constitutes the Autoconf Macro. cannam@154: dnl cannam@154: dnl This special exception to the GPL applies to versions of the cannam@154: dnl Autoconf Macro released by this project. When you make and cannam@154: dnl distribute a modified version of the Autoconf Macro, you may extend cannam@154: dnl this special exception to the GPL to apply to your modified version as cannam@154: dnl well. cannam@154: cannam@154: dnl Check if the flag is supported by compiler cannam@154: dnl CC_CHECK_CFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) cannam@154: cannam@154: AC_DEFUN([CC_CHECK_CFLAGS_SILENT], [ cannam@154: AC_CACHE_VAL(AS_TR_SH([cc_cv_cflags_$1]), cannam@154: [ac_save_CFLAGS="$CFLAGS" cannam@154: CFLAGS="$CFLAGS $1" cannam@154: AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])], cannam@154: [eval "AS_TR_SH([cc_cv_cflags_$1])='yes'"], cannam@154: [eval "AS_TR_SH([cc_cv_cflags_$1])='no'"]) cannam@154: CFLAGS="$ac_save_CFLAGS" cannam@154: ]) cannam@154: cannam@154: AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes], cannam@154: [$2], [$3]) cannam@154: ]) cannam@154: cannam@154: dnl Check if the flag is supported by compiler (cacheable) cannam@154: dnl CC_CHECK_CFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) cannam@154: cannam@154: AC_DEFUN([CC_CHECK_CFLAGS], [ cannam@154: AC_CACHE_CHECK([if $CC supports $1 flag], cannam@154: AS_TR_SH([cc_cv_cflags_$1]), cannam@154: CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here! cannam@154: ) cannam@154: cannam@154: AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes], cannam@154: [$2], [$3]) cannam@154: ]) cannam@154: cannam@154: dnl CC_CHECK_CFLAG_APPEND(FLAG, [action-if-found], [action-if-not-found]) cannam@154: dnl Check for CFLAG and appends them to CFLAGS if supported cannam@154: AC_DEFUN([CC_CHECK_CFLAG_APPEND], [ cannam@154: AC_CACHE_CHECK([if $CC supports $1 flag], cannam@154: AS_TR_SH([cc_cv_cflags_$1]), cannam@154: CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here! cannam@154: ) cannam@154: cannam@154: AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes], cannam@154: [CFLAGS="$CFLAGS $1"; $2], [$3]) cannam@154: ]) cannam@154: cannam@154: dnl CC_CHECK_CFLAGS_APPEND([FLAG1 FLAG2], [action-if-found], [action-if-not]) cannam@154: AC_DEFUN([CC_CHECK_CFLAGS_APPEND], [ cannam@154: for flag in $1; do cannam@154: CC_CHECK_CFLAG_APPEND($flag, [$2], [$3]) cannam@154: done cannam@154: ]) cannam@154: cannam@154: dnl Check if the flag is supported by linker (cacheable) cannam@154: dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) cannam@154: cannam@154: AC_DEFUN([CC_CHECK_LDFLAGS], [ cannam@154: AC_CACHE_CHECK([if $CC supports $1 flag], cannam@154: AS_TR_SH([cc_cv_ldflags_$1]), cannam@154: [ac_save_LDFLAGS="$LDFLAGS" cannam@154: LDFLAGS="$LDFLAGS $1" cannam@154: AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])], cannam@154: [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"], cannam@154: [eval "AS_TR_SH([cc_cv_ldflags_$1])="]) cannam@154: LDFLAGS="$ac_save_LDFLAGS" cannam@154: ]) cannam@154: cannam@154: AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes], cannam@154: [$2], [$3]) cannam@154: ]) cannam@154: cannam@154: dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for cannam@154: dnl the current linker to avoid undefined references in a shared object. cannam@154: AC_DEFUN([CC_NOUNDEFINED], [ cannam@154: dnl We check $host for which systems to enable this for. cannam@154: AC_REQUIRE([AC_CANONICAL_HOST]) cannam@154: cannam@154: case $host in cannam@154: dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads cannam@154: dnl are requested, as different implementations are present; to avoid problems cannam@154: dnl use -Wl,-z,defs only for those platform not behaving this way. cannam@154: *-freebsd* | *-openbsd*) ;; cannam@154: *) cannam@154: dnl First of all check for the --no-undefined variant of GNU ld. This allows cannam@154: dnl for a much more readable commandline, so that people can understand what cannam@154: dnl it does without going to look for what the heck -z defs does. cannam@154: for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do cannam@154: CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"]) cannam@154: break cannam@154: done cannam@154: ;; cannam@154: esac cannam@154: cannam@154: AC_SUBST([LDFLAGS_NOUNDEFINED]) cannam@154: ]) cannam@154: cannam@154: dnl Check for a -Werror flag or equivalent. -Werror is the GCC cannam@154: dnl and ICC flag that tells the compiler to treat all the warnings cannam@154: dnl as fatal. We usually need this option to make sure that some cannam@154: dnl constructs (like attributes) are not simply ignored. cannam@154: dnl cannam@154: dnl Other compilers don't support -Werror per se, but they support cannam@154: dnl an equivalent flag: cannam@154: dnl - Sun Studio compiler supports -errwarn=%all cannam@154: AC_DEFUN([CC_CHECK_WERROR], [ cannam@154: AC_CACHE_CHECK( cannam@154: [for $CC way to treat warnings as errors], cannam@154: [cc_cv_werror], cannam@154: [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror], cannam@154: [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])]) cannam@154: ]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_CHECK_ATTRIBUTE], [ cannam@154: AC_REQUIRE([CC_CHECK_WERROR]) cannam@154: AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))], cannam@154: AS_TR_SH([cc_cv_attribute_$1]), cannam@154: [ac_save_CFLAGS="$CFLAGS" cannam@154: CFLAGS="$CFLAGS $cc_cv_werror" cannam@154: AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])], cannam@154: [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"], cannam@154: [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"]) cannam@154: CFLAGS="$ac_save_CFLAGS" cannam@154: ]) cannam@154: cannam@154: AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes], cannam@154: [AC_DEFINE( cannam@154: AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1, cannam@154: [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))] cannam@154: ) cannam@154: $4], cannam@154: [$5]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [constructor],, cannam@154: [extern void foo(); cannam@154: void __attribute__((constructor)) ctor() { foo(); }], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_DESTRUCTOR], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [destructor],, cannam@154: [extern void foo(); cannam@154: void __attribute__((destructor)) dtor() { foo(); }], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_FORMAT], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [format], [format(printf, n, n)], cannam@154: [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [format_arg], [format_arg(printf)], cannam@154: [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [visibility_$1], [visibility("$1")], cannam@154: [void __attribute__((visibility("$1"))) $1_function() { }], cannam@154: [$2], [$3]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_NONNULL], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [nonnull], [nonnull()], cannam@154: [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_UNUSED], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [unused], , cannam@154: [void some_function(void *foo, __attribute__((unused)) void *bar);], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [sentinel], , cannam@154: [void some_function(void *foo, ...) __attribute__((sentinel));], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [deprecated], , cannam@154: [void some_function(void *foo, ...) __attribute__((deprecated));], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_ALIAS], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [alias], [weak, alias], cannam@154: [void other_function(void *foo) { } cannam@154: void some_function(void *foo) __attribute__((weak, alias("other_function")));], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_MALLOC], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [malloc], , cannam@154: [void * __attribute__((malloc)) my_alloc(int n);], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_PACKED], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [packed], , cannam@154: [struct astructure { char a; int b; long c; void *d; } __attribute__((packed)); cannam@154: char assert@<:@(sizeof(struct astructure) == (sizeof(char)+sizeof(int)+sizeof(long)+sizeof(void*)))-1@:>@;], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_CONST], [ cannam@154: CC_CHECK_ATTRIBUTE( cannam@154: [const], , cannam@154: [int __attribute__((const)) twopow(int n) { return 1 << n; } ], cannam@154: [$1], [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_FLAG_VISIBILITY], [ cannam@154: AC_REQUIRE([CC_CHECK_WERROR]) cannam@154: AC_CACHE_CHECK([if $CC supports -fvisibility=hidden], cannam@154: [cc_cv_flag_visibility], cannam@154: [cc_flag_visibility_save_CFLAGS="$CFLAGS" cannam@154: CFLAGS="$CFLAGS $cc_cv_werror" cannam@154: CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden], cannam@154: cc_cv_flag_visibility='yes', cannam@154: cc_cv_flag_visibility='no') cannam@154: CFLAGS="$cc_flag_visibility_save_CFLAGS"]) cannam@154: cannam@154: AS_IF([test "x$cc_cv_flag_visibility" = "xyes"], cannam@154: [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1, cannam@154: [Define this if the compiler supports the -fvisibility flag]) cannam@154: $1], cannam@154: [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_FUNC_EXPECT], [ cannam@154: AC_REQUIRE([CC_CHECK_WERROR]) cannam@154: AC_CACHE_CHECK([if compiler has __builtin_expect function], cannam@154: [cc_cv_func_expect], cannam@154: [ac_save_CFLAGS="$CFLAGS" cannam@154: CFLAGS="$CFLAGS $cc_cv_werror" cannam@154: AC_COMPILE_IFELSE([AC_LANG_SOURCE( cannam@154: [int some_function() { cannam@154: int a = 3; cannam@154: return (int)__builtin_expect(a, 3); cannam@154: }])], cannam@154: [cc_cv_func_expect=yes], cannam@154: [cc_cv_func_expect=no]) cannam@154: CFLAGS="$ac_save_CFLAGS" cannam@154: ]) cannam@154: cannam@154: AS_IF([test "x$cc_cv_func_expect" = "xyes"], cannam@154: [AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1, cannam@154: [Define this if the compiler supports __builtin_expect() function]) cannam@154: $1], cannam@154: [$2]) cannam@154: ]) cannam@154: cannam@154: AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [ cannam@154: AC_REQUIRE([CC_CHECK_WERROR]) cannam@154: AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported], cannam@154: [cc_cv_attribute_aligned], cannam@154: [ac_save_CFLAGS="$CFLAGS" cannam@154: CFLAGS="$CFLAGS $cc_cv_werror" cannam@154: for cc_attribute_align_try in 64 32 16 8 4 2; do cannam@154: AC_COMPILE_IFELSE([AC_LANG_SOURCE([ cannam@154: int main() { cannam@154: static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0; cannam@154: return c; cannam@154: }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break]) cannam@154: done cannam@154: CFLAGS="$ac_save_CFLAGS" cannam@154: ]) cannam@154: cannam@154: if test "x$cc_cv_attribute_aligned" != "x"; then cannam@154: AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned], cannam@154: [Define the highest alignment supported]) cannam@154: fi cannam@154: ])