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