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