1 # link-order2.at -- test link order of deplibs -*- Autotest -*-
3 # Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
4 # Written by Ralf Wildenhues, 2006
6 # This file is part of GNU Libtool.
8 # GNU Libtool is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of
11 # the License, or (at your option) any later version.
13 # GNU Libtool is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Libtool; see the file COPYING. If not, a copy
20 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
21 # or obtained by writing to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 # link-order2.test: make sure that depdepls are added right after
26 # the libs that pull them in: necessary at least for static linking
27 # and on systems where libraries do not link against other libraries.
29 # We test by overriding one symbol from a depdepl library.
30 # Test both a libtool library and a non-libtool library (simulated
31 # by removing the .la file, and setting $shlibpath_var so it is
32 # found at runtime). In order to ensure that the depdepl is
33 # actually loaded in each case, we also use an unrelated symbol
34 # from it directly in the main program. We test for failure by
35 # reversing the link order.
36 # We test both static and shared: it should work in both cases.
37 # But for the static case to work, the two symbols in the depdepl
38 # need to be in separate object files, otherwise duplicate symbol
39 # definitions can happen.
41 # The shared case fails on AIX without runtimelinking and on Darwin.
42 # On Darwin, using shared libs this only works without -no-undefined
43 # and only with MACOS_DEPLOYMENT_TARGET 10.2 and earlier
44 # (in that case $allow_undefined_flag contains -flat_namespace).
46 AT_SETUP([Link order of deplibs])
47 AT_KEYWORDS([libtool])
48 AT_KEYWORDS([interactive])dnl running 'wrong' may cause a popup window.
50 eval `$LIBTOOL --config | $EGREP '^(shlibpath_var|allow_undefined_flag)='`
52 undefined_setting=-no-undefined
54 case $host_os,$LDFLAGS,$allow_undefined_flag in
56 aix*) shared_fails=yes ;;
57 darwin*,*,*-flat_namespace*) undefined_setting= ;;
58 darwin*,*,*) shared_fails=yes ;;
65 mkdir bin lib inst inst/bin inst/lib
66 LDFLAGS="$LDFLAGS $undefined_setting -L$deflibdir"
69 int a (void) { return 1; }
73 int a (void) { return 0; }
78 int b (void) { return a (); }
87 return !(a () + b () == 0);
91 for file in a0 a1 b; do
92 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $file.c
94 $CC $CPPFLAGS $CFLAGS -c main.c
96 # Build an old, installed library.
97 $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS $static -o liba0.la a0.lo -rpath $deflibdir
98 $LIBTOOL --mode=install cp liba0.la $deflibdir/liba0.la
99 $LIBTOOL --mode=clean rm -f liba0.la
101 for type_of_depdepl in libtool non-libtool; do
102 echo "type of depdepl: $type_of_depdepl"
103 if test $type_of_depdepl = non-libtool; then
104 # Simulate a non-Libtool system library.
105 rm $deflibdir/liba1.la
107 if test "$shlibpath_var" = PATH; then
111 eval test -n \"\$$shlibpath_var\" && sep=:
112 eval $shlibpath_var='$addpath$sep$'$shlibpath_var
113 export $shlibpath_var
115 for static in '' -static-libtool-libs; do
116 case `$LIBTOOL --features` in
117 *disable\ static\ libraries*) test "$static" = '' || continue;;
119 test "$type_of_depdepl,$static" = "non-libtool,-static-libtool-libs" &&
121 $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS $static -o liba1.la a1.lo -rpath $libdir
122 $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS $static -o libb.la b.lo liba1.la -rpath $libdir
123 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS $static -o main$EXEEXT main.$OBJEXT libb.la -la0],
124 [], [ignore], [ignore])
125 LT_AT_EXEC_CHECK([./main])
126 # Now test that if we reverse the link order, the program fails.
127 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS $static -o wrong$EXEEXT main.$OBJEXT -la0 libb.la],
128 [], [ignore], [ignore])
129 if test $shared_fails,$static != yes,; then
130 LT_AT_EXEC_CHECK([./wrong], [1], [], [ignore], [|| (exit 1)])
133 $LIBTOOL --mode=install cp liba1.la $libdir/liba1.la
134 $LIBTOOL --mode=install cp libb.la $libdir/libb.la
135 $LIBTOOL --mode=install cp main$EXEEXT $bindir/main$EXEEXT
136 $LIBTOOL --mode=install cp wrong$EXEEXT $bindir/wrong$EXEEXT
137 $LIBTOOL --mode=clean rm -f liba1.la libb.la
138 LT_AT_EXEC_CHECK([$bindir/main])
139 if test $shared_fails,$static != yes,; then
140 LT_AT_EXEC_CHECK([$bindir/wrong], [1], [], [ignore], [|| (exit 1)])
145 AT_CHECK([test $shared_fails = no || (exit 77)])
147 # Now the converse: if both the program and the library need libm, then
148 # it needs to be sorted last. (TODO)