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';
16 $release = substr($ver,0,3); # Not used presently.
17 $patchlevel = substr($ver,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))
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'};
43 $notify = $opt_notify || $opt_n;
47 -x "./perl$Config{exe_ext}"
48 or warn "./perl$Config{exe_ext} not found! Have you run make?\n";
49 -d $Config{'installprivlib'}
50 || warn "Perl library directory $Config{'installprivlib'} not found.
51 Have you run make install?. (Installing anyway.)\n";
52 -x "t/perl$Config{exe_ext}" || warn "WARNING: You've never run 'make test'!!!",
53 " (Installing anyway.)\n";
55 $packlist = ExtUtils::Packlist->new("$Config{installarchlib}/.packlist");
57 # Install the main pod pages.
58 runpod2man('pod', $man1dir, $man1ext);
60 # Install the pods for library modules.
61 runpod2man('lib', $man3dir, $man3ext);
63 # Install the pods embedded in the installed scripts
64 runpod2man('utils', $man1dir, $man1ext, 'c2ph');
65 runpod2man('utils', $man1dir, $man1ext, 'h2ph');
66 runpod2man('utils', $man1dir, $man1ext, 'h2xs');
67 runpod2man('utils', $man1dir, $man1ext, 'perlcc');
68 runpod2man('utils', $man1dir, $man1ext, 'perldoc');
69 runpod2man('utils', $man1dir, $man1ext, 'perlbug');
70 runpod2man('utils', $man1dir, $man1ext, 'pl2pm');
71 runpod2man('utils', $man1dir, $man1ext, 'splain');
72 runpod2man('utils', $man1dir, $man1ext, 'dprofpp');
73 runpod2man('x2p', $man1dir, $man1ext, 's2p');
74 runpod2man('x2p', $man1dir, $man1ext, 'a2p.pod');
75 runpod2man('x2p', $man1dir, $man1ext, 'find2perl');
76 runpod2man('pod', $man1dir, $man1ext, 'pod2man');
77 runpod2man('pod', $man1dir, $man1ext, 'pod2html');
78 runpod2man('pod', $man1dir, $man1ext, 'pod2text');
79 runpod2man('pod', $man1dir, $man1ext, 'pod2usage');
80 runpod2man('pod', $man1dir, $man1ext, 'podchecker');
81 runpod2man('pod', $man1dir, $man1ext, 'podselect');
83 # It would probably be better to have this page linked
84 # to the c2ph man page. Or, this one could say ".so man1/c2ph.1",
85 # but then it would have to pay attention to $man1dir and $man1ext.
86 runpod2man('utils', $man1dir, $man1ext, 'pstruct');
88 runpod2man('lib/ExtUtils', $man1dir, $man1ext, 'xsubpp');
91 # $script is script name if we are installing a manpage embedded
92 # in a script, undef otherwise
93 my($poddir, $mandir, $manext, $script) = @_;
95 my($downdir); # can't just use .. when installing xsubpp manpage
98 $downdir =~ s:[^/]+:..:g;
99 my($builddir) = Cwd::getcwd();
101 if ($mandir eq ' ' or $mandir eq '') {
102 print STDERR "Skipping installation of ",
103 ($script ? "$poddir/$script man page" : "$poddir man pages"), ".\n";
107 print STDERR "chdir $poddir\n";
108 chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n";
110 # We insist on using the current version of pod2man in case there
111 # are enhancements or changes from previous installed versions.
112 # The error message doesn't include the '..' because the user
113 # won't be aware that we've chdir to $poddir.
114 -r "$downdir/pod/pod2man" || die "Executable pod/pod2man not found.\n";
116 # We want to be sure to use the current perl. We can't rely on
117 # the installed perl because it might not be actually installed
118 # yet. (The user may have set the $install* Configure variables
119 # to point to some temporary home, from which the executable gets
120 # installed by occult means.)
121 $pod2man = "$downdir/perl -I $downdir/lib $downdir/pod/pod2man --section=$manext --official";
123 mkpath($mandir, 1, 0777) unless $notify; # In File::Path
124 # Make a list of all the .pm and .pod files in the directory. We will
125 # always run pod2man from the lib directory and feed it the full pathname
126 # of the pod. This might be useful for pod2man someday.
128 @modpods = ($script);
132 find(\&lsmodpods, '.');
134 foreach $mod (@modpods) {
137 # Skip .pm files that have corresponding .pod files, and Functions.pm.
138 next if (($tmp = $mod) =~ s/\.pm$/.pod/ && -f $tmp);
139 next if ($mod eq 'Pod/Functions.pm'); #### Used only by pod itself
141 # Convert name from File/Basename.pm to File::Basename.3 format,
143 $manpage =~ s#\.p(m|od)$##;
144 if ($^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'uwin' || $^O =~ /cygwin/) {
148 $manpage =~ s#/#::#g;
150 $tmp = "${mandir}/${manpage}.tmp";
151 $manpage = "${mandir}/${manpage}.${manext}";
152 if (&cmd("$pod2man $mod > $tmp") == 0 && !$notify && -s $tmp) {
153 if (rename($tmp, $manpage)) {
154 $packlist->{$manpage} = { type => 'file' };
162 chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n";
163 print STDERR "chdir $builddir\n";
167 my $dir = $File::Find::dir;
168 my $name = $File::Find::name;
171 push(@modpods, $name) if ($name =~ /\.p(m|od)$/);
175 $packlist->write() unless $notify;
176 print STDERR " Installation complete\n";
181 ###############################################################################
182 # Utility subroutines from installperl
186 print STDERR " $cmd\n";
188 if ($Config{d_fork}) {
189 fork ? wait : exec $cmd; # Allow user to ^C out of command.
194 warn "Command failed!!\n" if $?;
203 foreach $name (@names) {
204 next unless -e $name;
205 chmod 0777, $name if $^O eq 'os2';
206 print STDERR " unlink $name\n";
207 ( CORE::unlink($name) and ++$cnt
208 or warn "Couldn't unlink $name: $!\n" ) unless $notify;
217 print STDERR " ln $from $to\n";
219 CORE::link($from, $to)
221 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
222 ? die "AFS" # okay inside eval {}
223 : warn "Couldn't link $from to $to: $!\n"
227 File::Copy::copy($from, $to)
229 : warn "Couldn't copy $from to $to: $!\n"
236 local($from,$to) = @_;
237 if (-f $to and not unlink($to)) {
239 for ($i = 1; $i < 50; $i++) {
240 last if CORE::rename($to, "$to.$i");
242 warn("Cannot rename to `$to.$i': $!"), return 0
243 if $i >= 50; # Give up!
245 link($from,$to) || return 0;
250 local($mode,$name) = @_;
252 printf STDERR " chmod %o %s\n", $mode, $name;
253 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
258 local($p1, $p2) = @_;
259 local($dev1, $ino1, $dev2, $ino2);
262 ($dev1, $ino1) = stat($p1);
263 ($dev2, $ino2) = stat($p2);
264 ($dev1 == $dev2 && $ino1 == $ino2);