Source: gcc-8,gcc-7
Tags: patch
User: helm...@debian.org
Usertags: rebootstrap

Hi Matthias,

since debhelper 10.9.1, more specifically
https://anonscm.debian.org/git/debhelper/debhelper.git/commit/?id=93d8fdfc5dfc994af53fc6fed7f36f271b3abee5
the DEB_STAGE=rtlibs build of gcc fails. Such builds use an environment
where DEB_BUILD_ARCH=DEB_HOST_ARCH=DEB_TARGET_ARCH, but internally set a
different TARGET and try to produce binaries for that TARGET. When
various dh_commands are instructed to operate on such packages, they now
figure that they are not enabled for DEB_HOST_ARCH and thus skip them:

| dh_installdirs -plibgcc1 usr/share/doc/libgcc1 /lib/x86_64-linux-gnux32
| dh_installdirs: All requested packages have been excluded (e.g. via a 
Build-Profile).

Turning some helpers into noops quickly makes the build fail.

I think that the cure is to call those helpers in an environment where
DEB_HOST_ARCH is set to the TARGET. The attached patch thus introduces a
$(for_target) prefix for affected commands and identifies which commands
need the prefix. After applying it DEB_STAGE=rtlibs does build.

Of course the other question is: What does the patch break? Whenever
DEB_HOST_ARCH is equal to the TARGET, the prefix does not actually
change anything, so native builds and cross builds are completely
unaffected. We only need to look at cross compiler builds (such as
DEB_STAGE=rtlibs, but also other stages). With the exception of
DEB_STAGE=rtlibs, the affected packages become Architecture: all (in the
typical dpkg-cross suffixed notation). Thus the change in DEB_HOST_ARCH
is mostly irrelevant there as well (and I did perform the full 4-stage
cross compiler bootstrap with the patch). For these reasons, I believe
that the attached patch has a low risk of introducing regressions.

I do note that Niels Thykier has been working on an alternative solution
involving support from debhelper:
https://anonscm.debian.org/git/debhelper/debhelper.git/log/?h=dh-cross-target
That branch enables tagging binary packages in debian/control to use
DEB_TARGET_ARCH whenever debhelper normally thinks DEB_HOST_ARCH. Using
this debhelper branch would allow tagging binary packages rather than
dh_commands, which generally means less tagging and thus a smaller risk
of mistakes. The approach would also allow building updates packages on
jessie and stretch, because their debhelper lacks ignores the new header
and lacks the breaking commit above. Please tell if you prefer that
approach.

Helmut
--- a/debian/rules.d/binary-fortran.mk
+++ b/debian/rules.d/binary-fortran.mk
@@ -86,8 +86,8 @@
 	mv $(install_stamp) $(install_stamp)-tmp

 	rm -rf $(d_l) $(d_d)
-	dh_installdirs -p$(p_l) $(usr_lib$(2))
-	$(dh_compat2) dh_movefiles -p$(p_l) $(usr_lib$(2))/libgfortran.so.*
+	$(for_target) dh_installdirs -p$(p_l) $(usr_lib$(2))
+	$(for_target) $(dh_compat2) dh_movefiles -p$(p_l) $(usr_lib$(2))/libgfortran.so.*

 	debian/dh_doclink -p$(p_l) $(p_lbase)
 	debian/dh_doclink -p$(p_d) $(p_lbase)
@@ -97,7 +97,7 @@
 		cp debian/$(p_l).overrides debian/$(p_l)/usr/share/lintian/overrides/$(p_l); \
 	fi

-	dh_strip -p$(p_l) --dbg-package=$(p_d)
+	$(for_target) dh_strip -p$(p_l) --dbg-package=$(p_d)
 	ln -sf libgfortran.symbols debian/$(p_l).symbols
 	$(cross_makeshlibs) dh_makeshlibs -p$(p_l)
 	$(call cross_mangle_shlibs,$(p_l))
@@ -130,7 +130,7 @@
 	debian/dh_doclink -p$(p_l) $(p_lbase)
 	debian/dh_rmemptydirs -p$(p_l)

-	dh_strip -p$(p_l)
+	$(for_target) dh_strip -p$(p_l)
 	$(cross_shlibdeps) dh_shlibdeps -p$(p_l)
 	$(call cross_mangle_substvars,$(p_l))
 	echo $(p_l) >> debian/$(lib_binaries)
--- a/debian/rules.d/binary-libatomic.mk
+++ b/debian/rules.d/binary-libatomic.mk
@@ -30,7 +30,7 @@
 	debian/dh_doclink -p$(p_l) $(p_lbase)
 	debian/dh_doclink -p$(p_d) $(p_lbase)

-	dh_strip -p$(p_l) --dbg-package=$(p_d)
+	$(for_target) dh_strip -p$(p_l) --dbg-package=$(p_d)
 	ln -sf libatomic.symbols debian/$(p_l).symbols
 	$(cross_makeshlibs) dh_makeshlibs -p$(p_l)
 	$(call cross_mangle_shlibs,$(p_l))
--- a/debian/rules.d/binary-libgcc.mk
+++ b/debian/rules.d/binary-libgcc.mk
@@ -161,7 +161,7 @@
 	debian/dh_doclink -p$(2) $(p_lbase)
 	debian/dh_rmemptydirs -p$(2)

-	dh_strip -p$(2)
+	$(for_target) dh_strip -p$(2)
 	$(cross_shlibdeps) dh_shlibdeps -p$(2)
 	$(call cross_mangle_substvars,$(2))
 	echo $(2) >> debian/$(lib_binaries)
@@ -281,7 +281,7 @@

 	rm -rf $(d_l) $(d_d)

-	dh_installdirs -p$(p_l) \
+	$(for_target) dh_installdirs -p$(p_l) \
 		$(docdir)/$(p_l) \
 		$(libgcc_dir$(2))

@@ -289,7 +289,7 @@
 	debian/dh_doclink -p$(p_d) $(if $(3),$(3),$(p_lbase))
 	debian/dh_rmemptydirs -p$(p_l)
 	debian/dh_rmemptydirs -p$(p_d)
-	dh_strip -p$(p_l) --dbg-package=$(p_d)
+	$(for_target) dh_strip -p$(p_l) --dbg-package=$(p_d)

 	# see Debian #533843 for the __aeabi symbol handling; this construct is
 	# just to include the symbols for dpkg versions older than 1.15.3 which
--- a/debian/rules.d/binary-libgomp.mk
+++ b/debian/rules.d/binary-libgomp.mk
@@ -24,13 +24,13 @@
 	mv $(install_stamp) $(install_stamp)-tmp

 	rm -rf $(d_l) $(d_d)
-	dh_installdirs -p$(p_l) $(usr_lib$(2))
-	$(dh_compat2) dh_movefiles -p$(p_l) $(usr_lib$(2))/libgomp.so.*
+	$(for_target) dh_installdirs -p$(p_l) $(usr_lib$(2))
+	$(for_target) $(dh_compat2) dh_movefiles -p$(p_l) $(usr_lib$(2))/libgomp.so.*

 	debian/dh_doclink -p$(p_l) $(p_lbase)
 	debian/dh_doclink -p$(p_d) $(p_lbase)

-	dh_strip -p$(p_l) --dbg-package=$(p_d)
+	$(for_target) dh_strip -p$(p_l) --dbg-package=$(p_d)
 	ln -sf libgomp.symbols debian/$(p_l).symbols
 	$(cross_makeshlibs) dh_makeshlibs -p$(p_l)
 	$(call cross_mangle_shlibs,$(p_l))
--- a/debian/rules.d/binary-libstdcxx.mk
+++ b/debian/rules.d/binary-libstdcxx.mk
@@ -185,7 +185,7 @@

 	rm -rf $(d_l)

-	dh_installdirs -p$(p_l) \
+	$(for_target) dh_installdirs -p$(p_l) \
 		$(docdir) \
 		$(usr_lib$(2)) \
 		$(PF)/share/gdb/auto-load/$(usr_lib$(2))
@@ -207,7 +207,7 @@
 	debian/dh_doclink -p$(p_l) $(p_lbase)
 	debian/dh_rmemptydirs -p$(p_l)

-	dh_strip -p$(p_l) $(if $(filter rtlibs,$(DEB_STAGE)),,--dbg-package=$(1)-$(BASE_VERSION)-dbg$(cross_lib_arch))
+	$(for_target) dh_strip -p$(p_l) $(if $(filter rtlibs,$(DEB_STAGE)),,--dbg-package=$(1)-$(BASE_VERSION)-dbg$(cross_lib_arch))

 	$(if $(filter $(DEB_TARGET_ARCH), armel hppa sparc64), \
 	  -$(cross_makeshlibs) dh_makeshlibs -p$(p_l) \
@@ -430,16 +430,16 @@
 ifeq ($(with_libcxx),yes)
 	cp -a $(d)/$(usr_lib)/libstdc++.so.*[0-9] \
 		$(d_dbg)/$(usr_lib)/
-	dh_strip -p$(p_dbg) --keep-debug
+	$(for_target) dh_strip -p$(p_dbg) --keep-debug
 	rm -f $(d_dbg)/$(usr_lib)/libstdc++.so.*[0-9]
 endif

-	dh_strip -p$(p_dev) --dbg-package=$(p_dbg)
+	$(for_target) dh_strip -p$(p_dev) --dbg-package=$(p_dbg)
 ifneq ($(with_common_libs),yes)
 	: # remove the debug symbols for libstdc++ built by a newer version of GCC
 	rm -rf $(d_dbg)/usr/lib/debug/$(PF)
 endif
-	dh_strip -p$(p_pic)
+	$(for_target) dh_strip -p$(p_pic)

 ifeq ($(with_cxxdev),yes)
 	debian/dh_rmemptydirs -p$(p_dev)
--- a/debian/rules.defs
+++ b/debian/rules.defs
@@ -239,6 +239,7 @@
   TARGET_ALIAS := $(DEB_TARGET_ALIAS)

   lib_binaries := indep_binaries
+  for_target = env `dpkg-architecture -f -a$(DEB_TARGET_ARCH)`
   cross_shlibdeps =  DEB_HOST_ARCH=$(TARGET) ARCH=$(DEB_TARGET_ARCH) MAKEFLAGS="CC=something"
   cross_gencontrol = DEB_HOST_ARCH=$(TARGET)
   cross_makeshlibs = DEB_HOST_ARCH=$(TARGET)
@@ -273,6 +274,7 @@
   #TARGET_ALIAS := $(subst linux-gnu,linux,$(TARGET_ALIAS))

   lib_binaries := arch_binaries
+  for_target :=
   cross_shlibdeps :=
   cross_gencontrol :=
   cross_makeshlibs :=
--- a/debian/rules2
+++ b/debian/rules2
@@ -2434,9 +2434,9 @@
 	cat debian/indep_binaries debian/indep_binaries.epoch > debian/indep_binaries.all

 binary-indep: debian/indep_binaries.all
-	dh_compress $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p)) \
+	$(for_target) dh_compress $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p)) \
 	  -X.log.xz -X.sum.xz -X.c -X.txt -X.tag -X.map -XREADME.Bugs
-	dh_fixperms $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p))
+	$(for_target) dh_fixperms $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p))
 	: # the export should be harmless for the binary indep packages of a native build
 	export DEB_HOST_ARCH=$(TARGET); \
 	dh_gencontrol $(foreach p,$(shell echo `cat debian/indep_binaries`),-p$(p)) \
@@ -2459,9 +2459,9 @@
 	done
 endif

-	dh_installdeb $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p))
-	dh_md5sums $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p))
-	dh_builddeb $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p))
+	$(for_target) dh_installdeb $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p))
+	$(for_target) dh_md5sums $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p))
+	$(for_target) dh_builddeb $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p))

 	@echo XXXXX `date -R`

Reply via email to