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