-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.PL
162 lines (130 loc) · 4.74 KB
/
Makefile.PL
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
#!/usr/bin/perl -w # -*- perl -*-
use strict;
use lib qw( ./lib );
use Config;
use File::Spec::Functions qw( catfile );
use ExtUtils::MakeMaker;
use Cwd;
select STDERR;
$| = 1;
select STDOUT;
our $QUIET = 0;
our $ACCEPT = 0;
our $WIN32 = ($^O eq 'MSWin32');
our $MODVERSION = get_module_version();
#------------------------------------------------------------------------
message(<<EOF);
Template-Plugin-Latex v$MODVERSION
------------------------------
The Template-Latex modules add LaTeX support for the Template Toolkit.
They allow you to create LaTeX documents using the full power of the
Template Toolkit. The generated output can then be processed with
either 'pdflatex' or 'latex'. 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 Template-Latex module you will first need to install LaTeX on
your system and make sure the above programs are available.
EOF
#------------------------------------------------------------------------
if (! find_program($ENV{PATH}, "latex") and ! find_program($ENV{PATH}, "pdflatex")) {
my $continue = ttprompt('You don\'t seem to have LaTeX installed. Continue anyway?', 'N');
die("Aborting as LaTeX is not installed\n") unless uc($continue) =~ /^Y/;
}
#------------------------------------------------------------------------
my %opts = (
'NAME' => 'Template-Plugin-Latex',
'VERSION_FROM' => 'lib/Template/Plugin/Latex.pm',
'PMLIBDIRS' => [ 'lib' ],
'PREREQ_PM' => {
'Template' => 2.16,
'LaTeX::Driver' => 0.07,
'LaTeX::Encode' => 0.02,
'LaTeX::Table' => 0,
},
'dist' => {
'COMPRESS' => 'gzip',
'SUFFIX' => 'gz',
},
'clean' => {
'FILES' => join(' ', qw( t/output/test1.pdf
t/output/test1.ps
t/output/test1.dvi
t/output/test2
t/output/test2.pdf
t/output/test2.ps
t/output/test2.dvi )),
},
);
if ($ExtUtils::MakeMaker::VERSION >= 5.43) {
$opts{ AUTHOR } = 'Andrew Ford <a.ford@ford-mason.co.uk>';
$opts{ ABSTRACT } = 'Latex support for the Template Toolkit',
}
WriteMakefile(%opts);
#------------------------------------------------------------------------
# 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;
}
#------------------------------------------------------------------------
# get_module_version()
#
# Reads the module version from the Template::Plugin::Latex module file
#------------------------------------------------------------------------
sub get_module_version {
if (open(MODULE, catfile('lib','Template','Plugin','Latex.pm'))) {
while (<MODULE>) {
return $1 if /VERSION = "?(\d+\.[\d_]+)/;
}
}
return "<unkown version>";
}