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