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