summary refs log tree commit diff
path: root/pkgs/build-support/mono-dll-fixer/dll-fixer.pl
blob: 4a8b468692f0c49fa8455ef87db8c673091062d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! @perl@ -w

use strict;

my @paths = split ' ', $ENV{"ALL_INPUTS"};

open IN, "<$ARGV[0]" or die;
open OUT, ">$ARGV[0].tmp" or die;

while (<IN>) {
    # !!! should use a real XML library here.
    if (!/<dllmap dll="(.*)" target="(.*)"\/>/) {
        print OUT;
        next;
    }
    my $dll = $1;
    my $target = $2;

    foreach my $path (@paths) {
        my $fullPath = "$path/lib/$target";
        if (-e "$fullPath") {
            $target = $fullPath;
            last;
        }
    }

    print OUT "  <dllmap dll=\"$dll\" target=\"$target\"/>\n";
}

close IN;

rename "$ARGV[0].tmp", "$ARGV[0]" or die "cannot rename $ARGV[0]";