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