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