visibility.m4 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # visibility.m4 serial 1 (gettext-0.15)
  2. dnl Copyright (C) 2005 Free Software Foundation, Inc.
  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([gl_VISIBILITY],
  21. [
  22. AC_REQUIRE([AC_PROG_CC])
  23. CFLAG_VISIBILITY=
  24. HAVE_VISIBILITY=0
  25. if test -n "$GCC"; then
  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. fi
  45. AC_SUBST([CFLAG_VISIBILITY])
  46. AC_SUBST([HAVE_VISIBILITY])
  47. AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY],
  48. [Define to 1 or 0, depending whether the compiler supports simple visibility declarations.])
  49. ])