Commit | Line | Data |
22d4bb9c |
1 | #!./perl -w |
16d20bd9 |
2 | BEGIN { @INC = ('lib') } |
22d4bb9c |
3 | use strict; |
16d20bd9 |
4 | use Config; |
5 | use Getopt::Long; |
6 | use File::Find; |
354f3b56 |
7 | use File::Copy; |
356fc125 |
8 | use File::Path qw(mkpath); |
354f3b56 |
9 | use ExtUtils::Packlist; |
cd8bccb5 |
10 | use subs qw(unlink chmod rename link); |
22d4bb9c |
11 | use vars qw($packlist @modpods); |
16d20bd9 |
12 | require Cwd; |
13 | |
cd8bccb5 |
14 | $ENV{SHELL} = 'sh' if $^O eq 'os2'; |
16d20bd9 |
15 | |
22d4bb9c |
16 | my $ver = $Config{version}; # Not used presently. |
17 | my $release = substr($],0,3); # Not used presently. |
18 | my $patchlevel = substr($],3,2); |
16d20bd9 |
19 | die "Patchlevel of perl ($patchlevel)", |
cceca5ed |
20 | "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n" |
21 | if $patchlevel != $Config{'PERL_VERSION'}; |
16d20bd9 |
22 | |
22d4bb9c |
23 | my $usage = |
16d20bd9 |
24 | "Usage: installman --man1dir=/usr/wherever --man1ext=1 |
22d4bb9c |
25 | --man3dir=/usr/wherever --man3ext=3 |
0e06870b |
26 | --batchlimit=40 |
22d4bb9c |
27 | --notify --verbose --silent --help |
16d20bd9 |
28 | Defaults are: |
29 | man1dir = $Config{'installman1dir'}; |
30 | man1ext = $Config{'man1ext'}; |
31 | man3dir = $Config{'installman3dir'}; |
32 | man3ext = $Config{'man3ext'}; |
0e06870b |
33 | batchlimit is maximum number of pod files per invocation of pod2man |
22d4bb9c |
34 | --notify (or -n) just lists commands that would be executed. |
35 | --verbose (or -V) report all progress. |
36 | --silent (or -S) be silent. Only report errors.\n"; |
37 | |
38 | my %opts; |
39 | GetOptions( \%opts, |
0e06870b |
40 | qw( man1dir=s man1ext=s man3dir=s man3ext=s batchlimit=i |
22d4bb9c |
41 | notify n help silent S verbose V)) |
16d20bd9 |
42 | || die $usage; |
22d4bb9c |
43 | die $usage if $opts{help}; |
44 | |
45 | $opts{man1dir} = $Config{'installman1dir'} |
46 | unless defined($opts{man1dir}); |
47 | $opts{man1ext} = $Config{'man1ext'} |
48 | unless defined($opts{man1ext}); |
49 | $opts{man3dir} = $Config{'installman3dir'} |
50 | unless defined($opts{man3dir}); |
51 | $opts{man3ext} = $Config{'man3ext'} |
52 | unless defined($opts{man3ext}); |
0e06870b |
53 | $opts{batchlimit} ||= 40; |
22d4bb9c |
54 | $opts{silent} ||= $opts{S}; |
55 | $opts{notify} ||= $opts{n}; |
56 | $opts{verbose} ||= $opts{V} || $opts{notify}; |
16d20bd9 |
57 | |
58 | #Sanity checks |
59 | |
cd8bccb5 |
60 | -x "./perl$Config{exe_ext}" |
61 | or warn "./perl$Config{exe_ext} not found! Have you run make?\n"; |
16d20bd9 |
62 | -d $Config{'installprivlib'} |
63 | || warn "Perl library directory $Config{'installprivlib'} not found. |
64 | Have you run make install?. (Installing anyway.)\n"; |
cd8bccb5 |
65 | -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!", |
16d20bd9 |
66 | " (Installing anyway.)\n"; |
67 | |
354f3b56 |
68 | $packlist = ExtUtils::Packlist->new("$Config{installarchlib}/.packlist"); |
69 | |
16d20bd9 |
70 | # Install the main pod pages. |
22d4bb9c |
71 | runpod2man('pod', $opts{man1dir}, $opts{man1ext}); |
16d20bd9 |
72 | |
73 | # Install the pods for library modules. |
22d4bb9c |
74 | runpod2man('lib', $opts{man3dir}, $opts{man3ext}); |
16d20bd9 |
75 | |
1fef88e7 |
76 | # Install the pods embedded in the installed scripts |
0e06870b |
77 | runpod2man('utils', $opts{man1dir}, $opts{man1ext}, 'c2ph', 'h2ph', 'h2xs', |
78 | 'perlcc', 'perldoc', 'perlbug', 'pl2pm', 'splain', 'dprofpp'); |
79 | runpod2man('x2p', $opts{man1dir}, $opts{man1ext}, 's2p', 'a2p.pod', |
80 | 'find2perl'); |
81 | runpod2man('pod', $opts{man1dir}, $opts{man1ext}, 'pod2man', 'pod2html', |
82 | 'pod2text', 'pod2usage', 'podchecker', 'podselect'); |
1fef88e7 |
83 | |
84 | # It would probably be better to have this page linked |
85 | # to the c2ph man page. Or, this one could say ".so man1/c2ph.1", |
22d4bb9c |
86 | # but then it would have to pay attention to $opts{man1dir} and $opts{man1ext}. |
87 | runpod2man('utils', $opts{man1dir}, $opts{man1ext}, 'pstruct'); |
1fef88e7 |
88 | |
22d4bb9c |
89 | runpod2man('lib/ExtUtils', $opts{man1dir}, $opts{man1ext}, 'xsubpp'); |
1fef88e7 |
90 | |
16d20bd9 |
91 | sub runpod2man { |
0e06870b |
92 | # @script is scripts names if we are installing manpages embedded |
93 | # in scripts, () otherwise |
94 | my($poddir, $mandir, $manext, @script) = @_; |
1fef88e7 |
95 | |
96 | my($downdir); # can't just use .. when installing xsubpp manpage |
97 | |
98 | $downdir = $poddir; |
99 | $downdir =~ s:[^/]+:..:g; |
16d20bd9 |
100 | my($builddir) = Cwd::getcwd(); |
101 | |
102 | if ($mandir eq ' ' or $mandir eq '') { |
0e06870b |
103 | if (@script) { |
104 | warn "Skipping installation of $poddir/$_ man page.\n" |
105 | foreach @script; |
106 | } else { |
107 | warn "Skipping installation of $poddir man pages.\n"; |
108 | } |
16d20bd9 |
109 | return; |
110 | } |
111 | |
22d4bb9c |
112 | print "chdir $poddir\n" if $opts{verbose}; |
1fef88e7 |
113 | chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n"; |
16d20bd9 |
114 | |
115 | # We insist on using the current version of pod2man in case there |
116 | # are enhancements or changes from previous installed versions. |
e50aee73 |
117 | # The error message doesn't include the '..' because the user |
118 | # won't be aware that we've chdir to $poddir. |
1fef88e7 |
119 | -r "$downdir/pod/pod2man" || die "Executable pod/pod2man not found.\n"; |
e50aee73 |
120 | |
121 | # We want to be sure to use the current perl. We can't rely on |
122 | # the installed perl because it might not be actually installed |
123 | # yet. (The user may have set the $install* Configure variables |
124 | # to point to some temporary home, from which the executable gets |
125 | # installed by occult means.) |
22d4bb9c |
126 | my $pod2man = "$downdir/perl -I $downdir/lib $downdir/pod/pod2man --section=$manext --official"; |
16d20bd9 |
127 | |
22d4bb9c |
128 | mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify}; # In File::Path |
16d20bd9 |
129 | # Make a list of all the .pm and .pod files in the directory. We will |
130 | # always run pod2man from the lib directory and feed it the full pathname |
131 | # of the pod. This might be useful for pod2man someday. |
0e06870b |
132 | if (@script) { |
133 | @modpods = @script; |
146174a9 |
134 | } |
135 | else { |
1fef88e7 |
136 | @modpods = (); |
22d4bb9c |
137 | File::Find::find(\&lsmodpods, '.'); |
1fef88e7 |
138 | } |
0e06870b |
139 | my @to_process; |
22d4bb9c |
140 | foreach my $mod (@modpods) { |
141 | my $manpage = $mod; |
cd8bccb5 |
142 | my $tmp; |
143 | # Skip .pm files that have corresponding .pod files, and Functions.pm. |
144 | next if (($tmp = $mod) =~ s/\.pm$/.pod/ && -f $tmp); |
145 | next if ($mod eq 'Pod/Functions.pm'); #### Used only by pod itself |
146 | |
16d20bd9 |
147 | # Convert name from File/Basename.pm to File::Basename.3 format, |
148 | # if necessary. |
149 | $manpage =~ s#\.p(m|od)$##; |
146174a9 |
150 | if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') { |
cd8bccb5 |
151 | $manpage =~ s#/#.#g; |
146174a9 |
152 | } |
153 | else { |
cd8bccb5 |
154 | $manpage =~ s#/#::#g; |
155 | } |
156 | $tmp = "${mandir}/${manpage}.tmp"; |
16d20bd9 |
157 | $manpage = "${mandir}/${manpage}.${manext}"; |
0e06870b |
158 | push @to_process, [$mod, $tmp, $manpage]; |
159 | } |
160 | # Don't do all pods in same command to avoid busting command line limits |
161 | while (my @this_batch = splice @to_process, 0, $opts{batchlimit}) { |
162 | my $cmd = join " ", $pod2man, map "$$_[0] $$_[1]", @this_batch; |
163 | if (&cmd($cmd) == 0 && !$opts{notify}) { |
164 | foreach (@this_batch) { |
165 | my (undef, $tmp, $manpage) = @$_; |
166 | if (-s $tmp) { |
167 | if (rename($tmp, $manpage)) { |
168 | $packlist->{$manpage} = { type => 'file' }; |
169 | next; |
170 | } |
171 | } |
172 | unless ($opts{notify}) { |
173 | unlink($tmp); |
174 | } |
146174a9 |
175 | } |
6d64b06f |
176 | } |
16d20bd9 |
177 | } |
178 | chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n"; |
22d4bb9c |
179 | print " chdir $builddir\n" if $opts{verbose}; |
16d20bd9 |
180 | } |
181 | |
182 | sub lsmodpods { |
183 | my $dir = $File::Find::dir; |
184 | my $name = $File::Find::name; |
185 | if (-f $_) { |
186 | $name =~ s#^\./##; |
187 | push(@modpods, $name) if ($name =~ /\.p(m|od)$/); |
188 | } |
189 | } |
190 | |
22d4bb9c |
191 | $packlist->write() unless $opts{notify}; |
192 | print " Installation complete\n" if $opts{verbose}; |
16d20bd9 |
193 | |
194 | exit 0; |
195 | |
196 | |
197 | ############################################################################### |
198 | # Utility subroutines from installperl |
199 | |
200 | sub cmd { |
22d4bb9c |
201 | my ($cmd) = @_; |
202 | print " $cmd\n" if $opts{verbose}; |
203 | unless ($opts{notify}) { |
b29d8d13 |
204 | if ($Config{d_fork}) { |
205 | fork ? wait : exec $cmd; # Allow user to ^C out of command. |
206 | } |
207 | else { |
208 | system $cmd; |
209 | } |
cb1a09d0 |
210 | warn "Command failed!!\n" if $?; |
16d20bd9 |
211 | } |
cb1a09d0 |
212 | return $? != 0; |
16d20bd9 |
213 | } |
214 | |
cd8bccb5 |
215 | sub unlink { |
22d4bb9c |
216 | my(@names) = @_; |
cd8bccb5 |
217 | my $cnt = 0; |
218 | |
22d4bb9c |
219 | foreach my $name (@names) { |
146174a9 |
220 | next unless -e $name; |
221 | chmod 0777, $name if $^O eq 'os2'; |
22d4bb9c |
222 | print " unlink $name\n" if $opts{verbose}; |
146174a9 |
223 | ( CORE::unlink($name) and ++$cnt |
22d4bb9c |
224 | or warn "Couldn't unlink $name: $!\n" ) unless $opts{notify}; |
cd8bccb5 |
225 | } |
226 | return $cnt; |
227 | } |
228 | |
16d20bd9 |
229 | sub link { |
354f3b56 |
230 | my($from,$to) = @_; |
231 | my($success) = 0; |
16d20bd9 |
232 | |
22d4bb9c |
233 | print $opts{verbose} ? " ln $from $to\n" : " $to\n" unless $opts{silent}; |
354f3b56 |
234 | eval { |
235 | CORE::link($from, $to) |
236 | ? $success++ |
237 | : ($from =~ m#^/afs/# || $to =~ m#^/afs/#) |
238 | ? die "AFS" # okay inside eval {} |
239 | : warn "Couldn't link $from to $to: $!\n" |
22d4bb9c |
240 | unless $opts{notify}; |
354f3b56 |
241 | }; |
242 | if ($@) { |
243 | File::Copy::copy($from, $to) |
244 | ? $success++ |
245 | : warn "Couldn't copy $from to $to: $!\n" |
22d4bb9c |
246 | unless $opts{notify}; |
354f3b56 |
247 | } |
248 | $success; |
cd8bccb5 |
249 | } |
250 | |
251 | sub rename { |
22d4bb9c |
252 | my($from,$to) = @_; |
cd8bccb5 |
253 | if (-f $to and not unlink($to)) { |
146174a9 |
254 | my($i); |
255 | for ($i = 1; $i < 50; $i++) { |
256 | last if CORE::rename($to, "$to.$i"); |
257 | } |
258 | warn("Cannot rename to `$to.$i': $!"), return 0 |
259 | if $i >= 50; # Give up! |
cd8bccb5 |
260 | } |
261 | link($from,$to) || return 0; |
262 | unlink($from); |
16d20bd9 |
263 | } |
264 | |
265 | sub chmod { |
22d4bb9c |
266 | my($mode,$name) = @_; |
16d20bd9 |
267 | |
22d4bb9c |
268 | printf " chmod %o %s\n", $mode, $name if $opts{verbose}; |
cd8bccb5 |
269 | CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name) |
22d4bb9c |
270 | unless $opts{notify}; |
16d20bd9 |
271 | } |
272 | |
16d20bd9 |
273 | sub samepath { |
22d4bb9c |
274 | my($p1, $p2) = @_; |
275 | my($dev1, $ino1, $dev2, $ino2); |
16d20bd9 |
276 | |
277 | if ($p1 ne $p2) { |
278 | ($dev1, $ino1) = stat($p1); |
279 | ($dev2, $ino2) = stat($p2); |
280 | ($dev1 == $dev2 && $ino1 == $ino2); |
281 | } |
282 | else { |
283 | 1; |
284 | } |
285 | } |