[1/3] gnulib: support building for --build [PR sim/30882]

Message ID 20231015171728.30138-1-vapier@gentoo.org
State New
Headers
Series [1/3] gnulib: support building for --build [PR sim/30882] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Testing failed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Testing failed

Commit Message

Mike Frysinger Oct. 15, 2023, 5:17 p.m. UTC
  The sim tree has some build-time programs for generating source files
that are a bit complicated and expect a POSIX-compatible system.  But
some targets (e.g. mingw) might not provide up-to-date support.  Since
we already have gnulib in the tree, leverage that to also build for
the --build system.

The top-level configure logic will pass down --with-build-subdir when
the subdir is built for it.  Use that to adjust the output variable
names and paths.  This allows us to include the gnulib makefile frags
for both --host and --build simultaneously.
---
 gnulib/Makefile.gnulib.inc.in | 18 ++++++++-----
 gnulib/Makefile.in            |  2 ++
 gnulib/configure              | 50 ++++++++++++++++++++++++++---------
 gnulib/configure.ac           | 12 +++++++++
 gnulib/import/Makefile.in     |  2 ++
 5 files changed, 65 insertions(+), 19 deletions(-)
  

Patch

diff --git a/gnulib/Makefile.gnulib.inc.in b/gnulib/Makefile.gnulib.inc.in
index 777a99c58d17..755516632f75 100644
--- a/gnulib/Makefile.gnulib.inc.in
+++ b/gnulib/Makefile.gnulib.inc.in
@@ -31,16 +31,20 @@ 
 #
 # INCGNU: A list of -I.... include paths that should be passed to the
 #        compiler, these are where the gnulib headers can be found.
+#
+# When building for --build, the variables will be prefixed with BUILD_.
 
 # Packages must define the relative path to gnulib's parent dir.
 ifndef GNULIB_PARENT_DIR
 $(error missing GNULIB_PARENT_DIR)
 endif
 
-LIBGNU = $(GNULIB_PARENT_DIR)/gnulib/import/libgnu.a
-LIBGNU_EXTRA_LIBS = @FREXPL_LIBM@ @FREXP_LIBM@ @INET_NTOP_LIB@ \
-                    @LIBTHREAD@ @LIB_GETLOGIN@ @LIB_GETRANDOM@ \
-                    @LIB_HARD_LOCALE@ @LIB_MBRTOWC@ \
-                    @LIB_SETLOCALE_NULL@ @LIBINTL@ @LIB_SELECT@ @LIBSOCKET@
-INCGNU = -I$(srcdir)/$(GNULIB_PARENT_DIR)/gnulib/import \
-         -I$(GNULIB_PARENT_DIR)/gnulib/import
+@VAR_PREFIX@LIBGNU = $(GNULIB_PARENT_DIR)/@BUILD_SUBDIR@gnulib/import/libgnu.a
+@VAR_PREFIX@LIBGNU_EXTRA_LIBS = \
+	@FREXPL_LIBM@ @FREXP_LIBM@ @INET_NTOP_LIB@ \
+	@LIBTHREAD@ @LIB_GETLOGIN@ @LIB_GETRANDOM@ \
+	@LIB_HARD_LOCALE@ @LIB_MBRTOWC@ \
+	@LIB_SETLOCALE_NULL@ @LIBINTL@ @LIB_SELECT@ @LIBSOCKET@
+@VAR_PREFIX@INCGNU = \
+	-I$(srcdir)/$(GNULIB_PARENT_DIR)/gnulib/import \
+	-I$(GNULIB_PARENT_DIR)/@BUILD_SUBDIR@gnulib/import
diff --git a/gnulib/configure.ac b/gnulib/configure.ac
index 9f081614efd5..72a16d5ae6ea 100644
--- a/gnulib/configure.ac
+++ b/gnulib/configure.ac
@@ -56,6 +56,18 @@  AC_CHECK_TOOL(AR, ar)
 # Checks for libraries.  #
 # ---------------------- #
 
+AC_ARG_WITH(build-subdir,
+  [AS_HELP_STRING([--with-build-subdir=SUBDIR], [Configuring in a subdirectory for build])])
+
+VAR_PREFIX=
+BUILD_SUBDIR=
+AS_IF([test -n "${with_build_subdir}"], [dnl
+  VAR_PREFIX="BUILD_"
+  BUILD_SUBDIR="${with_build_subdir}/"
+])
+AC_SUBST(BUILD_SUBDIR)
+AC_SUBST(VAR_PREFIX)
+
 AC_CONFIG_FILES(Makefile.gnulib.inc)
 
 AC_OUTPUT(Makefile import/Makefile,