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