make/scripts/fixpath.pl
author vlivanov
Mon, 23 Sep 2013 19:51:40 +0400
changeset 20494 cf77ae5ff678
parent 14069 2ca7a2522cb4
permissions -rw-r--r--
8001107: @Stable annotation for constant folding of lazily evaluated variables Reviewed-by: twisti, kvn, rbackman Contributed-by: john.r.rose@oracle.com, vladimir.x.ivanov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14069
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
     1
#!/bin/perl
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
     2
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
     3
#
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
     4
# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
     6
#
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
     9
# published by the Free Software Foundation.  Oracle designates this
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    10
# particular file as subject to the "Classpath" exception as provided
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    11
# by Oracle in the LICENSE file that accompanied this code.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    12
#
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    13
# This code is distributed in the hope that it will be useful, but WITHOUT
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    14
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    15
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    16
# version 2 for more details (a copy is included in the LICENSE file that
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    17
# accompanied this code).
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    18
#
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    19
# You should have received a copy of the GNU General Public License version
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    20
# 2 along with this work; if not, write to the Free Software Foundation,
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    21
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    22
#
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    23
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    24
# or visit www.oracle.com if you need additional information or have any
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    25
# questions.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    26
#
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    27
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    28
# Crunch down the input(s) to Windows short (mangled) form.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    29
# Any elements not actually found in the filesystem will be dropped.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    30
#
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    31
# This script needs three modes:
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    32
#   1) DOS mode with drive letter followed by : and ; path separator
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    33
#   2) Cygwin mode with /cygdrive/<drive letter>/ and : path separator
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    34
#   3) MinGW/MSYS mode with /<drive letter>/ and : path separator
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    35
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    36
use strict;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    37
use warnings;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    38
use Getopt::Std;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    39
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    40
sub Usage() {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    41
    print ("Usage:\n $0 -d | -c | -m \<PATH\>\n");
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    42
    print ("            -d DOS style (drive letter, :, and ; path separator)\n");
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    43
    print ("            -c Cywgin style (/cygdrive/drive/ and : path separator)\n");
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    44
    print ("            -m MinGW style (/drive/ and : path separator)\n");
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    45
    exit 1;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    46
}
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    47
# Process command line options:
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    48
my %opts;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    49
getopts('dcm', \%opts) || Usage();
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    50
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    51
if (scalar(@ARGV) != 1) {Usage()};
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    52
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    53
# Translate drive letters such as C:/
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    54
#   if MSDOS, Win32::GetShortPathName() does the work (see below).
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    55
#   if Cygwin, use the /cygdrive/c/ form.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    56
#   if MinGW, use the /c/ form.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    57
my $path0;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    58
my $sep2;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    59
if (defined ($opts{'d'})) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    60
    #MSDOS
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    61
    $path0 = '';
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    62
    $sep2 = ';';
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    63
} elsif (defined ($opts{'c'})) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    64
    #Cygwin
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    65
    $path0 = '/cygdrive';
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    66
    $sep2 = ':';
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    67
} elsif (defined ($opts{'m'})) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    68
    #MinGW/MSYS
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    69
    $path0 = '';
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    70
    $sep2 = ':';
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    71
} else {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    72
    Usage();
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    73
}
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    74
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    75
my $input = $ARGV[0];
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    76
my $sep1;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    77
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    78
# Is the input ';' separated, or ':' separated, or a simple string?
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    79
if (($input =~ tr/;/;/) > 0) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    80
    # One or more ';' implies Windows style path.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    81
    $sep1 = ';';
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    82
} elsif (($input =~ tr/:/:/) > 1) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    83
    # Two or more ':' implies Cygwin or MinGW/MSYS style path.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    84
    $sep1 = ':';
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    85
} else {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    86
    # Otherwise, this is not a path - take up to the end of string in
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    87
    # one piece.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    88
    $sep1 = '/$/';
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    89
}
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    90
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    91
# Split the input on $sep1 PATH separator and process the pieces.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    92
my @pieces;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    93
for (split($sep1, $input)) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    94
    my $try = $_;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    95
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    96
    if (($try =~ /^\/cygdrive\/(.)\/(.*)$/) || ($try =~ /^\/(.)\/(.*)$/)) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    97
        # Special case #1: This is a Cygwin /cygrive/<drive letter/ path.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    98
        # Special case #2: This is a MinGW/MSYS /<drive letter/ path.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
    99
        $try = $1.':/'.$2;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   100
    } elsif ($try =~ /^\/(.*)$/) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   101
        # Special case #3: check for a Cygwin or MinGW/MSYS form with a
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   102
        # leading '/' for example '/usr/bin/bash'.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   103
        # Look up where this is mounted and rebuild the
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   104
        # $try string with that information
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   105
        my $cmd = "df --portability --all --human-readable $try";
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   106
        my $line = qx ($cmd);
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   107
        my $status = $?; 
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   108
        if ($status == 0) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   109
            my @lines = split ('\n', $line);
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   110
            my ($device, $junk, $mountpoint);
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   111
            # $lines[0] is the df header.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   112
            # Example string for split - we want the first and last elements:
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   113
            # C:\jprt\products\P1\MinGW\msys\1.0  200G   78G  123G  39% /usr
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   114
            ($device, $junk, $junk, $junk, $junk, $mountpoint) = split (/\s+/, $lines[1]);
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   115
            # Replace $mountpoint with $device/ in the original string
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   116
            $try =~ s|$mountpoint|$device/|;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   117
        } else {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   118
            printf ("Error %d from command %s\n%s\n", $status, $cmd, $line);
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   119
        }
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   120
    }
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   121
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   122
    my $str = Win32::GetShortPathName($try);
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   123
    if (!defined($str)){
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   124
        # Special case #4: If the lookup did not work, loop through
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   125
        # adding extensions listed in PATHEXT, looking for the first
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   126
        # match.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   127
        for (split(';', $ENV{'PATHEXT'})) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   128
            $str = Win32::GetShortPathName($try.$_);
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   129
            if (defined($str)) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   130
                last;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   131
            }
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   132
        }
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   133
    }
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   134
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   135
    if (defined($str)){
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   136
        if (!defined($opts{'d'})) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   137
            # If not MSDOS, change C: to [/cygdrive]/c/
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   138
            if ($str =~ /^(\S):(.*)$/) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   139
                my $path1 = $1;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   140
                my $path2 = $2;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   141
                $str = $path0 . '/' . $path1 . '/' . $path2;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   142
            }
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   143
        }
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   144
        push (@pieces, $str);
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   145
    }
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   146
}
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   147
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   148
# If input was a PATH, join the pieces back together with $sep2 path
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   149
# separator.
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   150
my $result;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   151
if (scalar(@pieces > 1)) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   152
    $result = join ($sep2, @pieces);
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   153
} else {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   154
    $result = $pieces[0];
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   155
}
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   156
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   157
if (defined ($result)) {
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   158
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   159
    # Change all '\' to '/'
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   160
    $result =~ s/\\/\//g;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   161
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   162
    # Remove duplicate '/'
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   163
    $result =~ s/\/\//\//g;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   164
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   165
    # Map to lower case
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   166
    $result =~ tr/A-Z/a-z/;
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   167
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   168
    print ("$result\n");
2ca7a2522cb4 7152336: Enable builds on Windows with MinGW/MSYS
tbell
parents:
diff changeset
   169
}