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