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