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