From 65d1e4acac5d04b6ca5dac7f7562520a4c892719 Mon Sep 17 00:00:00 2001
From: Christian Kastner <debian@kvr.at>
Date: Fri, 29 Aug 2014 19:38:52 -0700
Subject: [PATCH] Make the multiarch tuple available in some helpers

Extend the dh_installdirs, dh_install, and dh_link helpers such that the string
:multiarch: is substituted with the value of DEB_HOST_MULTIARCH at build time.
This affects both direct invocations of the commands, as well as their
respective debian/<package>.* files.

This feature is only available in v10 mode or above.
---
 debhelper.pod  |  6 ++++++
 dh_install     | 13 ++++++++++++-
 dh_installdirs | 13 ++++++++++++-
 dh_link        | 11 +++++++++++
 4 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/debhelper.pod b/debhelper.pod
index 23f8582..d5dbb11 100644
--- a/debhelper.pod
+++ b/debhelper.pod
@@ -546,6 +546,12 @@ running debhelper commands. This will not affect packages that only build
 with debhelper commands, but it may expose bugs in commands not included in
 debhelper.
 
+=item -
+
+The B<dh_installdirs>, B<dh_install>, and B<dh_link> commands will
+substitute the string F<:multiarch:> in path names with the applicable
+multiarch tuple at build time.
+
 =back
 
 =back
diff --git a/dh_install b/dh_install
index 28a76ef..8924766 100755
--- a/dh_install
+++ b/dh_install
@@ -35,6 +35,10 @@ From debhelper compatibility level 7 on, B<dh_install> will fall back to
 looking in F<debian/tmp> for files, if it doesn't find them in the current
 directory (or wherever you've told it to look using B<--sourcedir>).
 
+From debhelper compatibility level 10 on, the string F<:multiarch:> may be
+used in the names of both of the sources and the destination; it will be
+substituted with the applicable multiarch tuplet.
+
 =head1 FILES
 
 =over 4
@@ -123,6 +127,8 @@ init(options => {
 
 my @installed;
 
+my $multiarch=dpkg_architecture_value("DEB_HOST_MULTIARCH");
+
 my $srcdir = '.';
 $srcdir = $dh{SOURCEDIR} if defined $dh{SOURCEDIR};
 
@@ -155,7 +161,12 @@ foreach my $package (getpackages()) {
 	foreach my $set (@install) {
 		my $dest;
 		my $tmpdest=0;
-		
+
+		# Perform substitution for multiarch tuple
+		if (! compat(9)) {
+			s/:multiarch:/$multiarch/g for @$set;
+		}
+
 		if (! defined $dh{AUTODEST} && @$set > 1) {
 			$dest=pop @$set;
 		}
diff --git a/dh_installdirs b/dh_installdirs
index fe5683d..90a5e3c 100755
--- a/dh_installdirs
+++ b/dh_installdirs
@@ -18,6 +18,10 @@ B<dh_installdirs> [S<I<debhelper options>>] [B<-A>] [S<I<dir> ...>]
 B<dh_installdirs> is a debhelper program that is responsible for creating
 subdirectories in package build directories.
 
+From debhelper compatibility level 10 on, the string F<:multiarch:> may be
+used in the name of directories; it will be substituted with the applicable
+multiarch tuplet.
+
 =head1 FILES
 
 =over 4
@@ -48,6 +52,8 @@ package acted on. (Or in all packages if B<-A> is specified.)
 
 init();
 
+my $multiarch=dpkg_architecture_value("DEB_HOST_MULTIARCH");
+
 # PROMISE: DH NOOP WITHOUT dirs
 
 foreach my $package (@{$dh{DOPACKAGES}}) {
@@ -61,7 +67,12 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 	my @dirs;
 
 	if ($file) {
-		@dirs=filearray($file)
+		@dirs=filearray($file);
+
+		# Perform substitution for multiarch tuple
+		if (! compat(9)) {
+			s/:multiarch:/$multiarch/g for @dirs;
+		}
 	}
 
 	if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
diff --git a/dh_link b/dh_link
index db4aea8..899b40b 100755
--- a/dh_link
+++ b/dh_link
@@ -38,6 +38,10 @@ Any pre-existing destination files will be replaced with symlinks.
 B<dh_link> also scans the package build tree for existing symlinks which do not
 conform to Debian policy, and corrects them (v4 or later).
 
+From debhelper compatibility level 10 on, the string F<:multiarch:> may be
+used in the names of both of the sources and the destinations; it will be
+substituted with the applicable multiarch tuplet.
+
 =head1 FILES
 
 =over 4
@@ -124,6 +128,8 @@ sub expand_path {
 
 init();
 
+my $multiarch=dpkg_architecture_value("DEB_HOST_MULTIARCH");
+
 foreach my $package (@{$dh{DOPACKAGES}}) {
 	my $tmp=tmpdir($package);
 	my $file=pkgfile($package,"links");
@@ -139,6 +145,11 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 		error("$file lists a link without a destination.");
 	}
 
+	# Perform substitution for multiarch tuple
+	if (! compat(9)) {
+		s/:multiarch:/$multiarch/g for @links;
+	}
+
 	if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
 		push @links, @ARGV;
 	}
-- 
2.1.0

