#!/usr/bin/perl
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#NAME
#  abc2mkf - ABC to Makefile entry
#
#SYNOPSIS
#  abc2mkf [file]..
#
#REQUIRES
#
#DESCRIPTION
#  This takes a list of .abc files on its command line, and generates Makefile
#  entries for them.  This includes generating both .ps and .pdf files.  
#
#  There are several global variables initialized to the names of the conversion
#  programs.  These may differ on another system than mine.
#
#OPTIONS
#
#EXAMPLES
#
#FILES
#
#BUGS
#
#SEE ALSO
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

$| = 1;
$exitstat = 0;
($P = $0) =~ s".*/"";
$V = $ENV{"V_$P"} || $ENV{"D_$P"} || 2;	# Verbose level.

$abc2ps = 'jcabc2ps';	# ABC-to-PostScript converter
$ps2pdf = 'ps2pdf';		# PostScript-to-PDF converter
$fmtdir = 'fmt/';		# Where .fmt files are kept
$fmt    = '_75';		# Default format file

for $arg (@ARGV) {
	if (($name,$suff) = ($arg =~ m/^(.*)\.(\w+)$/)) {
		print "# $name\n";
		print "$name: $name.abc $name.ps $name.pdf\n";
		print "$name.ps: $name.abc $fmtdir$fmt.fmt\n";
		print "\t$abc2ps +F$fmtdir$fmt $name.abc \\\n";	# Convert .abc to .ps
		print "\t|PShdr '$name' '' '$name' \\\n";		# Header line with name in corners
		print "\t|PSftr %D \$U %D >$name.ps\n";			# Footer line with date and URL
		print "$name.pdf: $name.ps\n";
		print "\t$ps2pdf $name.ps $name.pdf\n";
		print "\n";
	} else {
		print STDERR "$P: ### Can't parse \"$arg\"\n";	# Convert .ps to .pdf
	}
}

print "$P: Exit with status $exitstat.\n" if $V>1;
exit $exitstat;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
