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