2 BEGIN { @INC = ('lib') }
7 use File::Path qw(mkpath);
8 use ExtUtils::Packlist;
9 use subs qw(unlink chmod rename link);
10 use vars qw($packlist);
13 $ENV{SHELL} = 'sh' if $^O eq 'os2';
15 $ver = $Config{version};
16 $release = substr($],0,3); # Not used presently.
17 $patchlevel = substr($],3,2);
18 die "Patchlevel of perl ($patchlevel)",
19 "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
20 if $patchlevel != $Config{'PERL_VERSION'};
23 "Usage: installman --man1dir=/usr/wherever --man1ext=1
24 --man3dir=/usr/wherever --man3ext=3
27 man1dir = $Config{'installman1dir'};
28 man1ext = $Config{'man1ext'};
29 man3dir = $Config{'installman3dir'};
30 man3ext = $Config{'man3ext'};
31 --notify (or -n) just lists commands that would be executed.\n";
33 GetOptions( qw( man1dir=s man1ext=s man3dir=s man3ext=s notify n help silent S))
35 die $usage if $opt_help;
37 # These are written funny to avoid -w typo warnings.
38 $man1dir = defined($opt_man1dir) ? $opt_man1dir : $Config{'installman1dir'};
39 $man1ext = defined($opt_man1ext) ? $opt_man1ext : $Config{'man1ext'};
40 $man3dir = defined($opt_man3dir) ? $opt_man3dir : $Config{'installman3dir'};
41 $man3ext = defined($opt_man3ext) ? $opt_man3ext : $Config{'man3ext'};
42 $silent = $opt_silent || $opt_s;
44 $notify = $opt_notify || $opt_n;
48 -x "./perl$Config{exe_ext}"
49 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
50 -d $Config{'installprivlib'}
51 || warn "Perl library directory $Config{'installprivlib'} not found.
52 Have you run make install?. (Installing anyway.)\n";
53 -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
54 " (Installing anyway.)\n";
56 $packlist = ExtUtils::Packlist->new("$Config{installarchlib}/.packlist");
58 # Install the main pod pages.
59 runpod2man('pod', $man1dir, $man1ext);
61 # Install the pods for library modules.
62 runpod2man('lib', $man3dir, $man3ext);
64 # Install the pods embedded in the installed scripts
65 runpod2man('utils', $man1dir, $man1ext, 'c2ph');
66 runpod2man('utils', $man1dir, $man1ext, 'h2ph');
67 runpod2man('utils', $man1dir, $man1ext, 'h2xs');
68 runpod2man('utils', $man1dir, $man1ext, 'perlcc');
69 runpod2man('utils', $man1dir, $man1ext, 'perldoc');
70 runpod2man('utils', $man1dir, $man1ext, 'perlbug');
71 runpod2man('utils', $man1dir, $man1ext, 'pl2pm');
72 runpod2man('utils', $man1dir, $man1ext, 'splain');
73 runpod2man('utils', $man1dir, $man1ext, 'dprofpp');
74 runpod2man('x2p', $man1dir, $man1ext, 's2p');
75 runpod2man('x2p', $man1dir, $man1ext, 'a2p.pod');
76 runpod2man('x2p', $man1dir, $man1ext, 'find2perl');
77 runpod2man('pod', $man1dir, $man1ext, 'pod2man');
78 runpod2man('pod', $man1dir, $man1ext, 'pod2html');
79 runpod2man('pod', $man1dir, $man1ext, 'pod2text');
80 runpod2man('pod', $man1dir, $man1ext, 'pod2usage');
81 runpod2man('pod', $man1dir, $man1ext, 'podchecker');
82 runpod2man('pod', $man1dir, $man1ext, 'podselect');
84 # It would probably be better to have this page linked
85 # to the c2ph man page. Or, this one could say ".so man1/c2ph.1",
86 # but then it would have to pay attention to $man1dir and $man1ext.
87 runpod2man('utils', $man1dir, $man1ext, 'pstruct');
89 runpod2man('lib/ExtUtils', $man1dir, $man1ext, 'xsubpp');
92 # $script is script name if we are installing a manpage embedded
93 # in a script, undef otherwise
94 my($poddir, $mandir, $manext, $script) = @_;
96 my($downdir); # can't just use .. when installing xsubpp manpage
99 $downdir =~ s:[^/]+:..:g;
100 my($builddir) = Cwd::getcwd();
102 if ($mandir eq ' ' or $mandir eq '') {
103 warn "Skipping installation of ",
104 ($script ? "$poddir/$script man page" : "$poddir man pages"), ".\n";
108 warn "chdir $poddir\n" unless $silent;
109 chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n";
111 # We insist on using the current version of pod2man in case there
112 # are enhancements or changes from previous installed versions.
113 # The error message doesn't include the '..' because the user
114 # won't be aware that we've chdir to $poddir.
115 -r "$downdir/pod/pod2man" || die "Executable pod/pod2man not found.\n";
117 # We want to be sure to use the current perl. We can't rely on
118 # the installed perl because it might not be actually installed
119 # yet. (The user may have set the $install* Configure variables
120 # to point to some temporary home, from which the executable gets
121 # installed by occult means.)
122 $pod2man = "$downdir/perl -I $downdir/lib $downdir/pod/pod2man --section=$manext --official";
124 mkpath($mandir, 1, 0777) unless $notify; # In File::Path
125 # Make a list of all the .pm and .pod files in the directory. We will
126 # always run pod2man from the lib directory and feed it the full pathname
127 # of the pod. This might be useful for pod2man someday.
129 @modpods = ($script);
133 find(\&lsmodpods, '.');
135 foreach $mod (@modpods) {
138 # Skip .pm files that have corresponding .pod files, and Functions.pm.
139 next if (($tmp = $mod) =~ s/\.pm$/.pod/ && -f $tmp);
140 next if ($mod eq 'Pod/Functions.pm'); #### Used only by pod itself
142 # Convert name from File/Basename.pm to File::Basename.3 format,
144 $manpage =~ s#\.p(m|od)$##;
145 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O eq 'cygwin') {
149 $manpage =~ s#/#::#g;
151 $tmp = "${mandir}/${manpage}.tmp";
152 $manpage = "${mandir}/${manpage}.${manext}";
153 if (&cmd("$pod2man $mod > $tmp") == 0 && !$notify && -s $tmp) {
154 if (rename($tmp, $manpage)) {
155 $packlist->{$manpage} = { type => 'file' };
163 chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n";
164 warn "chdir $builddir\n" unless $silent;
168 my $dir = $File::Find::dir;
169 my $name = $File::Find::name;
172 push(@modpods, $name) if ($name =~ /\.p(m|od)$/);
176 $packlist->write() unless $notify;
177 warn " Installation complete\n";
182 ###############################################################################
183 # Utility subroutines from installperl
187 warn " $cmd\n" unless $cmd;
189 if ($Config{d_fork}) {
190 fork ? wait : exec $cmd; # Allow user to ^C out of command.
195 warn "Command failed!!\n" if $?;
204 foreach $name (@names) {
205 next unless -e $name;
206 chmod 0777, $name if $^O eq 'os2';
207 warn " unlink $name\n" unless $silent;
208 ( CORE::unlink($name) and ++$cnt
209 or warn "Couldn't unlink $name: $!\n" ) unless $notify;
218 warn $silent ? " $to\n" : " ln $from $to\n";
220 CORE::link($from, $to)
222 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
223 ? die "AFS" # okay inside eval {}
224 : warn "Couldn't link $from to $to: $!\n"
228 File::Copy::copy($from, $to)
230 : warn "Couldn't copy $from to $to: $!\n"
237 local($from,$to) = @_;
238 if (-f $to and not unlink($to)) {
240 for ($i = 1; $i < 50; $i++) {
241 last if CORE::rename($to, "$to.$i");
243 warn("Cannot rename to `$to.$i': $!"), return 0
244 if $i >= 50; # Give up!
246 link($from,$to) || return 0;
251 local($mode,$name) = @_;
253 warn( " chmod %o %s\n", $mode, $name) unless $silent;
254 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
259 local($p1, $p2) = @_;
260 local($dev1, $ino1, $dev2, $ino2);
263 ($dev1, $ino1) = stat($p1);
264 ($dev2, $ino2) = stat($p2);
265 ($dev1 == $dev2 && $ino1 == $ino2);