Home | History | Annotate | Download | only in m4
      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 Rodrguez.
     24 dnl Adjusted for PCRE2 by PH
     25 
     26 AC_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