Package: debhelper
Version: 9.20140817
Severity: wishlist
Tags: patch

With multiarch, some use cases which would traditionally be solved
through the static *.dirs, *.install, and *.link files now require
hackery in debian/rules instead, as some of the operations need the
build-time multiarch tuple.

It would be great if these files would support a substitution or
placeholder for the multiarch tuple so that we can go back to the
traditional approach even for multiarch packages.


Example #1
==========

A library package with a custom Makefile that installs everything to
$(DESTDIR), and in particular the shared library to a hard-coded
$(DESTDIR)/usr/lib/.

Before multi-arch, this was not an issue. I would just have created
simple one-line debian/libfooX.install files, and be done with it. Now,
I have to query DEB_HOST_MULTIARCH in debian/rules, override dh_install,
and move stuff around manually. Given the long path names involved, this
is really clutters up things.

Example #2
==========

An essential library package using autoconf.

The FHS specifies that the essential library should go into /lib/, but
development files (eg: .so symlink, pkgconfig files) must go into
/usr/lib/. This, too, requires a lot of manual moving and symlinking
where otherwise one-line *.{dirs,install,link} files would have sufficed.


Proposed Solution
=================

The attached patch extends dh_installdirs, dh_install, and dh_link such
that in v10 mode, the literal string :multiarch: is substituted with the
appropriate multiarch tuple during their operation.

Coming back to example #1, this should then work (and make debian/rules
hackery unnecessary):

  [ debian/libfooX.install ]
  usr/lib/*.so.*    usr/lib/:multiarch:/

The real added value is in the more complex cases, though.


Possible Issues
===============

The substitution is currently applied not only to debian/package.*
files, but to direct invocations of the dh_* helpers as well. I don't
know if this is a problem.

There might be a better alternative to the choice of :multiarch: as
substitution string, but to avoid conflicts, it should probably not
include symbols with a special meaning within debian/rules.

The dh_link extension is not as useful as the others because it does not
support wildcards are not supported. For example, in the -dev package, I
cannot symlink the .so to the .so.X.Y via .so.*.*

I haven't looked into the translation stuff.

I'm not aware of any use cases for it, but theoretically the same
approach could be applied to other DEB_*_ variables, in which case a
substitution such as :host:multarch: might be better.

Christian
>From 65d1e4acac5d04b6ca5dac7f7562520a4c892719 Mon Sep 17 00:00:00 2001
From: Christian Kastner <[email protected]>
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

Reply via email to