2 BEGIN { @INC = qw(lib) }
8 use File::Path qw(mkpath);
9 use ExtUtils::Packlist;
11 use subs qw(unlink chmod rename link);
12 use vars qw($packlist);
14 if ($Config{d_umask}) {
15 umask(022); # umasks like 077 aren't that useful for installations
18 $ENV{SHELL} = 'sh' if $^O eq 'os2';
20 my $ver = $Config{version}; # Not used presently.
21 my $release = substr($],0,3); # Not used presently.
22 my $patchlevel = substr($],3,2);
23 die "Patchlevel of perl ($patchlevel)",
24 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
25 if $patchlevel != $Config{'PERL_VERSION'};
28 "Usage: installman --man1dir=/usr/wherever --man1ext=1
29 --man3dir=/usr/wherever --man3ext=3
31 --notify --verbose --silent --help
33 man1dir = $Config{'installman1dir'};
34 man1ext = $Config{'man1ext'};
35 man3dir = $Config{'installman3dir'};
36 man3ext = $Config{'man3ext'};
37 --notify (or -n) just lists commands that would be executed.
38 --verbose (or -V) report all progress.
39 --silent (or -S) be silent. Only report errors.\n";
43 qw( man1dir=s man1ext=s man3dir=s man3ext=s batchlimit=i
44 notify n help silent S verbose V))
46 die $usage if $opts{help};
48 $opts{man1dir} = $Config{'installman1dir'}
49 unless defined($opts{man1dir});
50 $opts{man1ext} = $Config{'man1ext'}
51 unless defined($opts{man1ext});
52 $opts{man3dir} = $Config{'installman3dir'}
53 unless defined($opts{man3dir});
54 $opts{man3ext} = $Config{'man3ext'}
55 unless defined($opts{man3ext});
56 $opts{silent} ||= $opts{S};
57 $opts{notify} ||= $opts{n};
58 $opts{verbose} ||= $opts{V} || $opts{notify};
62 -x "./perl$Config{exe_ext}"
63 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
64 -d $Config{'installprivlib'}
65 || warn "Perl library directory $Config{'installprivlib'} not found.
66 Have you run make install?. (Installing anyway.)\n";
67 -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
68 " (Installing anyway.)\n";
70 $packlist = ExtUtils::Packlist->new("$Config{installarchlib}/.packlist");
73 # Install the main pod pages.
74 pod2man('pod', $opts{man1dir}, $opts{man1ext});
76 # Install the pods for library modules.
77 pod2man('lib', $opts{man3dir}, $opts{man3ext});
79 # Install the pods embedded in the installed scripts
80 my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir};
81 open UTILS, "utils.lst" or die "Can't open 'utils.lst': $!";
85 $_ = $1 if /#.*pod\s*=\s*(\S+)/;
86 my ($where, $what) = m|^(.*?)/(\S+)|;
87 pod2man($where, $opts{man1dir}, $opts{man1ext}, $what);
89 if (my ($where2, $what2) = m|#.*link\s*=\s*(\S+)/(\S+)|) {
90 my $old = "$opts{man1dir}/$what.$opts{man1ext}";
91 my $new = "$opts{man1dir}/$what2.$opts{man1ext}";
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 ($manpage eq 'Pod/Functions.pm'); #### Used only by pod itself
144 # Convert name from File/Basename.pm to File::Basename.3 format,
146 $manpage =~ s#\.p(m|od)$##;
147 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
151 $manpage =~ s#/#::#g;
153 $tmp = "${mandir}/${manpage}.tmp";
154 $manpage = "${mandir}/${manpage}.${manext}";
155 push @to_process, [$mod, $tmp, $manpage];
158 my $parser = Pod::Man->new( section => $manext,
160 center => 'Perl Programmers Reference Guide'
162 foreach my $page (@to_process) {
163 my($pod, $tmp, $manpage) = @$page;
166 if (!$opts{notify} && $parser->parse_from_file($pod, $tmp)) {
168 if (rename($tmp, $manpage)) {
169 $packlist->{$manpage} = { type => 'file' };
178 $packlist->write() unless $opts{notify};
179 print " Installation complete\n" if $opts{verbose};
184 ###############################################################################
185 # Utility subroutines from installperl
191 foreach my $name (@names) {
192 next unless -e $name;
193 chmod 0777, $name if $^O eq 'os2';
194 print " unlink $name\n" if $opts{verbose};
195 ( CORE::unlink($name) and ++$cnt
196 or warn "Couldn't unlink $name: $!\n" ) unless $opts{notify};
205 print " ln $from $to\n" if $opts{verbose};
207 CORE::link($from, $to)
209 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
210 ? die "AFS" # okay inside eval {}
211 : warn "Couldn't link $from to $to: $!\n"
212 unless $opts{notify};
215 File::Copy::copy($from, $to)
217 : warn "Couldn't copy $from to $to: $!\n"
218 unless $opts{notify};
225 if (-f $to and not unlink($to)) {
227 for ($i = 1; $i < 50; $i++) {
228 last if CORE::rename($to, "$to.$i");
230 warn("Cannot rename to `$to.$i': $!"), return 0
231 if $i >= 50; # Give up!
233 link($from,$to) || return 0;
238 my($mode,$name) = @_;
240 printf " chmod %o %s\n", $mode, $name if $opts{verbose};
241 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
242 unless $opts{notify};
247 my($dev1, $ino1, $dev2, $ino2);
250 ($dev1, $ino1) = stat($p1);
251 ($dev2, $ino2) = stat($p2);
252 ($dev1 == $dev2 && $ino1 == $ino2);