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