Blame m4/attributes.m4

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