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