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