From 6cff8927a01bce287fdc7d5c0c43679658fde7d6 Mon Sep 17 00:00:00 2001
From: Dima Kogan <dima@secretsauce.net>
Date: Sun, 3 May 2015 19:28:33 -0700
Subject: [PATCH 05/10] setting all the various paths, options for
 with_deps_on_target_arch_pkgs

---
 debian/rules.conf             |  7 ++++--
 debian/rules.d/binary-base.mk |  3 ++-
 debian/rules.d/binary-cpp.mk  | 10 ++++++++
 debian/rules.defs             | 34 ++++++++++++++++++++++----
 debian/rules2                 | 45 ++++++++++++++++++++++++++++-------
 5 files changed, 82 insertions(+), 17 deletions(-)

diff --git a/debian/rules.conf b/debian/rules.conf
index e045ba3..058a29e 100644
--- a/debian/rules.conf
+++ b/debian/rules.conf
@@ -737,7 +737,9 @@ ifeq ($(DEB_CROSS),yes)
 	-DTARGET=$(DEB_TARGET_ARCH) \
 	-DLIBUNWIND_BUILD_DEP="$(LIBUNWIND_BUILD_DEP)" \
 	-DLIBATOMIC_OPS_BUILD_DEP="$(LIBATOMIC_OPS_BUILD_DEP)"
-  ifeq ($(DEB_STAGE),rtlibs)
+
+  # if either DEB_STAGE=rtlibs or wdotap
+  ifneq (,$(filter rtlibs,$(DEB_STAGE))$(filter yes,$(with_deps_on_target_arch_pkgs)))
     ctrl_flags += -DCROSS_ARCH=$(DEB_TARGET_ARCH)
   endif
 else
@@ -1385,7 +1387,8 @@ parameters-file:
 
 symbols-files: control-file
 ifeq ($(DEB_CROSS),yes)
-  ifneq ($(DEB_STAGE),rtlibs)
+  # if DEB_STAGE!=rtlibs && !wdotap === !(DEB_STAGE==rtlibs || wdotap)
+  ifeq (,$(filter rtlibs,$(DEB_STAGE))$(filter yes,$(with_deps_on_target_arch_pkgs)))
 	test -n "$(LS)"
 	set -e; \
 	for p in $$(dh_listpackages -i | grep '^lib'); do \
diff --git a/debian/rules.d/binary-base.mk b/debian/rules.d/binary-base.mk
index c6f589b..b7c9aec 100644
--- a/debian/rules.d/binary-base.mk
+++ b/debian/rules.d/binary-base.mk
@@ -23,7 +23,8 @@ endif
 	dh_installchangelogs -p$(p_base)
 	dh_compress -p$(p_base)
 	dh_fixperms -p$(p_base)
-ifeq ($(DEB_STAGE)-$(DEB_CROSS),rtlibs-yes)
+# if either DEB_STAGE-DEB_CROSS=rtlibs-yes or wdotap
+ifneq (,$(filter rtlibs-yes,$(DEB_STAGE)-$(DEB_CROSS))$(filter yes,$(with_deps_on_target_arch_pkgs)))
 	$(cross_gencontrol) dh_gencontrol -p$(p_base) -- -v$(DEB_VERSION) $(common_substvars)
 else
 	dh_gencontrol -p$(p_base) -- -v$(DEB_VERSION) $(common_substvars)
diff --git a/debian/rules.d/binary-cpp.mk b/debian/rules.d/binary-cpp.mk
index d7ee242..7de65da 100644
--- a/debian/rules.d/binary-cpp.mk
+++ b/debian/rules.d/binary-cpp.mk
@@ -113,8 +113,18 @@ else
 	echo '$(p_cpp) binary: binary-without-manpage' \
 	  >> $(d_cpp)/usr/share/lintian/overrides/$(p_cpp)
 endif
+ifneq ($(unprefixed_names),yes)
+  ifeq ($(with_deps_on_target_arch_pkgs),yes)
+    # Copy docs (including copyright) that would be included in gcc-4.7-base
+       dh_installdocs -p$(p_xbase) debian/README.Debian.$(DEB_TARGET_ARCH)
+       rm -f $(d_xbase)/usr/share/doc/$(p_xbase)/README.Debian
+       dh_installchangelogs -p$(p_xbase)
+  endif
+endif
 
+ifneq ($(DEB_CROSS)-$(with_deps_on_target_arch_pkgs),yes-yes)
 	debian/dh_doclink -p$(p_cpp) $(p_xbase)
+endif
 	debian/dh_rmemptydirs -p$(p_cpp)
 
 	echo $(p_cpp) >> debian/arch_binaries
diff --git a/debian/rules.defs b/debian/rules.defs
index e90e123..81146c1 100644
--- a/debian/rules.defs
+++ b/debian/rules.defs
@@ -202,10 +202,16 @@ else
     # cross compiler, sets WITH_SYSROOT on it's own
     DEB_CROSS = yes
     build_type = build-cross
+    ifeq ($(with_deps_on_target_arch_pkgs),yes)
+      with_sysroot = /
+    endif
   else ifeq ($(FORCE_CROSS_LAYOUT),yes)
     # a native build with a cross layout
     DEB_CROSS = yes
     build_type = build-cross
+    ifeq ($(with_deps_on_target_arch_pkgs),yes)
+      with_sysroot = /
+    endif
   else
     # native build
     build_type = build-native
@@ -234,6 +240,13 @@ ifeq ($(DEB_CROSS),yes)
   cross_lib_arch := -$(subst _,-,$(DEB_TARGET_ARCH))-cross
   cmd_prefix := $(DEB_TARGET_GNU_TYPE)-
 
+  ifeq ($(with_deps_on_target_arch_pkgs),yes)
+    LS :=
+    LS_biarch :=
+    cross_lib_arch :=
+    AQ := :$(TARGET)
+  endif
+
   TARGET_ALIAS := $(DEB_TARGET_ALIAS)
 
   lib_binaries := indep_binaries
@@ -557,7 +570,11 @@ endif
 
 ifeq ($(with_multiarch_lib),yes)
   ifneq ($(single_package),yes)
-    ifneq ($(DEB_CROSS),yes)
+    ifeq ($(DEB_CROSS),yes)
+      ifeq ($(with_deps_on_target_arch_pkgs),yes)
+        with_multiarch_cxxheaders := yes
+      endif
+    else
       with_multiarch_cxxheaders := yes
     endif
   endif
@@ -2281,12 +2298,13 @@ stamp-dir:
 	mkdir -p $(stampdir)
 
 ifeq ($(DEB_CROSS),yes)
-  define cross_mangle_shlibs
+  ifneq ($(with_deps_on_target_arch_pkgs),yes)
+    define cross_mangle_shlibs
 	if [ -f debian/$(1)/DEBIAN/shlibs ]; then \
 	  sed -i s/$(cross_lib_arch)/:$(DEB_TARGET_ARCH)/g debian/$(1)/DEBIAN/shlibs; \
 	fi
-  endef
-  define cross_mangle_substvars
+    endef
+    define cross_mangle_substvars
 	if [ -f debian/$(1).substvars ]; then \
 	  sed -i \
 	    -e 's/:$(DEB_TARGET_ARCH)/$(cross_lib_arch)/g' \
@@ -2295,7 +2313,13 @@ ifeq ($(DEB_CROSS),yes)
 	    $(if $(filter armhf,$(DEB_TARGET_ARCH)),-e 's/:armel/-armel-cross/g') \
 	    debian/$(1).substvars; \
 	fi
-  endef
+    endef
+  else
+    define cross_mangle_shlibs
+    endef
+    define cross_mangle_substvars
+    endef
+  endif
 else
   define cross_mangle_shlibs
   endef
diff --git a/debian/rules2 b/debian/rules2
index 020b340..c894d35 100644
--- a/debian/rules2
+++ b/debian/rules2
@@ -853,8 +853,11 @@ CONFARGS += \
 
 ifeq ($(DEB_CROSS),yes)
   CONFARGS += \
-	--program-prefix=$(TARGET_ALIAS)- \
+	--program-prefix=$(TARGET_ALIAS)-
+  ifneq ($(with_deps_on_target_arch_pkgs),yes)
+    CONFARGS += \
 	--includedir=/$(PFL)/include
+  endif
 endif
 
 ifeq ($(with_bootstrap),off)
@@ -983,14 +986,23 @@ endif
 
 ifeq ($(DEB_CROSS),yes)
 ifneq ($(DEB_STAGE),rtlibs)
-  PFL		= $(PF)/$(DEB_TARGET_GNU_TYPE)
-  RPF		= $(PF)/$(DEB_TARGET_GNU_TYPE)
+  ifneq ($(with_deps_on_target_arch_pkgs),yes)
+    PFL                = $(PF)/$(DEB_TARGET_GNU_TYPE)
+    RPF                = $(PF)/$(DEB_TARGET_GNU_TYPE)
+  else
+    PFL                = $(PF)
+    RPF                =
+  endif
 endif
 endif
 
 ifeq ($(with_multiarch_lib),yes)
   ifeq ($(DEB_CROSS),yes)
-    libdir	= lib
+    ifneq ($(with_deps_on_target_arch_pkgs),yes)
+      libdir	= lib
+    else
+      libdir	= lib/$(DEB_TARGET_MULTIARCH)
+    endif
   else
     libdir	= lib/$(DEB_TARGET_MULTIARCH)
   endif
@@ -1017,7 +1029,9 @@ buildlibdir	= $(builddir)/$(TARGET_ALIAS)
 gcc_subdir_name = gcc
 ifneq ($(single_package),yes)
   ifeq ($(DEB_CROSS),yes)
-    gcc_subdir_name = gcc-cross
+    ifneq ($(with_deps_on_target_arch_pkgs),yes)
+      gcc_subdir_name = gcc-cross
+    endif
   endif
 endif
 
@@ -1039,7 +1053,11 @@ d_l= debian/$(p_l)
 d_d= debian/$(p_d)
 
 ifeq ($(DEB_CROSS),yes)
-  usr_lib = $(PFL)/lib
+  ifneq ($(with_deps_on_target_arch_pkgs),yes)
+    usr_lib = $(PFL)/lib
+  else
+    usr_lib = $(PFL)/$(libdir)
+  endif
 else
   usr_lib = $(PFL)/$(libdir)
 endif
@@ -2276,9 +2294,15 @@ ifeq ($(if $(filter yes,$(DEB_CROSS)),$(if $(filter rtlibs,$(DEB_STAGE)),native,
   p_xbase = gcc$(pkg_ver)-base
 else
   # only triggered if DEB_CROSS set
-  p_base = gcc$(pkg_ver)$(cross_bin_arch)-base
-  p_lbase = gcc$(pkg_ver)-cross-base$(GCC_PORTS_BUILD)
-  p_xbase = gcc$(pkg_ver)$(cross_bin_arch)-base
+  ifneq ($(with_deps_on_target_arch_pkgs),yes)
+    p_base = gcc$(pkg_ver)$(cross_bin_arch)-base
+    p_lbase = gcc$(pkg_ver)-cross-base$(GCC_PORTS_BUILD)
+    p_xbase = gcc$(pkg_ver)$(cross_bin_arch)-base
+  else
+    p_base = gcc$(pkg_ver)-base
+    p_lbase = gcc$(pkg_ver)-base$(GCC_PORTS_BUILD)
+    p_xbase = $(p_cpp)
+  endif
 endif
 p_cpp_b = cpp$(pkg_ver)-for-build
 p_hppa64 = gcc$(pkg_ver)-hppa64-linux-gnu
@@ -3043,6 +3067,8 @@ binary-indep: $(foreach i,$(indep_binaries),$(binary_stamp)-$(i)) debian/indep_b
 	fi
 
 ifneq (,$(filter $(DEB_TARGET_ARCH), mips mipsel mips64 mips64el mipsn32 mipsn32el))
+ifneq ($(with_deps_on_target_arch_pkgs),yes)
+
 	for p in `cat debian/indep_binaries debian/indep_binaries.epoch`; do \
 	  p=$${p#-p*}; \
 	  case "$$p" in \
@@ -3050,6 +3076,7 @@ ifneq (,$(filter $(DEB_TARGET_ARCH), mips mipsel mips64 mips64el mipsn32 mipsn32
 	    libn32*) echo mangle $$p; sed -i -r '/^(Dep|Rec|Sug)/s/lib64[^,]+(, *|$$)//g;/^(Dep|Rec|Sug)/s/$(p_lgcc)/$(p_ln32gcc)/;/^(Dep|Rec|Sug)/s/ *, *$$//' debian/$$p/DEBIAN/control;; \
 	  esac; \
 	done
+endif
 endif
 
 	dh_installdeb $(foreach p,$(shell echo `cat debian/indep_binaries.all`),-p$(p))
-- 
2.42.0

