summaryrefslogtreecommitdiff
path: root/web/glasgow/lit2x-0.16/literate/lit-2depend.lprl
blob: b6711cdb109cb271e885bafea126f06e225e1d22 (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
\section[lit2depend_code]{Code used only in generating dependencies}

\begin{code}
sub collect_dependencies {
    local($file_seen) = @_;

    # assuming we're checking dependencies for Input_file "foo.lit"
    # and we've just seen file "bar.lprl" (for example), we want a
    # dependencies of the form:
    #	foo.texi: bar.itxi
    #   foo.tex : bar.itex

    local($file_seen_root,$file_seen_suff) = &root_and_suffix($file_seen);

    if ($Inputfile_root ne $file_seen_root) {
	push(@Depend_lines, "$Inputfile_root.texi : $file_seen_root.itxi\n");
	push(@Depend_lines, "$Inputfile_root.tex  : $file_seen_root.itex\n");
    }
}

sub mangle_Makefile { # insert dependencies into Makefile
    # this really should be made to work just like other mkdepend scripts
    local($Makefile) = 'Makefile';
    local($begin_magic_str) = "# DO NOT DELETE: Beginning of literate-docs dependencies\n";
    local($end_magic_str)   = "# DO NOT DELETE: End of literate-docs dependencies\n";

    unlink("$Makefile.bak");
    rename($Makefile,"$Makefile.bak");
    # now copy Makefile.bak into Makefile, rm'ing old dependencies
    # and adding the new
    open(OMKF,"< $Makefile.bak") || die "$Pgm: can't open $Makefile.bak: $!\n";
    open(NMKF,"> $Makefile") || die "$Pgm: can't open $Makefile: $!\n";
    select(NMKF);
    $_ = <OMKF>;
    while ($_ && $_ ne $begin_magic_str) { # copy through, 'til begin_magic_str
	print $_;
	$_ = <OMKF>;
    }
    while ($_ && $_ ne $end_magic_str) { # delete 'til end_magic_str
	$_ = <OMKF>;
    }
    # insert dependencies
    print $begin_magic_str;
    print @Depend_lines;
    print $end_magic_str;
    while (<OMKF>) { # copy the rest through
	print $_;
    }
    close(NMKF);
    close(OMKF);
    chmod 0444, 'Makefile';
}

# this keeps 'do'ing happy
1;
\end{code}