| | 22 | |
| | 23 | #------------------------------------------------------------------------------ |
| | 24 | # CS_PATH_NORMALIZE_EMBEDDED(STRING) |
| | 25 | # Normalize all paths embedded in STRING at run-time by transliterating |
| | 26 | # Windows/DOS backslashes to forward slashes. Also collapses whitespace. |
| | 27 | # This is useful when applied to command output which may include |
| | 28 | # embedded Windows-style paths since the backslashes in those paths could |
| | 29 | # be incorrectly interpreted in the context of Makefiles or other |
| | 30 | # development utilities. For instance, a string such as "-Ic:\foo\inc |
| | 31 | # -Ic:\foo\local\inc" is normalized to "-Ic:/foo/inc -Ic:/foo/local/inc". |
| | 32 | # |
| | 33 | # Usage: opts=CS_PATH_NORMALIZE_EMBEDDED([$opts]) |
| | 34 | #------------------------------------------------------------------------------ |
| | 35 | AC_DEFUN([CS_PATH_NORMALIZE_EMBEDDED], |
| | 36 | [`echo "x$1" | tr '\\\\' '/' | sed 's/^x//;s/ */ /g;s/^ //;s/ $//'`]) |
| | 37 | |
| | 38 | |
| | 39 | |
| | 40 | #------------------------------------------------------------------------------ |
| | 41 | # CS_PATH_NORMALIZE_OUTPUT(COMMAND) |
| | 42 | # Normalize all paths emitted by COMMAND by transliterating Windows/DOS |
| | 43 | # backslashes to forward slashes. Also collapses whitespace. This is |
| | 44 | # useful when the output of COMMAND may include embedded Windows-style |
| | 45 | # paths since the backslashes in those paths could be incorrectly |
| | 46 | # interpreted in the context of Makefiles or other development |
| | 47 | # utilities. For instance, if COMMAND "pkg-config --cflags foo" emits |
| | 48 | # "-Ic:\foo\inc -Ic:\foo\local\inc", the output is normalized to |
| | 49 | # "-Ic:/foo/inc -Ic:/foo/local/inc". |
| | 50 | # |
| | 51 | # Usage: opts=CS_PATH_NORMALIZE_OUTPUT([$cmd]) |
| | 52 | #------------------------------------------------------------------------------ |
| | 53 | AC_DEFUN([CS_PATH_NORMALIZE_OUTPUT], |
| | 54 | [`AC_RUN_LOG([$1]) | tr '\\\\' '/' | sed 's/ */ /g;s/^ //;s/ $//'`]) |
| | 55 | |
| | 56 | |
| | 57 | |
| 36 | | AC_DEFUN([CS_RUN_PATH_NORMALIZE], |
| 37 | | [`AC_RUN_LOG([$1]) | tr '\\\\' '/' | sed 's/^x//;s/ */ /g;s/^ //;s/ $//'`]) |
| | 70 | AC_DEFUN([CS_RUN_PATH_NORMALIZE], [CS_PATH_NORMALIZE_OUTPUT([$1])]) |
| | 71 | |
| | 72 | |
| | 73 | |
| | 74 | #------------------------------------------------------------------------------ |
| | 75 | # CS_PATH_CANONICALIZE(PATH) |
| | 76 | # Canonicalize PATH by transliterating Windows/DOS backslashes to forward |
| | 77 | # slashes. On MSYS/MinGW, also converts MSYS-style paths |
| | 78 | # (ex. /home/foo/bar/, /c/foo/bar) to proper Windows-style paths |
| | 79 | # (ex. c:/msys/home/foo/bar, c:/foo/bar). This is important because an |
| | 80 | # MSYS-style path is meaningful only to MSYS, but not to utilities which |
| | 81 | # might be invoked by a Makefile or other build tool. Such utilities |
| | 82 | # invariably expect Windows-style paths. |
| | 83 | # |
| | 84 | # Usage: path=CS_PATH_CANONICALIZE([$path]) |
| | 85 | #------------------------------------------------------------------------------ |
| | 86 | AC_DEFUN([CS_PATH_CANONICALIZE], |
| | 87 | [$( |
| | 88 | cs_indir=CS_PATH_NORMALIZE_EMBEDDED([$1]) |
| | 89 | MSYS_AC_CANONICAL_PATH([cs_outdir], [$cs_indir]) |
| | 90 | echo $cs_outdir |
| | 91 | )]) |
| | 92 | |
| | 93 | |
| | 94 | |
| | 95 | #------------------------------------------------------------------------------ |
| | 96 | # MSYS_AC_CANONICAL_PATH(VAR, PATHNAME) |
| | 97 | # Set VAR to the canonically resolved absolute equivalent of PATHNAME, |
| | 98 | # (which may be a relative path, and need not refer to any existing |
| | 99 | # entity). |
| | 100 | # |
| | 101 | # On Win32-MSYS build hosts, the returned path is resolved to its true |
| | 102 | # native Win32 path name (but with slashes, not backslashes). |
| | 103 | # |
| | 104 | # On any other system, it is simply the result which would be obtained if |
| | 105 | # PATHNAME represented an existing directory, and the pwd command was |
| | 106 | # executed in that directory. |
| | 107 | # |
| | 108 | # Author: Keith Marshall <keith.marshall@total.com> |
| | 109 | # Source: http://article.gmane.org/gmane.comp.gnu.mingw.msys/2785 |
| | 110 | #------------------------------------------------------------------------------ |
| | 111 | AC_DEFUN([MSYS_AC_CANONICAL_PATH], |
| | 112 | [ac_dir="$2" |
| | 113 | pwd -W >/dev/null 2>&1 && ac_pwd_w="pwd -W" || ac_pwd_w=pwd |
| | 114 | until ac_val=`exec 2>/dev/null; cd "$ac_dir" && $ac_pwd_w` |
| | 115 | do |
| | 116 | ac_dir=`AS_DIRNAME(["$ac_dir"])` |
| | 117 | done |
| | 118 | ac_dir=`echo "$ac_dir" | sed 's?^[[./]]*??'` |
| | 119 | ac_val=`echo "$ac_val" | sed 's?/*$[]??'` |
| | 120 | $1=`echo "$2" | sed "s?^[[./]]*$ac_dir/*?$ac_val/?"';s?/*$[]??'`]) |
| | 121 | |
| | 122 | |
| | 123 | |
| | 124 | #------------------------------------------------------------------------------ |
| | 125 | # CS_PATH_INIT |
| | 126 | # Initialize commonly-used variable substitutions via AC_SUBST(). |
| | 127 | # Present implementation publishes CS_TOP_SRCDIR and CS_TOP_BUILDDIR, |
| | 128 | # which are canonicalized counterparts (via CS_PATH_CANONICALIZE()) of |
| | 129 | # Autoconf's top_srcdir and top_builddir substitutions (ex: in source |
| | 130 | # file, use @CS_TOP_SRCDIR@ rather than @top_srcdir@). |
| | 131 | #------------------------------------------------------------------------------ |
| | 132 | AC_DEFUN([CS_PATH_INIT], |
| | 133 | [AC_SUBST([CS_TOP_SRCDIR], [CS_PATH_CANONICALIZE([$srcdir])]) |
| | 134 | AC_SUBST([CS_TOP_BUILDDIR], [.]) |
| | 135 | ]) |