Debian Codegraph @

m4/kpse-visibility.m4

raw
1 # $Id: kpse-visibility.m4 70984 2024-04-18 22:14:36Z karl $
2 # Public macros for the TeX Live (TL) tree.
3 # Copyright 2017-2024 Karl Berry <[email protected]>
4 # Copyright 2013-2014 Peter Breitenlohner <[email protected]>
5 #
6 # This file is free software; the copyright holder
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
9
10 # KPSE_COMPILER_VISIBILITY
11 # ------------------------
12 # Set up compiler flags for C and C++ to hide external symbols.
13 # This macro determines and substitutes VISIBILITY_CFLAGS for the C compiler
14 # and, if applicable, VISIBILITY_CXXFLAGS for the C++ compiler. To activate
15 # them a Makefile.am must use them, e.g., in AM_CFLAGS or AM_CXXFLAGS.
16 AC_DEFUN([KPSE_COMPILER_VISIBILITY],
17 [dnl arrange that AC_PROG_CC uses _KPSE_VISIBILITY_CFLAGS etc.
18 echo 'tldbg:[$0] called.' >&AS_MESSAGE_LOG_FD
19 AC_PROVIDE_IFELSE([AC_PROG_CC],
20 [_KPSE_VISIBILITY_CFLAGS],
21 [m4_define([AC_PROG_CC],
22 m4_defn([AC_PROG_CC])[_KPSE_VISIBILITY_CFLAGS
23 ])])
24 AC_PROVIDE_IFELSE([AC_PROG_CXX],
25 [_KPSE_VISIBILITY_CXXFLAGS],
26 [m4_define([AC_PROG_CXX],
27 m4_defn([AC_PROG_CXX])[_KPSE_VISIBILITY_CXXFLAGS
28 ])])
29 ]) # KPSE_COMPILER_VISIBILITY
30
31 _KPSE_VISIBILITY_CFLAGS
32 # ---------------------
33 # Internal subroutine.
34 # Set up compiler flags for C to hide external symbols.
35 AC_DEFUN([_KPSE_VISIBILITY_CFLAGS], [dnl
36 AC_REQUIRE([AC_PROG_CC])[]dnl
37 _KPSE_VISIBILITY_FLAGS([C], [cflags])
38 m4_define([_KPSE_VISIBILITY_CFLAGS], [])[]dnl
39 ]) # _KPSE_VISIBILITY_CFLAGS
40
41 _KPSE_VISIBILITY_CXXFLAGS
42 # -----------------------
43 # Internal subroutine.
44 # Set up compiler flags for C++ to hide external symbols.
45 AC_DEFUN([_KPSE_VISIBILITY_CXXFLAGS], [dnl
46 AC_REQUIRE([AC_PROG_CXX])[]dnl
47 _KPSE_VISIBILITY_FLAGS([C++], [cxxflags])
48 m4_define([_KPSE_VISIBILITY_CXXFLAGS], [])[]dnl
49 ]) # _KPSE_VISIBILITY_CFLAGS
50
51 _KPSE_VISIBILITY_FLAGS(LANG, TAG)
52 # -------------------------------
53 # Internal subroutine.
54 # Set up compiler flags for C or C++ to hide external symbols.
55 m4_define([_KPSE_VISIBILITY_FLAGS], [dnl
56 AC_CACHE_CHECK(AS_TR_CPP($2) [for $1 to hide external symbols],
57 [kpse_cv_visibility_$2],
58 [dnl
59 AC_LANG_PUSH([$1])
60 kpse_cv_visibility_$2=unknown
61 kpse_save_flags=$AS_TR_CPP($2)
62 AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <stdio.h>
63 extern void foo(void);
64 void foo(void){printf("foo\n");}]])])
65 # Maybe other compiler need other tests; patches needed.
66 #
67 # The idea, maybe, is to use both flags when they are supported, but
68 # old C++ compilers, as well as C, don't support
69 # -fvisibility-inlines-hidden, so test just -fvisibility=hidden too?
70 #
71 for kpse_flag in "-fvisibility=hidden -fvisibility-inlines-hidden" \
72 "-fvisibility=hidden"; do
73 if test x"$1" = xC \
74 && echo "$kpse_flag" | grep inlines-hidden >/dev/null; then
75 # C does not support this additional flag; just skip the test.
76 continue
77 fi
78 AS_TR_CPP($2)="$kpse_save_flags -Werror $kpse_flag"
79 AC_COMPILE_IFELSE([], [kpse_cv_visibility_$2=$kpse_flag; break])
80 done
81 AS_TR_CPP($2)=$kpse_save_flags
82 AC_LANG_POP([$1])
83 ])
84 AS_CASE([$kpse_cv_visibility_$2],
85 [unknown], [],
86 [AC_SUBST([VISIBILITY_]AS_TR_CPP($2), [$kpse_cv_visibility_$2])])
87 ]) # _KPSE_VISIBILITY_FLAGS