Michele Locati noticed that when building a package for mingw, on
Cygwin as host environment, the --enable-relocatable option does not
fully work: Binaries are installed where they should, but when moved
on the file system, they don't find their (relocated) files.

Two values were wrong:
  - the value of INSTALLPREFIX,
  - the value of INSTALLDIR.
Both need to be processed through gl_BUILD_TO_HOST.

These two patches do it, or document how to do it.


2024-09-25  Bruno Haible  <br...@clisp.org>

        relocatable-lib-lgpl: Add support for mingw builds on Cygwin hosts.
        Reported by Michele Locati <mich...@locati.it> in
        <https://lists.gnu.org/archive/html/bug-gettext/2024-09/msg00033.html>.
        * m4/relocatable-lib.m4 (gl_RELOCATABLE_LIBRARY_BODY): Use
        gl_BUILD_TO_HOST on the value of INSTALLPREFIX.
        * modules/relocatable-lib (Files): Add m4/build-to-host.m4.
        * modules/relocatable-lib-lgpl (Files): Likewise.
        * modules/relocatable-prog-wrapper (Files): Likewise.

2024-09-25  Bruno Haible  <br...@clisp.org>

        build-to-host.m4: Add some convenience macros.
        Reported by Michele Locati <mich...@locati.it> in
        <https://lists.gnu.org/archive/html/bug-gettext/2024-09/msg00033.html>.
        * m4/build-to-host.m4 (gl_BUILD_TO_HOST_BINDIR, gl_BUILD_TO_HOST_LIBDIR,
        gl_BUILD_TO_HOST_LIBEXECDIR, gl_BUILD_TO_HOST_LOCALEDIR,
        gl_BUILD_TO_HOST_PKGDATADIR, gl_BUILD_TO_HOST_PKGLIBDIR): New macros.
        * m4/gettext.m4 (AM_GNU_GETTEXT): Invoke gl_BUILD_TO_HOST_LOCALEDIR.
        * doc/relocatable-maint.texi (Supporting Relocation): Suggest to use the
        *dir_c_make variables and explain how to get them.

>From eb515396a8506286d5bfa05a9cca4044c1750ff5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 26 Sep 2024 01:33:45 +0200
Subject: [PATCH 1/2] build-to-host.m4: Add some convenience macros.

Reported by Michele Locati <mich...@locati.it> in
<https://lists.gnu.org/archive/html/bug-gettext/2024-09/msg00033.html>.

* m4/build-to-host.m4 (gl_BUILD_TO_HOST_BINDIR, gl_BUILD_TO_HOST_LIBDIR,
gl_BUILD_TO_HOST_LIBEXECDIR, gl_BUILD_TO_HOST_LOCALEDIR,
gl_BUILD_TO_HOST_PKGDATADIR, gl_BUILD_TO_HOST_PKGLIBDIR): New macros.
* m4/gettext.m4 (AM_GNU_GETTEXT): Invoke gl_BUILD_TO_HOST_LOCALEDIR.
* doc/relocatable-maint.texi (Supporting Relocation): Suggest to use the
*dir_c_make variables and explain how to get them.
---
 ChangeLog                  |  12 +++
 doc/relocatable-maint.texi |  31 +++++++-
 m4/build-to-host.m4        | 147 ++++++++++++++++++++++++++++++++++++-
 m4/gettext.m4              |  18 +----
 4 files changed, 188 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 61367d2e45..eb64686dbb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-09-25  Bruno Haible  <br...@clisp.org>
+
+	build-to-host.m4: Add some convenience macros.
+	Reported by Michele Locati <mich...@locati.it> in
+	<https://lists.gnu.org/archive/html/bug-gettext/2024-09/msg00033.html>.
+	* m4/build-to-host.m4 (gl_BUILD_TO_HOST_BINDIR, gl_BUILD_TO_HOST_LIBDIR,
+	gl_BUILD_TO_HOST_LIBEXECDIR, gl_BUILD_TO_HOST_LOCALEDIR,
+	gl_BUILD_TO_HOST_PKGDATADIR, gl_BUILD_TO_HOST_PKGLIBDIR): New macros.
+	* m4/gettext.m4 (AM_GNU_GETTEXT): Invoke gl_BUILD_TO_HOST_LOCALEDIR.
+	* doc/relocatable-maint.texi (Supporting Relocation): Suggest to use the
+	*dir_c_make variables and explain how to get them.
+
 2024-09-25  Bruno Haible  <br...@clisp.org>
 
 	xstring-buffer: New module.
diff --git a/doc/relocatable-maint.texi b/doc/relocatable-maint.texi
index d391598108..fe4f7812fd 100644
--- a/doc/relocatable-maint.texi
+++ b/doc/relocatable-maint.texi
@@ -200,12 +200,37 @@
 installed in, say, @file{$(bindir)}, you add:
 
 @example
-foo_CPPFLAGS = -DINSTALLDIR=\"$(bindir)\"
+foo_CPPFLAGS = -DINSTALLDIR=$(bindir_c_make)
 if RELOCATABLE_VIA_LD
 foo_LDFLAGS = `$(RELOCATABLE_LDFLAGS) $(bindir)`
 endif
 @end example
 
+Similarly, if a program @command{foo} gets installed in @file{$(pkglibdir)},
+you add:
+
+@example
+foo_CPPFLAGS = -DINSTALLDIR=$(pkglibdir_c_make)
+if RELOCATABLE_VIA_LD
+foo_LDFLAGS = `$(RELOCATABLE_LDFLAGS) $(pkglibdir)`
+endif
+@end example
+
+The Makefile variables @code{bindir_c_make} or @code{pkglibdir_c_make}
+get defined by the Autoconf macros
+@code{gl_BUILD_TO_HOST_BINDIR} or @code{gl_BUILD_TO_HOST_PKGLIBDIR},
+respectively.
+These Autoconf macros are defined in the file @code{m4/build-to-host.m4}.
+You need to
+@itemize @bullet
+@item
+Import this file @code{m4/build-to-host.m4} into your package, for example
+by using of a command like @samp{gnulib-tool --copy m4/build-to-host.m4}.
+@item
+Invoke the corresponding macro(s) from your package's @file{configure.ac}.
+@end itemize
+
+@item
 When building gnulib to use with a relocatable library, you need to
 define the preprocessor symbol @code{IN_LIBRARY}.
 You may also want to build with @code{ENABLE_COSTLY_RELOCATABLE}, in which case
@@ -217,9 +242,9 @@
 AM_CPPFLAGS += -DIN_LIBRARY -DENABLE_COSTLY_RELOCATABLE
 
 if SHLIBS_IN_BINDIR
-AM_CPPFLAGS += -DINSTALLDIR=\"$(bindir)\"
+AM_CPPFLAGS += -DINSTALLDIR=$(bindir_c_make)
 else
-AM_CPPFLAGS += -DINSTALLDIR=\"$(libdir)\"
+AM_CPPFLAGS += -DINSTALLDIR=$(libdir_c_make)
 endif
 @end example
 
diff --git a/m4/build-to-host.m4 b/m4/build-to-host.m4
index f466bdbd84..1e9a8161b5 100644
--- a/m4/build-to-host.m4
+++ b/m4/build-to-host.m4
@@ -1,5 +1,5 @@
 # build-to-host.m4
-# serial 3
+# serial 4
 dnl Copyright (C) 2023-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -78,3 +78,148 @@ AC_DEFUN([gl_BUILD_TO_HOST_INIT]
     *)  gl_tr_cr='\r' ;;
   esac
 ])
+
+
+dnl The following macros are convenience invocations of gl_BUILD_TO_HOST
+dnl for some of the variables that are defined by Autoconf.
+dnl To do so for _all_ the possible variables, use the module 'configmake'.
+
+dnl Defines bindir_c and bindir_c_make.
+AC_DEFUN_ONCE([gl_BUILD_TO_HOST_BINDIR],
+[
+  dnl Find the final value of bindir.
+  gl_saved_prefix="${prefix}"
+  gl_saved_exec_prefix="${exec_prefix}"
+  gl_saved_bindir="${bindir}"
+  dnl Unfortunately, prefix and exec_prefix get only finally determined
+  dnl at the end of configure.
+  if test "X$prefix" = "XNONE"; then
+    prefix="$ac_default_prefix"
+  fi
+  if test "X$exec_prefix" = "XNONE"; then
+    exec_prefix='${prefix}'
+  fi
+  eval exec_prefix="$exec_prefix"
+  eval bindir="$bindir"
+  gl_BUILD_TO_HOST([bindir])
+  bindir="${gl_saved_bindir}"
+  exec_prefix="${gl_saved_exec_prefix}"
+  prefix="${gl_saved_prefix}"
+])
+
+dnl Defines libdir_c and libdir_c_make.
+AC_DEFUN_ONCE([gl_BUILD_TO_HOST_LIBDIR],
+[
+  dnl Find the final value of libdir.
+  gl_saved_prefix="${prefix}"
+  gl_saved_exec_prefix="${exec_prefix}"
+  gl_saved_libdir="${libdir}"
+  dnl Unfortunately, prefix and exec_prefix get only finally determined
+  dnl at the end of configure.
+  if test "X$prefix" = "XNONE"; then
+    prefix="$ac_default_prefix"
+  fi
+  if test "X$exec_prefix" = "XNONE"; then
+    exec_prefix='${prefix}'
+  fi
+  eval exec_prefix="$exec_prefix"
+  eval libdir="$libdir"
+  gl_BUILD_TO_HOST([libdir])
+  libdir="${gl_saved_libdir}"
+  exec_prefix="${gl_saved_exec_prefix}"
+  prefix="${gl_saved_prefix}"
+])
+
+dnl Defines libexecdir_c and libexecdir_c_make.
+AC_DEFUN_ONCE([gl_BUILD_TO_HOST_LIBEXECDIR],
+[
+  dnl Find the final value of libexecdir.
+  gl_saved_prefix="${prefix}"
+  gl_saved_exec_prefix="${exec_prefix}"
+  gl_saved_libexecdir="${libexecdir}"
+  dnl Unfortunately, prefix and exec_prefix get only finally determined
+  dnl at the end of configure.
+  if test "X$prefix" = "XNONE"; then
+    prefix="$ac_default_prefix"
+  fi
+  if test "X$exec_prefix" = "XNONE"; then
+    exec_prefix='${prefix}'
+  fi
+  eval exec_prefix="$exec_prefix"
+  eval libexecdir="$libexecdir"
+  gl_BUILD_TO_HOST([libexecdir])
+  libexecdir="${gl_saved_libexecdir}"
+  exec_prefix="${gl_saved_exec_prefix}"
+  prefix="${gl_saved_prefix}"
+])
+
+dnl Defines localedir_c and localedir_c_make.
+AC_DEFUN_ONCE([gl_BUILD_TO_HOST_LOCALEDIR],
+[
+  dnl Find the final value of localedir.
+  gl_saved_prefix="${prefix}"
+  gl_saved_datarootdir="${datarootdir}"
+  gl_saved_localedir="${localedir}"
+  dnl Unfortunately, prefix gets only finally determined at the end of
+  dnl configure.
+  if test "X$prefix" = "XNONE"; then
+    prefix="$ac_default_prefix"
+  fi
+  eval datarootdir="$datarootdir"
+  eval localedir="$localedir"
+  gl_BUILD_TO_HOST([localedir])
+  localedir="${gl_saved_localedir}"
+  datarootdir="${gl_saved_datarootdir}"
+  prefix="${gl_saved_prefix}"
+])
+
+dnl Defines pkgdatadir_c and pkgdatadir_c_make,
+dnl where pkgdatadir = $(datadir)/$(PACKAGE)
+AC_DEFUN_ONCE([gl_BUILD_TO_HOST_PKGDATADIR],
+[
+  dnl Find the final value of pkgdatadir.
+  gl_saved_prefix="${prefix}"
+  gl_saved_datarootdir="${datarootdir}"
+  gl_saved_datadir="${datadir}"
+  gl_saved_pkgdatadir="${pkgdatadir}"
+  dnl Unfortunately, prefix gets only finally determined at the end of
+  dnl configure.
+  if test "X$prefix" = "XNONE"; then
+    prefix="$ac_default_prefix"
+  fi
+  eval datarootdir="$datarootdir"
+  eval datadir="$datadir"
+  eval pkgdatadir="$pkgdatadir"
+  gl_BUILD_TO_HOST([pkgdatadir])
+  pkgdatadir="${gl_saved_pkgdatadir}"
+  datadir="${gl_saved_datadir}"
+  datarootdir="${gl_saved_datarootdir}"
+  prefix="${gl_saved_prefix}"
+])
+
+dnl Defines pkglibdir_c and pkglibdir_c_make,
+dnl where pkglibdir = $(libdir)/$(PACKAGE)
+AC_DEFUN_ONCE([gl_BUILD_TO_HOST_PKGLIBDIR],
+[
+  dnl Find the final value of pkglibdir.
+  gl_saved_prefix="${prefix}"
+  gl_saved_exec_prefix="${exec_prefix}"
+  gl_saved_libdir="${libdir}"
+  gl_saved_pkglibdir="${pkglibdir}"
+  dnl Unfortunately, prefix and exec_prefix get only finally determined
+  dnl at the end of configure.
+  if test "X$prefix" = "XNONE"; then
+    prefix="$ac_default_prefix"
+  fi
+  if test "X$exec_prefix" = "XNONE"; then
+    exec_prefix='${prefix}'
+  fi
+  eval exec_prefix="$exec_prefix"
+  eval libdir="$libdir"
+  eval pkglibdir="$pkglibdir"
+  gl_BUILD_TO_HOST([pkglibdir])
+  pkglibdir="${gl_saved_pkglibdir}"
+  libdir="${gl_saved_libdir}"
+  exec_prefix="${gl_saved_exec_prefix}"
+  prefix="${gl_saved_prefix}"
+])
diff --git a/m4/gettext.m4 b/m4/gettext.m4
index 8cd3890b2c..c8580c95fa 100644
--- a/m4/gettext.m4
+++ b/m4/gettext.m4
@@ -1,5 +1,5 @@
 # gettext.m4
-# serial 79 (gettext-0.23)
+# serial 80 (gettext-0.23)
 dnl Copyright (C) 1995-2014, 2016, 2018-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -365,21 +365,7 @@ AC_DEFUN([AM_GNU_GETTEXT]
   AC_SUBST([POSUB])
 
   dnl Define localedir_c and localedir_c_make.
-  dnl Find the final value of localedir.
-  gt_saved_prefix="${prefix}"
-  gt_saved_datarootdir="${datarootdir}"
-  gt_saved_localedir="${localedir}"
-  dnl Unfortunately, prefix gets only finally determined at the end of
-  dnl configure.
-  if test "X$prefix" = "XNONE"; then
-    prefix="$ac_default_prefix"
-  fi
-  eval datarootdir="$datarootdir"
-  eval localedir="$localedir"
-  gl_BUILD_TO_HOST([localedir])
-  localedir="${gt_saved_localedir}"
-  datarootdir="${gt_saved_datarootdir}"
-  prefix="${gt_saved_prefix}"
+  gl_BUILD_TO_HOST_LOCALEDIR
 ])
 
 
-- 
2.34.1

>From d34065436725869d4d3fd7f46c8f51e65c33ae3c Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 26 Sep 2024 02:02:56 +0200
Subject: [PATCH 2/2] relocatable-lib-lgpl: Add support for mingw builds on
 Cygwin hosts.

Reported by Michele Locati <mich...@locati.it> in
<https://lists.gnu.org/archive/html/bug-gettext/2024-09/msg00033.html>.

* m4/relocatable-lib.m4 (gl_RELOCATABLE_LIBRARY_BODY): Use
gl_BUILD_TO_HOST on the value of INSTALLPREFIX.
* modules/relocatable-lib (Files): Add m4/build-to-host.m4.
* modules/relocatable-lib-lgpl (Files): Likewise.
* modules/relocatable-prog-wrapper (Files): Likewise.
---
 ChangeLog                        | 11 +++++++++++
 m4/relocatable-lib.m4            |  6 ++++--
 modules/relocatable-lib          |  1 +
 modules/relocatable-lib-lgpl     |  1 +
 modules/relocatable-prog-wrapper |  1 +
 5 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index eb64686dbb..c42d59d189 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-09-25  Bruno Haible  <br...@clisp.org>
+
+	relocatable-lib-lgpl: Add support for mingw builds on Cygwin hosts.
+	Reported by Michele Locati <mich...@locati.it> in
+	<https://lists.gnu.org/archive/html/bug-gettext/2024-09/msg00033.html>.
+	* m4/relocatable-lib.m4 (gl_RELOCATABLE_LIBRARY_BODY): Use
+	gl_BUILD_TO_HOST on the value of INSTALLPREFIX.
+	* modules/relocatable-lib (Files): Add m4/build-to-host.m4.
+	* modules/relocatable-lib-lgpl (Files): Likewise.
+	* modules/relocatable-prog-wrapper (Files): Likewise.
+
 2024-09-25  Bruno Haible  <br...@clisp.org>
 
 	build-to-host.m4: Add some convenience macros.
diff --git a/m4/relocatable-lib.m4 b/m4/relocatable-lib.m4
index eee1d1f799..7fcf29758f 100644
--- a/m4/relocatable-lib.m4
+++ b/m4/relocatable-lib.m4
@@ -1,5 +1,5 @@
 # relocatable-lib.m4
-# serial 7
+# serial 8
 dnl Copyright (C) 2003, 2005-2007, 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -21,7 +21,9 @@ AC_DEFUN([gl_RELOCATABLE_LIBRARY_BODY]
   else
     reloc_final_prefix="$prefix"
   fi
-  AC_DEFINE_UNQUOTED([INSTALLPREFIX], ["${reloc_final_prefix}"],
+  dnl Define reloc_final_prefix_c and reloc_final_prefix_c_make.
+  gl_BUILD_TO_HOST([reloc_final_prefix])
+  AC_DEFINE_UNQUOTED([INSTALLPREFIX], [${reloc_final_prefix_c}],
     [Define to the value of ${prefix}, as a string.])
   if test $RELOCATABLE = yes; then
     AC_DEFINE([ENABLE_RELOCATABLE], [1],
diff --git a/modules/relocatable-lib b/modules/relocatable-lib
index 70f11f0f66..7cdca5ce0a 100644
--- a/modules/relocatable-lib
+++ b/modules/relocatable-lib
@@ -8,6 +8,7 @@ lib/relocatable.h
 lib/relocatable.c
 lib/relocatable.valgrind
 m4/relocatable-lib.m4
+m4/build-to-host.m4
 
 Depends-on:
 xalloc
diff --git a/modules/relocatable-lib-lgpl b/modules/relocatable-lib-lgpl
index da6c649156..b8ecb51ef8 100644
--- a/modules/relocatable-lib-lgpl
+++ b/modules/relocatable-lib-lgpl
@@ -8,6 +8,7 @@ lib/relocatable.h
 lib/relocatable.c
 lib/relocatable.valgrind
 m4/relocatable-lib.m4
+m4/build-to-host.m4
 
 Depends-on:
 strdup
diff --git a/modules/relocatable-prog-wrapper b/modules/relocatable-prog-wrapper
index b2143809ca..4d8e70d3ac 100644
--- a/modules/relocatable-prog-wrapper
+++ b/modules/relocatable-prog-wrapper
@@ -47,6 +47,7 @@ m4/rawmemchr.m4
 m4/readlink.m4
 m4/realloc.m4
 m4/relocatable-lib.m4
+m4/build-to-host.m4
 m4/setenv.m4
 
 Depends-on:
-- 
2.34.1

Reply via email to