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