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