Merge pull request #228 from DOCGroup/jwillemsen-patch-1
[MPC.git] / modules / Depgen / DependencyGenerator.pm
blob77c0eee81f73bc387d016374bb6748412ce8f7e2
1 package DependencyGenerator;
3 # ************************************************************
4 # Description : Runs the correct dependency generator on the file.
5 # Author : Chad Elliott
6 # Create Date : 2/10/2002
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 use Preprocessor;
16 use DependencyWriterFactory;
17 use ObjectGeneratorFactory;
19 # ************************************************************
20 # Subroutine Section
21 # ************************************************************
23 sub new {
24 my($class, $macros, $ipaths, $replace, $type, $noinline, $exclude) = @_;
25 my $self = bless {'pre' => new Preprocessor($macros,
26 $ipaths, $exclude),
27 'replace' => $replace,
28 'dwrite' => DependencyWriterFactory::create($type),
29 'objgen' => ObjectGeneratorFactory::create($type),
30 'noinline' => $noinline,
31 }, $class;
33 ## Set the current working directory, but
34 ## escape regular expression special characters
35 $self->{'cwd'} = Cwd::getcwd() . '/';
36 $self->{'cwd'} =~ s/([\+\-\\\$\[\]\(\)\.])/\\$1/g;
38 ## Sort the replace keys to get the longest key first. This way
39 ## when we are replacing portions of the file path, we replace the
40 ## most we can.
41 my @repkeys = sort { length($b) <=> length($a) } keys %$replace;
42 $self->{'repkeys'} = \@repkeys;
44 return $self;
48 sub process {
49 my($self, $file) = @_;
51 ## Generate the dependency string
52 my $depstr = $self->{'dwrite'}->process(
53 $self->{'objgen'}->process($file),
54 $self->{'pre'}->process($file, $self->{'noinline'}));
56 ## Perform the replacements on the dependency string
57 $depstr =~ s/$self->{'cwd'}//go;
58 my $replace = $self->{'replace'};
59 foreach my $rep (@{$self->{'repkeys'}}) {
60 $depstr =~ s/$rep/$$replace{$rep}/g;
63 return $depstr;