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