Upgrade to Term::ANSIColor 1.04.
[p5sagit/p5-mst-13.2.git] / installperl
CommitLineData
c623bd54 1#!./perl
68dc0745 2
3BEGIN {
c90c0ff4 4 require 5.004;
d07c2202 5 chdir '..' if !-d 'lib' and -d '..\lib';
68dc0745 6 @INC = 'lib';
7 $ENV{PERL5LIB} = 'lib';
a29d2910 8}
9
10use strict;
5f675712 11my ($Is_VMS, $Is_W32, $Is_OS2, $Is_Cygwin, $nonono, $dostrip,
2986a63f 12 $versiononly, $silent, $verbose, $otherperls, $archname,$Is_NetWare, $nwinstall);
5f675712 13use vars qw /$depth/;
a29d2910 14
15BEGIN {
17f28c40 16 $Is_VMS = $^O eq 'VMS';
4a71ed0c 17 $Is_W32 = $^O eq 'MSWin32';
18 $Is_OS2 = $^O eq 'os2';
146174a9 19 $Is_Cygwin = $^O eq 'cygwin';
17f28c40 20 if ($Is_VMS) { eval 'use VMS::Filespec;' }
68dc0745 21}
22
c2cd2081 23my $scr_ext = ($Is_VMS ? '.Com' : $Is_W32 ? '.bat' : '');
4a71ed0c 24
a0d0e21e 25use File::Find;
5f05dabc 26use File::Compare;
68dc0745 27use File::Copy ();
0ecb046b 28use File::Path ();
354f3b56 29use ExtUtils::Packlist;
4633a7c4 30use Config;
91a06757 31use subs qw(unlink link chmod);
c623bd54 32
791b4ad3 33if ($Config{d_umask}) {
34 umask(022); # umasks like 077 aren't that useful for installations
35}
36
2986a63f 37$Is_NetWare = $Config{osname} eq 'NetWare';
38if ($Is_NetWare) {
39 $Is_W32 = 0;
40 $scr_ext = '.pl';
41}
42
0ecb046b 43# override the ones in the rest of the script
68dc0745 44sub mkpath {
45 File::Path::mkpath(@_) unless $nonono;
0ecb046b 46}
47
c2cd2081 48my $mainperldir = "/usr/bin";
49my $exe_ext = $Config{exe_ext};
bee1dbe2 50
6ee623d5 51# Allow ``make install PERLNAME=something_besides_perl'':
c2cd2081 52my $perl = defined($ENV{PERLNAME}) ? $ENV{PERLNAME} : 'perl';
6ee623d5 53
146174a9 54# This is the base used for versioned names, like "perl5.6.0".
beb13193 55# It's separate because a common use of $PERLNAME is to install
56# perl as "perl5", if that's used as base for versioned files you
146174a9 57# get "perl55.6.0".
beb13193 58my $perl_verbase = defined($ENV{PERLNAME_VERBASE})
59 ? $ENV{PERLNAME_VERBASE}
60 : $perl;
61
5f675712 62$otherperls = 1;
c623bd54 63while (@ARGV) {
64 $nonono = 1 if $ARGV[0] eq '-n';
f556e5b9 65 $dostrip = 1 if $ARGV[0] eq '-s';
c623bd54 66 $versiononly = 1 if $ARGV[0] eq '-v';
f4a342c3 67 $versiononly = 0 if $ARGV[0] eq '+v';
5f675712 68 $silent = 1 if $ARGV[0] eq '-S';
69 $otherperls = 0 if $ARGV[0] eq '-o';
4ad019ef 70 $verbose = 1 if $ARGV[0] eq '-V' || $ARGV [0] eq '-n';
f4a342c3 71 $archname = 1 if $ARGV[0] eq '-A';
2986a63f 72 $nwinstall = 1 if $ARGV[0] eq '-netware';
c623bd54 73 shift;
74}
75
f4a342c3 76$versiononly = 1 if $Config{versiononly} && !defined $versiononly;
21dae8a0 77my (@scripts, @tolink);
78open SCRIPTS, "utils.lst" or die "Can't open utils.lst: $!";
79while (<SCRIPTS>) {
80 next if /^#/;
81 next if /#\s*pod\s*=/; # Binary programs need separate treatment
82 chomp;
83 if (/(\S*)\s*#\s*link\s*=\s*(\S*)/) {
84 push @scripts, $1;
85 push @tolink, [$1, $2];
86 } else {
87 push @scripts, $_;
88 }
89}
90close SCRIPTS;
16d20bd9 91
4a71ed0c 92if ($scr_ext) { @scripts = map { "$_$scr_ext" } @scripts; }
17f28c40 93
c2cd2081 94my @pods = (<pod/*.pod>);
c623bd54 95
e8ea6127 96# Specify here any .pm files that are actually architecture-dependent.
97# (Those included with XS extensions under ext/ are automatically
98# added later.)
99# Now that the default privlib has the full perl version number included,
100# we no longer have to play the trick of sticking version-specific .pm
101# files under the archlib directory.
c2cd2081 102my %archpms = (
e8ea6127 103 Config => 1,
a8efb694 104 lib => 1,
38b8243a 105);
39e571d4 106
107if ($^O eq 'dos') {
108 push(@scripts,'djgpp/fixpmain');
109 $archpms{config} = $archpms{filehand} = 1;
110}
111
6ee623d5 112if ((-e "testcompile") && (defined($ENV{'COMPILE'})))
113{
114 push(@scripts, map("$_.exe", @scripts));
115}
116
1dd15ed4 117find(sub {
68c887af 118 if ("$File::Find::dir/$_" =~ m{^ext\b(.*)/([^/]+)\.pm$}) {
119 my($path, $modname) = ($1,$2);
120
121 # strip trailing component first
122 $path =~ s{/[^/]*$}{};
123
124 # strip optional "/lib";
125 $path =~ s{/lib\b}{};
126
127 # strip any leading /
128 $path =~ s{^/}{};
129
130 # reconstitute canonical module name
131 $modname = "$path/$modname" if length $path;
132
133 # remember it
134 $archpms{$modname} = 1;
1dd15ed4 135 }
136 }, 'ext');
137
68c887af 138# print "[$_]\n" for sort keys %archpms;
139
146174a9 140my $ver = $Config{version};
f2766b05 141my $release = substr($],0,3); # Not used currently.
03284eb6 142my $patchlevel = substr($],3,2);
748a9306 143die "Patchlevel of perl ($patchlevel)",
cceca5ed 144 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
145 if $patchlevel != $Config{'PERL_VERSION'};
4633a7c4 146
147# Fetch some frequently-used items from %Config
c2cd2081 148my $installbin = $Config{installbin};
149my $installscript = $Config{installscript};
150my $installprivlib = $Config{installprivlib};
151my $installarchlib = $Config{installarchlib};
152my $installsitelib = $Config{installsitelib};
153my $installsitearch = $Config{installsitearch};
154my $installman1dir = $Config{installman1dir};
155my $man1ext = $Config{man1ext};
156my $libperl = $Config{libperl};
4633a7c4 157# Shared library and dynamic loading suffixes.
c2cd2081 158my $so = $Config{so};
159my $dlext = $Config{dlext};
146174a9 160my $dlsrc = $Config{dlsrc};
f2766b05 161if ($^O eq 'os390') {
162 my $pwd;
163 chomp($pwd=`pwd`);
164 my $archlibexp = $Config{archlibexp};
165 my $usedl = $Config{usedl};
166 if ($usedl eq 'define') {
167 `./$^X -pibak -e 's{$pwd\/libperl.x}{$archlibexp/CORE/libperl.x}' lib/Config.pm`;
168 }
169}
4633a7c4 170
2986a63f 171if ($nwinstall) {
172 # This is required only if we are installing on a NetWare server
173 $installscript = $Config{installnwscripts};
174 $installprivlib = $Config{installnwlib};
175 $installarchlib = $Config{installnwlib};
176 $installsitelib = $Config{installnwlib};
177}
178
c2cd2081 179my $d_dosuid = $Config{d_dosuid};
180my $binexp = $Config{binexp};
c623bd54 181
17f28c40 182if ($Is_VMS) { # Hang in there until File::Spec hits the big time
183 foreach ( \$installbin, \$installscript, \$installprivlib,
184 \$installarchlib, \$installsitelib, \$installsitearch,
185 \$installman1dir ) {
186 $$_ = unixify($$_); $$_ =~ s:/$::;
187 }
188}
189
c623bd54 190# Do some quick sanity checks.
191
192if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
193
fe14fcc3 194 $installbin || die "No installbin directory in config.sh\n";
7e7af249 195-d $installbin || mkpath($installbin, $verbose, 0777);
0ecb046b 196-d $installbin || $nonono || die "$installbin is not a directory\n";
197-w $installbin || $nonono || die "$installbin is not writable by you\n"
3edbfbe5 198 unless $installbin =~ m#^/afs/# || $nonono;
c623bd54 199
2986a63f 200if (!$Is_NetWare) {
39add537 201-x 'perl' . $exe_ext || die "perl isn't executable!\n";
202-x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid;
c623bd54 203
9fba8746 204-f 't/rantests' || $Is_W32
1af49140 205 || warn "WARNING: You've never run 'make test' or",
206 " some tests failed! (Installing anyway.)\n";
2986a63f 207} #if (!$Is_NetWare)
c623bd54 208
2986a63f 209if (($Is_W32 and ! $Is_NetWare) or $Is_Cygwin) {
8736538c 210 my $perldll;
211
5f675712 212 if ($Is_Cygwin) {
213 $perldll = $libperl;
214 $perldll =~ s/(\..*)?$/.$dlext/;
215 if ($Config{useshrplib} eq 'true') {
216 # install ld2 and perlld as well
217 foreach ('ld2', 'perlld') {
218 safe_unlink("$installbin/$_");
219 copy("$_", "$installbin/$_");
220 chmod(0755, "$installbin/$_");
221 };
8736538c 222 };
5f675712 223 } else {
b962b4fa 224 $perldll = 'perl57.' . $dlext;
5f675712 225 }
226
227 if ($dlsrc ne "dl_none.xs") {
228 -f $perldll || die "No perl DLL built\n";
229 }
230 # Install the DLL
231
232 safe_unlink("$installbin/$perldll");
233 copy("$perldll", "$installbin/$perldll");
234 chmod(0755, "$installbin/$perldll");
146174a9 235
2986a63f 236} # if (($Is_W32 and ! $Is_NetWare) or $Is_Cygwin)
eef1cf2a 237
354f3b56 238# This will be used to store the packlist
c2cd2081 239my $packlist = ExtUtils::Packlist->new("$installarchlib/.packlist");
354f3b56 240
c623bd54 241# First we install the version-numbered executables.
242
17f28c40 243if ($Is_VMS) {
6ee623d5 244 safe_unlink("$installbin/$perl$exe_ext");
245 copy("perl$exe_ext", "$installbin/$perl$exe_ext");
246 chmod(0755, "$installbin/$perl$exe_ext");
247 safe_unlink("$installbin/${perl}shr$exe_ext");
248 copy("perlshr$exe_ext", "$installbin/${perl}shr$exe_ext");
249 chmod(0755, "$installbin/${perl}shr$exe_ext");
17f28c40 250}
1d84e8df 251elsif ($^O eq 'mpeix') {
252 # MPE lacks hard links and requires that executables with special
253 # capabilities reside in the MPE namespace.
254 safe_unlink("$installbin/perl$ver$exe_ext", $Config{perlpath});
255 # Install the primary executable into the MPE namespace as perlpath.
256 copy("perl$exe_ext", $Config{perlpath});
257 chmod(0755, $Config{perlpath});
258 # Create a backup copy with the version number.
259 link($Config{perlpath}, "$installbin/perl$ver$exe_ext");
260}
3f5ee302 261elsif ($^O ne 'dos') {
2986a63f 262 if (!$Is_NetWare) {
263 safe_unlink("$installbin/$perl_verbase$ver$exe_ext");
264 copy("perl$exe_ext", "$installbin/$perl_verbase$ver$exe_ext");
265 strip("$installbin/$perl_verbase$ver$exe_ext");
266 chmod(0755, "$installbin/$perl_verbase$ver$exe_ext");
267 }
268 else {
269 # If installing onto a NetWare server
270 if ($nwinstall) {
271 # Copy perl.nlm, echo.nlm, type.nlm, a2p.nlm & cgi2perl.nlm
272 mkpath($Config{installnwsystem}, 1, 0777);
273 copy("netware\\".$ENV{'MAKE_TYPE'}."\\perl.nlm", $Config{installnwsystem});
274 copy("netware\\testnlm\\echo\\echo.nlm", $Config{installnwsystem});
275 copy("netware\\testnlm\\type\\type.nlm", $Config{installnwsystem});
276 copy("x2p\\a2p.nlm", $Config{installnwsystem});
277 chmod(0755, "$Config{installnwsystem}\\perl.nlm");
278 mkpath($Config{installnwlcgi}, 1, 0777);
279 copy("lib\\auto\\cgi2perl\\cgi2perl.nlm", $Config{installnwlcgi});
280 }
281 } #if (!$Is_NetWare)
3f5ee302 282}
1d84e8df 283else {
6ee623d5 284 safe_unlink("$installbin/$perl.exe");
285 copy("perl.exe", "$installbin/$perl.exe");
39e571d4 286}
c623bd54 287
beb13193 288safe_unlink("$installbin/s$perl_verbase$ver$exe_ext");
c623bd54 289if ($d_dosuid) {
beb13193 290 copy("suidperl$exe_ext", "$installbin/s$perl_verbase$ver$exe_ext");
291 chmod(04711, "$installbin/s$perl_verbase$ver$exe_ext");
c623bd54 292}
293
45d8adaa 294# Install library files.
295
c2cd2081 296my ($do_installarchlib, $do_installprivlib) = (0, 0);
a0d0e21e 297
7e7af249 298mkpath($installprivlib, $verbose, 0777);
299mkpath($installarchlib, $verbose, 0777);
300mkpath($installsitelib, $verbose, 0777) if ($installsitelib);
301mkpath($installsitearch, $verbose, 0777) if ($installsitearch);
4633a7c4 302
45d8adaa 303if (chdir "lib") {
68dc0745 304 $do_installarchlib = ! samepath($installarchlib, '.');
305 $do_installprivlib = ! samepath($installprivlib, '.');
146174a9 306 $do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$ver/);
45d8adaa 307
a0d0e21e 308 if ($do_installarchlib || $do_installprivlib) {
309 find(\&installlib, '.');
45d8adaa 310 }
311 chdir ".." || die "Can't cd back to source directory: $!\n";
312}
313else {
314 warn "Can't cd to lib to install lib files: $!\n";
315}
316
1aef975c 317# Install header files and libraries.
7e7af249 318mkpath("$installarchlib/CORE", $verbose, 0777);
c2cd2081 319my @corefiles;
17f28c40 320if ($Is_VMS) { # We did core file selection during build
0185066f 321 my $coredir = "lib/$Config{archname}/$ver/CORE";
17f28c40 322 $coredir =~ tr/./_/;
0185066f 323 map { s|^$coredir/||i; } @corefiles = <$coredir/*.*>;
17f28c40 324}
325else {
8736538c 326 # [als] hard-coded 'libperl' name... not good!
17f28c40 327 @corefiles = <*.h libperl*.*>;
8736538c 328
17f28c40 329 # AIX needs perl.exp installed as well.
330 push(@corefiles,'perl.exp') if $^O eq 'aix';
9d7f10f2 331 if ($^O eq 'mpeix') {
332 # MPE needs mpeixish.h installed as well.
7e7af249 333 mkpath("$installarchlib/CORE/mpeix", $verbose, 0777);
9d7f10f2 334 push(@corefiles,'mpeix/mpeixish.h');
335 }
17f28c40 336 # If they have built sperl.o...
337 push(@corefiles,'sperl.o') if -f 'sperl.o';
338}
c2cd2081 339foreach my $file (@corefiles) {
aa3cf465 340 # HP-UX (at least) needs to maintain execute permissions
efc5ad56 341 # on dynamically-loadable libraries. So we do it for all.
8f1f23e8 342 if (copy_if_diff($file,"$installarchlib/CORE/$file")) {
f556e5b9 343 if ($file =~ /\.(\Q$so\E|\Q$dlext\E)$/) {
8f1f23e8 344 chmod(0555, "$installarchlib/CORE/$file");
f556e5b9 345 strip("-S", "$installarchlib/CORE/$file") if $^O =~ /^(rhapsody|darwin)$/;
8f1f23e8 346 } else {
347 chmod(0444, "$installarchlib/CORE/$file");
348 }
349 }
340f689c 350}
3edbfbe5 351
156620fa 352# Install main perl executables
353# Make links to ordinary names if installbin directory isn't current directory.
354
2986a63f 355if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS && ! $Is_NetWare) {
6ee623d5 356 safe_unlink("$installbin/$perl$exe_ext", "$installbin/suid$perl$exe_ext");
1d84e8df 357 if ($^O eq 'mpeix') {
358 # MPE doesn't support hard links, so use a symlink.
359 # We don't want another cloned copy.
360 symlink($Config{perlpath}, "$installbin/perl$exe_ext");
361 } else {
beb13193 362 link("$installbin/$perl_verbase$ver$exe_ext",
363 "$installbin/$perl$exe_ext");
1d84e8df 364 }
beb13193 365 link("$installbin/s$perl_verbase$ver$exe_ext",
366 "$installbin/suid$perl$exe_ext")
156620fa 367 if $d_dosuid;
368}
369
f4a342c3 370# For development purposes it can be very useful to have multiple perls
371# build for different "architectures" (eg threading or not) simultaneously.
372if ($archname && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS) {
373 my $archperl = "$perl_verbase$ver-$Config{archname}$exe_ext";
374 safe_unlink("$installbin/$archperl");
375 if ($^O eq 'mpeix') {
376 # MPE doesn't support hard links, so use a symlink.
377 # We don't want another cloned copy.
378 symlink($Config{perlpath}, "$installbin/$archperl");
379 } else {
380 link("$installbin/$perl_verbase$ver$exe_ext",
381 "$installbin/$archperl");
382 }
383}
384
a0d0e21e 385# Offer to install perl in a "standard" location
386
c2cd2081 387my $mainperl_is_instperl = 0;
a0d0e21e 388
a3ed4895 389if ($Config{installusrbinperl} && $Config{installusrbinperl} eq 'define' &&
2986a63f 390 !$versiononly && !$nonono && !$Is_W32 && !$Is_NetWare && !$Is_VMS && -t STDIN && -t STDERR
68dc0745 391 && -w $mainperldir && ! samepath($mainperldir, $installbin)) {
c2cd2081 392 my($usrbinperl) = "$mainperldir/$perl$exe_ext";
393 my($instperl) = "$installbin/$perl$exe_ext";
394 my($expinstperl) = "$binexp/$perl$exe_ext";
55497cff 395
396 # First make sure $usrbinperl is not already the same as the perl we
397 # just installed.
398 if (-x $usrbinperl) {
a0d0e21e 399 # Try to be clever about mainperl being a symbolic link
400 # to binexp/perl if binexp and installbin are different.
401 $mainperl_is_instperl =
68dc0745 402 samepath($usrbinperl, $instperl) ||
403 samepath($usrbinperl, $expinstperl) ||
a0d0e21e 404 (($binexp ne $installbin) &&
55497cff 405 (-l $usrbinperl) &&
406 ((readlink $usrbinperl) eq $expinstperl));
a0d0e21e 407 }
408 if ((! $mainperl_is_instperl) &&
68dc0745 409 (yn("Many scripts expect perl to be installed as $usrbinperl.\n" .
55497cff 410 "Do you wish to have $usrbinperl be the same as\n" .
411 "$expinstperl? [y] ")))
1d84e8df 412 {
55497cff 413 unlink($usrbinperl);
1d84e8df 414 ( $Config{'d_link'} eq 'define' &&
415 eval { CORE::link $instperl, $usrbinperl } ) ||
416 eval { symlink $expinstperl, $usrbinperl } ||
417 copy($instperl, $usrbinperl);
418
a0d0e21e 419 $mainperl_is_instperl = 1;
420 }
421}
422
b971f6e4 423# Make links to ordinary names if installbin directory isn't current directory.
2986a63f 424if (!$Is_NetWare) {
425 if (!$versiononly && ! samepath($installbin, 'x2p')) {
426 safe_unlink("$installbin/a2p$exe_ext");
427 copy("x2p/a2p$exe_ext", "$installbin/a2p$exe_ext");
428 chmod(0755, "$installbin/a2p$exe_ext");
429 }
b971f6e4 430}
431
432# cppstdin is just a script, but it is architecture-dependent, so
433# it can't safely be shared. Place it in $installbin.
434# Note that Configure doesn't build cppstin if it isn't needed, so
435# we skip this if cppstdin doesn't exist.
68dc0745 436if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) {
437 safe_unlink("$installbin/cppstdin");
438 copy("cppstdin", "$installbin/cppstdin");
439 chmod(0755, "$installbin/cppstdin");
b971f6e4 440}
441
1a09d0c8 442sub script_alias {
443 my ($installscript, $orig, $alias, $scr_ext) = @_;
444
eea3e086 445 safe_unlink("$installscript/$alias$scr_ext");
1a09d0c8 446 if ($^O eq 'dos' or $Is_VMS or $^O eq 'transit') {
447 copy("$installscript/$orig$scr_ext",
448 "$installscript/$alias$scr_ext");
449 } else {
450 link("$installscript/$orig$scr_ext",
451 "$installscript/$alias$scr_ext");
452 }
453}
454
c8f392da 455# Install scripts.
456mkpath($installscript, $verbose, 0777);
457if ($versiononly) {
458 for (@scripts) {
459 (my $base = $_) =~ s#.*/##;
460 $base .= $ver;
461 copy($_, "$installscript/$base");
462 chmod(0755, "$installscript/$base");
463 }
b971f6e4 464
c8f392da 465 for (@tolink) {
466 my ($from, $to) = map { "$_$ver" } @$_;
467 (my $frbase = $from) =~ s#.*/##;
468 (my $tobase = $to) =~ s#.*/##;
469 script_alias($installscript, $frbase, $tobase, $scr_ext);
470 }
471} else {
22e77942 472 for (@scripts) {
473 (my $base = $_) =~ s#.*/##;
474 copy($_, "$installscript/$base");
475 chmod(0755, "$installscript/$base");
b971f6e4 476 }
22e77942 477
21dae8a0 478 for (@tolink) {
c8f392da 479 my ($from, $to) = @$_;
21dae8a0 480 (my $frbase = $from) =~ s#.*/##;
481 (my $tobase = $to) =~ s#.*/##;
482 script_alias($installscript, $frbase, $tobase, $scr_ext);
483 }
b971f6e4 484}
485
146174a9 486# Install pod pages. Where? I guess in $installprivlib/pod
487# ($installprivlib/pods for cygwin).
b971f6e4 488
146174a9 489my $pod = $Is_Cygwin ? 'pods' : 'pod';
d56c5707 490if ( !$versiononly || ($installprivlib =~ m/\Q$ver/)) {
7e7af249 491 mkpath("${installprivlib}/$pod", $verbose, 0777);
91a06757 492
493 # If Perl 5.003's perldiag.pod is there, rename it.
146174a9 494 if (open POD, "${installprivlib}/$pod/perldiag.pod") {
91a06757 495 read POD, $_, 4000;
496 close POD;
497 # Some of Perl 5.003's diagnostic messages ended with periods.
498 if (/^=.*\.$/m) {
146174a9 499 my ($from, $to) = ("${installprivlib}/$pod/perldiag.pod",
500 "${installprivlib}/$pod/perldiag-5.003.pod");
f311e742 501 print " rename $from $to";
91a06757 502 rename($from, $to)
503 or warn "Couldn't rename $from to $to: $!\n"
504 unless $nonono;
505 }
506 }
507
146174a9 508 for (@pods) {
509 # $_ is a name like pod/perl.pod
510 (my $base = $_) =~ s#.*/##;
511 copy_if_diff($_, "${installprivlib}/$pod/${base}");
b971f6e4 512 }
91a06757 513
b971f6e4 514}
515
a0d0e21e 516# Check to make sure there aren't other perls around in installer's
517# path. This is probably UNIX-specific. Check all absolute directories
518# in the path except for where public executables are supposed to live.
519# Also skip $mainperl if the user opted to have it be a link to the
520# installed perl.
521
5f675712 522if (!$versiononly && $otherperls) {
146174a9 523 my ($path, @path);
2986a63f 524 my $dirsep = ($Is_OS2 || $Is_W32 || $Is_NetWare) ? ';' : ':' ;
b971f6e4 525 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
526 @path = split(/$dirsep/, $path);
17f28c40 527 if ($Is_VMS) {
528 my $i = 0;
529 while (exists $ENV{'DCL$PATH' . $i}) {
c2cd2081 530 my $dir = unixpath($ENV{'DCL$PATH' . $i}); $dir =~ s-/$--;
17f28c40 531 push(@path,$dir);
532 }
533 }
c2cd2081 534 my @otherperls;
160a7e37 535 my %otherperls;
b971f6e4 536 for (@path) {
537 next unless m,^/,;
538 # Use &samepath here because some systems have other dirs linked
539 # to $mainperldir (like SunOS)
68dc0745 540 next if samepath($_, $binexp);
541 next if ($mainperl_is_instperl && samepath($_, $mainperldir));
160a7e37 542 my $otherperl = "$_/$perl$exe_ext";
543 next if $otherperls{$otherperl}++;
544 push(@otherperls, $otherperl)
545 if (-x $otherperl && ! -d $otherperl);
b971f6e4 546 }
547 if (@otherperls) {
5f675712 548 warn "\nWarning: $perl appears in your path in the following " .
b971f6e4 549 "locations beyond where\nwe just installed it:\n";
550 for (@otherperls) {
5f675712 551 warn " ", $_, "\n";
b971f6e4 552 }
5f675712 553 warn "\n";
a0d0e21e 554 }
b971f6e4 555
a0d0e21e 556}
557
3f9aafa0 558$packlist->write() unless $nonono;
94b11c62 559print " Installation complete\n" if $verbose;
c623bd54 560
561exit 0;
562
563###############################################################################
564
a0d0e21e 565sub yn {
c2cd2081 566 my($prompt) = @_;
567 my($answer);
568 my($default) = $prompt =~ m/\[([yn])\]\s*$/i;
802cdca0 569 print STDERR $prompt;
a0d0e21e 570 chop($answer = <STDIN>);
571 $answer = $default if $answer =~ m/^\s*$/;
572 ($answer =~ m/^[yY]/);
573}
574
c623bd54 575sub unlink {
c2cd2081 576 my(@names) = @_;
39add537 577 my($cnt) = 0;
c623bd54 578
17f28c40 579 return scalar(@names) if $Is_VMS;
580
c2cd2081 581 foreach my $name (@names) {
c623bd54 582 next unless -e $name;
2986a63f 583 chmod 0777, $name if ($Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare);
94b11c62 584 print " unlink $name\n" if $verbose;
39add537 585 ( CORE::unlink($name) and ++$cnt
586 or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
c623bd54 587 }
39add537 588 return $cnt;
c623bd54 589}
590
e50aee73 591sub safe_unlink {
17f28c40 592 return if $nonono or $Is_VMS;
c2cd2081 593 my @names = @_;
594 foreach my $name (@names) {
e50aee73 595 next unless -e $name;
2986a63f 596 chmod 0777, $name if ($Is_OS2 || $Is_W32 || $Is_NetWare);
94b11c62 597 print " unlink $name\n" if $verbose;
39add537 598 next if CORE::unlink($name);
e50aee73 599 warn "Couldn't unlink $name: $!\n";
600 if ($! =~ /busy/i) {
94b11c62 601 print " mv $name $name.old\n" if $verbose;
68dc0745 602 safe_rename($name, "$name.old")
603 or warn "Couldn't rename $name: $!\n";
e50aee73 604 }
605 }
606}
607
68dc0745 608sub safe_rename {
c2cd2081 609 my($from,$to) = @_;
55a105fd 610 if (-f $to and not unlink($to)) {
e50aee73 611 my($i);
612 for ($i = 1; $i < 50; $i++) {
91a06757 613 last if rename($to, "$to.$i");
e50aee73 614 }
39add537 615 warn("Cannot rename to `$to.$i': $!"), return 0
616 if $i >= 50; # Give up!
e50aee73 617 }
618 link($from,$to) || return 0;
55a105fd 619 unlink($from);
e50aee73 620}
621
c623bd54 622sub link {
15792f64 623 my($from,$to) = @_;
624 my($success) = 0;
c623bd54 625
94b11c62 626 print $verbose ? " ln $from $to\n" : " $to\n" unless $silent;
39add537 627 eval {
68dc0745 628 CORE::link($from, $to)
629 ? $success++
7bac28a0 630 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
631 ? die "AFS" # okay inside eval {}
146174a9 632 : die "Couldn't link $from to $to: $!\n"
68dc0745 633 unless $nonono;
354f3b56 634 $packlist->{$to} = { from => $from, type => 'link' };
39add537 635 };
636 if ($@) {
146174a9 637 warn $@;
94b11c62 638 print $verbose ? " cp $from $to\n" : " $to\n" unless $silent;
5f675712 639 print " creating new version of $to\n"
640 if $Is_VMS and -e $to and !$silent;
68dc0745 641 File::Copy::copy($from, $to)
642 ? $success++
643 : warn "Couldn't copy $from to $to: $!\n"
644 unless $nonono;
354f3b56 645 $packlist->{$to} = { type => 'file' };
39add537 646 }
15792f64 647 $success;
c623bd54 648}
649
650sub chmod {
c2cd2081 651 my($mode,$name) = @_;
c623bd54 652
39e571d4 653 return if ($^O eq 'dos');
94b11c62 654 printf " chmod %o %s\n", $mode, $name if $verbose;
68dc0745 655 CORE::chmod($mode,$name)
656 || warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name)
657 unless $nonono;
658}
659
660sub copy {
661 my($from,$to) = @_;
662
94b11c62 663 print $verbose ? " cp $from $to\n" : " $to\n" unless $silent;
5f675712 664 print " creating new version of $to\n" if $Is_VMS and -e $to and !$silent;
68dc0745 665 File::Copy::copy($from, $to)
666 || warn "Couldn't copy $from to $to: $!\n"
667 unless $nonono;
354f3b56 668 $packlist->{$to} = { type => 'file' };
c623bd54 669}
670
a0d0e21e 671sub samepath {
c2cd2081 672 my($p1, $p2) = @_;
eef1cf2a 673
2986a63f 674 return (lc($p1) eq lc($p2)) if ($Is_W32 || $Is_NetWare);
a0d0e21e 675
75f92628 676 if ($p1 ne $p2) {
c2cd2081 677 my($dev1, $ino1, $dev2, $ino2);
a0d0e21e 678 ($dev1, $ino1) = stat($p1);
679 ($dev2, $ino2) = stat($p2);
680 ($dev1 == $dev2 && $ino1 == $ino2);
681 }
682 else {
683 1;
684 }
685}
686
687sub installlib {
688 my $dir = $File::Find::dir;
689 $dir =~ s#^\.(?![^/])/?##;
0ecb046b 690 local($depth) = $dir ? "lib/$dir" : "lib";
a0d0e21e 691
692 my $name = $_;
efc5ad56 693
146174a9 694 # Ignore RCS and CVS directories.
695 if (($name eq 'CVS' or $name eq 'RCS') and -d $name) {
efc5ad56 696 $File::Find::prune = 1;
697 return;
698 }
e50aee73 699
146174a9 700 # ignore patch backups, RCS files, emacs backup & temp files and the
b695f709 701 # .exists files, .PL files, and .t files.
702 return if $name =~ m{\.orig$|~$|^#.+#$|,v$|^\.exists|\.PL$|\.t$};
703
a0d0e21e 704 $name = "$dir/$name" if $dir ne '';
705
706 my $installlib = $installprivlib;
1dd15ed4 707 if ($dir =~ /^auto/ ||
eef1cf2a 708 ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) ||
2986a63f 709 ($name =~ /^(.*)\.(?:h|lib)$/i && ($Is_W32 || $Is_NetWare))
eef1cf2a 710 ) {
a0d0e21e 711 $installlib = $installarchlib;
712 return unless $do_installarchlib;
713 } else {
714 return unless $do_installprivlib;
715 }
716
a0d0e21e 717 if (-f $_) {
5cc330c8 718 if (/\.(?:al|ix)$/ && !($dir =~ m[^auto/(.*)$] && $archpms{$1})) {
3edbfbe5 719 $installlib = $installprivlib;
720 #We're installing *.al and *.ix files into $installprivlib,
721 #but we have to delete old *.al and *.ix files from the 5.000
722 #distribution:
75f92628 723 #This might not work because $archname might have changed.
55a105fd 724 unlink("$installarchlib/$name");
3edbfbe5 725 }
354f3b56 726 $packlist->{"$installlib/$name"} = { type => 'file' };
5f05dabc 727 if (compare($_, "$installlib/$name") || $nonono) {
55a105fd 728 unlink("$installlib/$name");
7e7af249 729 mkpath("$installlib/$dir", $verbose, 0777);
75f92628 730 # HP-UX (at least) needs to maintain execute permissions
731 # on dynamically-loaded libraries.
2986a63f 732 if ($Is_NetWare && !$nwinstall) {
733 # Don't copy .nlp,.nlm files, doesn't make sense on Windows and also
734 # if copied will give problems when building new extensions.
735 # Has to be copied if we are installing on a NetWare server and hence
736 # the check !$nwinstall
737 if (!(/\.(?:nlp|nlm|bs)$/)) {
738 copy_if_diff($_, "$installlib/$name")
739 and chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444,
740 "$installlib/$name");
741 }
742 } else {
743 copy_if_diff($_, "$installlib/$name")
744 and chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444,
aa3cf465 745 "$installlib/$name");
2986a63f 746 } #if ($Is_NetWare)
a0d0e21e 747 }
a0d0e21e 748 }
749}
3edbfbe5 750
16d20bd9 751# Copy $from to $to, only if $from is different than $to.
752# Also preserve modification times for .a libraries.
753# On some systems, if you do
754# ranlib libperl.a
755# cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
756# and then try to link against the installed libperl.a, you might
757# get an error message to the effect that the symbol table is older
758# than the library.
aa3cf465 759# Return true if copying occurred.
68dc0745 760
761sub copy_if_diff {
3edbfbe5 762 my($from,$to)=@_;
8530e788 763 return 1 if (($^O eq 'VMS') && (-d $from));
f0963acb 764 -f $from || warn "$0: $from not found";
354f3b56 765 $packlist->{$to} = { type => 'file' };
5f05dabc 766 if (compare($from, $to) || $nonono) {
68dc0745 767 safe_unlink($to); # In case we don't have write permissions.
0ecb046b 768 if ($nonono) {
769 $from = $depth . "/" . $from if $depth;
770 }
68dc0745 771 copy($from, $to);
772 # Restore timestamps if it's a .a library or for OS/2.
4a71ed0c 773 if (!$nonono && ($Is_OS2 || $to =~ /\.a$/)) {
68dc0745 774 my ($atime, $mtime) = (stat $from)[8,9];
16d20bd9 775 utime $atime, $mtime, $to;
776 }
aa3cf465 777 1;
3edbfbe5 778 }
779}
8f1f23e8 780
781sub strip
782{
783 my(@args) = @_;
784
f556e5b9 785 return unless $dostrip;
786
8f1f23e8 787 my @opts;
788 while (@args && $args[0] =~ /^(-\w+)$/) {
789 push @opts, shift @args;
790 }
791
792 foreach my $file (@args) {
793 if (-f $file) {
94b11c62 794 print " strip $file\n" if $verbose;
8f1f23e8 795 system("strip", @opts, $file);
796 } else {
94b11c62 797 print "# file '$file' skipped\n" if $verbose;
8f1f23e8 798 }
799 }
800}
801