ltmain.in: Use func_warning for all warnings
[libtool.git] / tests / link-order2.at
blobd55bb61fd35c8c64bfe36ca0da8a1bf5141142f5
1 # link-order2.at -- test link order of deplibs                -*- Autotest -*-
3 #   Copyright (C) 2006-2008, 2011-2019, 2021-2024 Free Software
4 #   Foundation, Inc.
5 #   Written by Ralf Wildenhues, 2006
7 #   This file is part of GNU Libtool.
9 # GNU Libtool is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of
12 # the License, or (at your option) any later version.
14 # GNU Libtool is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GNU Libtool; see the file COPYING.  If not, a copy
21 # can be downloaded from  http://www.gnu.org/licenses/gpl.html,
22 # or obtained by writing to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 ####
26 # link-order2.test: make sure that depdepls are added right after
27 # the libs that pull them in: necessary at least for static linking
28 # and on systems where libraries do not link against other libraries.
30 # We test by overriding one symbol from a depdepl library.
31 # Test both a libtool library and a non-libtool library (simulated
32 # by removing the .la file, and setting $shlibpath_var so it is
33 # found at runtime).  In order to ensure that the depdepl is
34 # actually loaded in each case, we also use an unrelated symbol
35 # from it directly in the main program.  We test for failure by
36 # reversing the link order.
37 # We test both static and shared: it should work in both cases.
38 # But for the static case to work, the two symbols in the depdepl
39 # need to be in separate object files, otherwise duplicate symbol
40 # definitions can happen.
42 # The shared case fails on AIX without runtimelinking and on Darwin.
43 # On Darwin, using shared libs this only works without -no-undefined
44 # and only with MACOS_DEPLOYMENT_TARGET 10.2 and earlier
45 # (in that case $allow_undefined_flag contains -flat_namespace).
47 AT_SETUP([Link order of deplibs])
48 AT_KEYWORDS([libtool])
49 AT_KEYWORDS([interactive])dnl running 'wrong' may cause a popup window.
51 eval `$LIBTOOL --config | $EGREP '^(shlibpath_var|allow_undefined_flag)='`
53 undefined_setting=-no-undefined
54 shared_fails=no
55 case $host_os,$LDFLAGS,$allow_undefined_flag in
56 aix*,*-brtl*,*) ;;
57 aix*) shared_fails=yes ;;
58 darwin*,*,*-flat_namespace*) undefined_setting= ;;
59 darwin*,*,*) shared_fails=yes ;;
60 esac
62 deflibdir=`pwd`/lib
63 defbindir=`pwd`/lib
64 libdir=`pwd`/inst/lib
65 bindir=`pwd`/inst/bin
66 mkdir bin lib inst inst/bin inst/lib
67 LDFLAGS="$LDFLAGS $undefined_setting -L$deflibdir"
69 cat >a0.c <<\EOF
70 int a (void) { return 1; }
71 EOF
73 cat >a1.c <<\EOF
74 int a (void) { return 0; }
75 EOF
77 cat >b.c <<\EOF
78 int a (void);
79 int b (void) { return a (); }
80 EOF
82 cat >main.c <<\EOF
83 #include <stdlib.h>
84 extern int a (void);
85 extern int b (void);
86 int main (void)
88   return !(a () + b () == 0);
90 EOF
92 for file in a0 a1 b; do
93   $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $file.c
94 done
95 $CC $CPPFLAGS $CFLAGS -c main.c
97 # Build an old, installed library.
98 $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS $static -o liba0.la a0.lo -rpath $deflibdir
99 $LIBTOOL --mode=install cp liba0.la $deflibdir/liba0.la
100 $LIBTOOL --mode=clean rm -f liba0.la
102 for type_of_depdepl in libtool non-libtool; do
103   echo "type of depdepl: $type_of_depdepl"
104   if test non-libtool = "$type_of_depdepl"; then
105     # Simulate a non-Libtool system library.
106     rm $deflibdir/liba1.la
107     addpath=$deflibdir
108     if test PATH = "$shlibpath_var"; then
109       addpath=$defbindir
110     fi
111     sep=
112     eval test -n \"\$$shlibpath_var\" && sep=:
113     eval $shlibpath_var='$addpath$sep$'$shlibpath_var
114     export $shlibpath_var
115   fi
116   for static in '' -static-libtool-libs; do
117     case `$LIBTOOL --features` in
118     *disable\ static\ libraries*) test -z "$static" || continue;;
119     esac
120     test non-libtool,-static-libtool-libs = "$type_of_depdepl,$static" &&
121        static=-all-static
122     $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS $static -o liba1.la a1.lo -rpath $libdir
123     $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS $static -o libb.la b.lo liba1.la -rpath $libdir
124     AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS $static -o main$EXEEXT main.$OBJEXT libb.la -la0],
125              [], [ignore], [ignore])
126     LT_AT_EXEC_CHECK([./main])
127     # Now test that if we reverse the link order, the program fails.
128     AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS $static -o wrong$EXEEXT main.$OBJEXT -la0 libb.la],
129              [], [ignore], [ignore])
130     if test yes, != "$shared_fails,$static"; then
131       LT_AT_EXEC_CHECK([./wrong], [1], [], [ignore], [|| (exit 1)])
132     fi
134     $LIBTOOL --mode=install cp liba1.la $libdir/liba1.la
135     $LIBTOOL --mode=install cp libb.la $libdir/libb.la
136     $LIBTOOL --mode=install cp main$EXEEXT $bindir/main$EXEEXT
137     $LIBTOOL --mode=install cp wrong$EXEEXT $bindir/wrong$EXEEXT
138     $LIBTOOL --mode=clean rm -f liba1.la libb.la
139     LT_AT_EXEC_CHECK([$bindir/main])
140     if test yes, = "$shared_fails,$static"; then
141       LT_AT_EXEC_CHECK([$bindir/wrong], [1], [], [ignore], [|| (exit 1)])
142     fi
143   done
144 done
146 AT_CHECK([test no = "$shared_fails" || (exit 77)])
148 # Now the converse: if both the program and the library need libm, then
149 # it needs to be sorted last.  (TODO)
151 AT_CLEANUP