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