Blame m4macros/attributes.m4

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