ChainMake

 view release on metacpan or  search on metacpan

example/example-latex.pl  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use lib '..';
use ChainMake::Functions ':all';

target 'example.tex', (
    timestamps   => ['$t_name'],
    handler => sub {
        my $t_name=shift;
        open OUT,">",$t_name or print "Can't write $t_name: $!" && return 0;
        print OUT get_tex();
        close OUT;
        1;
    }
);

target 'example.dvi', (
    timestamps   => ['$t_name'],
    requirements => ['$t_base.tex'],
    handler => sub {
        my ($t_name,$t_base,$t_ext)=@_;
        my $rerun=1;
        my ($multiply_defined_labels,$undefined_references,$font_shapes_not_available);
        while ($rerun) {
	        print "> latex -interaction=batchmode $t_base.tex\n";
	        $rerun=0;
	        $multiply_defined_labels=0;
	        my $output=`latex $t_base.tex`;
            $rerun=1 if ($output =~ /LaTeX Warning: Label\(s\) may have changed/);
	        $multiply_defined_labels=1 if ($output =~ /LaTeX Warning: There were multiply-defined labels/);
	        $undefined_references=1 if ($output =~ /LaTeX Warning: There were undefined references/);
	        $font_shapes_not_available=1 if ($output =~ /LaTeX Font Warning: Some font shapes were not available/)
        }
        print STDOUT "Warning: There were undefined references.\n" if ($undefined_references);
        print STDOUT "Warning: Some font shapes were not available.\n" if ($font_shapes_not_available);
        print STDOUT "Warning: Multiply-defined labels.\n" if ($multiply_defined_labels);
        1;
    }
);

target ['example.ps','another.ps'], (
    timestamps   => ['$t_name'],
    requirements => ['$t_base.dvi'],
    handler => sub {
        my ($t_name,$t_base,$t_ext)=@_;
        execute_system(
            All => "dvips -P pdf -q -t a5 $t_base.dvi",
        );
    }
);

target qr/^[^\.]+\.pdf$/, (
    timestamps   => ['$t_name'],
    requirements => ['$t_base.ps'],
    handler => sub {
        my ($t_name,$t_base,$t_ext)=@_;
        execute_system(
            All => "ps2pdf $t_base.ps $t_base.pdf",
        );
    }
);

target 'clean', (
    handler => sub {
        unlink qw/example.tex example.aux example.dvi example.log/;
        1;
    }
);

target 'realclean', (
    requirements => ['clean'],
    handler => sub {
        unlink qw/example.pdf example.ps/;
        1;
    }
);

target [qw/all All/], requirements => ['example.pdf','clean'];

chainmake(@ARGV);


sub get_tex { <<'LATEX'
\documentclass[10pt,a5paper]{scrbook}        % oder was auch immer
\usepackage{ngerman}



( run in 2.522 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )