2 BEGIN { @INC = qw(lib) }
7 if ($Config{userelocatableinc}) {
8 # This might be a considered a hack. Need to get information about the
9 # configuration from Config.pm *before* Config.pm expands any .../
12 # So we set $^X to pretend that we're the already installed perl, so
13 # Config.pm doesits ... expansion off that location.
15 my $location = $Config{initialinstalllocation};
16 die <<'OS' unless defined $location;
17 $Config{initialinstalllocation} is not defined - can't install a relocatable
20 $^X = "$location/perl";
21 # And then remove all trace of ever having loaded Config.pm, so that
22 # it will reload with the revised $^X
24 delete $INC{"Config.pm"};
25 delete $INC{"Config_heavy.pl"};
26 # You never saw us. We weren't here.
34 use File::Path qw(mkpath);
35 use ExtUtils::Packlist;
37 use subs qw(unlink chmod rename link);
38 use vars qw($packlist);
40 if ($Config{d_umask}) {
41 umask(022); # umasks like 077 aren't that useful for installations
44 $ENV{SHELL} = 'sh' if $^O eq 'os2';
46 my $ver = $Config{version}; # Not used presently.
47 my $release = substr($],0,3); # Not used presently.
48 my $patchlevel = substr($],3,2);
49 die "Patchlevel of perl ($patchlevel)",
50 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
51 if $patchlevel != $Config{'PERL_VERSION'};
54 "Usage: installman --man1dir=/usr/wherever --man1ext=1
55 --man3dir=/usr/wherever --man3ext=3
57 --notify --verbose --silent --help
59 man1dir = $Config{'installman1dir'};
60 man1ext = $Config{'man1ext'};
61 man3dir = $Config{'installman3dir'};
62 man3ext = $Config{'man3ext'};
63 --notify (or -n) just lists commands that would be executed.
64 --verbose (or -V) report all progress.
65 --silent (or -S) be silent. Only report errors.\n";
69 qw( man1dir=s man1ext=s man3dir=s man3ext=s batchlimit=i
70 destdir:s notify n help silent S verbose V))
72 die $usage if $opts{help};
73 $opts{destdir} //= '';
75 $opts{man1dir} = "$opts{destdir}$Config{'installman1dir'}"
76 unless defined($opts{man1dir});
77 $opts{man1ext} = $Config{'man1ext'}
78 unless defined($opts{man1ext});
79 $opts{man3dir} = "$opts{destdir}$Config{'installman3dir'}"
80 unless defined($opts{man3dir});
81 $opts{man3ext} = $Config{'man3ext'}
82 unless defined($opts{man3ext});
83 $opts{silent} ||= $opts{S};
84 $opts{notify} ||= $opts{n};
85 $opts{verbose} ||= $opts{V} || $opts{notify};
89 -x "./perl$Config{exe_ext}"
90 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
91 -d "$opts{destdir}$Config{'installprivlib'}"
92 || warn "Perl library directory $Config{'installprivlib'} not found.
93 Have you run make install?. (Installing anyway.)\n";
94 -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
95 " (Installing anyway.)\n";
97 $packlist = ExtUtils::Packlist->new("$opts{destdir}$Config{installarchlib}/.packlist");
100 # Install the main pod pages.
101 pod2man('pod', $opts{man1dir}, $opts{man1ext});
103 # Install the pods for library modules.
104 pod2man('lib', $opts{man3dir}, $opts{man3ext});
106 # Install the pods embedded in the installed scripts
107 my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir};
108 open UTILS, "utils.lst" or die "Can't open 'utils.lst': $!";
112 $_ = $1 if /#.*pod\s*=\s*(\S+)/;
113 my ($where, $what) = m|^(\S*)/(\S+)|;
114 pod2man($where, $opts{man1dir}, $opts{man1ext}, $what);
116 if (my ($where2, $what2) = m|#.*link\s*=\s*(\S+)/(\S+)|) {
117 my $old = "$opts{man1dir}/$what.$opts{man1ext}";
118 my $new = "$opts{man1dir}/$what2.$opts{man1ext}";
122 $xold =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
124 $xnew =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
125 $packlist->{$xnew} = { from => $xold, type => 'link' };
131 # @script is scripts names if we are installing manpages embedded
132 # in scripts, () otherwise
133 my($poddir, $mandir, $manext, @script) = @_;
134 if ($mandir eq ' ' or $mandir eq '') {
136 warn "Skipping installation of $poddir/$_ man page.\n"
139 warn "Skipping installation of $poddir man pages.\n";
144 print "installing from $poddir\n" if $opts{verbose};
146 mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify}; # In File::Path
147 # Make a list of all the .pm and .pod files in the directory. We avoid
148 # chdir because we are running with @INC = '../lib', and modules may wish
149 # to dynamically require Carp::Heavy or other diagnostics warnings.
150 # Hash the names of files we find, keys are names relative to perl build
151 # dir ('.'), values are names relative to $poddir.
154 %modpods = (map {+"$poddir/$_", $_} @script);
157 File::Find::find({no_chdir=>1,
159 # $_ is $File::Find::name when using no_chdir
160 if (-f $_ and /\.p(?:m|od)$/) {
163 $modpods{$fullname} = $_;
169 foreach my $mod (sort keys %modpods) {
170 my $manpage = $modpods{$mod};
172 # Skip .pm files that have corresponding .pod files, and Functions.pm.
173 next if (($tmp = $mod) =~ s/\.pm$/.pod/ && -f $tmp);
174 next if $mod =~ m:/t/:; # no pods from test directories
175 next if ($manpage eq 'Pod/Functions.pm'); #### Used only by pod itself
177 # Skip files without pod docs
184 ++$has_pod and last if /^=(?:head\d+|item|pod)\b/;
192 warn "no documentation in $mod\n";
196 # Convert name from File/Basename.pm to File::Basename.3 format,
198 $manpage =~ s#\.p(m|od)$##;
199 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
203 $manpage =~ s#/#::#g;
205 $tmp = "${mandir}/${manpage}.tmp";
206 $manpage = "${mandir}/${manpage}.${manext}";
207 push @to_process, [$mod, $tmp, $manpage];
210 foreach my $page (@to_process) {
211 my($pod, $tmp, $manpage) = @$page;
213 my $parser = Pod::Man->new( section => $manext,
215 center => 'Perl Programmers Reference Guide'
217 my $xmanpage = $manpage;
218 $xmanpage =~ s/^\Q$opts{'destdir'}\E// if $opts{'destdir'};
219 print " $xmanpage\n";
220 if (!$opts{notify} && $parser->parse_from_file($pod, $tmp)) {
222 if (rename($tmp, $manpage)) {
223 $packlist->{$xmanpage} = { type => 'file' };
232 $packlist->write() unless $opts{notify};
233 print " Installation complete\n" if $opts{verbose};
237 ###############################################################################
238 # Utility subroutines from installperl
244 foreach my $name (@names) {
245 next unless -e $name;
246 chmod 0777, $name if $^O eq 'os2';
247 print " unlink $name\n" if $opts{verbose};
248 ( CORE::unlink($name) and ++$cnt
249 or warn "Couldn't unlink $name: $!\n" ) unless $opts{notify};
258 print " ln $from $to\n" if $opts{verbose};
260 CORE::link($from, $to)
262 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
263 ? die "AFS" # okay inside eval {}
264 : warn "Couldn't link $from to $to: $!\n"
265 unless $opts{notify};
268 File::Copy::copy($from, $to)
270 : warn "Couldn't copy $from to $to: $!\n"
271 unless $opts{notify};
278 if (-f $to and not unlink($to)) {
280 for ($i = 1; $i < 50; $i++) {
281 last if CORE::rename($to, "$to.$i");
283 warn("Cannot rename to `$to.$i': $!"), return 0
284 if $i >= 50; # Give up!
286 link($from,$to) || return 0;
291 my($mode,$name) = @_;
293 printf " chmod %o %s\n", $mode, $name if $opts{verbose};
294 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
295 unless $opts{notify};
300 my($dev1, $ino1, $dev2, $ino2);
303 ($dev1, $ino1) = stat($p1);
304 ($dev2, $ino2) = stat($p2);
305 ($dev1 == $dev2 && $ino1 == $ino2);