comparison perl-5.22.2/installperl @ 8045:a16537d2fe07

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