build: Fix inter-directory dependencies
authorMatthew Booth <mbooth@redhat.com>
Thu, 19 Nov 2009 16:10:00 +0000 (16:10 +0000)
committerRichard Jones <rjones@redhat.com>
Thu, 19 Nov 2009 16:40:22 +0000 (16:40 +0000)
This change adds an explicit dependency on generator.ml for every file it
generates, except java files. Java is left for another time because it's
considerably trickier.

It also adds a build rule for src/libguestfs.la so it can be rebuilt as required
from other directories.

It does this by creating a top level make file, subdir-rules.mk, which can be
included from sub-directories. sub-directories need to define 'generator_built'
to include local files which are built by generator.ml, and they will be updated
automatically.

This fixes parallel make, and will automatically re-create generated files when
make is run from any directory.

It also fixes the problem which efad4f53 was targetting. Specifically,
src/guestfs_protocol.(c|h) had an erroneous dependency on stamp-generator, and
therefore generator.ml, despite not being directly created by it. This caused
them to be recreated every time generator.ml ran rather than only when
src/guestfs_protocol.x was updated, which cascaded into a daemon and therefore
appliance update.

This patch also changes the contents of the distribution tarball by including
files created by rpcgen.

20 files changed:
Makefile.am
appliance/Makefile.am
capitests/Makefile.am
daemon/Makefile.am
examples/Makefile.am
fish/Makefile.am
fuse/Makefile.am
haskell/Makefile.am
images/Makefile.am
inspector/Makefile.am
java/Makefile.am
ocaml/Makefile.am
perl/Makefile.am
python/Makefile.am
regressions/Makefile.am
ruby/Makefile.am
src/Makefile.am
subdir-rules.mk [new file with mode: 0644]
test-tool/Makefile.am
tools/Makefile.am

index 87efb2d..9332a10 100644 (file)
@@ -15,6 +15,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
 ACLOCAL_AMFLAGS = -I m4
 
 SUBDIRS = gnulib/lib hivex src daemon appliance fish po examples images \
@@ -54,9 +56,15 @@ if HAVE_HASKELL
 SUBDIRS += haskell
 endif
 
+generator_built = \
+       guestfs-structs.pod \
+       guestfs-actions.pod \
+       guestfish-actions.pod
+
 EXTRA_DIST = \
-       guestfs.pod guestfs-actions.pod guestfs-structs.pod \
-       guestfish.pod guestfish-actions.pod \
+       $(generator_built) \
+       guestfs.pod \
+       guestfish.pod \
        html/pod.css \
        HACKING TODO \
        libguestfs.pc libguestfs.pc.in \
index b9bf953..bf1183d 100644 (file)
@@ -15,6 +15,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
 EXTRA_DIST = \
        libguestfs-supermin-helper \
        kmod.whitelist.in \
index 3b80c0e..74bfab0 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-EXTRA_DIST = \
-       tests.c
+include $(top_srcdir)/subdir-rules.mk
+
+generator_built = tests.c
+
+BUILT_SOURCES = $(generator_built)
+
+EXTRA_DIST = $(BUILT_SOURCES)
 
 # Tests.  These are auto-generated from the test descriptions
 # in the generator.
index d049da6..1716c2f 100644 (file)
@@ -19,6 +19,25 @@ ACLOCAL_AMFLAGS = -I m4
 
 SUBDIRS = lib tests .
 
+libsrcdir = $(top_builddir)/../src
+
+generator_built = \
+       actions.h \
+       stubs.c \
+       names.c
+
+.PHONY: force
+
+$(generator_built): force
+       $(MAKE) -C $(libsrcdir) stamp-generator
+
+BUILT_SOURCES = $(generator_built)
+
+EXTRA_DIST = $(BUILT_SOURCES)
+
+$(libsrcdir)/guestfs_protocol.o: force
+       $(MAKE) -C $(libsrcdir) guestfs_protocol.o
+
 noinst_PROGRAMS = guestfsd
 guestfsd_SOURCES = \
        actions.h \
@@ -83,11 +102,8 @@ guestfsd_SOURCES = \
        wc.c \
        xattr.c \
        zero.c \
-       zerofree.c \
-       $(top_builddir)/../src/guestfs_protocol.h \
-       $(top_builddir)/../src/guestfs_protocol.c
+       zerofree.c
+guestfsd_LDADD = $(libsrcdir)/guestfs_protocol.o lib/libgnu.a
 
 AM_CPPFLAGS = -I$(srcdir)/lib -Ilib
 guestfsd_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
-
-LDADD = lib/libgnu.a
index adbb934..04bbe5e 100644 (file)
@@ -1,5 +1,7 @@
 # libguestfs examples
 
+include $(top_srcdir)/subdir-rules.mk
+
 noinst_PROGRAMS = hello to-xml
 
 hello_SOURCES = hello.c
index c8ba3ea..795952a 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
 bin_PROGRAMS = guestfish
 
+generator_built = \
+       cmds.c \
+       completion.c
+
+BUILT_SOURCES = \
+       $(generator_built) \
+       rc_protocol.h \
+       rc_protocol.c
+
 EXTRA_DIST = \
+       $(BUILT_SOURCES) \
        rc_protocol.x
 
-CLEANFILES = rc_protocol.c rc_protocol.h
-
 guestfish_SOURCES = \
+       $(generator_built) \
        alloc.c \
-       cmds.c \
-       completion.c \
        destpaths.c \
        echo.c \
        edit.c \
@@ -44,10 +53,6 @@ guestfish_SOURCES = \
 librc_protocol_la_SOURCES = rc_protocol.c
 librc_protocol_la_CFLAGS = -Wall -Wno-unused
 
-BUILT_SOURCES = \
-       rc_protocol.c \
-       rc_protocol.h
-
 guestfish_CFLAGS = \
        -I$(top_srcdir)/src -I$(top_builddir)/src \
        -I$(top_srcdir)/fish -I$(top_builddir)/fish \
index d582c65..5ffdb95 100644 (file)
@@ -15,6 +15,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
 EXTRA_DIST = guestmount.pod test-fuse.sh
 
 if HAVE_FUSE
index dcaf18a..1836a14 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-EXTRA_DIST = *.hs run-bindtests
+include $(top_srcdir)/subdir-rules.mk
+
+generator_built = \
+       Guestfs.hs \
+       Bindtests.hs
+
+# $(generator_built) isn't redundant below as the wildcard rule won't match, and
+# therefore won't generate, the files if they haven't been created yet
+EXTRA_DIST = $(generator_built) *.hs run-bindtests
 
 CLEANFILES = *~
 
@@ -32,6 +40,8 @@ check_DATA = Bindtests
 
 GHCFLAGS = -I$(top_builddir)/src -L$(top_builddir)/src/.libs
 
+all: Bindtests Guestfs005Load Guestfs010Launch Guestfs050LVCreate
+
 Bindtests: Bindtests.hs Guestfs.hs
        $(GHC)  $(GHCFLAGS) -main-is $(shell basename $@) --make -o $@ $< -lguestfs
 
index ff6bc5d..c30d8c4 100644 (file)
@@ -15,6 +15,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
 # Old RHEL 5 autoconf doesn't have builddir.
 builddir ?= $(top_builddir)/images
 
index 058e565..0878725 100644 (file)
@@ -15,6 +15,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
 EXTRA_DIST = \
        run-inspector-locally \
        virt-inspector \
index 6ddf8b4..abd11ee 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
 # Old RHEL 5 autoconf doesn't have builddir.
 builddir ?= $(top_builddir)/java
 
+# XXX: Need to fix generator.ml dependencies
+#
+# Files generated by generator.ml:
+#   Makefile.inc
+#   All files listed in Makefile.inc
+#   com_redhat_et_libguestfs_GuestFS.c
+#   Bindtests.java
+
 java_prefix = com/redhat/et/libguestfs
 
 # Pull in automatically generated built sources
index bb7407a..5b51497 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
+generator_built = \
+       guestfs.mli \
+       guestfs.ml \
+       guestfs_c_actions.c \
+       bindtests.ml
+
 EXTRA_DIST = \
-       guestfs.mli guestfs.ml \
-       guestfs_c.c guestfs_c.h guestfs_c_actions.c \
+       $(generator_built) \
+       guestfs_c.c guestfs_c.h \
        guestfs_inspector.mli guestfs_inspector.ml \
        .depend META.in \
-       bindtests.ml \
        run-bindtests \
        t/*.ml
 
index 4b7ed99..b766244 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
+generator_built = \
+       Guestfs.xs \
+       lib/Sys/Guestfs.pm \
+       bindtests.pl
+
 EXTRA_DIST = \
+       $(generator_built) \
        Makefile.PL.in \
-       Guestfs.xs \
        examples/README \
        examples/LICENSE \
        examples/*.pl \
-       lib/Sys/Guestfs.pm \
        lib/Sys/Guestfs/Lib.pm \
        run-bindtests \
        run-perl-tests \
-       bindtests.pl \
        t/*.t \
        typemap
 
@@ -42,7 +47,7 @@ TESTS_ENVIRONMENT = \
 
 INSTALLDIRS = site
 
-all: Makefile-pl
+all: Makefile-pl $(generator_built)
        $(MAKE) -f Makefile-pl
 
 Makefile-pl: Makefile.PL
index da52cfa..519bda7 100644 (file)
 # Old RHEL 5 autoconf doesn't have builddir.
 builddir ?= $(top_builddir)/python
 
-EXTRA_DIST = \
-       guestfs.py \
+include $(top_srcdir)/subdir-rules.mk
+
+generator_built = \
        guestfs-py.c \
-       bindtests.py \
+       guestfs.py \
+       bindtests.py
+
+EXTRA_DIST = \
+       $(generator_built) \
        run-bindtests \
        run-python-tests \
        t/*.py
index 058b60d..7ceb0ce 100644 (file)
@@ -21,6 +21,8 @@
 #
 # See also capitests/
 
+include $(top_srcdir)/subdir-rules.mk
+
 TESTS = \
        rhbz503169c10.sh \
        rhbz503169c13.sh \
index 7ea0107..82d130d 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
+generator_built = \
+       ext/guestfs/_guestfs.c \
+       bindtests.rb
+
 EXTRA_DIST = \
+       $(generator_built) \
        Rakefile.in \
-       ext/guestfs/_guestfs.c \
        ext/guestfs/extconf.rb \
        lib/guestfs.rb \
        run-bindtests \
        run-ruby-tests \
-       bindtests.rb \
        tests/tc_*.rb
 
 CLEANFILES = \
@@ -43,7 +48,7 @@ TESTS_ENVIRONMENT = \
        LD_LIBRARY_PATH=$(top_builddir)/src/.libs \
        LIBGUESTFS_PATH=$(top_builddir)/appliance
 
-all:
+all: $(generator_built)
        rake build
 
 endif
index 2774ffc..f3abe35 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-EXTRA_DIST = \
+include $(top_srcdir)/subdir-rules.mk
+
+generator_built = \
        guestfs_protocol.x \
+       guestfs-structs.h \
+       guestfs-actions.h \
+       guestfs-internal-actions.h \
+       guestfs-actions.c \
+       guestfs-bindtests.c
+
+$(generator_built): stamp-generator
+
+BUILT_SOURCES = \
+  $(generator_built) \
+  guestfs_protocol.c \
+  guestfs_protocol.h
+
+EXTRA_DIST = \
+       $(BUILT_SOURCES) \
        MAX_PROC_NR \
        stamp-generator \
-       generator.ml \
-       guestfs-internal-actions.h
+       generator.ml
 
 # Rerun the generator if it has changed.
 # Git removes empty directories, so in cases where the
@@ -34,21 +50,10 @@ stamp-generator: generator.ml
        mkdir -p $(top_srcdir)/java/com/redhat/et/libguestfs
        cd $(top_srcdir) && ocaml -warn-error A src/generator.ml
 
-$(BUILT_SOURCES): stamp-generator
-
 include_HEADERS = guestfs.h guestfs-actions.h guestfs-structs.h
 
 lib_LTLIBRARIES = libguestfs.la
 
-BUILT_SOURCES = \
-  guestfs_protocol.x \
-  guestfs_protocol.c \
-  guestfs_protocol.h \
-  guestfs-structs.h \
-  guestfs-actions.h \
-  guestfs-actions.c \
-  guestfs-bindtests.c
-
 # This convenience library is solely to avoid compiler warnings
 # in its generated sources.
 libprotocol_la_SOURCES = \
@@ -57,8 +62,6 @@ libprotocol_la_SOURCES = \
 
 libprotocol_la_CFLAGS =
 
-CLEANFILES = guestfs_protocol.c guestfs_protocol.h
-
 # From the libtool info file, with comments:
 #
 # |  1. Start with version information of `0:0:0' for each libtool library.
diff --git a/subdir-rules.mk b/subdir-rules.mk
new file mode 100644 (file)
index 0000000..fd8bfef
--- /dev/null
@@ -0,0 +1,29 @@
+# libguestfs
+# Copyright (C) 2009 Red Hat Inc.
+#
+# This program 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# Define a force dependency which will always be rebuilt
+.PHONY: force
+
+# Rebuild rules for common dependencies
+$(top_builddir)/src/libguestfs.la: force
+       $(MAKE) -C $(top_builddir)/src libguestfs.la
+
+# Automatically build targets defined in generator_built
+# generator_built is defined in individual Makefiles
+$(generator_built): $(top_builddir)/src/stamp-generator
+$(top_builddir)/src/stamp-generator: force
+       $(MAKE) -C $(top_builddir)/src stamp-generator
index 510a42f..d58f137 100644 (file)
@@ -15,6 +15,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
 EXTRA_DIST = libguestfs-test-tool.pod
 
 CLEANFILES =
index f48edae..3055ab7 100644 (file)
@@ -15,6 +15,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+include $(top_srcdir)/subdir-rules.mk
+
 tools = cat df edit ls rescue tar win-reg
 
 EXTRA_DIST = \