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