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; | |
354f3b56 | 12 | use File::Copy; |
356fc125 | 13 | use File::Path qw(mkpath); |
354f3b56 | 14 | use ExtUtils::Packlist; |
a2743834 | 15 | use Pod::Man; |
9e6fc21f NC |
16 | use vars qw($Is_VMS $Is_W32 $Is_OS2 $Is_Cygwin $Is_Darwin $Is_NetWare |
17 | %opts $packlist); | |
791b4ad3 | 18 | |
cd8bccb5 | 19 | $ENV{SHELL} = 'sh' if $^O eq 'os2'; |
16d20bd9 | 20 | |
f0512cd0 | 21 | my $patchlevel = substr($],3,2); |
16d20bd9 | 22 | die "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 | 26 | my $usage = |
16d20bd9 | 27 | "Usage: installman --man1dir=/usr/wherever --man1ext=1 |
b5f05010 | 28 | --man3dir=/usr/wherever --man3ext=3 |
f1745d4f | 29 | --batchlimit=40 |
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, |
f1745d4f | 41 | qw( man1dir=s man1ext=s man3dir=s man3ext=s batchlimit=i |
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 | |
ae5391ad | 71 | ); |
21dae8a0 | 72 | |
16d20bd9 | 73 | # Install the main pod pages. |
a2743834 | 74 | pod2man('pod', $opts{man1dir}, $opts{man1ext}); |
16d20bd9 AD |
75 | |
76 | # Install the pods for library modules. | |
a2743834 | 77 | pod2man('lib', $opts{man3dir}, $opts{man3ext}); |
16d20bd9 | 78 | |
1fef88e7 | 79 | # Install the pods embedded in the installed scripts |
bf1ee2ba | 80 | my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir}; |
21dae8a0 SC |
81 | open UTILS, "utils.lst" or die "Can't open 'utils.lst': $!"; |
82 | while (<UTILS>) { | |
83 | next if /^#/; | |
84 | chomp; | |
85 | $_ = $1 if /#.*pod\s*=\s*(\S+)/; | |
53fb3a93 | 86 | my ($where, $what) = m|^(\S*)/(\S+)|; |
a2743834 | 87 | pod2man($where, $opts{man1dir}, $opts{man1ext}, $what); |
bf1ee2ba JH |
88 | if ($has_man1dir) { |
89 | if (my ($where2, $what2) = m|#.*link\s*=\s*(\S+)/(\S+)|) { | |
90 | my $old = "$opts{man1dir}/$what.$opts{man1ext}"; | |
91 | my $new = "$opts{man1dir}/$what2.$opts{man1ext}"; | |
92 | unlink($new); | |
93 | link($old, $new); | |
25207203 JH |
94 | my $xold = $old; |
95 | $xold =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'}; | |
96 | my $xnew = $new; | |
97 | $xnew =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'}; | |
98 | $packlist->{$xnew} = { from => $xold, type => 'link' }; | |
bf1ee2ba | 99 | } |
21dae8a0 SC |
100 | } |
101 | } | |
1fef88e7 | 102 | |
a2743834 | 103 | sub pod2man { |
ae5391ad | 104 | # @script is scripts names if we are installing manpages embedded |
f1745d4f JH |
105 | # in scripts, () otherwise |
106 | my($poddir, $mandir, $manext, @script) = @_; | |
16d20bd9 | 107 | if ($mandir eq ' ' or $mandir eq '') { |
f1745d4f JH |
108 | if (@script) { |
109 | warn "Skipping installation of $poddir/$_ man page.\n" | |
110 | foreach @script; | |
111 | } else { | |
112 | warn "Skipping installation of $poddir man pages.\n"; | |
113 | } | |
16d20bd9 AD |
114 | return; |
115 | } | |
116 | ||
b48e406f | 117 | print "installing from $poddir\n" if $opts{verbose}; |
16d20bd9 | 118 | |
418918ac | 119 | mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify}; # In File::Path |
b48e406f NC |
120 | # Make a list of all the .pm and .pod files in the directory. We avoid |
121 | # chdir because we are running with @INC = '../lib', and modules may wish | |
122 | # to dynamically require Carp::Heavy or other diagnostics warnings. | |
123 | # Hash the names of files we find, keys are names relative to perl build | |
124 | # dir ('.'), values are names relative to $poddir. | |
125 | my %modpods; | |
f1745d4f | 126 | if (@script) { |
b48e406f | 127 | %modpods = (map {+"$poddir/$_", $_} @script); |
72b3d9b4 GS |
128 | } |
129 | else { | |
b48e406f NC |
130 | File::Find::find({no_chdir=>1, |
131 | wanted => sub { | |
132 | # $_ is $File::Find::name when using no_chdir | |
133 | if (-f $_ and /\.p(?:m|od)$/) { | |
134 | my $fullname = $_; | |
135 | s!^\Q$poddir\E/!!; | |
136 | $modpods{$fullname} = $_; | |
137 | } | |
138 | }}, | |
139 | $poddir); | |
1fef88e7 | 140 | } |
f1745d4f | 141 | my @to_process; |
b48e406f NC |
142 | foreach my $mod (sort keys %modpods) { |
143 | my $manpage = $modpods{$mod}; | |
cd8bccb5 | 144 | my $tmp; |
145 | # Skip .pm files that have corresponding .pod files, and Functions.pm. | |
146 | next if (($tmp = $mod) =~ s/\.pm$/.pod/ && -f $tmp); | |
ae5391ad FR |
147 | next if $mod =~ m:/t/:; # no pods from test directories |
148 | next if $do_not_install{$manpage}; | |
cd8bccb5 | 149 | |
63fae907 AT |
150 | # Skip files without pod docs |
151 | my $has_pod; | |
152 | if (open T, $mod) | |
153 | { | |
154 | local $_; | |
155 | while (<T>) | |
156 | { | |
157 | ++$has_pod and last if /^=(?:head\d+|item|pod)\b/; | |
158 | } | |
159 | ||
160 | close T; | |
161 | } | |
162 | ||
163 | unless ($has_pod) | |
164 | { | |
165 | warn "no documentation in $mod\n"; | |
166 | next; | |
167 | } | |
168 | ||
16d20bd9 AD |
169 | # Convert name from File/Basename.pm to File::Basename.3 format, |
170 | # if necessary. | |
171 | $manpage =~ s#\.p(m|od)$##; | |
4fabb596 | 172 | if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') { |
cd8bccb5 | 173 | $manpage =~ s#/#.#g; |
72b3d9b4 GS |
174 | } |
175 | else { | |
cd8bccb5 | 176 | $manpage =~ s#/#::#g; |
177 | } | |
178 | $tmp = "${mandir}/${manpage}.tmp"; | |
16d20bd9 | 179 | $manpage = "${mandir}/${manpage}.${manext}"; |
f1745d4f JH |
180 | push @to_process, [$mod, $tmp, $manpage]; |
181 | } | |
a2743834 | 182 | |
a2743834 MS |
183 | foreach my $page (@to_process) { |
184 | my($pod, $tmp, $manpage) = @$page; | |
185 | ||
571afc3f SP |
186 | my $parser = Pod::Man->new( section => $manext, |
187 | official=> 1, | |
188 | center => 'Perl Programmers Reference Guide' | |
189 | ); | |
5a9231b0 MS |
190 | my $xmanpage = $manpage; |
191 | $xmanpage =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'}; | |
192 | print " $xmanpage\n"; | |
a2743834 MS |
193 | if (!$opts{notify} && $parser->parse_from_file($pod, $tmp)) { |
194 | if (-s $tmp) { | |
195 | if (rename($tmp, $manpage)) { | |
5a9231b0 | 196 | $packlist->{$xmanpage} = { type => 'file' }; |
a2743834 MS |
197 | next; |
198 | } | |
199 | } | |
200 | unlink($tmp); | |
6d64b06f | 201 | } |
16d20bd9 | 202 | } |
16d20bd9 AD |
203 | } |
204 | ||
f0512cd0 DC |
205 | $packlist->write() unless $opts{notify}; |
206 | print " Installation complete\n" if $opts{verbose}; | |
16d20bd9 AD |
207 | |
208 | exit 0; | |
16d20bd9 | 209 | |
cd8bccb5 | 210 | sub rename { |
f0512cd0 | 211 | my($from,$to) = @_; |
55a105fd | 212 | if (-f $to and not unlink($to)) { |
72b3d9b4 GS |
213 | my($i); |
214 | for ($i = 1; $i < 50; $i++) { | |
215 | last if CORE::rename($to, "$to.$i"); | |
216 | } | |
ae5391ad | 217 | warn("Cannot rename to `$to.$i': $!"), return 0 |
72b3d9b4 | 218 | if $i >= 50; # Give up! |
cd8bccb5 | 219 | } |
55a105fd NC |
220 | link($from,$to) || return 0; |
221 | unlink($from); | |
16d20bd9 | 222 | } |