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

[Libguestfs] using gnulib from daemon/



Hi Rich,

Prompted by your "New commands to list devices by UUID and label"
patch, I've adjusted it to use gnulib.

While just compiling hash.[ch] is probably ok, in general (given the
strict requirements of libguestfs) using the C files of a module is
usually not an option, since you don't get the benefit of the module's
m4 tests or automake snippets.  For other modules, those pieces
are often required.

To integrate gnulib into a project like this is not hard at all:

I ran this one-time command:

  ../.gnulib/gnulib-tool --import --with-tests hash

That created the file, daemon/m4/gnulib-cache.m4,
which I've git-added in the patch below.
It records the names of modules we're using
(currently only "hash") as well as a few other things,
including the fact that I told it to include unit tests.
That latter option creates and populates the tests/ directory.
The other new directory is lib/.

I added the SUBDIRS line in Makefile.am to build in those
directories and the corresponding */Makefile names in configure.ac.

Now that gnulib-cache.m4 records state, to update from gnulib
in the future, you'd just run this, perhaps from an ./autogen.sh script:
(I haven't done that yet)

  ../.gnulib/gnulib-tool --update

Also, I added the usual AC_CONFIG_AUX_DIR([build-aux])
directive to configure.ac so that all of the auxilliary
files pulled in by autoreconf don't clutter the daemon/ directory.

The only other change was the always-required-with-gnulib one
to add these two lines to configure.ac:

  gl_EARLY
  gl_INIT

If you apply this on top of yours, it should still build,
with no change in binary size, and it will then be trivial
to add a few more gnulib modules.

>From 21c185b04a41f61c06a64d1d4076aff4a98d0d40 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering redhat com>
Date: Wed, 5 Aug 2009 05:59:19 -0400
Subject: [PATCH] daemon: use gnulib

* Makefile.am (SUBDIRS): Define.
(AM_CPPFLAGS): Define, to include from gnulib's lib/
(LDADD): Define, to link with gnulib's libgnu.a.
* configure.ac: Use AC_CONFIG_AUX_DIR([build-aux]), gl_EARLY, gl_INIT.
(AC_CONFIG_FILES): Add lib/Makefile and tests/Makefile
* m4/gnulib-cache.m4: New file, generated by running
../.gnulib/gnulib-tool --import --with-tests hash
* .gitignore: Ignore all of the imported files.
---
 daemon/.gitignore         |   29 +++++++++++++++++++++++++++++
 daemon/Makefile.am        |   10 ++++++----
 daemon/configure.ac       |    6 +++++-
 daemon/m4/gnulib-cache.m4 |   35 +++++++++++++++++++++++++++++++++++
 4 files changed, 75 insertions(+), 5 deletions(-)
 create mode 100644 daemon/.gitignore
 create mode 100644 daemon/m4/gnulib-cache.m4

diff --git a/daemon/.gitignore b/daemon/.gitignore
new file mode 100644
index 0000000..7f60faf
--- /dev/null
+++ b/daemon/.gitignore
@@ -0,0 +1,29 @@
+build-aux
+lib
+link-warning.h
+m4/00gnulib.m4
+m4/errno_h.m4
+m4/error.m4
+m4/exitfail.m4
+m4/extensions.m4
+m4/gnulib-common.m4
+m4/gnulib-comp.m4
+m4/gnulib-tool.m4
+m4/hash.m4
+m4/include_next.m4
+m4/inline.m4
+m4/inttostr.m4
+m4/longlong.m4
+m4/multiarch.m4
+m4/onceonly.m4
+m4/stdbool.m4
+m4/stdint.m4
+m4/stdlib_h.m4
+m4/strerror.m4
+m4/string_h.m4
+m4/unistd_h.m4
+m4/wchar.m4
+m4/wchar_t.m4
+m4/wint_t.m4
+m4/xalloc.m4
+tests
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 0fec611..090338d 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -17,6 +17,8 @@

 ACLOCAL_AMFLAGS = -I m4

+SUBDIRS = lib tests .
+
 noinst_PROGRAMS = guestfsd
 guestfsd_SOURCES = \
 	actions.h \
@@ -75,8 +77,8 @@ guestfsd_SOURCES = \
 	zero.c \
 	zerofree.c \
 	$(top_builddir)/../src/guestfs_protocol.h \
-	$(top_builddir)/../src/guestfs_protocol.c \
-	$(srcdir)/../.gnulib/lib/hash.h \
-	$(srcdir)/../.gnulib/lib/hash.c
+	$(top_builddir)/../src/guestfs_protocol.c

-guestfsd_CFLAGS = -Wall -I$(srcdir)/../.gnulib/lib
+AM_CPPFLAGS = -I$(srcdir)/lib -Ilib
+guestfsd_CFLAGS = -Wall
+LDADD = lib/libgnu.a
diff --git a/daemon/configure.ac b/daemon/configure.ac
index 3bfd2ed..126e125 100644
--- a/daemon/configure.ac
+++ b/daemon/configure.ac
@@ -16,6 +16,7 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 AC_INIT([libguestfs-daemon],[1.0.0])
+AC_CONFIG_AUX_DIR([build-aux])
 AM_INIT_AUTOMAKE([foreign])

 AC_CONFIG_MACRO_DIR([m4])
@@ -41,6 +42,9 @@ AC_PROG_CC
 AC_PROG_INSTALL
 AC_PROG_CPP

+gl_EARLY
+gl_INIT
+
 AC_C_PROTOTYPES
 test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])

@@ -86,5 +90,5 @@ AC_CHECK_HEADERS([attr/xattr.h sys/xattr.h])

 dnl Produce output files.
 AC_CONFIG_HEADERS([config.h])
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile lib/Makefile tests/Makefile])
 AC_OUTPUT
diff --git a/daemon/m4/gnulib-cache.m4 b/daemon/m4/gnulib-cache.m4
new file mode 100644
index 0000000..8aa504a
--- /dev/null
+++ b/daemon/m4/gnulib-cache.m4
@@ -0,0 +1,35 @@
+# Copyright (C) 2002-2009 Free Software Foundation, Inc.
+#
+# This file is free software, distributed under the terms of the GNU
+# General Public License.  As a special exception to the GNU General
+# Public License, this file may be distributed as part of a program
+# that contains a configuration script generated by Autoconf, under
+# the same distribution terms as the rest of that program.
+#
+# Generated by gnulib-tool.
+#
+# This file represents the specification of how gnulib-tool is used.
+# It acts as a cache: It is written and read by gnulib-tool.
+# In projects using CVS, this file is meant to be stored in CVS,
+# like the configure.ac and various Makefile.am files.
+
+
+# Specification in the form of a command-line invocation:
+#   gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --with-tests --no-libtool --macro-prefix=gl hash
+
+# Specification in the form of a few gnulib-tool.m4 macro invocations:
+gl_LOCAL_DIR([])
+gl_MODULES([
+  hash
+])
+gl_AVOID([])
+gl_SOURCE_BASE([lib])
+gl_M4_BASE([m4])
+gl_PO_BASE([])
+gl_DOC_BASE([doc])
+gl_TESTS_BASE([tests])
+gl_WITH_TESTS
+gl_LIB([libgnu])
+gl_MAKEFILE_NAME([])
+gl_MACRO_PREFIX([gl])
+gl_PO_DOMAIN([])
--
1.6.4.226.g08063


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