1#!./perl 2# $OpenBSD: installperl,v 1.13 2001/05/24 18:34:50 millert Exp $ 3# 4# This is hacked up, in order to support DESTDIR and INSTALL_STRIP. 5# 6 7BEGIN { 8 require 5.004; 9 chdir '..' if !-d 'lib' and -d '..\lib'; 10 @INC = 'lib'; 11 $ENV{PERL5LIB} = 'lib'; 12} 13 14use strict; 15my ($Is_VMS, $Is_W32, $Is_OS2, $Is_Cygwin, $Is_Darwin, 16 $nonono, $dostrip, $versiononly, $silent, $verbose, 17 $otherperls, $archname,$Is_NetWare, $nwinstall, $nopods); 18use vars qw /$depth/; 19 20BEGIN { 21 $Is_VMS = $^O eq 'VMS'; 22 $Is_W32 = $^O eq 'MSWin32'; 23 $Is_OS2 = $^O eq 'os2'; 24 $Is_Cygwin = $^O eq 'cygwin'; 25 $Is_Darwin = $^O eq 'darwin'; 26 if ($Is_VMS) { eval 'use VMS::Filespec;' } 27} 28 29my $scr_ext = ($Is_VMS ? '.Com' : $Is_W32 ? '.bat' : ''); 30 31use File::Find; 32use File::Compare; 33use File::Copy (); 34use File::Path (); 35use ExtUtils::Packlist; 36use Config; 37use subs qw(unlink link chmod cmd); 38 39if ($Config{d_umask}) { 40 umask(022); # umasks like 077 aren't that useful for installations 41} 42 43$Is_NetWare = $Config{osname} eq 'NetWare'; 44if ($Is_NetWare) { 45 $Is_W32 = 0; 46 $scr_ext = '.pl'; 47} 48 49# override the ones in the rest of the script 50sub mkpath { 51 File::Path::mkpath(@_) unless $nonono; 52} 53 54my $mainperldir = "/usr/bin"; 55my $exe_ext = $Config{exe_ext}; 56 57# Allow ``make install PERLNAME=something_besides_perl'': 58my $perl = defined($ENV{PERLNAME}) ? $ENV{PERLNAME} : 'perl'; 59 60# This is the base used for versioned names, like "perl5.6.0". 61# It's separate because a common use of $PERLNAME is to install 62# perl as "perl5", if that's used as base for versioned files you 63# get "perl55.6.0". 64my $perl_verbase = defined($ENV{PERLNAME_VERBASE}) 65 ? $ENV{PERLNAME_VERBASE} 66 : $perl; 67 68$otherperls = 1; 69while (@ARGV) { 70 $nonono = 1 if $ARGV[0] eq '-n'; 71 $dostrip = 1 if $ARGV[0] eq '-s'; 72 $versiononly = 1 if $ARGV[0] eq '-v'; 73 $versiononly = 0 if $ARGV[0] eq '+v'; 74 $silent = 1 if $ARGV[0] eq '-S'; 75 $otherperls = 0 if $ARGV[0] eq '-o'; 76 $verbose = 1 if $ARGV[0] eq '-V' || $ARGV [0] eq '-n'; 77 $archname = 1 if $ARGV[0] eq '-A'; 78 $nwinstall = 1 if $ARGV[0] eq '-netware'; 79 $nopods = 1 if $ARGV[0] eq '-p'; 80 if ($ARGV[0] eq '-?' or $ARGV[0] =~ /^-?-h/) { 81 print <<"EOT"; 82Usage $0: [switches] 83 -n Don't actually run any commands; just print them. 84 -s Run strip on installed binaries. 85 -v Only install perl as a binary with the version number in the name. 86 (Override whatever config.sh says) 87 +v Install perl as "perl" and as a binary with the version number in 88 the name. (Override whatever config.sh says) 89 -S Silent mode. 90 -o Skip checking for other copies of perl in your PATH. 91 -V Verbose mode. 92 -A Also install perl with the architecture's name in the perl binary's 93 name. 94 -p Don't install the pod files. [This will break use diagnostics;] 95 -netware Install correctly on a Netware server. 96EOT 97 exit; 98 } 99 shift; 100} 101 102$versiononly = 1 if $Config{versiononly} && !defined $versiononly; 103my (@scripts, @tolink); 104open SCRIPTS, "utils.lst" or die "Can't open utils.lst: $!"; 105while (<SCRIPTS>) { 106 next if /^#/; 107 next if /#\s*pod\s*=/; # Binary programs need separate treatment 108 chomp; 109 if (/(\S*)\s*#\s*link\s*=\s*(\S*)/) { 110 push @scripts, $1; 111 push @tolink, [$1, $2]; 112 } else { 113 push @scripts, $_; 114 } 115} 116close SCRIPTS; 117 118if ($scr_ext) { @scripts = map { "$_$scr_ext" } @scripts; } 119 120my @pods = $nopods ? () : (<pod/*.pod>); 121 122# Specify here any .pm files that are actually architecture-dependent. 123# (Those included with XS extensions under ext/ are automatically 124# added later.) 125# Now that the default privlib has the full perl version number included, 126# we no longer have to play the trick of sticking version-specific .pm 127# files under the archlib directory. 128my %archpms = ( 129 Config => 1, 130 lib => 1, 131 Cwd => 1, 132); 133 134if ($^O eq 'dos') { 135 push(@scripts,'djgpp/fixpmain'); 136 $archpms{config} = $archpms{filehand} = 1; 137} 138 139if ((-e "testcompile") && (defined($ENV{'COMPILE'}))) 140{ 141 push(@scripts, map("$_.exe", @scripts)); 142} 143 144find(sub { 145 if ("$File::Find::dir/$_" =~ m{^ext\b(.*)/([^/]+)\.pm$}) { 146 my($path, $modname) = ($1,$2); 147 148 # strip trailing component first 149 $path =~ s{/[^/]*$}{}; 150 151 # strip optional "/lib"; 152 $path =~ s{/lib\b}{}; 153 154 # strip any leading / 155 $path =~ s{^/}{}; 156 157 # reconstitute canonical module name 158 $modname = "$path/$modname" if length $path; 159 160 # remember it 161 $archpms{$modname} = 1; 162 } 163 }, 'ext'); 164 165# print "[$_]\n" for sort keys %archpms; 166 167my $ver = $Config{version}; 168my $release = substr($],0,3); # Not used currently. 169my $patchlevel = substr($],3,2); 170die "Patchlevel of perl ($patchlevel)", 171 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n" 172 if $patchlevel != $Config{'PERL_VERSION'}; 173 174my $installbin; 175my $installscript; 176my $installprivlib; 177my $installarchlib; 178my $installsitelib; 179my $installsitearch; 180my $installman1dir; 181my $installdest = $ENV{"DESTDIR"}; 182 183$installdest =~ s:/+$::; 184if ($installdest ne '') { 185 # Fetch some frequently-used items from %Config, prefixing with DESTDIR. 186 $installbin = "$installdest/$Config{installbin}"; 187 $installscript = "$installdest/$Config{installscript}"; 188 $installprivlib = "$installdest/$Config{installprivlib}"; 189 $installarchlib = "$installdest/$Config{installarchlib}"; 190 $installsitelib = "$installdest/$Config{installsitelib}"; 191 $installsitearch = "$installdest/$Config{installsitearch}"; 192 $installman1dir = "$installdest/$Config{installman1dir}"; 193 # Also whack $mainperldir. 194 $mainperldir = "$installdest/$mainperldir"; 195} else { 196 # Fetch some frequently-used items from %Config 197 $installbin = $Config{installbin}; 198 $installscript = $Config{installscript}; 199 $installprivlib = $Config{installprivlib}; 200 $installarchlib = $Config{installarchlib}; 201 $installsitelib = $Config{installsitelib}; 202 $installsitearch = $Config{installsitearch}; 203 $installman1dir = $Config{installman1dir}; 204} 205 206my $man1ext = $Config{man1ext}; 207my $libperl = $Config{libperl}; 208# Shared library and dynamic loading suffixes. 209my $so = $Config{so}; 210my $dlext = $Config{dlext}; 211my $dlsrc = $Config{dlsrc}; 212if ($^O eq 'os390') { 213 my $pwd; 214 chomp($pwd=`pwd`); 215 my $archlibexp = $Config{archlibexp}; 216 my $usedl = $Config{usedl}; 217 if ($usedl eq 'define') { 218 `./$^X -pibak -e 's{$pwd\/libperl.x}{$archlibexp/CORE/libperl.x}' lib/Config.pm`; 219 } 220} 221 222if ($nwinstall) { 223 # This is required only if we are installing on a NetWare server 224 $installscript = $Config{installnwscripts}; 225 $installprivlib = $Config{installnwlib}; 226 $installarchlib = $Config{installnwlib}; 227 $installsitelib = $Config{installnwlib}; 228} 229 230my $d_dosuid = $Config{d_dosuid}; 231my $binexp = $Config{binexp}; 232 233if ($Is_VMS) { # Hang in there until File::Spec hits the big time 234 foreach ( \$installbin, \$installscript, \$installprivlib, 235 \$installarchlib, \$installsitelib, \$installsitearch, 236 \$installman1dir ) { 237 $$_ = unixify($$_); $$_ =~ s:/$::; 238 } 239} 240 241# Do some quick sanity checks. 242 243if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; } 244 245 $installbin || die "No installbin directory in config.sh\n"; 246-d $installbin || mkpath($installbin, $verbose, 0777); 247-d $installbin || $nonono || die "$installbin is not a directory\n"; 248-w $installbin || $nonono || die "$installbin is not writable by you\n" 249 unless $installbin =~ m#^/afs/# || $nonono; 250 251if (!$Is_NetWare) { 252-x 'perl' . $exe_ext || die "perl isn't executable!\n"; 253-x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid; 254 255-f 't/rantests' || $Is_W32 256 || warn "WARNING: You've never run 'make test' or", 257 " some tests failed! (Installing anyway.)\n"; 258} #if (!$Is_NetWare) 259 260if (($Is_W32 and ! $Is_NetWare) or $Is_Cygwin) { 261 my $perldll; 262 263 if ($Is_Cygwin) { 264 $perldll = $libperl; 265 my $v_e_r_s = $ver; $v_e_r_s =~ tr/./_/; 266 $perldll =~ s/(\..*)?$/$v_e_r_s.$dlext/; 267 $perldll =~ s/^lib/cyg/; 268 if ($Config{useshrplib} eq 'true') { 269 # install ld2 and perlld as well 270 foreach ('ld2', 'perlld') { 271 safe_unlink("$installbin/$_"); 272 copy("$_", "$installbin/$_"); 273 chmod(0755, "$installbin/$_"); 274 }; 275 { 276 open (LD2, ">$installbin/ld2"); 277 print LD2 "#!/bin/sh\n#\n# ld wrapper, passes all args to perlld;\n#\n" 278 . "for trythis in $installbin/perl\ndo\n if [ -x \$trythis ]\n" 279 . " then\n \$trythis $installbin/perlld \"\$\@\"\n" 280 . " exit \$?\n fi\ndone\n# hard luck!\necho i see no perl" 281 . " executable around there\necho perl is required to build " 282 . "dynamic libraries\necho look if the path to perl in /bin/ld2" 283 . " is correct\nexit 1\n"; 284 close LD2; 285 }; 286 chmod(0755, "$installbin/ld2"); 287 }; 288 } else { 289 $perldll = 'perl58.' . $dlext; 290 } 291 292 if ($dlsrc ne "dl_none.xs") { 293 -f $perldll || die "No perl DLL built\n"; 294 } 295 # Install the DLL 296 297 safe_unlink("$installbin/$perldll"); 298 copy("$perldll", "$installbin/$perldll"); 299 chmod(0755, "$installbin/$perldll"); 300 301} # if (($Is_W32 and ! $Is_NetWare) or $Is_Cygwin) 302 303# This will be used to store the packlist 304my $packlist = ExtUtils::Packlist->new("$installarchlib/.packlist"); 305 306# Get the install command from the environment 307my $installcmd; 308if (defined($ENV{"INSTALL"})) { 309 $installcmd = $ENV{"INSTALL"} 310 . " " . $ENV{"INSTALL_COPY"} 311 . " " . $ENV{"INSTALL_STRIP"}; 312} else { 313 $installcmd = "cp"; 314} 315 316# First we install the version-numbered executables. 317if ($Is_VMS) { 318 safe_unlink("$installbin/$perl$exe_ext"); 319 copy("perl$exe_ext", "$installbin/$perl$exe_ext"); 320 chmod(0755, "$installbin/$perl$exe_ext"); 321 safe_unlink("$installbin/${perl}shr$exe_ext"); 322 copy("perlshr$exe_ext", "$installbin/${perl}shr$exe_ext"); 323 chmod(0755, "$installbin/${perl}shr$exe_ext"); 324} 325elsif ($^O eq 'mpeix') { 326 # MPE lacks hard links and requires that executables with special 327 # capabilities reside in the MPE namespace. 328 safe_unlink("$installbin/perl$ver$exe_ext", $Config{perlpath}); 329 # Install the primary executable into the MPE namespace as perlpath. 330 copy("perl$exe_ext", $Config{perlpath}); 331 chmod(0755, $Config{perlpath}); 332 # Create a backup copy with the version number. 333 link($Config{perlpath}, "$installbin/perl$ver$exe_ext"); 334} 335elsif ($^O ne 'dos') { 336 if (!$Is_NetWare) { 337 safe_unlink("$installbin/$perl_verbase$ver$exe_ext"); 338 #copy("perl$exe_ext", "$installbin/$perl_verbase$ver$exe_ext"); 339 cmd("$installcmd perl$exe_ext $installbin/$perl_verbase$ver$exe_ext"); 340 strip("$installbin/$perl_verbase$ver$exe_ext"); 341 chmod(0755, "$installbin/$perl_verbase$ver$exe_ext"); 342 } 343 else { 344 # If installing onto a NetWare server 345 if ($nwinstall) { 346 # Copy perl.nlm, echo.nlm, type.nlm, a2p.nlm & cgi2perl.nlm 347 mkpath($Config{installnwsystem}, 1, 0777); 348 copy("netware\\".$ENV{'MAKE_TYPE'}."\\perl.nlm", $Config{installnwsystem}); 349 copy("netware\\testnlm\\echo\\echo.nlm", $Config{installnwsystem}); 350 copy("netware\\testnlm\\type\\type.nlm", $Config{installnwsystem}); 351 copy("x2p\\a2p.nlm", $Config{installnwsystem}); 352 chmod(0755, "$Config{installnwsystem}\\perl.nlm"); 353 mkpath($Config{installnwlcgi}, 1, 0777); 354 copy("lib\\auto\\cgi2perl\\cgi2perl.nlm", $Config{installnwlcgi}); 355 } 356 } #if (!$Is_NetWare) 357} 358else { 359 safe_unlink("$installbin/$perl.exe"); 360 copy("perl.exe", "$installbin/$perl.exe"); 361} 362 363safe_unlink("$installbin/s$perl_verbase$ver$exe_ext"); 364if ($d_dosuid) { 365 #copy("suidperl$exe_ext", "$installbin/s$perl_verbase$ver$exe_ext"); 366 cmd("$installcmd suidperl$exe_ext $installbin/s$perl_verbase$ver$exe_ext"); 367 chmod(04711, "$installbin/s$perl_verbase$ver$exe_ext"); 368} 369 370# Install library files. 371 372my ($do_installarchlib, $do_installprivlib) = (0, 0); 373 374mkpath($installprivlib, $verbose, 0777); 375mkpath($installarchlib, $verbose, 0777); 376mkpath($installsitelib, $verbose, 0777) if ($installsitelib); 377mkpath($installsitearch, $verbose, 0777) if ($installsitearch); 378 379if (chdir "lib") { 380 $do_installarchlib = ! samepath($installarchlib, '.'); 381 $do_installprivlib = ! samepath($installprivlib, '.'); 382 $do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$ver/); 383 384 if ($do_installarchlib || $do_installprivlib) { 385 find(\&installlib, '.'); 386 } 387 chdir ".." || die "Can't cd back to source directory: $!\n"; 388} 389else { 390 warn "Can't cd to lib to install lib files: $!\n"; 391} 392 393# Install header files and libraries. 394mkpath("$installarchlib/CORE", $verbose, 0777); 395my @corefiles; 396if ($Is_VMS) { # We did core file selection during build 397 my $coredir = "lib/$Config{archname}/$ver/CORE"; 398 $coredir =~ tr/./_/; 399 map { s|^$coredir/||i; } @corefiles = <$coredir/*.*>; 400} 401else { 402 # [als] hard-coded 'libperl' name... not good! 403 #@corefiles = <*.h libperl*.*>; 404 @corefiles = <*.h>; 405 push(@corefiles,<libperl*.*>) unless defined($ENV{"NOLIBINSTALL"}); 406 407 # AIX needs perl.exp installed as well. 408 push(@corefiles,'perl.exp') if $^O eq 'aix'; 409 if ($^O eq 'mpeix') { 410 # MPE needs mpeixish.h installed as well. 411 mkpath("$installarchlib/CORE/mpeix", $verbose, 0777); 412 push(@corefiles,'mpeix/mpeixish.h'); 413 } 414 # If they have built sperl.o... 415 push(@corefiles,'sperl.o') if -f 'sperl.o'; 416} 417foreach my $file (@corefiles) { 418 # HP-UX (at least) needs to maintain execute permissions 419 # on dynamically-loadable libraries. So we do it for all. 420 if (copy_if_diff($file,"$installarchlib/CORE/$file")) { 421 if ($file =~ /\.(\Q$so\E|\Q$dlext\E)$/) { 422 strip("-S", "$installarchlib/CORE/$file") if $^O =~ /^(rhapsody|darwin)$/; 423 chmod(0555, "$installarchlib/CORE/$file"); 424 } else { 425 chmod(0444, "$installarchlib/CORE/$file"); 426 } 427 } 428} 429 430# Switch in the 5.005-threads versions of he threadsafe queue and semaphore 431# modules if so needed. 432if ($Config{use5005threads}) { 433 for my $m (qw(Queue Semaphore)) { 434 my $t = "$installprivlib/Thread/$m.pm"; 435 unlink $t; 436 copy("ext/Thread/$m.pmx", $t); 437 chmod(0444, $t); 438 } 439} 440 441# Install main perl executables 442# Make links to ordinary names if installbin directory isn't current directory. 443 444if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS && ! $Is_NetWare) { 445 safe_unlink("$installbin/$perl$exe_ext", "$installbin/suid$perl$exe_ext"); 446 if ($^O eq 'mpeix') { 447 # MPE doesn't support hard links, so use a symlink. 448 # We don't want another cloned copy. 449 symlink($Config{perlpath}, "$installbin/perl$exe_ext"); 450 } elsif ($^O eq 'vos') { 451 # VOS doesn't support hard links, so use a symlink. 452 symlink("$installbin/$perl_verbase$ver$exe_ext", 453 "$installbin/$perl$exe_ext"); 454 } else { 455 link("$installbin/$perl_verbase$ver$exe_ext", 456 "$installbin/$perl$exe_ext"); 457 } 458 link("$installbin/s$perl_verbase$ver$exe_ext", 459 "$installbin/suid$perl$exe_ext") 460 if $d_dosuid; 461} 462 463# For development purposes it can be very useful to have multiple perls 464# build for different "architectures" (eg threading or not) simultaneously. 465if ($archname && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS) { 466 my $archperl = "$perl_verbase$ver-$Config{archname}$exe_ext"; 467 safe_unlink("$installbin/$archperl"); 468 if ($^O eq 'mpeix') { 469 # MPE doesn't support hard links, so use a symlink. 470 # We don't want another cloned copy. 471 symlink($Config{perlpath}, "$installbin/$archperl"); 472 } elsif ($^O eq 'vos') { 473 # VOS doesn't support hard links, so use a symlink. 474 symlink("$installbin/$perl_verbase$ver$exe_ext", 475 "$installbin/$archperl"); 476 } else { 477 link("$installbin/$perl_verbase$ver$exe_ext", 478 "$installbin/$archperl"); 479 } 480} 481 482# Offer to install perl in a "standard" location 483 484my $mainperl_is_instperl = 0; 485 486if ($Config{installusrbinperl} && $Config{installusrbinperl} eq 'define' && 487 !$versiononly && !$nonono && !$Is_W32 && !$Is_NetWare && !$Is_VMS && -t STDIN && -t STDERR 488 && -w $mainperldir && ! samepath($mainperldir, $installbin)) { 489 my($usrbinperl) = "$mainperldir/$perl$exe_ext"; 490 my($instperl) = "$installbin/$perl$exe_ext"; 491 my($expinstperl) = "$binexp/$perl$exe_ext"; 492 493 # First make sure $usrbinperl is not already the same as the perl we 494 # just installed. 495 if (-x $usrbinperl) { 496 # Try to be clever about mainperl being a symbolic link 497 # to binexp/perl if binexp and installbin are different. 498 $mainperl_is_instperl = 499 samepath($usrbinperl, $instperl) || 500 samepath($usrbinperl, $expinstperl) || 501 (($binexp ne $installbin) && 502 (-l $usrbinperl) && 503 ((readlink $usrbinperl) eq $expinstperl)); 504 } 505 if (! $mainperl_is_instperl) { 506 unlink($usrbinperl); 507 ( $Config{'d_link'} eq 'define' && 508 eval { CORE::link $instperl, $usrbinperl } ) || 509 eval { symlink $expinstperl, $usrbinperl } || 510 copy($instperl, $usrbinperl); 511 512 $mainperl_is_instperl = 1; 513 } 514} 515 516# Make links to ordinary names if installbin directory isn't current directory. 517if (!$Is_NetWare) { 518 if (!$versiononly && ! samepath($installbin, 'x2p')) { 519 safe_unlink("$installbin/a2p$exe_ext"); 520 #copy("x2p/a2p$exe_ext", "$installbin/a2p$exe_ext"); 521 cmd("$installcmd x2p/a2p$exe_ext $installbin/a2p$exe_ext"); 522 strip("$installbin/a2p$exe_ext"); 523 chmod(0755, "$installbin/a2p$exe_ext"); 524 } 525} 526 527# cppstdin is just a script, but it is architecture-dependent, so 528# it can't safely be shared. Place it in $installbin. 529# Note that Configure doesn't build cppstin if it isn't needed, so 530# we skip this if cppstdin doesn't exist. 531if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) { 532 safe_unlink("$installbin/cppstdin"); 533 copy("cppstdin", "$installbin/cppstdin"); 534 chmod(0755, "$installbin/cppstdin"); 535} 536 537sub script_alias { 538 my ($installscript, $orig, $alias, $scr_ext) = @_; 539 540 safe_unlink("$installscript/$alias$scr_ext"); 541 if ($^O eq 'dos' or $Is_VMS or $^O eq 'transit') { 542 copy("$installscript/$orig$scr_ext", 543 "$installscript/$alias$scr_ext"); 544 } elsif ($^O eq 'vos') { 545 symlink("$installscript/$orig$scr_ext", 546 "$installscript/$alias$scr_ext"); 547 } else { 548 link("$installscript/$orig$scr_ext", 549 "$installscript/$alias$scr_ext"); 550 } 551} 552 553# Install scripts. 554mkpath($installscript, $verbose, 0777); 555if ($versiononly) { 556 for (@scripts) { 557 (my $base = $_) =~ s#.*/##; 558 $base .= $ver; 559 copy($_, "$installscript/$base"); 560 chmod(0755, "$installscript/$base"); 561 } 562 563 for (@tolink) { 564 my ($from, $to) = map { "$_$ver" } @$_; 565 (my $frbase = $from) =~ s#.*/##; 566 (my $tobase = $to) =~ s#.*/##; 567 script_alias($installscript, $frbase, $tobase, $scr_ext); 568 } 569} else { 570 for (@scripts) { 571 (my $base = $_) =~ s#.*/##; 572 copy($_, "$installscript/$base"); 573 chmod(0755, "$installscript/$base"); 574 } 575 576 for (@tolink) { 577 my ($from, $to) = @$_; 578 (my $frbase = $from) =~ s#.*/##; 579 (my $tobase = $to) =~ s#.*/##; 580 script_alias($installscript, $frbase, $tobase, $scr_ext); 581 } 582} 583 584# Install pod pages. Where? I guess in $installprivlib/pod 585# ($installprivlib/pods for cygwin). 586 587my $pod = ($Is_Cygwin || $Is_Darwin) ? 'pods' : 'pod'; 588if ( !$versiononly || ($installprivlib =~ m/\Q$ver/)) { 589 mkpath("${installprivlib}/$pod", $verbose, 0777); 590 591 # If Perl 5.003's perldiag.pod is there, rename it. 592 if (open POD, "${installprivlib}/$pod/perldiag.pod") { 593 read POD, $_, 4000; 594 close POD; 595 # Some of Perl 5.003's diagnostic messages ended with periods. 596 if (/^=.*\.$/m) { 597 my ($from, $to) = ("${installprivlib}/$pod/perldiag.pod", 598 "${installprivlib}/$pod/perldiag-5.003.pod"); 599 print " rename $from $to"; 600 rename($from, $to) 601 or warn "Couldn't rename $from to $to: $!\n" 602 unless $nonono; 603 } 604 } 605 606 for (@pods) { 607 # $_ is a name like pod/perl.pod 608 (my $base = $_) =~ s#.*/##; 609 copy_if_diff($_, "${installprivlib}/$pod/${base}"); 610 } 611 612} 613 614# Check to make sure there aren't other perls around in installer's 615# path. This is probably UNIX-specific. Check all absolute directories 616# in the path except for where public executables are supposed to live. 617# Also skip $mainperl if the user opted to have it be a link to the 618# installed perl. 619 620if (!$versiononly && $otherperls) { 621 my ($path, @path); 622 my $dirsep = ($Is_OS2 || $Is_W32 || $Is_NetWare) ? ';' : ':' ; 623 ($path = $ENV{"PATH"}) =~ s:\\:/:g ; 624 @path = split(/$dirsep/, $path); 625 if ($Is_VMS) { 626 my $i = 0; 627 while (exists $ENV{'DCL$PATH' . $i}) { 628 my $dir = unixpath($ENV{'DCL$PATH' . $i}); $dir =~ s-/$--; 629 push(@path,$dir); 630 } 631 } 632 my @otherperls; 633 my %otherperls; 634 for (@path) { 635 next unless m,^/,; 636 # Use &samepath here because some systems have other dirs linked 637 # to $mainperldir (like SunOS) 638 next if samepath($_, $binexp); 639 next if ($mainperl_is_instperl && samepath($_, $mainperldir)); 640 my $otherperl = "$_/$perl$exe_ext"; 641 next if $otherperls{$otherperl}++; 642 push(@otherperls, $otherperl) 643 if (-x $otherperl && ! -d $otherperl); 644 } 645 if (@otherperls) { 646 warn "\nWarning: $perl appears in your path in the following " . 647 "locations beyond where\nwe just installed it:\n"; 648 for (@otherperls) { 649 warn " ", $_, "\n"; 650 } 651 warn "\n"; 652 } 653 654} 655 656$packlist->write() unless $nonono; 657print " Installation complete\n" if $verbose; 658 659exit 0; 660 661############################################################################### 662 663sub yn { 664 my($prompt) = @_; 665 my($answer); 666 my($default) = $prompt =~ m/\[([yn])\]\s*$/i; 667 print STDERR $prompt; 668 chop($answer = <STDIN>); 669 $answer = $default if $answer =~ m/^\s*$/; 670 ($answer =~ m/^[yY]/); 671} 672 673sub unlink { 674 my(@names) = @_; 675 my($cnt) = 0; 676 677 return scalar(@names) if $Is_VMS; 678 679 foreach my $name (@names) { 680 next unless -e $name; 681 chmod 0777, $name if ($Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare); 682 print " unlink $name\n" if $verbose; 683 ( CORE::unlink($name) and ++$cnt 684 or warn "Couldn't unlink $name: $!\n" ) unless $nonono; 685 } 686 return $cnt; 687} 688 689sub safe_unlink { 690 return if $nonono or $Is_VMS; 691 my @names = @_; 692 foreach my $name (@names) { 693 next unless -e $name; 694 chmod 0777, $name if ($Is_OS2 || $Is_W32 || $Is_NetWare); 695 print " unlink $name\n" if $verbose; 696 next if CORE::unlink($name); 697 warn "Couldn't unlink $name: $!\n"; 698 if ($! =~ /busy/i) { 699 print " mv $name $name.old\n" if $verbose; 700 safe_rename($name, "$name.old") 701 or warn "Couldn't rename $name: $!\n"; 702 } 703 } 704} 705 706sub safe_rename { 707 my($from,$to) = @_; 708 if (-f $to and not unlink($to)) { 709 my($i); 710 for ($i = 1; $i < 50; $i++) { 711 last if rename($to, "$to.$i"); 712 } 713 warn("Cannot rename to `$to.$i': $!"), return 0 714 if $i >= 50; # Give up! 715 } 716 link($from,$to) || return 0; 717 unlink($from); 718} 719 720sub link { 721 my($from,$to) = @_; 722 my($success) = 0; 723 724 print $verbose ? " ln $from $to\n" : " $to\n" unless $silent; 725 eval { 726 CORE::link($from, $to) 727 ? $success++ 728 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#) 729 ? die "AFS" # okay inside eval {} 730 : die "Couldn't link $from to $to: $!\n" 731 unless $nonono; 732 $packlist->{$to} = { from => $from, type => 'link' }; 733 }; 734 if ($@) { 735 warn $@; 736 print $verbose ? " cp $from $to\n" : " $to\n" unless $silent; 737 print " creating new version of $to\n" 738 if $Is_VMS and -e $to and !$silent; 739 File::Copy::copy($from, $to) 740 ? $success++ 741 : warn "Couldn't copy $from to $to: $!\n" 742 unless $nonono; 743 $packlist->{$to} = { type => 'file' }; 744 } 745 $success; 746} 747 748sub cmd { 749 my($cmd) = @_; 750 print STDERR " $cmd\n"; 751 unless ($nonono) { 752 system $cmd; 753 warn "Command failed!!!\n" if $?; 754 } 755} 756 757sub chmod { 758 my($mode,$name) = @_; 759 760 return if ($^O eq 'dos'); 761 printf " chmod %o %s\n", $mode, $name if $verbose; 762 CORE::chmod($mode,$name) 763 || warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name) 764 unless $nonono; 765} 766 767sub copy { 768 my($from,$to) = @_; 769 770 print $verbose ? " cp $from $to\n" : " $to\n" unless $silent; 771 print " creating new version of $to\n" if $Is_VMS and -e $to and !$silent; 772 File::Copy::copy($from, $to) 773 || warn "Couldn't copy $from to $to: $!\n" 774 unless $nonono; 775 $packlist->{$to} = { type => 'file' }; 776} 777 778sub samepath { 779 my($p1, $p2) = @_; 780 781 return (lc($p1) eq lc($p2)) if ($Is_W32 || $Is_NetWare); 782 783 if ($p1 ne $p2) { 784 my($dev1, $ino1, $dev2, $ino2); 785 ($dev1, $ino1) = stat($p1); 786 ($dev2, $ino2) = stat($p2); 787 ($dev1 == $dev2 && $ino1 == $ino2); 788 } 789 else { 790 1; 791 } 792} 793 794sub installlib { 795 my $dir = $File::Find::dir; 796 $dir =~ s#^\.(?![^/])/?##; 797 local($depth) = $dir ? "lib/$dir" : "lib"; 798 799 my $name = $_; 800 801 # Ignore RCS and CVS directories. 802 if (($name eq 'CVS' or $name eq 'RCS') and -d $name) { 803 $File::Find::prune = 1; 804 return; 805 } 806 807 # ignore patch backups, RCS files, emacs backup & temp files and the 808 # .exists files, .PL files, and .t files. 809 return if $name =~ m{\.orig$|~$|^#.+#$|,v$|^\.exists|\.PL$|\.t$} || 810 $dir =~ m{/t(?:/|$)}; 811 # ignore the test extensions 812 return if $dir =~ m{ext/XS/(?:APItest|Typemap)/}; 813 814 $name = "$dir/$name" if $dir ne ''; 815 816 my $installlib = $installprivlib; 817 if ($dir =~ /^auto/ || 818 ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) || 819 ($name =~ /^(.*)\.(?:h|lib)$/i && ($Is_W32 || $Is_NetWare)) 820 ) { 821 $installlib = $installarchlib; 822 return unless $do_installarchlib; 823 } else { 824 return unless $do_installprivlib; 825 } 826 827 if (-f $_) { 828 if (/\.(?:al|ix)$/ && !($dir =~ m[^auto/(.*)$] && $archpms{$1})) { 829 $installlib = $installprivlib; 830 #We're installing *.al and *.ix files into $installprivlib, 831 #but we have to delete old *.al and *.ix files from the 5.000 832 #distribution: 833 #This might not work because $archname might have changed. 834 unlink("$installarchlib/$name"); 835 } 836 $packlist->{"$installlib/$name"} = { type => 'file' }; 837 if (compare($_, "$installlib/$name") || $nonono) { 838 unlink("$installlib/$name"); 839 mkpath("$installlib/$dir", $verbose, 0777); 840 # HP-UX (at least) needs to maintain execute permissions 841 # on dynamically-loaded libraries. 842 if ($Is_NetWare && !$nwinstall) { 843 # Don't copy .nlp,.nlm files, doesn't make sense on Windows and also 844 # if copied will give problems when building new extensions. 845 # Has to be copied if we are installing on a NetWare server and hence 846 # the check !$nwinstall 847 if (!(/\.(?:nlp|nlm|bs)$/)) { 848 copy_if_diff($_, "$installlib/$name") 849 and chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444, 850 "$installlib/$name"); 851 } 852 } else { 853 if (copy_if_diff($_, "$installlib/$name")) { 854 if ($name =~ /\.(so|$dlext)$/o) { 855 strip("-S", "$installlib/$name") if $^O =~ /^(rhapsody|darwin)$/; 856 chmod(0555, "$installlib/$name"); 857 } else { 858 strip("-S", "$installlib/$name") 859 if ($name =~ /\.a$/o and $^O =~ /^(rhapsody|darwin)$/); 860 chmod(0444, "$installlib/$name"); 861 } 862 } 863 } #if ($Is_NetWare) 864 } 865 } 866} 867 868# Copy $from to $to, only if $from is different than $to. 869# Also preserve modification times for .a libraries. 870# On some systems, if you do 871# ranlib libperl.a 872# cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a 873# and then try to link against the installed libperl.a, you might 874# get an error message to the effect that the symbol table is older 875# than the library. 876# Return true if copying occurred. 877 878sub copy_if_diff { 879 my($from,$to)=@_; 880 return 1 if (($^O eq 'VMS') && (-d $from)); 881 my $perlpodbadsymlink; 882 if ($from =~ m!^pod/perl[\w-]+\.pod$! && 883 -l $from && 884 ! -e $from) { 885 # Some Linux implementations have problems traversing over 886 # multiple symlinks (when going over NFS?) and fail to read 887 # the symlink target. Combine this with the fact that some 888 # of the pod files (the perl$OS.pod) are symlinks (to ../README.$OS), 889 # and you end up with those pods not getting installed. 890 $perlpodbadsymlink = 1; 891 } 892 -f $from || $perlpodbadsymlink || warn "$0: $from not found"; 893 $packlist->{$to} = { type => 'file' }; 894 if (compare($from, $to) || $nonono) { 895 safe_unlink($to); # In case we don't have write permissions. 896 if ($nonono) { 897 $from = $depth . "/" . $from if $depth; 898 } 899 if ($perlpodbadsymlink && $from =~ m!^pod/perl(.+)\.pod$!) { 900 $from = "README.$1"; 901 } 902 copy($from, $to); 903 # Restore timestamps if it's a .a library or for OS/2. 904 if (!$nonono && ($Is_OS2 || $to =~ /\.a$/)) { 905 my ($atime, $mtime) = (stat $from)[8,9]; 906 utime $atime, $mtime, $to; 907 } 908 1; 909 } 910} 911 912sub strip 913{ 914 my(@args) = @_; 915 916 return unless $dostrip; 917 918 my @opts; 919 while (@args && $args[0] =~ /^(-\w+)$/) { 920 push @opts, shift @args; 921 } 922 923 foreach my $file (@args) { 924 if (-f $file) { 925 if ($verbose) { 926 print " strip " . join(' ', @opts); 927 print " " if (@opts); 928 print "$file\n"; 929 } 930 system("strip", @opts, $file); 931 } else { 932 print "# file '$file' skipped\n" if $verbose; 933 } 934 } 935} 936