blob: 91053a8a207f5795fd4c00a7652d6881c349d0ab (
plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
package DependencyGenerator;
# ************************************************************
# Description : Runs the correct dependency generator on the file.
# Author : Chad Elliott
# Create Date : 2/10/2002
# ************************************************************
# ************************************************************
# Pragmas
# ************************************************************
use strict;
use FileHandle;
use Preprocessor;
use DependencyWriterFactory;
# ************************************************************
# Subroutine Section
# ************************************************************
sub new {
my($class) = shift;
my($macros) = shift;
my($options) = shift;
my($ipaths) = shift;
my($replace) = shift;
my($type) = shift;
my($self) = bless {'pre' => new Preprocessor($macros,
$options, $ipaths),
'replace' => $replace,
'dwrite' => DependencyWriterFactory::create($type),
'cwd' => undef,
}, $class;
## Set the current working directory, but
## escape regular expression special characters
$self->{'cwd'} = $self->escape_regex_special(Cwd::getcwd()) . '/';
return $self;
}
sub escape_regex_special {
my($self) = shift;
my($name) = shift;
$name =~ s/([\+\-\\\$\[\]\(\)\.])/\\$1/g;
return $name;
}
sub process {
my($self) = shift;
my($file) = shift;
my($objects) = shift;
my($replace) = $self->{'replace'};
my(@repkeys) = keys %$replace;
my($cwd) = $self->{'cwd'};
my(@files) = @{$self->{'pre'}->process($file)};
## Go through each file
foreach my $finc (@files) {
## Remove the current working directory from the front of the
## file. This will help reduce the size of the dependency file.
$finc =~ s/^$cwd//;
## Modify those that have elements for replacement
foreach my $rep (@repkeys) {
if ($finc =~ /^$rep/) {
$finc =~ s/^$rep/$$replace{$rep}/;
last;
}
}
## Remove extra slashes
$finc =~ s/\/\//\\/g;
}
## Sort the dependencies to make them reproducible
@files = sort @files;
## Generate the dependency string
return $self->{'dwrite'}->process($objects, \@files);
}
1;
|