]> code.delx.au - gnu-emacs/blob - build-aux/msys-to-w32
Fix shr.el/image build problem
[gnu-emacs] / build-aux / msys-to-w32
1 #!/bin/bash
2 # Convert a MSYS path list to Windows-native format.
3 # Status is zero if successful, nonzero otherwise.
4
5 # Copyright (C) 2013-2016 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 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 absolute paths to Windows-native format.
36
37 Options:
38 --help display this help and exit
39
40 Report bugs to <bug-gnu-emacs@gnu.org>."
41
42 for arg
43 do
44 case $arg in
45 --help | --hel | --he | --h)
46 exec echo "$help" ;;
47 --)
48 shift
49 break ;;
50 -*)
51 echo "${me}: invalid option: $arg" >&2
52 exit 1 ;;
53 *)
54 break ;;
55 esac
56 done
57
58 [ $# -eq 1 ] || {
59 echo "${me}: $usage" >&2
60 exit 1
61 }
62
63 w32pathlist=""
64
65 # Put each MSYS path in one positional parameter and iterate through
66 # them
67 IFS=:
68 set -- $1
69
70 for p
71 do
72 [ -z "$p" ] && continue
73
74 if [ "${p:0:1}" != "/" ]
75 then
76 w32p=$p
77 elif [ -d "$p" ]
78 then
79 w32p=$(cd "$p" && pwd -W)
80 else
81 # Make some cleanup in the path and look for its deepest
82 # existing directory
83
84 p=${p//\\//}
85 p=${p//\/\///}
86 p=${p%/}
87
88 p1=$p
89 while :
90 do
91 p1=${p1%/*}
92 [ -z "$p1" ] && p1="/" && break
93 [ -d "$p1" ] && break
94 done
95
96 # translate the existing part and append the rest
97 w32p=$(cd "${p1}" && pwd -W)
98 remainder=${p#$p1}
99 w32p=${w32p%/}/${remainder#/}
100 fi
101
102 w32pathlist="${w32pathlist};${w32p}"
103
104 done
105
106 echo "${w32pathlist:1}"