Commit | Line | Data |
---|---|---|
f0512cd0 | 1 | #!./perl -w |
be61d08e | 2 | BEGIN { |
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 | 8 | use strict; |
be61d08e | 9 | |
16d20bd9 AD |
10 | use Getopt::Long; |
11 | use File::Find; | |
356fc125 | 12 | use File::Path qw(mkpath); |
354f3b56 | 13 | use ExtUtils::Packlist; |
a2743834 | 14 | use Pod::Man; |
d0265671 | 15 | use vars qw(%opts $packlist); |
791b4ad3 | 16 | |
d6a39ee2 NC |
17 | require './Porting/pod_lib.pl'; |
18 | my $state = get_pod_metadata(); | |
19 | ||
cd8bccb5 | 20 | $ENV{SHELL} = 'sh' if $^O eq 'os2'; |
16d20bd9 | 21 | |
f0512cd0 | 22 | my $patchlevel = substr($],3,2); |
16d20bd9 | 23 | die "Patchlevel of perl ($patchlevel)", |
cceca5ed GS |
24 | "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n" |
25 | if $patchlevel != $Config{'PERL_VERSION'}; | |
16d20bd9 | 26 | |
f0512cd0 | 27 | my $usage = |
16d20bd9 | 28 | "Usage: installman --man1dir=/usr/wherever --man1ext=1 |
b5f05010 | 29 | --man3dir=/usr/wherever --man3ext=3 |
eabd589f | 30 | --notify --verbose --silent --help |
16d20bd9 AD |
31 | Defaults are: |
32 | man1dir = $Config{'installman1dir'}; | |
33 | man1ext = $Config{'man1ext'}; | |
34 | man3dir = $Config{'installman3dir'}; | |
35 | man3ext = $Config{'man3ext'}; | |
eabd589f A |
36 | --notify (or -n) just lists commands that would be executed. |
37 | --verbose (or -V) report all progress. | |
38 | --silent (or -S) be silent. Only report errors.\n"; | |
16d20bd9 | 39 | |
f0512cd0 | 40 | GetOptions( \%opts, |
d0265671 | 41 | qw( man1dir=s man1ext=s man3dir=s man3ext=s |
ae5391ad | 42 | destdir:s notify n help silent S verbose V)) |
16d20bd9 | 43 | || die $usage; |
f0512cd0 | 44 | die $usage if $opts{help}; |
02bc0c09 | 45 | $opts{destdir} //= ''; |
16d20bd9 | 46 | |
3cc5758c NC |
47 | foreach my $pre (qw(man1 man3)) { |
48 | $opts{"${pre}dir"} //= $opts{destdir} . $Config{"install${pre}dir"}; | |
49 | $opts{"${pre}ext"} //= $Config{"${pre}ext"}; | |
50 | } | |
f0512cd0 | 51 | $opts{silent} ||= $opts{S}; |
f0512cd0 | 52 | $opts{notify} ||= $opts{n}; |
4ad019ef | 53 | $opts{verbose} ||= $opts{V} || $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 | |
ae5391ad FR |
67 | # manpages not to be installed |
68 | my %do_not_install = map { ($_ => 1) } qw( | |
69 | Pod/Functions.pm | |
70 | XS/APItest.pm | |
cf34e658 | 71 | XS/Typemap.pm |
ae5391ad | 72 | ); |
21dae8a0 | 73 | |
16d20bd9 | 74 | # Install the main pod pages. |
d6a39ee2 NC |
75 | pod2man({ |
76 | map { | |
2ce3647c | 77 | ($_->[0], $_->[1]) |
d6a39ee2 NC |
78 | } @{$state->{master}} |
79 | }, $opts{man1dir}, $opts{man1ext}); | |
16d20bd9 AD |
80 | |
81 | # Install the pods for library modules. | |
a2743834 | 82 | pod2man('lib', $opts{man3dir}, $opts{man3ext}); |
16d20bd9 | 83 | |
1fef88e7 | 84 | # Install the pods embedded in the installed scripts |
bf1ee2ba | 85 | my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir}; |
21dae8a0 SC |
86 | open UTILS, "utils.lst" or die "Can't open 'utils.lst': $!"; |
87 | while (<UTILS>) { | |
88 | next if /^#/; | |
89 | chomp; | |
90 | $_ = $1 if /#.*pod\s*=\s*(\S+)/; | |
b3e335c2 NC |
91 | my ($path, $leaf) = m|^(\S*/(\S+))|; |
92 | pod2man({$leaf, $path}, $opts{man1dir}, $opts{man1ext}); | |
bf1ee2ba | 93 | if ($has_man1dir) { |
b3e335c2 NC |
94 | if (my ($link) = m|#.*link\s*=\s*\S+/(\S+)|) { |
95 | my $old = "$opts{man1dir}/$leaf.$opts{man1ext}"; | |
96 | my $new = "$opts{man1dir}/$link.$opts{man1ext}"; | |
bf1ee2ba JH |
97 | unlink($new); |
98 | link($old, $new); | |
25207203 | 99 | my $xold = $old; |
100 | $xold =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'}; | |
101 | my $xnew = $new; | |
102 | $xnew =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'}; | |
103 | $packlist->{$xnew} = { from => $xold, type => 'link' }; | |
bf1ee2ba | 104 | } |
21dae8a0 SC |
105 | } |
106 | } | |
1fef88e7 | 107 | |
a2743834 | 108 | sub pod2man { |
b3e335c2 | 109 | my($what, $mandir, $manext) = @_; |
16d20bd9 | 110 | if ($mandir eq ' ' or $mandir eq '') { |
b3e335c2 NC |
111 | if (ref $what) { |
112 | warn "Skipping installation of $_ man page.\n" | |
113 | foreach values %$what; | |
f1745d4f | 114 | } else { |
b3e335c2 | 115 | warn "Skipping installation of $what man pages.\n" |
f1745d4f | 116 | } |
16d20bd9 AD |
117 | return; |
118 | } | |
119 | ||
b3e335c2 NC |
120 | if ($opts{verbose}) { |
121 | if (ref $what) { | |
122 | print "installing $_\n" | |
123 | foreach sort keys %$what; | |
124 | } else { | |
125 | print "installing from $what\n"; | |
126 | } | |
127 | } | |
16d20bd9 | 128 | |
418918ac | 129 | mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify}; # In File::Path |
b3e335c2 NC |
130 | |
131 | my $modpods; | |
132 | if (ref $what) { | |
133 | $modpods = $what; | |
72b3d9b4 GS |
134 | } |
135 | else { | |
b3e335c2 | 136 | # Make a list of all the .pm and .pod files in the directory. |
b48e406f NC |
137 | File::Find::find({no_chdir=>1, |
138 | wanted => sub { | |
139 | # $_ is $File::Find::name when using no_chdir | |
140 | if (-f $_ and /\.p(?:m|od)$/) { | |
d0265671 NC |
141 | my $pod = $_; |
142 | # Skip .pm files that have corresponding .pod files | |
143 | return if $pod =~ s/\.pm$/.pod/ && -f $pod; | |
144 | return if m!(?:^|/)t/!; | |
b3e335c2 | 145 | s!^\Q$what\E/!!; |
d0265671 | 146 | return if $do_not_install{$_}; |
d6a39ee2 | 147 | return if is_duplicate_pod($File::Find::name); |
d0265671 | 148 | $modpods->{$_} = $File::Find::name; |
b48e406f NC |
149 | } |
150 | }}, | |
b3e335c2 | 151 | $what); |
1fef88e7 | 152 | } |
d0265671 | 153 | |
b3e335c2 NC |
154 | foreach my $manpage (sort keys %$modpods) { |
155 | my $mod = $modpods->{$manpage}; | |
cd8bccb5 | 156 | |
63fae907 AT |
157 | # Skip files without pod docs |
158 | my $has_pod; | |
159 | if (open T, $mod) | |
160 | { | |
161 | local $_; | |
162 | while (<T>) | |
163 | { | |
5a6ebf5f | 164 | ++$has_pod and last if /^=head1\b/; |
63fae907 AT |
165 | } |
166 | ||
167 | close T; | |
168 | } | |
169 | ||
170 | unless ($has_pod) | |
171 | { | |
172 | warn "no documentation in $mod\n"; | |
173 | next; | |
174 | } | |
175 | ||
16d20bd9 AD |
176 | # Convert name from File/Basename.pm to File::Basename.3 format, |
177 | # if necessary. | |
178 | $manpage =~ s#\.p(m|od)$##; | |
4fabb596 | 179 | if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') { |
cd8bccb5 | 180 | $manpage =~ s#/#.#g; |
72b3d9b4 GS |
181 | } |
182 | else { | |
cd8bccb5 PP |
183 | $manpage =~ s#/#::#g; |
184 | } | |
d0265671 | 185 | my $tmp = "${mandir}/${manpage}.tmp"; |
16d20bd9 | 186 | $manpage = "${mandir}/${manpage}.${manext}"; |
a2743834 | 187 | |
571afc3f SP |
188 | my $parser = Pod::Man->new( section => $manext, |
189 | official=> 1, | |
190 | center => 'Perl Programmers Reference Guide' | |
191 | ); | |
5a9231b0 MS |
192 | my $xmanpage = $manpage; |
193 | $xmanpage =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'}; | |
194 | print " $xmanpage\n"; | |
d0265671 | 195 | if (!$opts{notify} && $parser->parse_from_file($mod, $tmp)) { |
a2743834 MS |
196 | if (-s $tmp) { |
197 | if (rename($tmp, $manpage)) { | |
5a9231b0 | 198 | $packlist->{$xmanpage} = { type => 'file' }; |
a2743834 MS |
199 | next; |
200 | } | |
201 | } | |
202 | unlink($tmp); | |
6d64b06f | 203 | } |
16d20bd9 | 204 | } |
16d20bd9 AD |
205 | } |
206 | ||
f0512cd0 DC |
207 | $packlist->write() unless $opts{notify}; |
208 | print " Installation complete\n" if $opts{verbose}; | |
16d20bd9 AD |
209 | |
210 | exit 0; | |
16d20bd9 | 211 | |
cd8bccb5 | 212 | sub rename { |
f0512cd0 | 213 | my($from,$to) = @_; |
55a105fd | 214 | if (-f $to and not unlink($to)) { |
72b3d9b4 GS |
215 | my($i); |
216 | for ($i = 1; $i < 50; $i++) { | |
217 | last if CORE::rename($to, "$to.$i"); | |
218 | } | |
19f4563d | 219 | warn("Cannot rename to '$to.$i': $!"), return 0 |
72b3d9b4 | 220 | if $i >= 50; # Give up! |
cd8bccb5 | 221 | } |
55a105fd | 222 | link($from,$to) || return 0; |
223 | unlink($from); | |
16d20bd9 | 224 | } |
5a6ebf5f NC |
225 | |
226 | # Local variables: | |
227 | # cperl-indent-level: 4 | |
228 | # indent-tabs-mode: nil | |
229 | # End: | |
230 | # | |
231 | # ex: set ts=8 sts=4 sw=4 et: |