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