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