summaryrefslogtreecommitdiff
path: root/web/glasgow/lit2x-0.16/mkworld/jrestoredeps
blob: 510185f7276d00b3a9a73a502e2374f3ccf66607 (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
eval "exec perl -S $0 $*"
     if $running_under_some_random_shell;
#
$Verbose = 0;
if ($ARGV[0] eq '-v') {
    $Verbose++;
    shift(@ARGV);
}
# assuming we've just saved a Makefile as Makefile.bak
# and run "jmake" to make a new Makefile, we now want
# to grab all the old "make depend" stuff from Makefile.bak and
# re-glue it onto the new Makefile.

open(MKF, "< Makefile")	    || die "Can't open Makefile\n";
open(NEW, "> Makefile.new") || die "Can't open Makefile.new\n";
while (<MKF>) {
    # don't go past a "# DO NOT DELETE" line
    last if /^# DO NOT DELETE/;

    # major HACK (to sidestep whitespace kludgery in jmake)
    # IF a Makefile line starts with a tab
    # AND IF it uses a make-variable followed by a backslashed semi-colon,
    # THEN un-backslash the semi-colon.  MEGA-SIGH
    if (/^\t/ && /\$\([A-Z][A-Z_]*\\:/) {
	s/(\$\([A-Z][A-Z_]*)\\:/\1:/g;
    }

    # while here, we may as well tidy up some mess that
    # an ANSI cpp can cause:
    s/\$\(\s*([_A-Z]+)\s\)/\$\(\1\)/g;

    # while we're here, we might as well tidy up any directory names...
    # s|/[^/.][^/]*/\.\.||g;	# nuke: /<dir>/..
    #    s|/\.[^.][^/]*/\.\.||g;	# nuke: /./.. (and others)
    # s| \./| |;

    print NEW $_;
}
close(MKF);

open(BAK, "< Makefile.bak") || exit(0); # die "Can't open Makefile.bak\n";

# skip to "# DO NOT DELETE"
$_ = <BAK>;
while ($_ && ! /^# DO NOT DELETE/ ) {
    $_ = <BAK>;
}
if (! $_) {
    print STDERR "No old dependencies to restore were found in Makefile.bak\n"
	if $Verbose;
} else {
    # copy through "DO NOT DELETE" line
    print NEW $_;

    # copy through the rest
    while (<BAK>) { print NEW $_; }

    close(NEW);
    close(BAK);
}

# now rename Makefile.new to Makefile.
rename('Makefile.new', 'Makefile');