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