automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Building a Shared Library


From: Alexandre Duret-Lutz
Subject: Building a Shared Library
Date: Thu, 31 Jul 2003 00:14:52 +0200
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux)

Here is the current state of patch for the "Building a Shared
Library" section being discussed on the main list.

2003-07-30  Alexandre Duret-Lutz  <address@hidden>

        * automake.texi (A Shared Library): Rewrite and split into
        subsections.  Valuable comments from Norman Gray, Harlan Stenn,
        Tim Van Holder, and Guido Draheim.
        * tests/ltcond.test, tests/ltcond2.test, tests/ltconv.test: New files.
        * tests/Makefile.am (TESTS): Add them.

Index: THANKS
===================================================================
RCS file: /cvs/automake/automake/THANKS,v
retrieving revision 1.186.2.31
diff -u -r1.186.2.31 THANKS
--- THANKS      4 Jul 2003 21:08:19 -0000       1.186.2.31
+++ THANKS      30 Jul 2003 22:11:30 -0000
@@ -153,6 +153,7 @@
 Nicolas Thiery         address@hidden
 NISHIDA Keisuke                address@hidden
 Noah Friedman          address@hidden
+Norman Gray            address@hidden
 Nyul Laszlo            address@hidden
 OKUJI Yoshinori                address@hidden
 Olivier Louchart-Fletcher address@hidden
Index: automake.texi
===================================================================
RCS file: /cvs/automake/automake/automake.texi,v
retrieving revision 1.305.2.30
diff -u -r1.305.2.30 automake.texi
--- automake.texi       10 Jul 2003 20:32:44 -0000      1.305.2.30
+++ automake.texi       30 Jul 2003 22:11:34 -0000
@@ -2061,7 +2061,7 @@
 
 This section also covers conditional compilation of sources or
 programs.  Most of the comments about these also apply to libraries
-(@pxref{A Library}) and Libtool libraries (@pxref{A Shared Library}).
+(@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
 
 @menu
 * Program Sources::             Defining program sources
@@ -2360,7 +2360,7 @@
 @code{libdir} or @code{pkglibdir}.
 
 @xref{A Shared Library}, for information on how to build shared
-libraries using Libtool and the @samp{LTLIBRARIES} primary.
+libraries using libtool and the @samp{LTLIBRARIES} primary.
 
 Each @samp{_LIBRARIES} variable is a list of the libraries to be built.
 For instance to create a library named @file{libcpio.a}, but not install
@@ -2400,71 +2400,384 @@
 
 @cindex Shared libraries, support for
 
-Building shared libraries is a relatively complex matter.  For this
-reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
+Building shared libraries portably is a relatively complex matter.
+For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
 Libtool Manual}) was created to help build shared libraries in a
 platform-independent way.
 
address@hidden
+* Libtool Concept::             Introducing Libtool
+* Libtool Libraries::           Declaring LiBtool Libraries
+* Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
+* Conditional Libtool Sources::  Choosing Library Sources Conditionally
+* Libtool Convenience Libraries::  Building Convenience Libtool Libraries
+* Libtool Modules::             Building Libtool Modules
+* Libtool Flags::               Using _LIBADD and _LDFLAGS
+* LTLIBOBJ::                    Using $(LTLIBOBJ)
+* Libtool Issues::              Common Issues Related to Libtool's Use
address@hidden menu
+
address@hidden Libtool Concept, Libtool Libraries, A Shared Library, A Shared 
Library
address@hidden The Libtool Concept
+
address@hidden libtool, introduction
address@hidden libtool library, definition
address@hidden suffix .la, defined
address@hidden .la suffix, defined
+
+Libtool abstracts shared and static libraries into a unified
+concept henceforth called @dfn{libtool libraries}.  Libtool libraries
+are files using the @file{.la} suffix, and can designate a static
+library, a shared library, or maybe both.  Their exact nature cannot
+be determined until @file{./configure} is run: not all platforms
+support all kinds of libraries, and users can explicitly select which
+libraries should be built.  (However the package's maintainers can
+tune the default, @xref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
+macro, libtool, The Libtool Manual}.)
+
address@hidden suffix .lo, defined
+Because object files for shared and static libraries must be compiled
+differently, libtool is also used during compilation.  Object files
+built by libtool are called @dfn{libtool objects}: these are files
+using the @file{.lo} suffix.  Libtool libraries are built from these
+libtool objects.
+
+You should not assume anything about the structure of @file{.la} or
address@hidden files and how libtool constructs them: this is libtool's
+concern, and the last thing one wants is to learn about libtool's
+guts.  However the existence of these files matters, because they are
+used as targets and dependencies in @file{Makefile}s when building
+libtool libraries.  There are situations where you may have to
+interact with these, for instance when setting dependencies for
+building source files conditionally (@pxref{Conditional Libtool
+Sources}).
+
address@hidden libltdl, introduction
+
+People considering writing a plug-in system, with dynamically loaded
+modules, should look into @file{libltdl}: libtool's dlopening library
+(@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
+This offers a portable dlopening facility to load libtool libraries
+dynamically, and can also achieve static linking where unavoidable.
+
+Before we discuss how to use libtool with Automake in details, it
+should be noted that the libtool manual also has a section about how
+to use Automake with libtool (@pxref{Using Automake, , Using Automake
+with Libtool, libtool, The Libtool Manual}).
+
address@hidden Libtool Libraries, Conditional Libtool Libraries, Libtool 
Concept, A Shared Library
address@hidden Building Libtool Libraries
+
 @cindex _LTLIBRARIES primary, defined
 @cindex LTLIBRARIES primary, defined
 @cindex Primary variable, LTLIBRARIES
 @cindex Example of shared libraries
address@hidden lib_LTLIBRARIES
address@hidden pkglib_LTLIBRARIES
 
address@hidden suffix .la, defined
-
-Automake uses Libtool to build libraries declared with the
address@hidden primary.  Each @samp{_LTLIBRARIES} variable is a list
-of shared libraries to build.  For instance, to create a library named
address@hidden and its corresponding shared libraries, and install
-them in @samp{libdir}, write:
+Automake uses libtool to build libraries declared with the
address@hidden primary.  Each @samp{_LTLIBRARIES} variable is a
+list of libtool libraries to build.  For instance, to create a libtool
+library named @file{libgettext.la}, and install it in @samp{libdir},
+write:
 
 @example
 lib_LTLIBRARIES = libgettext.la
+libgettext_la_SOURCES = gettext.c gettext.h @dots{}
 @end example
 
address@hidden lib_LTLIBRARIES
address@hidden pkglib_LTLIBRARIES
address@hidden noinst_LTLIBRARIES
address@hidden check_LTLIBRARIES
+Automake predefines the variable @samp{pkglibdir}, so you can use
address@hidden to install libraries in
address@hidden(libdir)/@@PACKAGE@@/}.
+
address@hidden Conditional Libtool Libraries, Conditional Libtool Sources, 
Libtool Libraries, A Shared Library
address@hidden Building Libtool Libraries Conditionally
address@hidden libtool libraries, conditional
address@hidden conditional libtool libraries
+
+Like conditional programs (@pxref{Conditional Programs}), there are
+two main ways to build conditional libraries: using Automake
+conditionals or using Autoconf @code{AC_SUBST}itutions.
+
+The important implementation detail you have to be aware of is that
+the place where a library will be installed matters to libtool: it
+needs to be indicated @emph{at link-time} using the @code{-rpath}
+option.
+
+For libraries whose destination directory is known when Automake runs,
+Automake will automatically supply the appropriate @samp{-rpath}
+option to libtool. This is the case for libraries listed explicitly in
+some @address@hidden variable.
+
+However, for libraries determined at configure time (and thus
+mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
+final installation directory.  For such libraries you must add the
address@hidden option to the appropriate @samp{_LDFLAGS} variable by
+hand.
+
+The examples below illustrate the differences between these two methods.
 
address@hidden check_LTLIBRARIES, not allowed
+Here is an example where @code{$(WANTEDLIBS)} is an @code{AC_SUBST}ed
+variable set at @file{./configure}-time to either @file{libfoo.la},
address@hidden, both, or none.  Although @code{$(WANTEDLIBS)}
+appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
+relates to @file{libfoo.la} or @file{libbar.la} by the time it creates
+the link rule for these two libraries.  Therefore the @code{-rpath}
+argument must be explicitly supplied.
+
address@hidden
+EXTRA_LTLIBRARIES = libfoo.la libbar.la
+lib_LTLIBRARIES = $(WANTEDLIBS)
+libfoo_la_SOURCES = foo.c @dots{}
+libfoo_la_LDFLAGS = -rpath '$(libdir)'
+libbar_la_SOURCES = bar.c @dots{}
+libbar_la_LDFLAGS = -rpath '$(libdir)'
address@hidden example
+
+Here is how the same @file{Makefile.am} would look using Automake
+conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
+Automake is able to compute the @code{-rpath} setting itself, because
+it's clear that both libraries will end up in @code{$(libdir)} if they
+are installed.
+
address@hidden
+lib_LTLIBRARIES =
+if WANT_LIBFOO
+lib_LTLIBRARIES += libfoo.la
+endif
+if WANT_LIBBAR
+lib_LTLIBRARIES += libbar.la
+endif
+libfoo_la_SOURCES = foo.c @dots{}
+libbar_la_SOURCES = bar.c @dots{}
address@hidden example
 
-Note that shared libraries @emph{must} be installed in order to work
-properly, so @code{check_LTLIBRARIES} is not allowed.  However,
address@hidden is allowed.  This feature should be used for
-libtool ``convenience libraries''.
address@hidden Conditional Libtool Sources, Libtool Convenience Libraries, 
Conditional Libtool Libraries, A Shared Library
address@hidden Libtool Libraries with Conditional Sources
 
address@hidden suffix .lo, defined
+Conditional compilation of sources in a library can be achieved in the
+same way as conditional compilation of sources in a program
+(@pxref{Conditional Sources}).  The only difference is that
address@hidden should be used instead of @code{_LDADD} and that it
+should mention libtool objects (@file{.lo} files).
+
+So, to mimic the @file{hello} example from @ref{Conditional Sources},
+we could build a @file{libhello.la} library using either
address@hidden or @file{hello-generic.c} with the following
address@hidden
+
address@hidden
+lib_LTLIBRARIES = libhello.la
+libhello_la_SOURCES = hello-common.c
+EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
+libhello_la_LIBADD = $(HELLO_SYSTEM)
+libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
address@hidden example
+
address@hidden
+And make sure @code{$(HELLO_SYSTEM)} is set to either
address@hidden or @file{hello-generic.lo} in
address@hidden/configure}.
 
-For each library, the @address@hidden variable contains the
-names of extra libtool objects (@file{.lo} files) to add to the shared
-library.  The @address@hidden variable contains any
-additional libtool flags, such as @samp{-version-info} or
address@hidden
+Or we could simply use an Automake conditional as follows.
 
address@hidden
+lib_LTLIBRARIES = libhello.la
+libhello_la_SOURCES = hello-common.c
+if LINUX
+libhello_la_SOURCES += hello-linux.c
+else
+libhello_la_SOURCES += hello-generic.c
+endif
address@hidden example
+
address@hidden Libtool Convenience Libraries, Libtool Modules, Conditional 
Libtool Sources, A Shared Library
address@hidden Libtool Convenience Libraries
address@hidden convenience libraries, libtool
address@hidden libtool convenience libraries
address@hidden noinst_LTLIBRARIES
address@hidden check_LTLIBRARIES
+
+Sometimes you want to build libtool libraries which should not be
+installed.  These are called @dfn{libtool convenience libraries} and
+are typically used to encapsulate many sublibraries, later gathered
+into one big installed library.
+
+Libtool convenience libraries are declared by
address@hidden, @code{check_LTLIBRARIES}, or even
address@hidden  Unlike installed libtool libraries they do
+not need an @code{-rpath} flag at link time (actually this is the only
+difference).
+
+Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
+built.  Those listed in @code{check_LTLIBRARIES} are built only upon
address@hidden check}.  Finally, libraries listed in
address@hidden are never built explicitly: Automake outputs
+rules to build them, but if the library does not appear as a Makefile
+dependency anywhere it won't be built (this is why
address@hidden is used for conditional compilation).
+
+Here is a sample setup merging libtool convenience libraries from
+subdirectories into one main @file{libtop.la} library.
+
address@hidden
+# -- Top-level Makefile.am --
+SUBDIRS = sub1 sub2 @dots{}
+lib_LTLIBRARIES = libtop.la
+libtop_la_SOURCES =
+libtop_la_LIBADD = \
+  sub1/libsub1.la \
+  sub2/libsub2.la \
+  @dots{}
+
+# -- sub1/Makefile.am --
+noinst_LTLIBRARIES = libsub1.la
+libsub1_la_SOURCES = @dots{}
+
+# -- sub2/Makefile.am --
+# showing nested convenience libraries
+SUBDIRS = sub2.1 sub2.2 @dots{}
+noinst_LTLIBRARIES = libsub2.la
+libsub2_la_SOURCES =
+libsub2_la_LIBADD = \
+  sub21/libsub21.la \
+  sub22/libsub22.la \
+  @dots{}
address@hidden example
+
address@hidden Libtool Modules, Libtool Flags, Libtool Convenience Libraries, A 
Shared Library
address@hidden Libtool Modules
address@hidden modules, libtool
address@hidden libtool modules
address@hidden -module, libtool
+
+These are libtool libraries meant to be dlopened.  They are
+indicated to libtool by passing @code{-module} at link-time.
+
address@hidden
+pkglib_LTLIBRARIES = mymodule.la
+mymodule_la_SOURCES = doit.c
+mymodule_LDFLAGS = -module
address@hidden example
+
+Ordinarily, Automake requires that a Library's name starts with
address@hidden  However, when building a dynamically loadable module you
+might wish to use a "nonstandard" name.
+
address@hidden Libtool Flags, LTLIBOBJ, Libtool Modules, A Shared Library
address@hidden _LIBADD and _LDFLAGS
address@hidden _LIBADD, libtool
address@hidden _LDFLAGS, libtool
+
+As shown in previous sections, the @address@hidden
+variable should be used to list extra libtool objects (@file{.lo}
+files) or libtool libraries (@file{.la}) to add to @var{library}.
+
+The @address@hidden variable is the place to list
+additional libtool flags, such as @samp{-version-info},
address@hidden, and a lot more.  See @xref{Link mode, , Using libltdl,
+libtool, The Libtool Manual}.
+
address@hidden LTLIBOBJ, Libtool Issues, Libtool Flags, A Shared Library
address@hidden @code{LTLIBOBJS}
 @cindex @code{LTLIBOBJS}, special handling
address@hidden LTLIBOBJS
address@hidden LIBOBJS
address@hidden AC_LIBOBJ
 
 Where an ordinary library might include @code{$(LIBOBJS)}, a libtool
 library must use @code{$(LTLIBOBJS)}.  This is required because the
 object files that libtool operates on do not necessarily end in
address@hidden  The libtool manual contains more details on this topic.
address@hidden
 
-For libraries installed in some directory, Automake will automatically
-supply the appropriate @samp{-rpath} option.  However, for libraries
-determined at configure time (and thus mentioned in
address@hidden), Automake does not know the eventual
-installation directory; for such libraries you must add the
address@hidden option to the appropriate @samp{_LDFLAGS} variable by
-hand.
+Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
+performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
address@hidden vs. @code{LIBOBJS}, autoconf, The Autoconf Manual}).
+
address@hidden Libtool Issues,  , LTLIBOBJ, A Shared Library
address@hidden Common Issues Related to Libtool's Use
+
address@hidden @code{required file `./ltmain.sh' not found}
address@hidden ltmain.sh not found
address@hidden libtoolize, no longer run by Automake
address@hidden libtoolize and autoreconf
address@hidden autoreconf and libtoolize
address@hidden bootstrap.sh and autoreconf
address@hidden autogen.sh and autoreconf
+
+Libtool comes with a tool called @command{libtoolize} that will
+install libtool's supporting files into a package.  Running this
+command will install @file{ltmain.sh}.  You should execute it before
address@hidden and @command{automake}.
+
+People upgrading old packages to newer autotools are likely to face
+this issue because older Automake versions used to call
address@hidden  Therefore old build scripts do not call
address@hidden
+
+Since Automake 1.6, it has been decided that running
address@hidden was none of Automake's business.  Instead, that
+functionality has been moved into the @command{autoreconf} command
+(@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
+The Autoconf Manual}).  If you do not want to remember what to run and
+when, just learn the @command{autoreconf} command.  Hopefully,
+replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
+a call to @command{autoreconf} should also free you from any similar
+incompatible change in the future.
+
address@hidden Objects @code{created with both libtool and without}
+
+Sometimes, the same source file is used both to build a libtool
+library and to build another non-libtool target (be it a program or
+another library).
 
-Ordinarily, Automake requires that a shared library's name start with
address@hidden  However, if you are building a dynamically loadable module
-then you might wish to use a "nonstandard" name.  In this case, put
address@hidden into the @samp{_LDFLAGS} variable.
+Let's consider the following @file{Makefile.am}.
 
address@hidden Automake, Using Automake with Libtool, The Libtool Manual,
-libtool, The Libtool Manual}, for more information.
address@hidden
+bin_PROGRAMS = prog
+prog_SOURCES = prog.c foo.c @dots{}
 
+lib_LTLIBRARIES = libfoo.la
+libfoo_la_SOURCES = foo.c @dots{}
address@hidden example
+
address@hidden
+(In this trivial case the issue could be avoided by linking
address@hidden with @file{prog} instead of listing @file{foo.c} in
address@hidden  But let's assume we really want to keep
address@hidden and @file{libfoo.la} separate.)
+
+Technically, it means that we should build @file{foo.$(OBJEXT)} for
address@hidden, and @file{foo.lo} for @file{libfoo.la}.  The problem is
+that in the course of creating @file{foo.lo}, libtool may erase (or
+replace) @file{foo.$(OBJEXT)} -- and this cannot be avoided.
+
+Therefore, when Automake detects this situation it will complain
+with a message such as
address@hidden
+object `foo.$(OBJEXT)' created both with libtool and without
address@hidden example
+
+A workaround for this issue is to ensure that these two objects get
+different basenames.  As explained in @ref{renamed objects}, this
+happens automatically when per-targets flags are used.
+
address@hidden
+bin_PROGRAMS = prog
+prog_SOURCES = prog.c foo.c @dots{}
+prog_CFLAGS = $(AM_CFLAGS)
+
+lib_LTLIBRARIES = libfoo.la
+libfoo_la_SOURCES = foo.c @dots{}
address@hidden example
+
address@hidden
+Adding @code{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
+when the @code{prog_CFLAGS} is defined, it is used instead of
address@hidden  However as a side effect it will cause
address@hidden and @file{foo.c} to be compiled as
address@hidden(OBJEXT)} and @file{prog-foo.$(OBJEXT)} which solves
+the issue.
 
 @node Program and Library Variables, LIBOBJS, A Shared Library, Programs
 @section Program and Library Variables
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.443.2.35
diff -u -r1.443.2.35 Makefile.am
--- tests/Makefile.am   24 Jul 2003 21:27:17 -0000      1.443.2.35
+++ tests/Makefile.am   30 Jul 2003 22:11:34 -0000
@@ -266,6 +266,9 @@
 lisp3.test \
 lisp4.test \
 listval.test \
+ltcond.test \
+ltcond2.test \
+ltconv.test \
 ltdeps.test \
 ltlibobjs.test \
 maintclean.test \
Index: tests/ltcond.test
===================================================================
RCS file: tests/ltcond.test
diff -N tests/ltcond.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/ltcond.test   30 Jul 2003 22:11:34 -0000
@@ -0,0 +1,108 @@
+#!/bin/sh
+# Copyright (C) 2003  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# Test for conditional libtool libraries.
+# This combines two examples from the manual.
+
+required='libtoolize gcc'
+. ./defs || exit 1
+
+set -e
+
+cat >>configure.in <<'END'
+AM_CONDITIONAL([WANT_LIBFOO], [true])
+AM_CONDITIONAL([WANT_LIBBAR], [false])
+AC_SUBST([WANTEDLIBS], ['lib1foo.la lib1bar.la'])
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+EXTRA_LTLIBRARIES = lib1foo.la lib1bar.la lib3bar.la
+lib_LTLIBRARIES = $(WANTEDLIBS)
+lib1foo_la_SOURCES = foo.c
+lib1foo_la_LDFLAGS = -rpath '$(libdir)'
+lib1bar_la_SOURCES = bar.c
+lib1bar_la_LDFLAGS = -rpath '$(libdir)'
+lib3bar_la_SOURCES = bar.c
+
+if WANT_LIBFOO
+lib_LTLIBRARIES += lib2foo.la
+check_LTLIBRARIES = lib3foo.la
+endif
+if WANT_LIBBAR
+lib_LTLIBRARIES += lib2bar.la
+endif
+lib2foo_la_SOURCES = foo.c
+lib2bar_la_SOURCES = bar.c
+lib3foo_la_SOURCES = foo.c
+END
+
+echo 'int one () { return 1; }' >foo.c
+echo 'int two () { return 2; }' >bar.c
+
+mkdir empty
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+# Install libraries in lib/, and the rest in empty/.
+# (in fact there is no "rest", so as the name imply empty/ is
+# expected to remain empty).
+./configure --prefix=`pwd`/empty --libdir=`pwd`/lib
+
+$MAKE
+test -f lib1foo.la
+test -f lib1bar.la
+test -f lib2foo.la
+test ! -f lib2bar.la
+test ! -f lib3foo.la
+test ! -f lib3bar.la
+
+$MAKE check
+test ! -f lib2bar.la
+test -f lib3foo.la
+test ! -f lib3bar.la
+
+$MAKE install
+test -f lib/lib1foo.la
+test -f lib/lib1bar.la
+test -f lib/lib2foo.la
+test -f lib/lib3foo.la
+find empty -type f -print > empty.lst
+cat empty.lst
+test 0 = `wc -l < empty.lst`
+
+$MAKE uninstall
+find lib -type f -print > lib.lst
+test 0 = `wc -l < lib.lst`
+test -f lib1foo.la
+test -f lib1bar.la
+test -f lib2foo.la
+test -f lib3foo.la
+
+$MAKE clean
+test ! -f lib1foo.la
+test ! -f lib1bar.la
+test ! -f lib2foo.la
+test ! -f lib3foo.la
Index: tests/ltcond2.test
===================================================================
RCS file: tests/ltcond2.test
diff -N tests/ltcond2.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/ltcond2.test  30 Jul 2003 22:11:34 -0000
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2003  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# Test for bug in conditionals.
+
+required='libtoolize gcc'
+. ./defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AC_SUBST([HELLO_SYSTEM], [hello-generic.lo])
+AM_CONDITIONAL([LINUX], true)
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libhello.la
+libhello_la_SOURCES = hello-common.c
+EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
+libhello_la_LIBADD = $(HELLO_SYSTEM)
+libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
+
+lib_LTLIBRARIES += libhello2.la
+libhello2_la_SOURCES = hello-common.c
+if LINUX
+libhello2_la_SOURCES += hello-linux.c
+else
+libhello2_la_SOURCES += hello-generic.c
+endif
+
+bin_PROGRAMS = hello hello2
+hello_SOURCES = main.c
+hello_LDADD = libhello.la
+hello2_SOURCES = main.c
+hello2_LDADD = libhello2.la
+
+check-local:
+       ./hello$(EXEEXT) | grep hello-generic
+       ./hello2$(EXEEXT) | grep hello-linux
+       : > check-ok
+END
+
+echo 'char* str() { return "hello-linux"; }' >hello-linux.c
+echo 'char* str() { return "hello-generic"; }' >hello-generic.c
+cat >hello-common.c <<'END'
+#include <stdio.h>
+char* str();
+void print()
+{
+  puts (str ());
+}
+END
+echo 'int main() { print(); return 0; }' >main.c
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE check
+test -f check-ok
Index: tests/ltconv.test
===================================================================
RCS file: tests/ltconv.test
diff -N tests/ltconv.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/ltconv.test   30 Jul 2003 22:11:34 -0000
@@ -0,0 +1,159 @@
+#!/bin/sh
+# Copyright (C) 2003  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# Test for libtool convenience libraries.
+# This example is taken from the manual.
+
+required='libtoolize gcc'
+. ./defs || exit 1
+
+set -e
+
+cat >>configure.in <<'END'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AC_CONFIG_FILES(sub1/Makefile
+               sub2/Makefile
+               sub2/sub21/Makefile
+               sub2/sub22/Makefile)
+AC_OUTPUT
+END
+
+mkdir sub1
+mkdir sub2
+mkdir sub2/sub21
+mkdir sub2/sub22
+mkdir empty
+
+cat >Makefile.am <<'END'
+SUBDIRS = sub1 sub2
+lib_LTLIBRARIES = libtop.la
+libtop_la_SOURCES =
+libtop_la_LIBADD = \
+  sub1/libsub1.la \
+  sub2/libsub2.la
+
+bin_PROGRAMS = ltconvtest
+ltconvtest_SOURCES = test.c
+ltconvtest_LDADD = libtop.la
+
+check-local:
+       ./ltconvtest$(EXEEXT)
+       : > check-ok
+installcheck-local:
+       $(bindir)/ltconvtest$(EXEEXT)
+       : > installcheck-ok
+END
+
+cat >sub1/Makefile.am <<'END'
+noinst_LTLIBRARIES = libsub1.la
+libsub1_la_SOURCES = sub1.c
+END
+
+echo 'int sub1 () { return 1; }' > sub1/sub1.c
+
+cat >sub2/Makefile.am <<'END'
+SUBDIRS = sub21 sub22
+noinst_LTLIBRARIES = libsub2.la
+libsub2_la_SOURCES = sub2.c
+libsub2_la_LIBADD = \
+  sub21/libsub21.la \
+  sub22/libsub22.la
+END
+
+echo 'int sub2 () { return 2; }' > sub2/sub2.c
+
+cat >sub2/sub21/Makefile.am <<'END'
+noinst_LTLIBRARIES = libsub21.la
+libsub21_la_SOURCES = sub21.c
+END
+
+echo 'int sub21 () { return 21; }' > sub2/sub21/sub21.c
+
+cat >sub2/sub22/Makefile.am <<'END'
+noinst_LTLIBRARIES = libsub22.la
+libsub22_la_SOURCES = sub22.c
+END
+
+echo 'int sub22 () { return 22; }' > sub2/sub22/sub22.c
+
+cat >test.c <<EOF
+#include <stdio.h>
+int main ()
+{
+  if (1 != sub1 ())
+    return 1;
+  if (2 != sub2 ())
+    return 2;
+  if (21 != sub21 ())
+    return 3;
+  if (22 != sub22 ())
+    return 4;
+  return 0;
+}
+EOF
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+# Install libraries in lib/, programs in bin/, and the rest in empty/.
+# (in fact there is no "rest", so as the name imply empty/ is
+# expected to remain empty).
+./configure --prefix=`pwd`/empty --libdir=`pwd`/lib --bindir=`pwd`/bin
+
+$MAKE
+test -f libtop.la
+test -f sub1/libsub1.la
+test -f sub2/libsub2.la
+test -f sub2/sub21/libsub21.la
+test -f sub2/sub22/libsub22.la
+$MAKE check
+test -f check-ok
+rm check-ok
+
+$MAKE install
+test -f lib/libtop.la
+$MAKE installcheck
+test -f installcheck-ok
+rm installcheck-ok
+
+find empty -type f -print > empty.lst
+cat empty.lst
+test 0 = `wc -l < empty.lst`
+
+$MAKE clean
+test ! -f libtop.la
+test ! -f sub1/libsub1.la
+test ! -f sub2/libsub2.la
+test ! -f sub2/sub21/libsub21.la
+test ! -f sub2/sub22/libsub22.la
+test ! -f ltconvtest
+
+$MAKE installcheck
+test -f installcheck-ok
+rm installcheck-ok
+
+$MAKE uninstall
+find lib -type f -print > lib.lst
+test 0 = `wc -l < lib.lst`
+find bin -type f -print > bin.lst
+test 0 = `wc -l < bin.lst`

-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]