Commit | Line | Data |
---|---|---|
f0512cd0 | 1 | #!./perl -w |
16d20bd9 | 2 | BEGIN { @INC = ('lib') } |
f0512cd0 | 3 | use strict; |
16d20bd9 AD |
4 | use Config; |
5 | use Getopt::Long; | |
6 | use File::Find; | |
354f3b56 | 7 | use File::Copy; |
356fc125 | 8 | use File::Path qw(mkpath); |
354f3b56 | 9 | use ExtUtils::Packlist; |
a2743834 | 10 | use Pod::Man; |
cd8bccb5 | 11 | use subs qw(unlink chmod rename link); |
f0512cd0 | 12 | use vars qw($packlist @modpods); |
16d20bd9 AD |
13 | require Cwd; |
14 | ||
791b4ad3 PZ |
15 | if ($Config{d_umask}) { |
16 | umask(022); # umasks like 077 aren't that useful for installations | |
17 | } | |
18 | ||
cd8bccb5 | 19 | $ENV{SHELL} = 'sh' if $^O eq 'os2'; |
16d20bd9 | 20 | |
f0512cd0 DC |
21 | my $ver = $Config{version}; # Not used presently. |
22 | my $release = substr($],0,3); # Not used presently. | |
23 | my $patchlevel = substr($],3,2); | |
16d20bd9 | 24 | die "Patchlevel of perl ($patchlevel)", |
cceca5ed GS |
25 | "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n" |
26 | if $patchlevel != $Config{'PERL_VERSION'}; | |
16d20bd9 | 27 | |
f0512cd0 | 28 | my $usage = |
16d20bd9 | 29 | "Usage: installman --man1dir=/usr/wherever --man1ext=1 |
b5f05010 | 30 | --man3dir=/usr/wherever --man3ext=3 |
f1745d4f | 31 | --batchlimit=40 |
eabd589f | 32 | --notify --verbose --silent --help |
16d20bd9 AD |
33 | Defaults are: |
34 | man1dir = $Config{'installman1dir'}; | |
35 | man1ext = $Config{'man1ext'}; | |
36 | man3dir = $Config{'installman3dir'}; | |
37 | man3ext = $Config{'man3ext'}; | |
eabd589f A |
38 | --notify (or -n) just lists commands that would be executed. |
39 | --verbose (or -V) report all progress. | |
40 | --silent (or -S) be silent. Only report errors.\n"; | |
16d20bd9 | 41 | |
f0512cd0 DC |
42 | my %opts; |
43 | GetOptions( \%opts, | |
f1745d4f | 44 | qw( man1dir=s man1ext=s man3dir=s man3ext=s batchlimit=i |
f0512cd0 | 45 | notify n help silent S verbose V)) |
16d20bd9 | 46 | || die $usage; |
f0512cd0 | 47 | die $usage if $opts{help}; |
16d20bd9 | 48 | |
f0512cd0 DC |
49 | $opts{man1dir} = $Config{'installman1dir'} |
50 | unless defined($opts{man1dir}); | |
51 | $opts{man1ext} = $Config{'man1ext'} | |
52 | unless defined($opts{man1ext}); | |
53 | $opts{man3dir} = $Config{'installman3dir'} | |
54 | unless defined($opts{man3dir}); | |
55 | $opts{man3ext} = $Config{'man3ext'} | |
56 | unless defined($opts{man3ext}); | |
57 | $opts{silent} ||= $opts{S}; | |
f0512cd0 | 58 | $opts{notify} ||= $opts{n}; |
4ad019ef | 59 | $opts{verbose} ||= $opts{V} || $opts{notify}; |
16d20bd9 AD |
60 | |
61 | #Sanity checks | |
62 | ||
cd8bccb5 | 63 | -x "./perl$Config{exe_ext}" |
64 | or warn "./perl$Config{exe_ext} not found! Have you run make?\n"; | |
16d20bd9 AD |
65 | -d $Config{'installprivlib'} |
66 | || warn "Perl library directory $Config{'installprivlib'} not found. | |
67 | Have you run make install?. (Installing anyway.)\n"; | |
cd8bccb5 | 68 | -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!", |
16d20bd9 AD |
69 | " (Installing anyway.)\n"; |
70 | ||
354f3b56 AB |
71 | $packlist = ExtUtils::Packlist->new("$Config{installarchlib}/.packlist"); |
72 | ||
21dae8a0 | 73 | |
16d20bd9 | 74 | # Install the main pod pages. |
a2743834 | 75 | pod2man('pod', $opts{man1dir}, $opts{man1ext}); |
16d20bd9 AD |
76 | |
77 | # Install the pods for library modules. | |
a2743834 | 78 | pod2man('lib', $opts{man3dir}, $opts{man3ext}); |
16d20bd9 | 79 | |
1fef88e7 | 80 | # Install the pods embedded in the installed scripts |
21dae8a0 SC |
81 | open UTILS, "utils.lst" or die "Can't open 'utils.lst': $!"; |
82 | while (<UTILS>) { | |
83 | next if /^#/; | |
84 | chomp; | |
85 | $_ = $1 if /#.*pod\s*=\s*(\S+)/; | |
7feaa10c | 86 | my ($where, $what) = m|^(.*?)/(\S+)|; |
a2743834 | 87 | pod2man($where, $opts{man1dir}, $opts{man1ext}, $what); |
93fe06f7 | 88 | if (($where, $what) = m|#.*link\s*=\s*(\S+)/(\S+)|) { |
a2743834 | 89 | pod2man($where, $opts{man1dir}, $opts{man1ext}, $what); |
21dae8a0 SC |
90 | } |
91 | } | |
1fef88e7 | 92 | |
a2743834 | 93 | sub pod2man { |
f1745d4f JH |
94 | # @script is scripts names if we are installing manpages embedded |
95 | # in scripts, () otherwise | |
96 | my($poddir, $mandir, $manext, @script) = @_; | |
1fef88e7 JM |
97 | |
98 | my($downdir); # can't just use .. when installing xsubpp manpage | |
99 | ||
100 | $downdir = $poddir; | |
101 | $downdir =~ s:[^/]+:..:g; | |
16d20bd9 AD |
102 | my($builddir) = Cwd::getcwd(); |
103 | ||
104 | if ($mandir eq ' ' or $mandir eq '') { | |
f1745d4f JH |
105 | if (@script) { |
106 | warn "Skipping installation of $poddir/$_ man page.\n" | |
107 | foreach @script; | |
108 | } else { | |
109 | warn "Skipping installation of $poddir man pages.\n"; | |
110 | } | |
16d20bd9 AD |
111 | return; |
112 | } | |
113 | ||
f0512cd0 | 114 | print "chdir $poddir\n" if $opts{verbose}; |
1fef88e7 | 115 | chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n"; |
16d20bd9 | 116 | |
418918ac | 117 | mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify}; # In File::Path |
16d20bd9 | 118 | # Make a list of all the .pm and .pod files in the directory. We will |
a2743834 MS |
119 | # always run from the lib directory and use the full pathname |
120 | # of the pod. | |
f1745d4f JH |
121 | if (@script) { |
122 | @modpods = @script; | |
72b3d9b4 GS |
123 | } |
124 | else { | |
1fef88e7 | 125 | @modpods = (); |
f0512cd0 | 126 | File::Find::find(\&lsmodpods, '.'); |
1fef88e7 | 127 | } |
f1745d4f | 128 | my @to_process; |
f0512cd0 DC |
129 | foreach my $mod (@modpods) { |
130 | my $manpage = $mod; | |
cd8bccb5 | 131 | my $tmp; |
132 | # Skip .pm files that have corresponding .pod files, and Functions.pm. | |
133 | next if (($tmp = $mod) =~ s/\.pm$/.pod/ && -f $tmp); | |
134 | next if ($mod eq 'Pod/Functions.pm'); #### Used only by pod itself | |
135 | ||
16d20bd9 AD |
136 | # Convert name from File/Basename.pm to File::Basename.3 format, |
137 | # if necessary. | |
138 | $manpage =~ s#\.p(m|od)$##; | |
4fabb596 | 139 | if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') { |
cd8bccb5 | 140 | $manpage =~ s#/#.#g; |
72b3d9b4 GS |
141 | } |
142 | else { | |
cd8bccb5 | 143 | $manpage =~ s#/#::#g; |
144 | } | |
145 | $tmp = "${mandir}/${manpage}.tmp"; | |
16d20bd9 | 146 | $manpage = "${mandir}/${manpage}.${manext}"; |
f1745d4f JH |
147 | push @to_process, [$mod, $tmp, $manpage]; |
148 | } | |
a2743834 MS |
149 | |
150 | my $parser = Pod::Man->new( section => $manext, | |
151 | official=> 1, | |
152 | center => 'Perl Programmers Reference Guide' | |
153 | ); | |
154 | foreach my $page (@to_process) { | |
155 | my($pod, $tmp, $manpage) = @$page; | |
156 | ||
157 | print " $manpage\n"; | |
158 | if (!$opts{notify} && $parser->parse_from_file($pod, $tmp)) { | |
159 | if (-s $tmp) { | |
160 | if (rename($tmp, $manpage)) { | |
161 | $packlist->{$manpage} = { type => 'file' }; | |
162 | next; | |
163 | } | |
164 | } | |
165 | unlink($tmp); | |
6d64b06f | 166 | } |
16d20bd9 AD |
167 | } |
168 | chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n"; | |
f0512cd0 | 169 | print " chdir $builddir\n" if $opts{verbose}; |
16d20bd9 AD |
170 | } |
171 | ||
172 | sub lsmodpods { | |
173 | my $dir = $File::Find::dir; | |
174 | my $name = $File::Find::name; | |
175 | if (-f $_) { | |
176 | $name =~ s#^\./##; | |
177 | push(@modpods, $name) if ($name =~ /\.p(m|od)$/); | |
178 | } | |
179 | } | |
180 | ||
f0512cd0 DC |
181 | $packlist->write() unless $opts{notify}; |
182 | print " Installation complete\n" if $opts{verbose}; | |
16d20bd9 AD |
183 | |
184 | exit 0; | |
185 | ||
186 | ||
187 | ############################################################################### | |
188 | # Utility subroutines from installperl | |
189 | ||
cd8bccb5 | 190 | sub unlink { |
f0512cd0 | 191 | my(@names) = @_; |
cd8bccb5 | 192 | my $cnt = 0; |
193 | ||
f0512cd0 | 194 | foreach my $name (@names) { |
72b3d9b4 GS |
195 | next unless -e $name; |
196 | chmod 0777, $name if $^O eq 'os2'; | |
f0512cd0 | 197 | print " unlink $name\n" if $opts{verbose}; |
72b3d9b4 | 198 | ( CORE::unlink($name) and ++$cnt |
f0512cd0 | 199 | or warn "Couldn't unlink $name: $!\n" ) unless $opts{notify}; |
cd8bccb5 | 200 | } |
201 | return $cnt; | |
202 | } | |
203 | ||
16d20bd9 | 204 | sub link { |
354f3b56 AB |
205 | my($from,$to) = @_; |
206 | my($success) = 0; | |
16d20bd9 | 207 | |
a2743834 | 208 | print " ln $from $to\n" if $opts{verbose}; |
354f3b56 AB |
209 | eval { |
210 | CORE::link($from, $to) | |
211 | ? $success++ | |
212 | : ($from =~ m#^/afs/# || $to =~ m#^/afs/#) | |
213 | ? die "AFS" # okay inside eval {} | |
214 | : warn "Couldn't link $from to $to: $!\n" | |
f0512cd0 | 215 | unless $opts{notify}; |
354f3b56 AB |
216 | }; |
217 | if ($@) { | |
218 | File::Copy::copy($from, $to) | |
219 | ? $success++ | |
220 | : warn "Couldn't copy $from to $to: $!\n" | |
f0512cd0 | 221 | unless $opts{notify}; |
354f3b56 AB |
222 | } |
223 | $success; | |
cd8bccb5 | 224 | } |
225 | ||
226 | sub rename { | |
f0512cd0 | 227 | my($from,$to) = @_; |
55a105fd | 228 | if (-f $to and not unlink($to)) { |
72b3d9b4 GS |
229 | my($i); |
230 | for ($i = 1; $i < 50; $i++) { | |
231 | last if CORE::rename($to, "$to.$i"); | |
232 | } | |
233 | warn("Cannot rename to `$to.$i': $!"), return 0 | |
234 | if $i >= 50; # Give up! | |
cd8bccb5 | 235 | } |
55a105fd NC |
236 | link($from,$to) || return 0; |
237 | unlink($from); | |
16d20bd9 AD |
238 | } |
239 | ||
240 | sub chmod { | |
f0512cd0 | 241 | my($mode,$name) = @_; |
16d20bd9 | 242 | |
f0512cd0 | 243 | printf " chmod %o %s\n", $mode, $name if $opts{verbose}; |
cd8bccb5 | 244 | CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name) |
f0512cd0 | 245 | unless $opts{notify}; |
16d20bd9 AD |
246 | } |
247 | ||
16d20bd9 | 248 | sub samepath { |
f0512cd0 DC |
249 | my($p1, $p2) = @_; |
250 | my($dev1, $ino1, $dev2, $ino2); | |
16d20bd9 AD |
251 | |
252 | if ($p1 ne $p2) { | |
253 | ($dev1, $ino1) = stat($p1); | |
254 | ($dev2, $ino2) = stat($p2); | |
255 | ($dev1 == $dev2 && $ino1 == $ino2); | |
256 | } | |
257 | else { | |
258 | 1; | |
259 | } | |
260 | } |