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