blob: 480f2eefedfcd9fe75d8a25f7310011a0eb1eb8d [file] [log] [blame]
Nick Kralevichf73ff172014-09-27 12:41:49 -07001# 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.
Janis Danisevskis112c9cc2016-03-31 13:35:25 +010024dnl Adjusted for PCRE2 by PH
Nick Kralevichf73ff172014-09-27 12:41:49 -070025
Janis Danisevskis112c9cc2016-03-31 13:35:25 +010026AC_DEFUN([PCRE2_VISIBILITY],
Nick Kralevichf73ff172014-09-27 12:41:49 -070027[
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])
Janis Danisevskis112c9cc2016-03-31 13:35:25 +010037 AC_CACHE_VAL([pcre2_cv_cc_vis_werror], [
38 pcre2_save_CFLAGS="$CFLAGS"
Nick Kralevichf73ff172014-09-27 12:41:49 -070039 CFLAGS="$CFLAGS -Werror"
40 AC_COMPILE_IFELSE(
41 [AC_LANG_PROGRAM([[]], [[]])],
Janis Danisevskis112c9cc2016-03-31 13:35:25 +010042 [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])
Nick Kralevichf73ff172014-09-27 12:41:49 -070046 dnl Now check whether visibility declarations are supported.
47 AC_MSG_CHECKING([for simple visibility declarations])
Janis Danisevskis112c9cc2016-03-31 13:35:25 +010048 AC_CACHE_VAL([pcre2_cv_cc_visibility], [
49 pcre2_save_CFLAGS="$CFLAGS"
Nick Kralevichf73ff172014-09-27 12:41:49 -070050 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.
Janis Danisevskis112c9cc2016-03-31 13:35:25 +010056 if test $pcre2_cv_cc_vis_werror = yes; then
Nick Kralevichf73ff172014-09-27 12:41:49 -070057 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 [[]])],
Janis Danisevskis112c9cc2016-03-31 13:35:25 +010068 [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
Nick Kralevichf73ff172014-09-27 12:41:49 -070073 VISIBILITY_CFLAGS="-fvisibility=hidden"
74 VISIBILITY_CXXFLAGS="-fvisibility=hidden -fvisibility-inlines-hidden"
75 HAVE_VISIBILITY=1
Janis Danisevskis112c9cc2016-03-31 13:35:25 +010076 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])
Nick Kralevichf73ff172014-09-27 12:41:49 -070080 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])