This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
bisect.pl now accepts repeated -e options, just like perl.
[perl5.git] / installman
CommitLineData
f0512cd0 1#!./perl -w
be61d08e 2BEGIN {
9e6fc21f 3 @INC = qw(lib);
ae5391ad 4
9e6fc21f
NC
5 # This needs to be at BEGIN time, before any use of Config
6 require './install_lib.pl';
be61d08e 7}
9e6fc21f 8use strict;
be61d08e 9
16d20bd9 10use Getopt::Long;
3301e5d1 11require File::Path;
354f3b56 12use ExtUtils::Packlist;
a2743834 13use Pod::Man;
d0265671 14use vars qw(%opts $packlist);
791b4ad3 15
d6a39ee2 16require './Porting/pod_lib.pl';
1cb2462d 17my %man1 = (map {($_->[0], $_->[1])} @{get_pod_metadata()->{master}});
d6a39ee2 18
cd8bccb5 19$ENV{SHELL} = 'sh' if $^O eq 'os2';
16d20bd9 20
f0512cd0 21my $patchlevel = substr($],3,2);
16d20bd9 22die "Patchlevel of perl ($patchlevel)",
cceca5ed
GS
23 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
24 if $patchlevel != $Config{'PERL_VERSION'};
16d20bd9 25
f0512cd0 26my $usage =
16d20bd9 27"Usage: installman --man1dir=/usr/wherever --man1ext=1
b5f05010 28 --man3dir=/usr/wherever --man3ext=3
eabd589f 29 --notify --verbose --silent --help
16d20bd9
AD
30 Defaults are:
31 man1dir = $Config{'installman1dir'};
32 man1ext = $Config{'man1ext'};
33 man3dir = $Config{'installman3dir'};
34 man3ext = $Config{'man3ext'};
eabd589f
A
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";
16d20bd9 38
8cef6e50
NC
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.
f0512cd0 42GetOptions( \%opts,
d0265671 43 qw( man1dir=s man1ext=s man3dir=s man3ext=s
8cef6e50 44 destdir:s notify|n help|h|? silent|S verbose|V strip))
16d20bd9 45 || die $usage;
f0512cd0 46die $usage if $opts{help};
02bc0c09 47$opts{destdir} //= '';
16d20bd9 48
3cc5758c
NC
49foreach my $pre (qw(man1 man3)) {
50 $opts{"${pre}dir"} //= $opts{destdir} . $Config{"install${pre}dir"};
51 $opts{"${pre}ext"} //= $Config{"${pre}ext"};
52}
bbb45456 53$opts{verbose} ||= $opts{notify};
16d20bd9
AD
54
55#Sanity checks
56
ae5391ad 57-x "./perl$Config{exe_ext}"
cd8bccb5 58 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
5a9231b0 59-d "$opts{destdir}$Config{'installprivlib'}"
16d20bd9
AD
60 || warn "Perl library directory $Config{'installprivlib'} not found.
61 Have you run make install?. (Installing anyway.)\n";
cd8bccb5 62-x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
16d20bd9
AD
63 " (Installing anyway.)\n";
64
1ef57a5c 65$packlist = ExtUtils::Packlist->new("$opts{destdir}$Config{installarchlib}/.packlist");
354f3b56 66
16d20bd9 67# Install the main pod pages.
1cb2462d 68pod2man(\%man1, $opts{man1dir}, $opts{man1ext}, 'pod');
16d20bd9
AD
69
70# Install the pods for library modules.
45a365ec 71{
9bbb230a
NC
72 my $found = pods_to_install();
73 pod2man($found->{$_}, $opts{man3dir}, $opts{man3ext}, 'lib')
74 foreach qw(MODULE PRAGMA);
45a365ec 75}
16d20bd9 76
1fef88e7 77# Install the pods embedded in the installed scripts
bf1ee2ba 78my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir};
3301e5d1
NC
79my $fh = open_or_die('utils.lst');
80while (<$fh>) {
21dae8a0
SC
81 next if /^#/;
82 chomp;
b3e335c2 83 my ($path, $leaf) = m|^(\S*/(\S+))|;
e1aae8e4 84 # Have we already installed the manpage for this? (eg perldoc, a2p)
1cb2462d 85 next if $man1{$leaf};
b3e335c2 86 pod2man({$leaf, $path}, $opts{man1dir}, $opts{man1ext});
bf1ee2ba 87 if ($has_man1dir) {
b3e335c2
NC
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}";
bf1ee2ba
JH
91 unlink($new);
92 link($old, $new);
3301e5d1
NC
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' };
bf1ee2ba 96 }
21dae8a0
SC
97 }
98}
3301e5d1 99close $fh or my_die("close 'utils.lst': $!");
1fef88e7 100
a2743834 101sub pod2man {
45a365ec 102 my($modpods, $mandir, $manext, $where) = @_;
16d20bd9 103 if ($mandir eq ' ' or $mandir eq '') {
45a365ec
NC
104 if ($where) {
105 warn "Skipping installation of $where man pages.\n"
106 } else {
b3e335c2 107 warn "Skipping installation of $_ man page.\n"
45a365ec
NC
108 foreach values %$modpods;
109 }
110 return;
16d20bd9
AD
111 }
112
b3e335c2 113 if ($opts{verbose}) {
45a365ec
NC
114 if ($where) {
115 print "installing from $where\n";
b3e335c2 116 } else {
45a365ec
NC
117 print "installing $_\n"
118 foreach sort keys %$modpods;
b3e335c2
NC
119 }
120 }
16d20bd9 121
3301e5d1 122 File::Path::mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify};
b3e335c2 123
b3e335c2
NC
124 foreach my $manpage (sort keys %$modpods) {
125 my $mod = $modpods->{$manpage};
cd8bccb5 126
63fae907
AT
127 # Skip files without pod docs
128 my $has_pod;
3301e5d1
NC
129 my $fh = open_or_die($mod);
130 while (my $line = <$fh>) {
131 if ($line =~ /^=head1\b/) {
132 ++$has_pod;
133 last;
134 }
135 }
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.
63fae907
AT
140
141 unless ($has_pod)
142 {
0f876784 143 warn "no documentation in $mod\n" unless $opts{silent};
63fae907
AT
144 next;
145 }
146
4fabb596 147 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
107ea3f3 148 $manpage =~ s#::#.#g;
cd8bccb5 149 }
d0265671 150 my $tmp = "${mandir}/${manpage}.tmp";
16d20bd9 151 $manpage = "${mandir}/${manpage}.${manext}";
a2743834 152
571afc3f
SP
153 my $parser = Pod::Man->new( section => $manext,
154 official=> 1,
155 center => 'Perl Programmers Reference Guide'
156 );
5a9231b0
MS
157 my $xmanpage = $manpage;
158 $xmanpage =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
0f876784 159 print " $xmanpage\n" unless $opts{silent};
d0265671 160 if (!$opts{notify} && $parser->parse_from_file($mod, $tmp)) {
a2743834
MS
161 if (-s $tmp) {
162 if (rename($tmp, $manpage)) {
5a9231b0 163 $packlist->{$xmanpage} = { type => 'file' };
a2743834
MS
164 next;
165 }
166 }
167 unlink($tmp);
6d64b06f 168 }
16d20bd9 169 }
16d20bd9
AD
170}
171
f0512cd0
DC
172$packlist->write() unless $opts{notify};
173print " Installation complete\n" if $opts{verbose};
16d20bd9 174
cd8bccb5 175sub rename {
f0512cd0 176 my($from,$to) = @_;
55a105fd 177 if (-f $to and not unlink($to)) {
72b3d9b4
GS
178 my($i);
179 for ($i = 1; $i < 50; $i++) {
180 last if CORE::rename($to, "$to.$i");
181 }
19f4563d 182 warn("Cannot rename to '$to.$i': $!"), return 0
72b3d9b4 183 if $i >= 50; # Give up!
cd8bccb5 184 }
55a105fd
NC
185 link($from,$to) || return 0;
186 unlink($from);
16d20bd9 187}
5a6ebf5f
NC
188
189# Local variables:
190# cperl-indent-level: 4
191# indent-tabs-mode: nil
192# End:
193#
194# ex: set ts=8 sts=4 sw=4 et: