Index: AUTHORS
===================================================================
RCS file: /cvsroot/build-common/cdbs/AUTHORS,v
retrieving revision 1.3
diff -u -p -r1.3 AUTHORS
--- AUTHORS	31 May 2003 16:53:36 -0000	1.3
+++ AUTHORS	4 Jun 2003 21:01:25 -0000
@@ -1,3 +1,4 @@
 walters: Colin Walters <walters@debian.org>
 ccheney: Chris Cheney <ccheney@debian.org>
 js: Jonas Smedegaard <dr@jones.dk>
+jbailey: Jeff Bailey <jbailey@debian.org>
Index: 1/class/autotools.mk.in
===================================================================
RCS file: /cvsroot/build-common/cdbs/1/class/autotools.mk.in,v
retrieving revision 1.9
diff -u -p -r1.9 autotools.mk.in
--- 1/class/autotools.mk.in	2 Jun 2003 07:30:24 -0000	1.9
+++ 1/class/autotools.mk.in	4 Jun 2003 21:01:25 -0000
@@ -14,10 +14,10 @@ include $(_cdbs_class_path)/makefile.mk$
 DEB_MAKE_INSTALL_TARGET := install DESTDIR=$(DEB_DESTDIR)
 DEB_MAKE_CLEAN_TARGET := distclean
 
-DEB_AC_AUX_DIR ?= $(CURDIR)
+DEB_AC_AUX_DIR ?= $(DEB_SRCDIR)
 
-DEB_CONFIGURE_SCRIPT ?= ./configure 
-DEB_CONFIGURE_INVOKE ?= $(DEB_CONFIGURE_SCRIPT) --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=$(DEB_CONFIGURE_PREFIX) --includedir=$(DEB_CONFIGURE_INCLUDEDIR) --mandir=$(DEB_CONFIGURE_MANDIR) --infodir=$(DEB_CONFIGURE_INFODIR) --sysconfdir=$(DEB_CONFIGURE_SYSCONFDIR) --localstatedir=$(DEB_CONFIGURE_LOCALSTATEDIR) --libexecdir=$(DEB_CONFIGURE_LIBEXECDIR) --disable-maintainer-mode
+DEB_CONFIGURE_SCRIPT ?= $(DEB_SRCDIR)/configure 
+DEB_CONFIGURE_INVOKE ?= (cd $(DEB_BUILDDIR) && $(CURDIR)/$(DEB_CONFIGURE_SCRIPT) --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=$(DEB_CONFIGURE_PREFIX) --includedir=$(DEB_CONFIGURE_INCLUDEDIR) --mandir=$(DEB_CONFIGURE_MANDIR) --infodir=$(DEB_CONFIGURE_INFODIR) --sysconfdir=$(DEB_CONFIGURE_SYSCONFDIR) --localstatedir=$(DEB_CONFIGURE_LOCALSTATEDIR) --libexecdir=$(DEB_CONFIGURE_LIBEXECDIR) --disable-maintainer-mode)
 DEB_CONFIGURE_PREFIX ?=/usr
 DEB_CONFIGURE_INCLUDEDIR ?= "\$${prefix}/include"
 DEB_CONFIGURE_MANDIR ?="\$${prefix}/share/man"
@@ -48,10 +48,10 @@ clean::
 	if [ -r $(DEB_AC_AUX_DIR)/config.guess.cdbs-orig ]; then \
 	  mv $(DEB_AC_AUX_DIR)/config.guess.cdbs-orig $(DEB_AC_AUX_DIR)/config.guess; \
 	fi
-	if [ -f config.log ] && grep -i 'generated.*by.*autoconf' config.log 1>/dev/null; then \
-	  rm -f config.log; \
+	if [ -f $(DEB_BUILDDIR)/config.log ] && grep -i 'generated.*by.*autoconf' $(DEB_BUILDDIR)/config.log 1>/dev/null; then \
+	  rm -f $(DEB_BUILDDIR)/config.log; \
 	fi
-	if test -f config.status && grep -i -q 'Generated.*by configure.' config.status; then rm -f config.status; fi
-	if test -f config.cache && grep -i -q 'shell.*script.*caches.*results.*configure' config.cache; then rm -f config.cache; fi
+	if test -f $(DEB_BUILDDIR)/config.status && grep -i -q 'Generated.*by configure.' $(DEB_BUILDDIR)/config.status; then rm -f $(DEB_BUILDDIR)/config.status; fi
+	if test -f $(DEB_BUILDDIR)/config.cache && grep -i -q 'shell.*script.*caches.*results.*configure' $(DEB_BUILDDIR)/config.cache; then rm -f $(DEB_BUILDDIR)/config.cache; fi
 
 endif
Index: 1/class/docbookxml.mk.in
===================================================================
RCS file: /cvsroot/build-common/cdbs/1/class/docbookxml.mk.in,v
retrieving revision 1.2
diff -u -p -r1.2 docbookxml.mk.in
--- 1/class/docbookxml.mk.in	2 Jun 2003 19:36:54 -0000	1.2
+++ 1/class/docbookxml.mk.in	4 Jun 2003 21:01:25 -0000
@@ -12,9 +12,9 @@ _cdbs_class_docbookxml := 1
 include $(_cdbs_rules_path)/buildcore.mk$(_cdbs_makefile_suffix)
 
 common-build::
-	find -name '*.xml' -exec perl -i -pe 's,http://www.oasis-open.org/docbook/xml/([^/])/docbookx.dtd,/usr/share/sgml/docbook/dtd/xml/\1/docbookx.dtd,' {} \;
+	find $(DEB_SRCDIR) -name '*.xml' -exec perl -i -pe 's,http://www.oasis-open.org/docbook/xml/([^/])/docbookx.dtd,/usr/share/sgml/docbook/dtd/xml/\1/docbookx.dtd,' {} \;
 
 clean::
-	find -name '*.xml' -exec perl -i -pe 's,/usr/share/sgml/docbook/dtd/xml/([^/])/docbookx.dtd,http://www.oasis-open.org/docbook/xml/\1/docbookx.dtd,' {} \;
+	find $(DEB_SRCDIR) -name '*.xml' -exec perl -i -pe 's,/usr/share/sgml/docbook/dtd/xml/([^/])/docbookx.dtd,http://www.oasis-open.org/docbook/xml/\1/docbookx.dtd,' {} \;
 
 endif
Index: 1/class/gnome.mk.in
===================================================================
RCS file: /cvsroot/build-common/cdbs/1/class/gnome.mk.in,v
retrieving revision 1.5
diff -u -p -r1.5 gnome.mk.in
--- 1/class/gnome.mk.in	2 Jun 2003 21:12:39 -0000	1.5
+++ 1/class/gnome.mk.in	4 Jun 2003 21:01:25 -0000
@@ -16,6 +16,6 @@ DEB_MAKE_ENVVARS += GCONF_DISABLE_MAKEFI
 
 # Most GNOME upstreams don't bother to fix this.
 clean::
-	rm -f intltool-extract intltool-merge intltool-update po/.intltool-merge-cache
+	(cd $(DEB_BUILDDIR) && rm -f intltool-extract intltool-merge intltool-update po/.intltool-merge-cache)
 
 endif
Index: 1/class/makefile.mk.in
===================================================================
RCS file: /cvsroot/build-common/cdbs/1/class/makefile.mk.in,v
retrieving revision 1.7
diff -u -p -r1.7 makefile.mk.in
--- 1/class/makefile.mk.in	2 Jun 2003 07:30:41 -0000	1.7
+++ 1/class/makefile.mk.in	4 Jun 2003 21:01:25 -0000
@@ -12,7 +12,7 @@ _cdbs_class_makefile := 1
 include $(_cdbs_class_path)/langcore.mk$(_cdbs_makefile_suffix)
 
 DEB_MAKE_ENVVARS ?= 
-DEB_MAKE_INVOKE ?= $(DEB_MAKE_ENVVARS) make CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" 
+DEB_MAKE_INVOKE ?= $(DEB_MAKE_ENVVARS) make -C $(DEB_BUILDDIR) CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" 
 
 # This variable is deprecated.
 DEB_BUILD_MAKE_TARGET ?= 
@@ -46,7 +46,7 @@ clean::
 
 common-install::
 	if test -n "$(DEB_MAKE_INSTALL_TARGET)"; then \
-	  $(DEB_MAKE_ENVVARS) make $(DEB_MAKE_INSTALL_TARGET); \
+	  $(DEB_MAKE_ENVVARS) make -C $(DEB_BUILDDIR) $(DEB_MAKE_INSTALL_TARGET); \
 	 else \
 	   echo "DEB_MAKE_INSTALL_TARGET unset, skipping default makefile.mk common-install target"; \
 	 fi
Index: 1/class/perlmodule.mk.in
===================================================================
RCS file: /cvsroot/build-common/cdbs/1/class/perlmodule.mk.in,v
retrieving revision 1.3
diff -u -p -r1.3 perlmodule.mk.in
--- 1/class/perlmodule.mk.in	2 Jun 2003 19:36:54 -0000	1.3
+++ 1/class/perlmodule.mk.in	4 Jun 2003 21:01:25 -0000
@@ -11,8 +11,12 @@ _cdbs_class_perlmodule := 1
 
 include $(_cdbs_class_path)/langcore.mk$(_cdbs_makefile_suffix)
 
+ifneq ($(DEB_BUILDDIR),$(DEB_SRCDIR))
+DEB_BUILDDIR and DEB_SRCDIR must the same for Perl builds.
+fi
+
 DEB_MAKE_ENVVARS ?= 
-DEB_MAKE_INVOKE ?= $(DEB_MAKE_ENVVARS) make OPTIMIZE="$(CFLAGS)"
+DEB_MAKE_INVOKE ?= $(DEB_MAKE_ENVVARS) make -C $(DEB_BUILDDIR) OPTIMIZE="$(CFLAGS)"
 
 DEB_MAKE_BUILD_TARGET ?= all
 
@@ -34,7 +38,7 @@ DEB_MAKEMAKER_INVOKE ?= /usr/bin/perl Ma
 
 common-configure:: Makefile
 Makefile:
-	$(DEB_MAKEMAKER_INVOKE) $(DEB_MAKEMAKER_USER_FLAGS)
+	(cd $(DEB_BUILDDIR) && $(DEB_MAKEMAKER_INVOKE) $(DEB_MAKEMAKER_USER_FLAGS) )
 
 common-build:: debian/stamp-perlmodule
 debian/stamp-perlmodule:
@@ -49,7 +53,7 @@ clean::
 	rm -f debian/stamp-perlmodule
 
 common-install::
-	$(DEB_MAKE_ENVVARS) make $(DEB_MAKE_INSTALL_TARGET)
+	$(DEB_MAKE_ENVVARS) make -C $(DEB_BUILDDIR) $(DEB_MAKE_INSTALL_TARGET)
 
 test::
 	$(DEB_MAKE_INVOKE) $(DEB_MAKE_TEST_TARGET)
Index: 1/rules/buildcore.mk.in
===================================================================
RCS file: /cvsroot/build-common/cdbs/1/rules/buildcore.mk.in,v
retrieving revision 1.8
diff -u -p -r1.8 buildcore.mk.in
--- 1/rules/buildcore.mk.in	2 Jun 2003 19:36:54 -0000	1.8
+++ 1/rules/buildcore.mk.in	4 Jun 2003 21:01:25 -0000
@@ -19,11 +19,19 @@ testdir:
 testroot:
 	test `id -u` = 0
 
+makebuilddir:
+	if [ ! -d $(DEB_BUILDDIR) ]; then \
+	  mkdir $(DEB_BUILDDIR); \
+	fi
+
+cleanbuilddir:
+	-rmdir $(DEB_BUILDDIR)
+
 # This target is called before almost anything else happens.  It's a good place
 # to do stuff like unpack extra source tarballs, apply patches, and stuff.  In
 # the future it will be a good place to generate debian/control, but right
 # now we don't support that very well.
-pre-build:: testdir
+pre-build:: testdir makebuilddir
 
 # This target is called after patches are applied.  Right now it's only used
 # by the patch system.
@@ -51,7 +59,7 @@ build-indep: $(patsubst %,build/%,$(DEB_
 # Typically you will invoke upstream's "make clean" rule here, although you
 # can also hook in other stuff here.  Many of the included rules and classes
 # add stuff to this rule.
-clean:: testdir testroot reverse-patches
+clean:: testdir testroot reverse-patches cleanbuilddir
 
 # This rule is called before the common-install target.  It's currently only
 # used by debhelper.mk, to run dh_clean -k.
Index: 1/rules/buildvars.mk.in
===================================================================
RCS file: /cvsroot/build-common/cdbs/1/rules/buildvars.mk.in,v
retrieving revision 1.2
diff -u -p -r1.2 buildvars.mk.in
--- 1/rules/buildvars.mk.in	2 Jun 2003 19:36:54 -0000	1.2
+++ 1/rules/buildvars.mk.in	4 Jun 2003 21:01:25 -0000
@@ -25,6 +25,11 @@ DEB_UDEB_PACKAGES ?= $(filter %-udeb, $(
 # A handy list of every package, udeb or not
 DEB_ALL_PACKAGES ?= $(DEB_PACKAGES) $(DEB_UDEB_PACKAGES)
 
+# Some support for srcdir != builddir builds.
+# These are relative to the root of the package
+DEB_BUILDDIR ?= .
+DEB_SRCDIR ?= .
+
 # Miscellaneous bits
 DEB_ARCH ?= $(shell dpkg --print-architecture)
 DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
Index: 1/rules/simple-patchsys.mk.in
===================================================================
RCS file: /cvsroot/build-common/cdbs/1/rules/simple-patchsys.mk.in,v
retrieving revision 1.4
diff -u -p -r1.4 simple-patchsys.mk.in
--- 1/rules/simple-patchsys.mk.in	2 Jun 2003 19:36:54 -0000	1.4
+++ 1/rules/simple-patchsys.mk.in	4 Jun 2003 21:01:25 -0000
@@ -47,8 +47,8 @@ debian/stamp-patched reverse-patches:
 	    for level in 0 1 2; do \
 	      if test -z "$$success"; then \
 	        echo -n "$$level..."; \
-	        if cat $$patch | patch $$reverse --dry-run -p$$level 1>$$patch.level-$$level.log 2>&1; then \
-	          if cat $$patch | patch $$reverse --no-backup-if-mismatch -V never -p$$level 1>$$patch.level-$$level.log 2>&1; then \
+	        if cat $$patch | patch -d $(DEB_BUILDDIR) $$reverse --dry-run -p$$level 1>$$patch.level-$$level.log 2>&1; then \
+	          if cat $$patch | patch -d $(DEB_BUILDDIR) $$reverse --no-backup-if-mismatch -V never -p$$level 1>$$patch.level-$$level.log 2>&1; then \
 	            success=yes; \
 	            touch debian/stamp-patch-$$(basename $$patch); \
 	            echo "success."; \
@@ -66,7 +66,7 @@ debian/stamp-patched reverse-patches:
 	    fi; \
 	  else \
 	    echo -n "Trying patch $$patch at level $$level..."; \
-	    if cat $$patch | patch $$reverse --no-backup-if-mismatch -V never -p$$level 1>$$patch.log 2>&1; then \
+	    if cat $$patch | patch -d $(DEB_BUILDDIR) $$reverse --no-backup-if-mismatch -V never -p$$level 1>$$patch.log 2>&1; then \
               touch debian/stamp-patch-$$(basename $$patch); \
 	      echo "success."; \
 	    else \
