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