]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Add libtool support
authorSimon Wilkinson <sxw@your-file-system.com>
Mon, 21 May 2012 07:57:05 +0000 (08:57 +0100)
committerDerrick Brashear <shadow@dementix.org>
Tue, 4 Sep 2012 13:55:51 +0000 (06:55 -0700)
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>
12 files changed:
.gitignore
Makefile.in
build-tools/.gitignore [new file with mode: 0644]
configure.ac
regen.sh
src/cf/.gitignore [new file with mode: 0644]
src/config/.gitignore
src/config/Makefile.config.in
src/config/Makefile.libtool.in [new file with mode: 0644]
src/config/Makefile.lwp.in
src/config/Makefile.pthread.in
src/config/lwptool [new file with mode: 0755]

index 31eb7b656c0b86802b1eda719e53800ce6c5f150..31ac33df199152e0f7060c70d9a1aaa8bc4249fa 100644 (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
index f46d149905a2610d2ac13da8db17c36877abe775..5095faa5a8fd7c269f24a41e9753029d20bac60b 100644 (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 \
diff --git a/build-tools/.gitignore b/build-tools/.gitignore
new file mode 100644 (file)
index 0000000..3443db6
--- /dev/null
@@ -0,0 +1 @@
+/ltmain.sh
index 3eb836fcee716728728cd11df97da3a814ebc160..5cbf591562b04bef1f4b5c39e88ef944d4b95a91 100644 (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 \
index c20c4bbb3a7ee0f8cf8fd0764784e2bd73359c57..0908683f0db6b413b88b1fa31d65b863f3beff59 100755 (executable)
--- a/regen.sh
+++ b/regen.sh
@@ -25,6 +25,8 @@ else
   exit 1
 fi
 
+echo "Running libtoolize"
+libtoolize -c -f
 echo "Running autoconf"
 autoconf
 echo "Running autoconf for configure-libafs"
diff --git a/src/cf/.gitignore b/src/cf/.gitignore
new file mode 100644 (file)
index 0000000..94e6f26
--- /dev/null
@@ -0,0 +1,5 @@
+/libtool.m4
+/ltoptions.m4
+/ltsugar.m4
+/ltversion.m4
+/lt~obsolete.m4
index 2bac1d5904d3574f05ea66126c3a4df0f0fcbd70..3d3de334def25dda695d9719d674b6ebb775f4e2 100644 (file)
@@ -5,6 +5,7 @@
 /Makefile.*_*[0123456789]
 /Makefile.*_*[0123456789].in
 /Makefile.config
+/Makefile.libtool
 /Makefile.lwp
 /Makefile.shared
 /Makefile.pthread
index b8e7ea58b8841d7718359be5021d431868cbe704..99756e9f4b5a6007193c8bc74032caa455bb147e 100644 (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)
 
diff --git a/src/config/Makefile.libtool.in b/src/config/Makefile.libtool.in
new file mode 100644 (file)
index 0000000..534809e
--- /dev/null
@@ -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) $<
+
index 00259680652e5307ea2a4c2587786f40a736dab9..0d536d65160f59c9fc89784baa7c3617a92af457 100644 (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
index f4af720d7a8088c55a2c4c5e501f96162e5a1cd6..471b0d436362c48c38d72a8d3e512000241cb52b 100644 (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) $<
diff --git a/src/config/lwptool b/src/config/lwptool
new file mode 100755 (executable)
index 0000000..2cb55e6
--- /dev/null
@@ -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