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