Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 1030 lines (803 sloc) 29.281 kB
a4123f8 @abw 2.04b
authored
1 #!/usr/bin/perl -w # -*- perl -*-
2
3 use strict;
4
5 use lib qw( ./lib );
6 use Template;
7 use ExtUtils::MakeMaker;
c8d76d4 @abw *** empty log message ***
authored
8 use Cwd;
3ebfa07 @abw Initial revision
authored
9
e39913f @abw *** empty log message ***
authored
10 select STDERR;
11 $| = 1;
12 select STDOUT;
13
a4123f8 @abw 2.04b
authored
14 use vars qw( $TT_VERSION $TT_PREFIX $TT_IMAGES $TT_RUN_DBI
ca4050f @abw prep for 2.02
authored
15 $TT_BUILD_DOCS $TT_SPLASH_DOCS $TT_EXAMPLES
a4123f8 @abw 2.04b
authored
16 $TT_LATEX_ENABLE $TT_LATEX_PATH $TT_PDFLATEX_PATH $TT_DVIPS_PATH
17 $TT_SPLASH_THEME $TT_QUIET $TT_ACCEPT $TT_YES );
18
19 # check O/S to set sensible defaults
20 my ($WIN32, $FLAVOUR, $PREFIX, $MAKE);
21 if ($^O =~ /win/i) {
22 $WIN32 = 1;
23 $FLAVOUR = 'Win32';
24 $PREFIX = 'C:/Program Files/Template Toolkit 2';
25 $MAKE = 'nmake';
26 }
27 else {
28 $WIN32 = 0;
29 $FLAVOUR = 'Unix';
30 $PREFIX = '/usr/local/tt2';
31 $MAKE = 'make';
32 }
33
34 # read command line args
35 my (%config, %ttconfig);
36 while ($_ = shift) {
37 my ($k, $v) = split(/=/);
38 if ($k =~ /^TT/) {
39 $ttconfig{ $k } = $v || 0;
40 }
41 else {
42 $config{ $k } = $v || 0;
43 }
44 };
45
46 if (exists $ttconfig{ TT_HELP }) {
47 print <<EOF;
48 The following options can be specified as command line
49 arguments to 'perl Makefile.PL'. e.g.
50
51 perl Makefile.PL TT_PREFIX=/my/tt2/dir TT_ACCEPT=y
52
53 TT_PREFIX installation prefix ($PREFIX)
54 TT_IMAGES images URL (/tt2/images)
55 TT_DOCS build HTML docs (y)
56 TT_SPLASH use Splash! for docs (y)
57 TT_THEME Splash! theme (default)
58 TT_EXAMPLES build HTML examples (y)
59 TT_DBI run DBI tests (y if DBI installed)
60 TT_LATEX install LaTeX filter (y if LaTeX found)
61 TT_QUIET no messages (n)
62 TT_ACCEPT accept defaults (n)
63
64 By default, the Makefile.PL runs in interactive mode,
65 prompting for confirmation of the various configuration
66 options. Setting the TT_ACCEPT option causes the default
67 value (possibly modified by other command line options)
68 to be accepted. The TT_QUIET option can also be set to
69 suppress the prompt messages.
70
71 EOF
72 exit(0);
73 }
ca4050f @abw prep for 2.02
authored
74
a4123f8 @abw 2.04b
authored
75 $TT_VERSION = $Template::VERSION;
76 $TT_PREFIX = $PREFIX;
f4df3b6 @abw approach v2.03
authored
77 $TT_IMAGES = '/tt2/images';
78 $TT_RUN_DBI = 'y';
79 $TT_BUILD_DOCS = 'y';
80 $TT_SPLASH_DOCS = 'y';
81 $TT_EXAMPLES = 'y';
82 $TT_SPLASH_THEME = 'default';
a4123f8 @abw 2.04b
authored
83 $TT_LATEX_ENABLE = 'y';
84 $TT_QUIET = 'n';
85 $TT_ACCEPT = 'n';
f4df3b6 @abw approach v2.03
authored
86
ca4050f @abw prep for 2.02
authored
87 my $TT_SPLASH_FG = '';
88 my $TT_SPLASH_BG = '';
89
90 my $DEFAULTS_FILE = '.defaults.cfg';
48634a1 @abw *** empty log message ***
authored
91 my $DBI_CONFIG_FILE = 't/dbi_test.cfg';
c8d76d4 @abw *** empty log message ***
authored
92 my $TT_DOCS_CFG = 'docs/ttree.cfg';
93 my $TT_EXAMPLE_CFG = 'examples/ttree.cfg';
ca4050f @abw prep for 2.02
authored
94 my $DEFAULTS = '';
911a5e3 @abw *** empty log message ***
authored
95
ca4050f @abw prep for 2.02
authored
96 if (-f $DEFAULTS_FILE) {
97 require $DEFAULTS_FILE;
98 $DEFAULTS = " read from '$DEFAULTS_FILE'";
99 }
100
a4123f8 @abw 2.04b
authored
101 $TT_PREFIX = $ttconfig{ TT_PREFIX } if defined $ttconfig{ TT_PREFIX };
102 $TT_IMAGES = $ttconfig{ TT_IMAGES } if defined $ttconfig{ TT_IMAGES };
103 $TT_RUN_DBI = $ttconfig{ TT_DBI } if defined $ttconfig{ TT_DBI };
104 $TT_BUILD_DOCS = $ttconfig{ TT_DOCS } if defined $ttconfig{ TT_DOCS };
105 $TT_SPLASH_DOCS = $ttconfig{ TT_SPLASH } if defined $ttconfig{ TT_SPLASH };
106 $TT_EXAMPLES = $ttconfig{ TT_EXAMPLES } if defined $ttconfig{ TT_EXAMPLES };
107 $TT_SPLASH_THEME = $ttconfig{ TT_THEME } if defined $ttconfig{ TT_THEME };
108 $TT_LATEX_ENABLE = $ttconfig{ TT_LATEX } if defined $ttconfig{ TT_LATEX };
109 $TT_QUIET = $ttconfig{ TT_QUIET } if defined $ttconfig{ TT_QUIET };
110 $TT_ACCEPT = $ttconfig{ TT_ACCEPT } if defined $ttconfig{ TT_ACCEPT };
111
112 foreach ($TT_RUN_DBI, $TT_BUILD_DOCS, $TT_SPLASH_DOCS, $TT_EXAMPLES, $TT_LATEX_ENABLE) {
113 $_ = 'n' if ! $_;
114 }
115 $TT_ACCEPT = 0 if $TT_ACCEPT eq 'n';
116 $TT_QUIET = 0 if $TT_QUIET eq 'n';
117 $TT_QUIET = 0 unless $TT_ACCEPT;
118
ca4050f @abw prep for 2.02
authored
119 my $SPLASH_STYLES = {
120 default => [ 'lilac', 'mauve' ],
121 aqua => [ 'aqua', 'marine' ],
122 grey => [ 'grey75', 'grey50' ],
123 blue => [ 'grey75', 'blue75' ],
124 red => [ 'grey75', 'red75' ],
125 green => [ 'grey75', 'green75' ],
126 };
127
c542301 @abw *** empty log message ***
authored
128
a4123f8 @abw 2.04b
authored
129 #========================================================================
130
131 welcome_message();
132 version_check();
133 mandatory_modules();
134 optional_modules();
135 optional_latex();
136 optional_extras();
137 splash_images();
138 html_docs();
139 html_docstyle();
140 html_examples();
141 write_defaults();
142
143 print "\n";
144
145
146 #------------------------------------------------------------------------
147 # build options and write Makefile
148 #------------------------------------------------------------------------
149
150 package MY;
151
152 sub postamble {
153 return '' unless $main::TT_PREFIX;
154 my $amble =<<'EOF';
155 tt2_install ::
156 @$(PERL) bin/tt2inst -v "$(TT_PREFIX)"
157
158 tt2_splash ::
159 @$(PERL) -I lib bin/gifsplash -v
160
161 EOF
162 $amble .=<<EOF if $main::TT_BUILD_DOCS;
163 tt2_html_docs ::
164 \@\$(PERL) bin/ttree -v -f "\$(TT_PREFIX)/$TT_DOCS_CFG"
165
166 EOF
167 $amble .=<<EOF if $main::TT_EXAMPLES;
168 tt2_examples ::
169 \@\$(PERL) bin/ttree -v -f "\$(TT_PREFIX)/$TT_EXAMPLE_CFG"
170
171 EOF
172 return $amble;
173 }
174
175 sub install {
176 my $class = shift;
177 my $basic = $class->SUPER::install(@_);
178 my $add = 'tt2_install tt2_splash';
179 $add .= ' tt2_html_docs' if $main::TT_BUILD_DOCS;
180 $add .= ' tt2_examples' if $main::TT_EXAMPLES;
181 $basic =~ s/^(install\s+::\s+.*)$/$1 $add/m
182 if $main::TT_PREFIX;
183 $basic;
184 }
185
186 sub constants {
187 my $class = shift;
188 my $basic = $class->SUPER::constants(@_);
189 $basic = "TT_PREFIX = $main::TT_PREFIX\n$basic"
190 if $main::TT_PREFIX;
191 $basic;
192 }
193
194 package main;
195
196 my %opts = (
197 %config,
198 'NAME' => 'Template',
199 'DISTNAME' => 'Template-Toolkit',
200 'VERSION_FROM' => 'lib/Template.pm',
201 'EXE_FILES' => [ 'bin/tpage', 'bin/ttree' ],
202 'PMLIBDIRS' => [ 'lib' ],
203 'PREREQ_PM' => { 'AppConfig' => 1.52 },
204 'dist' => {
205 'COMPRESS' => 'gzip',
206 'SUFFIX' => 'gz',
207 # 'PREOP' => build_docs(),
208 },
209 );
210
211 if ($ExtUtils::MakeMaker::VERSION >= 5.43) {
212 $opts{ AUTHOR } = 'Andy Wardley <abw@kfs.org>';
213 $opts{ ABSTRACT } =
214 'a fast, flexible and extensible template processing system',
215 }
216
217
218 WriteMakefile( %opts );
219
220 if ($WIN32) {
221 print <<EOF;
222
223 Configuration complete. You should now run '$MAKE', '$MAKE test' and
224 then '$MAKE install'. See the README file for further information.
225 EOF
226 }
227
228 message(<<EOF) if $TT_BUILD_DOCS;
229
230 Please note that the installation of the optional components and
231 building of the HTML documentation is performed at the "make install"
232 stage as the effective user at that time. This implies that this user
233 must have sufficient permission to install into the specified
234 directory and that all created directories and files will be owned by
235 them.
236
237 EOF
238
239 #========================================================================
240
241
242
243 #------------------------------------------------------------------------
244 # welcome_message()
245 #
246 # Print opening banner.
247 #------------------------------------------------------------------------
248
249 sub welcome_message {
250 print(<<EOF);
251
252 Template Toolkit Version $TT_VERSION
c542301 @abw *** empty log message ***
authored
253 =============================
911a5e3 @abw *** empty log message ***
authored
254
ca4050f @abw prep for 2.02
authored
255 Using $FLAVOUR defaults$DEFAULTS.
48634a1 @abw *** empty log message ***
authored
256 EOF
a4123f8 @abw 2.04b
authored
257 print "Messages suppressed (TT_QUIET). " if $TT_QUIET;
258 print "Accepting defaults automatically (TT_ACCEPT)." if $TT_ACCEPT;
259 print "\nRun 'perl Makefile.PL TT_HELP' for further info.\n"
260 if $TT_QUIET || $TT_ACCEPT;
261 }
262
263
48634a1 @abw *** empty log message ***
authored
264
265 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
266 # version_check()
267 #
268 # Check for pre-version 2.00 installation and issue warning
48634a1 @abw *** empty log message ***
authored
269 #------------------------------------------------------------------------
270
a4123f8 @abw 2.04b
authored
271 sub version_check {
272 eval "use Template";
273 unless ($@ or $Template::VERSION =~ /^2/) {
274 warn(<<EOF) unless $TT_QUIET;
48634a1 @abw *** empty log message ***
authored
275
c542301 @abw *** empty log message ***
authored
276 IMPORTANT NOTE:
a4123f8 @abw 2.04b
authored
277
48634a1 @abw *** empty log message ***
authored
278 You have version $Template::VERSION of the Template Toolkit installed.
25a8d8e @abw *** empty log message ***
authored
279
82cbea8 @abw version 2.00
authored
280 There are some minor incompatabilities between version 1 and 2
48634a1 @abw *** empty log message ***
authored
281 of the Template Toolkit which you should be aware of. Installing
282 this version will overwrite your version $Template::VERSION files
283 unless you take measures to install one or the other version in a
82cbea8 @abw version 2.00
authored
284 different location (i.e. perl Makefile.PL PREFIX=/other/path).
48634a1 @abw *** empty log message ***
authored
285
286 Please consult the README and Changes file for further details.
287 Most of the changes are in the more obscure features and
288 directives so hopefully you will find the upgrade process fairly
289 painless.
25a8d8e @abw *** empty log message ***
authored
290
291 EOF
a4123f8 @abw 2.04b
authored
292 exit unless ttprompt("Do you want to continue?", 'y') =~ /y/i;
293 }
48634a1 @abw *** empty log message ***
authored
294 }
295
a4123f8 @abw 2.04b
authored
296
48634a1 @abw *** empty log message ***
authored
297 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
298 # mandatory_modules()
299 #
300 # Detect mandatory module
c8d76d4 @abw *** empty log message ***
authored
301 #------------------------------------------------------------------------
302
a4123f8 @abw 2.04b
authored
303 sub mandatory_modules {
304 eval "use AppConfig";
305 if ($@ or $AppConfig::VERSION < 1.52) {
306 die(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
307
308 The Template Toolkit requires that the AppConfig module (version 1.52
309 or later) first be installed. This is used by the 'ttree' program for
310 reading command line options and configuration files. It is available
311 from CPAN:
312
313 http://www.cpan.org/authors/Andy_Wardley/
314
315 EOF
a4123f8 @abw 2.04b
authored
316 }
c8d76d4 @abw *** empty log message ***
authored
317
a4123f8 @abw 2.04b
authored
318 eval "use File::Spec";
319 if ($@ or $File::Spec::VERSION < 0.6) {
320 die(<<EOF);
911a5e3 @abw *** empty log message ***
authored
321
f4df3b6 @abw approach v2.03
authored
322 The Template Toolkit requires that the File::Spec module (version 0.6
911a5e3 @abw *** empty log message ***
authored
323 or later) first be installed. This is used by the File plugin. It is
324 available from CPAN:
325
326 http://search.cpan.org/search?dist=File-Spec
327
328 EOF
a4123f8 @abw 2.04b
authored
329 }
911a5e3 @abw *** empty log message ***
authored
330 }
331
332
a4123f8 @abw 2.04b
authored
333
c8d76d4 @abw *** empty log message ***
authored
334 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
335 # optional_modules()
336 #
337 # Detect additional modules required by plugins (just for fun)
48634a1 @abw *** empty log message ***
authored
338 #------------------------------------------------------------------------
25a8d8e @abw *** empty log message ***
authored
339
a4123f8 @abw 2.04b
authored
340 sub optional_modules {
341 message(<<EOF);
48634a1 @abw *** empty log message ***
authored
342
82cbea8 @abw version 2.00
authored
343 The Template Toolkit includes a number of plugin modules, some of
344 which interface to external Perl modules available from CPAN. All the
345 plugins will be installed regardless so that they will automatically
346 work as and when you install the relevant modules. The tests will be
347 skipped for plugins that require external modules not currently
348 available on your system.
e39913f @abw *** empty log message ***
authored
349
350 EOF
48634a1 @abw *** empty log message ***
authored
351
a4123f8 @abw 2.04b
authored
352 foreach my $mods ( [ 'Text::Autoformat' => \&check_taf ],
353 [ 'GD' => undef ],
354 [ 'GD::Text' => undef ],
355 [ 'GD::Graph' => undef ],
356 [ 'GD::Graph3d' => undef ],
357 [ 'Date::Calc' => undef ],
358 [ 'XML::DOM' => \&check_dom ],
359 [ 'XML::RSS' => \&check_rss ],
360 [ 'XML::XPath' => \&check_xpath ],
361 [ 'DBI' => \&dbi_config ] ) {
362 my ($module, $code) = ref $mods ? @$mods : ($mods, 0);
363
364 printf(" %-16s ", $module) unless $TT_QUIET;
365 eval "use $module";
366 if ($@) {
367 nope("module not installed");
368 }
369 elsif ($code) {
370 &$code;
371 }
372 else {
373 no strict qw( refs );
374 my $ver = ${"$module\::VERSION"};
375 yep("version $ver installed");
376 }
82cbea8 @abw version 2.00
authored
377 }
e39913f @abw *** empty log message ***
authored
378 }
379
a4123f8 @abw 2.04b
authored
380
381
c8d76d4 @abw *** empty log message ***
authored
382 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
383 # optional_latex()
384 #
385 # Prompt for installation of latex filter
f4df3b6 @abw approach v2.03
authored
386 #------------------------------------------------------------------------
387
a4123f8 @abw 2.04b
authored
388 sub optional_latex {
389 return if ! $TT_LATEX_ENABLE || $TT_LATEX_ENABLE eq 'n';
390
391 $TT_LATEX_PATH ||= findProgram($ENV{PATH}, "latex") || '';
392 $TT_PDFLATEX_PATH ||= findProgram($ENV{PATH}, "pdflatex") || '';
393 $TT_DVIPS_PATH ||= findProgram($ENV{PATH}, "dvips") || '';
394
395 message(<<EOF);
f4df3b6 @abw approach v2.03
authored
396
397 TT2 supports PDF, DVI and PostScript output using the latex filter,
398 implemented with the programs pdflatex, latex and dvips.
399
400 Because the latex filter runs latex and pdflatex, template authors could
401 use this feature to include any arbitrary file in their latex input, or
402 also open an arbitrary output file, independent of the ABSOLUTE or
403 RELATIVE configuration settings. This might create a security concern at
404 your site. If you don't trust your template authors then don't enable
405 the latex filter.
406
407 I found the following locations for pdflatex, latex and dvips:
408 + pdflatex => $TT_PDFLATEX_PATH
409 + latex => $TT_LATEX_PATH
410 + dvips => $TT_DVIPS_PATH
411
412 EOF
413
a4123f8 @abw 2.04b
authored
414 if ( $TT_LATEX_PATH eq "" || $TT_PDFLATEX_PATH eq "" || $TT_DVIPS_PATH eq "" ) {
415 $TT_LATEX_ENABLE = 'n';
416 }
417 $TT_LATEX_ENABLE ||= 'y';
418 $TT_LATEX_ENABLE = (
419 ttprompt('Do you want to enable the latex filter?',
420 $TT_LATEX_ENABLE) =~ /^y/i
421 );
422 if ( $TT_LATEX_ENABLE ) {
423 if (ttprompt('Are the pdflatex, latex and dvips paths ok?', 'y') !~ /^y/i) {
424 $TT_PDFLATEX_PATH = ttprompt('pdflatex path', $TT_PDFLATEX_PATH);
425 $TT_LATEX_PATH = ttprompt('latex path', $TT_LATEX_PATH);
426 $TT_DVIPS_PATH = ttprompt('dvips path', $TT_DVIPS_PATH);
427 }
428 } else {
429 #
430 # Empty paths will cause the latex filter to throw an error
431 #
432 $TT_PDFLATEX_PATH = $TT_LATEX_PATH = $TT_DVIPS_PATH = "";
f4df3b6 @abw approach v2.03
authored
433 }
a4123f8 @abw 2.04b
authored
434
435 fix_file('lib/Template/Config.pm', '$PDFLATEX_PATH', $TT_PDFLATEX_PATH);
436 fix_file('lib/Template/Config.pm', '$LATEX_PATH', $TT_LATEX_PATH);
437 fix_file('lib/Template/Config.pm', '$DVIPS_PATH', $TT_DVIPS_PATH);
f4df3b6 @abw approach v2.03
authored
438 }
439
a4123f8 @abw 2.04b
authored
440
f4df3b6 @abw approach v2.03
authored
441
442 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
443 # optional_extras()
444 #
445 # Prompt for installation of optional libraries and other components
c8d76d4 @abw *** empty log message ***
authored
446 #------------------------------------------------------------------------
447
a4123f8 @abw 2.04b
authored
448 sub optional_extras {
449 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
450
451 In additional to the Perl modules and POD documentation installed in
452 the usual way, the Template Toolkit distribution also contains a
453 number of optional components:
454
455 * Template libaries for basic HTML, Pod -> HTML, and PostScript
456
457 * Splash! - a stylish HTML user interface template library / widget set
458
459 * HTML documentation - distributed in template form for customisation
460
461 * Stylesheet templates to generate docs as vanilla HTML or using Splash!
462
463 * Examples - numerous examples of using the template libraries
464
465 If you want to install these optional components then you'll need to
466 specify a separate directory for them.
467
468 EOF
469
a4123f8 @abw 2.04b
authored
470 if (ttprompt('Do you want to install these components?', 'y') =~ /^y/i) {
471 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
472
473 You can chose any directory for the installation of the additional
911a5e3 @abw *** empty log message ***
authored
474 Template Toolkit components. The proposed default assumes a $FLAVOUR
475 flavour to your operating system (suggestions for suitable defaults
476 for other platforms welcome).
c8d76d4 @abw *** empty log message ***
authored
477
478 EOF
a4123f8 @abw 2.04b
authored
479 $TT_PREFIX = ttprompt('Installation directory', $TT_PREFIX);
480 }
481 else {
482 $TT_PREFIX = '';
483 }
484
485 fix_file('lib/Template/Config.pm', '$INSTDIR', $TT_PREFIX);
c8d76d4 @abw *** empty log message ***
authored
486 }
487
488
489
490 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
491 # splash_images()
492 #
493 # Prompt for Splash! image URL
c8d76d4 @abw *** empty log message ***
authored
494 #------------------------------------------------------------------------
495
a4123f8 @abw 2.04b
authored
496 sub splash_images {
497 return unless $TT_PREFIX;
911a5e3 @abw *** empty log message ***
authored
498
a4123f8 @abw 2.04b
authored
499 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
500
501 The Splash! template library uses a number of (very) small images to
502 build user interface components. These will be installed into the
503 directory:
504
a4123f8 @abw 2.04b
authored
505 $TT_PREFIX/images
911a5e3 @abw *** empty log message ***
authored
506 EOF
507
508 if ($WIN32) {
509 # default images value for Win32 to browse via file system
a4123f8 @abw 2.04b
authored
510 $TT_IMAGES = "$TT_PREFIX/images";
511
512 message(<<EOF);
513
911a5e3 @abw *** empty log message ***
authored
514 If you want to use the Splash! library then you'll need to make sure
515 you can access these images via your browser. If you want to deliver
516 pages via a web server then you'll need to specify the URL that can be
517 use to access these images. In the general case you can accept the
518 default and access the images via the filesystem.
519
520 EOF
521 }
522 else {
a4123f8 @abw 2.04b
authored
523 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
524
525 If you want to use the Splash! library then you'll need to copy these
526 images, define an alias (e.g. in the httpd.conf) or create a symbolic
527 link to them so that your web server can find them. Then you'll need
528 to specify the resulting URL which can be used to retrieve them from
529 the web server.
530
531 Typical values might be '/tt2/images', '/images/tt2', '/~user/tt2/images'
532 or even something like 'http://www.yourhost.org/images/tt2'.
533
534 (NOTE: If this is too much for you to think about right now, then
535 accept the default below and read the Template::Library::Splash
536 manpage at your leisure to find out more).
537
538 EOF
911a5e3 @abw *** empty log message ***
authored
539 }
c8d76d4 @abw *** empty log message ***
authored
540
a4123f8 @abw 2.04b
authored
541 $TT_IMAGES = ttprompt('URL base for TT2 images?', $TT_IMAGES);
c8d76d4 @abw *** empty log message ***
authored
542 $TT_IMAGES =~ s[/$][]g; # just in case
543 fix_file('templates/splash/config', 'images', "$TT_IMAGES/splash");
544 }
545
546
547
a4123f8 @abw 2.04b
authored
548 #------------------------------------------------------------------------
549 # html_docs()
550 #
551 # Prompt for HTML documentation build
552 #--------------------------------------------------------------------
553
554 sub html_docs {
555 return unless $TT_PREFIX;
556
c8d76d4 @abw *** empty log message ***
authored
557 my $style = 'plain';
558 my $style_cfg = '';
559
a4123f8 @abw 2.04b
authored
560 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
561
562 The modules comprising the Template Toolkit contain comprehensive POD
563 documentation which can be browsed using 'perldoc' or 'man' (if your
564 system supports it). In additional, the distribution also includes a
565 set of source templates and style elements for generating the same
566 documentation in HTML format. These will be installed in the
567 directory:
568
a4123f8 @abw 2.04b
authored
569 $TT_PREFIX/docs
c8d76d4 @abw *** empty log message ***
authored
570
571 The HTML documentation can be built for you at "make install" time in
572 a plain and simple HTML format or using the Splash! library. You can
573 see examples of these different styles and browse the documentation
574 online at:
575
576 http://www.template-toolkit.org/docs/
577
578 EOF
579
580 $TT_BUILD_DOCS = (
a4123f8 @abw 2.04b
authored
581 ttprompt('Do you want to build the HTML documentation?',
c8d76d4 @abw *** empty log message ***
authored
582 $TT_BUILD_DOCS) =~ /^y/i
583 );
584
a4123f8 @abw 2.04b
authored
585 }
586
587
588 #--------------------------------------------------------------------
589 # html_docstyle()
590 #
591 # prompt for docs style: plain or splash
592 #--------------------------------------------------------------------
593
594 sub html_docstyle {
595 return unless $TT_PREFIX && $TT_BUILD_DOCS;
596
597 my $style = 'plain';
598 my $style_cfg = '';
c8d76d4 @abw *** empty log message ***
authored
599
a4123f8 @abw 2.04b
authored
600 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
601
ca4050f @abw prep for 2.02
authored
602 If you want to build the HTML documentation using the Splash! library
603 then you'll need to make sure you correctly defined the URL for the
604 Splash! images above. Otherwise, answer 'n' to the next question to
605 use plain HTML.
c8d76d4 @abw *** empty log message ***
authored
606
607 EOF
a4123f8 @abw 2.04b
authored
608 $TT_SPLASH_DOCS = (
609 ttprompt('Do you want to use the Splash! library?', $TT_SPLASH_DOCS) =~ /^y/i
610 );
c8d76d4 @abw *** empty log message ***
authored
611
a4123f8 @abw 2.04b
authored
612 if ($TT_SPLASH_DOCS) {
613 my $splash_style = '';
614 message(<<EOF);
ca4050f @abw prep for 2.02
authored
615
616 Which Splash! colour scheme would you like to use to build the
617 documentation? Acceptable values are:
618
619 EOF
a4123f8 @abw 2.04b
authored
620 unless ($TT_QUIET) {
ca4050f @abw prep for 2.02
authored
621 print " Name Colours\n -------------------------\n";
622 foreach my $t ('default',
623 grep { ! /^default$/ } sort keys %$SPLASH_STYLES) {
624 my $v = $SPLASH_STYLES->{ $t };
625 local $" = '/';
626 printf(" %-8s @$v\n", $t);
627 }
628 print "\n";
629
630 while (! $splash_style) {
a4123f8 @abw 2.04b
authored
631 $TT_SPLASH_THEME = ttprompt("Enter name of colour scheme: ", $TT_SPLASH_THEME);
632 message("! No such scheme\n"), $TT_SPLASH_THEME = 'default'
ca4050f @abw prep for 2.02
authored
633 unless ($splash_style = $SPLASH_STYLES->{ $TT_SPLASH_THEME });
634 }
635 ($TT_SPLASH_BG, $TT_SPLASH_FG) = @$splash_style;
636
c8d76d4 @abw *** empty log message ***
authored
637 $style = 'splash';
ca4050f @abw prep for 2.02
authored
638 $style_cfg = <<EOF;
639
640 pre_process = splash/config
641 define splash_fg = '$TT_SPLASH_FG'
642 define splash_bg = '$TT_SPLASH_BG'
643 EOF
c8d76d4 @abw *** empty log message ***
authored
644 }
645 }
646
647 #--------------------------------------------------------------------
648 # write ttree config file for building docs
649 #--------------------------------------------------------------------
650
651 open(FP, "> $TT_DOCS_CFG") || die "$TT_DOCS_CFG: $!\n";
652 print FP <<EOF;
653 # This ttree configuration file is automatically generated by
654 # the Makefile.PL installation script. Feel free to edit it
655 # but be warned that re-installing the Template Toolkit will
656 # overwrite your changes.
a4123f8 @abw 2.04b
authored
657 src = $TT_PREFIX/docs/src
658 dest = $TT_PREFIX/docs/html
659 lib = $TT_PREFIX/docs/style/$style
660 lib = $TT_PREFIX/docs/lib
661 lib = $TT_PREFIX/templates
c8d76d4 @abw *** empty log message ***
authored
662 $style_cfg
663 pre_process = config
664 pre_process = header
665 post_process = footer
911a5e3 @abw *** empty log message ***
authored
666 recurse
667 verbose
c8d76d4 @abw *** empty log message ***
authored
668 EOF
669 close(FP);
a4123f8 @abw 2.04b
authored
670 }
c8d76d4 @abw *** empty log message ***
authored
671
672
a4123f8 @abw 2.04b
authored
673
674
675 #--------------------------------------------------------------------
676 # html_examples()
677 #
678 # Prompt for building examples
679 #--------------------------------------------------------------------
680
681 sub html_examples {
682 return unless $TT_PREFIX;
683
684 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
685
686 A number of examples showing use of the HTML, Splash! and PostScript
687 libraries will be installed into:
688
a4123f8 @abw 2.04b
authored
689 $TT_PREFIX/examples
c8d76d4 @abw *** empty log message ***
authored
690
691 As with the documentation, the examples are provided in template form
692 and can be automatically built into HTML pages during the "make
693 install". These pages rely on the Splash! library and expect the
694 images URL to be correctly defined for correct viewing.
695
696 EOF
697
698 $TT_EXAMPLES = (
a4123f8 @abw 2.04b
authored
699 ttprompt('Do you want to build the HTML example pages?',
c8d76d4 @abw *** empty log message ***
authored
700 $TT_EXAMPLES) =~ /^y/i
701 );
702
703 #--------------------------------------------------------------------
704 # write ttree config file for building examples
705 #--------------------------------------------------------------------
706
707 open(FP, "> $TT_EXAMPLE_CFG") || die "$TT_EXAMPLE_CFG: $!\n";
708 print FP <<EOF;
709 # This ttree configuration file is automatically generated by
710 # the Makefile.PL installation script. Feel free to edit it
711 # but be warned that re-installing the Template Toolkit will
712 # overwrite your changes.
713
a4123f8 @abw 2.04b
authored
714 src = $TT_PREFIX/examples/src
715 dest = $TT_PREFIX/examples/html
716 lib = $TT_PREFIX/examples/lib
717 lib = $TT_PREFIX/templates
ca4050f @abw prep for 2.02
authored
718 define splash_fg = '$TT_SPLASH_FG'
719 define splash_bg = '$TT_SPLASH_BG'
c8d76d4 @abw *** empty log message ***
authored
720 pre_process = config
911a5e3 @abw *** empty log message ***
authored
721 recurse
722 verbose
c8d76d4 @abw *** empty log message ***
authored
723 EOF
724
725 close(FP);
726 }
a4123f8 @abw 2.04b
authored
727
728
729 #--------------------------------------------------------------------
730 # write_defaults()
731 #
732 # write configuration defaults to file
733 #--------------------------------------------------------------------
734
735 sub write_defaults {
ca4050f @abw prep for 2.02
authored
736 open(FP, "> $DEFAULTS_FILE") || die "$DEFAULTS_FILE: $!\n";
f4df3b6 @abw approach v2.03
authored
737 my ($ttdbi, $ttdocs, $ttsplash, $ttex, $ttlatex) = map { $_ ? 'y' : 'n' }
a4123f8 @abw 2.04b
authored
738 ( $TT_RUN_DBI, $TT_BUILD_DOCS, $TT_SPLASH_DOCS, $TT_EXAMPLES, $TT_LATEX_ENABLE );
ca4050f @abw prep for 2.02
authored
739 print FP <<EOF;
a4123f8 @abw 2.04b
authored
740 \$TT_PREFIX = '$TT_PREFIX';
f4df3b6 @abw approach v2.03
authored
741 \$TT_IMAGES = '$TT_IMAGES';
742 \$TT_RUN_DBI = '$ttdbi';
743 \$TT_BUILD_DOCS = '$ttdocs';
744 \$TT_SPLASH_DOCS = '$ttsplash';
745 \$TT_EXAMPLES = '$ttex';
746 \$TT_SPLASH_THEME = '$TT_SPLASH_THEME';
747 \$TT_LATEX_ENABLE = '$ttlatex';
748 \$TT_LATEX_PATH = '$TT_LATEX_PATH';
749 \$TT_PDFLATEX_PATH = '$TT_PDFLATEX_PATH';
750 \$TT_DVIPS_PATH = '$TT_DVIPS_PATH';
a4123f8 @abw 2.04b
authored
751 \$TT_ACCEPT = '$TT_ACCEPT';
752 \$TT_QUIET = '$TT_QUIET';
9acc796 @abw post 2.03a
authored
753 1;
ca4050f @abw prep for 2.02
authored
754 EOF
755 close(FP);
c8d76d4 @abw *** empty log message ***
authored
756 }
757
48634a1 @abw *** empty log message ***
authored
758
759 #------------------------------------------------------------------------
760 # build_docs()
761 #
762 # Echo the relevant incantation so that 'make dist' regenerates the
763 # documentation from the template sources.
25a8d8e @abw *** empty log message ***
authored
764 #------------------------------------------------------------------------
eabb19e @abw *** empty log message ***
authored
765
3ebfa07 @abw Initial revision
authored
766 sub build_docs {
767 return <<EOF;
768 echo "Building documentation for version \$(VERSION)" ; \\
0b63aae @abw *** empty log message ***
authored
769 \$(PERL) bin/ttree -f ./docs/ttdist.cfg --define version=\$(VERSION) -a; \\
3ebfa07 @abw Initial revision
authored
770 EOF
771 }
772
48634a1 @abw *** empty log message ***
authored
773
82cbea8 @abw version 2.00
authored
774
775 #------------------------------------------------------------------------
867f44f @abw rc2
authored
776 # check_taf()
777 #
778 # There are some problems with Text::Autoformat with version of Perl
779 # prior to 5.6.0 not working properly with locales that use a numerical
780 # separator other than '.' (e.g. Swedish)
781 #------------------------------------------------------------------------
782
783 sub check_taf {
784 use POSIX qw( localeconv );
785 my $loc = localeconv;
786 my $dec = $loc->{ decimal_point };
787
788 yep("version $Text::Autoformat::VERSION installed");
789
790 if ($] <= 5.006 && $dec ne '.') {
791 print ' ' x 6,
792 "NOTE: tests 23 and 25 may fail under your locale, see TODO file.\n";
793 }
794 }
795
796
797 #------------------------------------------------------------------------
acff212 @abw *** empty log message ***
authored
798 # check_dom()
799 #
867f44f @abw rc2
authored
800 # XML::DOM changed from HASH to ARRAY objects somewhere between versions
801 # 1.25 and 1.27, so the latter version is an absolute necessity.
60dfe44 @abw *** empty log message ***
authored
802 #------------------------------------------------------------------------
803
804 sub check_dom {
867f44f @abw rc2
authored
805 if ($XML::DOM::VERSION < 1.27) {
806 nope("requires version 1.27 or later ($XML::DOM::VERSION installed)");
60dfe44 @abw *** empty log message ***
authored
807 }
808 else {
82cbea8 @abw version 2.00
authored
809 yep("version $XML::DOM::VERSION installed");
60dfe44 @abw *** empty log message ***
authored
810 }
811 }
812
813
acff212 @abw *** empty log message ***
authored
814 #------------------------------------------------------------------------
815 # check_rss()
816 #
817 # Version 0.8 of XML::RSS gave warnings under Perl 5.6.0 so issue an
818 # upgrade recommendation
819 #------------------------------------------------------------------------
820
60dfe44 @abw *** empty log message ***
authored
821 sub check_rss {
82cbea8 @abw version 2.00
authored
822 if ($] >= 5.006 && $XML::RSS::VERSION < 0.9) {
823 nope("requires version 0.9 or later ($XML::RSS::VERSION installed)");
60dfe44 @abw *** empty log message ***
authored
824 }
825 else {
82cbea8 @abw version 2.00
authored
826 yep("version $XML::RSS::VERSION installed");
60dfe44 @abw *** empty log message ***
authored
827 }
828 }
829
a4123f8 @abw 2.04b
authored
830
acff212 @abw *** empty log message ***
authored
831 #------------------------------------------------------------------------
832 # check_xpath()
833 #
834 # Tests fail under some of the earlier versions (e.g. 0.55) so we issue
835 # an upgrade recommendation.
836 #------------------------------------------------------------------------
60dfe44 @abw *** empty log message ***
authored
837
838 sub check_xpath {
839 if ($XML::XPath::VERSION < 1.00) {
82cbea8 @abw version 2.00
authored
840 nope("requires version 1.00 or later ($XML::XPath::VERSION installed)");
60dfe44 @abw *** empty log message ***
authored
841 }
842 else {
82cbea8 @abw version 2.00
authored
843 yep("version $XML::XPath::VERSION installed");
60dfe44 @abw *** empty log message ***
authored
844 }
845 }
846
847
848 #------------------------------------------------------------------------
48634a1 @abw *** empty log message ***
authored
849 # dbi_config()
850 #
851 # Quiz the user for options related to running the DBI tests.
852 #------------------------------------------------------------------------
853
854 sub dbi_config {
a4123f8 @abw 2.04b
authored
855 my ($dsn, $user, $pass) = ('') x 3;
48634a1 @abw *** empty log message ***
authored
856
a4123f8 @abw 2.04b
authored
857 message("[X] version $DBI::VERSION installed, configuring tests\n\n");
48634a1 @abw *** empty log message ***
authored
858
a4123f8 @abw 2.04b
authored
859 if (ttprompt("Do you want to run the DBI tests?\n" .
c8d76d4 @abw *** empty log message ***
authored
860 "It requires access to an existing test database.",
ca4050f @abw prep for 2.02
authored
861 $TT_RUN_DBI) =~ /y/i) {
48634a1 @abw *** empty log message ***
authored
862
ca4050f @abw prep for 2.02
authored
863 $TT_RUN_DBI = 1;
48634a1 @abw *** empty log message ***
authored
864 my ($driver, $dbname);
865 my @drivers = DBI->available_drivers();
866 local $" = ', ';
867
868 my $default = (grep(/m.?sql/i, @drivers))[0];
867f44f @abw rc2
authored
869
a4123f8 @abw 2.04b
authored
870 message(<<EOF);
48634a1 @abw *** empty log message ***
authored
871
c8d76d4 @abw *** empty log message ***
authored
872 Please enter the driver name for the test database.
873 The DBD drivers installed on your system are
874
875 @drivers
867f44f @abw rc2
authored
876
877 EOF
48634a1 @abw *** empty log message ***
authored
878
879 while (! $driver) {
a4123f8 @abw 2.04b
authored
880 $driver = ttprompt("Enter driver name: ", $default);
881 message("! No such DBD driver\n"), undef $driver
48634a1 @abw *** empty log message ***
authored
882 unless grep(/^$driver$/, @drivers);
883 }
884
a4123f8 @abw 2.04b
authored
885 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
886
887 Now enter the data source (DSN) for the test database.
888 Many DBD drivers require only a database name (e.g. 'test') while
889 others may require an alternate format or additional parameters
890 (e.g. 'dbname=test'). Please consult your DBD documentation for
891 further details.
892
867f44f @abw rc2
authored
893 EOF
894
895 my $dbname_eg = $driver eq 'Pg' ? 'dbname=test' : 'test';
48634a1 @abw *** empty log message ***
authored
896 while (! $dbname) {
a4123f8 @abw 2.04b
authored
897 $dbname = ttprompt('Database name: ', $dbname_eg);
48634a1 @abw *** empty log message ***
authored
898 }
899
900 $dsn = "dbi:$driver:$dbname";
901
a4123f8 @abw 2.04b
authored
902 $user = ttprompt('Enter user name : ', '');
903 $pass = ttprompt('Enter password : ', '');
48634a1 @abw *** empty log message ***
authored
904
905 $user = '' unless defined $user;
906 $pass = '' unless defined $pass;
907 }
908 else {
ca4050f @abw prep for 2.02
authored
909 $TT_RUN_DBI = 0;
48634a1 @abw *** empty log message ***
authored
910 }
911
a4123f8 @abw 2.04b
authored
912 message("\nwriting $DBI_CONFIG_FILE\n");
48634a1 @abw *** empty log message ***
authored
913 open(CFGFILE, ">$DBI_CONFIG_FILE") || die "$DBI_CONFIG_FILE: $!\n";
914 print CFGFILE <<EOF;
ca4050f @abw prep for 2.02
authored
915 \$run = $TT_RUN_DBI;
48634a1 @abw *** empty log message ***
authored
916 \$dsn = '$dsn';
917 \$user = '$user';
918 \$pass = '$pass';
919 1;
920 EOF
921 close(CFGFILE);
922 }
923
c8d76d4 @abw *** empty log message ***
authored
924
925
926 #------------------------------------------------------------------------
927 # fix_file($file, $find, $fix)
928 #
929 # Fixes a variable definition in a file. e.g.
930 # fix_file('lib/Template/Config.pm', '$INSTDIR', '/usr/local/tt2')
931 #------------------------------------------------------------------------
932
933 sub fix_file {
934 my ($file, $find, $fix) = @_;
935 local *FP;
936 local $/ = undef;
937
938 $find = quotemeta($find);
939
940 open(FP, "< $file") || die "$file: $!\n";
941 my $text = <FP>;
942 close(FP);
943
944 ($text =~ s/^(\s*${find}\s*=\s*)'.*?'/$1'$fix'/m)
945 || die "$find not found in $file\n";
946
947 open(FP, "> $file") || die "$file: $!\n";
948 print FP $text;
949 close(FP);
950 }
951
a4123f8 @abw 2.04b
authored
952
953 #------------------------------------------------------------------------
f4df3b6 @abw approach v2.03
authored
954 # findProgram($path, $prog)
955 #
956 # Find a program, $prog, by traversing the given directory path, $path.
957 # Returns full path if the program is found.
958 #
959 # Written by Craig Barratt, Richard Tietjen add fixes for Win32.
a4123f8 @abw 2.04b
authored
960 #------------------------------------------------------------------------
961
f4df3b6 @abw approach v2.03
authored
962 sub findProgram {
963 my($path, $prog) = @_;
964 my $sep = $WIN32 ? qr/;/ : qr/:/;
965 foreach my $dir ( split($sep, $path) ) {
966 my $file = File::Spec->catfile($dir, $prog);
967 if ( !$WIN32 ) {
968 return $file if ( -x $file );
969 } else {
970 # Windows executables end in .xxx, exe precedes .bat and .cmd
971 foreach my $dx ( qw/exe bat cmd/ ) {
972 return "$file.$dx" if ( -x "$file.$dx" );
973 }
974 }
975 }
976 }
a4123f8 @abw 2.04b
authored
977
978
979 #------------------------------------------------------------------------
980 # message($text)
981 #
982 # Print message unless quiet mode.
983 #------------------------------------------------------------------------
984
985 sub message {
986 return if $TT_QUIET;
987 print @_;
988 }
989
990
991 #------------------------------------------------------------------------
992 # ttprompt($message, $default)
993 #------------------------------------------------------------------------
994
995 sub ttprompt {
996 my ($msg, $def)=@_;
997 my $ISA_TTY = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)) ; # Pipe?
998 my $dispdef = defined $def ? "[$def] " : " ";
999 $def = defined $def ? $def : "";
1000 my $ans = '';
1001 local $|=1;
1002 print "$msg $dispdef" unless $TT_QUIET;
1003 if ($TT_ACCEPT || ! $ISA_TTY) {
1004 print "$def\n" unless $TT_QUIET;
1005 }
1006 else {
1007 chomp($ans = <STDIN>);
1008 }
1009 return ($ans ne '') ? $ans : $def;
1010 }
1011
1012
1013 #------------------------------------------------------------------------
1014 # yep($text)
1015 #------------------------------------------------------------------------
1016
1017 sub yep {
1018 return if $TT_QUIET;
1019 print '[X] ', shift, "\n";
1020 }
1021
1022
1023 #------------------------------------------------------------------------
1024 # nope($text)
1025 #------------------------------------------------------------------------
1026 sub nope {
1027 return if $TT_QUIET;
1028 print '[ ] ', shift, "\n";
1029 }
Something went wrong with that request. Please try again.