From e21146553371306d20dbbca166436e6f4976f7a0 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  |  9 +++++++
 debian/rules.defs             | 34 ++++++++++++++++++++----
 debian/rules2                 | 49 ++++++++++++++++++++++++++++-------
 5 files changed, 85 insertions(+), 17 deletions(-)

diff --git a/debian/rules.conf b/debian/rules.conf
index 2085811..4fae553 100644
--- a/debian/rules.conf
+++ b/debian/rules.conf
@@ -689,7 +689,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
@@ -1300,7 +1302,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 bac6087..e964b86 100644
--- a/debian/rules.d/binary-base.mk
+++ b/debian/rules.d/binary-base.mk
@@ -32,7 +32,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 cbeeb26..4a3d174 100644
--- a/debian/rules.d/binary-cpp.mk
+++ b/debian/rules.d/binary-cpp.mk
@@ -39,6 +39,13 @@ ifeq ($(unprefixed_names),yes)
 	ln -sf $(cmd_prefix)cpp$(pkg_ver).1 \
 	    $(d_cpp)/$(PF)/share/man/man1/cpp$(pkg_ver).1
   endif
+else
+  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
 
 	mkdir -p $(d_cpp)/usr/share/lintian/overrides
@@ -49,7 +56,9 @@ ifeq ($(GFDL_INVARIANT_FREE),yes)
 	  >> $(d_cpp)/usr/share/lintian/overrides/$(p_cpp)
 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)
 
 ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTONS)))
diff --git a/debian/rules.defs b/debian/rules.defs
index f83e22a..37c5647 100644
--- a/debian/rules.defs
+++ b/debian/rules.defs
@@ -207,10 +207,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
@@ -239,6 +245,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
@@ -525,7 +538,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
@@ -2137,12 +2154,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' \
@@ -2151,7 +2169,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 6d90a66..0596211 100644
--- a/debian/rules2
+++ b/debian/rules2
@@ -786,8 +786,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)
@@ -914,21 +917,33 @@ endif
 
 # PFL is the installation prefix with DEB_TARGET_GNU_TYPE attached for cross builds
 ifeq ($(DEB_CROSS),yes)
-  PFL		= $(PF)/$(DEB_TARGET_GNU_TYPE)
+  ifneq ($(with_deps_on_target_arch_pkgs),yes)
+    PFL		= $(PF)/$(DEB_TARGET_GNU_TYPE)
+  else
+    PFL		= $(PF)
+  endif
 else
   PFL		= $(PF)
 endif
 
 # RPF is the base prefix or installation prefix with DEB_TARGET_GNU_TYPE attached for cross builds
 ifeq ($(DEB_CROSS),yes)
-  RPF		= $(PF)/$(DEB_TARGET_GNU_TYPE)
+  ifneq ($(with_deps_on_target_arch_pkgs),yes)
+    RPF		= $(PF)/$(DEB_TARGET_GNU_TYPE)
+  else
+    RPF		=
+  endif
 else
   RPF		=
 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
@@ -954,7 +969,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
 
@@ -976,7 +993,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
@@ -1929,9 +1950,16 @@ ifeq ($(if $(filter yes,$(DEB_CROSS)),$(if $(filter rtlibs,$(DEB_STAGE)),native,
   p_doc  = gcc$(pkg_ver)-doc
 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
+
   p_cpp  = cpp$(pkg_ver)$(cross_bin_arch)
   p_gcc  = gcc$(pkg_ver)$(cross_bin_arch)
   p_cxx  = g++$(pkg_ver)$(cross_bin_arch)
@@ -2637,6 +2665,8 @@ binary-indep: debian/indep_binaries.all
 	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 \
@@ -2644,6 +2674,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.17.1

