]> code.delx.au - gnu-emacs/blob - build-aux/msys-to-w32
build-aux/msys-to-w32: always output absolute paths.
[gnu-emacs] / build-aux / msys-to-w32
1 #!/bin/bash
2 # Convert a MSYS path list to absolute, Windows-native format.
3 # Status is zero if successful, nonzero otherwise.
4
5 # Copyright (C) 2013-2014 Free Software Foundation, Inc.
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 # Take only the basename from the full pathname
21 me=${0//*\//}
22
23 usage="usage: ${me} PATHLIST"
24
25 help="$usage
26 or: ${me} OPTION
27
28 Convert a MSYS path list to absolute, Windows-native format.
29
30 PATHLIST should be a colon-separated list of MSYS paths, which will be
31 written to the standard output after performing these transformations:
32
33 1. Discard empty paths.
34 2. Replace: '\' with '/', '//' with '/' and ':' with ';'.
35 3. Translate each path to absolute, Windows-native format.
36
37 Paths starting with '%emacs_dir%' will be passed verbatim to the
38 standard output.
39
40 Each non existing path will be translated by looking for its deepest
41 existing directory, which will be translated and the remainder
42 appended.
43
44 Options:
45 --help display this help and exit
46
47 Report bugs to <bug-gnu-emacs@gnu.org>."
48
49 for arg
50 do
51 case $arg in
52 --help | --hel | --he | --h)
53 exec echo "$help" ;;
54 --)
55 shift
56 break ;;
57 -*)
58 echo "${me}: invalid option: $arg" >&2
59 exit 1 ;;
60 *)
61 break ;;
62 esac
63 done
64
65 [ $# -eq 1 ] || {
66 echo "${me}: $usage" >&2
67 exit 1
68 }
69
70 w32pathlist=""
71
72 # Put each MSYS path in one positional parameter and iterate through
73 # them
74 IFS=:
75 set -- $1
76
77 for p
78 do
79 [ -z "$p" ] && continue
80
81 if [ "${p:0:11}" = "%emacs_dir%" ]
82 then
83 w32p=$p
84 elif [ -d "$p" ]
85 then
86 w32p=$(cd "$p" && pwd -W)
87 else
88 # Make some cleanup in the path and look for its deepest
89 # existing directory
90
91 p=${p//\\//}
92 p=${p//\/\///}
93 p=${p%/}
94
95 p1=$p # last candidate tried
96 while :
97 do
98 p2=${p1%/*} # next candidate to try
99 [ "$p2" = "$p1" ] && {
100 # No more candidates to try
101 echo "Invalid path '$p'." >&2
102 exit 1
103 }
104 [ -z "$p2" ] && p2="/" && break
105 [ -d "$p2" ] && break
106 p1=$p2
107 done
108
109 # translate the existing part and append the rest
110 w32p=$(cd "${p2}" && pwd -W)
111 remainder=${p#$p2}
112 w32p+=/${remainder#/}
113 fi
114
115 w32pathlist="${w32pathlist};${w32p}"
116
117 done
118
119 echo "${w32pathlist:1}"