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