This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move the wrapper for File::Path::mkpath() to install_lib.pl
[perl5.git] / installman
CommitLineData
f0512cd0 1#!./perl -w
be61d08e 2BEGIN {
9e6fc21f 3 @INC = qw(lib);
ae5391ad 4
9e6fc21f
NC
5 # This needs to be at BEGIN time, before any use of Config
6 require './install_lib.pl';
be61d08e 7}
9e6fc21f 8use strict;
be61d08e 9
16d20bd9 10use Getopt::Long;
354f3b56 11use ExtUtils::Packlist;
a2743834 12use Pod::Man;
d0265671 13use vars qw(%opts $packlist);
791b4ad3 14
d6a39ee2 15require './Porting/pod_lib.pl';
1cb2462d 16my %man1 = (map {($_->[0], $_->[1])} @{get_pod_metadata()->{master}});
d6a39ee2 17
cd8bccb5 18$ENV{SHELL} = 'sh' if $^O eq 'os2';
16d20bd9 19
f0512cd0 20my $patchlevel = substr($],3,2);
16d20bd9 21die "Patchlevel of perl ($patchlevel)",
cceca5ed
GS
22 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
23 if $patchlevel != $Config{'PERL_VERSION'};
16d20bd9 24
f0512cd0 25my $usage =
16d20bd9 26"Usage: installman --man1dir=/usr/wherever --man1ext=1
b5f05010 27 --man3dir=/usr/wherever --man3ext=3
eabd589f 28 --notify --verbose --silent --help
16d20bd9
AD
29 Defaults are:
30 man1dir = $Config{'installman1dir'};
31 man1ext = $Config{'man1ext'};
32 man3dir = $Config{'installman3dir'};
33 man3ext = $Config{'man3ext'};
eabd589f
A
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";
16d20bd9 37
8cef6e50
NC
38# --strip intentionally does nothing. By permitting installman to accept it
39# without error, the Makefile can pass the same options to installperl and
40# installman, which permits more simplification there than this comment costs.
f0512cd0 41GetOptions( \%opts,
d0265671 42 qw( man1dir=s man1ext=s man3dir=s man3ext=s
8cef6e50 43 destdir:s notify|n help|h|? silent|S verbose|V strip))
16d20bd9 44 || die $usage;
f0512cd0 45die $usage if $opts{help};
02bc0c09 46$opts{destdir} //= '';
16d20bd9 47
3cc5758c
NC
48foreach my $pre (qw(man1 man3)) {
49 $opts{"${pre}dir"} //= $opts{destdir} . $Config{"install${pre}dir"};
50 $opts{"${pre}ext"} //= $Config{"${pre}ext"};
51}
bbb45456 52$opts{verbose} ||= $opts{notify};
16d20bd9
AD
53
54#Sanity checks
55
ae5391ad 56-x "./perl$Config{exe_ext}"
cd8bccb5 57 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
5a9231b0 58-d "$opts{destdir}$Config{'installprivlib'}"
16d20bd9
AD
59 || warn "Perl library directory $Config{'installprivlib'} not found.
60 Have you run make install?. (Installing anyway.)\n";
cd8bccb5 61-x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
16d20bd9
AD
62 " (Installing anyway.)\n";
63
1ef57a5c 64$packlist = ExtUtils::Packlist->new("$opts{destdir}$Config{installarchlib}/.packlist");
354f3b56 65
16d20bd9 66# Install the main pod pages.
1cb2462d 67pod2man(\%man1, $opts{man1dir}, $opts{man1ext}, 'pod');
16d20bd9
AD
68
69# Install the pods for library modules.
45a365ec 70{
9bbb230a
NC
71 my $found = pods_to_install();
72 pod2man($found->{$_}, $opts{man3dir}, $opts{man3ext}, 'lib')
73 foreach qw(MODULE PRAGMA);
45a365ec 74}
16d20bd9 75
1fef88e7 76# Install the pods embedded in the installed scripts
bf1ee2ba 77my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir};
3301e5d1
NC
78my $fh = open_or_die('utils.lst');
79while (<$fh>) {
21dae8a0
SC
80 next if /^#/;
81 chomp;
b3e335c2 82 my ($path, $leaf) = m|^(\S*/(\S+))|;
e1aae8e4 83 # Have we already installed the manpage for this? (eg perldoc, a2p)
1cb2462d 84 next if $man1{$leaf};
b3e335c2 85 pod2man({$leaf, $path}, $opts{man1dir}, $opts{man1ext});
bf1ee2ba 86 if ($has_man1dir) {
b3e335c2
NC
87 if (my ($link) = m|#.*link\s*=\s*\S+/(\S+)|) {
88 my $old = "$opts{man1dir}/$leaf.$opts{man1ext}";
89 my $new = "$opts{man1dir}/$link.$opts{man1ext}";
bf1ee2ba
JH
90 unlink($new);
91 link($old, $new);
3301e5d1
NC
92 $old =~ s/^\Q$opts{destdir}\E// if $opts{destdir};
93 $new =~ s/^\Q$opts{destdir}\E// if $opts{destdir};
94 $packlist->{$new} = { from => $old, type => 'link' };
bf1ee2ba 95 }
21dae8a0
SC
96 }
97}
3301e5d1 98close $fh or my_die("close 'utils.lst': $!");
1fef88e7 99
a2743834 100sub pod2man {
45a365ec 101 my($modpods, $mandir, $manext, $where) = @_;
16d20bd9 102 if ($mandir eq ' ' or $mandir eq '') {
45a365ec
NC
103 if ($where) {
104 warn "Skipping installation of $where man pages.\n"
105 } else {
b3e335c2 106 warn "Skipping installation of $_ man page.\n"
45a365ec
NC
107 foreach values %$modpods;
108 }
109 return;
16d20bd9
AD
110 }
111
b3e335c2 112 if ($opts{verbose}) {
45a365ec
NC
113 if ($where) {
114 print "installing from $where\n";
b3e335c2 115 } else {
45a365ec
NC
116 print "installing $_\n"
117 foreach sort keys %$modpods;
b3e335c2
NC
118 }
119 }
16d20bd9 120
a01f5661 121 mkpath($mandir);
b3e335c2 122
b3e335c2
NC
123 foreach my $manpage (sort keys %$modpods) {
124 my $mod = $modpods->{$manpage};
cd8bccb5 125
63fae907
AT
126 # Skip files without pod docs
127 my $has_pod;
3301e5d1
NC
128 my $fh = open_or_die($mod);
129 while (my $line = <$fh>) {
130 if ($line =~ /^=head1\b/) {
131 ++$has_pod;
132 last;
133 }
134 }
135 close $fh or my_die("close '$mod': $!");
136 # Sadly it doesn't seem possible to re-use this handle for the call
137 # to parse_from_file() below, as Pod::Man relies on source_filename(),
138 # which Pod::Simple only sets accurately if it opens the file itself.
63fae907
AT
139
140 unless ($has_pod)
141 {
0f876784 142 warn "no documentation in $mod\n" unless $opts{silent};
63fae907
AT
143 next;
144 }
145
4fabb596 146 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
107ea3f3 147 $manpage =~ s#::#.#g;
cd8bccb5 148 }
d0265671 149 my $tmp = "${mandir}/${manpage}.tmp";
16d20bd9 150 $manpage = "${mandir}/${manpage}.${manext}";
a2743834 151
571afc3f
SP
152 my $parser = Pod::Man->new( section => $manext,
153 official=> 1,
154 center => 'Perl Programmers Reference Guide'
155 );
5a9231b0
MS
156 my $xmanpage = $manpage;
157 $xmanpage =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
0f876784 158 print " $xmanpage\n" unless $opts{silent};
d0265671 159 if (!$opts{notify} && $parser->parse_from_file($mod, $tmp)) {
a2743834 160 if (-s $tmp) {
4c432614 161 if (safe_rename($tmp, $manpage)) {
5a9231b0 162 $packlist->{$xmanpage} = { type => 'file' };
a2743834
MS
163 next;
164 }
165 }
166 unlink($tmp);
6d64b06f 167 }
16d20bd9 168 }
16d20bd9
AD
169}
170
f0512cd0
DC
171$packlist->write() unless $opts{notify};
172print " Installation complete\n" if $opts{verbose};
16d20bd9 173
5a6ebf5f
NC
174# Local variables:
175# cperl-indent-level: 4
176# indent-tabs-mode: nil
177# End:
178#
179# ex: set ts=8 sts=4 sw=4 et: