package Facts; Filepp::AddKeyword('inc', \&Inc); Filepp::AddKeyword('header', \&Header); Filepp::AddKeyword('footer', \&Footer); sub Inc { my $include_file = shift; my $filename = Filepp::ReplaceDefines("__FILE__"); # Get current filename. my $found = 0; # Did we find a corresponding line? my $changed = 0; # Did we change anything? $filename =~ s/.in$//g; # Write a blank line to the output file. Filepp::Write("\n"); # Open Makefile in the current directory. open MAKEFILE, "; close MAKEFILE; # Find an all: line and add this file to that line if it isn't there. for (@lines) { if (/^all:/ and !(/\b$filename\b/)) { $changed = 1; s/$/ $filename/; } } my $found = 0; # Find the line corresponding to this file (if it's there) # and add this filename to it if it isn't there. for (@lines) { $found = 1 if /^$filename:/; if (/^$filename:/ and !(/\b$include_file\b/)) { $changed = 1; s/$/ $include_file/; } } # Add the filename to the Makefile if it wasn't found. unless ($found) { $changed = 1; push @lines, "$filename: $filename.in $include_file\n"; push @lines, "\tfilepp $filename.in > $filename\n"; } # If anything changed, re-write the lines. if ($changed) { open MAKEFILE, ">Makefile"; print MAKEFILE @lines; close MAKEFILE; } # Now include the file. Filepp::Include(qq/"$include_file"/); } sub Header { my $topic = shift; $topic =~ s/"//g; Filepp::Write( qq@ Interesting Facts - $topic

$topic

@) ; } sub Footer { Filepp::Write( qq@ @) ; } 1;