1#! /usr/bin/perl -w 2 3############################################################################### 4# $Id: install.pl,v 1.12 2002/04/27 11:31:23 RRM Exp $ 5# 6# install.pl 7# 8# This script is used to install LaTeX2HTML on the user's system 9# 10# Author: Marek Rouchal <marek@saftsack.fs.uni-bayreuth.de> 11# 12# This software is part of LaTeX2HTML, originally by Nikos Drakos 13# It is published under the GNU Public License and comes without any 14# warranty. 15# 16############################################################################### 17# Changes History 18# 19# $Log: install.pl,v $ 20# Revision 1.12 2002/04/27 11:31:23 RRM 21# new release version: 2002-1 22# 23# -- implements $LATEX2HTMLDIR (shared) and $LATEX2HTMLPLATDIR (unshared) 24# puts unshared l2hconf.pm into $LATEX2HTMLPLATDIR (platform-specific) 25# other modules into $LATEX2HTMLDIR (shareable across platforms) 26# 27# -- checks for more graphics conversion utilities, for use with revised 28# graphics.perl and graphicx.perl 29# 30# Revision 1.11 2002/03/07 01:56:19 RRM 31# -- allow the environment variable DESTDIR to be recognise, as a means 32# of giving the installation location; e.g. 33# 34# make install DESTDIR=/usr/local/mypackages/ 35# 36# This is mainly for package-manager software, such as Debian and fink. 37# Thanks to David R Morrison <drm@cgtp.duke.edu> 38# and Daniel Steffen <steffen@maths.mq.edu.au> for this feature. 39# 40# Revision 1.10 1999/11/16 00:07:21 MRO 41# 42# -- minimal change to make $TMP commentable, i.e. unavailable 43# 44# Revision 1.9 1999/11/09 00:43:42 MRO 45# 46# 47# -- added some changes suggested on the mail list recently: mainly cleanup 48# of -dir option 49# -- added installation support for latex2html styles 50# 51# Revision 1.8 1999/10/26 22:32:57 MRO 52# 53# -- added a credit 54# -- reworked parts of the INSTALL documentation 55# -- installation now tries to install styles 56# 57# Revision 1.7 1999/10/25 21:18:22 MRO 58# 59# -- added more configure options (Jens' suggestions) 60# -- fixed bug in regexp range reported by Achim Haertel 61# -- fixed old references in documentation (related to mail list/archive) 62# 63# Revision 1.6 1999/10/03 18:40:42 MRO 64# 65# -- some cleanups for beta2 66# -- "make check" now checks all Perl code 67# 68# Revision 1.5 1999/08/30 22:45:09 MRO 69# 70# -- perl now reports line numbers respective to .pin file - eases 71# code development! 72# -- l2hcfg.pm is installed, too for furtjer reference 73# -- some minor bugs (hopefully) fixed. 74# 75# Revision 1.4 1999/06/06 14:24:58 MRO 76# 77# 78# -- many cleanups wrt. to TeXlive 79# -- changed $* to /m as far as possible. $* is deprecated in perl5, all 80# occurrences should be removed. 81# 82# Revision 1.3 1999/06/04 15:30:20 MRO 83# 84# 85# -- fixed errors introduced by cleaning up TMP* 86# -- made pstoimg -quiet really quiet 87# -- pstoimg -debug now saves intermediate result files 88# -- several fixes for OS/2 89# 90# Revision 1.2 1999/05/19 23:54:07 MRO 91# 92# 93# -- uniquified icons - some of them look a little bit strange, might 94# need to be fixed. 95# -- got rid of unlink errors, cleaned up some cosmetics 96# 97# Revision 1.1 1999/05/11 06:10:03 MRO 98# 99# 100# - merged config stuff, did first tries on Linux. Simple document 101# passes! More test required, have to ger rid of Warnings in texexpand 102# 103# Revision 1.12 1999/02/23 23:32:35 MRO 104# 105# 106# -- few changes for Win32 107# 108# Revision 1.11 1999/02/10 01:37:15 MRO 109# 110# 111# -- changed os-dependency structure again - now neat OO modules are 112# used: portable, extensible, neat! 113# -- some minor cleanups and bugfixes 114# 115# Revision 1.10 1999/02/07 23:47:52 MRO 116# 117# 118# -- made install procedure work 119# 120# Revision 1.9 1998/12/14 22:55:07 MRO 121# 122# 123# -- commit test for MRO 124# 125# Revision 1.8 1998/12/12 16:39:17 MRO 126# 127# 128# -- cosmetic changes, reworked catching of STDERR in config.pl (Win32) 129# -- new configure opt --disable-paths 130# -- major cleanups 131# 132# Revision 1.7 1998/12/07 23:20:00 MRO 133# 134# 135# -- added POD documentation to pstoimg and did a general cleanup 136# -- some finetuning of config procedure and modules 137# 138# Revision 1.6 1998/10/31 14:13:09 MRO 139# -- changed OS-dependent module loading strategy: Modules are now located in 140# different (OS-specific) directories nut have the same name: Easier to 141# maintain and cleaner code 142# -- Cleaned up config procedure 143# -- Extended makefile functionality 144# 145# Revision 1.5 1998/05/06 22:31:24 latex2html 146# -- Enhancements to the config procedure: Added a "generic" target 147# in the Makefile for the TeXlive CD (not perfect yet) 148# -- included test for kpsewhich / Web2C 149# -- included latest stuff from Override.pm into os_*.pm 150# 151# Revision 1.4 1998/04/28 22:22:40 latex2html 152# - The platform specific stuff is now kept in a separate perl module. This 153# does not introduce significant overhead and enhances maintainability. 154# 155# Revision 1.3 1998/03/19 23:38:12 latex2html 156# -- made pstoimg plug-in compatible with old one (touchwood!) 157# -- cleaned up, added some comments 158# -- inserted version information output 159# -- incorporated patches to make OS/2 run better (thanks Uli) 160# -- updated Makefile: make, make test, make install should work now 161# 162# Revision 1.2 1998/03/17 23:26:47 latex2html 163# -- fixed some bugs in config.pl 164# -- first version of install.pl finished 165# 166# Revision 1.1 1998/03/16 23:32:01 latex2html 167# -- lots of cosmetic changes and bugfixes, thanks to Uli Wortmann 168# for OS/2 testing 169# -- start of install procedure; checks for installation paths implemented 170# 171############################################################################### 172 173require 5.003; 174use strict; 175# use diagnostics; 176use vars qw(%cfg); 177 178my ($VERSION) = q$Revision: 1.12 $ =~ /:\s*(\S*)/; 179 180# -------------------------------------------------------------------------- 181# Initialize 182# -------------------------------------------------------------------------- 183 184use cfgcache; 185use L2hos; 186 187my $dd = $cfg{'dd'}; 188 189print "install.pl (Revision $VERSION)\n\n"; 190 191my $FILECHMOD = 0644; # numbers staring with 0 are octal! 192my $DIRCHMOD = 0755; 193my $BINCHMOD = 0755; 194 195# -------------------------------------------------------------------------- 196# The distribution's contents 197# -------------------------------------------------------------------------- 198 199# legal values: bin|lib|plat store in binary or library directory 200# recurse recurse for contents (directory only) 201# from=<dir> use other source directory 202# to=<dir> use other destination directory 203# separate these flags with ',' 204 205my %Install_items = ( 206 #'Changes' => 'lib', 207 #'FAQ' => 'lib', 208 #'INSTALL' => 'lib', 209 'IndicTeX-HTML' => 'lib,recurse', 210 'L2hos' => 'lib,recurse', 211 'L2hos.pm' => 'lib', 212 #'MANIFEST' => 'lib', 213 #'README' => 'lib', 214 #'README.dvips' => 'lib', 215 #'TODO' => 'lib', 216 'XyMTeX-HTML' => 'lib,recurse', 217 #'config' => 'lib,recurse', 218 #'config.bat' => 'lib', 219 #'configure' => 'lib', 220 #'configure.in' => 'lib', 221 'cweb2html' => 'lib,recurse', 222 'docs' => 'lib,recurse', 223 'dot.latex2html-init' => 'lib', 224 'example' => 'lib,recurse', 225 'foilhtml' => 'lib,recurse', 226 # icons are teated specially below 227 # the local config is also installed 228 'cfgcache.pm' => 'plat', 229 #'latex2html.config' is now l2hconf.pm 230 'l2hconf.pm' => 'plat', 231 'makemap' => 'lib', 232 'makeseg' => 'lib,recurse', 233 #'prefs.pm' => 'lib', 234 'readme.hthtml' => 'lib', 235 'styles' => 'lib,recurse', 236 # MRO: Tests are for pre-installation testing 237 #'tests' => 'lib,recurse', 238 'texinputs' => 'lib,recurse', 239 #'texlive.pm' => 'lib', 240 'versions' => 'lib,recurse', 241 #'wrapper' => 'lib,recurse', 242); 243 244# -------------------------------------------------------------------------- 245# Special case: OS dependencies 246# -------------------------------------------------------------------------- 247 248my @scripts = qw(latex2html pstoimg texexpand); 249 250if($cfg{'texlive'}) { 251 #$Install_items{'bin'} = 'lib,recurse'; 252 # where to install what be built 253 my %plat_map = ( 254 win32 => 'win32:.bat', 255 unix => 'i386-linux,rs6000-aix3.2.5,alpha-osf3.2,rs6000-aix4.1,alpha-osf4.0,mips-irix5.3,sparc-solaris2.5.1,hppa1.1-hpux10.10,mips-irix6.2,sparc-sunos4.1.4,powerpc-apple-darwin-current:' 256 ); 257 my $script; 258 foreach $script (@scripts) { 259 my $plat; 260 foreach $plat (qw(unix win32)) { 261 my ($d,$ext) = split(/:/, $plat_map{$plat}); 262 my $ip; 263 foreach $ip (split(',',$d)) { 264 &install_file("./bin/$plat/$script$ext", 265 "$cfg{'PREFIX'}/bin/$ip",$BINCHMOD); 266 $Install_items{"bin/$plat/$script$ext"} = 267 "to=$cfg{'PREFIX'}/bin/$ip"; 268 } 269 } 270 $Install_items{"$script.pl"} = 'lib'; 271 } 272} elsif($cfg{'wrapper'}) { 273 foreach(@scripts) { 274 $Install_items{"$_$cfg{'exec_extension'}"} = 'bin,from=bin'; 275 $Install_items{"$_.pl"} = 'lib'; 276 } 277} else { 278 foreach(@scripts) { 279 $Install_items{"$_$cfg{'exec_extension'}"} = 'bin'; 280 } 281} 282 283# -------------------------------------------------------------------------- 284# Special case: icons 285# -------------------------------------------------------------------------- 286 287# icons come in two flavors: GIF and PNG. They go into a icons directory 288# in SHLIBDIR (for the -local_icons option) and - if set - to ICONSTORAGE. 289# The icons are installed corresponding to the supported image formats. 290# If there is no image format supported, GIF icons are copied. 291 292my @icon_types = $cfg{'IMAGE_TYPES'} ? 293 split(/\s+/,$cfg{'IMAGE_TYPES'}) : qw(gif); 294my $iconrx = join('|', @icon_types); 295 296my $dest1 = "$cfg{'SHLIBDIR'}${dd}icons"; 297if((-d $dest1 && !-w _) || (-d $cfg{'SHLIBDIR'} && !-w _)) { 298 print STDERR "Error: Cannot install icons in '$dest1': No write permission.\n"; 299 $dest1 = ''; 300} 301my $dest2 = $cfg{'ICONSTORAGE'} || ''; 302if(-d $dest2 && !-w $dest2) { 303 print STDERR "Error: Cannot install icons in '$dest2': No write permission.\n"; 304 $dest2 = ''; 305} 306my $dir = "icons"; 307unless(opendir(DIR,$dir)) { 308 print STDERR qq{Error: Could not read directory "$dir": $!\n}; 309} else { 310 my $icon; 311 while(defined($icon = readdir(DIR))) { 312 next unless($icon =~ /\.($iconrx|html)$/oi); 313 my $full = "$dir/$icon"; 314 next if($icon =~ /^\.{1,2}$/ || !-f $full || !-s _); 315 &install_file($full,$dest1,$FILECHMOD,0) if($dest1); 316 &install_file($full,$dest2,$FILECHMOD,0) if($dest2); 317 } 318 closedir(DIR); 319} 320 321# -------------------------------------------------------------------------- 322# Go! 323# -------------------------------------------------------------------------- 324 325my $item; 326foreach $item (sort keys %Install_items) { 327 328 # Special case: pstoimg 329 if($item =~ /pstoimg/ && !$cfg{'have_pstoimg'}) { 330 print qq{Warning: pstoimg not installed, because build failed.\n}; 331 next; 332 } 333 334 my $from = '.'; 335 if($Install_items{$item} =~ /(?:^|,)from=([^,]+)(?:,|$)/) { 336 $from = $1; 337 } 338 339 my $dest = ''; 340 my $chmod = $FILECHMOD; 341 if($Install_items{$item} =~ /(^|,)bin(,|$)/) { 342 $dest = $cfg{'BINDIR'}; 343 $chmod = $BINCHMOD; 344 } 345 elsif($Install_items{$item} =~ /(^|,)lib(,|$)/) { 346 $dest = $cfg{'SHLIBDIR'}; 347 } 348 elsif($Install_items{$item} =~ /(^|,)plat(,|$)/) { 349 $dest = $cfg{'LIBDIR'}; 350 } 351 if($Install_items{$item} =~ /(?:^|,)to=([^,]*)(?:,|$)/) { 352 $dest = $1; 353 } 354 355 unless($dest) { 356 die qq{Error: No destination for item "$item"\n}; 357 } 358 if($Install_items{$item} =~ /(?:^|,)chmod=(\d+)(,|$)/) { 359 $chmod = $1; 360 } 361 if($Install_items{$item} =~ /recurse/) { 362 &install_recurse($item,$dest,$chmod); 363 } 364 else { 365 &install_file("$from/$item",$dest,$chmod); 366 } 367} 368 369#----------------------------------------------------------------------------- 370# try to install LaTeX2HTML style files 371#----------------------------------------------------------------------------- 372 373if($cfg{TEXPATH}) { 374 print "\nNote: trying to install LaTeX2HTML style files in TeX directory tree\n ($cfg{TEXPATH})\n"; 375 unless(mkpath($ENV{DESTDIR}.$cfg{TEXPATH})) { 376 #my $testpath = $cfg{TEXPATH}; # to strip (latex2)html 377 #$testpath =~ s/[$dd$dd][^$dd$dd]*$//; 378 #if((-d $cfg{TEXPATH} && !-w _) || (-d $testpath && !-w _)) { 379 print STDERR "\nError: Cannot install LaTeX2HTML style files in $cfg{TEXPATH}\n"; 380 } else { 381 my $dir = 'texinputs'; 382 my $dest = $cfg{TEXPATH}; 383 unless(opendir(DIR,$dir)) { 384 print STDERR qq{Error: Could not read directory "$dir": $!\n}; 385 } else { 386 my $file; 387 my $ok = 1; 388 while(defined($file = readdir(DIR))) { 389 my $full = "$dir/$file"; 390 next if($file =~ /^\.\.?$/ || !-f $full || !-s _); 391 unless(&install_file($full,$cfg{TEXPATH},$FILECHMOD,0)) { 392 $ok = 0; 393 last; 394 } 395 } 396 closedir(DIR); 397 if($ok && $cfg{MKTEXLSR}) { 398 print "Info: Running $cfg{MKTEXLSR} to rebuild ls-R database...\n"; 399 system($cfg{MKTEXLSR}); 400 } 401 } 402 } 403} 404print "Done. Have a lot of fun with LaTeX2HTML!\n"; 405exit 0; 406 407sub install_file { 408 my ($src,$dest,$chmod) = @_; 409 410 # prepend the value of DESTDIR, for package-managers 411 $dest = $ENV{'DESTDIR'}.$dest if($ENV{'DESTDIR'}); 412 my $mkdir = $dest; 413 414 my $file = $src; 415 $file =~ s:^.*/::; 416 my $full = "$dest$dd$file"; 417 418 $src =~ s:/:$dd:g; # insert correct dir delimiter 419 420 &mkpath($mkdir) || return 0; 421 L2hos->Unlink($full); # avoid overwriting the target of symlinks 422 unless(L2hos->Copy($src,$full)) { 423 return 0; 424 } elsif($chmod) { 425 unless(chmod($chmod,$full)) { 426 print STDERR qq{Warning: chmod of "$full" failed: $!\n}; 427 return 0; 428 } 429 } 430 print "Info: Installed $full\n"; 431 1; 432} 433 434sub install_recurse { 435 my ($dir,$dest,$chmod) = @_; 436 437 my $reldir = $dir; 438 $reldir =~ s:^.*/::; 439 440 unless(opendir(DIR,$dir)) { 441 print STDERR qq{Error: Could not read directory "$dir": $!\n}; 442 return 0; 443 } 444 my @subdirs = (); 445 my $item; 446 while(defined($item = readdir(DIR))) { 447 next if($item =~ /^(\.{1,2}|CVS)$/); 448 my $full = "$dir/$item"; 449 if(-d $full) { 450 push(@subdirs,$full); 451 } elsif(-s _) { 452 &install_file($full,"$dest$dd$reldir",$chmod); 453 } else { 454 print "Warning: Skipping $full\n"; 455 } 456 } 457 closedir(DIR); 458 foreach(@subdirs) { 459 &install_recurse($_,"$dest$dd$reldir",$chmod); 460 } 461 1; 462} 463 464sub mkpath { 465 my ($dir) = @_; 466 467 unless(-d $dir) { 468 if($dir =~ m#^(.*)[$dd$dd]([^$dd$dd]+)$#o) { 469 my $parent = $1; 470 $parent .= $dd unless($parent =~ /[$dd$dd]/o); 471 &mkpath($parent) || return 0; # error 472 unless(mkdir($dir,$DIRCHMOD)) { 473 print STDERR qq{Error: Could not create directory "$dir": $!\n}; 474 return 0; 475 } 476 } else { 477 print STDERR qq{Error: Cannot split directory "$dir"\n}; 478 return 0; 479 } 480 } 481 1; 482} 483 484