1# versioning.at -- test libtool versioning           -*- Autotest -*-
2#
3#   Copyright (C) 2009-2015 Free Software Foundation, Inc.
4#
5#   This file is part of GNU Libtool.
6#
7# GNU Libtool is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of
10# the License, or (at your option) any later version.
11#
12# GNU Libtool is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with GNU Libtool; see the file COPYING.  If not, a copy
19# can be downloaded from  http://www.gnu.org/licenses/gpl.html,
20# or obtained by writing to the Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22####
23
24AT_SETUP([versioning])
25AT_KEYWORDS([libtool])
26
27eval "`$LIBTOOL --config | $EGREP '^(objdir|host_os|shared_archive_member_spec)='`"
28
29# Setup some library and program sources:
30# a library (a1), a new revision (a2), a compatible update (a3),
31# an incompatible update (a4).
32# Another library (libb) using liba, and a couple of programs,
33# using liba directly and indirectly through libb.
34
35AT_DATA([liba1.c], [[
36int a (void)
37{
38  return 0;
39}
40]])
41
42AT_DATA([liba2.c], [[
43/* The internal detail should be static.  It isn't static in this test,
44   so we can later find out that it's this revision of the library. */
45int internal_detail = 42;
46int a (void)
47{
48  return internal_detail - 42;
49}
50]])
51
52AT_DATA([liba3.c], [[
53int a (void)
54{
55  return 0;
56}
57int aa (void)
58{
59  return 0;
60}
61]])
62
63AT_DATA([liba4.c], [[
64int aa (void)
65{
66  return 0;
67}
68]])
69
70AT_DATA([libb.c], [[
71extern int a (void);
72int b (void)
73{
74  return a ();
75}
76]])
77
78AT_DATA([prog1.c], [[
79extern int a (void);
80int main (void)
81{
82  return a ();
83}
84]])
85
86AT_DATA([prog2.c], [[
87extern int b (void);
88int main (void)
89{
90  return b ();
91}
92]])
93
94
95inst=`pwd`/inst
96libdir=$inst/lib
97bindir=$inst/bin
98LDFLAGS="$LDFLAGS -no-undefined"
99mkdir $inst $libdir $bindir
100
101for file in liba1.c liba2.c liba3.c liba4.c libb.c; do
102  $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $file
103done
104for file in prog1.c prog2.c; do
105  $CC $CPPFLAGS $CFLAGS -c $file
106done
107
108# Setup is finished here.
109
110# Hypothesis: -version-info is ignored for convenience archives.
111AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba1.lo ]dnl
112	 [-version-info 0:0:0], [], [ignore], [stderr])
113AT_CHECK([$GREP 'version-info.*ignored for convenience' stderr], [], [ignore])
114
115# Hypothesis: the deprecated -version-number works.
116# Be sure not to use zero here, it's not portable.
117for version_number in 1 1:1 2:1 1:1:1 3:2:1; do
118  AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba1.lo ]dnl
119	   [-version-number $version_number -rpath $libdir], [], [ignore], [ignore])
120done
121
122# Hypothesis: -version-info can be passed kinds of values, esp. zero ones
123# and large ones.
124# TODO: check something like 1001:2419:189 after fixing issues
125# for 'version_type's of 'irix', 'nonstopux', or 'osf'.
126for version_info in 1 1:2 0:0:0 1:1:1 13:241:7; do
127  AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba1.lo ]dnl
128	   [-version-info $version_info -rpath $libdir], [], [ignore], [ignore])
129done
130
131# Hypothesis: we diagnose when AGE is higher than CURRENT.
132AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba1.lo ]dnl
133	 [-version-info 1:3:2 -rpath $libdir], [1], [ignore], [stderr])
134AT_CHECK([$GREP 'AGE.*is greater than' stderr], [], [ignore])
135
136# Hypothesis: we diagnose invalid values.
137for version_info in 1:2:3:4 -1 0:-1 0:0:-1; do
138  AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba1.lo ]dnl
139	   [-version-info $version_info -rpath $libdir], [1], [ignore], [ignore])
140done
141
142
143# Now, create an original version of the library and associated users.
144# This setup will be reused for further hypotheses below, and these
145# functions will be used to test working programs.
146
147test_uninstalled ()
148{
149  # temporarily move installed libraries out of the way in order to avoid
150  # skewing test results:
151  mv $libdir temp-lib
152  mv $bindir temp-bin
153  LT_AT_EXEC_CHECK([./prog1])
154  LT_AT_EXEC_CHECK([./prog2])
155  mv temp-lib $libdir
156  mv temp-bin $bindir
157}
158
159test_installed ()
160{
161  # temporarily move uninstalled libraries out of the way in order to avoid
162  # skewing test results:
163  mv $objdir temp
164  LT_AT_EXEC_CHECK([$bindir/prog1])
165  LT_AT_EXEC_CHECK([$bindir/prog2])
166  mv temp $objdir
167}
168
169AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba1.lo ]dnl
170	 [-version-info 0:0:0 -rpath $libdir], [], [ignore], [ignore])
171AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libb.la libb.lo liba.la ]dnl
172	 [-version-info 0:0:0 -rpath $libdir], [], [ignore], [ignore])
173AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o prog1$EXEEXT prog1.$OBJEXT ]dnl
174	 [liba.la], [], [ignore], [ignore])
175AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o prog2$EXEEXT prog2.$OBJEXT ]dnl
176	 [libb.la], [], [ignore], [ignore])
177test_uninstalled
178AT_CHECK([$LIBTOOL --mode=install cp liba.la libb.la $libdir],
179	 [], [ignore], [ignore])
180AT_CHECK([$LIBTOOL --mode=install cp prog1$EXEEXT prog2$EXEEXT $bindir],
181	 [], [ignore], [ignore])
182AT_CHECK([$LIBTOOL --mode=clean rm -f liba.la], [], [ignore], [ignore])
183test_installed
184AT_CHECK([$LIBTOOL --mode=uninstall rm -f $libdir/liba.la], [], [ignore], [ignore])
185
186
187# Hypothesis: library revision updates do not require (uninstalled
188# nor installed) programs or libraries to be relinked.
189AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba2.lo ]dnl
190	 [-version-info 0:1:0 -rpath $libdir], [], [ignore], [ignore])
191test_uninstalled
192AT_CHECK([$LIBTOOL --mode=install cp liba.la $libdir], [], [ignore], [ignore])
193AT_CHECK([$LIBTOOL --mode=clean rm -f liba.la], [], [ignore], [ignore])
194test_installed
195# do not uninstall here: the library may be reused in the next test.
196
197# Hypothesis: backward compatible library updates do not require
198# (uninstalled nor installed) programs or libraries to be relinked.
199# This can have one of several reasons:
200# - the soname is the difference between $current and $age, thus
201#   unchanged; in this case, the newly installed library will be used,
202# - the soname is only $current, or we are linking statically, in which case
203#   the old installed library code will be used,
204# - the numbers are not encoded at all, in which case the newly installed
205#   library will be used.
206AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba3.lo ]dnl
207	 [-version-info 1:0:1 -rpath $libdir], [], [ignore], [ignore])
208# Do not test the uninstalled program, it may be broken (in the second case).
209AT_CHECK([$LIBTOOL --mode=install cp liba.la $libdir], [], [ignore], [ignore])
210AT_CHECK([$LIBTOOL --mode=clean rm -f liba.la], [], [ignore], [ignore])
211test_installed
212# do not uninstall here: the library may be reused in the next test.
213
214
215# Hypothesis: with shared libraries, incompatible library updates
216# will not cause old installed programs or libraries (linked against the old
217# library version) to break.
218# This can have one of several reasons:
219# - the soname has changed, so the old installed library will still be
220#   available,
221# - we are linking statically, so the old library code will still be used.
222# In order to be sure we are still linking against the old library version,
223# we must ensure that libb is not relinked, so we must not reinstall libb here.
224AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba4.lo ]dnl
225	 [-version-info 2:0:0 -rpath $libdir], [], [ignore], [ignore])
226# We do not guarantee that old versions of an uninstalled library are still
227# available, so test_uninstalled will not necessarily work here any more.
228AT_CHECK([$LIBTOOL --mode=install cp liba.la $libdir], [], [ignore], [ignore])
229AT_CHECK([$LIBTOOL --mode=clean rm -f liba.la], [], [ignore], [ignore])
230
231# On AIX, this test only works when the 'aix-soname' feature is enabled and
232# active, which is reflected in shared_archive_member_spec being set and LDFLAGS
233# containing -brtl. Otherwise, even with runtime linking, the linker always
234# records the unversioned name as dependency.
235AT_CHECK([:; case $host_os,$shared_archive_member_spec,$LDFLAGS in
236aix*,,*) exit 77 ;;
237aix*,*,*-brtl*) ;;
238aix*,*) exit 77 ;;
239esac])
240
241test_installed
242
243
244AT_CLEANUP
245