# N.B. ===> (3, 4 Mar 2014) This file contains a correction relative to
#           the previous version

# This shows how to use mpost, as used by the feynmp package.
# The feynmp package writes files with extension .mp, e.g., foo.mp,
# and these are to be converted by mpost to make postscript files,
# e.g., foo.1, which are later read in by dvips.
#
# A more complicated custom dependency is needed than normal, because:
# if the output directory ($out_dir) or the auxiliary directory
# ($aux_dir) is set, mpost doesn't put its output in the correct
# place.

add_cus_dep( 'mp', '1', 0, 'mpost' );


sub mpost {
    my $file = $_[0];
    my ($name, $path) =  fileparse( $file );
    my $return = system "mpost \"$file\"";
    # Fix the problem that mpost puts its output and log files
    # in the current directory, not in the auxiliary directory
    # (which is often the same as the output directory):
    move "$name.1", $path;
    move "$name.log", $aux_dir;
    return $return;
}

