I need to pass /DEF:c:\\filepath\\myLib.def\" command line option from a bash script to MS compiler/linker. The path is generated as part of build process by a bash script.
cygpath
This program convert a DOS path to a UNIX path and vice versa
#!/bin/env perl
# DOS to UNIX path conversion
# © John S. Peterson. License GNU GPL 3.
use strict;
use Getopt::Std;
# usage
if ($#ARGV == -1) {
print 'Usage: cygpath (-w) NAME...
Convert Unix and Windows format paths
Output type options:
-w, --windows print Windows form of NAMEs (C:\WINNT)
';
exit 0;
}
# option
my %opt;
getopts('w', \%opt);
# convert path
my @r;
foreach my $e (@ARGV) {
if ($opt{w}) {
# add drive letter suffix
$e =~ s,^\/([A-Za-z])\/,\1:\/,;
$e =~ s,\/,\\,g;
} else {
$e =~ s,\\,\/,g;
# add leading slash
$e = "/$e";
# remove drive letter suffix
$e =~ s,:,,;
}
push @r, $e;
}
print join("\n", @r);
cygpath
The output from this program is better than the output from Cygwin cygpath
in MSYS because
cygpath
remove the Cygwin home from a converted path, f.e.cygpath "$CYGWIN/usr/local/bin"
/usr/local/bin
which is a problem because
This program doesn't remove the Cygwin home
cygpath "$CYGWIN/usr/local/bin"
/c/file/program/cygwin/usr/local/bin
Manual path conversion has a use in MSYS because
for f.e.