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