build-to-host.m4 (9242B)
1 # build-to-host.m4 2 # serial 5 3 dnl Copyright (C) 2023-2024 Free Software Foundation, Inc. 4 dnl This file is free software; the Free Software Foundation 5 dnl gives unlimited permission to copy and/or distribute it, 6 dnl with or without modifications, as long as this notice is preserved. 7 dnl This file is offered as-is, without any warranty. 8 9 dnl Written by Bruno Haible. 10 11 dnl When the build environment ($build_os) is different from the target runtime 12 dnl environment ($host_os), file names may need to be converted from the build 13 dnl environment syntax to the target runtime environment syntax. This is 14 dnl because the Makefiles are executed (mostly) by build environment tools and 15 dnl therefore expect file names in build environment syntax, whereas the runtime 16 dnl expects file names in target runtime environment syntax. 17 dnl 18 dnl For example, if $build_os = cygwin and $host_os = mingw32, filenames need 19 dnl be converted from Cygwin syntax to native Windows syntax: 20 dnl /cygdrive/c/foo/bar -> C:\foo\bar 21 dnl /usr/local/share -> C:\cygwin64\usr\local\share 22 dnl 23 dnl gl_BUILD_TO_HOST([somedir]) 24 dnl This macro takes as input an AC_SUBSTed variable 'somedir', which must 25 dnl already have its final value assigned, and produces two additional 26 dnl AC_SUBSTed variables 'somedir_c' and 'somedir_c_make', that designate the 27 dnl same file name value, just in different syntax: 28 dnl - somedir_c is the file name in target runtime environment syntax, 29 dnl as a C string (starting and ending with a double-quote, 30 dnl and with escaped backslashes and double-quotes in 31 dnl between). 32 dnl - somedir_c_make is the same thing, escaped for use in a Makefile. 33 34 AC_DEFUN([gl_BUILD_TO_HOST], 35 [ 36 AC_REQUIRE([AC_CANONICAL_BUILD]) 37 AC_REQUIRE([AC_CANONICAL_HOST]) 38 AC_REQUIRE([gl_BUILD_TO_HOST_INIT]) 39 40 dnl Define somedir_c. 41 gl_final_[$1]="$[$1]" 42 dnl Translate it from build syntax to host syntax. 43 case "$build_os" in 44 cygwin*) 45 case "$host_os" in 46 mingw* | windows*) 47 gl_final_[$1]=`cygpath -w "$gl_final_[$1]"` ;; 48 esac 49 ;; 50 esac 51 dnl Convert it to C string syntax. 52 [$1]_c=`printf '%s\n' "$gl_final_[$1]" | sed -e "$gl_sed_double_backslashes" -e "$gl_sed_escape_doublequotes" | tr -d "$gl_tr_cr"` 53 [$1]_c='"'"$[$1]_c"'"' 54 AC_SUBST([$1_c]) 55 56 dnl Define somedir_c_make. 57 [$1]_c_make=`printf '%s\n' "$[$1]_c" | sed -e "$gl_sed_escape_for_make_1" -e "$gl_sed_escape_for_make_2" | tr -d "$gl_tr_cr"` 58 dnl Use the substituted somedir variable, when possible, so that the user 59 dnl may adjust somedir a posteriori when there are no special characters. 60 if test "$[$1]_c_make" = '\"'"${gl_final_[$1]}"'\"'; then 61 [$1]_c_make='\"$([$1])\"' 62 fi 63 AC_SUBST([$1_c_make]) 64 ]) 65 66 dnl Some initializations for gl_BUILD_TO_HOST. 67 AC_DEFUN([gl_BUILD_TO_HOST_INIT], 68 [ 69 gl_sed_double_backslashes='s/\\/\\\\/g' 70 gl_sed_escape_doublequotes='s/"/\\"/g' 71 changequote(,)dnl 72 gl_sed_escape_for_make_1="s,\\([ \"&'();<>\\\\\`|]\\),\\\\\\1,g" 73 changequote([,])dnl 74 gl_sed_escape_for_make_2='s,\$,\\$$,g' 75 dnl Find out how to remove carriage returns from output. Solaris /usr/ucb/tr 76 dnl does not understand '\r'. 77 case `echo r | tr -d '\r'` in 78 '') gl_tr_cr='\015' ;; 79 *) gl_tr_cr='\r' ;; 80 esac 81 ]) 82 83 84 dnl The following macros are convenience invocations of gl_BUILD_TO_HOST 85 dnl for some of the variables that are defined by Autoconf. 86 dnl To do so for _all_ the possible variables, use the module 'configmake'. 87 88 dnl Defines bindir_c and bindir_c_make. 89 AC_DEFUN_ONCE([gl_BUILD_TO_HOST_BINDIR], 90 [ 91 dnl Find the final value of bindir. 92 gl_saved_prefix="${prefix}" 93 gl_saved_exec_prefix="${exec_prefix}" 94 gl_saved_bindir="${bindir}" 95 dnl Unfortunately, prefix and exec_prefix get only finally determined 96 dnl at the end of configure. 97 if test "X$prefix" = "XNONE"; then 98 prefix="$ac_default_prefix" 99 fi 100 if test "X$exec_prefix" = "XNONE"; then 101 exec_prefix='${prefix}' 102 fi 103 eval exec_prefix="$exec_prefix" 104 eval bindir="$bindir" 105 gl_BUILD_TO_HOST([bindir]) 106 bindir="${gl_saved_bindir}" 107 exec_prefix="${gl_saved_exec_prefix}" 108 prefix="${gl_saved_prefix}" 109 ]) 110 111 dnl Defines datadir_c and datadir_c_make, 112 dnl where datadir = $(datarootdir) 113 AC_DEFUN_ONCE([gl_BUILD_TO_HOST_DATADIR], 114 [ 115 dnl Find the final value of datadir. 116 gl_saved_prefix="${prefix}" 117 gl_saved_datarootdir="${datarootdir}" 118 gl_saved_datadir="${datadir}" 119 dnl Unfortunately, prefix gets only finally determined at the end of 120 dnl configure. 121 if test "X$prefix" = "XNONE"; then 122 prefix="$ac_default_prefix" 123 fi 124 eval datarootdir="$datarootdir" 125 eval datadir="$datadir" 126 gl_BUILD_TO_HOST([datadir]) 127 datadir="${gl_saved_datadir}" 128 datarootdir="${gl_saved_datarootdir}" 129 prefix="${gl_saved_prefix}" 130 ]) 131 132 dnl Defines libdir_c and libdir_c_make. 133 AC_DEFUN_ONCE([gl_BUILD_TO_HOST_LIBDIR], 134 [ 135 dnl Find the final value of libdir. 136 gl_saved_prefix="${prefix}" 137 gl_saved_exec_prefix="${exec_prefix}" 138 gl_saved_libdir="${libdir}" 139 dnl Unfortunately, prefix and exec_prefix get only finally determined 140 dnl at the end of configure. 141 if test "X$prefix" = "XNONE"; then 142 prefix="$ac_default_prefix" 143 fi 144 if test "X$exec_prefix" = "XNONE"; then 145 exec_prefix='${prefix}' 146 fi 147 eval exec_prefix="$exec_prefix" 148 eval libdir="$libdir" 149 gl_BUILD_TO_HOST([libdir]) 150 libdir="${gl_saved_libdir}" 151 exec_prefix="${gl_saved_exec_prefix}" 152 prefix="${gl_saved_prefix}" 153 ]) 154 155 dnl Defines libexecdir_c and libexecdir_c_make. 156 AC_DEFUN_ONCE([gl_BUILD_TO_HOST_LIBEXECDIR], 157 [ 158 dnl Find the final value of libexecdir. 159 gl_saved_prefix="${prefix}" 160 gl_saved_exec_prefix="${exec_prefix}" 161 gl_saved_libexecdir="${libexecdir}" 162 dnl Unfortunately, prefix and exec_prefix get only finally determined 163 dnl at the end of configure. 164 if test "X$prefix" = "XNONE"; then 165 prefix="$ac_default_prefix" 166 fi 167 if test "X$exec_prefix" = "XNONE"; then 168 exec_prefix='${prefix}' 169 fi 170 eval exec_prefix="$exec_prefix" 171 eval libexecdir="$libexecdir" 172 gl_BUILD_TO_HOST([libexecdir]) 173 libexecdir="${gl_saved_libexecdir}" 174 exec_prefix="${gl_saved_exec_prefix}" 175 prefix="${gl_saved_prefix}" 176 ]) 177 178 dnl Defines localedir_c and localedir_c_make. 179 AC_DEFUN_ONCE([gl_BUILD_TO_HOST_LOCALEDIR], 180 [ 181 dnl Find the final value of localedir. 182 gl_saved_prefix="${prefix}" 183 gl_saved_datarootdir="${datarootdir}" 184 gl_saved_localedir="${localedir}" 185 dnl Unfortunately, prefix gets only finally determined at the end of 186 dnl configure. 187 if test "X$prefix" = "XNONE"; then 188 prefix="$ac_default_prefix" 189 fi 190 eval datarootdir="$datarootdir" 191 eval localedir="$localedir" 192 gl_BUILD_TO_HOST([localedir]) 193 localedir="${gl_saved_localedir}" 194 datarootdir="${gl_saved_datarootdir}" 195 prefix="${gl_saved_prefix}" 196 ]) 197 198 dnl Defines pkgdatadir_c and pkgdatadir_c_make, 199 dnl where pkgdatadir = $(datadir)/$(PACKAGE) 200 AC_DEFUN_ONCE([gl_BUILD_TO_HOST_PKGDATADIR], 201 [ 202 dnl Find the final value of pkgdatadir. 203 gl_saved_prefix="${prefix}" 204 gl_saved_datarootdir="${datarootdir}" 205 gl_saved_datadir="${datadir}" 206 gl_saved_pkgdatadir="${pkgdatadir}" 207 dnl Unfortunately, prefix gets only finally determined at the end of 208 dnl configure. 209 if test "X$prefix" = "XNONE"; then 210 prefix="$ac_default_prefix" 211 fi 212 eval datarootdir="$datarootdir" 213 eval datadir="$datadir" 214 eval pkgdatadir="$pkgdatadir" 215 gl_BUILD_TO_HOST([pkgdatadir]) 216 pkgdatadir="${gl_saved_pkgdatadir}" 217 datadir="${gl_saved_datadir}" 218 datarootdir="${gl_saved_datarootdir}" 219 prefix="${gl_saved_prefix}" 220 ]) 221 222 dnl Defines pkglibdir_c and pkglibdir_c_make, 223 dnl where pkglibdir = $(libdir)/$(PACKAGE) 224 AC_DEFUN_ONCE([gl_BUILD_TO_HOST_PKGLIBDIR], 225 [ 226 dnl Find the final value of pkglibdir. 227 gl_saved_prefix="${prefix}" 228 gl_saved_exec_prefix="${exec_prefix}" 229 gl_saved_libdir="${libdir}" 230 gl_saved_pkglibdir="${pkglibdir}" 231 dnl Unfortunately, prefix and exec_prefix get only finally determined 232 dnl at the end of configure. 233 if test "X$prefix" = "XNONE"; then 234 prefix="$ac_default_prefix" 235 fi 236 if test "X$exec_prefix" = "XNONE"; then 237 exec_prefix='${prefix}' 238 fi 239 eval exec_prefix="$exec_prefix" 240 eval libdir="$libdir" 241 eval pkglibdir="$pkglibdir" 242 gl_BUILD_TO_HOST([pkglibdir]) 243 pkglibdir="${gl_saved_pkglibdir}" 244 libdir="${gl_saved_libdir}" 245 exec_prefix="${gl_saved_exec_prefix}" 246 prefix="${gl_saved_prefix}" 247 ]) 248 249 dnl Defines pkglibexecdir_c and pkglibexecdir_c_make, 250 dnl where pkglibexecdir = $(libexecdir)/$(PACKAGE) 251 AC_DEFUN_ONCE([gl_BUILD_TO_HOST_PKGLIBEXECDIR], 252 [ 253 dnl Find the final value of pkglibexecdir. 254 gl_saved_prefix="${prefix}" 255 gl_saved_exec_prefix="${exec_prefix}" 256 gl_saved_libexecdir="${libexecdir}" 257 gl_saved_pkglibexecdir="${pkglibexecdir}" 258 dnl Unfortunately, prefix and exec_prefix get only finally determined 259 dnl at the end of configure. 260 if test "X$prefix" = "XNONE"; then 261 prefix="$ac_default_prefix" 262 fi 263 if test "X$exec_prefix" = "XNONE"; then 264 exec_prefix='${prefix}' 265 fi 266 eval exec_prefix="$exec_prefix" 267 eval libexecdir="$libexecdir" 268 eval pkglibexecdir="$pkglibexecdir" 269 gl_BUILD_TO_HOST([pkglibexecdir]) 270 pkglibexecdir="${gl_saved_pkglibexecdir}" 271 libexecdir="${gl_saved_libexecdir}" 272 exec_prefix="${gl_saved_exec_prefix}" 273 prefix="${gl_saved_prefix}" 274 ])