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