diff options
author | Bruno Haible <bruno@clisp.org> | 2023-02-18 16:59:22 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-02-18 16:59:22 +0100 |
commit | bb3fd10e6309f017618a12b2c10d3bfb813bfc08 (patch) | |
tree | 008d92794c0e93e9e9f6381dfe06311d459146f8 /m4 | |
parent | f77a31de60963c994cd9b42c8088be0e734962d7 (diff) | |
download | gnulib-bb3fd10e6309f017618a12b2c10d3bfb813bfc08.tar.gz |
configmake: Add support for $build_os != $host_os.
* m4/build-to-host.m4: New file.
* m4/configmake.m4 (gl_CONFIGMAKE_PREP): Provide a configure-time
definition for pkgdatadir, pkgincludedir, pkglibdir.
(gl_CONFIGMAKE): New macro.
* modules/configmake (Files): Add m4/build-to-host.m4.
(configure.ac): Invoke gl_CONFIGMAKE instead of gl_CONFIGMAKE_PREP.
(Makefile.am): For creating configmake.h, use the various *prefix_c_make
and *dir_c_make variables.
Diffstat (limited to 'm4')
-rw-r--r-- | m4/build-to-host.m4 | 73 | ||||
-rw-r--r-- | m4/configmake.m4 | 147 |
2 files changed, 217 insertions, 3 deletions
diff --git a/m4/build-to-host.m4 b/m4/build-to-host.m4 new file mode 100644 index 0000000000..e3c72877f0 --- /dev/null +++ b/m4/build-to-host.m4 @@ -0,0 +1,73 @@ +# build-to-host.m4 serial 1 +dnl Copyright (C) 2023 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Bruno Haible. + +dnl When the build environment ($build_os) is different from the target runtime +dnl environment ($host_os), file names may need to be converted from the build +dnl environment syntax to the target runtime environment syntax. This is +dnl because the Makefiles are executed (mostly) by build environment tools and +dnl therefore expect file names in build environment syntax, whereas the runtime +dnl expects file names in target runtime environment syntax. +dnl +dnl For example, if $build_os = cygwin and $host_os = mingw32, filenames need +dnl be converted from Cygwin syntax to native Windows syntax: +dnl /cygdrive/c/foo/bar -> C:\foo\bar +dnl /usr/local/share -> C:\cygwin64\usr\local\share +dnl +dnl gl_BUILD_TO_HOST([somedir]) +dnl This macro takes as input an AC_SUBSTed variable 'somedir', which must +dnl already have its final value assigned, and produces two additional +dnl AC_SUBSTed variables 'somedir_c' and 'somedir_c_make', that designate the +dnl same file name value, just in different syntax: +dnl - somedir_c is the file name in target runtime environment syntax, +dnl as a C string (starting and ending with a double-quote, +dnl and with escaped backslashes and double-quotes in +dnl between). +dnl - somedir_c_make is the same thing, escaped for use in a Makefile. + +AC_DEFUN([gl_BUILD_TO_HOST], +[ + AC_REQUIRE([AC_CANONICAL_BUILD]) + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([gl_BUILD_TO_HOST_INIT]) + + dnl Define somedir_c. + gl_final_[$1]="$[$1]" + dnl Translate it from build syntax to host syntax. + case "$build_os" in + cygwin*) + case "$host_os" in + mingw*) + gl_final_[$1]=`cygpath -w "$gl_final_[$1]"` ;; + esac + ;; + esac + dnl Convert it to C string syntax. + [$1]_c=`echo "$gl_final_[$1]" | sed -e "$gl_sed_double_backslashes" -e "$gl_sed_escape_doublequotes"` + [$1]_c='"'"$[$1]_c"'"' + AC_SUBST([$1_c]) + + dnl Define somedir_c_make. + [$1]_c_make=`echo "$[$1]_c" | sed -e "$gl_sed_escape_for_make_1" -e "$gl_sed_escape_for_make_2"` + dnl Use the substituted somedir variable, when possible, so that the user + dnl may adjust somedir a posteriori when there are no special characters. + if test "$[$1]_c_make" = '\"'"${gl_final_[$1]}"'\"'; then + [$1]_c_make='\"$([$1])\"' + fi + AC_SUBST([$1_c_make]) +]) + +dnl Some initializations for gl_BUILD_TO_HOST. +AC_DEFUN([gl_BUILD_TO_HOST_INIT], +[ + gl_sed_double_backslashes='s/\\/\\\\/g' + gl_sed_escape_doublequotes='s/"/\\"/g' +changequote(,)dnl + gl_sed_escape_for_make_1="s,\\([ \"&'();<>\\\\\`|]\\),\\\\\\1,g" +changequote([,])dnl + gl_sed_escape_for_make_2='s,\$,\\$$,g' +]) diff --git a/m4/configmake.m4 b/m4/configmake.m4 index 7cd7cf5fb8..94f8ae24b9 100644 --- a/m4/configmake.m4 +++ b/m4/configmake.m4 @@ -1,4 +1,4 @@ -# configmake.m4 serial 4 +# configmake.m4 serial 5 dnl Copyright (C) 2010-2023 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,148 @@ AC_DEFUN([gl_CONFIGMAKE_PREP], AC_SUBST([runstatedir], ['${localstatedir}/run']) fi - dnl Automake 1.11 provides pkglibexecdir merely without AC_SUBST. - dnl This blind use of AC_SUBST is safe. + dnl Automake 1.11 provides the pkg*dir variables merely without AC_SUBST, + dnl that is, only at the Makefile.am level. AC_SUBST them, so that + dnl gl_CONFIGMAKE can compute the final values at configure time. + dnl Blindly assigning the value at configure time is OK, since configure + dnl does not have --pkg*dir=... options. + AC_SUBST([pkgdatadir], ['${datadir}/${PACKAGE}']) + AC_SUBST([pkgincludedir], ['${includedir}/${PACKAGE}']) + AC_SUBST([pkglibdir], ['${libdir}/${PACKAGE}']) AC_SUBST([pkglibexecdir], ['${libexecdir}/${PACKAGE}']) ]) + +# gl_CONFIGMAKE +# ------------- +# Find the final values of the standard directory variables, and create +# AC_SUBSTed *_c and *_c_make variables with the corresponding values in +# target runtime environment ($host_os) syntax. +AC_DEFUN([gl_CONFIGMAKE], +[ + AC_REQUIRE([gl_CONFIGMAKE_PREP]) + + dnl Save the values. + gl_save_prefix="${prefix}" + gl_save_exec_prefix="${exec_prefix}" + gl_save_bindir="${bindir}" + gl_save_sbindir="${sbindir}" + gl_save_libexecdir="${libexecdir}" + gl_save_datarootdir="${datarootdir}" + gl_save_datadir="${datadir}" + gl_save_sysconfdir="${sysconfdir}" + gl_save_sharedstatedir="${sharedstatedir}" + gl_save_localstatedir="${localstatedir}" + gl_save_runstatedir="${runstatedir}" + gl_save_includedir="${includedir}" + gl_save_oldincludedir="${oldincludedir}" + gl_save_docdir="${docdir}" + gl_save_infodir="${infodir}" + gl_save_htmldir="${htmldir}" + gl_save_dvidir="${dvidir}" + gl_save_pdfdir="${pdfdir}" + gl_save_psdir="${psdir}" + gl_save_libdir="${libdir}" + gl_save_lispdir="${lispdir}" + gl_save_localedir="${localedir}" + gl_save_mandir="${mandir}" + gl_save_pkgdatadir="${pkgdatadir}" + gl_save_pkgincludedir="${pkgincludedir}" + gl_save_pkglibdir="${pkglibdir}" + gl_save_pkglibexecdir="${pkglibexecdir}" + + dnl Find the final values. + dnl Unfortunately, prefix gets only finally determined at the end of + dnl configure. + if test "X$prefix" = "XNONE"; then + prefix="$ac_default_prefix" + fi + dnl Unfortunately, exec_prefix gets only finally determined at the end of + dnl configure. + if test "X$exec_prefix" = "XNONE"; then + exec_prefix='${prefix}' + fi + eval exec_prefix="$exec_prefix" + eval bindir="$bindir" + eval sbindir="$sbindir" + eval libexecdir="$libexecdir" + eval datarootdir="$datarootdir" + eval datadir="$datadir" + eval sysconfdir="$sysconfdir" + eval sharedstatedir="$sharedstatedir" + eval localstatedir="$localstatedir" + eval runstatedir="$runstatedir" + eval includedir="$includedir" + eval oldincludedir="$oldincludedir" + eval docdir="$docdir" + eval infodir="$infodir" + eval htmldir="$htmldir" + eval dvidir="$dvidir" + eval pdfdir="$pdfdir" + eval psdir="$psdir" + eval libdir="$libdir" + eval lispdir="$lispdir" + eval localedir="$localedir" + eval mandir="$mandir" + eval pkgdatadir="$pkgdatadir" + eval pkgincludedir="$pkgincludedir" + eval pkglibdir="$pkglibdir" + eval pkglibexecdir="$pkglibexecdir" + + dnl Transform the final values. + gl_BUILD_TO_HOST([prefix]) + gl_BUILD_TO_HOST([exec_prefix]) + gl_BUILD_TO_HOST([bindir]) + gl_BUILD_TO_HOST([sbindir]) + gl_BUILD_TO_HOST([libexecdir]) + gl_BUILD_TO_HOST([datarootdir]) + gl_BUILD_TO_HOST([datadir]) + gl_BUILD_TO_HOST([sysconfdir]) + gl_BUILD_TO_HOST([sharedstatedir]) + gl_BUILD_TO_HOST([localstatedir]) + gl_BUILD_TO_HOST([runstatedir]) + gl_BUILD_TO_HOST([includedir]) + gl_BUILD_TO_HOST([oldincludedir]) + gl_BUILD_TO_HOST([docdir]) + gl_BUILD_TO_HOST([infodir]) + gl_BUILD_TO_HOST([htmldir]) + gl_BUILD_TO_HOST([dvidir]) + gl_BUILD_TO_HOST([pdfdir]) + gl_BUILD_TO_HOST([psdir]) + gl_BUILD_TO_HOST([libdir]) + gl_BUILD_TO_HOST([lispdir]) + gl_BUILD_TO_HOST([localedir]) + gl_BUILD_TO_HOST([mandir]) + gl_BUILD_TO_HOST([pkgdatadir]) + gl_BUILD_TO_HOST([pkgincludedir]) + gl_BUILD_TO_HOST([pkglibdir]) + gl_BUILD_TO_HOST([pkglibexecdir]) + + dnl Restore the values. + pkglibexecdir="${gl_save_pkglibexecdir}" + pkglibdir="${gl_save_pkglibdir}" + pkgincludedir="${gl_save_pkgincludedir}" + pkgdatadir="${gl_save_pkgdatadir}" + mandir="${gl_save_mandir}" + localedir="${gl_save_localedir}" + lispdir="${gl_save_lispdir}" + libdir="${gl_save_libdir}" + psdir="${gl_save_psdir}" + pdfdir="${gl_save_pdfdir}" + dvidir="${gl_save_dvidir}" + htmldir="${gl_save_htmldir}" + infodir="${gl_save_infodir}" + docdir="${gl_save_docdir}" + oldincludedir="${gl_save_oldincludedir}" + includedir="${gl_save_includedir}" + runstatedir="${gl_save_runstatedir}" + localstatedir="${gl_save_localstatedir}" + sharedstatedir="${gl_save_sharedstatedir}" + sysconfdir="${gl_save_sysconfdir}" + datadir="${gl_save_datadir}" + datarootdir="${gl_save_datarootdir}" + libexecdir="${gl_save_libexecdir}" + sbindir="${gl_save_sbindir}" + bindir="${gl_save_bindir}" + exec_prefix="${gl_save_exec_prefix}" + prefix="${gl_save_prefix}" +]) |