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