From 69f26ece3c4545ecc9099641f7a507796fe9dc77 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Mon, 21 May 2012 08:57:05 +0100 Subject: [PATCH] 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 .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 Reviewed-by: Derrick Brashear --- .gitignore | 3 + Makefile.in | 1 + build-tools/.gitignore | 1 + configure.ac | 4 ++ regen.sh | 2 + src/cf/.gitignore | 5 ++ src/config/.gitignore | 1 + src/config/Makefile.config.in | 39 ++++++++++++- src/config/Makefile.libtool.in | 34 +++++++++++ src/config/Makefile.lwp.in | 4 ++ src/config/Makefile.pthread.in | 4 ++ src/config/lwptool | 103 +++++++++++++++++++++++++++++++++ 12 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 build-tools/.gitignore create mode 100644 src/cf/.gitignore create mode 100644 src/config/Makefile.libtool.in create mode 100755 src/config/lwptool diff --git a/.gitignore b/.gitignore index 31eb7b656..31ac33df1 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile.in b/Makefile.in index f46d14990..5095faa5a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 index 000000000..3443db6c0 --- /dev/null +++ b/build-tools/.gitignore @@ -0,0 +1 @@ +/ltmain.sh diff --git a/configure.ac b/configure.ac index 3eb836fce..5cbf59156 100644 --- a/configure.ac +++ b/configure.ac @@ -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 \ diff --git a/regen.sh b/regen.sh index c20c4bbb3..0908683f0 100755 --- 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 index 000000000..94e6f26a7 --- /dev/null +++ b/src/cf/.gitignore @@ -0,0 +1,5 @@ +/libtool.m4 +/ltoptions.m4 +/ltsugar.m4 +/ltversion.m4 +/lt~obsolete.m4 diff --git a/src/config/.gitignore b/src/config/.gitignore index 2bac1d590..3d3de334d 100644 --- a/src/config/.gitignore +++ b/src/config/.gitignore @@ -5,6 +5,7 @@ /Makefile.*_*[0123456789] /Makefile.*_*[0123456789].in /Makefile.config +/Makefile.libtool /Makefile.lwp /Makefile.shared /Makefile.pthread diff --git a/src/config/Makefile.config.in b/src/config/Makefile.config.in index b8e7ea58b..99756e9f4 100644 --- a/src/config/Makefile.config.in +++ b/src/config/Makefile.config.in @@ -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 index 000000000..534809e9d --- /dev/null +++ b/src/config/Makefile.libtool.in @@ -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) $< + diff --git a/src/config/Makefile.lwp.in b/src/config/Makefile.lwp.in index 002596806..0d536d651 100644 --- a/src/config/Makefile.lwp.in +++ b/src/config/Makefile.lwp.in @@ -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 diff --git a/src/config/Makefile.pthread.in b/src/config/Makefile.pthread.in index f4af720d7..471b0d436 100644 --- a/src/config/Makefile.pthread.in +++ b/src/config/Makefile.pthread.in @@ -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 index 000000000..2cb55e68b --- /dev/null +++ b/src/config/lwptool @@ -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 --lwpcc --mtcc -- ..." >&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 " >&2; + echo " --lwpcc " >&2; + echo " --mtcc 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 " >&2; + echo " --linker " >&2; + echo " --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 -- 2.39.5