1 package DependencyEditor
;
3 # ************************************************************
4 # Description : Edits existing dependencies.
5 # Author : Chad Elliott
6 # Create Date : 2/10/2002
7 # ************************************************************
9 # ************************************************************
11 # ************************************************************
16 use DependencyGenerator
;
18 # ************************************************************
20 # ************************************************************
23 return bless {}, $_[0];
28 my($self, $output, $type, $noinline, $macros,
29 $ipaths, $replace, $exclude, $files,
32 ## Back up the original file and receive the contents
36 if (!$self->backup($output, $contents, $append)) {
37 print STDERR
"ERROR: Unable to backup $output\n";
42 ## Write out the contents of the file
43 my $fh = new FileHandle
();
44 if (open($fh, ">$output")) {
45 if (defined $contents) {
46 foreach my $line (@
$contents) {
52 ## Write out the new dependency marker
53 print $fh "# DO NOT DELETE THIS LINE -- depgen.pl uses it.\n",
54 "# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.\n\n";
57 ## Write start append comment
58 print $fh "# DO NOT DELETE THIS LINE -- depgen.pl appended ",
60 "# APPENDED DEPENDENCY RULES " ,
64 ## Generate the new dependencies and write them to the file
65 my $dep = new DependencyGenerator
($macros, $ipaths, $replace,
69 ## Sort the files so the dependencies are reproducible
70 foreach my $file (sort @
$files) {
71 ## In some situations we may be passed a directory as part of an
72 ## option. If it is an unknown option, we may think the directory
73 ## needs to be part of the dependencies when it should not.
74 print $fh $dep->process($file), "\n" if (!-d
$file);
77 ## Write out the end of the block warning
78 print $fh "# IF YOU PUT ANYTHING HERE IT WILL GO AWAY\n";
82 print STDERR
"ERROR: Unable to open $output for output\n";
91 my($self, $source, $contents, $append) = @_;
93 my $fh = new FileHandle
();
94 my $backup = "$source.bak";
96 ## Back up the file. While doing so, keep track of the contents of the
97 ## file and keep everything except the old dependencies or keep
98 ## everything if appending.
101 $search_string = 'DO NOT DELETE';
104 $search_string = 'IF YOU PUT ANYTHING HERE IT WILL GO AWAY';
107 if (open($fh, $source)) {
108 my $oh = new FileHandle
();
109 if (open($oh, ">$backup")) {
115 if (index($_, $search_string) >= 0) {
119 push(@
$contents, $_);
125 ## Set file permission so that the backup has the same permissions
126 ## as the original file.
127 my @buf = stat($source);
128 if (defined $buf[8] && defined $buf[9]) {
129 utime($buf[8], $buf[9], $backup);