Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / demo-hardcode.test
1 #! /bin/sh
2 # demo-hardcode.test - check to see what the system linker hardcodes
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_require "demo-inst" "$prefix/lib/libhello.la"
29
30 func_mkprefixdir
31 func_cd "tests/demo"
32
33 # Check to make sure we have a dynamic library.
34 func_get_config "library_names" "cat ./libhello.la"
35 test -z "$library_names" \
36   && func_skip "Exiting: demo/libhello.la is not a shared library"
37
38 func_make "hardcode"
39
40 # Extra tools we might need
41 : ${DUMPSTABS=dumpstabs}
42
43 # Suck in all the hardcode_* variable settings.
44 func_msg "Finding libtool.m4's guesses at hardcoding values"
45 func_get_config 'hardcode_direct
46 hardcode_minus_L
47 hardcode_shlibpath_var
48 hardcode_libdir_flag_spec' "./libtool --config" ": fatal"
49
50 echo "= Searching for hardcoded library directories in each program"
51 for file in hc-*; do
52   case "$file" in
53   hc-direct)  expected="$hardcode_direct" ;;
54   hc-libpath) expected="$hardcode_shlibpath_var" ;;
55   hc-minusL)  expected="$hardcode_minus_L" ;;
56
57   hc-libflag)
58     if test -n "$hardcode_libdir_flag_spec"; then
59       expected=yes
60     else
61       expected=unsupported
62     fi
63     ;;
64
65   *)
66     continue
67     ;;
68   esac
69
70   # Discover whether the objdir really was hardcoded.
71   hardcoded=no
72
73   # Solaris cc may store the command line in a debugging section,
74   # which leads to false positives.  Unfortunately, Solaris strip
75   # is not capable to remove the section (unlike GNU binutils strip).
76   # So we use dumpstabs if it seems to work.
77   if { $DUMPSTABS -d $file; } >/dev/null 2>&1; then
78     if $DUMPSTABS -d $file 2>/dev/null | $FGREP "$objdir" >/dev/null 2>&1; then
79       hardcoded=yes
80     else
81       hardcoded=no
82     fi
83   # At least AIX fgrep doesn't work for binary files, and AIX also
84   # doesn't have strings(1), so we need this strange conversion
85   # (which only works on ASCII).
86   # AIX fgrep also has a limited line length, so we turn unprintable
87   # characters into newlines.
88   elif cat $file | (tr '\000-\037\200-\377' '\n' || cat) 2>/dev/null \
89                  | $FGREP "$objdir" > /dev/null 2>&1; then
90     hardcoded=yes
91   elif $FGREP "$objdir" $file > /dev/null 2>&1; then
92     # We retry fgrep without tr, in case the above lead to a false negative.
93     hardcoded=yes
94   elif (sed -e '1!d' $file | grep 'unsupported') >/dev/null 2>&1; then
95     hardcoded=unsupported
96   fi
97
98   # Check the result.
99   case "$hardcoded" in
100   yes)
101     if test $expected = yes; then
102       echo "$objdir was hardcoded in \`$file', as libtool expected"
103     else
104       echo "$objdir was hardcoded in \`$file', which fooled libtool" 1>&2
105       exit_status=1
106     fi
107     ;;
108
109   no)
110     if test $expected = no; then
111       echo "$objdir was not hardcoded in \`$file', as libtool expected"
112     else
113       echo "$objdir was not hardcoded in \`$file', which fooled libtool" 1>&2
114       exit_status=1
115     fi
116     ;;
117
118   unsupported)
119     if test $expected = unsupported; then
120       echo "\`$file' was not linked properly, as libtool expected"
121     else
122       echo "\`$file' was not linked properly, which fooled libtool" 1>&2
123       exit_status=1
124     fi
125     ;;
126   esac
127 done
128
129 exit $exit_status