#!/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 = 0; our $WIN32 = ($^O eq 'MSWin32'); our $MODVERSION = get_module_version(); #------------------------------------------------------------------------ message(< 'LaTeX-Driver', 'VERSION_FROM' => 'lib/LaTeX/Driver.pm', '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 '; $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 = ; 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 = ); } 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 () { return $1 if /VERSION = (\d+\.\d+)/; } return ""; }