File: Makefile.PL

package info (click to toggle)
liblatex-driver-perl 0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 432 kB
  • sloc: perl: 1,242; makefile: 4
file content (190 lines) | stat: -rw-r--r-- 6,244 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/perl -w                                         # -*- perl -*-

use strict;

use Config;
use File::Spec::Functions qw( catfile );
use ExtUtils::MakeMaker;
use Cwd;

select STDERR;
$| = 1;
select STDOUT;

our $QUIET  = 0;
our $ACCEPT = 1;
our $WIN32  = ($^O eq 'MSWin32');
our $MODVERSION = sprintf("%.2f", get_module_version());

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

message(<<EOF);

LaTeX::Driver v$MODVERSION
-------------------

LaTeX::Driver runs either the 'latex' or 'pdflatex' command on a LaTeX
document.  If unresolved cross references, bibliographic references or
index definitions are found then 'bibtex' or 'makeindex' will be run
as appropriate and 'latex' or 'pdflatex' re-run as necessary.  The
output will be postprocessed with the 'dvips' and 'ps2pdf' programs if
necessary to create PDF, DVI or PostScript documents.

To use the module you will first need to install LaTeX on your system
and make sure the above programs are available.  Answer the following
questions to confirm their locations, then run 'make', 'make test' and
'make install'.

EOF

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

our $LATEX     = ttprompt('latex path',     find_program($ENV{PATH}, "latex"));
our $PDFLATEX  = ttprompt('pdflatex path',  find_program($ENV{PATH}, "pdflatex"));
our $BIBTEX    = ttprompt('bibtex path',    find_program($ENV{PATH}, "bibtex"));
our $MAKEINDEX = ttprompt('makeindex path', find_program($ENV{PATH}, "makeindex"));
our $DVIPS     = ttprompt('dvips path',     find_program($ENV{PATH}, "dvips"));
our $DVIPDFM   = ttprompt('dvipdfm path',   find_program($ENV{PATH}, "dvipdfm"));
our $PS2PDF    = ttprompt('ps2pdf path',    find_program($ENV{PATH}, "ps2pdf"));
our $PDF2PS    = ttprompt('pdf2ps path',    find_program($ENV{PATH}, "pdf2ps"));

if (!$LATEX and !$PDFLATEX) {
    my $continue = ttprompt('You don\'t seem to have LaTeX installed.  Continue anyway?', 'N');
    warn("Aborting as LaTeX is not installed\n"), exit(0) unless uc($continue) =~ /^Y/;
}

fix_path_assignment(catfile('lib','LaTeX','Driver','Paths.pm'), 'latex',     $LATEX);
fix_path_assignment(catfile('lib','LaTeX','Driver','Paths.pm'), 'pdflatex',  $PDFLATEX);
fix_path_assignment(catfile('lib','LaTeX','Driver','Paths.pm'), 'bibtex',    $BIBTEX);
fix_path_assignment(catfile('lib','LaTeX','Driver','Paths.pm'), 'makeindex', $MAKEINDEX);
fix_path_assignment(catfile('lib','LaTeX','Driver','Paths.pm'), 'dvips',     $DVIPS);
fix_path_assignment(catfile('lib','LaTeX','Driver','Paths.pm'), 'dvipdfm',   $DVIPDFM);
fix_path_assignment(catfile('lib','LaTeX','Driver','Paths.pm'), 'ps2pdf',    $PS2PDF);
fix_path_assignment(catfile('lib','LaTeX','Driver','Paths.pm'), 'ps2pdf',    $PDF2PS);

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

my %opts = (
    'NAME'         => 'LaTeX-Driver',
    'VERSION'      => $MODVERSION,
    'EXE_FILES'    => [ 'scripts/latex2dvi', 'scripts/latex2pdf', 'scripts/latex2ps' ],
    'PMLIBDIRS'    => [ 'lib' ], 
    'PREREQ_PM'    => { 
	'Class::Accessor'  => 0,
	'Cwd'              => 0,
	'Exception::Class' => 0,
	'File::Slurp'      => 0,
	'File::Spec'       => 0,
	'IO::File'         => 0,
    },
    'dist'         => {
        'COMPRESS' => 'gzip',
        'SUFFIX'   => 'gz',
    },
);

if ($ExtUtils::MakeMaker::VERSION >= 5.43) {
    $opts{ AUTHOR   } = 'Andrew Ford <a.ford@ford-mason.co.uk>';
    $opts{ ABSTRACT } = 'LaTeX Driver',
}

WriteMakefile(%opts);


#------------------------------------------------------------------------
# fix_assignment($file, $find, $fix)
#
# Fixes a variable definition in a file.  e.g. 
# fix_path_assignment('lib/LaTeX/Driver/Paths.pm', '$LATEX', '/path/to/latex')
#------------------------------------------------------------------------

sub fix_path_assignment {
    my ($file, $find, $fix) = @_;
    local *FP;
    local $/ = undef;

    $find = quotemeta($find);

    open(FP, "< $file") || die "$file: $!\n";
    my $text = <FP>;
    close(FP);

    ($text =~ s/^(\s*\$program_path\{\s*${find}\s*\}\s*=\s*)'.*?'/$1'$fix'/m)
    	|| die "$find not found in $file\n";

    open(FP, "> $file") || die "$file: $!\n";
    print FP $text;
    close(FP);
}


#------------------------------------------------------------------------
# find_program($path, $prog)
#
# Find a program, $prog, by traversing the given directory path, $path.
# Returns full path if the program is found.
#
# Written by Craig Barratt, Richard Tietjen add fixes for Win32.
#
# abw changed name from studly caps findProgram() to find_program() :-)
#------------------------------------------------------------------------

sub find_program {
    my($path, $prog) = @_;

    foreach my $dir ( split($Config{path_sep}, $path) ) {
        my $file = File::Spec->catfile($dir, $prog);
        if ( !$WIN32 ) {
            return $file if ( -x $file );
        } else {
            # Windows executables end in .xxx, exe precedes .bat and .cmd
            foreach my $dx ( qw/exe bat cmd/ ) {
                return "$file.$dx" if ( -x "$file.$dx" );
            }
        }
    }
}


#------------------------------------------------------------------------
# message($text)
#
# Print message unless quiet mode.
#------------------------------------------------------------------------

sub message {
    return if $QUIET;
    print @_;
}


#------------------------------------------------------------------------
# ttprompt($message, $default)
#------------------------------------------------------------------------

sub ttprompt {
    my ($msg, $def)=@_;
    my $ISA_TTY = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)) ; # Pipe?
    my $dispdef = defined $def ? "[$def] " : " ";
    $def = defined $def ? $def : "";
    my $ans = '';
    local $|=1;
    print "$msg $dispdef" unless $QUIET;
    if ($ACCEPT || ! $ISA_TTY) {
        print "$def\n" unless $QUIET;
    }
    else {
        chomp($ans = <STDIN>);
    }
    return ($ans ne '') ? $ans : $def;
}


sub get_module_version {
    open(MODULE, catfile('lib','LaTeX','Driver.pm'))
	or die "cannot find LaTeX::Driver module\n";
    while (<MODULE>) {
	return $1 if /VERSION = (\d+\.\d+)/;
    }
    return "<unkown version>";
}