public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Recover in-tree libiconv build support
@ 2024-04-13 21:58 Arsen Arsenović
  2024-04-13 21:58 ` [PATCH 1/3] toplevel: don't override gettext-runtime/configure-discovered build args Arsen Arsenović
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Arsen Arsenović @ 2024-04-13 21:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Kévin Le Gouguec, Arsen Arsenović

Evening!

This patchset recovers support for building the toolchain tree with
in-tree libiconv being used for host modules and gettext.  As spotted by
Kévin Le Gouguec <legouguec@adacore.com>, I accidentally removed this
functionality earlier.

This patchset includes the patch sent as:

https://inbox.sourceware.gcc-patches/20231221193243.368541-1-arsen@aarsen.me/

... and so, supersedes that patchset.

For the in-tree case, the old patch functionality was restored and
rebased on top of current iconv.m4.  Of course, this does not work for
gettext, an out-of-tree lib depending on the in-tree libiconv, so, for
that case, we needed to provide the right information to configure, and
suppress logic in iconv.m4 using cache vars.

Build-tested on arm64-apple-darwin21.6.0, and I intend to do further
testing tomorrow.

OK for trunk?  It would be good to get these patches into GCC 14.

I apologize for being quite late with delivering these, I have,
unfortunately, been busied by various external factors.  Hopefully, it
is not too late yet.

Thanks in advance, have a lovely night!

Arsen Arsenović (3):
  toplevel: don't override gettext-runtime/configure-discovered build
    args
  gitignore: ignore /libiconv*
  *: support in-tree libiconv again

 .gitignore             |   1 +
 Makefile.def           |   9 +-
 Makefile.in            | 100 ++++++++---------
 Makefile.tpl           |   8 +-
 config/iconv.m4        |  50 +++++++--
 configure              |  25 +++++
 configure.ac           |  21 ++++
 gcc/configure          | 240 +++++++++++++++++++++++++++++++----------
 libcpp/configure       | 206 ++++++++++++++++++++++++++++-------
 libstdc++-v3/configure | 121 ++++++++++++++++-----
 10 files changed, 601 insertions(+), 180 deletions(-)

-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] toplevel: don't override gettext-runtime/configure-discovered build args
  2024-04-13 21:58 [PATCH 0/3] Recover in-tree libiconv build support Arsen Arsenović
@ 2024-04-13 21:58 ` Arsen Arsenović
  2024-04-13 21:58 ` [PATCH 2/3] gitignore: ignore /libiconv* Arsen Arsenović
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Arsen Arsenović @ 2024-04-13 21:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Kévin Le Gouguec, Arsen Arsenović

ChangeLog:
	PR bootstrap/112534
	* Makefile.def (host-gettext): Set all_args_override="".
	* Makefile.in: Regenerate.
	* Makefile.tpl (all--args): Define as a helper macro for
	computing extra arguments to make.
	(all): Use all--args over args.
---
 Makefile.def |  2 ++
 Makefile.in  | 40 +++++++++++++++++++++-------------------
 Makefile.tpl |  8 +++++---
 3 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/Makefile.def b/Makefile.def
index 19954e7d7318..d25edb6ed76d 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -76,6 +76,8 @@ host_modules= { module= gprof; };
 host_modules= { module= gprofng; };
 host_modules= { module= gettext; bootstrap=true; no_install=true;
                 module_srcdir= "gettext/gettext-runtime";
+		// Don't override configure-discovered build arguments
+		all_args_override="";
 		// We always build gettext with pic, because some packages (e.g. gdbserver)
 		// need it in some configuratons, which is determined via nontrivial tests.
 		// Always enabling pic seems to make sense for something tied to
diff --git a/Makefile.in b/Makefile.in
index db4fa6c62605..f71f515b7aa1 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -3174,6 +3174,8 @@ TAGS: do-TAGS
 
 
 
+
+
 # --------------------------------------
 # Modules which run on the build machine
 # --------------------------------------
@@ -20195,7 +20197,7 @@ all-gettext: configure-gettext
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	$(HOST_EXPORTS)  \
 	(cd $(HOST_SUBDIR)/gettext && \
-	  $(MAKE) $(BASE_FLAGS_TO_PASS) $(EXTRA_HOST_FLAGS) $(STAGE1_FLAGS_TO_PASS)  \
+	  $(MAKE) $(BASE_FLAGS_TO_PASS)  $(STAGE1_FLAGS_TO_PASS)  \
 		$(TARGET-gettext))
 @endif gettext
 
@@ -20225,7 +20227,7 @@ all-stage1-gettext: configure-stage1-gettext
 		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
 		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
 		LIBCFLAGS_FOR_TARGET="$(LIBCFLAGS_FOR_TARGET)" \
-		$(EXTRA_HOST_FLAGS)  \
+		  \
 		$(STAGE1_FLAGS_TO_PASS)  \
 		TFLAGS="$(STAGE1_TFLAGS)"  \
 		$(TARGET-stage1-gettext)
@@ -20240,7 +20242,7 @@ clean-stage1-gettext:
 	  $(MAKE) stage1-start; \
 	fi; \
 	cd $(HOST_SUBDIR)/gettext && \
-	$(MAKE) $(EXTRA_HOST_FLAGS)  \
+	$(MAKE)   \
 	$(STAGE1_FLAGS_TO_PASS)  clean
 @endif gettext-bootstrap
 
@@ -20270,7 +20272,7 @@ all-stage2-gettext: configure-stage2-gettext
 		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
 		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
 		LIBCFLAGS_FOR_TARGET="$(LIBCFLAGS_FOR_TARGET)" \
-		$(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  \
+		 $(POSTSTAGE1_FLAGS_TO_PASS)  \
 		TFLAGS="$(STAGE2_TFLAGS)"  \
 		$(TARGET-stage2-gettext)
 
@@ -20284,7 +20286,7 @@ clean-stage2-gettext:
 	  $(MAKE) stage2-start; \
 	fi; \
 	cd $(HOST_SUBDIR)/gettext && \
-	$(MAKE) $(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  clean
+	$(MAKE)  $(POSTSTAGE1_FLAGS_TO_PASS)  clean
 @endif gettext-bootstrap
 
 
@@ -20313,7 +20315,7 @@ all-stage3-gettext: configure-stage3-gettext
 		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
 		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
 		LIBCFLAGS_FOR_TARGET="$(LIBCFLAGS_FOR_TARGET)" \
-		$(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  \
+		 $(POSTSTAGE1_FLAGS_TO_PASS)  \
 		TFLAGS="$(STAGE3_TFLAGS)"  \
 		$(TARGET-stage3-gettext)
 
@@ -20327,7 +20329,7 @@ clean-stage3-gettext:
 	  $(MAKE) stage3-start; \
 	fi; \
 	cd $(HOST_SUBDIR)/gettext && \
-	$(MAKE) $(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  clean
+	$(MAKE)  $(POSTSTAGE1_FLAGS_TO_PASS)  clean
 @endif gettext-bootstrap
 
 
@@ -20356,7 +20358,7 @@ all-stage4-gettext: configure-stage4-gettext
 		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
 		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
 		LIBCFLAGS_FOR_TARGET="$(LIBCFLAGS_FOR_TARGET)" \
-		$(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  \
+		 $(POSTSTAGE1_FLAGS_TO_PASS)  \
 		TFLAGS="$(STAGE4_TFLAGS)"  \
 		$(TARGET-stage4-gettext)
 
@@ -20370,7 +20372,7 @@ clean-stage4-gettext:
 	  $(MAKE) stage4-start; \
 	fi; \
 	cd $(HOST_SUBDIR)/gettext && \
-	$(MAKE) $(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  clean
+	$(MAKE)  $(POSTSTAGE1_FLAGS_TO_PASS)  clean
 @endif gettext-bootstrap
 
 
@@ -20399,7 +20401,7 @@ all-stageprofile-gettext: configure-stageprofile-gettext
 		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
 		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
 		LIBCFLAGS_FOR_TARGET="$(LIBCFLAGS_FOR_TARGET)" \
-		$(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  \
+		 $(POSTSTAGE1_FLAGS_TO_PASS)  \
 		TFLAGS="$(STAGEprofile_TFLAGS)"  \
 		$(TARGET-stageprofile-gettext)
 
@@ -20413,7 +20415,7 @@ clean-stageprofile-gettext:
 	  $(MAKE) stageprofile-start; \
 	fi; \
 	cd $(HOST_SUBDIR)/gettext && \
-	$(MAKE) $(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  clean
+	$(MAKE)  $(POSTSTAGE1_FLAGS_TO_PASS)  clean
 @endif gettext-bootstrap
 
 
@@ -20442,7 +20444,7 @@ all-stagetrain-gettext: configure-stagetrain-gettext
 		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
 		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
 		LIBCFLAGS_FOR_TARGET="$(LIBCFLAGS_FOR_TARGET)" \
-		$(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  \
+		 $(POSTSTAGE1_FLAGS_TO_PASS)  \
 		TFLAGS="$(STAGEtrain_TFLAGS)"  \
 		$(TARGET-stagetrain-gettext)
 
@@ -20456,7 +20458,7 @@ clean-stagetrain-gettext:
 	  $(MAKE) stagetrain-start; \
 	fi; \
 	cd $(HOST_SUBDIR)/gettext && \
-	$(MAKE) $(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  clean
+	$(MAKE)  $(POSTSTAGE1_FLAGS_TO_PASS)  clean
 @endif gettext-bootstrap
 
 
@@ -20485,7 +20487,7 @@ all-stagefeedback-gettext: configure-stagefeedback-gettext
 		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
 		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
 		LIBCFLAGS_FOR_TARGET="$(LIBCFLAGS_FOR_TARGET)" \
-		$(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  \
+		 $(POSTSTAGE1_FLAGS_TO_PASS)  \
 		TFLAGS="$(STAGEfeedback_TFLAGS)"  \
 		$(TARGET-stagefeedback-gettext)
 
@@ -20499,7 +20501,7 @@ clean-stagefeedback-gettext:
 	  $(MAKE) stagefeedback-start; \
 	fi; \
 	cd $(HOST_SUBDIR)/gettext && \
-	$(MAKE) $(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  clean
+	$(MAKE)  $(POSTSTAGE1_FLAGS_TO_PASS)  clean
 @endif gettext-bootstrap
 
 
@@ -20528,7 +20530,7 @@ all-stageautoprofile-gettext: configure-stageautoprofile-gettext
 		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
 		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
 		LIBCFLAGS_FOR_TARGET="$(LIBCFLAGS_FOR_TARGET)" \
-		$(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  \
+		 $(POSTSTAGE1_FLAGS_TO_PASS)  \
 		TFLAGS="$(STAGEautoprofile_TFLAGS)"  \
 		$(TARGET-stageautoprofile-gettext)
 
@@ -20542,7 +20544,7 @@ clean-stageautoprofile-gettext:
 	  $(MAKE) stageautoprofile-start; \
 	fi; \
 	cd $(HOST_SUBDIR)/gettext && \
-	$(MAKE) $(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  clean
+	$(MAKE)  $(POSTSTAGE1_FLAGS_TO_PASS)  clean
 @endif gettext-bootstrap
 
 
@@ -20571,7 +20573,7 @@ all-stageautofeedback-gettext: configure-stageautofeedback-gettext
 		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
 		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
 		LIBCFLAGS_FOR_TARGET="$(LIBCFLAGS_FOR_TARGET)" \
-		$(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  \
+		 $(POSTSTAGE1_FLAGS_TO_PASS)  \
 		TFLAGS="$(STAGEautofeedback_TFLAGS)" PERF_DATA=perf.data \
 		$(TARGET-stageautofeedback-gettext)
 
@@ -20585,7 +20587,7 @@ clean-stageautofeedback-gettext:
 	  $(MAKE) stageautofeedback-start; \
 	fi; \
 	cd $(HOST_SUBDIR)/gettext && \
-	$(MAKE) $(EXTRA_HOST_FLAGS) $(POSTSTAGE1_FLAGS_TO_PASS)  clean
+	$(MAKE)  $(POSTSTAGE1_FLAGS_TO_PASS)  clean
 @endif gettext-bootstrap
 
 
diff --git a/Makefile.tpl b/Makefile.tpl
index 1d5813cd5695..dd3ec65036e3 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -1261,6 +1261,8 @@ configure-stage[+id+]-[+prefix+][+module+]:
 [+ ENDIF bootstrap +]
 [+ ENDDEF +]
 
+[+ DEFINE all--args +][+ (get "all_args_override" (get "args")) +][+ ENDDEF +]
+
 [+ DEFINE all +]
 .PHONY: all-[+prefix+][+module+] maybe-all-[+prefix+][+module+]
 maybe-all-[+prefix+][+module+]:
@@ -1277,7 +1279,7 @@ all-[+prefix+][+module+]: configure-[+prefix+][+module+][+ IF bootstrap +][+ ELS
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	[+exports+] [+extra_exports+] \
 	(cd [+subdir+]/[+module+] && \
-	  $(MAKE) $(BASE_FLAGS_TO_PASS) [+args+] [+stage1_args+] [+extra_make_flags+] \
+	  $(MAKE) $(BASE_FLAGS_TO_PASS) [+all--args+] [+stage1_args+] [+extra_make_flags+] \
 		$(TARGET-[+prefix+][+module+]))
 @endif [+prefix+][+module+]
 
@@ -1312,7 +1314,7 @@ all-stage[+id+]-[+prefix+][+module+]: configure-stage[+id+]-[+prefix+][+module+]
 		CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
 		CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
 		LIBCFLAGS_FOR_TARGET="$(LIBCFLAGS_FOR_TARGET)" \
-		[+args+] [+IF prev +][+poststage1_args+][+ ELSE prev +] \
+		[+all--args+] [+IF prev +][+poststage1_args+][+ ELSE prev +] \
 		[+stage1_args+][+ ENDIF prev +] [+extra_make_flags+] \
 		TFLAGS="$(STAGE[+id+]_TFLAGS)" [+profile_data+] \
 		$(TARGET-stage[+id+]-[+prefix+][+module+])
@@ -1327,7 +1329,7 @@ clean-stage[+id+]-[+prefix+][+module+]:
 	  $(MAKE) stage[+id+]-start; \
 	fi; \
 	cd [+subdir+]/[+module+] && \
-	$(MAKE) [+args+] [+ IF prev +][+poststage1_args+][+ ELSE prev +] \
+	$(MAKE) [+all--args+] [+ IF prev +][+poststage1_args+][+ ELSE prev +] \
 	[+stage1_args+][+ ENDIF prev +] [+extra_make_flags+] clean
 @endif [+prefix+][+module+]-bootstrap
 
-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/3] gitignore: ignore /libiconv*
  2024-04-13 21:58 [PATCH 0/3] Recover in-tree libiconv build support Arsen Arsenović
  2024-04-13 21:58 ` [PATCH 1/3] toplevel: don't override gettext-runtime/configure-discovered build args Arsen Arsenović
@ 2024-04-13 21:58 ` Arsen Arsenović
  2024-04-13 21:58 ` [PATCH 3/3] *: support in-tree libiconv again Arsen Arsenović
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Arsen Arsenović @ 2024-04-13 21:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Kévin Le Gouguec, Arsen Arsenović

ChangeLog:

	* .gitignore: Ignore /libiconv* as with other possibly-in-tree
	libs.
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 93a16b0b950c..3528d9a115ee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -70,3 +70,4 @@ stamp-*
 /gmp*
 /isl*
 /gettext*
+/libiconv*
-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/3] *: support in-tree libiconv again
  2024-04-13 21:58 [PATCH 0/3] Recover in-tree libiconv build support Arsen Arsenović
  2024-04-13 21:58 ` [PATCH 1/3] toplevel: don't override gettext-runtime/configure-discovered build args Arsen Arsenović
  2024-04-13 21:58 ` [PATCH 2/3] gitignore: ignore /libiconv* Arsen Arsenović
@ 2024-04-13 21:58 ` Arsen Arsenović
  2024-04-18 16:41 ` [PATCH 0/3] Recover in-tree libiconv build support Kévin Le Gouguec
  2024-05-04 18:48 ` Ping: " Arsen Arsenović
  4 siblings, 0 replies; 8+ messages in thread
From: Arsen Arsenović @ 2024-04-13 21:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Kévin Le Gouguec, Arsen Arsenović

ChangeLog:

	* Makefile.def: Inform gettext of our freshly-built libiconv.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (LIBICONV_SIBLING): If an in-tree host libiconv
	is being built, set this variable to the path to libiconv.a
	(LTLIBICONV_SIBLING): If an in-tree host libiconv is being
	built, set this variable to the path to libiconv.la.
	(LIBICONV_EXTRA_CPPFLAGS): If an in-tree host libiconv is being,
	set this variable to the appropriate CPPFLAGS for using the new
	libiconv.
	(LIBICONV_CVS): If an in-tree host libiconv is being, set this
	variable to the cache variables that iconv.m4 uses that need to
	be specicified in order to use the related variables.

config/ChangeLog:

	* iconv.m4: Restore modifications from GCC commit
	d485982286692075d175dbbcf17d00431106ce96 and co.

gcc/ChangeLog:

	* configure: Regenerate.

libcpp/ChangeLog:

	* configure: Regenerate.

libstdc++-v3/ChangeLog:

	* configure: Regenerate.
---
 Makefile.def           |   7 +-
 Makefile.in            |  60 +++++------
 config/iconv.m4        |  50 +++++++--
 configure              |  25 +++++
 configure.ac           |  21 ++++
 gcc/configure          | 240 +++++++++++++++++++++++++++++++----------
 libcpp/configure       | 206 ++++++++++++++++++++++++++++-------
 libstdc++-v3/configure | 121 ++++++++++++++++-----
 8 files changed, 572 insertions(+), 158 deletions(-)

diff --git a/Makefile.def b/Makefile.def
index d25edb6ed76d..c37f78f2e1da 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -78,11 +78,16 @@ host_modules= { module= gettext; bootstrap=true; no_install=true;
                 module_srcdir= "gettext/gettext-runtime";
 		// Don't override configure-discovered build arguments
 		all_args_override="";
+		// The toolchain build system overrides LDFLAGS that configure
+		// discovers, so specifying these flags as part of the
+		// configure arguments will not work.  Instead, we need to
+		// export them at configure time as well as make time.
+		extra_exports='LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS;';
 		// We always build gettext with pic, because some packages (e.g. gdbserver)
 		// need it in some configuratons, which is determined via nontrivial tests.
 		// Always enabling pic seems to make sense for something tied to
 		// user-facing output.
-		extra_configure_flags='--disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf';
+		extra_configure_flags='--disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@';
 		missing= pdf;
 		missing= html;
 		missing= info;
diff --git a/Makefile.in b/Makefile.in
index f71f515b7aa1..d65b4b2994a7 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -19856,7 +19856,7 @@ configure-gettext:
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	test ! -f $(HOST_SUBDIR)/gettext/Makefile || exit 0; \
 	$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gettext; \
-	$(HOST_EXPORTS)  \
+	$(HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	echo Configuring in $(HOST_SUBDIR)/gettext; \
 	cd "$(HOST_SUBDIR)/gettext" || exit 1; \
 	case $(srcdir) in \
@@ -19869,7 +19869,7 @@ configure-gettext:
 	  $$s/$$module_srcdir/configure \
 	  --srcdir=$${topdir}/$$module_srcdir \
 	  $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
-	  --target=${target_alias} --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf \
+	  --target=${target_alias} --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@ \
 	  || exit 1
 @endif gettext
 
@@ -19889,7 +19889,7 @@ configure-stage1-gettext:
 	$(HOST_EXPORTS) \
 	CFLAGS="$(STAGE1_CFLAGS)"; export CFLAGS; \
 	CXXFLAGS="$(STAGE1_CXXFLAGS)"; export CXXFLAGS; \
-	LIBCFLAGS="$(LIBCFLAGS)"; export LIBCFLAGS;  \
+	LIBCFLAGS="$(LIBCFLAGS)"; export LIBCFLAGS; LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	echo Configuring stage 1 in $(HOST_SUBDIR)/gettext; \
 	$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gettext; \
 	cd $(HOST_SUBDIR)/gettext || exit 1; \
@@ -19905,7 +19905,7 @@ configure-stage1-gettext:
 	  --target=${target_alias} \
 	   \
 	  $(STAGE1_CONFIGURE_FLAGS) \
-	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf
+	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@
 @endif gettext-bootstrap
 
 .PHONY: configure-stage2-gettext maybe-configure-stage2-gettext
@@ -19923,7 +19923,7 @@ configure-stage2-gettext:
 	$(POSTSTAGE1_HOST_EXPORTS) \
 	CFLAGS="$(STAGE2_CFLAGS)"; export CFLAGS; \
 	CXXFLAGS="$(STAGE2_CXXFLAGS)"; export CXXFLAGS; \
-	LIBCFLAGS="$(STAGE2_CFLAGS)"; export LIBCFLAGS;  \
+	LIBCFLAGS="$(STAGE2_CFLAGS)"; export LIBCFLAGS; LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	echo Configuring stage 2 in $(HOST_SUBDIR)/gettext; \
 	$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gettext; \
 	cd $(HOST_SUBDIR)/gettext || exit 1; \
@@ -19939,7 +19939,7 @@ configure-stage2-gettext:
 	  --target=${target_alias} \
 	  --with-build-libsubdir=$(HOST_SUBDIR) \
 	  $(STAGE2_CONFIGURE_FLAGS) \
-	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf
+	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@
 @endif gettext-bootstrap
 
 .PHONY: configure-stage3-gettext maybe-configure-stage3-gettext
@@ -19957,7 +19957,7 @@ configure-stage3-gettext:
 	$(POSTSTAGE1_HOST_EXPORTS) \
 	CFLAGS="$(STAGE3_CFLAGS)"; export CFLAGS; \
 	CXXFLAGS="$(STAGE3_CXXFLAGS)"; export CXXFLAGS; \
-	LIBCFLAGS="$(STAGE3_CFLAGS)"; export LIBCFLAGS;  \
+	LIBCFLAGS="$(STAGE3_CFLAGS)"; export LIBCFLAGS; LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	echo Configuring stage 3 in $(HOST_SUBDIR)/gettext; \
 	$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gettext; \
 	cd $(HOST_SUBDIR)/gettext || exit 1; \
@@ -19973,7 +19973,7 @@ configure-stage3-gettext:
 	  --target=${target_alias} \
 	  --with-build-libsubdir=$(HOST_SUBDIR) \
 	  $(STAGE3_CONFIGURE_FLAGS) \
-	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf
+	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@
 @endif gettext-bootstrap
 
 .PHONY: configure-stage4-gettext maybe-configure-stage4-gettext
@@ -19991,7 +19991,7 @@ configure-stage4-gettext:
 	$(POSTSTAGE1_HOST_EXPORTS) \
 	CFLAGS="$(STAGE4_CFLAGS)"; export CFLAGS; \
 	CXXFLAGS="$(STAGE4_CXXFLAGS)"; export CXXFLAGS; \
-	LIBCFLAGS="$(STAGE4_CFLAGS)"; export LIBCFLAGS;  \
+	LIBCFLAGS="$(STAGE4_CFLAGS)"; export LIBCFLAGS; LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	echo Configuring stage 4 in $(HOST_SUBDIR)/gettext; \
 	$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gettext; \
 	cd $(HOST_SUBDIR)/gettext || exit 1; \
@@ -20007,7 +20007,7 @@ configure-stage4-gettext:
 	  --target=${target_alias} \
 	  --with-build-libsubdir=$(HOST_SUBDIR) \
 	  $(STAGE4_CONFIGURE_FLAGS) \
-	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf
+	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@
 @endif gettext-bootstrap
 
 .PHONY: configure-stageprofile-gettext maybe-configure-stageprofile-gettext
@@ -20025,7 +20025,7 @@ configure-stageprofile-gettext:
 	$(POSTSTAGE1_HOST_EXPORTS) \
 	CFLAGS="$(STAGEprofile_CFLAGS)"; export CFLAGS; \
 	CXXFLAGS="$(STAGEprofile_CXXFLAGS)"; export CXXFLAGS; \
-	LIBCFLAGS="$(STAGEprofile_CFLAGS)"; export LIBCFLAGS;  \
+	LIBCFLAGS="$(STAGEprofile_CFLAGS)"; export LIBCFLAGS; LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	echo Configuring stage profile in $(HOST_SUBDIR)/gettext; \
 	$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gettext; \
 	cd $(HOST_SUBDIR)/gettext || exit 1; \
@@ -20041,7 +20041,7 @@ configure-stageprofile-gettext:
 	  --target=${target_alias} \
 	  --with-build-libsubdir=$(HOST_SUBDIR) \
 	  $(STAGEprofile_CONFIGURE_FLAGS) \
-	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf
+	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@
 @endif gettext-bootstrap
 
 .PHONY: configure-stagetrain-gettext maybe-configure-stagetrain-gettext
@@ -20059,7 +20059,7 @@ configure-stagetrain-gettext:
 	$(POSTSTAGE1_HOST_EXPORTS) \
 	CFLAGS="$(STAGEtrain_CFLAGS)"; export CFLAGS; \
 	CXXFLAGS="$(STAGEtrain_CXXFLAGS)"; export CXXFLAGS; \
-	LIBCFLAGS="$(STAGEtrain_CFLAGS)"; export LIBCFLAGS;  \
+	LIBCFLAGS="$(STAGEtrain_CFLAGS)"; export LIBCFLAGS; LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	echo Configuring stage train in $(HOST_SUBDIR)/gettext; \
 	$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gettext; \
 	cd $(HOST_SUBDIR)/gettext || exit 1; \
@@ -20075,7 +20075,7 @@ configure-stagetrain-gettext:
 	  --target=${target_alias} \
 	  --with-build-libsubdir=$(HOST_SUBDIR) \
 	  $(STAGEtrain_CONFIGURE_FLAGS) \
-	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf
+	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@
 @endif gettext-bootstrap
 
 .PHONY: configure-stagefeedback-gettext maybe-configure-stagefeedback-gettext
@@ -20093,7 +20093,7 @@ configure-stagefeedback-gettext:
 	$(POSTSTAGE1_HOST_EXPORTS) \
 	CFLAGS="$(STAGEfeedback_CFLAGS)"; export CFLAGS; \
 	CXXFLAGS="$(STAGEfeedback_CXXFLAGS)"; export CXXFLAGS; \
-	LIBCFLAGS="$(STAGEfeedback_CFLAGS)"; export LIBCFLAGS;  \
+	LIBCFLAGS="$(STAGEfeedback_CFLAGS)"; export LIBCFLAGS; LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	echo Configuring stage feedback in $(HOST_SUBDIR)/gettext; \
 	$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gettext; \
 	cd $(HOST_SUBDIR)/gettext || exit 1; \
@@ -20109,7 +20109,7 @@ configure-stagefeedback-gettext:
 	  --target=${target_alias} \
 	  --with-build-libsubdir=$(HOST_SUBDIR) \
 	  $(STAGEfeedback_CONFIGURE_FLAGS) \
-	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf
+	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@
 @endif gettext-bootstrap
 
 .PHONY: configure-stageautoprofile-gettext maybe-configure-stageautoprofile-gettext
@@ -20127,7 +20127,7 @@ configure-stageautoprofile-gettext:
 	$(POSTSTAGE1_HOST_EXPORTS) \
 	CFLAGS="$(STAGEautoprofile_CFLAGS)"; export CFLAGS; \
 	CXXFLAGS="$(STAGEautoprofile_CXXFLAGS)"; export CXXFLAGS; \
-	LIBCFLAGS="$(STAGEautoprofile_CFLAGS)"; export LIBCFLAGS;  \
+	LIBCFLAGS="$(STAGEautoprofile_CFLAGS)"; export LIBCFLAGS; LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	echo Configuring stage autoprofile in $(HOST_SUBDIR)/gettext; \
 	$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gettext; \
 	cd $(HOST_SUBDIR)/gettext || exit 1; \
@@ -20143,7 +20143,7 @@ configure-stageautoprofile-gettext:
 	  --target=${target_alias} \
 	  --with-build-libsubdir=$(HOST_SUBDIR) \
 	  $(STAGEautoprofile_CONFIGURE_FLAGS) \
-	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf
+	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@
 @endif gettext-bootstrap
 
 .PHONY: configure-stageautofeedback-gettext maybe-configure-stageautofeedback-gettext
@@ -20161,7 +20161,7 @@ configure-stageautofeedback-gettext:
 	$(POSTSTAGE1_HOST_EXPORTS) \
 	CFLAGS="$(STAGEautofeedback_CFLAGS)"; export CFLAGS; \
 	CXXFLAGS="$(STAGEautofeedback_CXXFLAGS)"; export CXXFLAGS; \
-	LIBCFLAGS="$(STAGEautofeedback_CFLAGS)"; export LIBCFLAGS;  \
+	LIBCFLAGS="$(STAGEautofeedback_CFLAGS)"; export LIBCFLAGS; LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	echo Configuring stage autofeedback in $(HOST_SUBDIR)/gettext; \
 	$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gettext; \
 	cd $(HOST_SUBDIR)/gettext || exit 1; \
@@ -20177,7 +20177,7 @@ configure-stageautofeedback-gettext:
 	  --target=${target_alias} \
 	  --with-build-libsubdir=$(HOST_SUBDIR) \
 	  $(STAGEautofeedback_CONFIGURE_FLAGS) \
-	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf
+	  --disable-shared --disable-threads --disable-java --disable-csharp --with-pic --disable-libasprintf CPPFLAGS="@LIBICONV_EXTRA_CPPFLAGS@ $$CPPFLAGS" @LIBICONV_CVS@
 @endif gettext-bootstrap
 
 
@@ -20195,7 +20195,7 @@ maybe-all-gettext: all-gettext
 all-gettext: configure-gettext
 	@r=`${PWD_COMMAND}`; export r; \
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
-	$(HOST_EXPORTS)  \
+	$(HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	(cd $(HOST_SUBDIR)/gettext && \
 	  $(MAKE) $(BASE_FLAGS_TO_PASS)  $(STAGE1_FLAGS_TO_PASS)  \
 		$(TARGET-gettext))
@@ -20216,7 +20216,7 @@ all-stage1-gettext: configure-stage1-gettext
 	@r=`${PWD_COMMAND}`; export r; \
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	TFLAGS="$(STAGE1_TFLAGS)"; \
-	$(HOST_EXPORTS)  \
+	$(HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	cd $(HOST_SUBDIR)/gettext && \
 	 \
 	$(MAKE) $(BASE_FLAGS_TO_PASS) \
@@ -20261,7 +20261,7 @@ all-stage2-gettext: configure-stage2-gettext
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	TFLAGS="$(STAGE2_TFLAGS)"; \
 	$(HOST_EXPORTS) \
-	$(POSTSTAGE1_HOST_EXPORTS)  \
+	$(POSTSTAGE1_HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	cd $(HOST_SUBDIR)/gettext && \
 	 \
 	$(MAKE) $(BASE_FLAGS_TO_PASS) \
@@ -20304,7 +20304,7 @@ all-stage3-gettext: configure-stage3-gettext
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	TFLAGS="$(STAGE3_TFLAGS)"; \
 	$(HOST_EXPORTS) \
-	$(POSTSTAGE1_HOST_EXPORTS)  \
+	$(POSTSTAGE1_HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	cd $(HOST_SUBDIR)/gettext && \
 	 \
 	$(MAKE) $(BASE_FLAGS_TO_PASS) \
@@ -20347,7 +20347,7 @@ all-stage4-gettext: configure-stage4-gettext
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	TFLAGS="$(STAGE4_TFLAGS)"; \
 	$(HOST_EXPORTS) \
-	$(POSTSTAGE1_HOST_EXPORTS)  \
+	$(POSTSTAGE1_HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	cd $(HOST_SUBDIR)/gettext && \
 	 \
 	$(MAKE) $(BASE_FLAGS_TO_PASS) \
@@ -20390,7 +20390,7 @@ all-stageprofile-gettext: configure-stageprofile-gettext
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	TFLAGS="$(STAGEprofile_TFLAGS)"; \
 	$(HOST_EXPORTS) \
-	$(POSTSTAGE1_HOST_EXPORTS)  \
+	$(POSTSTAGE1_HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	cd $(HOST_SUBDIR)/gettext && \
 	 \
 	$(MAKE) $(BASE_FLAGS_TO_PASS) \
@@ -20433,7 +20433,7 @@ all-stagetrain-gettext: configure-stagetrain-gettext
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	TFLAGS="$(STAGEtrain_TFLAGS)"; \
 	$(HOST_EXPORTS) \
-	$(POSTSTAGE1_HOST_EXPORTS)  \
+	$(POSTSTAGE1_HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	cd $(HOST_SUBDIR)/gettext && \
 	 \
 	$(MAKE) $(BASE_FLAGS_TO_PASS) \
@@ -20476,7 +20476,7 @@ all-stagefeedback-gettext: configure-stagefeedback-gettext
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	TFLAGS="$(STAGEfeedback_TFLAGS)"; \
 	$(HOST_EXPORTS) \
-	$(POSTSTAGE1_HOST_EXPORTS)  \
+	$(POSTSTAGE1_HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	cd $(HOST_SUBDIR)/gettext && \
 	 \
 	$(MAKE) $(BASE_FLAGS_TO_PASS) \
@@ -20519,7 +20519,7 @@ all-stageautoprofile-gettext: configure-stageautoprofile-gettext
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	TFLAGS="$(STAGEautoprofile_TFLAGS)"; \
 	$(HOST_EXPORTS) \
-	$(POSTSTAGE1_HOST_EXPORTS)  \
+	$(POSTSTAGE1_HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	cd $(HOST_SUBDIR)/gettext && \
 	$$s/gcc/config/i386/$(AUTO_PROFILE) \
 	$(MAKE) $(BASE_FLAGS_TO_PASS) \
@@ -20562,7 +20562,7 @@ all-stageautofeedback-gettext: configure-stageautofeedback-gettext
 	s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 	TFLAGS="$(STAGEautofeedback_TFLAGS)"; \
 	$(HOST_EXPORTS) \
-	$(POSTSTAGE1_HOST_EXPORTS)  \
+	$(POSTSTAGE1_HOST_EXPORTS) LDFLAGS="@LTLIBICONV_SIBLING@ $$LDFLAGS"; export LDFLAGS; \
 	cd $(HOST_SUBDIR)/gettext && \
 	 \
 	$(MAKE) $(BASE_FLAGS_TO_PASS) \
diff --git a/config/iconv.m4 b/config/iconv.m4
index ff5d52611397..cb07797ff218 100644
--- a/config/iconv.m4
+++ b/config/iconv.m4
@@ -6,6 +6,7 @@ dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
 dnl From Bruno Haible.
+dnl with modifications to support building with in-tree libiconv
 
 AC_PREREQ([2.64])
 
@@ -34,16 +35,15 @@ AC_DEFUN([AM_ICONV_LINK],
   dnl accordingly.
   AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
 
-  dnl Add $INCICONV to CPPFLAGS before performing the following checks,
-  dnl because if the user has installed libiconv and not disabled its use
-  dnl via --without-libiconv-prefix, he wants to use it. The first
-  dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed.
-  am_save_CPPFLAGS="$CPPFLAGS"
-  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
-
   AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
     am_cv_func_iconv="no, consider installing GNU libiconv"
     am_cv_lib_iconv=no
+    dnl Add $INCICONV to CPPFLAGS before performing the following checks,
+    dnl because if the user has installed libiconv and not disabled its use
+    dnl via --without-libiconv-prefix, he wants to use it. The first
+    dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed.
+    am_save_CPPFLAGS="$CPPFLAGS"
+    AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
     AC_LINK_IFELSE(
       [AC_LANG_PROGRAM(
          [[
@@ -54,8 +54,39 @@ AC_DEFUN([AM_ICONV_LINK],
            iconv(cd,NULL,NULL,NULL,NULL);
            iconv_close(cd);]])],
       [am_cv_func_iconv=yes])
+    CPPFLAGS="$am_save_CPPFLAGS"
+
+    if test "$am_cv_func_iconv" != yes && test -d ../libiconv; then
+      for _libs in .libs _libs; do
+        am_save_CPPFLAGS="$CPPFLAGS"
+        am_save_LIBS="$LIBS"
+        CPPFLAGS="$CPPFLAGS -I../libiconv/include"
+        LIBS="$LIBS ../libiconv/lib/$_libs/libiconv.a"
+        AC_TRY_LINK([#include <stdlib.h>
+#include <iconv.h>],
+          [iconv_t cd = iconv_open("","");
+           iconv(cd,NULL,NULL,NULL,NULL);
+           iconv_close(cd);],
+          INCICONV="-I../libiconv/include"
+          LIBICONV='${top_builddir}'/../libiconv/lib/"$_libs"/libiconv.a
+          LTLIBICONV='${top_builddir}'/../libiconv/lib/libiconv.la
+          am_cv_lib_iconv=yes
+          # The setup above only works if expanded at make time, so we need to
+          # suppress various configure-time tests.
+          am_cv_func_iconv_works=yes
+          am_cv_func_iconv=yes)
+        CPPFLAGS="$am_save_CPPFLAGS"
+        LIBS="$am_save_LIBS"
+        if test "$am_cv_func_iconv" = "yes"; then
+          break
+        fi
+      done
+    fi
+
     if test "$am_cv_func_iconv" != yes; then
+      am_save_CPPFLAGS="$CPPFLAGS"
       am_save_LIBS="$LIBS"
+      CPPFLAGS="$CPPFLAGS $INCICONV"
       LIBS="$LIBS $LIBICONV"
       AC_LINK_IFELSE(
         [AC_LANG_PROGRAM(
@@ -68,6 +99,7 @@ AC_DEFUN([AM_ICONV_LINK],
              iconv_close(cd);]])],
         [am_cv_lib_iconv=yes]
         [am_cv_func_iconv=yes])
+      CPPFLAGS="$am_save_CPPFLAGS"
       LIBS="$am_save_LIBS"
     fi
   ])
@@ -219,12 +251,10 @@ AC_DEFUN([AM_ICONV_LINK],
       [Define if you have the iconv() function and it works.])
   fi
   if test "$am_cv_lib_iconv" = yes; then
+    AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
     AC_MSG_CHECKING([how to link with libiconv])
     AC_MSG_RESULT([$LIBICONV])
   else
-    dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
-    dnl either.
-    CPPFLAGS="$am_save_CPPFLAGS"
     LIBICONV=
     LTLIBICONV=
   fi
diff --git a/configure b/configure
index 02b435c1163b..39771554ee27 100755
--- a/configure
+++ b/configure
@@ -679,6 +679,10 @@ RPATH_ENVVAR
 target_configargs
 host_configargs
 build_configargs
+LIBICONV_CVS
+LTLIBICONV_SIBLING
+LIBICONV_SIBLING
+LIBICONV_EXTRA_CPPFLAGS
 BUILD_CONFIG
 LDFLAGS_FOR_TARGET
 CXXFLAGS_FOR_TARGET
@@ -9978,6 +9982,27 @@ case " ${configdirs} " in
     ;;
 esac
 
+# Check whether we should inject an in-tree libiconv into our subconfigures.
+LIBICONV_EXTRA_CPPFLAGS=
+LIBICONV_SIBLING=
+LTLIBICONV_SIBLING=
+LIBICONV_CVS=
+case " ${configdirs} " in
+  *\ libiconv\ *)
+  # For out-of-tree dependencies that might use libiconv (e.g. gettext).
+  # https://lists.gnu.org/archive/html/bug-gettext/2023-11/msg00056.html
+  LIBICONV_EXTRA_CPPFLAGS="-I`${PWDCMD-pwd}`/\$(HOST_SUBDIR)/libiconv/include"
+  LIBICONV_SIBLING="`${PWDCMD-pwd}`/\$(HOST_SUBDIR)/libiconv/lib/.libs/libiconv.a"
+  LTLIBICONV_SIBLING="`${PWDCMD-pwd}`/\$(HOST_SUBDIR)/libiconv/lib/.libs/libiconv.la"
+  # Cache vars used for tricking iconv.m4.
+  LIBICONV_CVS="am_cv_func_iconv=yes am_cv_lib_iconv=no am_cv_func_iconv_works=yes"
+  ;;
+esac
+
+
+
+
+
 # Strip out unwanted targets.
 
 # While at that, we remove Makefiles if we were started for recursive
diff --git a/configure.ac b/configure.ac
index 1a19c07a27b8..991aa8eb441c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3097,6 +3097,27 @@ case " ${configdirs} " in
     ;;
 esac
 
+# Check whether we should inject an in-tree libiconv into our subconfigures.
+LIBICONV_EXTRA_CPPFLAGS=
+LIBICONV_SIBLING=
+LTLIBICONV_SIBLING=
+LIBICONV_CVS=
+case " ${configdirs} " in
+  *\ libiconv\ *)
+  # For out-of-tree dependencies that might use libiconv (e.g. gettext).
+  # https://lists.gnu.org/archive/html/bug-gettext/2023-11/msg00056.html
+  LIBICONV_EXTRA_CPPFLAGS="-I`${PWDCMD-pwd}`/\$(HOST_SUBDIR)/libiconv/include"
+  LIBICONV_SIBLING="`${PWDCMD-pwd}`/\$(HOST_SUBDIR)/libiconv/lib/.libs/libiconv.a"
+  LTLIBICONV_SIBLING="`${PWDCMD-pwd}`/\$(HOST_SUBDIR)/libiconv/lib/.libs/libiconv.la"
+  # Cache vars used for tricking iconv.m4.
+  LIBICONV_CVS="am_cv_func_iconv=yes am_cv_lib_iconv=no am_cv_func_iconv_works=yes"
+  ;;
+esac
+AC_SUBST([LIBICONV_EXTRA_CPPFLAGS])
+AC_SUBST([LIBICONV_SIBLING])
+AC_SUBST([LTLIBICONV_SIBLING])
+AC_SUBST([LIBICONV_CVS])
+
 # Strip out unwanted targets.
 
 # While at that, we remove Makefiles if we were started for recursive
diff --git a/gcc/configure b/gcc/configure
index 266ab8f84b2a..40fadb13737e 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -11792,31 +11792,6 @@ fi
 
 
 
-          am_save_CPPFLAGS="$CPPFLAGS"
-
-  for element in $INCICONV; do
-    haveit=
-    for x in $CPPFLAGS; do
-
-  acl_save_prefix="$prefix"
-  prefix="$acl_final_prefix"
-  acl_save_exec_prefix="$exec_prefix"
-  exec_prefix="$acl_final_exec_prefix"
-  eval x=\"$x\"
-  exec_prefix="$acl_save_exec_prefix"
-  prefix="$acl_save_prefix"
-
-      if test "X$x" = "X$element"; then
-        haveit=yes
-        break
-      fi
-    done
-    if test -z "$haveit"; then
-      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
-    fi
-  done
-
-
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5
 $as_echo_n "checking for iconv... " >&6; }
 if ${am_cv_func_iconv+:} false; then :
@@ -11825,6 +11800,30 @@ else
 
     am_cv_func_iconv="no, consider installing GNU libiconv"
     am_cv_lib_iconv=no
+                    am_save_CPPFLAGS="$CPPFLAGS"
+
+  for element in $INCICONV; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -11846,8 +11845,52 @@ if ac_fn_cxx_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+    CPPFLAGS="$am_save_CPPFLAGS"
+
+    if test "$am_cv_func_iconv" != yes && test -d ../libiconv; then
+      for _libs in .libs _libs; do
+        am_save_CPPFLAGS="$CPPFLAGS"
+        am_save_LIBS="$LIBS"
+        CPPFLAGS="$CPPFLAGS -I../libiconv/include"
+        LIBS="$LIBS ../libiconv/lib/$_libs/libiconv.a"
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <iconv.h>
+int
+main ()
+{
+iconv_t cd = iconv_open("","");
+           iconv(cd,NULL,NULL,NULL,NULL);
+           iconv_close(cd);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  INCICONV="-I../libiconv/include"
+          LIBICONV='${top_builddir}'/../libiconv/lib/"$_libs"/libiconv.a
+          LTLIBICONV='${top_builddir}'/../libiconv/lib/libiconv.la
+          am_cv_lib_iconv=yes
+          # The setup above only works if expanded at make time, so we need to
+          # suppress various configure-time tests.
+          am_cv_func_iconv_works=yes
+          am_cv_func_iconv=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+        CPPFLAGS="$am_save_CPPFLAGS"
+        LIBS="$am_save_LIBS"
+        if test "$am_cv_func_iconv" = "yes"; then
+          break
+        fi
+      done
+    fi
+
     if test "$am_cv_func_iconv" != yes; then
+      am_save_CPPFLAGS="$CPPFLAGS"
       am_save_LIBS="$LIBS"
+      CPPFLAGS="$CPPFLAGS $INCICONV"
       LIBS="$LIBS $LIBICONV"
       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -11871,6 +11914,7 @@ if ac_fn_cxx_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+      CPPFLAGS="$am_save_CPPFLAGS"
       LIBS="$am_save_LIBS"
     fi
 
@@ -12047,12 +12091,34 @@ $as_echo "#define HAVE_ICONV 1" >>confdefs.h
 
   fi
   if test "$am_cv_lib_iconv" = yes; then
+
+  for element in $INCICONV; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5
 $as_echo_n "checking how to link with libiconv... " >&6; }
     { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5
 $as_echo "$LIBICONV" >&6; }
   else
-            CPPFLAGS="$am_save_CPPFLAGS"
     LIBICONV=
     LTLIBICONV=
   fi
@@ -14013,31 +14079,6 @@ $as_echo "$ac_res" >&6; }
 
 
 
-          am_save_CPPFLAGS="$CPPFLAGS"
-
-  for element in $INCICONV; do
-    haveit=
-    for x in $CPPFLAGS; do
-
-  acl_save_prefix="$prefix"
-  prefix="$acl_final_prefix"
-  acl_save_exec_prefix="$exec_prefix"
-  exec_prefix="$acl_final_exec_prefix"
-  eval x=\"$x\"
-  exec_prefix="$acl_save_exec_prefix"
-  prefix="$acl_save_prefix"
-
-      if test "X$x" = "X$element"; then
-        haveit=yes
-        break
-      fi
-    done
-    if test -z "$haveit"; then
-      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
-    fi
-  done
-
-
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5
 $as_echo_n "checking for iconv... " >&6; }
 if ${am_cv_func_iconv+:} false; then :
@@ -14046,6 +14087,30 @@ else
 
     am_cv_func_iconv="no, consider installing GNU libiconv"
     am_cv_lib_iconv=no
+                    am_save_CPPFLAGS="$CPPFLAGS"
+
+  for element in $INCICONV; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -14067,8 +14132,52 @@ if ac_fn_cxx_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+    CPPFLAGS="$am_save_CPPFLAGS"
+
+    if test "$am_cv_func_iconv" != yes && test -d ../libiconv; then
+      for _libs in .libs _libs; do
+        am_save_CPPFLAGS="$CPPFLAGS"
+        am_save_LIBS="$LIBS"
+        CPPFLAGS="$CPPFLAGS -I../libiconv/include"
+        LIBS="$LIBS ../libiconv/lib/$_libs/libiconv.a"
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <iconv.h>
+int
+main ()
+{
+iconv_t cd = iconv_open("","");
+           iconv(cd,NULL,NULL,NULL,NULL);
+           iconv_close(cd);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  INCICONV="-I../libiconv/include"
+          LIBICONV='${top_builddir}'/../libiconv/lib/"$_libs"/libiconv.a
+          LTLIBICONV='${top_builddir}'/../libiconv/lib/libiconv.la
+          am_cv_lib_iconv=yes
+          # The setup above only works if expanded at make time, so we need to
+          # suppress various configure-time tests.
+          am_cv_func_iconv_works=yes
+          am_cv_func_iconv=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+        CPPFLAGS="$am_save_CPPFLAGS"
+        LIBS="$am_save_LIBS"
+        if test "$am_cv_func_iconv" = "yes"; then
+          break
+        fi
+      done
+    fi
+
     if test "$am_cv_func_iconv" != yes; then
+      am_save_CPPFLAGS="$CPPFLAGS"
       am_save_LIBS="$LIBS"
+      CPPFLAGS="$CPPFLAGS $INCICONV"
       LIBS="$LIBS $LIBICONV"
       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -14092,6 +14201,7 @@ if ac_fn_cxx_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+      CPPFLAGS="$am_save_CPPFLAGS"
       LIBS="$am_save_LIBS"
     fi
 
@@ -14268,12 +14378,34 @@ $as_echo "#define HAVE_ICONV 1" >>confdefs.h
 
   fi
   if test "$am_cv_lib_iconv" = yes; then
+
+  for element in $INCICONV; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5
 $as_echo_n "checking how to link with libiconv... " >&6; }
     { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5
 $as_echo "$LIBICONV" >&6; }
   else
-            CPPFLAGS="$am_save_CPPFLAGS"
     LIBICONV=
     LTLIBICONV=
   fi
@@ -21569,7 +21701,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 21572 "configure"
+#line 21704 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -21675,7 +21807,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 21678 "configure"
+#line 21810 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/libcpp/configure b/libcpp/configure
index 8a38c0546e3e..e704853b768a 100755
--- a/libcpp/configure
+++ b/libcpp/configure
@@ -7654,31 +7654,6 @@ $as_echo "$ac_res" >&6; }
 
 
 
-          am_save_CPPFLAGS="$CPPFLAGS"
-
-  for element in $INCICONV; do
-    haveit=
-    for x in $CPPFLAGS; do
-
-  acl_save_prefix="$prefix"
-  prefix="$acl_final_prefix"
-  acl_save_exec_prefix="$exec_prefix"
-  exec_prefix="$acl_final_exec_prefix"
-  eval x=\"$x\"
-  exec_prefix="$acl_save_exec_prefix"
-  prefix="$acl_save_prefix"
-
-      if test "X$x" = "X$element"; then
-        haveit=yes
-        break
-      fi
-    done
-    if test -z "$haveit"; then
-      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
-    fi
-  done
-
-
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5
 $as_echo_n "checking for iconv... " >&6; }
 if ${am_cv_func_iconv+:} false; then :
@@ -7687,6 +7662,30 @@ else
 
     am_cv_func_iconv="no, consider installing GNU libiconv"
     am_cv_lib_iconv=no
+                    am_save_CPPFLAGS="$CPPFLAGS"
+
+  for element in $INCICONV; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -7708,8 +7707,52 @@ if ac_fn_c_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+    CPPFLAGS="$am_save_CPPFLAGS"
+
+    if test "$am_cv_func_iconv" != yes && test -d ../libiconv; then
+      for _libs in .libs _libs; do
+        am_save_CPPFLAGS="$CPPFLAGS"
+        am_save_LIBS="$LIBS"
+        CPPFLAGS="$CPPFLAGS -I../libiconv/include"
+        LIBS="$LIBS ../libiconv/lib/$_libs/libiconv.a"
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <iconv.h>
+int
+main ()
+{
+iconv_t cd = iconv_open("","");
+           iconv(cd,NULL,NULL,NULL,NULL);
+           iconv_close(cd);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  INCICONV="-I../libiconv/include"
+          LIBICONV='${top_builddir}'/../libiconv/lib/"$_libs"/libiconv.a
+          LTLIBICONV='${top_builddir}'/../libiconv/lib/libiconv.la
+          am_cv_lib_iconv=yes
+          # The setup above only works if expanded at make time, so we need to
+          # suppress various configure-time tests.
+          am_cv_func_iconv_works=yes
+          am_cv_func_iconv=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+        CPPFLAGS="$am_save_CPPFLAGS"
+        LIBS="$am_save_LIBS"
+        if test "$am_cv_func_iconv" = "yes"; then
+          break
+        fi
+      done
+    fi
+
     if test "$am_cv_func_iconv" != yes; then
+      am_save_CPPFLAGS="$CPPFLAGS"
       am_save_LIBS="$LIBS"
+      CPPFLAGS="$CPPFLAGS $INCICONV"
       LIBS="$LIBS $LIBICONV"
       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -7733,6 +7776,7 @@ if ac_fn_c_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+      CPPFLAGS="$am_save_CPPFLAGS"
       LIBS="$am_save_LIBS"
     fi
 
@@ -7909,12 +7953,34 @@ $as_echo "#define HAVE_ICONV 1" >>confdefs.h
 
   fi
   if test "$am_cv_lib_iconv" = yes; then
+
+  for element in $INCICONV; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5
 $as_echo_n "checking how to link with libiconv... " >&6; }
     { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5
 $as_echo "$LIBICONV" >&6; }
   else
-            CPPFLAGS="$am_save_CPPFLAGS"
     LIBICONV=
     LTLIBICONV=
   fi
@@ -8694,7 +8760,15 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
 
 
-          am_save_CPPFLAGS="$CPPFLAGS"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5
+$as_echo_n "checking for iconv... " >&6; }
+if ${am_cv_func_iconv+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+    am_cv_func_iconv="no, consider installing GNU libiconv"
+    am_cv_lib_iconv=no
+                    am_save_CPPFLAGS="$CPPFLAGS"
 
   for element in $INCICONV; do
     haveit=
@@ -8718,15 +8792,6 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
     fi
   done
 
-
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5
-$as_echo_n "checking for iconv... " >&6; }
-if ${am_cv_func_iconv+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-
-    am_cv_func_iconv="no, consider installing GNU libiconv"
-    am_cv_lib_iconv=no
     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -8748,8 +8813,52 @@ if ac_fn_cxx_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+    CPPFLAGS="$am_save_CPPFLAGS"
+
+    if test "$am_cv_func_iconv" != yes && test -d ../libiconv; then
+      for _libs in .libs _libs; do
+        am_save_CPPFLAGS="$CPPFLAGS"
+        am_save_LIBS="$LIBS"
+        CPPFLAGS="$CPPFLAGS -I../libiconv/include"
+        LIBS="$LIBS ../libiconv/lib/$_libs/libiconv.a"
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <iconv.h>
+int
+main ()
+{
+iconv_t cd = iconv_open("","");
+           iconv(cd,NULL,NULL,NULL,NULL);
+           iconv_close(cd);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  INCICONV="-I../libiconv/include"
+          LIBICONV='${top_builddir}'/../libiconv/lib/"$_libs"/libiconv.a
+          LTLIBICONV='${top_builddir}'/../libiconv/lib/libiconv.la
+          am_cv_lib_iconv=yes
+          # The setup above only works if expanded at make time, so we need to
+          # suppress various configure-time tests.
+          am_cv_func_iconv_works=yes
+          am_cv_func_iconv=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+        CPPFLAGS="$am_save_CPPFLAGS"
+        LIBS="$am_save_LIBS"
+        if test "$am_cv_func_iconv" = "yes"; then
+          break
+        fi
+      done
+    fi
+
     if test "$am_cv_func_iconv" != yes; then
+      am_save_CPPFLAGS="$CPPFLAGS"
       am_save_LIBS="$LIBS"
+      CPPFLAGS="$CPPFLAGS $INCICONV"
       LIBS="$LIBS $LIBICONV"
       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -8773,6 +8882,7 @@ if ac_fn_cxx_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+      CPPFLAGS="$am_save_CPPFLAGS"
       LIBS="$am_save_LIBS"
     fi
 
@@ -8949,12 +9059,34 @@ $as_echo "#define HAVE_ICONV 1" >>confdefs.h
 
   fi
   if test "$am_cv_lib_iconv" = yes; then
+
+  for element in $INCICONV; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5
 $as_echo_n "checking how to link with libiconv... " >&6; }
     { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5
 $as_echo "$LIBICONV" >&6; }
   else
-            CPPFLAGS="$am_save_CPPFLAGS"
     LIBICONV=
     LTLIBICONV=
   fi
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 21abaeb07788..0d72b95c0ab2 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -26968,31 +26968,6 @@ fi
 
 
 
-          am_save_CPPFLAGS="$CPPFLAGS"
-
-  for element in $INCICONV; do
-    haveit=
-    for x in $CPPFLAGS; do
-
-  acl_save_prefix="$prefix"
-  prefix="$acl_final_prefix"
-  acl_save_exec_prefix="$exec_prefix"
-  exec_prefix="$acl_final_exec_prefix"
-  eval x=\"$x\"
-  exec_prefix="$acl_save_exec_prefix"
-  prefix="$acl_save_prefix"
-
-      if test "X$x" = "X$element"; then
-        haveit=yes
-        break
-      fi
-    done
-    if test -z "$haveit"; then
-      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
-    fi
-  done
-
-
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5
 $as_echo_n "checking for iconv... " >&6; }
 if ${am_cv_func_iconv+:} false; then :
@@ -27001,6 +26976,30 @@ else
 
     am_cv_func_iconv="no, consider installing GNU libiconv"
     am_cv_lib_iconv=no
+                    am_save_CPPFLAGS="$CPPFLAGS"
+
+  for element in $INCICONV; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
     if test x$gcc_no_link = xyes; then
   as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
 fi
@@ -27025,8 +27024,55 @@ if ac_fn_c_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+    CPPFLAGS="$am_save_CPPFLAGS"
+
+    if test "$am_cv_func_iconv" != yes && test -d ../libiconv; then
+      for _libs in .libs _libs; do
+        am_save_CPPFLAGS="$CPPFLAGS"
+        am_save_LIBS="$LIBS"
+        CPPFLAGS="$CPPFLAGS -I../libiconv/include"
+        LIBS="$LIBS ../libiconv/lib/$_libs/libiconv.a"
+        if test x$gcc_no_link = xyes; then
+  as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
+fi
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <iconv.h>
+int
+main ()
+{
+iconv_t cd = iconv_open("","");
+           iconv(cd,NULL,NULL,NULL,NULL);
+           iconv_close(cd);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  INCICONV="-I../libiconv/include"
+          LIBICONV='${top_builddir}'/../libiconv/lib/"$_libs"/libiconv.a
+          LTLIBICONV='${top_builddir}'/../libiconv/lib/libiconv.la
+          am_cv_lib_iconv=yes
+          # The setup above only works if expanded at make time, so we need to
+          # suppress various configure-time tests.
+          am_cv_func_iconv_works=yes
+          am_cv_func_iconv=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+        CPPFLAGS="$am_save_CPPFLAGS"
+        LIBS="$am_save_LIBS"
+        if test "$am_cv_func_iconv" = "yes"; then
+          break
+        fi
+      done
+    fi
+
     if test "$am_cv_func_iconv" != yes; then
+      am_save_CPPFLAGS="$CPPFLAGS"
       am_save_LIBS="$LIBS"
+      CPPFLAGS="$CPPFLAGS $INCICONV"
       LIBS="$LIBS $LIBICONV"
       if test x$gcc_no_link = xyes; then
   as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
@@ -27053,6 +27099,7 @@ if ac_fn_c_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+      CPPFLAGS="$am_save_CPPFLAGS"
       LIBS="$am_save_LIBS"
     fi
 
@@ -27229,12 +27276,34 @@ $as_echo "#define HAVE_ICONV 1" >>confdefs.h
 
   fi
   if test "$am_cv_lib_iconv" = yes; then
+
+  for element in $INCICONV; do
+    haveit=
+    for x in $CPPFLAGS; do
+
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  eval x=\"$x\"
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
+    fi
+  done
+
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5
 $as_echo_n "checking how to link with libiconv... " >&6; }
     { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5
 $as_echo "$LIBICONV" >&6; }
   else
-            CPPFLAGS="$am_save_CPPFLAGS"
     LIBICONV=
     LTLIBICONV=
   fi
-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] Recover in-tree libiconv build support
  2024-04-13 21:58 [PATCH 0/3] Recover in-tree libiconv build support Arsen Arsenović
                   ` (2 preceding siblings ...)
  2024-04-13 21:58 ` [PATCH 3/3] *: support in-tree libiconv again Arsen Arsenović
@ 2024-04-18 16:41 ` Kévin Le Gouguec
  2024-05-04 18:48 ` Ping: " Arsen Arsenović
  4 siblings, 0 replies; 8+ messages in thread
From: Kévin Le Gouguec @ 2024-04-18 16:41 UTC (permalink / raw)
  To: Arsen Arsenović; +Cc: gcc-patches

Arsen Arsenović <arsen@aarsen.me> writes:

> Evening!
>
> This patchset recovers support for building the toolchain tree with
> in-tree libiconv being used for host modules and gettext.  As spotted by
> Kévin Le Gouguec <legouguec@adacore.com>, I accidentally removed this
> functionality earlier.
>
> This patchset includes the patch sent as:
>
> https://inbox.sourceware.gcc-patches/20231221193243.368541-1-arsen@aarsen.me/
>
> ... and so, supersedes that patchset.
>
> For the in-tree case, the old patch functionality was restored and
> rebased on top of current iconv.m4.  Of course, this does not work for
> gettext, an out-of-tree lib depending on the in-tree libiconv, so, for
> that case, we needed to provide the right information to configure, and
> suppress logic in iconv.m4 using cache vars.
>
> Build-tested on arm64-apple-darwin21.6.0, and I intend to do further
> testing tomorrow.
>
> OK for trunk?  It would be good to get these patches into GCC 14.
>
> I apologize for being quite late with delivering these, I have,
> unfortunately, been busied by various external factors.  Hopefully, it
> is not too late yet.

FWIW, I apologize too for not taking a stab at the fix; on our end, we
pondered this briefly and figured we had no compelling reason to
continue relying on in-tree libiconv builds, so we tweaked our packaging
recipes to configure --with-libiconv-prefix and that was that.

Thanks for finding the time to work on this!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Ping: [PATCH 0/3] Recover in-tree libiconv build support
  2024-04-13 21:58 [PATCH 0/3] Recover in-tree libiconv build support Arsen Arsenović
                   ` (3 preceding siblings ...)
  2024-04-18 16:41 ` [PATCH 0/3] Recover in-tree libiconv build support Kévin Le Gouguec
@ 2024-05-04 18:48 ` Arsen Arsenović
  2024-06-15 12:50   ` Ping^2: " Arsen Arsenović
  4 siblings, 1 reply; 8+ messages in thread
From: Arsen Arsenović @ 2024-05-04 18:48 UTC (permalink / raw)
  To: gcc-patches; +Cc: Kévin Le Gouguec

[-- Attachment #1: Type: text/plain, Size: 212 bytes --]

Hi!

Given that trunk is now GCC 15, it might be good to land this patch
early.  I will re-test it just in case after a rebase but, otherwise, OK
for trunk?

TIA, have a lovely day.
-- 
Arsen Arsenović

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Ping^2: [PATCH 0/3] Recover in-tree libiconv build support
  2024-05-04 18:48 ` Ping: " Arsen Arsenović
@ 2024-06-15 12:50   ` Arsen Arsenović
  2024-07-08  0:30     ` Ping^3: " Arsen Arsenović
  0 siblings, 1 reply; 8+ messages in thread
From: Arsen Arsenović @ 2024-06-15 12:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: Kévin Le Gouguec

[-- Attachment #1: Type: text/plain, Size: 133 bytes --]

Hi!

Another gentle ping on this patch series.  Could it be merged into
trunk?

TIA, have a lovely day!
-- 
Arsen Arsenović

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 381 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Ping^3: [PATCH 0/3] Recover in-tree libiconv build support
  2024-06-15 12:50   ` Ping^2: " Arsen Arsenović
@ 2024-07-08  0:30     ` Arsen Arsenović
  0 siblings, 0 replies; 8+ messages in thread
From: Arsen Arsenović @ 2024-07-08  0:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: Kévin Le Gouguec

[-- Attachment #1: Type: text/plain, Size: 234 bytes --]

Arsen Arsenović <arsen@aarsen.me> writes:

> Another gentle ping on this patch series.  Could it be merged into
> trunk?

And another!  Sorry about them being sparse - I was quite busy in the
meanwhile.
-- 
Arsen Arsenović

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 381 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-07-08  0:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-13 21:58 [PATCH 0/3] Recover in-tree libiconv build support Arsen Arsenović
2024-04-13 21:58 ` [PATCH 1/3] toplevel: don't override gettext-runtime/configure-discovered build args Arsen Arsenović
2024-04-13 21:58 ` [PATCH 2/3] gitignore: ignore /libiconv* Arsen Arsenović
2024-04-13 21:58 ` [PATCH 3/3] *: support in-tree libiconv again Arsen Arsenović
2024-04-18 16:41 ` [PATCH 0/3] Recover in-tree libiconv build support Kévin Le Gouguec
2024-05-04 18:48 ` Ping: " Arsen Arsenović
2024-06-15 12:50   ` Ping^2: " Arsen Arsenović
2024-07-08  0:30     ` Ping^3: " Arsen Arsenović

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).