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