github的一些开源项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.8 KiB

  1. # visibility.m4 serial 4 (gettext-0.18.2)
  2. dnl Copyright (C) 2005, 2008, 2010-2011 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. dnl Modified to fit with PCRE build environment by Cristian Rodríguez.
  21. dnl Adjusted for PCRE2 by PH
  22. AC_DEFUN([PCRE2_VISIBILITY],
  23. [
  24. AC_REQUIRE([AC_PROG_CC])
  25. VISIBILITY_CFLAGS=
  26. VISIBILITY_CXXFLAGS=
  27. HAVE_VISIBILITY=0
  28. if test -n "$GCC"; then
  29. dnl First, check whether -Werror can be added to the command line, or
  30. dnl whether it leads to an error because of some other option that the
  31. dnl user has put into $CC $CFLAGS $CPPFLAGS.
  32. AC_MSG_CHECKING([whether the -Werror option is usable])
  33. AC_CACHE_VAL([pcre2_cv_cc_vis_werror], [
  34. pcre2_save_CFLAGS="$CFLAGS"
  35. CFLAGS="$CFLAGS -Werror"
  36. AC_COMPILE_IFELSE(
  37. [AC_LANG_PROGRAM([[]], [[]])],
  38. [pcre2_cv_cc_vis_werror=yes],
  39. [pcre2_cv_cc_vis_werror=no])
  40. CFLAGS="$pcre2_save_CFLAGS"])
  41. AC_MSG_RESULT([$pcre2_cv_cc_vis_werror])
  42. dnl Now check whether visibility declarations are supported.
  43. AC_MSG_CHECKING([for simple visibility declarations])
  44. AC_CACHE_VAL([pcre2_cv_cc_visibility], [
  45. pcre2_save_CFLAGS="$CFLAGS"
  46. CFLAGS="$CFLAGS -fvisibility=hidden"
  47. dnl We use the option -Werror and a function dummyfunc, because on some
  48. dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning
  49. dnl "visibility attribute not supported in this configuration; ignored"
  50. dnl at the first function definition in every compilation unit, and we
  51. dnl don't want to use the option in this case.
  52. if test $pcre2_cv_cc_vis_werror = yes; then
  53. CFLAGS="$CFLAGS -Werror"
  54. fi
  55. AC_COMPILE_IFELSE(
  56. [AC_LANG_PROGRAM(
  57. [[extern __attribute__((__visibility__("hidden"))) int hiddenvar;
  58. extern __attribute__((__visibility__("default"))) int exportedvar;
  59. extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
  60. extern __attribute__((__visibility__("default"))) int exportedfunc (void);
  61. void dummyfunc (void) {}
  62. ]],
  63. [[]])],
  64. [pcre2_cv_cc_visibility=yes],
  65. [pcre2_cv_cc_visibility=no])
  66. CFLAGS="$pcre2_save_CFLAGS"])
  67. AC_MSG_RESULT([$pcre2_cv_cc_visibility])
  68. if test $pcre2_cv_cc_visibility = yes; then
  69. VISIBILITY_CFLAGS="-fvisibility=hidden"
  70. VISIBILITY_CXXFLAGS="-fvisibility=hidden -fvisibility-inlines-hidden"
  71. HAVE_VISIBILITY=1
  72. AC_DEFINE(PCRE2_EXPORT, [__attribute__ ((visibility ("default")))], [to make a symbol visible])
  73. else
  74. AC_DEFINE(PCRE2_EXPORT, [], [to make a symbol visible])
  75. fi
  76. else
  77. AC_DEFINE(PCRE2_EXPORT, [], [to make a symbol visible])
  78. fi
  79. AC_SUBST([VISIBILITY_CFLAGS])
  80. AC_SUBST([VISIBILITY_CXXFLAGS])
  81. AC_SUBST([HAVE_VISIBILITY])
  82. AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY],
  83. [Define to 1 if the compiler supports simple visibility declarations.])
  84. ])