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