Blame m4/attributes.m4

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