#!/usr/bin/perl -w # -*- perl -*- use strict; use warnings; use 5.008; use lib qw( ./lib ); use Config; use File::Spec::Functions qw( catfile ); use Template; use ExtUtils::MakeMaker; use Cwd; select STDERR; $| = 1; select STDOUT; our ( $TT_VERSION, $TT_PREFIX, $TT_XS_ENABLE, $TT_XS_DEFAULT, $TT_QUIET, $TT_ACCEPT, $TT_YES ); # check O/S to set sensible defaults my ($WIN32, $FLAVOUR, $PREFIX, $IMAGES, $MAKE); if ($^O eq 'MSWin32') { # any others also? $WIN32 = 1; $FLAVOUR = 'Win32'; $PREFIX = 'C:/Program Files/Template Toolkit 2'; $IMAGES = '/tt2/images'; } else { $WIN32 = 0; $FLAVOUR = 'Unix'; $PREFIX = '/usr/local/tt2'; $IMAGES = '/tt2/images'; } $MAKE=$Config{'make'}; # read command line args putting TT_* into $ttconfig and # everything else (regular Makefile.PL args, e.g. PREFIX) # goes into $config my (%config, %ttconfig); while ($_ = shift) { my ($k, $v) = split(/=/, $_, 2); if ($k =~ /^TT/) { $ttconfig{ $k } = $v || 0; } else { $config{ $k } = $v || 0; } }; # print help if they asked for it if (exists $ttconfig{ TT_HELP }) { print < 'Template', 'DISTNAME' => 'Template-Toolkit', 'VERSION_FROM' => 'lib/Template.pm', 'EXE_FILES' => [ 'bin/tpage', 'bin/ttree' ], 'PMLIBDIRS' => [ 'lib' ], 'DIR' => [ ], 'PREREQ_PM' => { 'AppConfig' => $TT_APPCONFIG_VERSION, 'File::Spec' => $TT_FILE_SPEC_VERSION, 'File::Temp' => $TT_FILE_TEMP_VERSION, 'Scalar::Util' => 0, }, 'TEST_REQUIRES' => { 'Test::LeakTrace' => 0, }, 'META_MERGE' => { 'meta-spec' => { version => 2 }, "resources" => { "bugtracker" => { web => "https://github.com/abw/Template2/issues" }, "homepage" => "http://www.template-toolkit.org", "repository" => { "type" => "git", "url" => "https://github.com/abw/Template2.git", "web" => "https://github.com/abw/Template2" }, } }, 'dist' => { 'COMPRESS' => 'gzip', 'SUFFIX' => 'gz', }, 'test' => { 'TESTS' => join(' ', map { glob } qw( t/*.t t/vmethods/*.t )), }, 'clean' => { 'FILES' => join(' ', qw( docs/ttree.cfg examples/ttree.cfg t/dbi_test.cfg t/test/src/baz.ttc t/test/src/complex.org t/test/src/complex.ttc t/test/src/evalperl.ttc t/test/src/foo.ttc )), }, ); push @{ $opts{'DIR'} }, 'xs' if $TT_XS_ENABLE; # Handle dev versions in our check my $mmv = $ExtUtils::MakeMaker::VERSION; $mmv =~ s/\_.+//; if ($mmv >= 5.43) { $opts{ AUTHOR } = 'Andy Wardley '; $opts{ ABSTRACT } = 'comprehensive template processing system', } if ($ExtUtils::MakeMaker::VERSION ge '6.30_00') { $opts{'LICENSE' } = 'perl'; } WriteMakefile( %opts ); print <", $DEFAULTS_FILE) || die "$DEFAULTS_FILE: $!\n"; my ( $ttxs_enable, $ttxs_default ) = map { $_ ? 'y' : 'n' } ( $TT_XS_ENABLE, $TT_XS_DEFAULT ); print FP <; close(FP); ($text =~ s/^(\s*${find}\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) = @_; # my $sep = $WIN32 ? qr/;/ : qr/:/; # foreach my $dir ( split($sep, $path) ) { 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 $TT_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 $TT_QUIET; if ($TT_ACCEPT || ! $ISA_TTY) { print "$def\n" unless $TT_QUIET; } else { chomp($ans = ); } return ($ans ne '') ? $ans : $def; } #------------------------------------------------------------------------ # yep($text) #------------------------------------------------------------------------ sub yep { return if $TT_QUIET; print '[X] ', shift, "\n"; } #------------------------------------------------------------------------ # nope($text) #------------------------------------------------------------------------ sub nope { return if $TT_QUIET; print '[ ] ', shift, "\n"; }