[Build-common-hackers] Bug#841761: cdbs: improve cross compilation with makefile and cmake classes

Helmut Grohne helmut at subdivi.de
Sun Oct 23 09:58:57 UTC 2016


Package: cdbs
Version: 0.4.148
Severity: wishlist
Tags: patch
User: helmutg at debian.org
Usertags: rebootstrap
Control: affects -1 + src:cmt src:duma src:freerdp src:hydrogen

Cross building debian packages that use cdbs does not work as well as it
could work. Recent improvements in debhelper have made a significant
chunk of packages cross build without modification. Maybe we can
replicate that for cdbs? I have a number of small and larger issues:

In 1/class/cmake.mk, the DEB_BUILDDIR variable uses DEB_BUILD_GNU_TYPE.
That sounds wrong as building things for the build architecture is not a
common thing to do. I suggest to change this to DEB_HOST_GNU_TYPE and
note that in the vast majority of uses, this is only an aesthetic
change.

When using cmake for cross compilation, one needs to pass a number of
variables such as CMAKE_SYSTEM_NAME or CMAKE_SYSTEM_PROCESSOR. I think
that cdbs is the right place to add them (as did debhelper) and propose
adding a new variables DEB_CMAKE_CROSS_ARGS to 1/class/cmake.mk to hold
these.

The cmake class defaults to passing $(CC) as CMAKE_C_COMPILER.
Unfortunately, CC defaults to cc and cdbs does nothing to fix that. I
propose that 1/class/langcore.mk changes CC and CXX such that if they
are still at their default values, it will go and substitute
triplet-prefixed versions. Note that for doing so, it should in
principle include 1/rules/buildvars.mk which sets up DEB_HOST_GNU_TYPE
(not done in patch). I wasn't sure whether that is ok, and didn't add
it in my patch. If it is, add the include and drop the "ifneq
($(DEB_HOST_GNU_TYPE),)".

When using the makefile class, it only sets up CC for cross compilation,
but CXX (and PKG_CONFIG) is often needed as well. It also doesn't honour
a user preference for CC.

I note that debhelper's makefile buildsystem doesn't pass CC and friends
via environment but via the make command line, because many Makefiles
set broken defaults (not covered in patch).

I also note that 1/rules/buildvars.mk wonders when to stop setting
DEB_{BUILD,HOST}_* variables. The correct answer is never, because we do
not mandate the use of dpkg-buildpackage. Building a package should
remain possible by invoking "./debian/rules binary". It would be far
better to just include /usr/share/dpkg/architecture.mk though (not
covered in patch).

Most of the issues listed above are addressed in the attached patch.
Aspects messing with includes aren't. Please consider it as a basis for
discussing cross improvements for cdbs and taking the parts that look
like immediate improvements.

Helmut
-------------- next part --------------
diff --minimal -Nru cdbs-0.4.148/1/class/cmake.mk.in cdbs-0.4.148+nmu1/1/class/cmake.mk.in
--- cdbs-0.4.148/1/class/cmake.mk.in	2016-06-10 12:36:00.000000000 +0200
+++ cdbs-0.4.148+nmu1/1/class/cmake.mk.in	2016-10-23 11:34:31.000000000 +0200
@@ -29,9 +29,9 @@
 
 # FIXME: Restructure to allow early override (or lowercase the variable!)
 ifdef _cdbs_tarball_dir
-DEB_BUILDDIR = $(_cdbs_tarball_dir)/obj-$(DEB_BUILD_GNU_TYPE)
+DEB_BUILDDIR = $(_cdbs_tarball_dir)/obj-$(DEB_HOST_GNU_TYPE)
 else
-DEB_BUILDDIR = obj-$(DEB_BUILD_GNU_TYPE)
+DEB_BUILDDIR = obj-$(DEB_HOST_GNU_TYPE)
 endif
 
 # Overriden from makefile-vars.mk
@@ -41,6 +41,18 @@
 
 DEB_MAKE_INSTALL_TARGET ?= install DESTDIR=$(DEB_DESTDIR)
 
+ifneq (,$(cdbs_crossbuild))
+_system_name_map_linux = Linux
+_system_name_map_kfreebsd = FreeBSD
+_system_name_map_hurd = GNU
+ifneq (,$(_system_name_map_$(DEB_HOST_ARCH_OS)))
+DEB_CMAKE_CROSS_ARGS ?= \
+	-DCMAKE_SYSTEM_NAME=$(_system_name_map_$(DEB_HOST_ARCH_OS)) \
+	-DCMAKE_SYSTEM_PROCESSOR=$(DEB_HOST_GNU_CPU) \
+	-DPKG_CONFIG_EXECUTABLE=/usr/bin/$(DEB_HOST_GNU_TYPE)-pkg-config
+endif
+endif
+
 CMAKE ?= cmake
 DEB_CMAKE_INSTALL_PREFIX ?= /usr
 DEB_CMAKE_CFLAGS ?= $(CFLAGS) $(CPPFLAGS)
@@ -64,6 +76,7 @@
 	$(strip cd $(DEB_BUILDDIR) && \
 	$(CMAKE) $(CURDIR)/$(DEB_SRCDIR) \
 		$(DEB_CMAKE_NORMAL_ARGS) \
+		$(DEB_CMAKE_CROSS_ARGS) \
 		$(DEB_CMAKE_EXTRA_FLAGS))
 
 cleanbuilddir::
diff --minimal -Nru cdbs-0.4.148/1/class/langcore.mk.in cdbs-0.4.148+nmu1/1/class/langcore.mk.in
--- cdbs-0.4.148/1/class/langcore.mk.in	2016-06-10 12:36:00.000000000 +0200
+++ cdbs-0.4.148+nmu1/1/class/langcore.mk.in	2016-10-23 11:24:56.000000000 +0200
@@ -43,6 +43,15 @@
 -include debian/_cdbs_buildflags.mk
 $(shell rm -f debian/_cdbs_buildflags.mk)
 
+ifneq ($(DEB_HOST_GNU_TYPE),)
+ifeq ($(origin CC),default)
+CC := $(DEB_HOST_GNU_TYPE)-gcc
+endif
+ifeq ($(origin CXX),default)
+CXX := $(DEB_HOST_GNU_TYPE)-g++
+endif
+endif
+
 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
 	DEB_PARALLEL_JOBS ?= $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
 endif
diff --minimal -Nru cdbs-0.4.148/1/class/makefile-vars.mk.in cdbs-0.4.148+nmu1/1/class/makefile-vars.mk.in
--- cdbs-0.4.148/1/class/makefile-vars.mk.in	2016-06-10 12:36:00.000000000 +0200
+++ cdbs-0.4.148+nmu1/1/class/makefile-vars.mk.in	2016-10-23 11:19:43.000000000 +0200
@@ -25,7 +25,7 @@
 
 #DEB_MAKE_MAKEFILE =
 DEB_MAKE_ENVVARS ?= $(if $(cdbs_crossbuild),\
-	CC="$(DEB_HOST_GNU_TYPE)-gcc")
+	CC="$(CC)" CXX="$(CXX)" PKG_CONFIG="$(DEB_HOST_GNU_TYPE)-pkg-config")
 DEB_MAKE_PARALLEL ?= $(and $(DEB_BUILD_PARALLEL),$(DEB_PARALLEL_JOBS),\
 	-j$(DEB_PARALLEL_JOBS))
 
diff --minimal -Nru cdbs-0.4.148/debian/changelog cdbs-0.4.148+nmu1/debian/changelog
--- cdbs-0.4.148/debian/changelog	2016-09-16 10:40:37.000000000 +0200
+++ cdbs-0.4.148+nmu1/debian/changelog	2016-10-23 11:13:08.000000000 +0200
@@ -1,3 +1,10 @@
+cdbs (0.4.148+nmu1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Improve cross compilation cmake and makefile classes. Closes: #-1.
+
+ -- Helmut Grohne <helmut at subdivi.de>  Sun, 23 Oct 2016 11:00:44 +0200
+
 cdbs (0.4.148) unstable; urgency=medium
 
   * Fix license-miner.


More information about the Build-common-hackers mailing list