]> git.ipfire.org Git - thirdparty/util-linux.git/blob - m4/ax_check_vscript.m4
Merge branch 'PR/libsmartcols-reduce-fix' of github.com:karelzak/util-linux-work
[thirdparty/util-linux.git] / m4 / ax_check_vscript.m4
1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_check_vscript.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 # AX_CHECK_VSCRIPT
8 #
9 # DESCRIPTION
10 #
11 # Check whether the linker supports version scripts. Version scripts are
12 # used when building shared libraries to bind symbols to version nodes
13 # (helping to detect incompatibilities) or to limit the visibility of
14 # non-public symbols.
15 #
16 # Output:
17 #
18 # If version scripts are supported, VSCRIPT_LDFLAGS will contain the
19 # appropriate flag to pass to the linker. On GNU systems this would
20 # typically be "-Wl,--version-script", and on Solaris it would typically
21 # be "-Wl,-M".
22 #
23 # Two Automake conditionals are also set:
24 #
25 # HAVE_VSCRIPT is true if the linker supports version scripts with
26 # entries that use simple wildcards, like "local: *".
27 #
28 # HAVE_VSCRIPT_COMPLEX is true if the linker supports version scripts with
29 # pattern matching wildcards, like "global: Java_*".
30 #
31 # On systems that do not support symbol versioning, such as Mac OS X, both
32 # conditionals will be false. They will also be false if the user passes
33 # "--disable-symvers" on the configure command line.
34 #
35 # Example:
36 #
37 # configure.ac:
38 #
39 # AX_CHECK_VSCRIPT
40 #
41 # Makefile.am:
42 #
43 # if HAVE_VSCRIPT
44 # libfoo_la_LDFLAGS += $(VSCRIPT_LDFLAGS),@srcdir@/libfoo.map
45 # endif
46 #
47 # if HAVE_VSCRIPT_COMPLEX
48 # libbar_la_LDFLAGS += $(VSCRIPT_LDFLAGS),@srcdir@/libbar.map
49 # endif
50 #
51 # LICENSE
52 #
53 # Copyright (c) 2014 Kevin Cernekee <cernekee@gmail.com>
54 #
55 # Copying and distribution of this file, with or without modification, are
56 # permitted in any medium without royalty provided the copyright notice
57 # and this notice are preserved. This file is offered as-is, without any
58 # warranty.
59
60 #serial 1
61
62 # _AX_CHECK_VSCRIPT(flag, global-sym, action-if-link-succeeds, [junk-file=no])
63 AC_DEFUN([_AX_CHECK_VSCRIPT], [
64 AC_LANG_PUSH([C])
65 ax_check_vscript_save_flags="$LDFLAGS"
66 echo "V1 { global: $2; local: *; };" > conftest.map
67 AS_IF([test x$4 = xyes], [
68 echo "{" >> conftest.map
69 ])
70 LDFLAGS="$LDFLAGS -Wl,$1,conftest.map"
71 AC_LINK_IFELSE([AC_LANG_PROGRAM([[int show, hide;]], [])], [$3])
72 LDFLAGS="$ax_check_vscript_save_flags"
73 rm -f conftest.map
74 AC_LANG_POP([C])
75 ]) dnl _AX_CHECK_VSCRIPT
76
77 AC_DEFUN([AX_CHECK_VSCRIPT], [
78
79 AC_ARG_ENABLE([symvers],
80 AS_HELP_STRING([--disable-symvers],
81 [disable library symbol versioning [default=auto]]),
82 [want_symvers=$enableval],
83 [want_symvers=yes]
84 )
85
86 AS_IF([test x$want_symvers = xyes], [
87
88 dnl First test --version-script and -M with a simple wildcard.
89
90 AC_CACHE_CHECK([linker version script flag], ax_cv_check_vscript_flag, [
91 ax_cv_check_vscript_flag=unsupported
92 _AX_CHECK_VSCRIPT([--version-script], [show], [
93 ax_cv_check_vscript_flag=--version-script
94 ])
95 AS_IF([test x$ax_cv_check_vscript_flag = xunsupported], [
96 _AX_CHECK_VSCRIPT([-M], [show], [ax_cv_check_vscript_flag=-M])
97 ])
98
99 dnl The linker may interpret -M (no argument) as "produce a load map."
100 dnl If "-M conftest.map" doesn't fail when conftest.map contains
101 dnl obvious syntax errors, assume this is the case.
102
103 AS_IF([test x$ax_cv_check_vscript_flag != xunsupported], [
104 _AX_CHECK_VSCRIPT([$ax_cv_check_vscript_flag], [show],
105 [ax_cv_check_vscript_flag=unsupported], [yes])
106 ])
107 ])
108
109 dnl If the simple wildcard worked, retest with a complex wildcard.
110
111 AS_IF([test x$ax_cv_check_vscript_flag != xunsupported], [
112 ax_check_vscript_flag=$ax_cv_check_vscript_flag
113 AC_CACHE_CHECK([if version scripts can use complex wildcards],
114 ax_cv_check_vscript_complex_wildcards, [
115 ax_cv_check_vscript_complex_wildcards=no
116 _AX_CHECK_VSCRIPT([$ax_cv_check_vscript_flag], [sh*], [
117 ax_cv_check_vscript_complex_wildcards=yes])
118 ])
119 ax_check_vscript_complex_wildcards="$ax_cv_check_vscript_complex_wildcards"
120 ], [
121 ax_check_vscript_flag=
122 ax_check_vscript_complex_wildcards=no
123 ])
124 ], [
125 AC_MSG_CHECKING([linker version script flag])
126 AC_MSG_RESULT([disabled])
127
128 ax_check_vscript_flag=
129 ax_check_vscript_complex_wildcards=no
130 ])
131
132 AS_IF([test x$ax_check_vscript_flag != x], [
133 VSCRIPT_LDFLAGS="-Wl,$ax_check_vscript_flag"
134 AC_SUBST([VSCRIPT_LDFLAGS])
135 ])
136
137 AM_CONDITIONAL([HAVE_VSCRIPT],
138 [test x$ax_check_vscript_flag != x])
139 AM_CONDITIONAL([HAVE_VSCRIPT_COMPLEX],
140 [test x$ax_check_vscript_complex_wildcards = xyes])
141
142 ]) dnl AX_CHECK_VSCRIPT