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