1dnl Copyright (C) 2005, 2008 Free Software Foundation, Inc.
2dnl Copyright (C) 2009 Monty Taylor
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Bruno Haible.
8
9dnl Tests whether the compiler supports the command-line option
10dnl -fvisibility=hidden and the function and variable attributes
11dnl __attribute__((__visibility__("hidden"))) and
12dnl __attribute__((__visibility__("default"))).
13dnl Does *not* test for __visibility__("protected") - which has tricky
14dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
15dnl MacOS X.
16dnl Does *not* test for __visibility__("internal") - which has processor
17dnl dependent semantics.
18dnl Does *not* test for #pragma GCC visibility push(hidden) - which is
19dnl "really only recommended for legacy code".
20dnl Set the variable CFLAG_VISIBILITY.
21dnl Defines and sets the variable HAVE_VISIBILITY.
22
23AC_DEFUN([PANDORA_VISIBILITY],
24[
25  AC_REQUIRE([AC_PROG_CC])
26  AC_REQUIRE([PANDORA_PLATFORM])
27  CFLAG_VISIBILITY=
28  HAVE_VISIBILITY=0
29  AS_IF([test -n "$GCC"],[
30    AC_MSG_CHECKING([for simple visibility declarations])
31    AC_CACHE_VAL([gl_cv_cc_visibility], [
32      gl_save_CFLAGS="$CFLAGS"
33      CFLAGS="$CFLAGS -fvisibility=hidden"
34      AC_TRY_COMPILE(
35        [extern __attribute__((__visibility__("hidden"))) int hiddenvar;
36         extern __attribute__((__visibility__("default"))) int exportedvar;
37         extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
38         extern __attribute__((__visibility__("default"))) int exportedfunc (void);],
39        [],
40        [gl_cv_cc_visibility=yes],
41        [gl_cv_cc_visibility=no])
42      CFLAGS="$gl_save_CFLAGS"])
43    AC_MSG_RESULT([$gl_cv_cc_visibility])
44    if test $gl_cv_cc_visibility = yes; then
45      CFLAG_VISIBILITY="-fvisibility=hidden"
46      HAVE_VISIBILITY=1
47    fi
48  ])
49  AS_IF([test "x$SUNCC" = "xyes"],[
50    CFLAG_VISIBILITY="-xldscope=hidden"
51    HAVE_VISIBILITY=1
52  ])
53  AC_SUBST([CFLAG_VISIBILITY])
54  AC_SUBST([HAVE_VISIBILITY])
55  AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY],
56    [Define to 1 or 0, depending whether the compiler supports simple visibility declarations.])
57])
58