5 # This needs to be at BEGIN time, before any use of Config
6 require './install_lib.pl';
12 use ExtUtils::Packlist;
14 use vars qw(%opts $packlist);
16 require './Porting/pod_lib.pl';
17 my %man1 = (map {($_->[0], $_->[1])} @{get_pod_metadata()->{master}});
19 $ENV{SHELL} = 'sh' if $^O eq 'os2';
21 my $patchlevel = substr($],3,2);
22 die "Patchlevel of perl ($patchlevel)",
23 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
24 if $patchlevel != $Config{'PERL_VERSION'};
27 "Usage: installman --man1dir=/usr/wherever --man1ext=1
28 --man3dir=/usr/wherever --man3ext=3
29 --notify --verbose --silent --help
31 man1dir = $Config{'installman1dir'};
32 man1ext = $Config{'man1ext'};
33 man3dir = $Config{'installman3dir'};
34 man3ext = $Config{'man3ext'};
35 --notify (or -n) just lists commands that would be executed.
36 --verbose (or -V) report all progress.
37 --silent (or -S) be silent. Only report errors.\n";
39 # --strip intentionally does nothing. By permitting installman to accept it
40 # without error, the Makefile can pass the same options to installperl and
41 # installman, which permits more simplification there than this comment costs.
43 qw( man1dir=s man1ext=s man3dir=s man3ext=s
44 destdir:s notify|n help|h|? silent|S verbose|V strip))
46 die $usage if $opts{help};
47 $opts{destdir} //= '';
49 foreach my $pre (qw(man1 man3)) {
50 $opts{"${pre}dir"} //= $opts{destdir} . $Config{"install${pre}dir"};
51 $opts{"${pre}ext"} //= $Config{"${pre}ext"};
53 $opts{verbose} ||= $opts{notify};
57 -x "./perl$Config{exe_ext}"
58 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
59 -d "$opts{destdir}$Config{'installprivlib'}"
60 || warn "Perl library directory $Config{'installprivlib'} not found.
61 Have you run make install?. (Installing anyway.)\n";
62 -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
63 " (Installing anyway.)\n";
65 $packlist = ExtUtils::Packlist->new("$opts{destdir}$Config{installarchlib}/.packlist");
67 # Install the main pod pages.
68 pod2man(\%man1, $opts{man1dir}, $opts{man1ext}, 'pod');
70 # Install the pods for library modules.
72 my $found = pods_to_install();
73 pod2man($found->{$_}, $opts{man3dir}, $opts{man3ext}, 'lib')
74 foreach qw(MODULE PRAGMA);
77 # Install the pods embedded in the installed scripts
78 my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir};
79 my $fh = open_or_die('utils.lst');
83 my ($path, $leaf) = m|^(\S*/(\S+))|;
84 # Have we already installed the manpage for this? (eg perldoc, a2p)
86 pod2man({$leaf, $path}, $opts{man1dir}, $opts{man1ext});
88 if (my ($link) = m|#.*link\s*=\s*\S+/(\S+)|) {
89 my $old = "$opts{man1dir}/$leaf.$opts{man1ext}";
90 my $new = "$opts{man1dir}/$link.$opts{man1ext}";
93 $old =~ s/^\Q$opts{destdir}\E// if $opts{destdir};
94 $new =~ s/^\Q$opts{destdir}\E// if $opts{destdir};
95 $packlist->{$new} = { from => $old, type => 'link' };
99 close $fh or my_die("close 'utils.lst': $!");
102 my($modpods, $mandir, $manext, $where) = @_;
103 if ($mandir eq ' ' or $mandir eq '') {
105 warn "Skipping installation of $where man pages.\n"
107 warn "Skipping installation of $_ man page.\n"
108 foreach values %$modpods;
113 if ($opts{verbose}) {
115 print "installing from $where\n";
117 print "installing $_\n"
118 foreach sort keys %$modpods;
122 File::Path::mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify};
124 foreach my $manpage (sort keys %$modpods) {
125 my $mod = $modpods->{$manpage};
127 # Skip files without pod docs
129 my $fh = open_or_die($mod);
130 while (my $line = <$fh>) {
131 if ($line =~ /^=head1\b/) {
136 close $fh or my_die("close '$mod': $!");
137 # Sadly it doesn't seem possible to re-use this handle for the call
138 # to parse_from_file() below, as Pod::Man relies on source_filename(),
139 # which Pod::Simple only sets accurately if it opens the file itself.
143 warn "no documentation in $mod\n" unless $opts{silent};
147 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
148 $manpage =~ s#::#.#g;
150 my $tmp = "${mandir}/${manpage}.tmp";
151 $manpage = "${mandir}/${manpage}.${manext}";
153 my $parser = Pod::Man->new( section => $manext,
155 center => 'Perl Programmers Reference Guide'
157 my $xmanpage = $manpage;
158 $xmanpage =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
159 print " $xmanpage\n" unless $opts{silent};
160 if (!$opts{notify} && $parser->parse_from_file($mod, $tmp)) {
162 if (rename($tmp, $manpage)) {
163 $packlist->{$xmanpage} = { type => 'file' };
172 $packlist->write() unless $opts{notify};
173 print " Installation complete\n" if $opts{verbose};
177 if (-f $to and not unlink($to)) {
179 for ($i = 1; $i < 50; $i++) {
180 last if CORE::rename($to, "$to.$i");
182 warn("Cannot rename to '$to.$i': $!"), return 0
183 if $i >= 50; # Give up!
185 link($from,$to) || return 0;
190 # cperl-indent-level: 4
191 # indent-tabs-mode: nil
194 # ex: set ts=8 sts=4 sw=4 et: