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