Blame m4/visibility.m4

Packit 575503
# visibility.m4 serial 5 (gettext-0.18.2)
Packit 575503
dnl Copyright (C) 2005, 2008, 2010-2014 Free Software Foundation, Inc.
Packit 575503
dnl This file is free software; the Free Software Foundation
Packit 575503
dnl gives unlimited permission to copy and/or distribute it,
Packit 575503
dnl with or without modifications, as long as this notice is preserved.
Packit 575503
Packit 575503
dnl From Bruno Haible.
Packit 575503
Packit 575503
dnl Tests whether the compiler supports the command-line option
Packit 575503
dnl -fvisibility=hidden and the function and variable attributes
Packit 575503
dnl __attribute__((__visibility__("hidden"))) and
Packit 575503
dnl __attribute__((__visibility__("default"))).
Packit 575503
dnl Does *not* test for __visibility__("protected") - which has tricky
Packit 575503
dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
Packit 575503
dnl Mac OS X.
Packit 575503
dnl Does *not* test for __visibility__("internal") - which has processor
Packit 575503
dnl dependent semantics.
Packit 575503
dnl Does *not* test for #pragma GCC visibility push(hidden) - which is
Packit 575503
dnl "really only recommended for legacy code".
Packit 575503
dnl Set the variable CFLAG_VISIBILITY.
Packit 575503
dnl Defines and sets the variable HAVE_VISIBILITY.
Packit 575503
Packit 575503
AC_DEFUN([gl_VISIBILITY],
Packit 575503
[
Packit 575503
  AC_REQUIRE([AC_PROG_CC])
Packit 575503
  CFLAG_VISIBILITY=
Packit 575503
  HAVE_VISIBILITY=0
Packit 575503
  if test -n "$GCC"; then
Packit 575503
    dnl First, check whether -Werror can be added to the command line, or
Packit 575503
    dnl whether it leads to an error because of some other option that the
Packit 575503
    dnl user has put into $CC $CFLAGS $CPPFLAGS.
Packit 575503
    AC_MSG_CHECKING([whether the -Werror option is usable])
Packit 575503
    AC_CACHE_VAL([gl_cv_cc_vis_werror], [
Packit 575503
      gl_save_CFLAGS="$CFLAGS"
Packit 575503
      CFLAGS="$CFLAGS -Werror"
Packit 575503
      AC_COMPILE_IFELSE(
Packit 575503
        [AC_LANG_PROGRAM([[]], [[]])],
Packit 575503
        [gl_cv_cc_vis_werror=yes],
Packit 575503
        [gl_cv_cc_vis_werror=no])
Packit 575503
      CFLAGS="$gl_save_CFLAGS"])
Packit 575503
    AC_MSG_RESULT([$gl_cv_cc_vis_werror])
Packit 575503
    dnl Now check whether visibility declarations are supported.
Packit 575503
    AC_MSG_CHECKING([for simple visibility declarations])
Packit 575503
    AC_CACHE_VAL([gl_cv_cc_visibility], [
Packit 575503
      gl_save_CFLAGS="$CFLAGS"
Packit 575503
      CFLAGS="$CFLAGS -fvisibility=hidden"
Packit 575503
      dnl We use the option -Werror and a function dummyfunc, because on some
Packit 575503
      dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning
Packit 575503
      dnl "visibility attribute not supported in this configuration; ignored"
Packit 575503
      dnl at the first function definition in every compilation unit, and we
Packit 575503
      dnl don't want to use the option in this case.
Packit 575503
      if test $gl_cv_cc_vis_werror = yes; then
Packit 575503
        CFLAGS="$CFLAGS -Werror"
Packit 575503
      fi
Packit 575503
      AC_COMPILE_IFELSE(
Packit 575503
        [AC_LANG_PROGRAM(
Packit 575503
           [[extern __attribute__((__visibility__("hidden"))) int hiddenvar;
Packit 575503
             extern __attribute__((__visibility__("default"))) int exportedvar;
Packit 575503
             extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
Packit 575503
             extern __attribute__((__visibility__("default"))) int exportedfunc (void);
Packit 575503
             void dummyfunc (void) {}
Packit 575503
           ]],
Packit 575503
           [[]])],
Packit 575503
        [gl_cv_cc_visibility=yes],
Packit 575503
        [gl_cv_cc_visibility=no])
Packit 575503
      CFLAGS="$gl_save_CFLAGS"])
Packit 575503
    AC_MSG_RESULT([$gl_cv_cc_visibility])
Packit 575503
    if test $gl_cv_cc_visibility = yes; then
Packit 575503
      CFLAG_VISIBILITY="-fvisibility=hidden"
Packit 575503
      HAVE_VISIBILITY=1
Packit 575503
    fi
Packit 575503
  fi
Packit 575503
  AC_SUBST([CFLAG_VISIBILITY])
Packit 575503
  AC_SUBST([HAVE_VISIBILITY])
Packit 575503
  AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY],
Packit 575503
    [Define to 1 or 0, depending whether the compiler supports simple visibility declarations.])
Packit 575503
])