pack_dep_gcc.pl
1.21 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use strict;
if ($#ARGV != 2)
{
print "pack_dep_gcc.pl output_filename dep_input_dir src_input_dir\n";
die "DIE\n";
}
my $fileOut = shift @ARGV;
my $depDir = shift @ARGV;
my $curDir = shift @ARGV;
my $depContent;
opendir DIRHANDLE, "$depDir" or die "Cannot open dir $depDir: $!";
foreach my $file (readdir DIRHANDLE)
{
next if (($file eq ".") || ($file eq ".."));
if ($file =~ /\.d$/i)
{
ParseDep(\$depContent, "$depDir\\$file");
}
}
closedir DIRHANDLE;
open OUTPUTHANDLE, ">$fileOut" or die "Cannot write $fileOut\n";
print OUTPUTHANDLE "$depContent";
close OUTPUTHANDLE;
sub ParseDep
{
my $refContent = shift @_;
my $fileInput = shift @_;
my $Backup = $/;
undef $/;
open INPUTHANDLE, "<$fileInput" or die "Cannot open file $fileInput\n";
my $fileContent = <INPUTHANDLE>;
close INPUTHANDLE;
$/ = $Backup;
$fileContent =~ s/\\\n//gs;
$fileContent =~ s/\//\\/gs;
my @fileList = split(/\s+/, $fileContent);
$fileList[0] =~ s/(\S*\\)?(\S+?)\.(o|obj)\:/$2.obj\:/i;
$$refContent .= $fileList[0];
my $index;
for($index=1; $index <= $#fileList; $index++)
{
my $line = " $curDir\\" . $fileList[$index];
if ($index < $#fileList)
{
$$refContent .= "$line \\\n";
}
else
{
$$refContent .= "$line\n";
}
}
}