From 349814e9d912c4f372b8fbdfb10b03749911021f Mon Sep 17 00:00:00 2001 From: Matthew Booth 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 | 5 +++-- 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 +- haskell/Makefile.am | 4 ++-- 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 | 24 +++++++++++------------- src/Makefile.am | 8 ++++++-- src/generator.ml | 2 +- 22 files changed, 104 insertions(+), 68 deletions(-) diff --git a/appliance/Makefile.am b/appliance/Makefile.am index e2b0b31..7abee80 100644 --- a/appliance/Makefile.am +++ b/appliance/Makefile.am @@ -105,6 +105,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 57f5223..a132ed8 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 diff --git a/appliance/update.sh.in b/appliance/update.sh.in index 01e22b6..cdc441b 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 appliance/@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/haskell/Makefile.am b/haskell/Makefile.am index 3cb721f..dcaf18a 100644 --- a/haskell/Makefile.am +++ b/haskell/Makefile.am @@ -30,7 +30,7 @@ TESTS = run-bindtests Guestfs005Load Guestfs010Launch Guestfs050LVCreate check_DATA = Bindtests -GHCFLAGS = -I$(abs_top_builddir)/src -L$(abs_top_builddir)/src/.libs +GHCFLAGS = -I$(top_builddir)/src -L$(top_builddir)/src/.libs Bindtests: Bindtests.hs Guestfs.hs $(GHC) $(GHCFLAGS) -main-is $(shell basename $@) --make -o $@ $< -lguestfs @@ -44,4 +44,4 @@ Guestfs010Launch: Guestfs010Launch.hs Guestfs.hs Guestfs050LVCreate: Guestfs050LVCreate.hs Guestfs.hs $(GHC) $(GHCFLAGS) -main-is $(shell basename $@) --make -o $@ $< -lguestfs -endif \ No newline at end of file +endif 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..076efd8 100644 --- a/ruby/Rakefile.in +++ b/ruby/Rakefile.in @@ -24,26 +24,24 @@ 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" - $stderr.puts "Failed to run extconf" - break - end - end + unless sh "top_srcdir=$(pwd)/@top_srcdir@; top_builddir=$(pwd)/@top_builddir@; cd #{File::dirname(EXT_CONF)}; ruby #{File::basename(EXT_CONF)} --with-_guestfs-include=$top_srcdir --with-_guestfs-lib=$top_builddir/src/.libs" + $stderr.puts "Failed to run extconf" + break + end end file GUESTFS_MODULE => [ MAKEFILE, GUESTFS_SRC ] do |t| Dir::chdir(File::dirname(EXT_CONF)) do 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 5c9e1c3..e86fce1 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.8.3.1