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