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