Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / depdemo-relink.test
1 #! /bin/sh
2 # depdemo-relink.test - check to see whether shlibpath overrides runpath
3 #
4 #   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
5 #   Written by Gary V. Vaughan, 2003
6 #
7 #   This file is part of GNU Libtool.
8 #
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.
13 #
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.
18 #
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 ####
25
26 . tests/defs || exit 1
27
28 func_restore_files ()
29 {
30     func_mkdir_p "$objdir"
31     test "`echo _fnord/temp/libs/*`" = "_fnord/temp/libs/*" \
32       || mv -f _fnord/temp/libs/* "l3/$objdir"
33     mv -f "_fnord/temp/libl3.la" "l3"
34     test -f "_fnord/temp/lt-depdemo$EXEEXT" \
35       && mv -f "_fnord/temp/lt-depdemo$EXEEXT" "$objdir"
36     test -f "_fnord/temp/depdemo$EXEEXT" \
37       && mv -f "_fnord/temp/depdemo$EXEEXT" "$objdir"
38     rm -rf "_fnord"
39 }
40
41 func_save_files ()
42 {
43     func_mkdir_p "_fnord/temp/libs"
44     test -f "$objdir/lt-depdemo$EXEEXT" \
45       && cp -f "$objdir/lt-depdemo$EXEEXT" "_fnord/temp"
46     test -f "$objdir/depdemo$EXEEXT" \
47       && cp -f "$objdir/depdemo$EXEEXT" "_fnord/temp"
48     cp -f l3/libl3.la "_fnord/temp"
49     cp -f l3/"$objdir"/* "_fnord/temp/libs"
50     trap "func_restore_files" 0 1 2 13 15
51 }
52
53 func_require "depdemo-inst" "$prefix/lib/libl3.la"  "tests/depdemo/l3/libl3.la"
54
55 func_mkprefixdir
56 func_cd "tests/depdemo"
57
58 # Check to make sure we have a dynamic library.
59 func_get_config "library_names" "cat l3/libl3.la"
60 test -z "$library_names" \
61   && func_skip "Exiting: depdemo/l3/libl3.la is not a shared library"
62
63 func_save_files
64
65 func_get_config 'shlibpath_overrides_runpath
66 hardcode_action
67 hardcode_direct
68 hardcode_into_libs' "./libtool --config" ": fatal"
69
70 ./depdemo$EXEEXT # so that it links on-demand if needed
71
72 func_msg "removing libl3.la from depdemo/l3"
73 rm -rf l3/libl3.la l3/$objdir
74
75 func_msg "running depdemo/depdemo"
76 if ./depdemo$EXEEXT ||
77    # On AIX 4.1, when the installed copy of libl3 is loaded, it brings
78    # with it the installed copies of libl1 and libl2, with disjoint
79    # counters var_l1 and var_l2.  This is arguably acceptable behavior,
80    # but it's definitely not enough of a reason for the test to fail.
81    ./depdemo$EXEEXT -alt; then
82   :
83 elif test "x,$hardcode_action,$hardcode_direct" = x,relink,yes; then
84   func_msg "Ok, uninstalled programs fail after uninstalled libraries are removed"
85   func_msg "This works in other configurations, but not in this particular one"
86 elif test "$build" != "$host"; then
87   func_msg "depdemo/depdemo does not run.  Since you seem to be"
88   func_msg "cross-compiling, this might be ok."
89 else
90   func_fail "Exiting: depdemo/depdemo does not run, maybe libl3 was not installed"
91 fi
92
93 func_msg "linking a broken depdemo/l3/libl3.la"
94 (cd l3 && $MAKE libl3.la libl3_la_OBJECTS=../l2/l2.lo) \
95   || func_fail "Exiting: cannot link broken libl3.la"
96 rm -f l3/libl3.la
97
98 func_msg "running depdemo/depdemo with broken libl3.la"
99 if (./depdemo$EXEEXT) 2>&1; then
100   func_msg "Exiting: depdemo/depdemo runs even though libl3.la is incomplete"
101   func_fail "shlibpath_overrides_runpath should be set to no"
102 elif test "$build" != "$host"; then
103   func_msg "Failed, as expected.  But since you seem to be"
104   func_msg "cross-compiling, this is not reliable."
105   status=$EXIT_SKIP
106 else
107   func_msg "Failed, as expected"
108 fi
109
110 if test "x$hardcode_action" = xrelink; then
111   func_msg "Exiting: install-time relinking is required"
112   exit $EXIT_SUCCESS
113 fi
114
115 if test "$shlibpath_overrides_runpath" != yes; then
116   rm -f $objdir/lt-depdemo || exit $EXIT_FAILURE
117   cp $objdir/depdemo $objdir/lt-depdemo || exit $EXIT_FAILURE
118   func_msg "running depdemo/depdemo with installed libl3.la"
119   if ./depdemo; then
120     func_msg "Worked, as expected"
121   else
122     func_msg "shlibpath_overrides_runpath should be set to yes"
123     status=$EXIT_FAILURE
124   fi
125 fi
126
127 exit $status