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