This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In installperl rename $opt{dostrip} to $opt{strip}.
[perl5.git] / installperl
CommitLineData
dca8fd5c 1#!./perl -w
68dc0745
PP
2
3BEGIN {
c90c0ff4 4 require 5.004;
922ef74c 5 chdir '..' if !-d 'lib' and -d '../lib';
68dc0745
PP
6 @INC = 'lib';
7 $ENV{PERL5LIB} = 'lib';
a29d2910 8
dca8fd5c 9 # This needs to be at BEGIN time, before any use of Config
9e6fc21f 10 require './install_lib.pl';
1d230ada
NC
11}
12
a29d2910 13use strict;
9e6fc21f
NC
14use vars qw($Is_VMS $Is_W32 $Is_OS2 $Is_Cygwin $Is_Darwin $Is_NetWare
15 %opts $packlist);
c164bd94 16my $versiononly;
a29d2910
A
17
18BEGIN {
17f28c40 19 if ($Is_VMS) { eval 'use VMS::Filespec;' }
68dc0745
PP
20}
21
c2cd2081 22my $scr_ext = ($Is_VMS ? '.Com' : $Is_W32 ? '.bat' : '');
4a71ed0c 23
a0d0e21e 24use File::Find;
5f05dabc 25use File::Compare;
68dc0745 26use File::Copy ();
0ecb046b 27use File::Path ();
354f3b56 28use ExtUtils::Packlist;
ebef0ab4 29use Cwd;
791b4ad3 30
91e41fa7
NC
31require './Porting/pod_lib.pl';
32
2986a63f 33if ($Is_NetWare) {
2e2b85db
MB
34 $Is_W32 = 0;
35 $scr_ext = '.pl';
2986a63f
JH
36}
37
0ecb046b 38# override the ones in the rest of the script
68dc0745 39sub mkpath {
68006eea 40 File::Path::mkpath(@_) unless $opts{notify};
0ecb046b 41}
42
c2cd2081
KS
43my $mainperldir = "/usr/bin";
44my $exe_ext = $Config{exe_ext};
bee1dbe2 45
dca8fd5c 46# Allow "make install PERLNAME=something_besides_perl":
c2cd2081 47my $perl = defined($ENV{PERLNAME}) ? $ENV{PERLNAME} : 'perl';
6ee623d5 48
146174a9 49# This is the base used for versioned names, like "perl5.6.0".
beb13193
RS
50# It's separate because a common use of $PERLNAME is to install
51# perl as "perl5", if that's used as base for versioned files you
146174a9 52# get "perl55.6.0".
beb13193
RS
53my $perl_verbase = defined($ENV{PERLNAME_VERBASE})
54 ? $ENV{PERLNAME_VERBASE}
55 : $perl;
5d25492c
PP
56my $dbg = '';
57my $ndbg = '';
58if ( $Is_VMS ) {
59 if ( defined $Config{usevmsdebug} ) {
60 if ( $Config{usevmsdebug} eq 'define' ) {
61 $dbg = 'dbg';
62 $ndbg = 'ndbg';
63 }
64 }
65}
beb13193 66
99d21f8b
NC
67# This little hack simplifies making the code after the comment "Fetch some
68# frequently-used items from %Config" warning free. With $opts{destdir} always
69# defined, it's also possible to make the s/\Q$opts{destdir}\E unconditional.
70
71$opts{destdir} = '';
dca8fd5c
NC
72# Consider refactoring this to use Getopt::Long once Getopt::Long's planned
73# feature is implemented, to distinguish + and - options.
c623bd54 74while (@ARGV) {
68006eea 75 $opts{notify} = 1 if $ARGV[0] eq '-n';
4609f84f 76 $opts{strip} = 1 if $ARGV[0] eq '-s';
c623bd54 77 $versiononly = 1 if $ARGV[0] eq '-v';
f4a342c3 78 $versiononly = 0 if $ARGV[0] eq '+v';
68006eea 79 $opts{silent} = 1 if $ARGV[0] eq '-S';
c164bd94
NC
80 $opts{'skip-otherperls'} = 1 if $ARGV[0] eq '-o';
81 $opts{force} = 1 if $ARGV[0] eq '-f';
68006eea 82 $opts{verbose} = 1 if $ARGV[0] eq '-V' || $ARGV [0] eq '-n';
c164bd94
NC
83 $opts{archname} = 1 if $ARGV[0] eq '-A';
84 $opts{netware} = 1 if $ARGV[0] eq '-netware';
85 $opts{nopods} = 1 if $ARGV[0] eq '-p';
2227e2d5 86 $opts{destdir} = $1 if $ARGV[0] =~ /^-?-destdir=(.*)$/;
33bd2d8f 87 if ($ARGV[0] eq '-?' or $ARGV[0] =~ /^-?-h/) {
2e2b85db 88 print <<"EOT";
33bd2d8f
NC
89Usage $0: [switches]
90 -n Don't actually run any commands; just print them.
91 -s Run strip on installed binaries.
92 -v Only install perl as a binary with the version number in the name.
93 (Override whatever config.sh says)
94 +v Install perl as "perl" and as a binary with the version number in
95 the name. (Override whatever config.sh says)
96 -S Silent mode.
2e2b85db 97 -f Force installation (don't check if same version is there)
33bd2d8f
NC
98 -o Skip checking for other copies of perl in your PATH.
99 -V Verbose mode.
100 -A Also install perl with the architecture's name in the perl binary's
101 name.
4f048c5d 102 -p Don't install the pod files. [This will break use diagnostics;]
33bd2d8f 103 -netware Install correctly on a Netware server.
70eaf669 104 -destdir Prefix installation directories by this string.
33bd2d8f 105EOT
2e2b85db 106 exit;
33bd2d8f 107 }
c623bd54
LW
108 shift;
109}
110
f4a342c3 111$versiononly = 1 if $Config{versiononly} && !defined $versiononly;
21dae8a0
SC
112my (@scripts, @tolink);
113open SCRIPTS, "utils.lst" or die "Can't open utils.lst: $!";
114while (<SCRIPTS>) {
115 next if /^#/;
71c9e11c 116 next if /a2p/; # a2p is binary, to be installed separately
21dae8a0
SC
117 chomp;
118 if (/(\S*)\s*#\s*link\s*=\s*(\S*)/) {
2e2b85db
MB
119 push @scripts, $1;
120 push @tolink, [$1, $2];
21dae8a0 121 } else {
2e2b85db 122 push @scripts, $_;
21dae8a0
SC
123 }
124}
125close SCRIPTS;
16d20bd9 126
4a71ed0c 127if ($scr_ext) { @scripts = map { "$_$scr_ext" } @scripts; }
17f28c40 128
e8ea6127
AD
129# Specify here any .pm files that are actually architecture-dependent.
130# (Those included with XS extensions under ext/ are automatically
131# added later.)
132# Now that the default privlib has the full perl version number included,
0b3bfb33 133# we no longer have to play the trick of sticking version-specific .pm
e8ea6127 134# files under the archlib directory.
c2cd2081 135my %archpms = (
0b3bfb33
NIS
136 Config => 1,
137 lib => 1,
138 Cwd => 1,
38b8243a 139);
39e571d4
ML
140
141if ($^O eq 'dos') {
142 push(@scripts,'djgpp/fixpmain');
143 $archpms{config} = $archpms{filehand} = 1;
144}
145
2e2b85db
MB
146if ((-e "testcompile") && (defined($ENV{'COMPILE'}))) {
147 push(@scripts, map("$_.exe", @scripts));
6ee623d5
GS
148}
149
08baf503
JH
150# Exclude nonxs extensions that are not architecture dependent
151my @nonxs = grep(!/^Errno$/, split(' ', $Config{'nonxs_ext'}));
152
19c8b195
SH
153my @ext_dirs = qw(cpan dist ext);
154foreach my $ext_dir (@ext_dirs) {
155 find(sub {
156 if (($File::Find::name =~ m{^$ext_dir\b(.*)/([^/]+)\.pm$}) &&
157 ! grep { (my $dir = $_) =~ s/\//-/g;
158 $File::Find::name =~ /^$ext_dir\/$dir\// } @nonxs)
159 {
160 my($path, $modname) = ($1,$2);
161
af1e27ef 162 # Change hyphenated name like Filter-Util-Call to nested
19c8b195
SH
163 # directory name Filter/Util/Call
164 $path =~ s{-}{/}g;
165
166 # strip to optional "/lib", or remove trailing component
167 $path =~ s{.*/lib\b}{} or $path =~ s{/[^/]*$}{};
168
169 # strip any leading /
170 $path =~ s{^/}{};
171
172 # reconstitute canonical module name
173 $modname = "$path/$modname" if length $path;
174
175 # remember it
176 $archpms{$modname} = 1;
177 }
178 }, $ext_dir);
179}
1dd15ed4 180
68c887af
GS
181# print "[$_]\n" for sort keys %archpms;
182
146174a9 183my $ver = $Config{version};
f2766b05 184my $release = substr($],0,3); # Not used currently.
03284eb6 185my $patchlevel = substr($],3,2);
748a9306 186die "Patchlevel of perl ($patchlevel)",
cceca5ed
GS
187 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
188 if $patchlevel != $Config{'PERL_VERSION'};
4633a7c4
LW
189
190# Fetch some frequently-used items from %Config
2227e2d5
NC
191my $installbin = "$opts{destdir}$Config{installbin}";
192my $installscript = "$opts{destdir}$Config{installscript}";
193my $installprivlib = "$opts{destdir}$Config{installprivlib}";
194my $installarchlib = "$opts{destdir}$Config{installarchlib}";
195my $installsitelib = "$opts{destdir}$Config{installsitelib}";
196my $installsitearch = "$opts{destdir}$Config{installsitearch}";
197my $installman1dir = "$opts{destdir}$Config{installman1dir}";
c2cd2081
KS
198my $man1ext = $Config{man1ext};
199my $libperl = $Config{libperl};
4633a7c4 200# Shared library and dynamic loading suffixes.
c2cd2081
KS
201my $so = $Config{so};
202my $dlext = $Config{dlext};
146174a9 203my $dlsrc = $Config{dlsrc};
f2766b05
PP
204if ($^O eq 'os390') {
205 my $pwd;
206 chomp($pwd=`pwd`);
207 my $archlibexp = $Config{archlibexp};
208 my $usedl = $Config{usedl};
209 if ($usedl eq 'define') {
2e2b85db 210 `./$^X -pibak -e 's{$pwd\/libperl.x}{$archlibexp/CORE/libperl.x}' lib/Config.pm`;
f2766b05
PP
211 }
212}
4633a7c4 213
c164bd94 214if ($opts{netware}) {
2e2b85db
MB
215 # This is required only if we are installing on a NetWare server
216 $installscript = $Config{installnwscripts};
217 $installprivlib = $Config{installnwlib};
218 $installarchlib = $Config{installnwlib};
219 $installsitelib = $Config{installnwlib};
2986a63f
JH
220}
221
c2cd2081 222my $binexp = $Config{binexp};
c623bd54 223
17f28c40
CB
224if ($Is_VMS) { # Hang in there until File::Spec hits the big time
225 foreach ( \$installbin, \$installscript, \$installprivlib,
2e2b85db
MB
226 \$installarchlib, \$installsitelib, \$installsitearch,
227 \$installman1dir ) {
228 $$_ = unixify($$_); $$_ =~ s:/$::;
17f28c40
CB
229 }
230}
231
c623bd54
LW
232# Do some quick sanity checks.
233
fe14fcc3 234 $installbin || die "No installbin directory in config.sh\n";
68006eea
NC
235-d $installbin || mkpath($installbin, $opts{verbose}, 0777);
236-d $installbin || $opts{notify} || die "$installbin is not a directory\n";
237-w $installbin || $opts{notify} || die "$installbin is not writable by you\n"
238 unless $installbin =~ m#^/afs/# || $opts{notify};
c623bd54 239
2986a63f 240if (!$Is_NetWare) {
5d25492c 241if (!$Is_VMS) {
39add537 242-x 'perl' . $exe_ext || die "perl isn't executable!\n";
5d25492c
PP
243}
244else {
245-x $ndbg . 'perl' . $exe_ext || die "${ndbg}perl$exe_ext isn't executable!\n";
246 if ($dbg) {
247 -x $dbg . 'perl' . $exe_ext || die "${dbg}perl$exe_ext isn't executable!\n";
248 }
249}
c623bd54 250
9fba8746 251-f 't/rantests' || $Is_W32
2e2b85db
MB
252 || warn "WARNING: You've never run 'make test' or",
253 " some tests failed! (Installing anyway.)\n";
2986a63f 254} #if (!$Is_NetWare)
c623bd54 255
25207203 256# This will be used to store the packlist
9e6fc21f 257$packlist = ExtUtils::Packlist->new("$installarchlib/.packlist");
25207203 258
2e2b85db
MB
259if (($Is_W32 and ! $Is_NetWare) or $Is_Cygwin) {
260 my $perldll;
261
262 if ($Is_Cygwin) {
263 $perldll = $libperl;
2e2b85db 264 } else {
5f9145a3 265 $perldll = 'perl5'.$Config{patchlevel}.'.'.$dlext;
2e2b85db 266 }
5f675712 267
2e2b85db
MB
268 if ($dlsrc ne "dl_none.xs") {
269 -f $perldll || die "No perl DLL built\n";
270 }
0b3bfb33 271
2e2b85db
MB
272 # Install the DLL
273 safe_unlink("$installbin/$perldll");
274 copy("$perldll", "$installbin/$perldll");
275 chmod(0755, "$installbin/$perldll");
b7c0c6b4 276 $packlist->{"$Config{installbin}/$perldll"} = { type => 'file' };
2986a63f 277} # if (($Is_W32 and ! $Is_NetWare) or $Is_Cygwin)
eef1cf2a 278
c623bd54
LW
279# First we install the version-numbered executables.
280
17f28c40 281if ($Is_VMS) {
9edbfc61
PP
282 safe_unlink("$installbin/perl_setup.com");
283 copy("perl_setup.com", "$installbin/perl_setup.com");
284 chmod(0755, "$installbin/perl_setup.com");
5d25492c
PP
285 safe_unlink("$installbin/$dbg$perl$exe_ext");
286 copy("$dbg$perl$exe_ext", "$installbin/$dbg$perl$exe_ext");
287 chmod(0755, "$installbin/$dbg$perl$exe_ext");
288 safe_unlink("$installbin/$dbg${perl}shr$exe_ext");
289 copy("$dbg${perl}shr$exe_ext", "$installbin/$dbg${perl}shr$exe_ext");
290 chmod(0755, "$installbin/$dbg${perl}shr$exe_ext");
291 if ($ndbg) {
9edbfc61
PP
292 safe_unlink("$installbin/$ndbg$perl$exe_ext");
293 copy("$ndbg$perl$exe_ext", "$installbin/$ndbg$perl$exe_ext");
294 chmod(0755, "$installbin/$ndbg$perl$exe_ext");
295 safe_unlink("$installbin/${dbg}a2p$exe_ext");
296 copy("x2p/${dbg}a2p$exe_ext", "$installbin/${dbg}a2p$exe_ext");
297 chmod(0755, "$installbin/${dbg}a2p$exe_ext");
5d25492c 298 }
17f28c40 299}
3f5ee302 300elsif ($^O ne 'dos') {
2e2b85db
MB
301 if (!$Is_NetWare) {
302 safe_unlink("$installbin/$perl_verbase$ver$exe_ext");
303 copy("perl$exe_ext", "$installbin/$perl_verbase$ver$exe_ext");
304 strip("$installbin/$perl_verbase$ver$exe_ext");
305 chmod(0755, "$installbin/$perl_verbase$ver$exe_ext");
306 }
307 else {
308 # If installing onto a NetWare server
c164bd94 309 if ($opts{netware}) {
2e2b85db 310 # Copy perl.nlm, echo.nlm, type.nlm, a2p.nlm & cgi2perl.nlm
efe502bb 311 mkpath($Config{installnwsystem}, $opts{verbose}, 0777);
2e2b85db
MB
312 copy("netware\\".$ENV{'MAKE_TYPE'}."\\perl.nlm", $Config{installnwsystem});
313 copy("netware\\testnlm\\echo\\echo.nlm", $Config{installnwsystem});
314 copy("netware\\testnlm\\type\\type.nlm", $Config{installnwsystem});
315 copy("x2p\\a2p.nlm", $Config{installnwsystem});
316 chmod(0755, "$Config{installnwsystem}\\perl.nlm");
efe502bb 317 mkpath($Config{installnwlcgi}, $opts{verbose}, 0777);
2e2b85db 318 copy("lib\\auto\\cgi2perl\\cgi2perl.nlm", $Config{installnwlcgi});
2986a63f 319 }
2e2b85db 320 } #if (!$Is_NetWare)
3f5ee302 321}
1d84e8df 322else {
6ee623d5
GS
323 safe_unlink("$installbin/$perl.exe");
324 copy("perl.exe", "$installbin/$perl.exe");
39e571d4 325}
c623bd54 326
45d8adaa
LW
327# Install library files.
328
8473bff1
NC
329my $do_installarchlib = !samepath($installarchlib, 'lib');
330my $do_installprivlib = !samepath($installprivlib, 'lib');
5f9145a3 331my $vershort = ($Is_Cygwin and !$Config{usedevel}) ? substr($ver,0,-2) : $ver;
8473bff1 332$do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$vershort/);
0b3bfb33 333
68006eea
NC
334mkpath($installprivlib, $opts{verbose}, 0777);
335mkpath($installarchlib, $opts{verbose}, 0777);
336mkpath($installsitelib, $opts{verbose}, 0777) if ($installsitelib);
337mkpath($installsitearch, $opts{verbose}, 0777) if ($installsitearch);
4633a7c4 338
ce64b292 339if (-d 'lib') {
2c65a6e1 340 find({no_chdir => 1, wanted => \&installlib}, 'lib')
ce64b292 341 if $do_installarchlib || $do_installprivlib;
45d8adaa
LW
342}
343else {
ce64b292 344 warn "Can't install lib files - 'lib/' does not exist";
45d8adaa
LW
345}
346
1aef975c 347# Install header files and libraries.
68006eea 348mkpath("$installarchlib/CORE", $opts{verbose}, 0777);
c2cd2081 349my @corefiles;
17f28c40 350if ($Is_VMS) { # We did core file selection during build
0185066f 351 my $coredir = "lib/$Config{archname}/$ver/CORE";
17f28c40 352 $coredir =~ tr/./_/;
0185066f 353 map { s|^$coredir/||i; } @corefiles = <$coredir/*.*>;
17f28c40 354}
b5920ff0 355elsif ($Is_Cygwin) { # On Cygwin symlink it to CORE to make Makefile happy
2a21c444 356 @corefiles = <*.h libperl*.* perl*$Config{lib_ext}>;
b5920ff0 357 my $coredll = "$installarchlib/CORE/$libperl";
b7c0c6b4 358 my $instcoredll = "$Config{installarchlib}/CORE/$libperl";
2a21c444 359 safe_unlink($coredll);
b5920ff0 360 ( $Config{'d_link'} eq 'define' &&
2a21c444
JH
361 eval {
362 CORE::link("$installbin/$libperl", $coredll);
b7c0c6b4 363 $packlist->{$instcoredll} = { from => "$Config{installbin}/$libperl",
2a21c444
JH
364 type => 'link' };
365 }
366 ) ||
367 eval {
368 symlink("$installbin/$libperl", $coredll);
b7c0c6b4 369 $packlist->{$instcoredll} = { from => "$Config{installbin}/$libperl",
2a21c444
JH
370 type => 'link' };
371 } ||
372 ( copy("$installbin/$libperl", $coredll) &&
b7c0c6b4 373 push(@corefiles, $instcoredll)
2a21c444 374 )
b5920ff0 375} else {
8736538c 376 # [als] hard-coded 'libperl' name... not good!
1933e12c 377 @corefiles = <*.h libperl*.* perl*$Config{lib_ext}>;
8736538c 378
17f28c40
CB
379 # AIX needs perl.exp installed as well.
380 push(@corefiles,'perl.exp') if $^O eq 'aix';
17f28c40 381}
c2cd2081 382foreach my $file (@corefiles) {
aa3cf465 383 # HP-UX (at least) needs to maintain execute permissions
efc5ad56 384 # on dynamically-loadable libraries. So we do it for all.
8f1f23e8 385 if (copy_if_diff($file,"$installarchlib/CORE/$file")) {
f556e5b9 386 if ($file =~ /\.(\Q$so\E|\Q$dlext\E)$/) {
7eb35c03 387 strip("-S", "$installarchlib/CORE/$file") if $^O eq 'darwin';
2e2b85db 388 chmod(0555, "$installarchlib/CORE/$file");
8f1f23e8
W
389 } else {
390 chmod(0444, "$installarchlib/CORE/$file");
391 }
392 }
340f689c 393}
3edbfbe5 394
156620fa
NA
395# Install main perl executables
396# Make links to ordinary names if installbin directory isn't current directory.
397
2986a63f 398if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS && ! $Is_NetWare) {
6ee623d5 399 safe_unlink("$installbin/$perl$exe_ext", "$installbin/suid$perl$exe_ext");
b5afd346 400 if ($^O eq 'vos') {
7e6b8b1f 401 # VOS doesn't support hard links, so use a symlink.
2e2b85db
MB
402 symlink("$installbin/$perl_verbase$ver$exe_ext",
403 "$installbin/$perl$exe_ext");
1d84e8df 404 } else {
beb13193
RS
405 link("$installbin/$perl_verbase$ver$exe_ext",
406 "$installbin/$perl$exe_ext");
1d84e8df 407 }
156620fa
NA
408}
409
f4a342c3
JH
410# For development purposes it can be very useful to have multiple perls
411# build for different "architectures" (eg threading or not) simultaneously.
c164bd94 412if ($opts{archname} && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS) {
f4a342c3
JH
413 my $archperl = "$perl_verbase$ver-$Config{archname}$exe_ext";
414 safe_unlink("$installbin/$archperl");
b5afd346 415 if ($^O eq 'vos') {
eb96f679
PG
416 # VOS doesn't support hard links, so use a symlink.
417 symlink("$installbin/$perl_verbase$ver$exe_ext",
418 "$installbin/$archperl");
f4a342c3 419 } else {
2e2b85db 420 link("$installbin/$perl_verbase$ver$exe_ext", "$installbin/$archperl");
f4a342c3
JH
421 }
422}
423
a0d0e21e
LW
424# Offer to install perl in a "standard" location
425
c2cd2081 426my $mainperl_is_instperl = 0;
a0d0e21e 427
a3ed4895 428if ($Config{installusrbinperl} && $Config{installusrbinperl} eq 'define' &&
68006eea 429 !$versiononly && !$opts{notify} && !$Is_W32 && !$Is_NetWare && !$Is_VMS && -t STDIN && -t STDERR
68dc0745 430 && -w $mainperldir && ! samepath($mainperldir, $installbin)) {
c2cd2081
KS
431 my($usrbinperl) = "$mainperldir/$perl$exe_ext";
432 my($instperl) = "$installbin/$perl$exe_ext";
433 my($expinstperl) = "$binexp/$perl$exe_ext";
55497cff
PP
434
435 # First make sure $usrbinperl is not already the same as the perl we
436 # just installed.
437 if (-x $usrbinperl) {
a0d0e21e
LW
438 # Try to be clever about mainperl being a symbolic link
439 # to binexp/perl if binexp and installbin are different.
440 $mainperl_is_instperl =
68dc0745
PP
441 samepath($usrbinperl, $instperl) ||
442 samepath($usrbinperl, $expinstperl) ||
a0d0e21e 443 (($binexp ne $installbin) &&
55497cff
PP
444 (-l $usrbinperl) &&
445 ((readlink $usrbinperl) eq $expinstperl));
a0d0e21e 446 }
835f8a63 447 if (! $mainperl_is_instperl) {
55497cff 448 unlink($usrbinperl);
1d84e8df
JH
449 ( $Config{'d_link'} eq 'define' &&
450 eval { CORE::link $instperl, $usrbinperl } ) ||
451 eval { symlink $expinstperl, $usrbinperl } ||
452 copy($instperl, $usrbinperl);
453
a0d0e21e
LW
454 $mainperl_is_instperl = 1;
455 }
456}
457
b971f6e4 458# Make links to ordinary names if installbin directory isn't current directory.
9edbfc61 459if (!$Is_NetWare && $dbg eq '') {
bbd0f0ff
RGS
460 if (! samepath($installbin, 'x2p')) {
461 my $base = 'a2p';
462 $base .= $ver if $versiononly;
463 safe_unlink("$installbin/$base$exe_ext");
464 copy("x2p/a2p$exe_ext", "$installbin/$base$exe_ext");
465 strip("$installbin/$base$exe_ext");
466 chmod(0755, "$installbin/$base$exe_ext");
467 }
b971f6e4
PP
468}
469
470# cppstdin is just a script, but it is architecture-dependent, so
471# it can't safely be shared. Place it in $installbin.
472# Note that Configure doesn't build cppstin if it isn't needed, so
473# we skip this if cppstdin doesn't exist.
68dc0745
PP
474if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) {
475 safe_unlink("$installbin/cppstdin");
476 copy("cppstdin", "$installbin/cppstdin");
477 chmod(0755, "$installbin/cppstdin");
b971f6e4
PP
478}
479
1a09d0c8
JH
480sub script_alias {
481 my ($installscript, $orig, $alias, $scr_ext) = @_;
482
eea3e086 483 safe_unlink("$installscript/$alias$scr_ext");
1a09d0c8
JH
484 if ($^O eq 'dos' or $Is_VMS or $^O eq 'transit') {
485 copy("$installscript/$orig$scr_ext",
0b3bfb33 486 "$installscript/$alias$scr_ext");
7e6b8b1f
PG
487 } elsif ($^O eq 'vos') {
488 symlink("$installscript/$orig$scr_ext",
2e2b85db 489 "$installscript/$alias$scr_ext");
1a09d0c8
JH
490 } else {
491 link("$installscript/$orig$scr_ext",
492 "$installscript/$alias$scr_ext");
493 }
494}
495
c8f392da 496# Install scripts.
68006eea 497mkpath($installscript, $opts{verbose}, 0777);
c8f392da
JH
498if ($versiononly) {
499 for (@scripts) {
500 (my $base = $_) =~ s#.*/##;
501 $base .= $ver;
502 copy($_, "$installscript/$base");
503 chmod(0755, "$installscript/$base");
504 }
b971f6e4 505
0b3bfb33 506 for (@tolink) {
2e2b85db
MB
507 my ($from, $to) = map { "$_$ver" } @$_;
508 (my $frbase = $from) =~ s#.*/##;
509 (my $tobase = $to) =~ s#.*/##;
510 script_alias($installscript, $frbase, $tobase, $scr_ext);
c8f392da
JH
511 }
512} else {
22e77942
JH
513 for (@scripts) {
514 (my $base = $_) =~ s#.*/##;
515 copy($_, "$installscript/$base");
516 chmod(0755, "$installscript/$base");
b971f6e4 517 }
22e77942 518
0b3bfb33 519 for (@tolink) {
2e2b85db
MB
520 my ($from, $to) = @$_;
521 (my $frbase = $from) =~ s#.*/##;
522 (my $tobase = $to) =~ s#.*/##;
523 script_alias($installscript, $frbase, $tobase, $scr_ext);
21dae8a0 524 }
b971f6e4
PP
525}
526
146174a9
CB
527# Install pod pages. Where? I guess in $installprivlib/pod
528# ($installprivlib/pods for cygwin).
c164bd94 529if (!$opts{nopods} && (!$versiononly || ($installprivlib =~ m/\Q$vershort/))) {
91e41fa7 530 my $pod = ($Is_Cygwin || $Is_Darwin || $Is_VMS || $Is_W32) ? 'pods' : 'pod';
68006eea 531 mkpath("${installprivlib}/$pod", $opts{verbose}, 0777);
91a06757 532
91e41fa7 533 for (map {$_->[1]} @{get_pod_metadata()->{master}}) {
146174a9 534 # $_ is a name like pod/perl.pod
2e2b85db 535 (my $base = $_) =~ s#.*/##;
146174a9 536 copy_if_diff($_, "${installprivlib}/$pod/${base}");
ed5958d4 537 chmod(0644, "${installprivlib}/$pod/${base}");
b971f6e4 538 }
91a06757 539
b971f6e4
PP
540}
541
a0d0e21e
LW
542# Check to make sure there aren't other perls around in installer's
543# path. This is probably UNIX-specific. Check all absolute directories
544# in the path except for where public executables are supposed to live.
545# Also skip $mainperl if the user opted to have it be a link to the
546# installed perl.
547
c164bd94 548if (!$versiononly && !$opts{'skip-otherperls'}) {
146174a9 549 my ($path, @path);
2986a63f 550 my $dirsep = ($Is_OS2 || $Is_W32 || $Is_NetWare) ? ';' : ':' ;
b971f6e4
PP
551 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
552 @path = split(/$dirsep/, $path);
17f28c40 553 if ($Is_VMS) {
2e2b85db
MB
554 my $i = 0;
555 while (exists $ENV{'DCL$PATH' . $i}) {
556 my $dir = unixpath($ENV{'DCL$PATH' . $i}); $dir =~ s-/$--;
557 push(@path,$dir);
558 }
17f28c40 559 }
c2cd2081 560 my @otherperls;
160a7e37 561 my %otherperls;
b971f6e4
PP
562 for (@path) {
563 next unless m,^/,;
564 # Use &samepath here because some systems have other dirs linked
565 # to $mainperldir (like SunOS)
44591ba5 566 next unless -d;
68dc0745 567 next if samepath($_, $binexp);
ebef0ab4 568 next if samepath($_, cwd());
68dc0745 569 next if ($mainperl_is_instperl && samepath($_, $mainperldir));
2e2b85db 570 my $otherperl = "$_/$perl$exe_ext";
160a7e37
HS
571 next if $otherperls{$otherperl}++;
572 push(@otherperls, $otherperl)
573 if (-x $otherperl && ! -d $otherperl);
b971f6e4
PP
574 }
575 if (@otherperls) {
5f675712 576 warn "\nWarning: $perl appears in your path in the following " .
b971f6e4
PP
577 "locations beyond where\nwe just installed it:\n";
578 for (@otherperls) {
5f675712 579 warn " ", $_, "\n";
b971f6e4 580 }
5f675712 581 warn "\n";
a0d0e21e 582 }
b971f6e4 583
a0d0e21e
LW
584}
585
68006eea
NC
586$packlist->write() unless $opts{notify};
587print " Installation complete\n" if $opts{verbose};
c623bd54
LW
588
589exit 0;
590
591###############################################################################
592
9e6fc21f
NC
593# If these are needed elsewhere, move them into install_lib.pl rather than
594# copying them.
595
a0d0e21e 596sub yn {
c2cd2081
KS
597 my($prompt) = @_;
598 my($answer);
599 my($default) = $prompt =~ m/\[([yn])\]\s*$/i;
802cdca0 600 print STDERR $prompt;
a0d0e21e
LW
601 chop($answer = <STDIN>);
602 $answer = $default if $answer =~ m/^\s*$/;
603 ($answer =~ m/^[yY]/);
604}
605
e50aee73 606sub safe_unlink {
68006eea 607 return if $opts{notify} or $Is_VMS;
c2cd2081
KS
608 my @names = @_;
609 foreach my $name (@names) {
e50aee73 610 next unless -e $name;
2986a63f 611 chmod 0777, $name if ($Is_OS2 || $Is_W32 || $Is_NetWare);
68006eea 612 print " unlink $name\n" if $opts{verbose};
39add537 613 next if CORE::unlink($name);
e50aee73
AD
614 warn "Couldn't unlink $name: $!\n";
615 if ($! =~ /busy/i) {
68006eea 616 print " mv $name $name.old\n" if $opts{verbose};
68dc0745
PP
617 safe_rename($name, "$name.old")
618 or warn "Couldn't rename $name: $!\n";
e50aee73
AD
619 }
620 }
621}
622
68dc0745 623sub safe_rename {
c2cd2081 624 my($from,$to) = @_;
55a105fd 625 if (-f $to and not unlink($to)) {
e50aee73
AD
626 my($i);
627 for ($i = 1; $i < 50; $i++) {
91a06757 628 last if rename($to, "$to.$i");
e50aee73 629 }
19f4563d 630 warn("Cannot rename to '$to.$i': $!"), return 0
39add537 631 if $i >= 50; # Give up!
e50aee73
AD
632 }
633 link($from,$to) || return 0;
55a105fd 634 unlink($from);
e50aee73
AD
635}
636
68dc0745
PP
637sub copy {
638 my($from,$to) = @_;
639
5a9231b0 640 my $xto = $to;
99d21f8b 641 $xto =~ s/^\Q$opts{destdir}\E//;
68006eea
NC
642 print $opts{verbose} ? " cp $from $xto\n" : " $xto\n"
643 unless $opts{silent};
644 print " creating new version of $xto\n"
645 if $Is_VMS and -e $to and !$opts{silent};
646 unless ($opts{notify} or File::Copy::copy($from, $to)) {
6c9f5ae6
IZ
647 # Might have been that F::C::c can't overwrite the target
648 warn "Couldn't copy $from to $to: $!\n"
649 unless -f $to and (chmod(0666, $to), unlink $to)
650 and File::Copy::copy($from, $to);
651 }
5a9231b0 652 $packlist->{$xto} = { type => 'file' };
c623bd54
LW
653}
654
a0d0e21e
LW
655sub installlib {
656 my $dir = $File::Find::dir;
ce64b292 657 $dir =~ s!\Alib/?!!;
a0d0e21e 658
2c65a6e1
NC
659 m!([^/]+)\z!;
660 my $name = $1;
661
662 # This remains ugly, and in need of refactoring.
663
664 # $name always starts as the leafname
665 # $dir is the directory *within* lib
666 # $name later has $dir pre-pended, to give the relative path in lib/
667 # which is used to create the path in the target directory.
668
669 # $_ was always the filename to use on disk. Adding no_chdir doesn't change
670 # this, as $_ becomes a pathname, and so still works. However, it's not
671 # obvious that $_ is needed later, and hence $_ must not be modified.
672
2effe01f 673 # Also, many of the regex exclusion tests below are now superfluous, as the
2c65a6e1
NC
674 # files in question are either no longer in blead, or now in ext/, dist/ or
675 # cpan/ and not copied into lib/
efc5ad56 676
ce28de53 677 # Ignore version control directories.
559940b2 678 if ($name =~ /^(?:CVS|RCS|SCCS|\.svn)\z/ and -d $name) {
efc5ad56
TB
679 $File::Find::prune = 1;
680 return;
681 }
0b3bfb33 682
146174a9 683 # ignore patch backups, RCS files, emacs backup & temp files and the
056a8fbe 684 # .exists files, .PL files, and test files.
4540f59a 685 return if $name =~ m{\.orig$|\.rej$|~$|^#.+#$|,v$|^\.exists|\.PL$|\.plc$|\.t$|^test\.pl$|^dbm_filter_util\.pl$|^filter-util\.pl$|^uupacktool\.pl$|^\.gitignore$} ||
2e2b85db 686 $dir =~ m{/t(?:/|$)};
e4fc8a1e 687 # ignore the cpan script in lib/CPAN/bin, the instmodsh and xsubpp
04f9cde5 688 # scripts in lib/ExtUtils, the prove script in lib/Test/Harness,
ca32a3cb 689 # the corelist script from lib/Module/CoreList/bin and ptar* in
bb4e9162 690 # lib/Archive/Tar/bin, the config_data script in lib/Module/Build/scripts
08ad9465 691 # and zipdetails in cpan/IO-Compress/bin
e4fc8a1e 692 # (they're installed later with other utils)
fb598ba5 693 return if $name =~ /^(?:cpan|instmodsh|prove|corelist|ptar|ptardiff|ptargrep|config_data|zipdetails)\z/;
922ef74c
RGS
694 # ignore the Makefiles
695 return if $name =~ /^makefile$/i;
f9aa124c 696 # ignore the test extensions
f631d084
RGS
697 return if $dir =~ m{\bXS/(?:APItest|Typemap)\b};
698 return if $name =~ m{\b(?:APItest|Typemap)\.pm$};
5e4c4c91
NC
699 # ignore the build support code
700 return if $name =~ /\bbuildcustomize\.pl$/;
a6c3b020 701 # ignore the demo files
021db424 702 return if $dir =~ /\b(?:demos?|eg)\b/;
e4ed29fb
DG
703 # ignore unneeded unicore files
704 if ( $dir =~ /^unicore/ ) {
705 if ( $name =~ /\.txt\z/ ) {
706 # We can ignore most, but not all .txt files
4731737c 707 return unless $name =~ /\A(?:Blocks|SpecialCasing|NamedSequences)\.txt\z/;
e4ed29fb
DG
708 }
709 else {
710 # TestProp only needed during testing
711 return if $name =~ /\ATestProp.pl\z/;
712 # we need version and *.pl files and can skip the rest
971c5244 713 return unless $name =~ /\A(?:version|\w+\.p[lm])\z/;
e4ed29fb
DG
714 }
715 }
b695f709 716
0ae089ad
MS
717 # ignore READMEs, MANIFESTs, INSTALL docs, META.ymls and change logs.
718 # Changes.e2x and README.e2x are needed by enc2xs.
ae5e75fd 719 return if $name =~ m{^(?:README(?:\.\w+)?)$} && $name ne 'README.e2x';
021db424
JH
720 return if $name =~ m{^(?:MANIFEST|META\.yml)$};
721 return if $name =~ m{^(?:INSTALL|TODO|BUGS|CREDITS)$}i;
0ae089ad 722 return if $name =~ m{^change(?:s|log)(?:\.libnet)?$}i;
021db424
JH
723 return if $name =~ m{^(?:SIGNATURE|PAUSE200\d\.pub)$}; # CPAN files
724 return if $name =~ m{^(?:NOTES|PATCHING)$}; # ExtUtils files
0ae089ad 725
54f1e9b4
SH
726 # if using a shared perl library then ignore:
727 # - static library files [of statically linked extensions];
728 # - import library files and export library files (only present on Win32
729 # anyway?) and empty bootstrap files [of dynamically linked extensions].
730 return if $Config{useshrplib} eq 'true' and
731 ($name =~ /$Config{_a}$/ or $name =~ /\.exp$/ or ($name =~ /\.bs$/ and -z $name));
732
a0d0e21e
LW
733 $name = "$dir/$name" if $dir ne '';
734
91e41fa7
NC
735 # ignore pods that are stand alone documentation from dual life modules.
736 return if /\.pod\z/ && is_duplicate_pod($_);
737
e2c1c280
NC
738 return if $name eq 'ExtUtils/XSSymSet.pm' and !$Is_VMS;
739
a0d0e21e 740 my $installlib = $installprivlib;
cad0fd6e 741 if ($dir =~ /^auto\// ||
eef1cf2a 742 ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) ||
b809f04e 743 ($name =~ /^(.*)\.(?:h|lib)$/i && ($Is_W32 || $Is_NetWare)) ||
d62d5a53 744 $name=~/^Config_(heavy|git)\.pl\z/
eef1cf2a 745 ) {
2e2b85db 746 $installlib = $installarchlib;
a0d0e21e
LW
747 return unless $do_installarchlib;
748 } else {
749 return unless $do_installprivlib;
750 }
751
c164bd94 752 if ($Is_NetWare && !$opts{netware} && /\.(?:nlp|nlm|bs)$/) {
efe502bb
NC
753 # Don't copy .nlp,.nlm files, doesn't make sense on Windows and also
754 # if copied will give problems when building new extensions.
755 # Has to be copied if we are installing on a NetWare server and
c164bd94 756 # hence the check !$opts{netware}
efe502bb
NC
757 return;
758 }
759
a0d0e21e 760 if (-f $_) {
5a9231b0 761 my $xname = "$installlib/$name";
99d21f8b 762 $xname =~ s/^\Q$opts{destdir}\E//;
5a9231b0 763 $packlist->{$xname} = { type => 'file' };
c164bd94 764 if ($opts{force} || compare($_, "$installlib/$name") || $opts{notify}) {
55a105fd 765 unlink("$installlib/$name");
68006eea 766 mkpath("$installlib/$dir", $opts{verbose}, 0777);
75f92628
AD
767 # HP-UX (at least) needs to maintain execute permissions
768 # on dynamically-loaded libraries.
efe502bb 769 if (copy_if_diff($_, "$installlib/$name")) {
3a548b36 770 strip("-S", "$installlib/$name")
7eb35c03 771 if $^O eq 'darwin' and /\.(?:so|$dlext|a)$/;
3a548b36 772 chmod(/\.(so|$dlext)$/ ? 0555 : 0444, "$installlib/$name");
efe502bb 773 }
a0d0e21e 774 }
a0d0e21e
LW
775 }
776}
3edbfbe5 777
16d20bd9
AD
778# Copy $from to $to, only if $from is different than $to.
779# Also preserve modification times for .a libraries.
780# On some systems, if you do
781# ranlib libperl.a
782# cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
783# and then try to link against the installed libperl.a, you might
784# get an error message to the effect that the symbol table is older
785# than the library.
aa3cf465 786# Return true if copying occurred.
68dc0745
PP
787
788sub copy_if_diff {
3edbfbe5 789 my($from,$to)=@_;
8530e788 790 return 1 if (($^O eq 'VMS') && (-d $from));
5a9231b0 791 my $xto = $to;
99d21f8b 792 $xto =~ s/^\Q$opts{destdir}\E//;
5f239f73
JH
793 my $perlpodbadsymlink;
794 if ($from =~ m!^pod/perl[\w-]+\.pod$! &&
795 -l $from &&
796 ! -e $from) {
797 # Some Linux implementations have problems traversing over
798 # multiple symlinks (when going over NFS?) and fail to read
799 # the symlink target. Combine this with the fact that some
800 # of the pod files (the perl$OS.pod) are symlinks (to ../README.$OS),
801 # and you end up with those pods not getting installed.
802 $perlpodbadsymlink = 1;
803 }
804 -f $from || $perlpodbadsymlink || warn "$0: $from not found";
5a9231b0 805 $packlist->{$xto} = { type => 'file' };
c164bd94 806 if ($opts{force} || compare($from, $to) || $opts{notify}) {
68dc0745 807 safe_unlink($to); # In case we don't have write permissions.
5f239f73
JH
808 if ($perlpodbadsymlink && $from =~ m!^pod/perl(.+)\.pod$!) {
809 $from = "README.$1";
810 }
68dc0745
PP
811 copy($from, $to);
812 # Restore timestamps if it's a .a library or for OS/2.
68006eea 813 if (!$opts{notify} && ($Is_OS2 || $to =~ /\.a$/)) {
68dc0745 814 my ($atime, $mtime) = (stat $from)[8,9];
16d20bd9
AD
815 utime $atime, $mtime, $to;
816 }
aa3cf465 817 1;
3edbfbe5
TB
818 }
819}
8f1f23e8
W
820
821sub strip
822{
823 my(@args) = @_;
824
4609f84f 825 return unless $opts{strip};
f556e5b9 826
8f1f23e8
W
827 my @opts;
828 while (@args && $args[0] =~ /^(-\w+)$/) {
2e2b85db 829 push @opts, shift @args;
8f1f23e8
W
830 }
831
832 foreach my $file (@args) {
2e2b85db 833 if (-f $file) {
68006eea 834 if ($opts{verbose}) {
2e2b85db
MB
835 print " strip " . join(' ', @opts);
836 print " " if (@opts);
837 print "$file\n";
838 }
839 system("strip", @opts, $file);
840 } else {
68006eea 841 print "# file '$file' skipped\n" if $opts{verbose};
2e2b85db 842 }
8f1f23e8
W
843 }
844}
8473bff1
NC
845
846# Local variables:
847# cperl-indent-level: 4
848# indent-tabs-mode: nil
849# End:
850#
851# ex: set ts=8 sts=4 sw=4 et: