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