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