source: trunk/third/perl/installman @ 10724

Revision 10724, 7.0 KB checked in by ghudson, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10723, which included commits to RCS files with non-trunk default branches.
  • Property svn:executable set to *
Line 
1#!./perl
2BEGIN { @INC = ('lib') }
3use Config;
4use Getopt::Long;
5use File::Find;
6use File::Path qw(mkpath);
7use subs qw(unlink chmod rename link);
8require Cwd;
9
10umask 022;
11$ENV{SHELL} = 'sh' if $^O eq 'os2';
12
13$ver = $];
14$release = substr($ver,0,3);   # Not used presently.
15$patchlevel = substr($ver,3,2);
16die "Patchlevel of perl ($patchlevel)",
17    "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
18        if $patchlevel != $Config{'PATCHLEVEL'};
19
20$usage =
21"Usage:  installman --man1dir=/usr/wherever --man1ext=1
22                    --man3dir=/usr/wherever --man3ext=3
23                    --notify --help
24        Defaults are:
25        man1dir = $Config{'installman1dir'};
26        man1ext = $Config{'man1ext'};
27        man3dir = $Config{'installman3dir'};
28        man3ext = $Config{'man3ext'};
29        --notify (or -n) just lists commands that would be executed.\n";
30
31GetOptions( qw( man1dir=s man1ext=s man3dir=s man3ext=s notify n help))
32        || die $usage;
33die $usage if $opt_help;
34
35# These are written funny to avoid -w typo warnings.
36$man1dir = defined($opt_man1dir) ? $opt_man1dir : $Config{'installman1dir'};
37$man1ext = defined($opt_man1ext) ? $opt_man1ext : $Config{'man1ext'};
38$man3dir = defined($opt_man3dir) ? $opt_man3dir : $Config{'installman3dir'};
39$man3ext = defined($opt_man3ext) ? $opt_man3ext : $Config{'man3ext'};
40
41$notify = $opt_notify || $opt_n;
42
43#Sanity checks
44
45-x  "./perl$Config{exe_ext}"
46  or warn "./perl$Config{exe_ext} not found!  Have you run make?\n";
47-d  $Config{'installprivlib'}
48        || warn "Perl library directory $Config{'installprivlib'} not found.
49                Have you run make install?.  (Installing anyway.)\n";
50-x "t/perl$Config{exe_ext}"             || warn "WARNING: You've never run 'make test'!!!",
51        "  (Installing anyway.)\n";
52
53# Install the main pod pages.
54runpod2man('pod', $man1dir, $man1ext);
55
56# Install the pods for library modules.
57runpod2man('lib', $man3dir, $man3ext);
58
59# Install the pods embedded in the installed scripts
60runpod2man('utils', $man1dir, $man1ext, 'c2ph');
61runpod2man('utils', $man1dir, $man1ext, 'h2ph');
62runpod2man('utils', $man1dir, $man1ext, 'h2xs');
63runpod2man('utils', $man1dir, $man1ext, 'perldoc');
64runpod2man('utils', $man1dir, $man1ext, 'perlbug');
65runpod2man('utils', $man1dir, $man1ext, 'pl2pm');
66runpod2man('utils', $man1dir, $man1ext, 'splain');
67runpod2man('x2p', $man1dir, $man1ext, 's2p');
68runpod2man('x2p', $man1dir, $man1ext, 'a2p.pod');
69runpod2man('pod', $man1dir, $man1ext, 'pod2man');
70runpod2man('pod', $man1dir, $man1ext, 'pod2html');
71
72# It would probably be better to have this page linked
73# to the c2ph man page.  Or, this one could say ".so man1/c2ph.1",
74# but then it would have to pay attention to $man1dir and $man1ext.
75runpod2man('utils', $man1dir, $man1ext, 'pstruct');
76
77runpod2man('lib/ExtUtils', $man1dir, $man1ext, 'xsubpp');
78
79sub runpod2man {
80    # $script is script name if we are installing a manpage embedded
81    # in a script, undef otherwise
82    my($poddir, $mandir, $manext, $script) = @_;
83
84    my($downdir); # can't just use .. when installing xsubpp manpage
85
86    $downdir = $poddir;
87    $downdir =~ s:[^/]+:..:g;
88    my($builddir) = Cwd::getcwd();
89
90    if ($mandir eq ' ' or $mandir eq '') {
91        print STDERR "Skipping installation of ",
92            ($script ? "$poddir/$script man page" : "$poddir man pages"), ".\n";
93        return;
94    }
95
96    print STDERR "chdir $poddir\n";
97    chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n";
98
99    # We insist on using the current version of pod2man in case there
100    # are enhancements or changes from previous installed versions.
101    # The error message doesn't include the '..' because the user
102    # won't be aware that we've chdir to $poddir.
103    -r  "$downdir/pod/pod2man" || die "Executable pod/pod2man not found.\n";
104
105    # We want to be sure to use the current perl.  We can't rely on
106    # the installed perl because it might not be actually installed
107    # yet. (The user may have set the $install* Configure variables
108    # to point to some temporary home, from which the executable gets
109    # installed by occult means.)
110    $pod2man = "$downdir/perl -I $downdir/lib $downdir/pod/pod2man --section=$manext --official";
111
112    mkpath($mandir, 1, 0777) unless $notify;  # In File::Path
113    # Make a list of all the .pm and .pod files in the directory.  We will
114    # always run pod2man from the lib directory and feed it the full pathname
115    # of the pod.  This might be useful for pod2man someday.
116    if ($script) {
117        @modpods = ($script);
118    } else {
119        @modpods = ();
120        find(\&lsmodpods, '.');
121    }
122    foreach $mod (@modpods) {
123        $manpage = $mod;
124        my $tmp;
125        # Skip .pm files that have corresponding .pod files, and Functions.pm.
126        next if (($tmp = $mod) =~ s/\.pm$/.pod/ && -f $tmp);
127        next if ($mod eq 'Pod/Functions.pm');   #### Used only by pod itself
128
129        # Convert name from  File/Basename.pm to File::Basename.3 format,
130        # if necessary.
131        $manpage =~ s#\.p(m|od)$##;
132        if ($^O eq 'os2' || $^O eq 'amigaos') {
133          $manpage =~ s#/#.#g;
134        } else {
135          $manpage =~ s#/#::#g;
136        }
137        $tmp = "${mandir}/${manpage}.tmp";
138        $manpage = "${mandir}/${manpage}.${manext}";
139        if (&cmd("$pod2man $mod > $tmp") == 0 && !$notify && -s $tmp) {
140            rename($tmp, $manpage) && next;
141        }
142        unless ($notify) {
143    unlink($tmp);
144        }
145    }
146    chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n";
147    print STDERR "chdir $builddir\n";
148}
149
150sub lsmodpods {
151    my $dir  = $File::Find::dir;
152    my $name = $File::Find::name;
153    if (-f $_) {
154        $name =~ s#^\./##;
155        push(@modpods, $name) if ($name =~ /\.p(m|od)$/);
156    }
157}
158
159print STDERR "  Installation complete\n";
160
161exit 0;
162   
163
164###############################################################################
165# Utility subroutines from installperl
166
167sub cmd {
168    local($cmd) = @_;
169    print STDERR "  $cmd\n";
170    unless ($notify) {
171        if ($Config{d_fork}) {
172            fork ? wait : exec $cmd;  # Allow user to ^C out of command.
173        }
174        else {
175            system $cmd;
176        }
177        warn "Command failed!!\n" if $?;
178    }
179    return $? != 0;
180}
181
182sub unlink {
183    local(@names) = @_;
184    my $cnt = 0;
185
186    foreach $name (@names) {
187next unless -e $name;
188chmod 0777, $name if $^O eq 'os2';
189print STDERR "  unlink $name\n";
190( CORE::unlink($name) and ++$cnt
191    or warn "Couldn't unlink $name: $!\n" ) unless $notify;
192    }
193    return $cnt;
194}
195
196sub link {
197    local($from,$to) = @_;
198
199    print STDERR "  ln $from $to\n";
200    eval { CORE::link($from,$to) }
201|| system('cp', $from, $to) == 0
202|| warn "Couldn't link $from to $to: $!\n" unless $notify;
203}
204
205sub rename {
206    local($from,$to) = @_;
207    if (-f $to and not unlink($to)) {
208my($i);
209for ($i = 1; $i < 50; $i++) {
210    last if CORE::rename($to, "$to.$i");
211}
212warn("Cannot rename to `$to.$i': $!"), return 0
213    if $i >= 50;        # Give up!
214    }
215    link($from,$to) || return 0;
216    unlink($from);
217}
218
219sub chmod {
220    local($mode,$name) = @_;
221
222    printf STDERR "  chmod %o %s\n", $mode, $name;
223    CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
224        unless $notify;
225}
226
227sub samepath {
228    local($p1, $p2) = @_;
229    local($dev1, $ino1, $dev2, $ino2);
230
231    if ($p1 ne $p2) {
232        ($dev1, $ino1) = stat($p1);
233        ($dev2, $ino2) = stat($p2);
234        ($dev1 == $dev2 && $ino1 == $ino2);
235    }
236    else {
237        1;
238    }
239}
Note: See TracBrowser for help on using the repository browser.