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