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