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