1#! /bin/sh 2# hardcode.test - check to see what the system linker hardcodes 3 4# Test script header. 5need_prefix=yes 6if test -z "$srcdir"; then 7 srcdir=`echo "$0" | sed 's%/[^/]*$%%'` 8 test "$srcdir" = "$0" && srcdir=. 9 test "${VERBOSE+set}" != "set" && VERBOSE=yes 10fi 11. $srcdir/defs || exit 1 12 13# Extra tools we might need 14: ${DUMPSTABS=dumpstabs} 15 16# Check that things are built. 17if test -f $prefix/lib/libhello.la && cd ../demo; then : 18else 19 echo "You must run demo-inst.test before $0" 1>&2 20 exit 77 21fi 22 23# Unfortunately, we need access to libtool internals for this test. 24objdir=NONE 25eval `grep '^objdir=' ./libtool 2>/dev/null` 26if test "$objdir" = NONE; then 27 echo "objdir not set in ../demo/libtool" 1>&2 28 exit 1 29fi 30 31# Check to make sure we have a dynamic library. 32library_names=NONE 33eval `grep '^library_names=' ./libhello.la 2>/dev/null` 34 35if test "$library_names" = NONE; then 36 echo "library_names not set in ../demo/libhello.la" 1>&2 37 exit 1 38elif test -z "$library_names"; then 39 echo "= Exiting: ../demo/libhello.la is not a shared library" 40 exit 0 41fi 42 43echo "= Running $make hardcode in ../demo" 44$make hardcode || exit 1 45 46echo "= Finding libtool.m4's guesses at hardcoding values" 47status=0 48hardcode_direct=NONE 49hardcode_minus_L=NONE 50hardcode_shlibpath_var=NONE 51hardcode_libdir_flag_spec=NONE 52 53# Suck in all the hardcode_* variable settings. 54eval `./libtool --config | grep '^hardcode_' 2>/dev/null` 55 56if test "$hardcode_direct" = NONE; then 57 echo "hardcode_direct not set in ../demo/libtool" 1>&2 58 status=1 59fi 60 61if test "$hardcode_minus_L" = NONE; then 62 echo "hardcode_minus_L not set in ../demo/libtool" 1>&2 63 status=1 64fi 65 66if test "$hardcode_shlibpath_var" = NONE; then 67 echo "hardcode_shlibpath_var not set in ../demo/libtool" 1>&2 68 status=1 69fi 70 71if test "$hardcode_libdir_flag_spec" = NONE; then 72 echo "hardcode_libdir_flag_spec not set in ../demo/libtool" 1>&2 73 status=1 74fi 75 76test $status -eq 0 || exit $status 77 78echo "= Searching for hardcoded library directories in each program" 79for file in hc-*; do 80 case "$file" in 81 hc-direct) expected="$hardcode_direct" ;; 82 hc-libpath) expected="$hardcode_shlibpath_var" ;; 83 hc-minusL) expected="$hardcode_minus_L" ;; 84 85 hc-libflag) 86 if test -n "$hardcode_libdir_flag_spec"; then 87 expected=yes 88 else 89 expected=unsupported 90 fi 91 ;; 92 93 *) 94 continue 95 ;; 96 esac 97 98 # Discover whether the objdir really was hardcoded. 99 hardcoded=no 100 101 # Solaris cc may store the command line in a debugging section, 102 # which leads to false positives. Unfortunately, Solaris strip 103 # is not capable to remove the section (unlike GNU binutils strip). 104 # So we use dumpstabs if it seems to work. 105 if { $DUMPSTABS -d $file; } >/dev/null 2>&1; then 106 if $DUMPSTABS -d $file 2>/dev/null | $FGREP "$objdir" >/dev/null 2>&1; then 107 hardcoded=yes 108 else 109 hardcoded=no 110 fi 111 # At least AIX fgrep doesn't work for binary files, and AIX also 112 # doesn't have strings(1), so we need this strange conversion 113 # (which only works on ASCII). 114 # AIX fgrep also has a limited line length, so we turn unprintable 115 # characters into newlines. 116 elif cat $file | (tr '\000-\037\200-\377' '\n' || cat) 2>/dev/null \ 117 | $FGREP "$objdir" > /dev/null 2>&1; then 118 hardcoded=yes 119 elif $FGREP "$objdir" $file > /dev/null 2>&1; then 120 # We retry fgrep without tr, in case the above lead to a false negative. 121 hardcoded=yes 122 elif (sed -e '1!d' $file | grep 'unsupported') >/dev/null 2>&1; then 123 hardcoded=unsupported 124 fi 125 126 # Check the result. 127 case "$hardcoded" in 128 yes) 129 if test $expected = yes; then 130 echo "$objdir was hardcoded in \`$file', as libtool expected" 131 else 132 echo "$objdir was hardcoded in \`$file', which fooled libtool" 1>&2 133 status=1 134 fi 135 ;; 136 137 no) 138 if test $expected = no; then 139 echo "$objdir was not hardcoded in \`$file', as libtool expected" 140 else 141 echo "$objdir was not hardcoded in \`$file', which fooled libtool" 1>&2 142 status=1 143 fi 144 ;; 145 146 unsupported) 147 if test $expected = unsupported; then 148 echo "\`$file' was not linked properly, as libtool expected" 149 else 150 echo "\`$file' was not linked properly, which fooled libtool" 1>&2 151 status=1 152 fi 153 ;; 154 esac 155done 156 157exit $status 158