pandora_visibility.m4 2.2 KB

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