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