1#!./perl 2# $OpenBSD: installperl,v 1.12 2000/04/06 17:03:58 millert Exp $ 3# 4# This is hacked up, in order to support DESTDIR and INSTALL_STRIP. 5# 6 7BEGIN { 8 require 5.004; 9 chdir '..' if !-d 'lib' and -d '..\lib'; 10 @INC = 'lib'; 11 $ENV{PERL5LIB} = 'lib'; 12} 13 14use strict; 15my ($Is_VMS, $Is_W32, $Is_OS2, $Is_Cygwin, $nonono, $dostrip, 16 $versiononly, $silent, $verbose, $otherperls); 17use vars qw /$depth/; 18 19BEGIN { 20 $Is_VMS = $^O eq 'VMS'; 21 $Is_W32 = $^O eq 'MSWin32'; 22 $Is_OS2 = $^O eq 'os2'; 23 $Is_Cygwin = $^O eq 'cygwin'; 24 if ($Is_VMS) { eval 'use VMS::Filespec;' } 25} 26 27my $scr_ext = ($Is_VMS ? '.Com' : $Is_W32 ? '.bat' : ''); 28 29use File::Find; 30use File::Compare; 31use File::Copy (); 32use File::Path (); 33use ExtUtils::Packlist; 34use Config; 35use subs qw(unlink link chmod cmd); 36 37# override the ones in the rest of the script 38sub mkpath { 39 File::Path::mkpath(@_) unless $nonono; 40} 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; 55 56$otherperls = 1; 57while (@ARGV) { 58 $nonono = 1 if $ARGV[0] eq '-n'; 59 $dostrip = 1 if $ARGV[0] eq '-s'; 60 $versiononly = 1 if $ARGV[0] eq '-v'; 61 $silent = 1 if $ARGV[0] eq '-S'; 62 $otherperls = 0 if $ARGV[0] eq '-o'; 63 $verbose = 1 if $ARGV[0] eq '-V' || $ARGV [0] eq '-n'; 64 shift; 65} 66 67$versiononly = 1 if $Config{versiononly}; 68 69my @scripts = qw(utils/c2ph utils/h2ph utils/h2xs utils/perlbug utils/perldoc 70 utils/pl2pm utils/splain utils/perlcc utils/dprofpp 71 x2p/s2p x2p/find2perl 72 pod/pod2man pod/pod2html pod/pod2latex pod/pod2text 73 pod/pod2usage pod/podchecker pod/podselect); 74 75if ($scr_ext) { @scripts = map { "$_$scr_ext" } @scripts; } 76 77my @pods = (<pod/*.pod>); 78 79# Specify here any .pm files that are actually architecture-dependent. 80# (Those included with XS extensions under ext/ are automatically 81# added later.) 82# Now that the default privlib has the full perl version number included, 83# we no longer have to play the trick of sticking version-specific .pm 84# files under the archlib directory. 85my %archpms = ( 86 Config => 1, 87); 88 89if ($^O eq 'dos') { 90 push(@scripts,'djgpp/fixpmain'); 91 $archpms{config} = $archpms{filehand} = 1; 92} 93 94if ((-e "testcompile") && (defined($ENV{'COMPILE'}))) 95{ 96 push(@scripts, map("$_.exe", @scripts)); 97} 98 99find(sub { 100 if ("$File::Find::dir/$_" =~ m{^ext\b(.*)/([^/]+)\.pm$}) { 101 my($path, $modname) = ($1,$2); 102 103 # strip trailing component first 104 $path =~ s{/[^/]*$}{}; 105 106 # strip optional "/lib"; 107 $path =~ s{/lib\b}{}; 108 109 # strip any leading / 110 $path =~ s{^/}{}; 111 112 # reconstitute canonical module name 113 $modname = "$path/$modname" if length $path; 114 115 # remember it 116 $archpms{$modname} = 1; 117 } 118 }, 'ext'); 119 120# print "[$_]\n" for sort keys %archpms; 121 122my $ver = $Config{version}; 123my $release = substr($],0,3); # Not used currently. 124my $patchlevel = substr($],3,2); 125die "Patchlevel of perl ($patchlevel)", 126 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n" 127 if $patchlevel != $Config{'PERL_VERSION'}; 128 129my $installbin; 130my $installscript; 131my $installprivlib; 132my $installarchlib; 133my $installsitelib; 134my $installsitearch; 135my $installman1dir; 136my $installdest = $ENV{"DESTDIR"}; 137 138$installdest =~ s:/+$::; 139if ($installdest ne '') { 140 # Fetch some frequently-used items from %Config, prefixing with DESTDIR. 141 $installbin = "$installdest/$Config{installbin}"; 142 $installscript = "$installdest/$Config{installscript}"; 143 $installprivlib = "$installdest/$Config{installprivlib}"; 144 $installarchlib = "$installdest/$Config{installarchlib}"; 145 $installsitelib = "$installdest/$Config{installsitelib}"; 146 $installsitearch = "$installdest/$Config{installsitearch}"; 147 $installman1dir = "$installdest/$Config{installman1dir}"; 148 # Also whack $mainperldir. 149 $mainperldir = "$installdest/$mainperldir"; 150} else { 151 # Fetch some frequently-used items from %Config 152 $installbin = $Config{installbin}; 153 $installscript = $Config{installscript}; 154 $installprivlib = $Config{installprivlib}; 155 $installarchlib = $Config{installarchlib}; 156 $installsitelib = $Config{installsitelib}; 157 $installsitearch = $Config{installsitearch}; 158 $installman1dir = $Config{installman1dir}; 159} 160 161my $man1ext = $Config{man1ext}; 162my $libperl = $Config{libperl}; 163# Shared library and dynamic loading suffixes. 164my $so = $Config{so}; 165my $dlext = $Config{dlext}; 166my $dlsrc = $Config{dlsrc}; 167if ($^O eq 'os390') { 168 my $usedl = $Config{usedl}; 169 if ($usedl eq 'define') { 170 my $pwd; 171 chomp($pwd=`pwd`); 172 my $archlibexp = $Config{archlibexp}; 173 `./$^X -p -e 's{$pwd\/libperl.x}{$archlibexp/CORE/libperl.x}' lib/Config.pm`; 174 } 175} 176 177my $d_dosuid = $Config{d_dosuid}; 178my $binexp = $Config{binexp}; 179 180if ($Is_VMS) { # Hang in there until File::Spec hits the big time 181 foreach ( \$installbin, \$installscript, \$installprivlib, 182 \$installarchlib, \$installsitelib, \$installsitearch, 183 \$installman1dir ) { 184 $$_ = unixify($$_); $$_ =~ s:/$::; 185 } 186} 187 188# Do some quick sanity checks. 189 190if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; } 191 192 $installbin || die "No installbin directory in config.sh\n"; 193-d $installbin || mkpath($installbin, $verbose, 0777); 194-d $installbin || $nonono || die "$installbin is not a directory\n"; 195-w $installbin || $nonono || die "$installbin is not writable by you\n" 196 unless $installbin =~ m#^/afs/# || $nonono; 197 198-x 'perl' . $exe_ext || die "perl isn't executable!\n"; 199-x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid; 200 201-f 't/rantests' || $Is_W32 202 || warn "WARNING: You've never run 'make test'!!!", 203 " (Installing anyway.)\n"; 204 205if ($Is_W32 or $Is_Cygwin) { 206 my $perldll; 207 208 if ($Is_Cygwin) { 209 $perldll = $libperl; 210 $perldll =~ s/(\..*)?$/.$dlext/; 211 if ($Config{useshrplib} eq 'true') { 212 # install ld2 and perlld as well 213 foreach ('ld2', 'perlld') { 214 safe_unlink("$installbin/$_"); 215 copy("$_", "$installbin/$_"); 216 chmod(0755, "$installbin/$_"); 217 }; 218 }; 219 } else { 220 $perldll = 'perl56.' . $dlext; 221 } 222 223 if ($dlsrc ne "dl_none.xs") { 224 -f $perldll || die "No perl DLL built\n"; 225 } 226 # Install the DLL 227 228 safe_unlink("$installbin/$perldll"); 229 copy("$perldll", "$installbin/$perldll"); 230 chmod(0755, "$installbin/$perldll"); 231 232} # if ($Is_W32 or $Is_Cygwin) 233 234# This will be used to store the packlist 235my $packlist = ExtUtils::Packlist->new("$installarchlib/.packlist"); 236 237# Get the install command from the environment 238my $installcmd; 239if (defined($ENV{"INSTALL"})) { 240 $installcmd = $ENV{"INSTALL"} 241 . " " . $ENV{"INSTALL_COPY"} 242 . " " . $ENV{"INSTALL_STRIP"}; 243} else { 244 $installcmd = "cp"; 245} 246 247# First we install the version-numbered executables. 248if ($Is_VMS) { 249 safe_unlink("$installbin/$perl$exe_ext"); 250 copy("perl$exe_ext", "$installbin/$perl$exe_ext"); 251 chmod(0755, "$installbin/$perl$exe_ext"); 252 safe_unlink("$installbin/${perl}shr$exe_ext"); 253 copy("perlshr$exe_ext", "$installbin/${perl}shr$exe_ext"); 254 chmod(0755, "$installbin/${perl}shr$exe_ext"); 255} 256elsif ($^O eq 'mpeix') { 257 # MPE lacks hard links and requires that executables with special 258 # capabilities reside in the MPE namespace. 259 safe_unlink("$installbin/perl$ver$exe_ext", $Config{perlpath}); 260 # Install the primary executable into the MPE namespace as perlpath. 261 copy("perl$exe_ext", $Config{perlpath}); 262 chmod(0755, $Config{perlpath}); 263 # Create a backup copy with the version number. 264 link($Config{perlpath}, "$installbin/perl$ver$exe_ext"); 265} 266elsif ($^O ne 'dos') { 267 safe_unlink("$installbin/$perl_verbase$ver$exe_ext"); 268 #copy("perl$exe_ext", "$installbin/$perl_verbase$ver$exe_ext"); 269 cmd("$installcmd perl$exe_ext $installbin/$perl_verbase$ver$exe_ext"); 270 strip("$installbin/$perl_verbase$ver$exe_ext"); 271 chmod(0755, "$installbin/$perl_verbase$ver$exe_ext"); 272} 273else { 274 safe_unlink("$installbin/$perl.exe"); 275 copy("perl.exe", "$installbin/$perl.exe"); 276} 277 278safe_unlink("$installbin/s$perl_verbase$ver$exe_ext"); 279if ($d_dosuid) { 280 #copy("suidperl$exe_ext", "$installbin/s$perl_verbase$ver$exe_ext"); 281 cmd("$installcmd suidperl$exe_ext $installbin/s$perl_verbase$ver$exe_ext"); 282 chmod(04711, "$installbin/s$perl_verbase$ver$exe_ext"); 283} 284 285# Install library files. 286 287my ($do_installarchlib, $do_installprivlib) = (0, 0); 288 289mkpath($installprivlib, $verbose, 0777); 290mkpath($installarchlib, $verbose, 0777); 291mkpath($installsitelib, $verbose, 0777) if ($installsitelib); 292mkpath($installsitearch, $verbose, 0777) if ($installsitearch); 293 294if (chdir "lib") { 295 $do_installarchlib = ! samepath($installarchlib, '.'); 296 $do_installprivlib = ! samepath($installprivlib, '.'); 297 $do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$ver/); 298 299 if ($do_installarchlib || $do_installprivlib) { 300 find(\&installlib, '.'); 301 } 302 chdir ".." || die "Can't cd back to source directory: $!\n"; 303} 304else { 305 warn "Can't cd to lib to install lib files: $!\n"; 306} 307 308# Install header files and libraries. 309mkpath("$installarchlib/CORE", $verbose, 0777); 310my @corefiles; 311if ($Is_VMS) { # We did core file selection during build 312 my $coredir = "lib/$Config{archname}/$ver/CORE"; 313 $coredir =~ tr/./_/; 314 map { s|^$coredir/||i; } @corefiles = <$coredir/*.*>; 315} 316else { 317 # [als] hard-coded 'libperl' name... not good! 318 #@corefiles = <*.h libperl*.*>; 319 @corefiles = <*.h>; 320 push(@corefiles,<libperl*.*>) unless defined($ENV{"NOLIBINSTALL"}); 321 322 # AIX needs perl.exp installed as well. 323 push(@corefiles,'perl.exp') if $^O eq 'aix'; 324 if ($^O eq 'mpeix') { 325 # MPE needs mpeixish.h installed as well. 326 mkpath("$installarchlib/CORE/mpeix", $verbose, 0777); 327 push(@corefiles,'mpeix/mpeixish.h'); 328 } 329 # If they have built sperl.o... 330 push(@corefiles,'sperl.o') if -f 'sperl.o'; 331} 332foreach my $file (@corefiles) { 333 # HP-UX (at least) needs to maintain execute permissions 334 # on dynamically-loadable libraries. So we do it for all. 335 if (copy_if_diff($file,"$installarchlib/CORE/$file")) { 336 if ($file =~ /\.(\Q$so\E|\Q$dlext\E)$/) { 337 chmod(0555, "$installarchlib/CORE/$file"); 338 strip("-S", "$installarchlib/CORE/$file") if $^O =~ /^(rhapsody|darwin)$/; 339 } else { 340 chmod(0444, "$installarchlib/CORE/$file"); 341 } 342 } 343} 344 345# Install main perl executables 346# Make links to ordinary names if installbin directory isn't current directory. 347 348if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS) { 349 safe_unlink("$installbin/$perl$exe_ext", "$installbin/suid$perl$exe_ext"); 350 if ($^O eq 'mpeix') { 351 # MPE doesn't support hard links, so use a symlink. 352 # We don't want another cloned copy. 353 symlink($Config{perlpath}, "$installbin/perl$exe_ext"); 354 } else { 355 link("$installbin/$perl_verbase$ver$exe_ext", 356 "$installbin/$perl$exe_ext"); 357 } 358 link("$installbin/s$perl_verbase$ver$exe_ext", 359 "$installbin/suid$perl$exe_ext") 360 if $d_dosuid; 361} 362 363# Offer to install perl in a "standard" location 364 365my $mainperl_is_instperl = 0; 366 367if ($Config{installusrbinperl} && $Config{installusrbinperl} eq 'define' && 368 !$versiononly && !$nonono && !$Is_W32 && !$Is_VMS && -t STDIN && -t STDERR 369 && -w $mainperldir && ! samepath($mainperldir, $installbin)) { 370 my($usrbinperl) = "$mainperldir/$perl$exe_ext"; 371 my($instperl) = "$installbin/$perl$exe_ext"; 372 my($expinstperl) = "$binexp/$perl$exe_ext"; 373 374 # First make sure $usrbinperl is not already the same as the perl we 375 # just installed. 376 if (-x $usrbinperl) { 377 # Try to be clever about mainperl being a symbolic link 378 # to binexp/perl if binexp and installbin are different. 379 $mainperl_is_instperl = 380 samepath($usrbinperl, $instperl) || 381 samepath($usrbinperl, $expinstperl) || 382 (($binexp ne $installbin) && 383 (-l $usrbinperl) && 384 ((readlink $usrbinperl) eq $expinstperl)); 385 } 386 if ((! $mainperl_is_instperl) && 387 (yn("Many scripts expect perl to be installed as $usrbinperl.\n" . 388 "Do you wish to have $usrbinperl be the same as\n" . 389 "$expinstperl? [y] "))) 390 { 391 unlink($usrbinperl); 392 ( $Config{'d_link'} eq 'define' && 393 eval { CORE::link $instperl, $usrbinperl } ) || 394 eval { symlink $expinstperl, $usrbinperl } || 395 copy($instperl, $usrbinperl); 396 397 $mainperl_is_instperl = 1; 398 } 399} 400 401# Make links to ordinary names if installbin directory isn't current directory. 402 403if (!$versiononly && ! samepath($installbin, 'x2p')) { 404 safe_unlink("$installbin/a2p$exe_ext"); 405 #copy("x2p/a2p$exe_ext", "$installbin/a2p$exe_ext"); 406 cmd("$installcmd x2p/a2p$exe_ext $installbin/a2p$exe_ext"); 407 chmod(0755, "$installbin/a2p$exe_ext"); 408} 409 410# cppstdin is just a script, but it is architecture-dependent, so 411# it can't safely be shared. Place it in $installbin. 412# Note that Configure doesn't build cppstin if it isn't needed, so 413# we skip this if cppstdin doesn't exist. 414if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) { 415 safe_unlink("$installbin/cppstdin"); 416 copy("cppstdin", "$installbin/cppstdin"); 417 chmod(0755, "$installbin/cppstdin"); 418} 419 420if (! $versiononly) { 421 # Install scripts. 422 423 mkpath($installscript, $verbose, 0777); 424 425 for (@scripts) { 426 (my $base = $_) =~ s#.*/##; 427 copy($_, "$installscript/$base"); 428 chmod(0755, "$installscript/$base"); 429 } 430 431 # pstruct should be a link to c2ph 432 safe_unlink("$installscript/pstruct$scr_ext"); 433 if ($^O eq 'dos' or $Is_VMS or $^O eq 'transit') { 434 copy("$installscript/c2ph$scr_ext", 435 "$installscript/pstruct$scr_ext"); 436 } else { 437 link("$installscript/c2ph$scr_ext", 438 "$installscript/pstruct$scr_ext"); 439 } 440} 441 442# Install pod pages. Where? I guess in $installprivlib/pod 443# ($installprivlib/pods for cygwin). 444 445my $pod = $Is_Cygwin ? 'pods' : 'pod'; 446if ( !$versiononly || ($installprivlib =~ m/\Q$ver/)) { 447 mkpath("${installprivlib}/$pod", $verbose, 0777); 448 449 # If Perl 5.003's perldiag.pod is there, rename it. 450 if (open POD, "${installprivlib}/$pod/perldiag.pod") { 451 read POD, $_, 4000; 452 close POD; 453 # Some of Perl 5.003's diagnostic messages ended with periods. 454 if (/^=.*\.$/m) { 455 my ($from, $to) = ("${installprivlib}/$pod/perldiag.pod", 456 "${installprivlib}/$pod/perldiag-5.003.pod"); 457 print " rename $from $to"; 458 rename($from, $to) 459 or warn "Couldn't rename $from to $to: $!\n" 460 unless $nonono; 461 } 462 } 463 464 for (@pods) { 465 # $_ is a name like pod/perl.pod 466 (my $base = $_) =~ s#.*/##; 467 copy_if_diff($_, "${installprivlib}/$pod/${base}"); 468 } 469 470} 471 472# Check to make sure there aren't other perls around in installer's 473# path. This is probably UNIX-specific. Check all absolute directories 474# in the path except for where public executables are supposed to live. 475# Also skip $mainperl if the user opted to have it be a link to the 476# installed perl. 477 478if (!$versiononly && $otherperls) { 479 my ($path, @path); 480 my $dirsep = ($Is_OS2 || $Is_W32) ? ';' : ':' ; 481 ($path = $ENV{"PATH"}) =~ s:\\:/:g ; 482 @path = split(/$dirsep/, $path); 483 if ($Is_VMS) { 484 my $i = 0; 485 while (exists $ENV{'DCL$PATH' . $i}) { 486 my $dir = unixpath($ENV{'DCL$PATH' . $i}); $dir =~ s-/$--; 487 push(@path,$dir); 488 } 489 } 490 my @otherperls; 491 my %otherperls; 492 for (@path) { 493 next unless m,^/,; 494 # Use &samepath here because some systems have other dirs linked 495 # to $mainperldir (like SunOS) 496 next if samepath($_, $binexp); 497 next if ($mainperl_is_instperl && samepath($_, $mainperldir)); 498 my $otherperl = "$_/$perl$exe_ext"; 499 next if $otherperls{$otherperl}++; 500 push(@otherperls, $otherperl) 501 if (-x $otherperl && ! -d $otherperl); 502 } 503 if (@otherperls) { 504 warn "\nWarning: $perl appears in your path in the following " . 505 "locations beyond where\nwe just installed it:\n"; 506 for (@otherperls) { 507 warn " ", $_, "\n"; 508 } 509 warn "\n"; 510 } 511 512} 513 514$packlist->write() unless $nonono; 515print " Installation complete\n" if $verbose; 516 517exit 0; 518 519############################################################################### 520 521sub yn { 522 my($prompt) = @_; 523 my($answer); 524 my($default) = $prompt =~ m/\[([yn])\]\s*$/i; 525 warn $prompt; 526 chop($answer = <STDIN>); 527 $answer = $default if $answer =~ m/^\s*$/; 528 ($answer =~ m/^[yY]/); 529} 530 531sub unlink { 532 my(@names) = @_; 533 my($cnt) = 0; 534 535 return scalar(@names) if $Is_VMS; 536 537 foreach my $name (@names) { 538 next unless -e $name; 539 chmod 0777, $name if ($Is_OS2 || $Is_W32 || $Is_Cygwin); 540 print " unlink $name\n" if $verbose; 541 ( CORE::unlink($name) and ++$cnt 542 or warn "Couldn't unlink $name: $!\n" ) unless $nonono; 543 } 544 return $cnt; 545} 546 547sub safe_unlink { 548 return if $nonono or $Is_VMS; 549 my @names = @_; 550 foreach my $name (@names) { 551 next unless -e $name; 552 chmod 0777, $name if ($Is_OS2 || $Is_W32); 553 print " unlink $name\n" if $verbose; 554 next if CORE::unlink($name); 555 warn "Couldn't unlink $name: $!\n"; 556 if ($! =~ /busy/i) { 557 print " mv $name $name.old\n" if $verbose; 558 safe_rename($name, "$name.old") 559 or warn "Couldn't rename $name: $!\n"; 560 } 561 } 562} 563 564sub safe_rename { 565 my($from,$to) = @_; 566 if (-f $to and not unlink($to)) { 567 my($i); 568 for ($i = 1; $i < 50; $i++) { 569 last if rename($to, "$to.$i"); 570 } 571 warn("Cannot rename to `$to.$i': $!"), return 0 572 if $i >= 50; # Give up! 573 } 574 link($from,$to) || return 0; 575 unlink($from); 576} 577 578sub link { 579 my($from,$to) = @_; 580 my($success) = 0; 581 582 print $verbose ? " ln $from $to\n" : " $to\n" unless $silent; 583 eval { 584 CORE::link($from, $to) 585 ? $success++ 586 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#) 587 ? die "AFS" # okay inside eval {} 588 : die "Couldn't link $from to $to: $!\n" 589 unless $nonono; 590 $packlist->{$to} = { from => $from, type => 'link' }; 591 }; 592 if ($@) { 593 warn $@; 594 print $verbose ? " cp $from $to\n" : " $to\n" unless $silent; 595 print " creating new version of $to\n" 596 if $Is_VMS and -e $to and !$silent; 597 File::Copy::copy($from, $to) 598 ? $success++ 599 : warn "Couldn't copy $from to $to: $!\n" 600 unless $nonono; 601 $packlist->{$to} = { type => 'file' }; 602 } 603 $success; 604} 605 606sub cmd { 607 my($cmd) = @_; 608 print STDERR " $cmd\n"; 609 unless ($nonono) { 610 system $cmd; 611 warn "Command failed!!!\n" if $?; 612 } 613} 614 615sub chmod { 616 my($mode,$name) = @_; 617 618 return if ($^O eq 'dos'); 619 printf " chmod %o %s\n", $mode, $name if $verbose; 620 CORE::chmod($mode,$name) 621 || warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name) 622 unless $nonono; 623} 624 625sub copy { 626 my($from,$to) = @_; 627 628 print $verbose ? " cp $from $to\n" : " $to\n" unless $silent; 629 print " creating new version of $to\n" if $Is_VMS and -e $to and !$silent; 630 File::Copy::copy($from, $to) 631 || warn "Couldn't copy $from to $to: $!\n" 632 unless $nonono; 633 $packlist->{$to} = { type => 'file' }; 634} 635 636sub samepath { 637 my($p1, $p2) = @_; 638 639 return (lc($p1) eq lc($p2)) if $Is_W32; 640 641 if ($p1 ne $p2) { 642 my($dev1, $ino1, $dev2, $ino2); 643 ($dev1, $ino1) = stat($p1); 644 ($dev2, $ino2) = stat($p2); 645 ($dev1 == $dev2 && $ino1 == $ino2); 646 } 647 else { 648 1; 649 } 650} 651 652sub installlib { 653 my $dir = $File::Find::dir; 654 $dir =~ s#^\.(?![^/])/?##; 655 local($depth) = $dir ? "lib/$dir" : "lib"; 656 657 my $name = $_; 658 659 # Ignore RCS and CVS directories. 660 if (($name eq 'CVS' or $name eq 'RCS') and -d $name) { 661 $File::Find::prune = 1; 662 return; 663 } 664 665 # ignore patch backups, RCS files, emacs backup & temp files and the 666 # .exists files. 667 return if $name =~ m{\.orig$|~$|^#.+#$|,v$|^\.exists}; 668 669 $name = "$dir/$name" if $dir ne ''; 670 671 my $installlib = $installprivlib; 672 if ($dir =~ /^auto/ || 673 ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) || 674 ($name =~ /^(.*)\.(?:h|lib)$/i && $Is_W32) 675 ) { 676 $installlib = $installarchlib; 677 return unless $do_installarchlib; 678 } else { 679 return unless $do_installprivlib; 680 } 681 682 if (-f $_) { 683 if (/\.(?:al|ix)$/ && !($dir =~ m[^auto/(.*)$] && $archpms{$1})) { 684 $installlib = $installprivlib; 685 #We're installing *.al and *.ix files into $installprivlib, 686 #but we have to delete old *.al and *.ix files from the 5.000 687 #distribution: 688 #This might not work because $archname might have changed. 689 unlink("$installarchlib/$name"); 690 } 691 $packlist->{"$installlib/$name"} = { type => 'file' }; 692 if (compare($_, "$installlib/$name") || $nonono) { 693 unlink("$installlib/$name"); 694 mkpath("$installlib/$dir", $verbose, 0777); 695 # HP-UX (at least) needs to maintain execute permissions 696 # on dynamically-loaded libraries. 697 copy_if_diff($_, "$installlib/$name") 698 and chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444, 699 "$installlib/$name"); 700 } 701 } 702} 703 704# Copy $from to $to, only if $from is different than $to. 705# Also preserve modification times for .a libraries. 706# On some systems, if you do 707# ranlib libperl.a 708# cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a 709# and then try to link against the installed libperl.a, you might 710# get an error message to the effect that the symbol table is older 711# than the library. 712# Return true if copying occurred. 713 714sub copy_if_diff { 715 my($from,$to)=@_; 716 return 1 if (($^O eq 'VMS') && (-d $from)); 717 -f $from || warn "$0: $from not found"; 718 $packlist->{$to} = { type => 'file' }; 719 if (compare($from, $to) || $nonono) { 720 safe_unlink($to); # In case we don't have write permissions. 721 if ($nonono) { 722 $from = $depth . "/" . $from if $depth; 723 } 724 copy($from, $to); 725 # Restore timestamps if it's a .a library or for OS/2. 726 if (!$nonono && ($Is_OS2 || $to =~ /\.a$/)) { 727 my ($atime, $mtime) = (stat $from)[8,9]; 728 utime $atime, $mtime, $to; 729 } 730 1; 731 } 732} 733 734sub strip 735{ 736 my(@args) = @_; 737 738 return unless $dostrip; 739 740 my @opts; 741 while (@args && $args[0] =~ /^(-\w+)$/) { 742 push @opts, shift @args; 743 } 744 745 foreach my $file (@args) { 746 if (-f $file) { 747 print " strip $file\n" if $verbose; 748 system("strip", @opts, $file); 749 } else { 750 print "# file '$file' skipped\n" if $verbose; 751 } 752 } 753} 754 755