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