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