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