bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / build / fixwin32mak.pl
1 #
2 # fixwin32mak.pl ::: Apache/Win32 maintanace program
3 #
4 # This program, launched from the build/ directory, replaces all nasty absoulute paths
5 # in the win32 .mak files with the appropriate relative root.
6 #
7 # Run this program prior to committing or packaging any newly exported make files.
8
9 use Cwd;
10 use IO::File;
11 use File::Find;
12
13 $root = cwd;
14 # ignore our own direcory (allowing us to move into any parallel tree)
15 $root =~ s|^.:(.*)?$|cd "$1|;
16 $root =~ s|/|\\\\|g;
17 $altroot = $root;
18 $altroot =~ s| ".:| "|;
19 print "Stripping " . $root . " and " . $altroot . "\n";
20 find(\&fixcwd, '.');
21
22 sub fixcwd { 
23     if (m|.mak$|) {
24         $thisroot = $File::Find::dir;
25         $thisroot =~ s|^./(.*)$|$1|;
26         $thisroot =~ s|/|\\\\|g;
27         $thisroot = $root . "\\\\" . $thisroot;
28         $thisaltroot = $altroot . "\\\\" . $thisroot;
29         $oname = $_;
30         $tname = '.#' . $_;
31         $verchg = 0;
32         $srcfl = new IO::File $_, "r" || die;
33         $dstfl = new IO::File $tname, "w" || die;
34         while ($src = <$srcfl>) {
35             if ($src =~ m|^\s*($root[^\"]*)\".*$|) {
36                 $orig = $thisroot;
37             } elsif ($src =~ m|^\s*($altroot[^\"]*)\".*$|) {
38                 $orig = $thisaltroot;
39             }
40             if (defined($orig)) {
41                 $repl = "cd \".";
42                 while (!($src =~ s|$orig|$repl|)) {
43                    if (!($orig =~ s|^(.*)\\\\[^\\]+$|$1|)) {
44                        break;
45                    }
46                    $repl .= "\\..";
47                 }
48                 print "Replaced " . $orig . " with " . $repl . "\n";
49                 $verchg = -1;
50                 undef $orig;
51             }
52             print $dstfl $src; 
53         }
54         undef $srcfl;
55         undef $dstfl;
56         if ($verchg) {
57             unlink $oname || die;
58             rename $tname, $oname || die;
59             print "Corrected absolute paths within " . $oname . " in " . $File::Find::dir . "\n"; 
60         }
61         else {
62             unlink $tname;
63         }
64         $dname = $oname;
65         $dname =~ s/.mak$/.dsp/;
66         @dstat = stat($dname);
67         @ostat = stat($oname);    
68         if ($ostat[9] && $dstat[9] && ($ostat[9] != $dstat[9])) {
69             @onames = ($oname);
70             utime $dstat[9], $dstat[9], @onames;
71             print "Touched datestamp for " . $oname . " in " . $File::Find::dir . "\n"; 
72         }
73         $oname =~ s/.mak$/.dep/;
74         @ostat = stat($oname);    
75         if ($ostat[9] && $dstat[9] && ($ostat[9] != $dstat[9])) {
76             @onames = ($oname);
77             utime $dstat[9], $dstat[9], @onames;
78             print "Touched datestamp for " . $oname . " in " . $File::Find::dir . "\n"; 
79         }
80     }
81 }