summaryrefslogtreecommitdiff
path: root/build/fixwin32mak.pl
blob: c3f6acf86b86a25581132ee63f46775a905ace52 (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
#
# fixwin32mak.pl ::: Apache/Win32 maintanace program
#
# This program, launched from the build/ directory, replaces all nasty absoulute paths
# in the win32 .mak files with the appropriate relative root.
#
# Run this program prior to committing or packaging any newly exported make files.

use Cwd;
use IO::File;
use File::Find;

$root = cwd;
# ignore our own direcory (allowing us to move into any parallel tree)
$root =~ s|^.:(.*)/.*?$|cd "$1|;
$root =~ s|/|\\\\|g;
print "Testing " . $root . "\n";
find(\&fixcwd, '.');

sub fixcwd { 
    if (m|.mak$|) {
# note repl is broken... isn't freindly to directories with periods.
	$repl = $File::Find::dir;
# replace ./ with the parent (moving into any parallel tree)
        $repl =~ s|^\./|../|;
# replace each directory in this path with .. to get back to our root
        $repl =~ s|[^/]+|..|g;
        $repl =~ s|/|\\|;
        $oname = $_;
	$tname = '.#' . $_;
	$verchg = 0;
print "Processing " . $_ . "\n";
	$srcfl = new IO::File $_, "r" || die;
	$dstfl = new IO::File $tname, "w" || die;
	while ($src = <$srcfl>) {
	    if ($src =~ s|^(\s*)$root|$1cd "$repl|) {
		$verchg = -1;
	    }
            print $dstfl $src; 
	}
	undef $srcfl;
	undef $dstfl;
	if ($verchg) {
	    unlink $oname || die;
	    rename $tname, $oname || die;
	    print "Corrected absolute paths within " . $oname . " in " . $File::Find::dir . "\n"; 
	}
	else {
	    unlink $tname;
	}
        $dname = $oname;
        $dname =~ s/.mak$/.dsp/;
	@dstat = stat($dname);
        @ostat = stat($oname);    
        if ($ostat[9] != $dstat[9]) {
            @onames = ($oname);
            utime $dstat[9], $dstat[9], @onames;
	    print "Touched datestamp for " . $oname . " in " . $File::Find::dir . "\n"; 
        }
        $oname =~ s/.mak$/.dep/;
        @ostat = stat($oname);    
        if ($ostat[9] != $dstat[9]) {
            @onames = ($oname);
            utime $dstat[9], $dstat[9], @onames;
	    print "Touched datestamp for " . $oname . " in " . $File::Find::dir . "\n"; 
        }
    }
}