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