From eb500a5782d74caaf652172f951f0767c9f91e74 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Sun, 22 May 2016 09:52:23 +0100
Subject: [PATCH] [configury] Deal better with --with-build-sysroot

... and don't try to pass SYSROOT_CFLAGS_FOR_TARGET in TEST_ALWAYS_FLAGS.
This breaks gnat testing, since gnatmake does't accept --sysroot.
TODO; figure out how/where to put the sysroot flags.
---
 Makefile.in                       | 15 +++++++++++----
 gcc/Makefile.in                   |  2 +-
 gcc/ada/gcc-interface/Makefile.in |  1 +
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 899f4332ce..70078120f0 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -231,6 +231,7 @@ HOST_EXPORTS = \
 @endif gcc-bootstrap
 	$(RPATH_ENVVAR)=`echo "$(HOST_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR);
 
+
 POSTSTAGE1_CXX_EXPORT = \
 	CXX='$(CXX)'; export CXX; \
 	CXX_FOR_BUILD='$(CXX_FOR_BUILD)'; export CXX_FOR_BUILD;
@@ -245,11 +246,13 @@ POSTSTAGE1_CXX_EXPORT = \
 	  `if $(LEAN); then echo ' -isystem '; else echo ' -I'; fi`$$r/prev-$(TARGET_SUBDIR)/libstdc++-v3/include \
 	  `if $(LEAN); then echo ' -isystem '; else echo ' -I'; fi`$$s/libstdc++-v3/libsupc++ \
 	  -L$$r/prev-$(TARGET_SUBDIR)/libstdc++-v3/src/.libs \
-	  -L$$r/prev-$(TARGET_SUBDIR)/libstdc++-v3/libsupc++/.libs"; \
-	  export CXX; \
+	  -L$$r/prev-$(TARGET_SUBDIR)/libstdc++-v3/libsupc++/.libs \
+	  $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS "; export CXX; \
 	CXX_FOR_BUILD="$$CXX"; export CXX_FOR_BUILD;
 @endif target-libstdc++-v3-bootstrap
 
+POSTSTAGE1_LDFLAGS += $(SYSROOT_CFLAGS_FOR_TARGET)
+
 # Similar, for later GCC stages.
 POSTSTAGE1_HOST_EXPORTS = \
 	$(HOST_EXPORTS) \
@@ -610,8 +613,6 @@ COMPILER_NM_FOR_TARGET=@COMPILER_NM_FOR_TARGET@
 CFLAGS_FOR_TARGET = @CFLAGS_FOR_TARGET@
 CXXFLAGS_FOR_TARGET = @CXXFLAGS_FOR_TARGET@
 
-LIBCFLAGS_FOR_TARGET = $(CFLAGS_FOR_TARGET)
-LIBCXXFLAGS_FOR_TARGET = $(CXXFLAGS_FOR_TARGET) -fno-implicit-templates
 LDFLAGS_FOR_TARGET = @LDFLAGS_FOR_TARGET@
 GOCFLAGS_FOR_TARGET = -O2 -g
 GDCFLAGS_FOR_TARGET = -O2 -g
@@ -621,6 +622,12 @@ SYSROOT_CFLAGS_FOR_TARGET = @SYSROOT_CFLAGS_FOR_TARGET@
 DEBUG_PREFIX_CFLAGS_FOR_TARGET = @DEBUG_PREFIX_CFLAGS_FOR_TARGET@
 
 XGCC_FLAGS_FOR_TARGET = $(FLAGS_FOR_TARGET) $(SYSROOT_CFLAGS_FOR_TARGET) $(DEBUG_PREFIX_CFLAGS_FOR_TARGET)
+LDFLAGS_FOR_TARGET += $(SYSROOT_CFLAGS_FOR_TARGET)
+CFLAGS_FOR_TARGET += $(SYSROOT_CFLAGS_FOR_TARGET)
+CXXFLAGS_FOR_TARGET += $(SYSROOT_CFLAGS_FOR_TARGET)
+CPPFLAGS_FOR_TARGET += $(SYSROOT_CFLAGS_FOR_TARGET)
+LIBCFLAGS_FOR_TARGET = $(CFLAGS_FOR_TARGET)
+LIBCXXFLAGS_FOR_TARGET = $(CXXFLAGS_FOR_TARGET) -fno-implicit-templates
 
 # ------------------------------------
 # Miscellaneous targets and flag lists
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 881487b083..69bda4e042 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -3891,7 +3891,7 @@ site.exp: ./config.status Makefile
 	@echo "set HOSTCXXFLAGS \"$(CXXFLAGS)\"" >> ./site.tmp
 # TEST_ALWAYS_FLAGS are flags that should be passed to every compilation.
 # They are passed first to allow individual tests to override them.
-	@echo "set TEST_ALWAYS_FLAGS \"$(SYSROOT_CFLAGS_FOR_TARGET)\"" >> ./site.tmp
+	@echo "set TEST_ALWAYS_FLAGS \"\"" >> ./site.tmp
 # When running the tests we set GCC_EXEC_PREFIX to the install tree so that
 # files that have already been installed there will be found.  The -B option
 # overrides it, so use of GCC_EXEC_PREFIX will not result in using GCC files
diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in
index 4d870c2f9c..7efd6cd0b2 100644
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -376,6 +376,7 @@ TOOLS_FLAGS_TO_PASS=		\
 	"GNATLINK=$(GNATLINK)"	\
 	"GNATBIND=$(GNATBIND)"
 
+GCC_LINK_FLAGS += $(SYSROOT_CFLAGS_FOR_TARGET)
 GCC_LINK=$(CXX) $(GCC_LINK_FLAGS) $(ADA_INCLUDES) $(LDFLAGS)
 
 # Build directory for the tools. Let's copy the target-dependent
-- 
2.17.1