jpayne@68: # build-to-host.m4 serial 3 jpayne@68: dnl Copyright (C) 2023-2024 Free Software Foundation, Inc. jpayne@68: dnl This file is free software; the Free Software Foundation jpayne@68: dnl gives unlimited permission to copy and/or distribute it, jpayne@68: dnl with or without modifications, as long as this notice is preserved. jpayne@68: jpayne@68: dnl Written by Bruno Haible. jpayne@68: jpayne@68: dnl When the build environment ($build_os) is different from the target runtime jpayne@68: dnl environment ($host_os), file names may need to be converted from the build jpayne@68: dnl environment syntax to the target runtime environment syntax. This is jpayne@68: dnl because the Makefiles are executed (mostly) by build environment tools and jpayne@68: dnl therefore expect file names in build environment syntax, whereas the runtime jpayne@68: dnl expects file names in target runtime environment syntax. jpayne@68: dnl jpayne@68: dnl For example, if $build_os = cygwin and $host_os = mingw32, filenames need jpayne@68: dnl be converted from Cygwin syntax to native Windows syntax: jpayne@68: dnl /cygdrive/c/foo/bar -> C:\foo\bar jpayne@68: dnl /usr/local/share -> C:\cygwin64\usr\local\share jpayne@68: dnl jpayne@68: dnl gl_BUILD_TO_HOST([somedir]) jpayne@68: dnl This macro takes as input an AC_SUBSTed variable 'somedir', which must jpayne@68: dnl already have its final value assigned, and produces two additional jpayne@68: dnl AC_SUBSTed variables 'somedir_c' and 'somedir_c_make', that designate the jpayne@68: dnl same file name value, just in different syntax: jpayne@68: dnl - somedir_c is the file name in target runtime environment syntax, jpayne@68: dnl as a C string (starting and ending with a double-quote, jpayne@68: dnl and with escaped backslashes and double-quotes in jpayne@68: dnl between). jpayne@68: dnl - somedir_c_make is the same thing, escaped for use in a Makefile. jpayne@68: jpayne@68: AC_DEFUN([gl_BUILD_TO_HOST], jpayne@68: [ jpayne@68: AC_REQUIRE([AC_CANONICAL_BUILD]) jpayne@68: AC_REQUIRE([AC_CANONICAL_HOST]) jpayne@68: AC_REQUIRE([gl_BUILD_TO_HOST_INIT]) jpayne@68: jpayne@68: dnl Define somedir_c. jpayne@68: gl_final_[$1]="$[$1]" jpayne@68: dnl Translate it from build syntax to host syntax. jpayne@68: case "$build_os" in jpayne@68: cygwin*) jpayne@68: case "$host_os" in jpayne@68: mingw* | windows*) jpayne@68: gl_final_[$1]=`cygpath -w "$gl_final_[$1]"` ;; jpayne@68: esac jpayne@68: ;; jpayne@68: esac jpayne@68: dnl Convert it to C string syntax. jpayne@68: [$1]_c=`printf '%s\n' "$gl_final_[$1]" | sed -e "$gl_sed_double_backslashes" -e "$gl_sed_escape_doublequotes" | tr -d "$gl_tr_cr"` jpayne@68: [$1]_c='"'"$[$1]_c"'"' jpayne@68: AC_SUBST([$1_c]) jpayne@68: jpayne@68: dnl Define somedir_c_make. jpayne@68: [$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"` jpayne@68: dnl Use the substituted somedir variable, when possible, so that the user jpayne@68: dnl may adjust somedir a posteriori when there are no special characters. jpayne@68: if test "$[$1]_c_make" = '\"'"${gl_final_[$1]}"'\"'; then jpayne@68: [$1]_c_make='\"$([$1])\"' jpayne@68: fi jpayne@68: AC_SUBST([$1_c_make]) jpayne@68: ]) jpayne@68: jpayne@68: dnl Some initializations for gl_BUILD_TO_HOST. jpayne@68: AC_DEFUN([gl_BUILD_TO_HOST_INIT], jpayne@68: [ jpayne@68: gl_sed_double_backslashes='s/\\/\\\\/g' jpayne@68: gl_sed_escape_doublequotes='s/"/\\"/g' jpayne@68: changequote(,)dnl jpayne@68: gl_sed_escape_for_make_1="s,\\([ \"&'();<>\\\\\`|]\\),\\\\\\1,g" jpayne@68: changequote([,])dnl jpayne@68: gl_sed_escape_for_make_2='s,\$,\\$$,g' jpayne@68: dnl Find out how to remove carriage returns from output. Solaris /usr/ucb/tr jpayne@68: dnl does not understand '\r'. jpayne@68: case `echo r | tr -d '\r'` in jpayne@68: '') gl_tr_cr='\015' ;; jpayne@68: *) gl_tr_cr='\r' ;; jpayne@68: esac jpayne@68: ])