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