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