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