Subject: Use of libtool in pkgs
To: None <packages@NetBSD.ORG>
From: Todd Vierling <tv@pobox.com>
List: tech-pkg
Date: 07/14/1998 15:01:48
I now have two examples in-tree of pkgs that use libtool to build their
static and shared libraries.  Coupled with the new automatic shared library
handling in the PLIST, this poses the potential of relieving many headaches
dealing with shared libraries.

You casn take a look at libwww for a pkg which actually supports libtool,
and whose configure script was hacked to make use of the pkg version of
libtool (as opposed to the one libwww ships).  You can look at rsaref (and
soon libmpeg) for pkgs whose native Makefiles were modified to make use of
libtool.

Here's how to use libtool in a pkg in seven simple steps:

=====

Define LIBTOOL=${PREFIX}/bin/libtool in MAKE_ENV, or define it in a patch to
the native Makefile.  Make the pkg depend on libtool with:

  BUILD_DEPENDS= ${PREFIX}/bin/libtool:../../devel/libtool

=====

For library objects, use "${LIBTOOL} --mode=compile ${CC}" in place of
${CC}.  You could even add it to the definition of CC, if only libraries are
being built in a given Makefile.  This one command will build both PIC and
non-PIC library objects, so you need not have separate shared and non-shared
library rules.

=====

For the linking of the library, remove any "ar", "ranlib", and "ld
-Bshareable" commands, and use instead:

  ${LIBTOOL} --mode=link cc -o ${.TARGET:.a=.la} ${OBJS:.o=.lo} -rpath ${PREFIX}/lib -version-info major:minor

Note that the library is changed to have a .la extension, and the objects
are changed to have a .lo extension.  Change OBJS as necessary.  This
automatically creates all of the .a, .so.major.minor, and ELF symlinks (if
necessary) in the build directory.

=====

When linking programs that depend on thse libraries _before_ they are
installed, preface the cc or ld line with "${LIBTOOL} --mode=link", and it
will find the correct libraries (static or shared).

=====

When installing libraries, preface the install or cp command with
"${LIBTOOL} --mode=install", and change the library name to .la.  For
example:

  ${LIBTOOL} --mode=install ${BSD_INSTALL_DATA} ${SOMELIB:.a=.la} ${PREFIX}/lib

This will install the static .a, shared library, any needed symlinks, and
run "ldconfig."

=====

In your PLIST, include the .a, .la, and .so.major.minor files.  Don't
include the ELF symlink files; those are automatic. 

=====

FOR GNU PKGS THAT ALREADY SUPPORT LIBTOOL:

Put LIBTOOL=${PREFIX}/bin/libtool in CONFIGURE_ENV, and possibly modify the
"configure" script not to check for or configure its own libtool.  See the
libwww pkg, patch-ab, for the quick way to bypass the pkg's own libtool.

=====

Any more questions, ask me.  I'm not saying (yet?) that libtool is a
mandatory way to build shared libraries in the pkg system, but with the
simple changes above, it automates the system pretty completely.

-- 
-- Todd Vierling (Personal tv@pobox.com; Bus. todd_vierling@xn.xerox.com)