Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / versioning.at
1 # versioning.at -- test libtool versioning           -*- Autotest -*-
2 #
3 #   Copyright (C) 2009, 2010 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
24 AT_SETUP([versioning])
25 AT_KEYWORDS([libtool])
26
27 eval "`$LIBTOOL --config | $EGREP '^(objdir|host_os)='`"
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
35 AT_DATA([liba1.c], [[
36 int a (void)
37 {
38   return 0;
39 }
40 ]])
41
42 AT_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. */
45 int internal_detail = 42;
46 int a (void)
47 {
48   return internal_detail - 42;
49 }
50 ]])
51
52 AT_DATA([liba3.c], [[
53 int a (void)
54 {
55   return 0;
56 }
57 int aa (void)
58 {
59   return 0;
60 }
61 ]])
62
63 AT_DATA([liba4.c], [[
64 int aa (void)
65 {
66   return 0;
67 }
68 ]])
69
70 AT_DATA([libb.c], [[
71 extern int a (void);
72 int b (void)
73 {
74   return a ();
75 }
76 ]])
77
78 AT_DATA([prog1.c], [[
79 extern int a (void);
80 int main (void)
81 {
82   return a ();
83 }
84 ]])
85
86 AT_DATA([prog2.c], [[
87 extern int b (void);
88 int main (void)
89 {
90   return b ();
91 }
92 ]])
93
94
95 inst=`pwd`/inst
96 libdir=$inst/lib
97 bindir=$inst/bin
98 LDFLAGS="$LDFLAGS -no-undefined"
99 mkdir $inst $libdir $bindir
100
101 for file in liba1.c liba2.c liba3.c liba4.c libb.c; do
102   $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $file
103 done
104 for file in prog1.c prog2.c; do
105   $CC $CPPFLAGS $CFLAGS -c $file
106 done
107
108 # Setup is finished here.
109
110 # Hypothesis: -version-info is ignored for convenience archives.
111 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba1.lo ]dnl
112          [-version-info 0:0:0], [], [ignore], [stderr])
113 AT_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.
117 for 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])
120 done
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'.
126 for 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])
129 done
130
131 # Hypothesis: we diagnose when AGE is higher than CURRENT.
132 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba1.lo ]dnl
133          [-version-info 1:3:2 -rpath $libdir], [1], [ignore], [stderr])
134 AT_CHECK([grep 'AGE.*is greater than' stderr], [], [ignore])
135
136 # Hypothesis: we diagnose invalid values.
137 for 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])
140 done
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
147 test_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
159 test_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
169 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba1.lo ]dnl
170          [-version-info 0:0:0 -rpath $libdir], [], [ignore], [ignore])
171 AT_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])
173 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o prog1$EXEEXT prog1.$OBJEXT ]dnl
174          [liba.la], [], [ignore], [ignore])
175 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o prog2$EXEEXT prog2.$OBJEXT ]dnl
176          [libb.la], [], [ignore], [ignore])
177 test_uninstalled
178 AT_CHECK([$LIBTOOL --mode=install cp liba.la libb.la $libdir],
179          [], [ignore], [ignore])
180 AT_CHECK([$LIBTOOL --mode=install cp prog1$EXEEXT prog2$EXEEXT $bindir],
181          [], [ignore], [ignore])
182 AT_CHECK([$LIBTOOL --mode=clean rm -f liba.la], [], [ignore], [ignore])
183 test_installed
184 AT_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.
189 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la liba2.lo ]dnl
190          [-version-info 0:1:0 -rpath $libdir], [], [ignore], [ignore])
191 test_uninstalled
192 AT_CHECK([$LIBTOOL --mode=install cp liba.la $libdir], [], [ignore], [ignore])
193 AT_CHECK([$LIBTOOL --mode=clean rm -f liba.la], [], [ignore], [ignore])
194 test_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.
206 AT_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).
209 AT_CHECK([$LIBTOOL --mode=install cp liba.la $libdir], [], [ignore], [ignore])
210 AT_CHECK([$LIBTOOL --mode=clean rm -f liba.la], [], [ignore], [ignore])
211 test_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.
224 AT_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.
228 AT_CHECK([$LIBTOOL --mode=install cp liba.la $libdir], [], [ignore], [ignore])
229 AT_CHECK([$LIBTOOL --mode=clean rm -f liba.la], [], [ignore], [ignore])
230
231 # This test does not work on AIX, not even with runtimelinking, because
232 # the linker always records the unversioned name as dependency.
233 AT_CHECK([:; case $host_os in aix*) exit 77;; esac])
234
235 test_installed
236
237
238 AT_CLEANUP