Add libtool support

Add support for using libtool to the Unix build system to build
both pthreaded and lwp libraries. For purely pthread libraries,
this just provides convenience macros to invoke the standard GNU
libtool from the OpenAFS build system. For libraries that have
lwp variants, we provide an initial wrapper script - lwptool,
which handles building a non-PIC LWP object before asking libtool
to build the pthread variants.

For a given source example.c, example.o is the non-PIC pthread
object, .libs/example.o is the PIC pthread object, and
.lwp/example.o is the LWP object.

To use libtool for a particular library directory, add the line
    include @TOP_OBJDIR@/src/config/Makefile.libtool
to the file's preamble. Makefile.pthread, or Makefile.lwp should be
included as normal to indicate whether the libraries in this Makefile
are pthread only, or should be built for both pthread and LWP objects.

The variables LT_current, LT_revision and LT_age may be used to control
the version of the shared objects produced. They have the same meaning
as that documented in the Versioning section of the libtool manual.

The LT_objs variable should be set to a space separated list of the .lo
objects included in the library. Note that there should _never_ be a
dependency on the .o form of these objects in the Makefile, as this
breaks parallel builds.

LT_deps is a list of the libtool dependencies of the library, and
LT_libs is a list of the external (non-OpenAFS) library dependencies.

A file called <libraryname>.sym should be created which contains a
newline seperated list of all of the symbols exported from this
library.

LWP library names remain the same as always. To distinguish the
pthreaded static and shared libraries these

LWP libraries should be linked using
    libexample.a: $(LT_objs)
	    $(LTLWP_LDLIB) $(LT_objs)

Shared libraries should be linked using
    libexample.la: $(LT_objs) $(LT_deps)

(note that the pattern rules in the included Makefile take care of the
 build rule here)

If necessary, static convenience libraries can be produced using:
    libconvenience.a: $(LT_objs)
	    $(LTLWP_LDLIB_static) $(LT_objs)

PIC convenience libaries can be linked using:
    libconvenience_pic.a: $(LT_objs)
	    $(LTLWP_LDLIB_pic) $(LT_objs)

Libtool libraries should be installed using the $(LT_INSTALL_DATA) macro

Binaries linking agains libtool libraries should be linked using the
$(LT_LDRULE) or $(LT_LRDULE_static) options, with library paths in the
built locations relative to the top of the tree. For example

example_test: example_test.o $(top_builddir)/src/example/libexample.la
	$(LT_LDRULE) example_test.o \
		     $(top_builddir)/src/example/libexample.la

Change-Id: I32b162e8443119e8115febc532c5b5a0ec8fed32
Reviewed-on: http://gerrit.openafs.org/8033
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
This commit is contained in:
Simon Wilkinson 2012-05-21 08:57:05 +01:00 committed by Derrick Brashear
parent 0b31aba6a6
commit 69f26ece3c
12 changed files with 200 additions and 1 deletions

3
.gitignore vendored
View File

@ -15,7 +15,9 @@
*.orig
*.rej
*.o
*.lo
*.a
*.la
*.so
*.sl
*.so.*
@ -49,6 +51,7 @@ config.log
/cscope.out
/include
/lib
/libtool
/autom4te.cache
/ID
/TAGS

View File

@ -829,6 +829,7 @@ distclean: clean
src/comerr/test/Makefile \
src/config/Makefile \
src/config/Makefile.config \
src/config/Makefile.libtool \
src/config/Makefile.lwp \
src/config/Makefile.pthread \
src/config/Makefile.shared \

1
build-tools/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/ltmain.sh

View File

@ -1,6 +1,7 @@
AC_PREREQ([2.60])
AC_INIT([OpenAFS], m4_esyscmd([build-tools/git-version .]))
AC_CONFIG_AUX_DIR([build-tools])
AC_CONFIG_MACRO_DIR([src/cf])
AC_CONFIG_SRCDIR([src/config/stds.h])
AM_INIT_AUTOMAKE
@ -24,6 +25,8 @@ AS_IF([test -z "$CFLAGS"], [CFLAGS=" "], [])
AC_USE_SYSTEM_EXTENSIONS
LT_INIT
AC_PROG_CC
AC_PATH_PROGS([PATH_CPP], [cpp], [${CC-cc} -E], [$PATH:/lib:/usr/ccs/lib])
@ -148,6 +151,7 @@ src/comerr/Makefile \
src/comerr/test/Makefile \
src/config/Makefile \
src/config/Makefile.config \
src/config/Makefile.libtool \
src/config/Makefile.lwp \
src/config/Makefile.pthread \
src/config/Makefile.shared \

View File

@ -25,6 +25,8 @@ else
exit 1
fi
echo "Running libtoolize"
libtoolize -c -f
echo "Running autoconf"
autoconf
echo "Running autoconf for configure-libafs"

5
src/cf/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/libtool.m4
/ltoptions.m4
/ltsugar.m4
/ltversion.m4
/lt~obsolete.m4

View File

@ -5,6 +5,7 @@
/Makefile.*_*[0123456789]
/Makefile.*_*[0123456789].in
/Makefile.config
/Makefile.libtool
/Makefile.lwp
/Makefile.shared
/Makefile.pthread

View File

@ -25,6 +25,7 @@ prefix=@prefix@
sbindir=@sbindir@
sysconfdir=@sysconfdir@
viceetcdir=@viceetcdir@/
top_builddir=@top_builddir@
#
@ -62,6 +63,7 @@ LIB_curses = @LIB_curses@
LIB_hcrypto = @LIB_hcrypto@
LIB_roken = @LIB_roken@
LIB_krb5 = @KRB5_LIBS@
LIBTOOL= @LIBTOOL@
LIBS = @LIBS@
LIB_LIBINTL = @LIB_libintl@
LINUX_KERNEL_PATH = @LINUX_KERNEL_PATH@
@ -144,7 +146,8 @@ KERNELDIR = ../libafs
#
COMPILE_ET = ${TOP_OBJDIR}/src/comerr/compile_et
RXGEN = ${TOP_OBJDIR}/src/rxgen/rxgen
SHELL = /bin/sh
SHELL = @SHELL@
LWPTOOL = ${TOP_SRCDIR}/config/lwptool
#
# "Pretty" build line stuff
@ -225,6 +228,40 @@ SHD_LDFLAGS=$(COMMON_LDFLAGS) $(MODULE_LDFLAGS) $(SHLIB_LDFLAGS)
SHD_CCRULE =$(RUN_CC) $(MT_CC) $(SHD_CFLAGS) $(CFLAGS_$(@)) -o $@ -c
SHD_CCRULE_NOQ=$(RUN_CC_NOQ) $(MT_CC) $(SHD_CFLAGS) $(CFLAGS_$(@)) -o $@ -c
# Libtool - for objects that are part of pthread-only libraries
LT_CCRULE=$(RUN_CC) $(LIBTOOL) --quiet --mode=compile --tag=CC \
$(MT_CC) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c
# Libtool - for objects that are built for both pthread and lwp libraries
LTLWP_CCRULE=$(RUN_CC) $(LWPTOOL) --mode compile \
--lwpcc $(CCOBJ) \
--mtcc "$(LIBTOOL) --quiet --mode=compile --tag=CC $(MT_CC) $(MT_CFLAGS)" \
-o $@ \
-- \
$(COMMON_CFLAGS) $(MODULE_CFLAGS) $(CFLAGS_$(@)) \
-c
LT_LDLIB_lwp=$(RUN_LD) $(LWPTOOL) --mode link \
--ranlib "$(RANLIB)" \
--linker "$(AR) crv" \
-o $@ \
--
# Use this to link an executable with one or more libtool libraries
LT_LDRULE = $(RUN_LD) $(LIBTOOL) --quiet --mode=link --tag=CC \
$(MT_CC) $(PTH_LDFLAGS) $(PTH_CFLAGS) \
$(LDFLAGS_$(@)) -o $@
LT_LDRULE_static = $(RUN_LD) $(LIBTOOL) --quiet --mode=link --tag=CC \
$(MT_CC) -static $(PTH_LDFLAGS) $(PTH_CFLAGS) \
$(LDFLAGS_$(@)) -o $@
LT_INSTALL_DATA=$(LIBTOOL) --quiet --mode=install $(INSTALL_DATA)
LT_INSTALL_PROGRAM=$(LIBTOOL) --quiet --mode=install $(INSTALL_PROGRAM)
LT_CLEAN=$(RM) -rf .libs *.la *.lo
# Default rules. These will be overriden if the module Makefile specifically
# includes a particular type (lwp, pthread, or shared)

View File

@ -0,0 +1,34 @@
# This Makefile fragment contains rules necessary to build libtool libraries,
# the Makefile rules necessary to use them are all in Makefile.config
LT_current=0
LT_revision=0
LT_age=0
# Basic rule to link a shared library.
LT_LDLIB_shlib=$(LIBTOOL) --quiet --mode=link --tag=CC \
$(MT_CC) -rpath $(libdir) \
$(PTH_LDFLAGS) $(PTH_CFLAGS) $(LDFLAGS_$(@)) \
-o $@ \
-no-undefined \
-export-symbols $@.sym \
-version-info=$(LT_current):$(LT_revision):$(LT_age)
# Link a static convenience library (contains no PIC code)
LT_LDLIB_static=$(LIBTOOL) --quiet --mode=link --tag=CC \
$(MT_CC) -static $(LDFLAGS) $(DBG) $(OPTMZ) \
$(LDFLAGS_$(@)) -o $@
# Link a convenience library for use in other libs (contains PIC code)
LT_LDLIB_pic= $(LIBTOOL) --quiet --mode=link --tag=CC \
$(MT_CC) $(LDFLAGS) $(DBG) $(OPTMZ) \
$(LDFLAGS_$(@)) -o $@
LT_CLEAN=$(RM) -rf .libs *.la *.lo
.SUFFIXES: .lo
.m.lo:
$(LT_CCRULE) $<

View File

@ -3,6 +3,10 @@ AFS_LDFLAGS = $(LWP_LDFLAGS)
AFS_CCRULE =$(LWP_CCRULE)
AFS_CCRULE_NOQ =$(LWP_CCRULE_NOQ)
.c.lo:
$(LTLWP_CCRULE) $<
%.lo: %.c
$(LTLWP_CCRULE) $<
.c.o:
$(AFS_CCRULE) $<
%.o: %.c

View File

@ -10,5 +10,9 @@ AFS_LDRULE_NOQ=$(RUN_LD_NOQ) $(MT_CC) $(AFS_LDFLAGS) $(AFS_CFLAGS) $(LDFLAGS_$(@
$(AFS_CCRULE) $<
%.o: %.c
$(AFS_CCRULE) $<
.c.lo:
$(LT_CCRULE) $<
%.lo: %.c
$(LT_CCRULE) $<
.m.o:
$(AFS_CCRULE) $<

103
src/config/lwptool Executable file
View File

@ -0,0 +1,103 @@
#!/bin/sh
# This is a little helper script to build LWP static, and pthread shared and static
# objects from a single source file. We use libtool to do the heavy lifting for
# the pthreaded builds, but build the LWP objects here ourselves.
lwpcc=
mtcc=
linker=
ranlib=
mode=
object=
done=
while [ -z "$done" ] && [ $# -gt 0 ] ; do
case "$1" in
--lwpcc)
shift
lwpcc="$1"
shift
;;
--mtcc)
shift
mtcc="$1"
shift
;;
--linker)
shift
linker="$1"
shift
;;
--mode)
shift
mode="$1"
shift
;;
--ranlib)
shift
ranlib="$1"
shift
;;
-o)
shift
object="$1"
shift
;;
--)
shift;
done=yes
;;
*)
echo "Usage: lwptool --mode compile|link -o <object> --lwpcc <lwp compiler> --mtcc <pthread compiler> -- ..." >&2;
exit 1;
;;
esac
done
case "$mode" in
compile)
if [ -z "$object" ] || [ -z "$lwpcc" ] || \
[ -z "$mtcc" ] || [ -z "$mode" ] ; then
echo "Usage: lwptool --mode compile -o <object>" >&2;
echo " --lwpcc <lwp compiler>" >&2;
echo " --mtcc <pthread compiler> blah -- ..." >&2;
exit 1
fi
lwpobj=`echo $object | sed -e 's/.lo$/.o/'`
lwpobj=".lwp/$lwpobj"
mkdir .lwp 2>/dev/null
echo $lwpcc -o $lwpobj "$@"
$lwpcc -o $lwpobj "$@" || exit 1
echo $mtcc -o $object "$@"
$mtcc -o $object "$@" || exit 1
;;
link)
if [ -z "$object" ] || [ -z "$linker" ] || \
[ -z "$ranlib" ] ; then
echo "Usage: l§wptool --mode linker -o <object>" >&2;
echo " --linker <linker and options>" >&2;
echo " --ranlib <ranlib>" >&2;
exit 1
fi
# This will go horribly wrong if we ever have objects with shell
# special characters in their names
objects=
while [ $# -gt 0 ] ; do
arg=$1;
realobject=`echo $arg | sed -e 's/\(.*\).lo/.lwp\/\1.o/'`
objects="$objects $realobject"
shift
done
rm -f $object 2>/dev/null
echo $linker $object $objects
$linker $object $objects
echo $ranlib $object
$ranlib $object
;;
esac