6 # This needs to be at BEGIN time, before any use of Config
7 # install_lib itself loads and imports Config into main::
8 require './install_lib.pl';
14 use ExtUtils::Packlist;
16 use vars qw(%opts $packlist);
18 require './Porting/pod_lib.pl';
19 my %man1 = (map {($_->[0], $_->[1])} @{get_pod_metadata()->{master}});
21 $ENV{SHELL} = 'sh' if $^O eq 'os2';
23 my $patchlevel = substr($],3,2);
24 die "Patchlevel of perl ($patchlevel)",
25 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
26 if $patchlevel != $Config{'PERL_VERSION'};
29 "Usage: installman --man1dir=/usr/wherever --man1ext=1
30 --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";
41 # --strip intentionally does nothing. By permitting installman to accept it
42 # without error, the Makefile can pass the same options to installperl and
43 # installman, which permits more simplification there than this comment costs.
45 qw( man1dir=s man1ext=s man3dir=s man3ext=s
46 destdir:s notify|n help|h|? silent|S verbose|V strip))
48 die $usage if $opts{help};
49 $opts{destdir} //= '';
51 foreach my $pre (qw(man1 man3)) {
52 $opts{"${pre}dir"} //= $opts{destdir} . $Config{"install${pre}dir"};
53 $opts{"${pre}ext"} //= $Config{"${pre}ext"};
55 $opts{verbose} ||= $opts{notify};
59 -x "./perl$Config{exe_ext}"
60 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
61 -d "$opts{destdir}$Config{'installprivlib'}"
62 || warn "Perl library directory $Config{'installprivlib'} not found.
63 Have you run make install?. (Installing anyway.)\n";
64 -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
65 " (Installing anyway.)\n";
67 $packlist = ExtUtils::Packlist->new("$opts{destdir}$Config{installarchlib}/.packlist");
69 # Install the main pod pages.
70 pod2man(\%man1, $opts{man1dir}, $opts{man1ext}, 'pod');
72 # Install the pods for library modules.
74 my $found = pods_to_install();
75 pod2man($found->{$_}, $opts{man3dir}, $opts{man3ext}, 'lib')
76 foreach qw(MODULE PRAGMA);
79 # Install the pods embedded in the installed scripts
80 my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir};
81 my $fh = open_or_die('utils.lst');
85 my ($path, $leaf) = m|^(\S*/(\S+))|;
86 # Have we already installed the manpage for this? (eg perldoc)
88 pod2man({$leaf, $path}, $opts{man1dir}, $opts{man1ext});
90 if (my ($link) = m|#.*link\s*=\s*\S+/(\S+)|) {
91 my $old = "$opts{man1dir}/$leaf.$opts{man1ext}";
92 my $new = "$opts{man1dir}/$link.$opts{man1ext}";
95 $old =~ s/^\Q$opts{destdir}\E// if $opts{destdir};
96 $new =~ s/^\Q$opts{destdir}\E// if $opts{destdir};
97 $packlist->{$new} = { from => $old, type => 'link' };
101 close $fh or my_die("close 'utils.lst': $!");
104 my($modpods, $mandir, $manext, $where) = @_;
105 if ($mandir eq ' ' or $mandir eq '') {
107 warn "Skipping installation of $where man pages.\n"
109 warn "Skipping installation of $_ man page.\n"
110 foreach values %$modpods;
115 if ($opts{verbose}) {
117 print "installing from $where\n";
119 print "installing $_\n"
120 foreach sort keys %$modpods;
126 foreach my $manpage (sort keys %$modpods) {
127 my $mod = $modpods->{$manpage};
129 # Skip files without pod docs
131 my $fh = open_or_die($mod);
132 while (my $line = <$fh>) {
133 if ($line =~ /^=head1\b/) {
138 close $fh or my_die("close '$mod': $!");
139 # Sadly it doesn't seem possible to re-use this handle for the call
140 # to parse_from_file() below, as Pod::Man relies on source_filename(),
141 # which Pod::Simple only sets accurately if it opens the file itself.
145 print "no documentation in $mod\n" if $opts{verbose};
149 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
150 $manpage =~ s#::#.#g;
152 my $tmp = "${mandir}/${manpage}.tmp";
153 $manpage = "${mandir}/${manpage}.${manext}";
155 my $parser = Pod::Man->new( section => $manext,
157 center => 'Perl Programmers Reference Guide'
159 my $xmanpage = $manpage;
160 $xmanpage =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
161 print " $xmanpage\n" unless $opts{silent};
162 if (!$opts{notify} && $parser->parse_from_file($mod, $tmp)) {
164 # We've already emitted a progress message for this file, if
165 # needed, so ensure safe_rename() doesn't emit another one.
166 local $opts{silent} = 1;
167 if (safe_rename($tmp, $manpage)) {
168 $packlist->{$xmanpage} = { type => 'file' };
177 $packlist->write() unless $opts{notify};
178 print " Installation complete\n" if $opts{verbose};
180 # ex: set ts=8 sts=4 sw=4 et: