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

[fedora-virt] [PATCH] Make it possible to build in a separate directory



Attached fixes up some build related things. Note that I'm not convinced that the debirf will work if the build directory isn't the top level, and I haven't been able to test. However, the behaviour shouldn't be changed if you aren't using a separate build directory.

Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team

M:       +44 (0)7977 267231
GPG ID:  D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
>From 44fcbed6e42718948f831030e96ae00f96469217 Mon Sep 17 00:00:00 2001
From: Matthew Booth <mbooth redhat com>
Date: Fri, 3 Jul 2009 11:52:50 +0100
Subject: [PATCH] Make it possible to build in a separate directory

This patch allows you to do:
mkdir build
cd build
../configure ...
make

This will output all generated files to the build directory. Given that
autogen automatically runs configure, you can also do:

BUILDDIR=./build ./autogen.sh

which will do the right thing.

Also:

* Fix a dependency bug which means that guestfs_protocol.h
  isn't automatically rebuilt.
* Re-running autogen.sh with no arguments won't blow away your previous
  configure arguments.
---
 appliance/Makefile.am  |    1 +
 appliance/make.sh.in   |    7 ++++---
 appliance/update.sh.in |    2 +-
 autogen.sh             |   26 +++++++++++++++++++-------
 capitests/Makefile.am  |    3 +--
 configure.ac           |    2 +-
 daemon/Makefile.am     |    4 ++--
 daemon/configure.ac    |    2 +-
 examples/Makefile.am   |    4 ++--
 fish/Makefile.am       |    2 +-
 images/Makefile.am     |   20 +++++++++++++++++---
 inspector/Makefile.am  |    7 ++++---
 java/Makefile.am       |   28 ++++++++++++++--------------
 ocaml/Makefile.am      |    8 ++++++--
 perl/Makefile.PL.in    |    5 +++--
 perl/Makefile.am       |    4 ++--
 python/Makefile.am     |    5 +++--
 ruby/Makefile.am       |    6 +++---
 ruby/Rakefile.in       |   16 ++++++++--------
 src/Makefile.am        |    8 ++++++--
 src/generator.ml       |    2 +-
 21 files changed, 100 insertions(+), 62 deletions(-)

diff --git a/appliance/Makefile.am b/appliance/Makefile.am
index 9de11cd..f488708 100644
--- a/appliance/Makefile.am
+++ b/appliance/Makefile.am
@@ -109,6 +109,7 @@ debirf_symlinks = \
 noinst_DATA = $(debirf_symlinks:%=debian/modules/%)
 $(debirf_symlinks:%=debian/modules/%): stamp-debirf-modules
 stamp-debirf-modules:
+	mkdir -p debian/modules
 	for f in $(debirf_symlinks); do \
 	  ln -sf /usr/share/debirf/modules/$$f debian/modules/$$f; \
 	done
diff --git a/appliance/make.sh.in b/appliance/make.sh.in
index cf772e0..d8c0e90 100755
--- a/appliance/make.sh.in
+++ b/appliance/make.sh.in
@@ -21,6 +21,7 @@
 unset CDPATH
 
 set -e
+set -x
 
 if [ "@DIST@" = "REDHAT" ]; then
   cd @top_builddir@
@@ -65,8 +66,8 @@ if [ "@DIST@" = "REDHAT" ]; then
   # Don't need any keyboard maps.
   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/kbd
 
-  # Remove anything in home directory.  Because this is potentially
-  # liable to monstrous fuck-ups, we don't put a slash before 'home'.
+  # Remove anything in home directory.  Because of the potential for disaster
+  # we don't put a slash before 'home'.
   (cd initramfs && echo home/*) |
     xargs @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
 
@@ -139,7 +140,7 @@ __EOF__
   cd appliance && bash update.sh
 
 elif [ "@DIST@" = "DEBIAN" ]; then
-  cd @top_builddir@/appliance
+  cd @abs_top_builddir@/appliance
   debirf make -n debian
 fi
 
diff --git a/appliance/update.sh.in b/appliance/update.sh.in
index 01e22b6..31d0db9 100755
--- a/appliance/update.sh.in
+++ b/appliance/update.sh.in
@@ -28,7 +28,7 @@ if [ "@DIST@" = "REDHAT" ]; then
   output=appliance/initramfs  REPO@  host_cpu@.img
 
   # Create the init script.
-  @FEBOOTSTRAP_INSTALL@ initramfs appliance/init /init 0755 root.root
+  @FEBOOTSTRAP_INSTALL@ initramfs @abs_top_srcdir@/appliance/init /init 0755 root.root
 
   # Copy the daemon into the filesystem.
   @FEBOOTSTRAP_INSTALL@ initramfs daemon/guestfsd /sbin/guestfsd 0755 root.root
diff --git a/autogen.sh b/autogen.sh
index a1d7e27..ba4612c 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -20,12 +20,24 @@
 
 set -e
 set -v
-export AUTOMAKE='automake --foreign'
+
 mkdir -p daemon/m4
-aclocal
-libtoolize
-autoreconf -i
-pushd daemon
 autoreconf -i
-popd
-./configure "$@"
+
+CONFIGUREDIR=.
+
+# Run configure in BUILDDIR if it's set
+if [ ! -z "$BUILDDIR" ]; then
+    mkdir -p $BUILDDIR
+    cd $BUILDDIR
+
+    CONFIGUREDIR=..
+fi
+
+# If no arguments were specified and configure has run before, use the previous
+# arguments
+if [ $# == 0 -a -x ./config.status ]; then
+    ./config.status --recheck
+else
+    $CONFIGUREDIR/configure "$@"
+fi
diff --git a/capitests/Makefile.am b/capitests/Makefile.am
index 5a10a92..dd2e556 100644
--- a/capitests/Makefile.am
+++ b/capitests/Makefile.am
@@ -24,8 +24,7 @@ EXTRA_DIST = \
 check_PROGRAMS = tests test-command
 
 tests_SOURCES = tests.c
-tests_CFLAGS = \
-	-I$(top_builddir)/src -Wall
+tests_CFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src -Wall
 tests_LDADD = $(top_builddir)/src/libguestfs.la
 
 TESTS = tests
diff --git a/configure.ac b/configure.ac
index 4a57fa3..f0eba8a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 AC_INIT([libguestfs],[1.0.55])
-AM_INIT_AUTOMAKE
+AM_INIT_AUTOMAKE([foreign])
 
 AC_CONFIG_MACRO_DIR([m4])
 
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 141dfad..846a95c 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -67,7 +67,7 @@ guestfsd_SOURCES = \
 	wc.c \
 	zero.c \
 	zerofree.c \
-	../src/guestfs_protocol.h \
-	../src/guestfs_protocol.c
+	$(top_builddir)/../src/guestfs_protocol.h \
+	$(top_builddir)/../src/guestfs_protocol.c
 
 guestfsd_CFLAGS = -Wall
diff --git a/daemon/configure.ac b/daemon/configure.ac
index 6ecbb8a..238532e 100644
--- a/daemon/configure.ac
+++ b/daemon/configure.ac
@@ -16,7 +16,7 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 AC_INIT([libguestfs-daemon],[1.0.0])
-AM_INIT_AUTOMAKE
+AM_INIT_AUTOMAKE([foreign])
 
 AC_CONFIG_MACRO_DIR([m4])
 
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 13302d9..fb3d656 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -3,11 +3,11 @@
 noinst_PROGRAMS = hello to-xml
 
 hello_SOURCES = hello.c
-hello_CFLAGS = -I$(top_builddir)/src -Wall
+hello_CFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src -Wall
 hello_LDADD = $(top_builddir)/src/libguestfs.la
 
 to_xml_SOURCES = to-xml.c
-to_xml_CFLAGS = -I$(top_builddir)/src -Wall
+to_xml_CFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src -Wall
 to_xml_LDADD = $(top_builddir)/src/libguestfs.la
 
 CLEANFILES = $(noinst_PROGRAMS)
diff --git a/fish/Makefile.am b/fish/Makefile.am
index 03e872c..1439a5d 100644
--- a/fish/Makefile.am
+++ b/fish/Makefile.am
@@ -32,6 +32,6 @@ guestfish_SOURCES = \
 	time.c
 
 guestfish_CFLAGS = \
-	-I$(top_builddir)/src -Wall \
+	-I$(top_srcdir)/src -I$(top_builddir)/src -Wall \
 	-DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"'
 guestfish_LDADD = $(top_builddir)/src/libguestfs.la $(LIBREADLINE)
diff --git a/images/Makefile.am b/images/Makefile.am
index 8855382..9353e17 100644
--- a/images/Makefile.am
+++ b/images/Makefile.am
@@ -28,9 +28,23 @@ CLEANFILES = \
 	100kallzeroes 100kallnewlines 100kallspaces 100krandom 10klines \
 	initrd
 
-squash_files = helloworld.tar helloworld.tar.gz empty known-1 known-2 known-3 \
-	100kallzeroes 100kallnewlines 100kallspaces 100krandom 10klines \
-	initrd
+squash_files_src = \
+    $(srcdir)/helloworld.tar \
+    $(srcdir)/helloworld.tar.gz \
+    $(srcdir)/empty \
+    $(srcdir)/known-1 \
+    $(srcdir)/known-2 \
+    $(srcdir)/known-3
+
+squash_files_build = \
+    $(builddir)/100kallzeroes \
+    $(builddir)/100kallnewlines \
+    $(builddir)/100kallspaces \
+    $(builddir)/100krandom \
+    $(builddir)/10klines \
+    $(builddir)/initrd
+
+squash_files = $(squash_files_src) $(squash_files_build)
 
 test.sqsh: $(squash_files)
 	rm -f $@
diff --git a/inspector/Makefile.am b/inspector/Makefile.am
index b43870d..a1df2ab 100644
--- a/inspector/Makefile.am
+++ b/inspector/Makefile.am
@@ -23,7 +23,7 @@ if HAVE_INSPECTOR
 
 man_MANS = virt-inspector.1
 
-noinst_DATA = ../html/virt-inspector.1.html
+noinst_DATA = @top_builddir@/html/virt-inspector.1.html
 
 virt-inspector.1: virt-inspector.pl
 	$(POD2MAN) \
@@ -32,8 +32,9 @@ virt-inspector.1: virt-inspector.pl
 	  --release "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" \
 	  $< > $@
 
-../html/virt-inspector.1.html: virt-inspector.pl
-	cd .. && pod2html \
+ top_builddir@/html/virt-inspector.1.html: virt-inspector.pl
+	mkdir -p @top_builddir@/html
+	cd @top_builddir@ && pod2html \
 	  --css 'pod.css' \
 	  --title 'virt-inspector, display OS version, kernel, drivers, mount points, applications, etc. in a virtual machine' \
 	  --htmldir html \
diff --git a/java/Makefile.am b/java/Makefile.am
index ea90a48..b682747 100644
--- a/java/Makefile.am
+++ b/java/Makefile.am
@@ -15,18 +15,18 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-CPTH = com/redhat/et/libguestfs
+java_prefix = com/redhat/et/libguestfs
 
 java_sources = \
-	$(CPTH)/LibGuestFSException.java \
-	$(CPTH)/IntBool.java \
-	$(CPTH)/PV.java \
-	$(CPTH)/VG.java \
-	$(CPTH)/LV.java \
-	$(CPTH)/Stat.java \
-	$(CPTH)/StatVFS.java \
-	$(CPTH)/Dirent.java \
-	$(CPTH)/GuestFS.java
+	$(java_prefix)/LibGuestFSException.java \
+	$(java_prefix)/IntBool.java \
+	$(java_prefix)/PV.java \
+	$(java_prefix)/VG.java \
+	$(java_prefix)/LV.java \
+	$(java_prefix)/Stat.java \
+	$(java_prefix)/StatVFS.java \
+	$(java_prefix)/Dirent.java \
+	$(java_prefix)/GuestFS.java
 
 java_tests = \
 	Bindtests.java \
@@ -50,7 +50,7 @@ libguestfs_jardir = $(JAR_INSTALL_DIR)
 libguestfs_jar_DATA = libguestfs-${VERSION}.jar
 libguestfs_jar_class_files = $(java_sources:.java=.class)
 $(libguestfs_jar_class_files): %.class: %.java
-	$(JAVAC) $(JAVAC_FLAGS) -classpath $(CPTH) $(java_sources)
+	$(JAVAC) $(JAVAC_FLAGS) -d @builddir@ -classpath @srcdir@:@builddir@ -sourcepath @srcdir@:@builddir@ $<
 
 libguestfs-${VERSION}.jar: $(libguestfs_jar_class_files)
 	$(JAR) cf $@ $^
@@ -64,12 +64,12 @@ libguestfs_jni_la_SOURCES = \
 
 libguestfs_jni_la_LIBADD = $(top_builddir)/src/libguestfs.la
 libguestfs_jni_la_LDFLAGS = -version-info $(JNI_VERSION_INFO)
-libguestfs_jni_la_CFLAGS = -Wall -I$(top_builddir)/src $(JNI_CFLAGS)
+libguestfs_jni_la_CFLAGS = -Wall -I$(top_srcdir)/src -I$(top_builddir)/src $(JNI_CFLAGS)
 
 BUILT_SOURCES = com_redhat_et_libguestfs_GuestFS.h
 
-com_redhat_et_libguestfs_GuestFS.h: $(CPTH)/GuestFS.class
-	$(JAVAH) -classpath .:$(CPTH) com.redhat.et.libguestfs.GuestFS
+com_redhat_et_libguestfs_GuestFS.h: $(java_prefix)/GuestFS.class
+	$(JAVAH) -classpath @srcdir@:@builddir@ com.redhat.et.libguestfs.GuestFS
 
 # Documentation.
 
diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index bed1f92..bf9760c 100644
--- a/ocaml/Makefile.am
+++ b/ocaml/Makefile.am
@@ -39,10 +39,10 @@ mlguestfs.cmxa: guestfs_c.o guestfs_c_actions.o guestfs.cmx
 	$(OCAMLMKLIB) -o mlguestfs $^ -L$(top_builddir)/src/.libs -lguestfs
 
 guestfs_c.o: guestfs_c.c
-	$(CC) $(CFLAGS) -I$(OCAMLLIB) -I$(top_builddir)/src -fPIC -Wall -c $<
+	$(CC) $(CFLAGS) -I$(OCAMLLIB) -I$(top_srcdir)/ocaml -I$(top_srcdir)/src -I$(top_builddir)/src -fPIC -Wall -c $<
 
 guestfs_c_actions.o: guestfs_c_actions.c
-	$(CC) $(CFLAGS) -I$(OCAMLLIB) -I$(top_builddir)/src -fPIC -Wall -c $<
+	$(CC) $(CFLAGS) -I$(OCAMLLIB) -I$(top_srcdir)/ocaml -I$(top_srcdir)/src -I$(top_builddir)/src -fPIC -Wall -c $<
 
 TESTS_ENVIRONMENT = \
 	LD_LIBRARY_PATH=$(top_builddir)/src/.libs \
@@ -60,15 +60,19 @@ bindtests: bindtests.ml mlguestfs.cmxa
 	$(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@
 
 t/guestfs_005_load: t/guestfs_005_load.ml mlguestfs.cmxa
+	mkdir -p t
 	$(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@
 
 t/guestfs_010_launch: t/guestfs_010_launch.ml mlguestfs.cmxa
+	mkdir -p t
 	$(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@
 
 t/guestfs_050_lvcreate: t/guestfs_050_lvcreate.ml mlguestfs.cmxa
+	mkdir -p t
 	$(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@
 
 t/guestfs_060_readdir: t/guestfs_060_readdir.ml mlguestfs.cmxa
+	mkdir -p t
 	$(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@
 
 .mli.cmi:
diff --git a/perl/Makefile.PL.in b/perl/Makefile.PL.in
index 40d1d6c..d18aba6 100644
--- a/perl/Makefile.PL.in
+++ b/perl/Makefile.PL.in
@@ -23,7 +23,8 @@ WriteMakefile (
     NAME => 'Sys::Guestfs',
     VERSION => '@PACKAGE_VERSION@',
 
-    LIBS => '-L abs_top_builddir@/src/.libs -lguestfs',
-    INC => '-I abs_top_builddir@/src',
+    LIBS => '-L top_builddir@/src/.libs -lguestfs',
+    INC => '-I top_builddir@/src -I top_srcdir@/src',
+    TYPEMAPS => [ '@srcdir@/typemap' ],
     CCFLAGS => '@CFLAGS@',
     );
diff --git a/perl/Makefile.am b/perl/Makefile.am
index 747ac43..66d1d4b 100644
--- a/perl/Makefile.am
+++ b/perl/Makefile.am
@@ -36,8 +36,8 @@ if HAVE_PERL
 TESTS = run-bindtests run-perl-tests
 
 TESTS_ENVIRONMENT = \
-	LD_LIBRARY_PATH=../src/.libs \
-	LIBGUESTFS_PATH=../appliance
+	LD_LIBRARY_PATH=$(top_builddir)/src/.libs \
+	LIBGUESTFS_PATH=$(top_builddir)/appliance
 
 INSTALLDIRS = site
 
diff --git a/python/Makefile.am b/python/Makefile.am
index dcd0625..2928f98 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -32,12 +32,13 @@ python_DATA = guestfs.py
 python_LTLIBRARIES = libguestfsmod.la
 
 libguestfsmod_la_SOURCES = guestfs-py.c
-libguestfsmod_la_CFLAGS = -Wall -I$(PYTHON_INCLUDEDIR) -I$(top_builddir)/src
+libguestfsmod_la_CFLAGS = -Wall -I$(PYTHON_INCLUDEDIR) \
+			  -I$(top_srcdir)/src -I$(top_builddir)/src
 libguestfsmod_la_LIBADD = $(top_builddir)/src/libguestfs.la
 
 TESTS_ENVIRONMENT = \
 	LIBGUESTFS_PATH=$(top_builddir)/appliance \
-	PYTHONPATH=$(top_builddir)/python:$(top_builddir)/python/.libs
+	PYTHONPATH=$(builddir):$(builddir)/.libs
 
 TESTS = run-bindtests run-python-tests
 
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 389399f..7ea0107 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -40,10 +40,10 @@ if HAVE_RUBY
 TESTS = run-bindtests run-ruby-tests
 
 TESTS_ENVIRONMENT = \
-	LD_LIBRARY_PATH=../src/.libs \
-	LIBGUESTFS_PATH=../appliance
+	LD_LIBRARY_PATH=$(top_builddir)/src/.libs \
+	LIBGUESTFS_PATH=$(top_builddir)/appliance
 
 all:
 	rake build
 
-endif
\ No newline at end of file
+endif
diff --git a/ruby/Rakefile.in b/ruby/Rakefile.in
index 67f6b17..b09a52b 100644
--- a/ruby/Rakefile.in
+++ b/ruby/Rakefile.in
@@ -24,22 +24,22 @@ require 'rake/gempackagetask'
 PKG_NAME='@PACKAGE_NAME@'
 PKG_VERSION='@PACKAGE_VERSION@'
 
-EXT_CONF='ext/guestfs/extconf.rb'
-MAKEFILE='ext/guestfs/Makefile'
-GUESTFS_MODULE='ext/guestfs/_guestfs.so'
-GUESTFS_SRC='ext/guestfs/_guestfs.c'
+EXT_CONF='@srcdir@/ext/guestfs/extconf.rb'
+MAKEFILE='@builddir@/ext/guestfs/Makefile'
+GUESTFS_MODULE='@builddir@/ext/guestfs/_guestfs.so'
+GUESTFS_SRC='@builddir@/ext/guestfs/_guestfs.c'
 
-CLEAN.include [ "ext/**/*.o", GUESTFS_MODULE,
-                "ext/**/depend" ]
+CLEAN.include [ "@builddir@/ext/**/*.o", GUESTFS_MODULE,
+                "@builddir@/ext/**/depend" ]
 
-CLOBBER.include [ "config.save", "ext/**/mkmf.log",
+CLOBBER.include [ "@builddir@/config.save", "@builddir@/ext/**/mkmf.log",
                   MAKEFILE ]
 
 # Build locally
 
 file MAKEFILE => EXT_CONF do |t|
     Dir::chdir(File::dirname(EXT_CONF)) do
-         unless sh "ruby #{File::basename(EXT_CONF)} --with-_guestfs-include=../../../src --with-_guestfs-lib=../../../src/.libs"
+         unless sh "ruby #{File::basename(EXT_CONF)} --with-_guestfs-include= abs_top_srcdir@/src --with-_guestfs-lib= abs_top_builddir@/src/.libs"
              $stderr.puts "Failed to run extconf"
              break
          end
diff --git a/src/Makefile.am b/src/Makefile.am
index 1c0fa0a..9dc8e99 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,8 +30,10 @@ EXTRA_DIST = \
 noinst_DATA = stamp-generator
 
 stamp-generator: generator.ml
-	mkdir -p $(top_srcdir)/perl/lib/Sys
-	cd .. && ocaml -warn-error A $(srcdir)/src/$<
+	mkdir -p $(top_builddir)/perl/lib/Sys
+	mkdir -p $(top_builddir)/ruby/ext/guestfs
+	mkdir -p $(top_builddir)/java/com/redhat/et/libguestfs
+	cd $(top_builddir) && ocaml -warn-error A ./src/$<
 
 guestfs_protocol.x: stamp-generator
 
@@ -83,6 +85,8 @@ lib_LTLIBRARIES = libguestfs.la
 
 BUILT_SOURCES = \
   guestfs_protocol.x \
+  guestfs_protocol.c \
+  guestfs_protocol.h \
   guestfs-structs.h \
   guestfs-actions.h \
   guestfs-actions.c \
diff --git a/src/generator.ml b/src/generator.ml
index c65e717..ee915fd 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -8607,7 +8607,7 @@ let output_to filename =
 let () =
   check_functions ();
 
-  if not (Sys.file_exists "configure.ac") then (
+  if not (Sys.file_exists "config.status") then (
     eprintf "\
 You are probably running this from the wrong directory.
 Run it from the top source directory using the command
-- 
1.6.2.5


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