Hello, It is a well known problem with libtool (at least in the packaging business!) that relinking breaks things when packages are make install'ed in a buildroot rather than in the final runtime destination. There seem to be various workarounds and fixes available, but it seems it would be much better if this could be fixed upstream in the libtool distribution itself.
The best patch I have come across is the one attributed to maddog in Mandrake's libtool package. I don't have any problem with the patch, but Alexandre Oliva told me he would prefer an implementation that avoids adding a new prefix (-inst-prefix-dir) to libtool. I am still not very familiar with libtool's internals, but last month spent a chunk of time looking into this (see https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=58664 for my naive wanderings), and came to the conclusion that it looks rather hard to avoid using -inst-prefix-dir, since in the final invocation of libtool there is really no way for libtool to know what the DESTDIR prefix should be. But I would like to solicit opinions from the libtool community on this matter, before taking it further. So any comments please on the above and the patch below? Cheers, Jens
--- libtool-1.4.1/ltmain.sh.relink Wed Oct 3 02:05:35 2001 +++ libtool-1.4.1/ltmain.sh Wed Oct 3 05:16:14 2001 @@ -754,6 +754,7 @@ linker_flags= dllsearchpath= lib_search_path=`pwd` + inst_prefix_dir= avoid_version=no dlfiles= @@ -884,6 +885,11 @@ prev= continue ;; + inst_prefix) + inst_prefix_dir="$arg" + prev= + continue + ;; release) release="-$arg" prev= @@ -985,6 +991,11 @@ continue ;; + -inst-prefix-dir) + prev=inst_prefix + continue + ;; + # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* # so, if we see these flags be careful not to treat them like -L -L[A-Z][A-Z]*:*) @@ -1866,6 +1877,7 @@ if test "$linkmode" = prog || test "$mode" = relink; then add_shlibpath= + add_prefix_dir= add_dir= add= # Finalize command for both is simple: just hardcode it. @@ -1886,10 +1898,22 @@ add="-l$name" fi + if test -n "$inst_prefix_dir"; then + case "$libdir" in + [\\/]*) + add_prefix_dir="-L$inst_prefix_dir$libdir" + ;; + esac + fi + + # add_prefix_dir must be appended instead, otherwise it can + # possibly be overrided by any hardcoded -L/... path in deplibs if test "$linkmode" = prog; then + test -n "$add_prefix_dir" && finalize_deplibs="$finalize_deplibs $add_prefix_dir" test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" test -n "$add" && finalize_deplibs="$add $finalize_deplibs" else + test -n "$add_prefix_dir" && deplibs="$deplibs $add_prefix_dir" test -n "$add_dir" && deplibs="$add_dir $deplibs" test -n "$add" && deplibs="$add $deplibs" fi @@ -3856,7 +3880,7 @@ fi done # Quote the link command for shipping. - relink_command="cd `pwd`; $SHELL $0 --mode=relink $libtool_args" + relink_command="cd `pwd`; $SHELL $0 --mode=relink $libtool_args @inst_prefix_dir@" relink_command=`$echo "X$relink_command" | $Xsed -e "$sed_quote_subst"` # Only create the output if not a dry run. @@ -4157,6 +4181,24 @@ dir="$dir$objdir" if test -n "$relink_command"; then + # Determine the prefix the user has applied to our future dir. + inst_prefix_dir=`$echo "$destdir" | sed "s%$libdir\$%%"` + + # Don't allow the user to place us outside of our expected + # location b/c this prevents finding dependent libraries that + # are installed to the same prefix. + if test "$inst_prefix_dir" = "$destdir"; then + $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2 + exit 1 + fi + + if test -n "$inst_prefix_dir"; then + # Stick the inst_prefix_dir data into the link command. + relink_command=`$echo "$relink_command" | sed "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"` + else + relink_command=`$echo "$relink_command" | sed "s%@inst_prefix_dir@%%"` + fi + $echo "$modename: warning: relinking \`$file'" 1>&2 $show "$relink_command" if $run eval "$relink_command"; then :