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 @modpods);
15 if ($Config{d_umask}) {
16 umask(022); # umasks like 077 aren't that useful for installations
19 $ENV{SHELL} = 'sh' if $^O eq 'os2';
21 my $ver = $Config{version}; # Not used presently.
22 my $release = substr($],0,3); # Not used presently.
23 my $patchlevel = substr($],3,2);
24 die "Patchlevel of perl ($patchlevel)",
25 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
26 if $patchlevel != $Config{'PERL_VERSION'};
29 "Usage: installman --man1dir=/usr/wherever --man1ext=1
30 --man3dir=/usr/wherever --man3ext=3
32 --notify --verbose --silent --help
34 man1dir = $Config{'installman1dir'};
35 man1ext = $Config{'man1ext'};
36 man3dir = $Config{'installman3dir'};
37 man3ext = $Config{'man3ext'};
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";
44 qw( man1dir=s man1ext=s man3dir=s man3ext=s batchlimit=i
45 notify n help silent S verbose V))
47 die $usage if $opts{help};
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};
58 $opts{notify} ||= $opts{n};
59 $opts{verbose} ||= $opts{V} || $opts{notify};
63 -x "./perl$Config{exe_ext}"
64 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
65 -d $Config{'installprivlib'}
66 || warn "Perl library directory $Config{'installprivlib'} not found.
67 Have you run make install?. (Installing anyway.)\n";
68 -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
69 " (Installing anyway.)\n";
71 $packlist = ExtUtils::Packlist->new("$Config{installarchlib}/.packlist");
74 # Install the main pod pages.
75 pod2man('pod', $opts{man1dir}, $opts{man1ext});
77 # Install the pods for library modules.
78 pod2man('lib', $opts{man3dir}, $opts{man3ext});
80 # Install the pods embedded in the installed scripts
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);
88 if (my ($where2, $what2) = m|#.*link\s*=\s*(\S+)/(\S+)|) {
89 my $old = "$opts{man1dir}/$what.$opts{man1ext}";
90 my $new = "$opts{man1dir}/$what2.$opts{man1ext}";
97 # @script is scripts names if we are installing manpages embedded
98 # in scripts, () otherwise
99 my($poddir, $mandir, $manext, @script) = @_;
101 my($downdir); # can't just use .. when installing xsubpp manpage
104 $downdir =~ s:[^/]+:..:g;
105 my($builddir) = Cwd::getcwd();
107 if ($mandir eq ' ' or $mandir eq '') {
109 warn "Skipping installation of $poddir/$_ man page.\n"
112 warn "Skipping installation of $poddir man pages.\n";
117 print "chdir $poddir\n" if $opts{verbose};
118 chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n";
120 mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify}; # In File::Path
121 # Make a list of all the .pm and .pod files in the directory. We will
122 # always run from the lib directory and use the full pathname
129 File::Find::find(\&lsmodpods, '.');
132 foreach my $mod (@modpods) {
135 # Skip .pm files that have corresponding .pod files, and Functions.pm.
136 next if (($tmp = $mod) =~ s/\.pm$/.pod/ && -f $tmp);
137 next if ($mod eq 'Pod/Functions.pm'); #### Used only by pod itself
139 # Convert name from File/Basename.pm to File::Basename.3 format,
141 $manpage =~ s#\.p(m|od)$##;
142 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
146 $manpage =~ s#/#::#g;
148 $tmp = "${mandir}/${manpage}.tmp";
149 $manpage = "${mandir}/${manpage}.${manext}";
150 push @to_process, [$mod, $tmp, $manpage];
153 my $parser = Pod::Man->new( section => $manext,
155 center => 'Perl Programmers Reference Guide'
157 foreach my $page (@to_process) {
158 my($pod, $tmp, $manpage) = @$page;
161 if (!$opts{notify} && $parser->parse_from_file($pod, $tmp)) {
163 if (rename($tmp, $manpage)) {
164 $packlist->{$manpage} = { type => 'file' };
171 chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n";
172 print " chdir $builddir\n" if $opts{verbose};
176 my $dir = $File::Find::dir;
177 my $name = $File::Find::name;
180 push(@modpods, $name) if ($name =~ /\.p(m|od)$/);
184 $packlist->write() unless $opts{notify};
185 print " Installation complete\n" if $opts{verbose};
190 ###############################################################################
191 # Utility subroutines from installperl
197 foreach my $name (@names) {
198 next unless -e $name;
199 chmod 0777, $name if $^O eq 'os2';
200 print " unlink $name\n" if $opts{verbose};
201 ( CORE::unlink($name) and ++$cnt
202 or warn "Couldn't unlink $name: $!\n" ) unless $opts{notify};
211 print " ln $from $to\n" if $opts{verbose};
213 CORE::link($from, $to)
215 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
216 ? die "AFS" # okay inside eval {}
217 : warn "Couldn't link $from to $to: $!\n"
218 unless $opts{notify};
221 File::Copy::copy($from, $to)
223 : warn "Couldn't copy $from to $to: $!\n"
224 unless $opts{notify};
231 if (-f $to and not unlink($to)) {
233 for ($i = 1; $i < 50; $i++) {
234 last if CORE::rename($to, "$to.$i");
236 warn("Cannot rename to `$to.$i': $!"), return 0
237 if $i >= 50; # Give up!
239 link($from,$to) || return 0;
244 my($mode,$name) = @_;
246 printf " chmod %o %s\n", $mode, $name if $opts{verbose};
247 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
248 unless $opts{notify};
253 my($dev1, $ino1, $dev2, $ino2);
256 ($dev1, $ino1) = stat($p1);
257 ($dev2, $ino2) = stat($p2);
258 ($dev1 == $dev2 && $ino1 == $ino2);