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