2 BEGIN { @INC = ('lib') }
8 use File::Path qw(mkpath);
9 use ExtUtils::Packlist;
10 use subs qw(unlink chmod rename link);
11 use vars qw($packlist @modpods);
14 $ENV{SHELL} = 'sh' if $^O eq 'os2';
16 my $ver = $Config{version}; # Not used presently.
17 my $release = substr($],0,3); # Not used presently.
18 my $patchlevel = substr($],3,2);
19 die "Patchlevel of perl ($patchlevel)",
20 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
21 if $patchlevel != $Config{'PERL_VERSION'};
24 "Usage: installman --man1dir=/usr/wherever --man1ext=1
25 --man3dir=/usr/wherever --man3ext=3
27 --notify --verbose --silent --help
29 man1dir = $Config{'installman1dir'};
30 man1ext = $Config{'man1ext'};
31 man3dir = $Config{'installman3dir'};
32 man3ext = $Config{'man3ext'};
33 batchlimit is maximum number of pod files per invocation of pod2man
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";
40 qw( man1dir=s man1ext=s man3dir=s man3ext=s batchlimit=i
41 notify n help silent S verbose V))
43 die $usage if $opts{help};
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});
53 $opts{batchlimit} ||= 40;
54 $opts{silent} ||= $opts{S};
55 $opts{notify} ||= $opts{n};
56 $opts{verbose} ||= $opts{V} || $opts{notify};
60 -x "./perl$Config{exe_ext}"
61 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
62 -d $Config{'installprivlib'}
63 || warn "Perl library directory $Config{'installprivlib'} not found.
64 Have you run make install?. (Installing anyway.)\n";
65 -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
66 " (Installing anyway.)\n";
68 $packlist = ExtUtils::Packlist->new("$Config{installarchlib}/.packlist");
70 # Install the main pod pages.
71 runpod2man('pod', $opts{man1dir}, $opts{man1ext});
73 # Install the pods for library modules.
74 runpod2man('lib', $opts{man3dir}, $opts{man3ext});
76 # Install the pods embedded in the installed scripts
77 runpod2man('utils', $opts{man1dir}, $opts{man1ext}, 'c2ph', 'h2ph', 'h2xs',
78 'perlcc', 'perldoc', 'perlbug', 'pl2pm', 'splain', 'dprofpp');
79 runpod2man('x2p', $opts{man1dir}, $opts{man1ext}, 's2p', 'a2p.pod',
81 runpod2man('pod', $opts{man1dir}, $opts{man1ext}, 'pod2man', 'pod2html',
82 'pod2text', 'pod2usage', 'podchecker', 'podselect');
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 $opts{man1dir} and $opts{man1ext}.
87 runpod2man('utils', $opts{man1dir}, $opts{man1ext}, 'pstruct');
89 # Similar concern as with pstruct/c2ph above: psed is s2p by other name.
90 runpod2man('x2p', $opts{man1dir}, $opts{man1ext}, 'psed');
92 runpod2man('lib/ExtUtils', $opts{man1dir}, $opts{man1ext}, 'xsubpp');
95 # @script is scripts names if we are installing manpages embedded
96 # in scripts, () otherwise
97 my($poddir, $mandir, $manext, @script) = @_;
99 my($downdir); # can't just use .. when installing xsubpp manpage
102 $downdir =~ s:[^/]+:..:g;
103 my($builddir) = Cwd::getcwd();
105 if ($mandir eq ' ' or $mandir eq '') {
107 warn "Skipping installation of $poddir/$_ man page.\n"
110 warn "Skipping installation of $poddir man pages.\n";
115 print "chdir $poddir\n" if $opts{verbose};
116 chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n";
118 # We insist on using the current version of pod2man in case there
119 # are enhancements or changes from previous installed versions.
120 # The error message doesn't include the '..' because the user
121 # won't be aware that we've chdir to $poddir.
122 -r "$downdir/pod/pod2man" || die "Executable pod/pod2man not found.\n";
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.)
129 my $pod2man = "$downdir/perl -I $downdir/lib $downdir/pod/pod2man --section=$manext --official";
131 mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify}; # In File::Path
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.
140 File::Find::find(\&lsmodpods, '.');
143 foreach my $mod (@modpods) {
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
150 # Convert name from File/Basename.pm to File::Basename.3 format,
152 $manpage =~ s#\.p(m|od)$##;
153 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
157 $manpage =~ s#/#::#g;
159 $tmp = "${mandir}/${manpage}.tmp";
160 $manpage = "${mandir}/${manpage}.${manext}";
161 push @to_process, [$mod, $tmp, $manpage];
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) = @$_;
170 if (rename($tmp, $manpage)) {
171 $packlist->{$manpage} = { type => 'file' };
175 unless ($opts{notify}) {
181 chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n";
182 print " chdir $builddir\n" if $opts{verbose};
186 my $dir = $File::Find::dir;
187 my $name = $File::Find::name;
190 push(@modpods, $name) if ($name =~ /\.p(m|od)$/);
194 $packlist->write() unless $opts{notify};
195 print " Installation complete\n" if $opts{verbose};
200 ###############################################################################
201 # Utility subroutines from installperl
205 print " $cmd\n" if $opts{verbose};
206 unless ($opts{notify}) {
207 if ($Config{d_fork}) {
208 fork ? wait : exec $cmd; # Allow user to ^C out of command.
213 warn "Command failed!!\n" if $?;
222 foreach my $name (@names) {
223 next unless -e $name;
224 chmod 0777, $name if $^O eq 'os2';
225 print " unlink $name\n" if $opts{verbose};
226 ( CORE::unlink($name) and ++$cnt
227 or warn "Couldn't unlink $name: $!\n" ) unless $opts{notify};
236 print $opts{verbose} ? " ln $from $to\n" : " $to\n" unless $opts{silent};
238 CORE::link($from, $to)
240 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
241 ? die "AFS" # okay inside eval {}
242 : warn "Couldn't link $from to $to: $!\n"
243 unless $opts{notify};
246 File::Copy::copy($from, $to)
248 : warn "Couldn't copy $from to $to: $!\n"
249 unless $opts{notify};
256 if (-f $to and not unlink($to)) {
258 for ($i = 1; $i < 50; $i++) {
259 last if CORE::rename($to, "$to.$i");
261 warn("Cannot rename to `$to.$i': $!"), return 0
262 if $i >= 50; # Give up!
264 link($from,$to) || return 0;
269 my($mode,$name) = @_;
271 printf " chmod %o %s\n", $mode, $name if $opts{verbose};
272 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
273 unless $opts{notify};
278 my($dev1, $ino1, $dev2, $ino2);
281 ($dev1, $ino1) = stat($p1);
282 ($dev2, $ino2) = stat($p2);
283 ($dev1 == $dev2 && $ino1 == $ino2);