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