xref: /aosp_15_r20/external/pcre/m4/pcre2_visibility.m4 (revision 22dc650d8ae982c6770746019a6f94af92b0f024)
1*22dc650dSSadaf Ebrahimi# visibility.m4 serial 4 (gettext-0.18.2)
2*22dc650dSSadaf Ebrahimidnl Copyright (C) 2005, 2008, 2010-2011 Free Software Foundation, Inc.
3*22dc650dSSadaf Ebrahimidnl This file is free software; the Free Software Foundation
4*22dc650dSSadaf Ebrahimidnl gives unlimited permission to copy and/or distribute it,
5*22dc650dSSadaf Ebrahimidnl with or without modifications, as long as this notice is preserved.
6*22dc650dSSadaf Ebrahimi
7*22dc650dSSadaf Ebrahimidnl From Bruno Haible.
8*22dc650dSSadaf Ebrahimi
9*22dc650dSSadaf Ebrahimidnl Tests whether the compiler supports the command-line option
10*22dc650dSSadaf Ebrahimidnl -fvisibility=hidden and the function and variable attributes
11*22dc650dSSadaf Ebrahimidnl __attribute__((__visibility__("hidden"))) and
12*22dc650dSSadaf Ebrahimidnl __attribute__((__visibility__("default"))).
13*22dc650dSSadaf Ebrahimidnl Does *not* test for __visibility__("protected") - which has tricky
14*22dc650dSSadaf Ebrahimidnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
15*22dc650dSSadaf Ebrahimidnl MacOS X.
16*22dc650dSSadaf Ebrahimidnl Does *not* test for __visibility__("internal") - which has processor
17*22dc650dSSadaf Ebrahimidnl dependent semantics.
18*22dc650dSSadaf Ebrahimidnl Does *not* test for #pragma GCC visibility push(hidden) - which is
19*22dc650dSSadaf Ebrahimidnl "really only recommended for legacy code".
20*22dc650dSSadaf Ebrahimidnl Set the variable CFLAG_VISIBILITY.
21*22dc650dSSadaf Ebrahimidnl Defines and sets the variable HAVE_VISIBILITY.
22*22dc650dSSadaf Ebrahimi
23*22dc650dSSadaf Ebrahimidnl Modified to fit with PCRE build environment by Cristian Rodríguez.
24*22dc650dSSadaf Ebrahimidnl Adjusted for PCRE2 by PH
25*22dc650dSSadaf Ebrahimi
26*22dc650dSSadaf EbrahimiAC_DEFUN([PCRE2_VISIBILITY],
27*22dc650dSSadaf Ebrahimi[
28*22dc650dSSadaf Ebrahimi  AC_REQUIRE([AC_PROG_CC])
29*22dc650dSSadaf Ebrahimi  VISIBILITY_CFLAGS=
30*22dc650dSSadaf Ebrahimi  VISIBILITY_CXXFLAGS=
31*22dc650dSSadaf Ebrahimi  HAVE_VISIBILITY=0
32*22dc650dSSadaf Ebrahimi  if test -n "$GCC"; then
33*22dc650dSSadaf Ebrahimi    dnl First, check whether -Werror can be added to the command line, or
34*22dc650dSSadaf Ebrahimi    dnl whether it leads to an error because of some other option that the
35*22dc650dSSadaf Ebrahimi    dnl user has put into $CC $CFLAGS $CPPFLAGS.
36*22dc650dSSadaf Ebrahimi    AC_MSG_CHECKING([whether the -Werror option is usable])
37*22dc650dSSadaf Ebrahimi    AC_CACHE_VAL([pcre2_cv_cc_vis_werror], [
38*22dc650dSSadaf Ebrahimi      pcre2_save_CFLAGS="$CFLAGS"
39*22dc650dSSadaf Ebrahimi      CFLAGS="$CFLAGS -Werror"
40*22dc650dSSadaf Ebrahimi      AC_COMPILE_IFELSE(
41*22dc650dSSadaf Ebrahimi        [AC_LANG_PROGRAM([[]], [[]])],
42*22dc650dSSadaf Ebrahimi        [pcre2_cv_cc_vis_werror=yes],
43*22dc650dSSadaf Ebrahimi        [pcre2_cv_cc_vis_werror=no])
44*22dc650dSSadaf Ebrahimi      CFLAGS="$pcre2_save_CFLAGS"])
45*22dc650dSSadaf Ebrahimi    AC_MSG_RESULT([$pcre2_cv_cc_vis_werror])
46*22dc650dSSadaf Ebrahimi    dnl Now check whether visibility declarations are supported.
47*22dc650dSSadaf Ebrahimi    AC_MSG_CHECKING([for simple visibility declarations])
48*22dc650dSSadaf Ebrahimi    AC_CACHE_VAL([pcre2_cv_cc_visibility], [
49*22dc650dSSadaf Ebrahimi      pcre2_save_CFLAGS="$CFLAGS"
50*22dc650dSSadaf Ebrahimi      CFLAGS="$CFLAGS -fvisibility=hidden"
51*22dc650dSSadaf Ebrahimi      dnl We use the option -Werror and a function dummyfunc, because on some
52*22dc650dSSadaf Ebrahimi      dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning
53*22dc650dSSadaf Ebrahimi      dnl "visibility attribute not supported in this configuration; ignored"
54*22dc650dSSadaf Ebrahimi      dnl at the first function definition in every compilation unit, and we
55*22dc650dSSadaf Ebrahimi      dnl don't want to use the option in this case.
56*22dc650dSSadaf Ebrahimi      if test $pcre2_cv_cc_vis_werror = yes; then
57*22dc650dSSadaf Ebrahimi        CFLAGS="$CFLAGS -Werror"
58*22dc650dSSadaf Ebrahimi      fi
59*22dc650dSSadaf Ebrahimi      AC_COMPILE_IFELSE(
60*22dc650dSSadaf Ebrahimi        [AC_LANG_PROGRAM(
61*22dc650dSSadaf Ebrahimi           [[extern __attribute__((__visibility__("hidden"))) int hiddenvar;
62*22dc650dSSadaf Ebrahimi             extern __attribute__((__visibility__("default"))) int exportedvar;
63*22dc650dSSadaf Ebrahimi             extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
64*22dc650dSSadaf Ebrahimi             extern __attribute__((__visibility__("default"))) int exportedfunc (void);
65*22dc650dSSadaf Ebrahimi             void dummyfunc (void) {}
66*22dc650dSSadaf Ebrahimi           ]],
67*22dc650dSSadaf Ebrahimi           [[]])],
68*22dc650dSSadaf Ebrahimi        [pcre2_cv_cc_visibility=yes],
69*22dc650dSSadaf Ebrahimi        [pcre2_cv_cc_visibility=no])
70*22dc650dSSadaf Ebrahimi      CFLAGS="$pcre2_save_CFLAGS"])
71*22dc650dSSadaf Ebrahimi    AC_MSG_RESULT([$pcre2_cv_cc_visibility])
72*22dc650dSSadaf Ebrahimi    if test $pcre2_cv_cc_visibility = yes; then
73*22dc650dSSadaf Ebrahimi      VISIBILITY_CFLAGS="-fvisibility=hidden"
74*22dc650dSSadaf Ebrahimi      VISIBILITY_CXXFLAGS="-fvisibility=hidden -fvisibility-inlines-hidden"
75*22dc650dSSadaf Ebrahimi      HAVE_VISIBILITY=1
76*22dc650dSSadaf Ebrahimi      AC_DEFINE(PCRE2_EXPORT, [__attribute__ ((visibility ("default")))], [to make a symbol visible])
77*22dc650dSSadaf Ebrahimi    else
78*22dc650dSSadaf Ebrahimi      AC_DEFINE(PCRE2_EXPORT, [], [to make a symbol visible])
79*22dc650dSSadaf Ebrahimi    fi
80*22dc650dSSadaf Ebrahimi  else
81*22dc650dSSadaf Ebrahimi    AC_DEFINE(PCRE2_EXPORT, [], [to make a symbol visible])
82*22dc650dSSadaf Ebrahimi  fi
83*22dc650dSSadaf Ebrahimi  AC_SUBST([VISIBILITY_CFLAGS])
84*22dc650dSSadaf Ebrahimi  AC_SUBST([VISIBILITY_CXXFLAGS])
85*22dc650dSSadaf Ebrahimi  AC_SUBST([HAVE_VISIBILITY])
86*22dc650dSSadaf Ebrahimi  AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY],
87*22dc650dSSadaf Ebrahimi    [Define to 1 if the compiler supports simple visibility declarations.])
88*22dc650dSSadaf Ebrahimi])
89