This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_coreargs: rationalise @_ code
[perl5.git] / installperl
CommitLineData
dca8fd5c 1#!./perl -w
68dc0745 2
3BEGIN {
922ef74c 4 chdir '..' if !-d 'lib' and -d '../lib';
68dc0745 5 @INC = 'lib';
6 $ENV{PERL5LIB} = 'lib';
a29d2910 7
dca8fd5c 8 # This needs to be at BEGIN time, before any use of Config
f4df373d 9 # install_lib itself loads and imports Config into main::
9e6fc21f 10 require './install_lib.pl';
1d230ada
NC
11}
12
a29d2910 13use strict;
de35015f 14use vars qw($Is_VMS $Is_W32 $Is_OS2 $Is_Cygwin $Is_Darwin $Is_NetWare $Is_AmigaOS
9e6fc21f 15 %opts $packlist);
c164bd94 16my $versiononly;
a29d2910
A
17
18BEGIN {
17f28c40 19 if ($Is_VMS) { eval 'use VMS::Filespec;' }
68dc0745 20}
21
de35015f
AB
22# HP-UX (at least) needs to maintain execute permissions
23# on dynamically-loadable libraries. So we do it for all.
24#
25# In AmigaOS, the 0777 means 'rwed' (e = execute, d = delete),
26# (not 'rwx') and having the 'd' makes updates more convenient.
27my $SO_MODE = $Is_AmigaOS ? 0777 : 0555;
28my $NON_SO_MODE = $Is_AmigaOS ? 0666 : 0444;
29
c2cd2081 30my $scr_ext = ($Is_VMS ? '.Com' : $Is_W32 ? '.bat' : '');
4a71ed0c 31
a0d0e21e 32use File::Find;
5f05dabc 33use File::Compare;
68dc0745 34use File::Copy ();
354f3b56 35use ExtUtils::Packlist;
ebef0ab4 36use Cwd;
3f7e1bf8
NC
37# nogetopt_compat to disable treating +v as meaning -v
38use Getopt::Long qw(:config nogetopt_compat no_auto_abbrev noignorecase);
791b4ad3 39
91e41fa7
NC
40require './Porting/pod_lib.pl';
41
2986a63f 42if ($Is_NetWare) {
2e2b85db
MB
43 $Is_W32 = 0;
44 $scr_ext = '.pl';
2986a63f
JH
45}
46
c2cd2081
KS
47my $mainperldir = "/usr/bin";
48my $exe_ext = $Config{exe_ext};
bee1dbe2 49
dca8fd5c 50# Allow "make install PERLNAME=something_besides_perl":
c2cd2081 51my $perl = defined($ENV{PERLNAME}) ? $ENV{PERLNAME} : 'perl';
6ee623d5 52
146174a9 53# This is the base used for versioned names, like "perl5.6.0".
beb13193
RS
54# It's separate because a common use of $PERLNAME is to install
55# perl as "perl5", if that's used as base for versioned files you
146174a9 56# get "perl55.6.0".
beb13193
RS
57my $perl_verbase = defined($ENV{PERLNAME_VERBASE})
58 ? $ENV{PERLNAME_VERBASE}
59 : $perl;
5d25492c
PP
60my $dbg = '';
61my $ndbg = '';
62if ( $Is_VMS ) {
63 if ( defined $Config{usevmsdebug} ) {
64 if ( $Config{usevmsdebug} eq 'define' ) {
65 $dbg = 'dbg';
66 $ndbg = 'ndbg';
67 }
68 }
69}
beb13193 70
99d21f8b
NC
71# This little hack simplifies making the code after the comment "Fetch some
72# frequently-used items from %Config" warning free. With $opts{destdir} always
73# defined, it's also possible to make the s/\Q$opts{destdir}\E unconditional.
74
75$opts{destdir} = '';
3f7e1bf8
NC
76{
77 my $usage = 0;
78 if (!GetOptions(\%opts, 'notify|n', 'strip|s', 'silent|S',
79 'skip-otherperls|o', 'force|f', 'verbose|V', 'archname|A',
80 'netware', 'nopods|p', 'destdir:s', 'help|h|?',
81 'versiononly|v' => \$versiononly, '<>' => sub {
82 if ($_[0] eq '+v') {
83 $versiononly = 0;
84 } else {
85 # Any other unknown argument is going to be an error
86 $usage = 1;
87 }
88 },
89 )) {
90 $usage = 1;
91 }
92 $opts{verbose} ||= $opts{notify};
93
94 if ($usage || $opts{help}) {
95 print <<"EOT";
33bd2d8f
NC
96Usage $0: [switches]
97 -n Don't actually run any commands; just print them.
98 -s Run strip on installed binaries.
99 -v Only install perl as a binary with the version number in the name.
100 (Override whatever config.sh says)
101 +v Install perl as "perl" and as a binary with the version number in
102 the name. (Override whatever config.sh says)
103 -S Silent mode.
2e2b85db 104 -f Force installation (don't check if same version is there)
33bd2d8f
NC
105 -o Skip checking for other copies of perl in your PATH.
106 -V Verbose mode.
107 -A Also install perl with the architecture's name in the perl binary's
108 name.
4f048c5d 109 -p Don't install the pod files. [This will break use diagnostics;]
33bd2d8f 110 -netware Install correctly on a Netware server.
70eaf669 111 -destdir Prefix installation directories by this string.
3f7e1bf8 112 -h Display this help message.
33bd2d8f 113EOT
3f7e1bf8 114 exit $usage;
33bd2d8f 115 }
c623bd54
LW
116}
117
f4a342c3 118$versiononly = 1 if $Config{versiononly} && !defined $versiononly;
21dae8a0
SC
119my (@scripts, @tolink);
120open SCRIPTS, "utils.lst" or die "Can't open utils.lst: $!";
121while (<SCRIPTS>) {
122 next if /^#/;
21dae8a0
SC
123 chomp;
124 if (/(\S*)\s*#\s*link\s*=\s*(\S*)/) {
2e2b85db
MB
125 push @scripts, $1;
126 push @tolink, [$1, $2];
21dae8a0 127 } else {
2e2b85db 128 push @scripts, $_;
21dae8a0
SC
129 }
130}
131close SCRIPTS;
16d20bd9 132
4a71ed0c 133if ($scr_ext) { @scripts = map { "$_$scr_ext" } @scripts; }
17f28c40 134
e8ea6127
AD
135# Specify here any .pm files that are actually architecture-dependent.
136# (Those included with XS extensions under ext/ are automatically
137# added later.)
138# Now that the default privlib has the full perl version number included,
0b3bfb33 139# we no longer have to play the trick of sticking version-specific .pm
e8ea6127 140# files under the archlib directory.
c2cd2081 141my %archpms = (
0b3bfb33
NIS
142 Config => 1,
143 lib => 1,
38b8243a 144);
39e571d4
LM
145
146if ($^O eq 'dos') {
147 push(@scripts,'djgpp/fixpmain');
148 $archpms{config} = $archpms{filehand} = 1;
149}
150
2e2b85db
MB
151if ((-e "testcompile") && (defined($ENV{'COMPILE'}))) {
152 push(@scripts, map("$_.exe", @scripts));
6ee623d5
GS
153}
154
08baf503
JH
155# Exclude nonxs extensions that are not architecture dependent
156my @nonxs = grep(!/^Errno$/, split(' ', $Config{'nonxs_ext'}));
157
19c8b195
SH
158my @ext_dirs = qw(cpan dist ext);
159foreach 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
af1e27ef 167 # Change hyphenated name like Filter-Util-Call to nested
19c8b195
SH
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}
1dd15ed4 185
68c887af
GS
186# print "[$_]\n" for sort keys %archpms;
187
146174a9 188my $ver = $Config{version};
f2766b05 189my $release = substr($],0,3); # Not used currently.
03284eb6 190my $patchlevel = substr($],3,2);
748a9306 191die "Patchlevel of perl ($patchlevel)",
cceca5ed
GS
192 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
193 if $patchlevel != $Config{'PERL_VERSION'};
4633a7c4
LW
194
195# Fetch some frequently-used items from %Config
2227e2d5
NC
196my $installbin = "$opts{destdir}$Config{installbin}";
197my $installscript = "$opts{destdir}$Config{installscript}";
198my $installprivlib = "$opts{destdir}$Config{installprivlib}";
199my $installarchlib = "$opts{destdir}$Config{installarchlib}";
200my $installsitelib = "$opts{destdir}$Config{installsitelib}";
201my $installsitearch = "$opts{destdir}$Config{installsitearch}";
202my $installman1dir = "$opts{destdir}$Config{installman1dir}";
c2cd2081
KS
203my $man1ext = $Config{man1ext};
204my $libperl = $Config{libperl};
4633a7c4 205# Shared library and dynamic loading suffixes.
c2cd2081
KS
206my $so = $Config{so};
207my $dlext = $Config{dlext};
146174a9 208my $dlsrc = $Config{dlsrc};
f2766b05
PP
209if ($^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') {
2e2b85db 215 `./$^X -pibak -e 's{$pwd\/libperl.x}{$archlibexp/CORE/libperl.x}' lib/Config.pm`;
f2766b05
PP
216 }
217}
4633a7c4 218
c164bd94 219if ($opts{netware}) {
2e2b85db
MB
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};
2986a63f
JH
225}
226
c2cd2081 227my $binexp = $Config{binexp};
c623bd54 228
17f28c40
CB
229if ($Is_VMS) { # Hang in there until File::Spec hits the big time
230 foreach ( \$installbin, \$installscript, \$installprivlib,
2e2b85db
MB
231 \$installarchlib, \$installsitelib, \$installsitearch,
232 \$installman1dir ) {
233 $$_ = unixify($$_); $$_ =~ s:/$::;
17f28c40
CB
234 }
235}
236
c623bd54
LW
237# Do some quick sanity checks.
238
fe14fcc3 239 $installbin || die "No installbin directory in config.sh\n";
a01f5661 240-d $installbin || mkpath($installbin);
68006eea
NC
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};
c623bd54 244
2986a63f 245if (!$Is_NetWare) {
5d25492c 246if (!$Is_VMS) {
39add537 247-x 'perl' . $exe_ext || die "perl isn't executable!\n";
5d25492c
PP
248}
249else {
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}
c623bd54 255
9fba8746 256-f 't/rantests' || $Is_W32
2e2b85db
MB
257 || warn "WARNING: You've never run 'make test' or",
258 " some tests failed! (Installing anyway.)\n";
2986a63f 259} #if (!$Is_NetWare)
c623bd54 260
25207203 261# This will be used to store the packlist
9e6fc21f 262$packlist = ExtUtils::Packlist->new("$installarchlib/.packlist");
25207203 263
2e2b85db
MB
264if (($Is_W32 and ! $Is_NetWare) or $Is_Cygwin) {
265 my $perldll;
266
267 if ($Is_Cygwin) {
268 $perldll = $libperl;
2e2b85db 269 } else {
dc5c2add 270 $perldll = 'perl5'.$Config{patchlevel}.'.'.$so;
2e2b85db 271 }
5f675712 272
2e2b85db
MB
273 if ($dlsrc ne "dl_none.xs") {
274 -f $perldll || die "No perl DLL built\n";
275 }
0b3bfb33 276
2e2b85db
MB
277 # Install the DLL
278 safe_unlink("$installbin/$perldll");
279 copy("$perldll", "$installbin/$perldll");
280 chmod(0755, "$installbin/$perldll");
b7c0c6b4 281 $packlist->{"$Config{installbin}/$perldll"} = { type => 'file' };
2986a63f 282} # if (($Is_W32 and ! $Is_NetWare) or $Is_Cygwin)
eef1cf2a 283
c623bd54
LW
284# First we install the version-numbered executables.
285
17f28c40 286if ($Is_VMS) {
9edbfc61
PP
287 safe_unlink("$installbin/perl_setup.com");
288 copy("perl_setup.com", "$installbin/perl_setup.com");
289 chmod(0755, "$installbin/perl_setup.com");
5d25492c
PP
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) {
9edbfc61
PP
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");
5d25492c 300 }
17f28c40 301}
3f5ee302 302elsif ($^O ne 'dos') {
2e2b85db
MB
303 if (!$Is_NetWare) {
304 safe_unlink("$installbin/$perl_verbase$ver$exe_ext");
305 copy("perl$exe_ext", "$installbin/$perl_verbase$ver$exe_ext");
306 strip("$installbin/$perl_verbase$ver$exe_ext");
307 chmod(0755, "$installbin/$perl_verbase$ver$exe_ext");
308 }
309 else {
310 # If installing onto a NetWare server
c164bd94 311 if ($opts{netware}) {
6af091cd 312 # Copy perl.nlm, echo.nlm, type.nlm & cgi2perl.nlm
a01f5661 313 mkpath($Config{installnwsystem});
2e2b85db
MB
314 copy("netware\\".$ENV{'MAKE_TYPE'}."\\perl.nlm", $Config{installnwsystem});
315 copy("netware\\testnlm\\echo\\echo.nlm", $Config{installnwsystem});
316 copy("netware\\testnlm\\type\\type.nlm", $Config{installnwsystem});
2e2b85db 317 chmod(0755, "$Config{installnwsystem}\\perl.nlm");
a01f5661 318 mkpath($Config{installnwlcgi});
2e2b85db 319 copy("lib\\auto\\cgi2perl\\cgi2perl.nlm", $Config{installnwlcgi});
2986a63f 320 }
2e2b85db 321 } #if (!$Is_NetWare)
3f5ee302 322}
1d84e8df 323else {
6ee623d5
GS
324 safe_unlink("$installbin/$perl.exe");
325 copy("perl.exe", "$installbin/$perl.exe");
39e571d4 326}
c623bd54 327
45d8adaa
LW
328# Install library files.
329
8473bff1
NC
330my $do_installarchlib = !samepath($installarchlib, 'lib');
331my $do_installprivlib = !samepath($installprivlib, 'lib');
5f9145a3 332my $vershort = ($Is_Cygwin and !$Config{usedevel}) ? substr($ver,0,-2) : $ver;
8473bff1 333$do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$vershort/);
0b3bfb33 334
a01f5661
NC
335mkpath($installprivlib);
336mkpath($installarchlib);
68006eea
NC
337mkpath($installsitelib, $opts{verbose}, 0777) if ($installsitelib);
338mkpath($installsitearch, $opts{verbose}, 0777) if ($installsitearch);
4633a7c4 339
ce64b292 340if (-d 'lib') {
2c65a6e1 341 find({no_chdir => 1, wanted => \&installlib}, 'lib')
ce64b292 342 if $do_installarchlib || $do_installprivlib;
45d8adaa
LW
343}
344else {
ce64b292 345 warn "Can't install lib files - 'lib/' does not exist";
45d8adaa
LW
346}
347
1aef975c 348# Install header files and libraries.
a01f5661 349mkpath("$installarchlib/CORE");
c2cd2081 350my @corefiles;
17f28c40 351if ($Is_VMS) { # We did core file selection during build
0185066f 352 my $coredir = "lib/$Config{archname}/$ver/CORE";
17f28c40 353 $coredir =~ tr/./_/;
0185066f 354 map { s|^$coredir/||i; } @corefiles = <$coredir/*.*>;
17f28c40 355}
b5920ff0 356elsif ($Is_Cygwin) { # On Cygwin symlink it to CORE to make Makefile happy
2a21c444 357 @corefiles = <*.h libperl*.* perl*$Config{lib_ext}>;
b5920ff0 358 my $coredll = "$installarchlib/CORE/$libperl";
b7c0c6b4 359 my $instcoredll = "$Config{installarchlib}/CORE/$libperl";
2a21c444 360 safe_unlink($coredll);
b5920ff0 361 ( $Config{'d_link'} eq 'define' &&
2a21c444
JH
362 eval {
363 CORE::link("$installbin/$libperl", $coredll);
b7c0c6b4 364 $packlist->{$instcoredll} = { from => "$Config{installbin}/$libperl",
2a21c444
JH
365 type => 'link' };
366 }
367 ) ||
368 eval {
369 symlink("$installbin/$libperl", $coredll);
b7c0c6b4 370 $packlist->{$instcoredll} = { from => "$Config{installbin}/$libperl",
2a21c444
JH
371 type => 'link' };
372 } ||
373 ( copy("$installbin/$libperl", $coredll) &&
b7c0c6b4 374 push(@corefiles, $instcoredll)
2a21c444 375 )
b5920ff0 376} else {
8736538c 377 # [als] hard-coded 'libperl' name... not good!
1933e12c 378 @corefiles = <*.h libperl*.* perl*$Config{lib_ext}>;
8736538c 379
17f28c40
CB
380 # AIX needs perl.exp installed as well.
381 push(@corefiles,'perl.exp') if $^O eq 'aix';
17f28c40 382}
de35015f
AB
383
384
c2cd2081 385foreach my $file (@corefiles) {
8f1f23e8 386 if (copy_if_diff($file,"$installarchlib/CORE/$file")) {
f556e5b9 387 if ($file =~ /\.(\Q$so\E|\Q$dlext\E)$/) {
7eb35c03 388 strip("-S", "$installarchlib/CORE/$file") if $^O eq 'darwin';
de35015f 389 chmod($SO_MODE, "$installarchlib/CORE/$file");
8f1f23e8 390 } else {
de35015f 391 chmod($NON_SO_MODE, "$installarchlib/CORE/$file");
8f1f23e8
W
392 }
393 }
340f689c 394}
3edbfbe5 395
156620fa
NA
396# Install main perl executables
397# Make links to ordinary names if installbin directory isn't current directory.
398
2986a63f 399if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS && ! $Is_NetWare) {
6ee623d5 400 safe_unlink("$installbin/$perl$exe_ext", "$installbin/suid$perl$exe_ext");
b5afd346 401 if ($^O eq 'vos') {
7e6b8b1f 402 # VOS doesn't support hard links, so use a symlink.
2e2b85db
MB
403 symlink("$installbin/$perl_verbase$ver$exe_ext",
404 "$installbin/$perl$exe_ext");
1d84e8df 405 } else {
beb13193
RS
406 link("$installbin/$perl_verbase$ver$exe_ext",
407 "$installbin/$perl$exe_ext");
1d84e8df 408 }
156620fa
NA
409}
410
f4a342c3
JH
411# For development purposes it can be very useful to have multiple perls
412# build for different "architectures" (eg threading or not) simultaneously.
c164bd94 413if ($opts{archname} && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS) {
f4a342c3
JH
414 my $archperl = "$perl_verbase$ver-$Config{archname}$exe_ext";
415 safe_unlink("$installbin/$archperl");
b5afd346 416 if ($^O eq 'vos') {
eb96f679
PG
417 # VOS doesn't support hard links, so use a symlink.
418 symlink("$installbin/$perl_verbase$ver$exe_ext",
419 "$installbin/$archperl");
f4a342c3 420 } else {
2e2b85db 421 link("$installbin/$perl_verbase$ver$exe_ext", "$installbin/$archperl");
f4a342c3
JH
422 }
423}
424
a0d0e21e
LW
425# Offer to install perl in a "standard" location
426
c2cd2081 427my $mainperl_is_instperl = 0;
a0d0e21e 428
a3ed4895 429if ($Config{installusrbinperl} && $Config{installusrbinperl} eq 'define' &&
68006eea 430 !$versiononly && !$opts{notify} && !$Is_W32 && !$Is_NetWare && !$Is_VMS && -t STDIN && -t STDERR
68dc0745 431 && -w $mainperldir && ! samepath($mainperldir, $installbin)) {
c2cd2081
KS
432 my($usrbinperl) = "$mainperldir/$perl$exe_ext";
433 my($instperl) = "$installbin/$perl$exe_ext";
434 my($expinstperl) = "$binexp/$perl$exe_ext";
55497cff 435
436 # First make sure $usrbinperl is not already the same as the perl we
437 # just installed.
438 if (-x $usrbinperl) {
a0d0e21e
LW
439 # Try to be clever about mainperl being a symbolic link
440 # to binexp/perl if binexp and installbin are different.
441 $mainperl_is_instperl =
68dc0745 442 samepath($usrbinperl, $instperl) ||
443 samepath($usrbinperl, $expinstperl) ||
a0d0e21e 444 (($binexp ne $installbin) &&
55497cff 445 (-l $usrbinperl) &&
446 ((readlink $usrbinperl) eq $expinstperl));
a0d0e21e 447 }
835f8a63 448 if (! $mainperl_is_instperl) {
55497cff 449 unlink($usrbinperl);
1d84e8df
JH
450 ( $Config{'d_link'} eq 'define' &&
451 eval { CORE::link $instperl, $usrbinperl } ) ||
452 eval { symlink $expinstperl, $usrbinperl } ||
453 copy($instperl, $usrbinperl);
454
a0d0e21e
LW
455 $mainperl_is_instperl = 1;
456 }
457}
458
b971f6e4 459# cppstdin is just a script, but it is architecture-dependent, so
460# it can't safely be shared. Place it in $installbin.
461# Note that Configure doesn't build cppstin if it isn't needed, so
462# we skip this if cppstdin doesn't exist.
68dc0745 463if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) {
464 safe_unlink("$installbin/cppstdin");
465 copy("cppstdin", "$installbin/cppstdin");
466 chmod(0755, "$installbin/cppstdin");
b971f6e4 467}
468
1a09d0c8
JH
469sub script_alias {
470 my ($installscript, $orig, $alias, $scr_ext) = @_;
471
eea3e086 472 safe_unlink("$installscript/$alias$scr_ext");
1a09d0c8
JH
473 if ($^O eq 'dos' or $Is_VMS or $^O eq 'transit') {
474 copy("$installscript/$orig$scr_ext",
0b3bfb33 475 "$installscript/$alias$scr_ext");
7e6b8b1f
PG
476 } elsif ($^O eq 'vos') {
477 symlink("$installscript/$orig$scr_ext",
2e2b85db 478 "$installscript/$alias$scr_ext");
1a09d0c8
JH
479 } else {
480 link("$installscript/$orig$scr_ext",
481 "$installscript/$alias$scr_ext");
482 }
483}
484
c8f392da 485# Install scripts.
a01f5661 486mkpath($installscript);
c8f392da
JH
487if ($versiononly) {
488 for (@scripts) {
489 (my $base = $_) =~ s#.*/##;
490 $base .= $ver;
491 copy($_, "$installscript/$base");
492 chmod(0755, "$installscript/$base");
493 }
b971f6e4 494
0b3bfb33 495 for (@tolink) {
2e2b85db
MB
496 my ($from, $to) = map { "$_$ver" } @$_;
497 (my $frbase = $from) =~ s#.*/##;
498 (my $tobase = $to) =~ s#.*/##;
499 script_alias($installscript, $frbase, $tobase, $scr_ext);
c8f392da
JH
500 }
501} else {
22e77942
JH
502 for (@scripts) {
503 (my $base = $_) =~ s#.*/##;
504 copy($_, "$installscript/$base");
505 chmod(0755, "$installscript/$base");
de35015f
AB
506 if ($Is_AmigaOS) {
507 my $amigapath = unixtoamiga("$installscript/$base");
508 amigaprotect($amigapath,"+s");
509 }
b971f6e4 510 }
22e77942 511
0b3bfb33 512 for (@tolink) {
2e2b85db
MB
513 my ($from, $to) = @$_;
514 (my $frbase = $from) =~ s#.*/##;
515 (my $tobase = $to) =~ s#.*/##;
516 script_alias($installscript, $frbase, $tobase, $scr_ext);
21dae8a0 517 }
b971f6e4 518}
519
146174a9
CB
520# Install pod pages. Where? I guess in $installprivlib/pod
521# ($installprivlib/pods for cygwin).
c164bd94 522if (!$opts{nopods} && (!$versiononly || ($installprivlib =~ m/\Q$vershort/))) {
91e41fa7 523 my $pod = ($Is_Cygwin || $Is_Darwin || $Is_VMS || $Is_W32) ? 'pods' : 'pod';
a01f5661 524 mkpath("${installprivlib}/$pod");
91a06757 525
91e41fa7 526 for (map {$_->[1]} @{get_pod_metadata()->{master}}) {
146174a9 527 # $_ is a name like pod/perl.pod
2e2b85db 528 (my $base = $_) =~ s#.*/##;
146174a9 529 copy_if_diff($_, "${installprivlib}/$pod/${base}");
ed5958d4 530 chmod(0644, "${installprivlib}/$pod/${base}");
b971f6e4 531 }
91a06757 532
b971f6e4 533}
534
a0d0e21e
LW
535# Check to make sure there aren't other perls around in installer's
536# path. This is probably UNIX-specific. Check all absolute directories
537# in the path except for where public executables are supposed to live.
538# Also skip $mainperl if the user opted to have it be a link to the
539# installed perl.
540
c164bd94 541if (!$versiononly && !$opts{'skip-otherperls'}) {
146174a9 542 my ($path, @path);
2986a63f 543 my $dirsep = ($Is_OS2 || $Is_W32 || $Is_NetWare) ? ';' : ':' ;
b971f6e4 544 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
545 @path = split(/$dirsep/, $path);
17f28c40 546 if ($Is_VMS) {
2e2b85db
MB
547 my $i = 0;
548 while (exists $ENV{'DCL$PATH' . $i}) {
549 my $dir = unixpath($ENV{'DCL$PATH' . $i}); $dir =~ s-/$--;
550 push(@path,$dir);
551 }
17f28c40 552 }
c2cd2081 553 my @otherperls;
160a7e37 554 my %otherperls;
b971f6e4 555 for (@path) {
556 next unless m,^/,;
557 # Use &samepath here because some systems have other dirs linked
558 # to $mainperldir (like SunOS)
44591ba5 559 next unless -d;
68dc0745 560 next if samepath($_, $binexp);
ebef0ab4 561 next if samepath($_, cwd());
68dc0745 562 next if ($mainperl_is_instperl && samepath($_, $mainperldir));
2e2b85db 563 my $otherperl = "$_/$perl$exe_ext";
160a7e37
HS
564 next if $otherperls{$otherperl}++;
565 push(@otherperls, $otherperl)
566 if (-x $otherperl && ! -d $otherperl);
b971f6e4 567 }
568 if (@otherperls) {
5f675712 569 warn "\nWarning: $perl appears in your path in the following " .
b971f6e4 570 "locations beyond where\nwe just installed it:\n";
571 for (@otherperls) {
5f675712 572 warn " ", $_, "\n";
b971f6e4 573 }
5f675712 574 warn "\n";
a0d0e21e 575 }
b971f6e4 576
a0d0e21e
LW
577}
578
68006eea
NC
579$packlist->write() unless $opts{notify};
580print " Installation complete\n" if $opts{verbose};
c623bd54
LW
581
582exit 0;
583
584###############################################################################
585
9e6fc21f
NC
586# If these are needed elsewhere, move them into install_lib.pl rather than
587# copying them.
588
a0d0e21e 589sub yn {
c2cd2081
KS
590 my($prompt) = @_;
591 my($answer);
592 my($default) = $prompt =~ m/\[([yn])\]\s*$/i;
802cdca0 593 print STDERR $prompt;
a0d0e21e
LW
594 chop($answer = <STDIN>);
595 $answer = $default if $answer =~ m/^\s*$/;
596 ($answer =~ m/^[yY]/);
597}
598
e50aee73 599sub safe_unlink {
68006eea 600 return if $opts{notify} or $Is_VMS;
c2cd2081
KS
601 my @names = @_;
602 foreach my $name (@names) {
e50aee73 603 next unless -e $name;
2986a63f 604 chmod 0777, $name if ($Is_OS2 || $Is_W32 || $Is_NetWare);
68006eea 605 print " unlink $name\n" if $opts{verbose};
39add537 606 next if CORE::unlink($name);
e50aee73
AD
607 warn "Couldn't unlink $name: $!\n";
608 if ($! =~ /busy/i) {
68006eea 609 print " mv $name $name.old\n" if $opts{verbose};
68dc0745 610 safe_rename($name, "$name.old")
611 or warn "Couldn't rename $name: $!\n";
e50aee73
AD
612 }
613 }
614}
615
68dc0745 616sub copy {
617 my($from,$to) = @_;
618
5a9231b0 619 my $xto = $to;
99d21f8b 620 $xto =~ s/^\Q$opts{destdir}\E//;
68006eea
NC
621 print $opts{verbose} ? " cp $from $xto\n" : " $xto\n"
622 unless $opts{silent};
623 print " creating new version of $xto\n"
624 if $Is_VMS and -e $to and !$opts{silent};
625 unless ($opts{notify} or File::Copy::copy($from, $to)) {
6c9f5ae6
IZ
626 # Might have been that F::C::c can't overwrite the target
627 warn "Couldn't copy $from to $to: $!\n"
628 unless -f $to and (chmod(0666, $to), unlink $to)
629 and File::Copy::copy($from, $to);
630 }
5a9231b0 631 $packlist->{$xto} = { type => 'file' };
c623bd54
LW
632}
633
a0d0e21e
LW
634sub installlib {
635 my $dir = $File::Find::dir;
ce64b292 636 $dir =~ s!\Alib/?!!;
a0d0e21e 637
2c65a6e1
NC
638 m!([^/]+)\z!;
639 my $name = $1;
640
641 # This remains ugly, and in need of refactoring.
642
643 # $name always starts as the leafname
644 # $dir is the directory *within* lib
645 # $name later has $dir pre-pended, to give the relative path in lib/
646 # which is used to create the path in the target directory.
647
648 # $_ was always the filename to use on disk. Adding no_chdir doesn't change
649 # this, as $_ becomes a pathname, and so still works. However, it's not
650 # obvious that $_ is needed later, and hence $_ must not be modified.
651
2effe01f 652 # Also, many of the regex exclusion tests below are now superfluous, as the
2c65a6e1
NC
653 # files in question are either no longer in blead, or now in ext/, dist/ or
654 # cpan/ and not copied into lib/
efc5ad56 655
ce28de53 656 # Ignore version control directories.
559940b2 657 if ($name =~ /^(?:CVS|RCS|SCCS|\.svn)\z/ and -d $name) {
efc5ad56
TB
658 $File::Find::prune = 1;
659 return;
660 }
0b3bfb33 661
146174a9 662 # ignore patch backups, RCS files, emacs backup & temp files and the
056a8fbe 663 # .exists files, .PL files, and test files.
4540f59a 664 return if $name =~ m{\.orig$|\.rej$|~$|^#.+#$|,v$|^\.exists|\.PL$|\.plc$|\.t$|^test\.pl$|^dbm_filter_util\.pl$|^filter-util\.pl$|^uupacktool\.pl$|^\.gitignore$} ||
2e2b85db 665 $dir =~ m{/t(?:/|$)};
e4fc8a1e 666 # ignore the cpan script in lib/CPAN/bin, the instmodsh and xsubpp
04f9cde5 667 # scripts in lib/ExtUtils, the prove script in lib/Test/Harness,
ca32a3cb 668 # the corelist script from lib/Module/CoreList/bin and ptar* in
a4678072 669 # lib/Archive/Tar/bin and zipdetails in cpan/IO-Compress/bin
e4fc8a1e 670 # (they're installed later with other utils)
a4678072 671 return if $name =~ /^(?:cpan|instmodsh|prove|corelist|ptar|ptardiff|ptargrep|zipdetails)\z/;
922ef74c
RGS
672 # ignore the Makefiles
673 return if $name =~ /^makefile$/i;
581f1868
DD
674 # ignore the test extensions, dont install PPPort.so/.dll
675 return if $dir =~ m{\b(?:XS/(?:APItest|Typemap)|Devel/PPPort)\b};
f631d084 676 return if $name =~ m{\b(?:APItest|Typemap)\.pm$};
5e4c4c91
NC
677 # ignore the build support code
678 return if $name =~ /\bbuildcustomize\.pl$/;
a6c3b020 679 # ignore the demo files
021db424 680 return if $dir =~ /\b(?:demos?|eg)\b/;
e4ed29fb
DG
681 # ignore unneeded unicore files
682 if ( $dir =~ /^unicore/ ) {
683 if ( $name =~ /\.txt\z/ ) {
684 # We can ignore most, but not all .txt files
4731737c 685 return unless $name =~ /\A(?:Blocks|SpecialCasing|NamedSequences)\.txt\z/;
e4ed29fb
DG
686 }
687 else {
688 # TestProp only needed during testing
689 return if $name =~ /\ATestProp.pl\z/;
690 # we need version and *.pl files and can skip the rest
971c5244 691 return unless $name =~ /\A(?:version|\w+\.p[lm])\z/;
e4ed29fb
DG
692 }
693 }
b695f709 694
0ae089ad
MS
695 # ignore READMEs, MANIFESTs, INSTALL docs, META.ymls and change logs.
696 # Changes.e2x and README.e2x are needed by enc2xs.
ae5e75fd 697 return if $name =~ m{^(?:README(?:\.\w+)?)$} && $name ne 'README.e2x';
021db424
JH
698 return if $name =~ m{^(?:MANIFEST|META\.yml)$};
699 return if $name =~ m{^(?:INSTALL|TODO|BUGS|CREDITS)$}i;
0ae089ad 700 return if $name =~ m{^change(?:s|log)(?:\.libnet)?$}i;
021db424
JH
701 return if $name =~ m{^(?:SIGNATURE|PAUSE200\d\.pub)$}; # CPAN files
702 return if $name =~ m{^(?:NOTES|PATCHING)$}; # ExtUtils files
0ae089ad 703
54f1e9b4
SH
704 # if using a shared perl library then ignore:
705 # - static library files [of statically linked extensions];
706 # - import library files and export library files (only present on Win32
707 # anyway?) and empty bootstrap files [of dynamically linked extensions].
708 return if $Config{useshrplib} eq 'true' and
709 ($name =~ /$Config{_a}$/ or $name =~ /\.exp$/ or ($name =~ /\.bs$/ and -z $name));
710
a0d0e21e
LW
711 $name = "$dir/$name" if $dir ne '';
712
91e41fa7
NC
713 # ignore pods that are stand alone documentation from dual life modules.
714 return if /\.pod\z/ && is_duplicate_pod($_);
715
e2c1c280
NC
716 return if $name eq 'ExtUtils/XSSymSet.pm' and !$Is_VMS;
717
ce9582af
DD
718 #blead comes with version, blead isn't 5.8/5.6
719 return if $name eq 'ExtUtils/MakeMaker/version/regex.pm';
720
a0d0e21e 721 my $installlib = $installprivlib;
cad0fd6e 722 if ($dir =~ /^auto\// ||
eef1cf2a 723 ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) ||
b809f04e 724 ($name =~ /^(.*)\.(?:h|lib)$/i && ($Is_W32 || $Is_NetWare)) ||
d62d5a53 725 $name=~/^Config_(heavy|git)\.pl\z/
eef1cf2a 726 ) {
2e2b85db 727 $installlib = $installarchlib;
a0d0e21e
LW
728 return unless $do_installarchlib;
729 } else {
730 return unless $do_installprivlib;
731 }
732
c164bd94 733 if ($Is_NetWare && !$opts{netware} && /\.(?:nlp|nlm|bs)$/) {
efe502bb
NC
734 # Don't copy .nlp,.nlm files, doesn't make sense on Windows and also
735 # if copied will give problems when building new extensions.
736 # Has to be copied if we are installing on a NetWare server and
c164bd94 737 # hence the check !$opts{netware}
efe502bb
NC
738 return;
739 }
740
a0d0e21e 741 if (-f $_) {
5a9231b0 742 my $xname = "$installlib/$name";
99d21f8b 743 $xname =~ s/^\Q$opts{destdir}\E//;
5a9231b0 744 $packlist->{$xname} = { type => 'file' };
c164bd94 745 if ($opts{force} || compare($_, "$installlib/$name") || $opts{notify}) {
55a105fd 746 unlink("$installlib/$name");
a01f5661 747 mkpath("$installlib/$dir");
75f92628
AD
748 # HP-UX (at least) needs to maintain execute permissions
749 # on dynamically-loaded libraries.
efe502bb 750 if (copy_if_diff($_, "$installlib/$name")) {
3a548b36 751 strip("-S", "$installlib/$name")
7eb35c03 752 if $^O eq 'darwin' and /\.(?:so|$dlext|a)$/;
de35015f
AB
753 chmod(/\.(so|$dlext)$/ ? $SO_MODE : $NON_SO_MODE,
754 "$installlib/$name");
efe502bb 755 }
a0d0e21e 756 }
a0d0e21e
LW
757 }
758}
3edbfbe5 759
16d20bd9
AD
760# Copy $from to $to, only if $from is different than $to.
761# Also preserve modification times for .a libraries.
762# On some systems, if you do
763# ranlib libperl.a
764# cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
765# and then try to link against the installed libperl.a, you might
766# get an error message to the effect that the symbol table is older
767# than the library.
aa3cf465 768# Return true if copying occurred.
68dc0745 769
770sub copy_if_diff {
3edbfbe5 771 my($from,$to)=@_;
8530e788 772 return 1 if (($^O eq 'VMS') && (-d $from));
5a9231b0 773 my $xto = $to;
99d21f8b 774 $xto =~ s/^\Q$opts{destdir}\E//;
5f239f73
JH
775 my $perlpodbadsymlink;
776 if ($from =~ m!^pod/perl[\w-]+\.pod$! &&
777 -l $from &&
778 ! -e $from) {
779 # Some Linux implementations have problems traversing over
780 # multiple symlinks (when going over NFS?) and fail to read
781 # the symlink target. Combine this with the fact that some
782 # of the pod files (the perl$OS.pod) are symlinks (to ../README.$OS),
783 # and you end up with those pods not getting installed.
784 $perlpodbadsymlink = 1;
785 }
786 -f $from || $perlpodbadsymlink || warn "$0: $from not found";
5a9231b0 787 $packlist->{$xto} = { type => 'file' };
c164bd94 788 if ($opts{force} || compare($from, $to) || $opts{notify}) {
68dc0745 789 safe_unlink($to); # In case we don't have write permissions.
5f239f73
JH
790 if ($perlpodbadsymlink && $from =~ m!^pod/perl(.+)\.pod$!) {
791 $from = "README.$1";
792 }
68dc0745 793 copy($from, $to);
794 # Restore timestamps if it's a .a library or for OS/2.
68006eea 795 if (!$opts{notify} && ($Is_OS2 || $to =~ /\.a$/)) {
68dc0745 796 my ($atime, $mtime) = (stat $from)[8,9];
16d20bd9
AD
797 utime $atime, $mtime, $to;
798 }
aa3cf465 799 1;
3edbfbe5
TB
800 }
801}
8f1f23e8
W
802
803sub strip
804{
805 my(@args) = @_;
806
4609f84f 807 return unless $opts{strip};
f556e5b9 808
8f1f23e8
W
809 my @opts;
810 while (@args && $args[0] =~ /^(-\w+)$/) {
2e2b85db 811 push @opts, shift @args;
8f1f23e8
W
812 }
813
814 foreach my $file (@args) {
2e2b85db 815 if (-f $file) {
68006eea 816 if ($opts{verbose}) {
2e2b85db
MB
817 print " strip " . join(' ', @opts);
818 print " " if (@opts);
819 print "$file\n";
820 }
821 system("strip", @opts, $file);
822 } else {
68006eea 823 print "# file '$file' skipped\n" if $opts{verbose};
2e2b85db 824 }
8f1f23e8
W
825 }
826}
8473bff1 827
8473bff1 828# ex: set ts=8 sts=4 sw=4 et: