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