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