jpayne@68
|
1 # build-to-host.m4 serial 3
|
jpayne@68
|
2 dnl Copyright (C) 2023-2024 Free Software Foundation, Inc.
|
jpayne@68
|
3 dnl This file is free software; the Free Software Foundation
|
jpayne@68
|
4 dnl gives unlimited permission to copy and/or distribute it,
|
jpayne@68
|
5 dnl with or without modifications, as long as this notice is preserved.
|
jpayne@68
|
6
|
jpayne@68
|
7 dnl Written by Bruno Haible.
|
jpayne@68
|
8
|
jpayne@68
|
9 dnl When the build environment ($build_os) is different from the target runtime
|
jpayne@68
|
10 dnl environment ($host_os), file names may need to be converted from the build
|
jpayne@68
|
11 dnl environment syntax to the target runtime environment syntax. This is
|
jpayne@68
|
12 dnl because the Makefiles are executed (mostly) by build environment tools and
|
jpayne@68
|
13 dnl therefore expect file names in build environment syntax, whereas the runtime
|
jpayne@68
|
14 dnl expects file names in target runtime environment syntax.
|
jpayne@68
|
15 dnl
|
jpayne@68
|
16 dnl For example, if $build_os = cygwin and $host_os = mingw32, filenames need
|
jpayne@68
|
17 dnl be converted from Cygwin syntax to native Windows syntax:
|
jpayne@68
|
18 dnl /cygdrive/c/foo/bar -> C:\foo\bar
|
jpayne@68
|
19 dnl /usr/local/share -> C:\cygwin64\usr\local\share
|
jpayne@68
|
20 dnl
|
jpayne@68
|
21 dnl gl_BUILD_TO_HOST([somedir])
|
jpayne@68
|
22 dnl This macro takes as input an AC_SUBSTed variable 'somedir', which must
|
jpayne@68
|
23 dnl already have its final value assigned, and produces two additional
|
jpayne@68
|
24 dnl AC_SUBSTed variables 'somedir_c' and 'somedir_c_make', that designate the
|
jpayne@68
|
25 dnl same file name value, just in different syntax:
|
jpayne@68
|
26 dnl - somedir_c is the file name in target runtime environment syntax,
|
jpayne@68
|
27 dnl as a C string (starting and ending with a double-quote,
|
jpayne@68
|
28 dnl and with escaped backslashes and double-quotes in
|
jpayne@68
|
29 dnl between).
|
jpayne@68
|
30 dnl - somedir_c_make is the same thing, escaped for use in a Makefile.
|
jpayne@68
|
31
|
jpayne@68
|
32 AC_DEFUN([gl_BUILD_TO_HOST],
|
jpayne@68
|
33 [
|
jpayne@68
|
34 AC_REQUIRE([AC_CANONICAL_BUILD])
|
jpayne@68
|
35 AC_REQUIRE([AC_CANONICAL_HOST])
|
jpayne@68
|
36 AC_REQUIRE([gl_BUILD_TO_HOST_INIT])
|
jpayne@68
|
37
|
jpayne@68
|
38 dnl Define somedir_c.
|
jpayne@68
|
39 gl_final_[$1]="$[$1]"
|
jpayne@68
|
40 dnl Translate it from build syntax to host syntax.
|
jpayne@68
|
41 case "$build_os" in
|
jpayne@68
|
42 cygwin*)
|
jpayne@68
|
43 case "$host_os" in
|
jpayne@68
|
44 mingw* | windows*)
|
jpayne@68
|
45 gl_final_[$1]=`cygpath -w "$gl_final_[$1]"` ;;
|
jpayne@68
|
46 esac
|
jpayne@68
|
47 ;;
|
jpayne@68
|
48 esac
|
jpayne@68
|
49 dnl Convert it to C string syntax.
|
jpayne@68
|
50 [$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
|
51 [$1]_c='"'"$[$1]_c"'"'
|
jpayne@68
|
52 AC_SUBST([$1_c])
|
jpayne@68
|
53
|
jpayne@68
|
54 dnl Define somedir_c_make.
|
jpayne@68
|
55 [$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
|
56 dnl Use the substituted somedir variable, when possible, so that the user
|
jpayne@68
|
57 dnl may adjust somedir a posteriori when there are no special characters.
|
jpayne@68
|
58 if test "$[$1]_c_make" = '\"'"${gl_final_[$1]}"'\"'; then
|
jpayne@68
|
59 [$1]_c_make='\"$([$1])\"'
|
jpayne@68
|
60 fi
|
jpayne@68
|
61 AC_SUBST([$1_c_make])
|
jpayne@68
|
62 ])
|
jpayne@68
|
63
|
jpayne@68
|
64 dnl Some initializations for gl_BUILD_TO_HOST.
|
jpayne@68
|
65 AC_DEFUN([gl_BUILD_TO_HOST_INIT],
|
jpayne@68
|
66 [
|
jpayne@68
|
67 gl_sed_double_backslashes='s/\\/\\\\/g'
|
jpayne@68
|
68 gl_sed_escape_doublequotes='s/"/\\"/g'
|
jpayne@68
|
69 changequote(,)dnl
|
jpayne@68
|
70 gl_sed_escape_for_make_1="s,\\([ \"&'();<>\\\\\`|]\\),\\\\\\1,g"
|
jpayne@68
|
71 changequote([,])dnl
|
jpayne@68
|
72 gl_sed_escape_for_make_2='s,\$,\\$$,g'
|
jpayne@68
|
73 dnl Find out how to remove carriage returns from output. Solaris /usr/ucb/tr
|
jpayne@68
|
74 dnl does not understand '\r'.
|
jpayne@68
|
75 case `echo r | tr -d '\r'` in
|
jpayne@68
|
76 '') gl_tr_cr='\015' ;;
|
jpayne@68
|
77 *) gl_tr_cr='\r' ;;
|
jpayne@68
|
78 esac
|
jpayne@68
|
79 ])
|