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