[debhelper-devel] Bug#836988: dh_auto_build: makefile build system: handle cross compilation

Helmut Grohne helmut at subdivi.de
Wed Sep 7 20:37:39 UTC 2016


Source: debhelper
Version: 9.20160814
Severity: wishlist
Tags: patch
User: helmutg at debian.org
Usertags: rebootstrap
Control: affects -1 + src:cjet

Hi Niels et al,

During my journey on cross compiling more packages I encountered cjet.
Its debian/rules file currently is the text book example containing
nothing more than the default "%:\n\tdh $@\n" rule. I couldn't take away
its pristine beauty and figured that debhelper should just work here.

The issue here is that for the makefile build system, no cross compilers
are passed to make. The solution is to have dh_auto_build figure that we
are cross compiling and pass CC and CXX with suitable values to make.
Given that quite some Makefiles provide defaults, I opted for passing
them as command line arguments overriding simple assignments.

The difficulty now is that we only want to pass them for simple Makefile
packages. In particular, the autoconf and cmake build systems handle
cross compilation quite well already. I first tried to rename the
makefile build system into a makefile_base class and have makefile
derive it.  Unfortunately, that causes cmake packages to be detected as
makefile packages, because cmake no longer inherits from makefile (see
comment in autoselect_buildsystem). Thus we cannot change the class
hierarchy of build systems and I opted for disabling that functionality
via a constant in child classes.

This may not be the best solution, but it doesn't break cmake and it
makes cjet cross build just fine. So the patch should at least serve as
a basis for further discussion. What do you think?

Helmut
-------------- next part --------------
diff --minimal -Nru debhelper-9.20160814/Debian/Debhelper/Buildsystem/autoconf.pm debhelper-9.20160814+nmu1/Debian/Debhelper/Buildsystem/autoconf.pm
--- debhelper-9.20160814/Debian/Debhelper/Buildsystem/autoconf.pm	2016-06-10 19:44:02.000000000 +0200
+++ debhelper-9.20160814+nmu1/Debian/Debhelper/Buildsystem/autoconf.pm	2016-09-07 22:06:06.000000000 +0200
@@ -11,6 +11,8 @@
 use Debian::Debhelper::Dh_Lib qw(dpkg_architecture_value sourcepackage compat);
 use parent qw(Debian::Debhelper::Buildsystem::makefile);
 
+use constant DEB_CROSS_TOOLS => 0;
+
 sub DESCRIPTION {
 	"GNU Autoconf (configure)"
 }
diff --minimal -Nru debhelper-9.20160814/Debian/Debhelper/Buildsystem/cmake.pm debhelper-9.20160814+nmu1/Debian/Debhelper/Buildsystem/cmake.pm
--- debhelper-9.20160814/Debian/Debhelper/Buildsystem/cmake.pm	2016-06-10 19:44:02.000000000 +0200
+++ debhelper-9.20160814+nmu1/Debian/Debhelper/Buildsystem/cmake.pm	2016-09-07 22:06:13.000000000 +0200
@@ -11,6 +11,8 @@
 use Debian::Debhelper::Dh_Lib qw(compat dpkg_architecture_value error is_cross_compiling);
 use parent qw(Debian::Debhelper::Buildsystem::makefile);
 
+use constant DEB_CROSS_TOOLS => 0;
+
 my @STANDARD_CMAKE_FLAGS = qw(
   -DCMAKE_INSTALL_PREFIX=/usr
   -DCMAKE_VERBOSE_MAKEFILE=ON
diff --minimal -Nru debhelper-9.20160814/Debian/Debhelper/Buildsystem/makefile.pm debhelper-9.20160814+nmu1/Debian/Debhelper/Buildsystem/makefile.pm
--- debhelper-9.20160814/Debian/Debhelper/Buildsystem/makefile.pm	2015-07-01 19:17:30.000000000 +0200
+++ debhelper-9.20160814+nmu1/Debian/Debhelper/Buildsystem/makefile.pm	2016-09-07 22:05:37.000000000 +0200
@@ -8,9 +8,16 @@
 
 use strict;
 use warnings;
-use Debian::Debhelper::Dh_Lib qw(escape_shell clean_jobserver_makeflags);
+use Debian::Debhelper::Dh_Lib qw(dpkg_architecture_value escape_shell clean_jobserver_makeflags is_cross_compiling);
 use parent qw(Debian::Debhelper::Buildsystem);
 
+my %DEB_DEFAULT_TOOLS = (
+	'CC'	=> 'gcc',
+	'CXX'	=> 'g++',
+);
+
+use constant DEB_CROSS_TOOLS => 1;
+
 # make makes things difficult by not providing a simple way to test
 # whether a Makefile target exists. Using -n and checking for a nonzero
 # exit status is not good enough, because even with -n, make will
@@ -127,6 +134,15 @@
 
 sub build {
 	my $this=shift;
+	if (ref($this)->DEB_CROSS_TOOLS and is_cross_compiling()) {
+		while (my ($var, $tool) = each %DEB_DEFAULT_TOOLS) {
+			if ($ENV{$var}) {
+				unshift @_, $var . "=" . $ENV{$var};
+			} else {
+				unshift @_, $var . "=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-" . $tool;
+			}
+		}
+	}
 	$this->do_make(@_);
 }
 
diff --minimal -Nru debhelper-9.20160814/Debian/Debhelper/Buildsystem/perl_makemaker.pm debhelper-9.20160814+nmu1/Debian/Debhelper/Buildsystem/perl_makemaker.pm
--- debhelper-9.20160814/Debian/Debhelper/Buildsystem/perl_makemaker.pm	2016-07-31 20:23:50.000000000 +0200
+++ debhelper-9.20160814+nmu1/Debian/Debhelper/Buildsystem/perl_makemaker.pm	2016-09-07 22:06:23.000000000 +0200
@@ -12,6 +12,8 @@
 use parent qw(Debian::Debhelper::Buildsystem::makefile);
 use Config;
 
+use constant DEB_CROSS_TOOLS => 0;
+
 sub DESCRIPTION {
 	"Perl ExtUtils::MakeMaker (Makefile.PL)"
 }
diff --minimal -Nru debhelper-9.20160814/Debian/Debhelper/Buildsystem/qmake.pm debhelper-9.20160814+nmu1/Debian/Debhelper/Buildsystem/qmake.pm
--- debhelper-9.20160814/Debian/Debhelper/Buildsystem/qmake.pm	2016-06-10 19:44:02.000000000 +0200
+++ debhelper-9.20160814+nmu1/Debian/Debhelper/Buildsystem/qmake.pm	2016-09-07 22:06:31.000000000 +0200
@@ -11,6 +11,8 @@
 use Debian::Debhelper::Dh_Lib qw(error);
 use parent qw(Debian::Debhelper::Buildsystem::makefile);
 
+use constant DEB_CROSS_TOOLS => 0;
+
 our $qmake="qmake";
 
 sub DESCRIPTION {
diff --minimal -Nru debhelper-9.20160814/debian/changelog debhelper-9.20160814+nmu1/debian/changelog
--- debhelper-9.20160814/debian/changelog	2016-08-14 11:19:35.000000000 +0200
+++ debhelper-9.20160814+nmu1/debian/changelog	2016-09-07 21:35:01.000000000 +0200
@@ -1,3 +1,11 @@
+debhelper (9.20160814+nmu1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * makefile buildsystem: Pass triplet-prefixed tools to make.
+    (Closes: #-1)
+
+ -- Helmut Grohne <helmut at subdivi.de>  Wed, 07 Sep 2016 21:34:37 +0200
+
 debhelper (9.20160814) unstable; urgency=medium
 
   * dh_installdocs: Apply patch from Sven Joachim to make


More information about the debhelper-devel mailing list