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