1 # link-order.at -- ensure that library linking order matches -*- Autotest -*-
3 # Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
4 # Written by Alexandre Oliva & Ralf Wildenhues, 2005
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.
26 AT_SETUP([Link order test])
27 AT_KEYWORDS([libtool])
28 eval `$LIBTOOL --config | $EGREP '^(hardcode_direct|hardcode_direct_absolute|shrext_cmds)='`
29 LDFLAGS="$LDFLAGS -no-undefined"
32 eval shared_ext=\"$shrext_cmds\"
36 mkdir src $prefix_old $prefix_new $prefix_old/lib $prefix_new/lib
42 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c src/c.c -o src/c.lo
43 $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o src/libcee.la src/c.lo -rpath $prefix_old/lib
44 $LIBTOOL --mode=install cp src/libcee.la $prefix_old/lib/libcee.la
51 /* w32 fun, MSVC needs to dllimport when using a shared library, so use
52 * DLL_EXPORT to discriminate as that happens to coinside in this case.
53 * gnu has auto import.
55 #if defined _MSC_VER && defined DLL_EXPORT
56 # define LIBCEE_SCOPE __declspec(dllimport)
58 # define LIBCEE_SCOPE extern
62 int a_$i() { return c + b_$i(); }
66 /* w32 fun, MSVC needs to dllimport when using a shared library, so use
67 * DLL_EXPORT to discriminate as that happens to coinside in this case.
68 * gnu has auto import.
70 #if defined _MSC_VER && defined DLL_EXPORT
71 # define LIBCEE_SCOPE __declspec(dllimport)
73 # define LIBCEE_SCOPE extern
76 int b_$i() { return 1 + c; }
79 prefix=`eval echo \\$prefix_$i`
80 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c src/a_$i.c -o src/a.lo
81 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c src/b_$i.c -o src/b.lo
82 $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o src/libb.la src/b.lo \
83 -L$prefix_old/lib -lcee -rpath $prefix/lib
84 $LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o src/liba.la src/a.lo \
85 src/libb.la -L$prefix_old/lib -lcee -rpath $prefix/lib
86 $LIBTOOL --mode=install cp src/libb.la $prefix/lib/libb.la
87 AT_CHECK([$LIBTOOL --mode=install cp src/liba.la $prefix/lib/liba.la],
88 [0], [stdout], [stderr])
91 $LIBTOOL --mode=clean rm -f src/libb.la
92 $LIBTOOL --mode=clean rm -f src/liba.la
95 aix* | interix*) ;; # These systems have different path syntax
97 # Do not error if we do not relink (e.g. static-only systems)
98 case $hardcode_direct$hardcode_direct_absolute in
100 AT_CHECK([if $EGREP relinking stderr; then
101 $EGREP " .*\/new\/lib/libb$shared_ext .*\/old\/lib/libcee$shared_ext" stdout
102 else :; fi], [0], [ignore], [], [echo "wrong link order"])
105 AT_CHECK([if $EGREP relinking stderr; then
106 $EGREP " -L.*\/new\/lib -lb -L.*\/old\/lib -lcee" stdout
107 else :; fi], [0], [ignore], [], [echo "wrong link order"])
114 cat >src/main_$i.c <<EOF
116 int main(void) { return a_$i() != 3; }
119 prefix=`eval echo \\$prefix_$i`
120 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c src/main_$i.c -o src/main_$i.lo
121 AT_CHECK($LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o src/main_$i$EXEEXT src/main_$i.lo -L$prefix/lib -la,
122 [0], [ignore], [ignore])
123 LT_AT_EXEC_CHECK([src/main_$i])