Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 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 | |
| 7 | dnl From Bruno Haible. |
| 8 | |
| 9 | dnl Tests whether the compiler supports the command-line option |
| 10 | dnl -fvisibility=hidden and the function and variable attributes |
| 11 | dnl __attribute__((__visibility__("hidden"))) and |
| 12 | dnl __attribute__((__visibility__("default"))). |
| 13 | dnl Does *not* test for __visibility__("protected") - which has tricky |
| 14 | dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on |
| 15 | dnl MacOS X. |
| 16 | dnl Does *not* test for __visibility__("internal") - which has processor |
| 17 | dnl dependent semantics. |
| 18 | dnl Does *not* test for #pragma GCC visibility push(hidden) - which is |
| 19 | dnl "really only recommended for legacy code". |
| 20 | dnl Set the variable CFLAG_VISIBILITY. |
| 21 | dnl Defines and sets the variable HAVE_VISIBILITY. |
| 22 | |
| 23 | dnl Modified to fit with PCRE build environment by Cristian Rodríguez. |
Janis Danisevskis | 112c9cc | 2016-03-31 13:35:25 +0100 | [diff] [blame^] | 24 | dnl Adjusted for PCRE2 by PH |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 25 | |
Janis Danisevskis | 112c9cc | 2016-03-31 13:35:25 +0100 | [diff] [blame^] | 26 | AC_DEFUN([PCRE2_VISIBILITY], |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 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]) |
Janis Danisevskis | 112c9cc | 2016-03-31 13:35:25 +0100 | [diff] [blame^] | 37 | AC_CACHE_VAL([pcre2_cv_cc_vis_werror], [ |
| 38 | pcre2_save_CFLAGS="$CFLAGS" |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 39 | CFLAGS="$CFLAGS -Werror" |
| 40 | AC_COMPILE_IFELSE( |
| 41 | [AC_LANG_PROGRAM([[]], [[]])], |
Janis Danisevskis | 112c9cc | 2016-03-31 13:35:25 +0100 | [diff] [blame^] | 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]) |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 46 | dnl Now check whether visibility declarations are supported. |
| 47 | AC_MSG_CHECKING([for simple visibility declarations]) |
Janis Danisevskis | 112c9cc | 2016-03-31 13:35:25 +0100 | [diff] [blame^] | 48 | AC_CACHE_VAL([pcre2_cv_cc_visibility], [ |
| 49 | pcre2_save_CFLAGS="$CFLAGS" |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 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. |
Janis Danisevskis | 112c9cc | 2016-03-31 13:35:25 +0100 | [diff] [blame^] | 56 | if test $pcre2_cv_cc_vis_werror = yes; then |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 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 | [[]])], |
Janis Danisevskis | 112c9cc | 2016-03-31 13:35:25 +0100 | [diff] [blame^] | 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 |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 73 | VISIBILITY_CFLAGS="-fvisibility=hidden" |
| 74 | VISIBILITY_CXXFLAGS="-fvisibility=hidden -fvisibility-inlines-hidden" |
| 75 | HAVE_VISIBILITY=1 |
Janis Danisevskis | 112c9cc | 2016-03-31 13:35:25 +0100 | [diff] [blame^] | 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]) |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 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 | ]) |