2 BEGIN { @INC = qw(lib) }
8 use File::Path qw(mkpath);
9 use ExtUtils::Packlist;
11 use subs qw(unlink chmod rename link);
12 use vars qw($packlist);
14 if ($Config{d_umask}) {
15 umask(022); # umasks like 077 aren't that useful for installations
18 $ENV{SHELL} = 'sh' if $^O eq 'os2';
20 my $ver = $Config{version}; # Not used presently.
21 my $release = substr($],0,3); # Not used presently.
22 my $patchlevel = substr($],3,2);
23 die "Patchlevel of perl ($patchlevel)",
24 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
25 if $patchlevel != $Config{'PERL_VERSION'};
28 "Usage: installman --man1dir=/usr/wherever --man1ext=1
29 --man3dir=/usr/wherever --man3ext=3
31 --notify --verbose --silent --help
33 man1dir = $Config{'installman1dir'};
34 man1ext = $Config{'man1ext'};
35 man3dir = $Config{'installman3dir'};
36 man3ext = $Config{'man3ext'};
37 --notify (or -n) just lists commands that would be executed.
38 --verbose (or -V) report all progress.
39 --silent (or -S) be silent. Only report errors.\n";
43 qw( man1dir=s man1ext=s man3dir=s man3ext=s batchlimit=i
44 destdir:s notify n help silent S verbose V))
46 die $usage if $opts{help};
47 $opts{destdir} //= '';
49 $opts{man1dir} = "$opts{destdir}$Config{'installman1dir'}"
50 unless defined($opts{man1dir});
51 $opts{man1ext} = $Config{'man1ext'}
52 unless defined($opts{man1ext});
53 $opts{man3dir} = "$opts{destdir}$Config{'installman3dir'}"
54 unless defined($opts{man3dir});
55 $opts{man3ext} = $Config{'man3ext'}
56 unless defined($opts{man3ext});
57 $opts{silent} ||= $opts{S};
58 $opts{notify} ||= $opts{n};
59 $opts{verbose} ||= $opts{V} || $opts{notify};
63 -x "./perl$Config{exe_ext}"
64 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
65 -d "$opts{destdir}$Config{'installprivlib'}"
66 || warn "Perl library directory $Config{'installprivlib'} not found.
67 Have you run make install?. (Installing anyway.)\n";
68 -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
69 " (Installing anyway.)\n";
71 $packlist = ExtUtils::Packlist->new("$opts{destdir}$Config{installarchlib}/.packlist");
74 # Install the main pod pages.
75 pod2man('pod', $opts{man1dir}, $opts{man1ext});
77 # Install the pods for library modules.
78 pod2man('lib', $opts{man3dir}, $opts{man3ext});
80 # Install the pods embedded in the installed scripts
81 my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir};
82 open UTILS, "utils.lst" or die "Can't open 'utils.lst': $!";
86 $_ = $1 if /#.*pod\s*=\s*(\S+)/;
87 my ($where, $what) = m|^(\S*)/(\S+)|;
88 pod2man($where, $opts{man1dir}, $opts{man1ext}, $what);
90 if (my ($where2, $what2) = m|#.*link\s*=\s*(\S+)/(\S+)|) {
91 my $old = "$opts{man1dir}/$what.$opts{man1ext}";
92 my $new = "$opts{man1dir}/$what2.$opts{man1ext}";
96 $xold =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
98 $xnew =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
99 $packlist->{$xnew} = { from => $xold, type => 'link' };
105 # @script is scripts names if we are installing manpages embedded
106 # in scripts, () otherwise
107 my($poddir, $mandir, $manext, @script) = @_;
108 if ($mandir eq ' ' or $mandir eq '') {
110 warn "Skipping installation of $poddir/$_ man page.\n"
113 warn "Skipping installation of $poddir man pages.\n";
118 print "installing from $poddir\n" if $opts{verbose};
120 mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify}; # In File::Path
121 # Make a list of all the .pm and .pod files in the directory. We avoid
122 # chdir because we are running with @INC = '../lib', and modules may wish
123 # to dynamically require Carp::Heavy or other diagnostics warnings.
124 # Hash the names of files we find, keys are names relative to perl build
125 # dir ('.'), values are names relative to $poddir.
128 %modpods = (map {+"$poddir/$_", $_} @script);
131 File::Find::find({no_chdir=>1,
133 # $_ is $File::Find::name when using no_chdir
134 if (-f $_ and /\.p(?:m|od)$/) {
137 $modpods{$fullname} = $_;
143 foreach my $mod (sort keys %modpods) {
144 my $manpage = $modpods{$mod};
146 # Skip .pm files that have corresponding .pod files, and Functions.pm.
147 next if (($tmp = $mod) =~ s/\.pm$/.pod/ && -f $tmp);
148 next if $mod =~ m:/t/:; # no pods from test directories
149 next if ($manpage eq 'Pod/Functions.pm'); #### Used only by pod itself
151 # Skip files without pod docs
158 ++$has_pod and last if /^=(?:head\d+|item|pod)\b/;
166 warn "no documentation in $mod\n";
170 # Convert name from File/Basename.pm to File::Basename.3 format,
172 $manpage =~ s#\.p(m|od)$##;
173 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
177 $manpage =~ s#/#::#g;
179 $tmp = "${mandir}/${manpage}.tmp";
180 $manpage = "${mandir}/${manpage}.${manext}";
181 push @to_process, [$mod, $tmp, $manpage];
184 foreach my $page (@to_process) {
185 my($pod, $tmp, $manpage) = @$page;
187 my $parser = Pod::Man->new( section => $manext,
189 center => 'Perl Programmers Reference Guide'
191 my $xmanpage = $manpage;
192 $xmanpage =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
193 print " $xmanpage\n";
194 if (!$opts{notify} && $parser->parse_from_file($pod, $tmp)) {
196 if (rename($tmp, $manpage)) {
197 $packlist->{$xmanpage} = { type => 'file' };
206 $packlist->write() unless $opts{notify};
207 print " Installation complete\n" if $opts{verbose};
211 ###############################################################################
212 # Utility subroutines from installperl
218 foreach my $name (@names) {
219 next unless -e $name;
220 chmod 0777, $name if $^O eq 'os2';
221 print " unlink $name\n" if $opts{verbose};
222 ( CORE::unlink($name) and ++$cnt
223 or warn "Couldn't unlink $name: $!\n" ) unless $opts{notify};
232 print " ln $from $to\n" if $opts{verbose};
234 CORE::link($from, $to)
236 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
237 ? die "AFS" # okay inside eval {}
238 : warn "Couldn't link $from to $to: $!\n"
239 unless $opts{notify};
242 File::Copy::copy($from, $to)
244 : warn "Couldn't copy $from to $to: $!\n"
245 unless $opts{notify};
252 if (-f $to and not unlink($to)) {
254 for ($i = 1; $i < 50; $i++) {
255 last if CORE::rename($to, "$to.$i");
257 warn("Cannot rename to `$to.$i': $!"), return 0
258 if $i >= 50; # Give up!
260 link($from,$to) || return 0;
265 my($mode,$name) = @_;
267 printf " chmod %o %s\n", $mode, $name if $opts{verbose};
268 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
269 unless $opts{notify};
274 my($dev1, $ino1, $dev2, $ino2);
277 ($dev1, $ino1) = stat($p1);
278 ($dev2, $ino2) = stat($p2);
279 ($dev1 == $dev2 && $ino1 == $ino2);