This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
DB_File 1.72 update from Paul Marquess <paul.marquess@bt.com>
[perl5.git] / installman
CommitLineData
16d20bd9
AD
1#!./perl
2BEGIN { @INC = ('lib') }
3use Config;
4use Getopt::Long;
5use File::Find;
354f3b56 6use File::Copy;
356fc125 7use File::Path qw(mkpath);
354f3b56 8use ExtUtils::Packlist;
cd8bccb5 9use subs qw(unlink chmod rename link);
354f3b56 10use vars qw($packlist);
16d20bd9
AD
11require Cwd;
12
cd8bccb5 13$ENV{SHELL} = 'sh' if $^O eq 'os2';
16d20bd9 14
273cf8d1
GS
15$ver = $Config{version};
16$release = substr($],0,3); # Not used presently.
17$patchlevel = substr($],3,2);
16d20bd9 18die "Patchlevel of perl ($patchlevel)",
cceca5ed
GS
19 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
20 if $patchlevel != $Config{'PERL_VERSION'};
16d20bd9
AD
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
c07a80fd 33GetOptions( qw( man1dir=s man1ext=s man3dir=s man3ext=s notify n help))
16d20bd9 34 || die $usage;
4633a7c4 35die $usage if $opt_help;
16d20bd9
AD
36
37# These are written funny to avoid -w typo warnings.
38$man1dir = defined($opt_man1dir) ? $opt_man1dir : $Config{'installman1dir'};
39$man1ext = defined($opt_man1ext) ? $opt_man1ext : $Config{'man1ext'};
40$man3dir = defined($opt_man3dir) ? $opt_man3dir : $Config{'installman3dir'};
41$man3ext = defined($opt_man3ext) ? $opt_man3ext : $Config{'man3ext'};
42
c07a80fd 43$notify = $opt_notify || $opt_n;
16d20bd9
AD
44
45#Sanity checks
46
cd8bccb5 47-x "./perl$Config{exe_ext}"
48 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
16d20bd9
AD
49-d $Config{'installprivlib'}
50 || warn "Perl library directory $Config{'installprivlib'} not found.
51 Have you run make install?. (Installing anyway.)\n";
cd8bccb5 52-x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
16d20bd9
AD
53 " (Installing anyway.)\n";
54
354f3b56
AB
55$packlist = ExtUtils::Packlist->new("$Config{installarchlib}/.packlist");
56
16d20bd9
AD
57# Install the main pod pages.
58runpod2man('pod', $man1dir, $man1ext);
59
60# Install the pods for library modules.
61runpod2man('lib', $man3dir, $man3ext);
62
1fef88e7
JM
63# Install the pods embedded in the installed scripts
64runpod2man('utils', $man1dir, $man1ext, 'c2ph');
65runpod2man('utils', $man1dir, $man1ext, 'h2ph');
66runpod2man('utils', $man1dir, $man1ext, 'h2xs');
791035f5 67runpod2man('utils', $man1dir, $man1ext, 'perlcc');
1fef88e7 68runpod2man('utils', $man1dir, $man1ext, 'perldoc');
d121ca8c 69runpod2man('utils', $man1dir, $man1ext, 'perlbug');
1fef88e7 70runpod2man('utils', $man1dir, $man1ext, 'pl2pm');
3e3baf6d 71runpod2man('utils', $man1dir, $man1ext, 'splain');
95667ae4 72runpod2man('utils', $man1dir, $man1ext, 'dprofpp');
1fef88e7
JM
73runpod2man('x2p', $man1dir, $man1ext, 's2p');
74runpod2man('x2p', $man1dir, $man1ext, 'a2p.pod');
eeb7fe44 75runpod2man('x2p', $man1dir, $man1ext, 'find2perl');
1fef88e7 76runpod2man('pod', $man1dir, $man1ext, 'pod2man');
3e3baf6d 77runpod2man('pod', $man1dir, $man1ext, 'pod2html');
eeb7fe44 78runpod2man('pod', $man1dir, $man1ext, 'pod2text');
791035f5
GS
79runpod2man('pod', $man1dir, $man1ext, 'pod2usage');
80runpod2man('pod', $man1dir, $man1ext, 'podchecker');
81runpod2man('pod', $man1dir, $man1ext, 'podselect');
1fef88e7
JM
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.
86runpod2man('utils', $man1dir, $man1ext, 'pstruct');
87
88runpod2man('lib/ExtUtils', $man1dir, $man1ext, 'xsubpp');
89
16d20bd9 90sub runpod2man {
1fef88e7
JM
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;
16d20bd9
AD
99 my($builddir) = Cwd::getcwd();
100
101 if ($mandir eq ' ' or $mandir eq '') {
1fef88e7
JM
102 print STDERR "Skipping installation of ",
103 ($script ? "$poddir/$script man page" : "$poddir man pages"), ".\n";
16d20bd9
AD
104 return;
105 }
106
0ecb046b 107 print STDERR "chdir $poddir\n";
1fef88e7 108 chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n";
16d20bd9
AD
109
110 # We insist on using the current version of pod2man in case there
111 # are enhancements or changes from previous installed versions.
e50aee73
AD
112 # The error message doesn't include the '..' because the user
113 # won't be aware that we've chdir to $poddir.
1fef88e7 114 -r "$downdir/pod/pod2man" || die "Executable pod/pod2man not found.\n";
e50aee73
AD
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.)
1fef88e7 121 $pod2man = "$downdir/perl -I $downdir/lib $downdir/pod/pod2man --section=$manext --official";
16d20bd9 122
0ecb046b 123 mkpath($mandir, 1, 0777) unless $notify; # In File::Path
16d20bd9
AD
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.
1fef88e7
JM
127 if ($script) {
128 @modpods = ($script);
72b3d9b4
GS
129 }
130 else {
1fef88e7
JM
131 @modpods = ();
132 find(\&lsmodpods, '.');
133 }
16d20bd9
AD
134 foreach $mod (@modpods) {
135 $manpage = $mod;
cd8bccb5 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
16d20bd9
AD
141 # Convert name from File/Basename.pm to File::Basename.3 format,
142 # if necessary.
143 $manpage =~ s#\.p(m|od)$##;
4fabb596 144 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
cd8bccb5 145 $manpage =~ s#/#.#g;
72b3d9b4
GS
146 }
147 else {
cd8bccb5 148 $manpage =~ s#/#::#g;
149 }
150 $tmp = "${mandir}/${manpage}.tmp";
16d20bd9 151 $manpage = "${mandir}/${manpage}.${manext}";
cd8bccb5 152 if (&cmd("$pod2man $mod > $tmp") == 0 && !$notify && -s $tmp) {
72b3d9b4
GS
153 if (rename($tmp, $manpage)) {
154 $packlist->{$manpage} = { type => 'file' };
155 next;
156 }
6d64b06f 157 }
6d64b06f 158 unless ($notify) {
72b3d9b4 159 unlink($tmp);
6d64b06f 160 }
16d20bd9
AD
161 }
162 chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n";
0ecb046b 163 print STDERR "chdir $builddir\n";
16d20bd9
AD
164}
165
166sub 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
354f3b56 175$packlist->write() unless $notify;
16d20bd9
AD
176print STDERR " Installation complete\n";
177
178exit 0;
179
180
181###############################################################################
182# Utility subroutines from installperl
183
184sub cmd {
185 local($cmd) = @_;
186 print STDERR " $cmd\n";
187 unless ($notify) {
b29d8d13 188 if ($Config{d_fork}) {
189 fork ? wait : exec $cmd; # Allow user to ^C out of command.
190 }
191 else {
192 system $cmd;
193 }
cb1a09d0 194 warn "Command failed!!\n" if $?;
16d20bd9 195 }
cb1a09d0 196 return $? != 0;
16d20bd9
AD
197}
198
cd8bccb5 199sub unlink {
200 local(@names) = @_;
201 my $cnt = 0;
202
203 foreach $name (@names) {
72b3d9b4
GS
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;
cd8bccb5 209 }
210 return $cnt;
211}
212
16d20bd9 213sub link {
354f3b56
AB
214 my($from,$to) = @_;
215 my($success) = 0;
16d20bd9
AD
216
217 print STDERR " ln $from $to\n";
354f3b56
AB
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;
354f3b56
AB
225 };
226 if ($@) {
227 File::Copy::copy($from, $to)
228 ? $success++
229 : warn "Couldn't copy $from to $to: $!\n"
230 unless $notify;
354f3b56
AB
231 }
232 $success;
cd8bccb5 233}
234
235sub rename {
236 local($from,$to) = @_;
237 if (-f $to and not unlink($to)) {
72b3d9b4
GS
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!
cd8bccb5 244 }
245 link($from,$to) || return 0;
246 unlink($from);
16d20bd9
AD
247}
248
249sub chmod {
250 local($mode,$name) = @_;
251
252 printf STDERR " chmod %o %s\n", $mode, $name;
cd8bccb5 253 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
16d20bd9
AD
254 unless $notify;
255}
256
16d20bd9
AD
257sub 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}