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