Blame buildutil/attributes.m4

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