Blame m4/visibility.m4

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