bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] Document how to use multiple instances of gnulib


From: Christian Egli
Subject: [PATCH] Document how to use multiple instances of gnulib
Date: Fri, 04 Sep 2015 12:06:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

* doc/gnulib-tool.texi: Add a section to the manual outlining how two
instances of gnulib with different modules can be used, for example one
for a lib and another one for associated tools.
---
 doc/gnulib-tool.texi | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)

diff --git a/doc/gnulib-tool.texi b/doc/gnulib-tool.texi
index f749abb..93b269a 100644
--- a/doc/gnulib-tool.texi
+++ b/doc/gnulib-tool.texi
@@ -44,6 +44,7 @@ a real run without changing anything.
 * Modified imports::            Changing the import specification.
 * Simple update::               Tracking Gnulib development.
 * Source changes::              Impact of Gnulib on your source files.
+* Multiple instances::          Using Gnulib for both a library and a binary
 * gettextize and autopoint::    Caveat: @code{gettextize} and @code{autopoint} 
users!
 * Localization::                Handling Gnulib's own message translations.
 * VCS Issues::                  Integration with Version Control Systems.
@@ -448,6 +449,114 @@ used to set system dependent flags (such as 
@code{_GNU_SOURCE} on GNU systems),
 and these flags have no effect after any system header file has been included.
 
 
address@hidden Multiple instances
address@hidden Using Gnulib for both a library and a binary
+
+Your project might build both a library and some accompanying binaries
+in the same source tree. In that case you might want to use different
+modules for the library than for the binaries. Typically the binaries
+might want to make use of @code{getopt-posix} or @code{version-etc},
+while the library wants to stay clear of these modules for technical
+or licensing reasons.
+
+Let's assume that your project contains a @file{lib} directory where
+the source of the library resides and a @file{src} directory for the
+sources of the binaries as follows.
+
address@hidden
+.
+|-- configure.ac
+|-- lib
+|   |-- foo.c
+|   `-- Makefile.am
+|-- Makefile.am
+`-- src
+    |-- bar.c
+    `-- Makefile.am
address@hidden example
+
+You can now add two instances of Gnulib to your project in separate
+source trees:
+
address@hidden
+~/src/libfoo$ gnulib-tool --import --lib=libgnu --source-base=gnulib \
+              --m4-base=gnulib/m4 --macro-prefix=gl strndup
+~/src/libfoo$ gnulib-tool --import --lib=libgnutools \
+              --source-base=src/gnulib --m4-base=src/gnulib/m4 \
+              --macro-prefix=gl_tools getopt-gnu
address@hidden example
+
+The first one will import the module @code{strndup} in @file{gnulib}
+and the second one will import @code{getopt-gnu} in @file{src/gnulib}
+and you will end up with the following source tree (many files omitted
+in the interest of brevity):
+
address@hidden
+.
+|-- configure.ac
+|-- gnulib
+|   |-- m4
+|   |-- strndup.c
+|-- lib
+|   |-- foo.c
+|   `-- Makefile.am
+|-- Makefile.am
+`-- src
+    |-- bar.c
+    |-- gnulib
+    |   |-- getopt.c
+    |   |-- getopt.in.h
+    |   |-- m4
+    `-- Makefile.am
address@hidden example
+
+Integration with your code is basically the same as outlined in
address@hidden import} with the one exception that you have to add both
+the macro @code{gl_EARLY} and the macro @code{gl_tools_EARLY} to your
address@hidden (and of course also both macros @code{gl_INIT} and
address@hidden). Obviously the name of the second macro is
+dependent on the value of the @option{--macro-prefix} option in your
address@hidden invocation.
+
address@hidden
+...
+AC_PROG_CC
+gl_EARLY
+gl_tools_EARLY
+...
+# For gnulib.
+gl_INIT
+gl_tools_INIT
+...
address@hidden example
+
+Also as outlined in @ref{Initial import} you will have to add compiler
+and linker flags. For the library you might have to add something
+along the line of the following to your @file{Makefile.am}:
+
address@hidden
+...
+AM_CPPFLAGS = -I$(top_srcdir)/gnulib -I$(top_builddir)/gnulib
+...
+libfoo_la_LIBADD = $(top_builddir)/gnulib/libgnu.la
+...
address@hidden example
+
+Correspondingly for the binary you will have to add something along
+the lines of to the following:
+
address@hidden
+...
+AM_CPPFLAGS = -I$(top_srcdir)/src/gnulib -I$(top_builddir)/src/gnulib
+...
+LIBADD = $(top_builddir)/src/gnulib/libgnutools.la
+...
address@hidden example
+
+The name of the library that you have pass in the linker option
+depends on the @option{--lib} option in @command{gnulib-tool}
+invocation.
+
 @node gettextize and autopoint
 @section Caveat: @code{gettextize} and @code{autopoint} users
 
-- 
2.1.4




reply via email to

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