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