From 4788b7eea8403a5b800349dda949ed009cf2483e Mon Sep 17 00:00:00 2001
From: Roger Leigh <rleigh@debian.org>
Date: Thu, 25 Nov 2010 10:36:28 +0000
Subject: [PATCH 4/6] examples: Update examples to use build-arch and build-indep targets
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add build-arch and build-indep targets to all rules files.  The
existing build target depends upon both of these targets.
Add corresponding install-arch and install-indep targets.
Existing binary-arch and binary-indep targets use new rules in
place of old build and install targets.
Additional changes are to give better guidance as to best practice in
writing scripts and makefiles.
Example install command uses:
• DESTDIR in place of prefix (much less broken where prefix is
  not present in variables such as $(sysconfdir) and $(localstatedir),
  for example).
• $(CURDIR) used in place of `pwd` (more efficient, no external command
  is run).
• Uses $$(dh_listpackages) in place of `dh_listpackages` (more robust
  if changed in the future, given the broken quoting behaviour of
  backquotes).
Stamp files touch "$@" rather than the stamp file name (more robust
if the target name changes).
Trailing whitespace cleaned up.

rules.multi2 was deleted.  Its pattern rule to build individual
packages does not work with separate build-arch and build-indep
targets, because it requires us to know if the package is
architecture dependent or independent.  This could probably be
accomplished using some quite complex shell functions to run and
parse the output of dh_listpackages.  But given the lack of need
for this functionality (dpkg-buildpackage doesn't make use of it,
and it's not mentioned in Policy), I removed it.

Signed-off-by: Roger Leigh <rleigh@debian.org>
---
 examples/rules.arch   |   40 ++++++++++++++------
 examples/rules.indep  |   40 ++++++++++++++------
 examples/rules.multi  |   62 +++++++++++++++++++++---------
 examples/rules.multi2 |   98 -------------------------------------------------
 4 files changed, 99 insertions(+), 141 deletions(-)
 delete mode 100755 examples/rules.multi2

diff --git a/examples/rules.arch b/examples/rules.arch
index adfc385..66d1f79 100755
--- a/examples/rules.arch
+++ b/examples/rules.arch
@@ -1,25 +1,37 @@
 #!/usr/bin/make -f
 # Sample debian/rules that uses debhelper.
-# This file is public domain software, originally written by Joey Hess. 
+# This file is public domain software, originally written by Joey Hess.
 #
 # This version is for packages that are architecture dependent.
 
 # Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
 
-build: build-stamp
-build-stamp:
+build-indep: build-indep-stamp
+build-indep-stamp:
+# We have nothing to do by default.
+#	dh_testdir
+
+	# Add here commands to compile the architecture independent
+	# parts of the package.
+	#$(MAKE) doc
+
+#	touch "$@"
+
+build-arch: build-arch-stamp
+build-arch-stamp:
 	dh_testdir
 
-	# Add here commands to compile the package.
+	# Add here commands to compile the architecture dependent
+	# parts of the package.
 	#$(MAKE)
 
-	touch build-stamp
+	touch "$@"
 
 clean:
 	dh_testdir
 	dh_testroot
-	rm -f build-stamp
+	rm -f build-indep-stamp build-arch-stamp
 
 	# Add here commands to clean up after the build process.
 	#$(MAKE) clean
@@ -27,21 +39,24 @@ clean:
 
 	dh_clean
 
-install: build
+install-indep: build-indep
+# We have nothing to do by default.
+
+install-arch: build-arch
 	dh_testdir
 	dh_testroot
 	dh_prep
 	dh_installdirs
 
 	# Add here commands to install the package into debian/<packagename>
-	#$(MAKE) prefix=`pwd`/debian/`dh_listpackages`/usr install
+	#$(MAKE) DESTDIR=$(CURDIR)/debian/$$(dh_listpackages) install
 
 # Build architecture-independent files here.
-binary-indep: build install
+binary-indep: build-indep install-indep
 # We have nothing to do by default.
 
 # Build architecture-dependent files here.
-binary-arch: build install
+binary-arch: build-arch install-arch
 	dh_testdir
 	dh_testroot
 	dh_installchangelogs
@@ -49,7 +64,7 @@ binary-arch: build install
 	dh_installexamples
 #	dh_install
 #	dh_installmenu
-#	dh_installdebconf	
+#	dh_installdebconf
 #	dh_installlogrotate
 #	dh_installemacsen
 #	dh_installcatalogs
@@ -76,5 +91,6 @@ binary-arch: build install
 	dh_md5sums
 	dh_builddeb
 
+build: build-indep build-arch
 binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install
+.PHONY: build-indep build-arch build clean binary-indep binary-arch binary install-indep install-arch
diff --git a/examples/rules.indep b/examples/rules.indep
index 831365a..a3ebf53 100755
--- a/examples/rules.indep
+++ b/examples/rules.indep
@@ -1,5 +1,5 @@
 #!/usr/bin/make -f
-# Sample debian/rules that uses debhelper. 
+# Sample debian/rules that uses debhelper.
 # This file is public domain software, originally written by Joey Hess.
 #
 # This version is for packages that are architecture independent.
@@ -7,19 +7,31 @@
 # Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
 
-build: build-stamp
-build-stamp:
+build-indep: build-indep-stamp
+build-indep-stamp:
 	dh_testdir
 
-	# Add here commands to compile the package.
+	# Add here commands to compile the architecture independent
+	# parts of the package.
 	#$(MAKE)
 
-	touch build-stamp
+	touch "$@"
+
+build-arch: build-arch-stamp
+build-arch-stamp:
+# We have nothing to do by default.
+#	dh_testdir
+
+	# Add here commands to compile the architecture dependent
+	# parts of the package.
+	#$(MAKE)
+
+#	touch "$@"
 
 clean:
 	dh_testdir
 	dh_testroot
-	rm -f build-stamp
+	rm -f build-indep-stamp build-arch-stamp
 
 	# Add here commands to clean up after the build process.
 	#$(MAKE) clean
@@ -27,17 +39,20 @@ clean:
 
 	dh_clean
 
-install: build
+install-indep: build-indep
 	dh_testdir
 	dh_testroot
 	dh_prep
 	dh_installdirs
 
-	# Add here commands to install the package into debian/<packagename>.
-	#$(MAKE) prefix=`pwd`/debian/`dh_listpackages`/usr install
+	# Add here commands to install the package into debian/<packagename>
+	#$(MAKE) DESTDIR=$(CURDIR)/debian/$$(dh_listpackages) install
+
+install-arch: build-arch
+# We have nothing to do by default.
 
 # Build architecture-independent files here.
-binary-indep: build install
+binary-indep: build-indep install-indep
 	dh_testdir
 	dh_testroot
 	dh_installchangelogs
@@ -69,8 +84,9 @@ binary-indep: build install
 	dh_builddeb
 
 # Build architecture-dependent files here.
-binary-arch: build install
+binary-arch: build-arch install-arch
 # We have nothing to do by default.
 
+build: build-indep build-arch
 binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install
+.PHONY: build-indep build-arch build clean binary-indep binary-arch binary install-indep install-arch
diff --git a/examples/rules.multi b/examples/rules.multi
index 78d6279..31ff954 100755
--- a/examples/rules.multi
+++ b/examples/rules.multi
@@ -1,27 +1,38 @@
 #!/usr/bin/make -f
-# Sample debian/rules that uses debhelper. 
+# Sample debian/rules that uses debhelper.
 # This file is public domain software, originally written by Joey Hess.
 #
 # This version is for a hypothetical package that builds an
 # architecture-dependant package, as well as an architecture-independent
 # package.
 
-# Uncomment this to turn on verbose mode. 
+# Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
 
-build: build-stamp
-build-stamp:
+build-indep: build-indep-stamp
+build-indep-stamp:
 	dh_testdir
 
-	# Add here commands to compile the package.
+	# Add here commands to compile the architecture independent
+	# parts of the package.
+	#$(MAKE) doc
+
+	touch "$@"
+
+build-arch: build-arch-stamp
+build-arch-stamp:
+	dh_testdir
+
+	# Add here commands to compile the architecture dependent
+	# parts of the package.
 	#$(MAKE)
 
-	touch build-stamp
+	touch "$@"
 
 clean:
 	dh_testdir
 	dh_testroot
-	rm -f build-stamp 
+	rm -f build-indep-stamp build-arch-stamp
 
 	# Add here commands to clean up after the build process.
 	#$(MAKE) clean
@@ -29,20 +40,32 @@ clean:
 
 	dh_clean
 
-install:
-install: build
-	dh_testdir
-	dh_testroot
-	dh_prep
-	dh_installdirs
+install-indep: build-indep
+	dh_testdir -i
+	dh_testroot -i
+	dh_prep -i
+	dh_installdirs -i
+
+	# Add here commands to install the architecture independent
+	# parts of the package into debian/tmp.
+	#$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install-docs
+
+	dh_install -i
+
+install-arch: build-arch
+	dh_testdir -a
+	dh_testroot -a
+	dh_prep -a
+	dh_installdirs -a
 
-	# Add here commands to install the package into debian/tmp.
-	#$(MAKE) prefix=`pwd`/debian/tmp/usr install
+	# Add here commands to install the architecture dependent
+	# parts of the package into debian/tmp.
+	#$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
 
-	dh_install
+	dh_install -a
 
 # Build architecture-independent files here.
-binary-indep: build install
+binary-indep: build-indep install-indep
 	dh_testdir -i
 	dh_testroot -i
 	dh_installchangelogs -i
@@ -74,7 +97,7 @@ binary-indep: build install
 	dh_builddeb -i
 
 # Build architecture-dependent files here.
-binary-arch: build install
+binary-arch: build-arch install-arch
 	dh_testdir -a
 	dh_testroot -a
 	dh_installchangelogs -a
@@ -108,5 +131,6 @@ binary-arch: build install
 	dh_md5sums -a
 	dh_builddeb -a
 
+build: build-indep build-arch
 binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install
+.PHONY: build-indep build-arch build clean binary-indep binary-arch binary install-indep install-arch
diff --git a/examples/rules.multi2 b/examples/rules.multi2
deleted file mode 100755
index ae5a9ca..0000000
--- a/examples/rules.multi2
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/usr/bin/make -f
-# Sample debian/rules that uses debhelper.
-# This file is public domain software, originally written by Joey Hess.
-#
-# This version is for a multibinary package. It also allows you to build any
-# of the binary packages independantly, via binary-<package> targets.
-
-# Uncomment this to turn on verbose mode. 
-#export DH_VERBOSE=1
-
-# This has to be exported to make some magic below work.
-export DH_OPTIONS
-
-build: build-stamp
-build-stamp:
-	dh_testdir
-
-	# Add here commands to compile the package.
-	#$(MAKE)
-
-	touch build-stamp
-
-clean:
-	dh_testdir
-	dh_testroot
-	rm -f build-stamp
-
-	# Add here commands to clean up after the build process.
-	#$(MAKE) clean
-	#$(MAKE) distclean
-
-	dh_clean
-
-install: DH_OPTIONS=
-install: build
-	dh_testdir
-	dh_testroot
-	dh_prep
-	dh_installdirs
-
-	# Add here commands to install the package into debian/tmp.
-	#$(MAKE) prefix=`pwd`/debian/tmp/usr install
-
-	dh_install
-
-# This single target is used to build all the packages, all at once, or
-# one at a time. So keep in mind: any options passed to commands here will
-# affect _all_ packages. Anything you want to only affect one package
-# should be put in another target, such as the install target.
-binary-common:
-	dh_testdir
-	dh_testroot
-	dh_installchangelogs
-	dh_installdocs
-	dh_installexamples
-	dh_installmenu
-#	dh_installdebconf
-#	dh_installlogrotate
-#	dh_installemacsen
-#	dh_installcatalogs
-#	dh_installpam
-#	dh_installmime
-#	dh_installinit
-#	dh_installman
-#	dh_installcron
-#	dh_installinfo
-#	dh_installwm
-#	dh_installudev
-#	dh_lintian
-#	dh_bugfiles
-#	dh_undocumented
-	dh_strip
-	dh_link
-	dh_compress
-	dh_fixperms
-#	dh_perl
-#	dh_makeshlibs
-	dh_installdeb
-	dh_shlibdeps
-	dh_gencontrol
-	dh_md5sums
-	dh_builddeb
-
-# Build architecture independant packages using the common target.
-binary-indep: build install
-# (Uncomment this next line if you have such packages.)
-#	 $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
-
-# Build architecture dependant packages using the common target.
-binary-arch: build install
-	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
-
-# Any other binary targets build just one binary package at a time.
-binary-%: build install
-	make -f debian/rules binary-common DH_OPTIONS=-p$*
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary-common binary install
-- 
1.7.2.3

