5 # This needs to be at BEGIN time, before any use of Config
6 require './install_lib.pl';
13 use File::Path qw(mkpath);
14 use ExtUtils::Packlist;
16 use vars qw($Is_VMS $Is_W32 $Is_OS2 $Is_Cygwin $Is_Darwin $Is_NetWare
19 $ENV{SHELL} = 'sh' if $^O eq 'os2';
21 my $patchlevel = substr($],3,2);
22 die "Patchlevel of perl ($patchlevel)",
23 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
24 if $patchlevel != $Config{'PERL_VERSION'};
27 "Usage: installman --man1dir=/usr/wherever --man1ext=1
28 --man3dir=/usr/wherever --man3ext=3
30 --notify --verbose --silent --help
32 man1dir = $Config{'installman1dir'};
33 man1ext = $Config{'man1ext'};
34 man3dir = $Config{'installman3dir'};
35 man3ext = $Config{'man3ext'};
36 --notify (or -n) just lists commands that would be executed.
37 --verbose (or -V) report all progress.
38 --silent (or -S) be silent. Only report errors.\n";
41 qw( man1dir=s man1ext=s man3dir=s man3ext=s batchlimit=i
42 destdir:s notify n help silent S verbose V))
44 die $usage if $opts{help};
45 $opts{destdir} //= '';
47 foreach my $pre (qw(man1 man3)) {
48 $opts{"${pre}dir"} //= $opts{destdir} . $Config{"install${pre}dir"};
49 $opts{"${pre}ext"} //= $Config{"${pre}ext"};
51 $opts{silent} ||= $opts{S};
52 $opts{notify} ||= $opts{n};
53 $opts{verbose} ||= $opts{V} || $opts{notify};
57 -x "./perl$Config{exe_ext}"
58 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
59 -d "$opts{destdir}$Config{'installprivlib'}"
60 || warn "Perl library directory $Config{'installprivlib'} not found.
61 Have you run make install?. (Installing anyway.)\n";
62 -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
63 " (Installing anyway.)\n";
65 $packlist = ExtUtils::Packlist->new("$opts{destdir}$Config{installarchlib}/.packlist");
68 # Install the main pod pages.
69 pod2man('pod', $opts{man1dir}, $opts{man1ext});
71 # Install the pods for library modules.
72 pod2man('lib', $opts{man3dir}, $opts{man3ext});
74 # Install the pods embedded in the installed scripts
75 my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir};
76 open UTILS, "utils.lst" or die "Can't open 'utils.lst': $!";
80 $_ = $1 if /#.*pod\s*=\s*(\S+)/;
81 my ($where, $what) = m|^(\S*)/(\S+)|;
82 pod2man($where, $opts{man1dir}, $opts{man1ext}, $what);
84 if (my ($where2, $what2) = m|#.*link\s*=\s*(\S+)/(\S+)|) {
85 my $old = "$opts{man1dir}/$what.$opts{man1ext}";
86 my $new = "$opts{man1dir}/$what2.$opts{man1ext}";
90 $xold =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
92 $xnew =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
93 $packlist->{$xnew} = { from => $xold, type => 'link' };
99 # @script is scripts names if we are installing manpages embedded
100 # in scripts, () otherwise
101 my($poddir, $mandir, $manext, @script) = @_;
102 if ($mandir eq ' ' or $mandir eq '') {
104 warn "Skipping installation of $poddir/$_ man page.\n"
107 warn "Skipping installation of $poddir man pages.\n";
112 print "installing from $poddir\n" if $opts{verbose};
114 mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify}; # In File::Path
115 # Make a list of all the .pm and .pod files in the directory. We avoid
116 # chdir because we are running with @INC = '../lib', and modules may wish
117 # to dynamically require Carp::Heavy or other diagnostics warnings.
118 # Hash the names of files we find, keys are names relative to perl build
119 # dir ('.'), values are names relative to $poddir.
122 %modpods = (map {+"$poddir/$_", $_} @script);
125 File::Find::find({no_chdir=>1,
127 # $_ is $File::Find::name when using no_chdir
128 if (-f $_ and /\.p(?:m|od)$/) {
131 $modpods{$fullname} = $_;
137 foreach my $mod (sort keys %modpods) {
138 my $manpage = $modpods{$mod};
140 # Skip .pm files that have corresponding .pod files, and Functions.pm.
141 next if (($tmp = $mod) =~ s/\.pm$/.pod/ && -f $tmp);
142 next if $mod =~ m:/t/:; # no pods from test directories
143 next if ($manpage eq 'Pod/Functions.pm'); #### Used only by pod itself
145 # Skip files without pod docs
152 ++$has_pod and last if /^=(?:head\d+|item|pod)\b/;
160 warn "no documentation in $mod\n";
164 # Convert name from File/Basename.pm to File::Basename.3 format,
166 $manpage =~ s#\.p(m|od)$##;
167 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
171 $manpage =~ s#/#::#g;
173 $tmp = "${mandir}/${manpage}.tmp";
174 $manpage = "${mandir}/${manpage}.${manext}";
175 push @to_process, [$mod, $tmp, $manpage];
178 foreach my $page (@to_process) {
179 my($pod, $tmp, $manpage) = @$page;
181 my $parser = Pod::Man->new( section => $manext,
183 center => 'Perl Programmers Reference Guide'
185 my $xmanpage = $manpage;
186 $xmanpage =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
187 print " $xmanpage\n";
188 if (!$opts{notify} && $parser->parse_from_file($pod, $tmp)) {
190 if (rename($tmp, $manpage)) {
191 $packlist->{$xmanpage} = { type => 'file' };
200 $packlist->write() unless $opts{notify};
201 print " Installation complete\n" if $opts{verbose};
207 if (-f $to and not unlink($to)) {
209 for ($i = 1; $i < 50; $i++) {
210 last if CORE::rename($to, "$to.$i");
212 warn("Cannot rename to `$to.$i': $!"), return 0
213 if $i >= 50; # Give up!
215 link($from,$to) || return 0;