1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-13 16:38:14 +00:00
emacs/build-aux/msys-to-w32
Dani Moncayo 7c86a2a7d8 build-aux/msys-to-w32: simplify the initial interface.
* build-aux/msys-to-w32: simplify the initial over-engineered
interface, and the implementation.
* Makefile.in (epaths-force-w32): Update for the above.
2014-11-08 15:55:09 +01:00

118 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# Take a list of MSYS-compatible paths and convert them to native
# MS-Windows format.
# Status is zero if successful, nonzero otherwise.
# Copyright (C) 2013-2014 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Take only the basename from the full pathname
me=${0//*\//}
usage="usage: ${me} PATHLIST"
help="$usage
or: ${me} OPTION
Convert a MSYS path list to Windows-native format.
PATHLIST should be a colon-separated list of MSYS paths, which will be
written to the standard output after performing these transformations:
1. Discard empty paths.
2. Replace: '\' with '/', '//' with '/' and ':' with ';'.
3. Translate each path to Windows-native format.
Relative paths or paths starting with '%emacs_dir%' will be passed
verbatim to the standard output.
Each non existing absolute paths will be translated by looking for its
deepest existing directory, which will be translated and the remainder
will be appended.
Options:
--help display this help and exit
Report bugs to <bug-gnu-emacs@gnu.org>."
for arg
do
case $arg in
--help | --hel | --he | --h)
exec echo "$help" ;;
--)
shift
break ;;
-*)
echo "${me}: invalid option: $arg" >&2
exit 1 ;;
*)
break ;;
esac
done
[ $# -eq 1 ] || {
echo "${me}: $usage" >&2
exit 1
}
w32pathlist=""
# Put each MSYS path in one positional parameter and iterate through
# them
IFS=:
set -- $1
for p
do
[ -z "$p" ] && continue
if [ "${p:0:11}" = "%emacs_dir%" ]
then
w32p=$p
elif [ "${p:0:1}" != "/" ]
then
w32p=$p
elif [ -d "$p" ]
then
w32p=$(cd "$p" && pwd -W)
else
# Make some cleanup in the path and look for its deepest
# existing directory
p=${p//\\//}
p=${p//\/\///}
p=${p%/}
p1=$p
while :
do
p1=${p1%/*}
[ -z "$p1" ] && p1="/" && break
[ -d "$p1" ] && break
done
# translate the existing part and append the rest
w32p=$(cd "${p1}" && pwd -W)
remainder=${p#$p1}
w32p+=/${remainder#/}
fi
w32pathlist="${w32pathlist};${w32p}"
done
echo "${w32pathlist:1}"