From cc297c844f80d85c7078554c80a2900b5f9ffda0 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Thu, 19 Nov 1998 18:01:07 +0000 Subject: [PATCH] * ltmain.in (installed): new variable defined within a .la file, so that libtool can now link already-installed libraries into a program. * NEWS: ditto * doc/libtool.texi (Linking executables): document it --- ChangeLog | 6 ++++++ NEWS | 3 ++- doc/libtool.texi | 38 ++++++++++++++++++++++++++++++++++++-- ltmain.in | 36 +++++++++++++++++++++++++++--------- 4 files changed, 71 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e9001e1..2db94203 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 1998-11-19 Alexandre Oliva + * ltmain.in (installed): new variable defined within a .la file, + so that libtool can now link already-installed libraries into a + program. + * NEWS: ditto + * doc/libtool.texi (Linking executables): document it + * ltmain.in (output_objdir): compute it from $output, not $arg 1998-11-18 Alexandre Oliva diff --git a/NEWS b/NEWS index 49df135e..79d0df60 100644 --- a/NEWS +++ b/NEWS @@ -1,8 +1,9 @@ NEWS - list of user-visible changes between releases of GNU Libtool New in 1.2c - 1998-XX-XX: +* libtool will correctly link already-installed libraries into programs. * New -module flag, to create loadable modules. -# New libltdl, a small library for portable dynamic loading of modules. +* New libltdl, a small library for portable dynamic loading of modules. * Inter-library dependencies patch finally integrated, but there's still much porting to do. See PORTING for details (some plans for the future in mail/deplibs in the CVS tree). diff --git a/doc/libtool.texi b/doc/libtool.texi index ca425e84..6fc6b689 100644 --- a/doc/libtool.texi +++ b/doc/libtool.texi @@ -680,6 +680,39 @@ creating hell burger$ @end example +@cindex linking with installed libtool libraries + +Now assume @file{libhello.la} had already been installed, and you want +to link a new program with it. You could figure out where it lives by +yourself, then run: + +@example +burger$ @kbd{gcc -g -O -o test test.o -L/usr/local/lib -lhello} +@end example + +However, unless @file{/usr/local/lib} is in the standard library search +path, you won't be able to run @code{test}. However, if you use libtool +to link the already-installed libtool library, it will do The Right +Thing (TM) for you: + +@example +burger$ @kbd{libtool gcc -g -O -o test test.o /usr/local/lib/libhello.la} +gcc -g -O -o @value{objdir}/test test.o -Wl,--rpath -Wl,/usr/local/lib /usr/local/lib/libhello.la -lm +creating test +burger$ +@end example + +Note that libtool added the necessary run-time path flag, as well as +@samp{-lm}, the library libhello.la depended upon. Nice, huh? + +Since libtool created a wrapper script, you should use libtool to +install it and debug it too. However, since the program does not depend +on any uninstalled libtool library, it is probably usable even without +the wrapper script. Libtool could probably be made smarter to avoid the +creation of the wrapper script in this case, but this is left as an +exercise for the reader. + + @cindex wrapper scripts for programs @cindex program wrapper scripts Notice that the executable, @code{hell}, was actually created in the @@ -837,8 +870,9 @@ a23# @end example Note that the libtool library @file{libhello.la} is also installed, to -help libtool with uninstallation (@pxref{Uninstall mode}) and to help -programs with dlopening (@pxref{Dlopened modules}). +help libtool with uninstallation (@pxref{Uninstall mode}) and linking +(@pxref{Linking executables}) and to help programs with dlopening +(@pxref{Dlopened modules}). Here is the shared library example: diff --git a/ltmain.in b/ltmain.in index 82f3d9c6..998d4117 100644 --- a/ltmain.in +++ b/ltmain.in @@ -549,7 +549,7 @@ compiler." # Unlock the critical section if it was locked if test "$need_locks" != no; then - rm -f "$lockfile" + $rm "$lockfile" fi # Create an invalid libtool object if no PIC, so that we do not @@ -839,6 +839,10 @@ compiler." exit 1 fi + # If the library was installed with an old release of libtool, + # it will not redefine variable installed. + installed=yes + # If there is no directory component, then add one. case "$arg" in */* | *\\*) . $arg ;; @@ -858,12 +862,17 @@ compiler." # Find the relevant object directory and library name. name=`$echo "X$arg" | $Xsed -e 's%^.*/%%' -e 's/\.la$//' -e 's/^lib//'` - dir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$dir" = "X$arg"; then - dir="$objdir" - else - dir="$dir/$objdir" - fi + + if test "X$installed" = Xyes; then + dir="$libdir" + else + dir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` + if test "X$dir" = "X$arg"; then + dir="$objdir" + else + dir="$dir/$objdir" + fi + fi if test -z "$libdir"; then # It is a libtool convenience library, so add in its objects. @@ -2182,6 +2191,9 @@ current=$current age=$age revision=$revision +# Is this an already installed library? +installed=no + # Directory that this library needs to be installed in: libdir='$install_libdir'\ " @@ -2431,8 +2443,14 @@ libdir='$install_libdir'\ # Install the pseudo-library for information purposes. name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - $show "$install_prog $file $destdir/$name" - $run eval "$install_prog $file $destdir/$name" || exit $? + instname="$dir/$name"i + $show "Creating $instname" + $rm "$instname" + sed 's/^installed=no$/installed=yes/' "$file" > "$instname" + $show "$install_prog $instname $destdir/$name" + $run eval "$install_prog $instname $destdir/$name" || exit $? + $show "$rm $instname" + $rm "$instname" # Maybe install the static library, too. test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library"