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