This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Updated to version 1.20.
[perl5.git] / installman
1 #!./perl
2 BEGIN { @INC = ('lib') }
3 use Config;
4 use Getopt::Long;
5 use File::Find;
6 use File::Path qw(mkpath);
7 require Cwd;
8
9 umask 022;
10
11 $ver = $];
12 $release = substr($ver,0,3);   # Not used presently.
13 $patchlevel = substr($ver,3,2);
14 die "Patchlevel of perl ($patchlevel)",
15     "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
16         if $patchlevel != $Config{'PATCHLEVEL'};
17
18 $usage =
19 "Usage:  installman --man1dir=/usr/wherever --man1ext=1
20                     --man3dir=/usr/wherever --man3ext=3
21                     --notify --help
22         Defaults are:
23         man1dir = $Config{'installman1dir'};
24         man1ext = $Config{'man1ext'};
25         man3dir = $Config{'installman3dir'};
26         man3ext = $Config{'man3ext'};
27         --notify (or -n) just lists commands that would be executed.\n";
28
29 GetOptions( qw( man1dir=s man1ext=s man3dir=s man3ext=s notify n help)) 
30         || die $usage;
31 die $usage if $opt_help;
32
33 # These are written funny to avoid -w typo warnings.
34 $man1dir = defined($opt_man1dir) ? $opt_man1dir : $Config{'installman1dir'};
35 $man1ext = defined($opt_man1ext) ? $opt_man1ext : $Config{'man1ext'};
36 $man3dir = defined($opt_man3dir) ? $opt_man3dir : $Config{'installman3dir'};
37 $man3ext = defined($opt_man3ext) ? $opt_man3ext : $Config{'man3ext'};
38
39 $notify = $opt_notify || $opt_n;
40
41 #Sanity checks
42
43 -x  "./perl"    || warn "./perl not found!  Have you run make?\n";
44 -d  $Config{'installprivlib'}
45         || warn "Perl library directory $Config{'installprivlib'} not found.
46                 Have you run make install?.  (Installing anyway.)\n";
47 -x 't/TEST'             || warn "WARNING: You've never run 'make test'!!!",
48         "  (Installing anyway.)\n";
49
50 # Install the main pod pages.
51 runpod2man('pod', $man1dir, $man1ext);
52
53 # Install the pods for library modules.
54 runpod2man('lib', $man3dir, $man3ext);
55
56 sub runpod2man {
57     my($poddir, $mandir, $manext) = @_;
58     my($builddir) = Cwd::getcwd();
59
60     if ($mandir eq ' ' or $mandir eq '') {
61         print STDERR "Skipping installation of $poddir man pages.\n";
62         return;
63     }
64
65     chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n";
66
67     # We insist on using the current version of pod2man in case there
68     # are enhancements or changes from previous installed versions.
69     # The error message doesn't include the '..' because the user
70     # won't be aware that we've chdir to $poddir.
71     -x  "../pod/pod2man" || die "Executable pod/pod2man not found.\n";
72
73     # We want to be sure to use the current perl.  We can't rely on
74     # the installed perl because it might not be actually installed
75     # yet. (The user may have set the $install* Configure variables 
76     # to point to some temporary home, from which the executable gets
77     # installed by occult means.)
78     $pod2man = "../perl -I ../lib ../pod/pod2man --section=$manext --official";
79
80     mkpath($mandir, 1, 0777);  # In File::Path
81     # Make a list of all the .pm and .pod files in the directory.  We will
82     # always run pod2man from the lib directory and feed it the full pathname
83     # of the pod.  This might be useful for pod2man someday.
84     @modpods = ();
85     find(\&lsmodpods, '.');
86     foreach $mod (@modpods) {
87         $manpage = $mod;
88         # Convert name from  File/Basename.pm to File::Basename.3 format,
89         # if necessary.
90         $manpage =~ s#\.p(m|od)$##;
91         $manpage =~ s#/#::#g;
92         $manpage = "${mandir}/${manpage}.${manext}";
93         &cmd("$pod2man $mod > $manpage");
94         if (-z $manpage) {
95             print STDERR "unlink $manpage\n";
96             unless ($notify) {
97                 unlink($manpage) || warn "cannot unlink $manpage: $!";
98             } 
99         } 
100     }
101     chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n";
102 }
103
104 sub lsmodpods {
105     my $dir  = $File::Find::dir;
106     my $name = $File::Find::name;
107     if (-f $_) {
108         $name =~ s#^\./##;
109         push(@modpods, $name) if ($name =~ /\.p(m|od)$/);
110     }
111 }
112
113 print STDERR "  Installation complete\n";
114
115 exit 0;
116     
117
118 ###############################################################################
119 # Utility subroutines from installperl
120
121 sub cmd {
122     local($cmd) = @_;
123     print STDERR "  $cmd\n";
124     unless ($notify) {
125         if ($Config{d_fork}) {
126             fork ? wait : exec $cmd;  # Allow user to ^C out of command.
127         }
128         else {
129             system $cmd;
130         }
131         warn "Command failed!!\n" if $?;
132     }
133     return $? != 0;
134 }
135
136 sub link {
137     local($from,$to) = @_;
138
139     print STDERR "  ln $from $to\n";
140     link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $notify;
141 }
142
143 sub chmod {
144     local($mode,$name) = @_;
145
146     printf STDERR "  chmod %o %s\n", $mode, $name;
147     chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
148         unless $notify;
149 }
150
151 sub samepath {
152     local($p1, $p2) = @_;
153     local($dev1, $ino1, $dev2, $ino2);
154
155     if ($p1 ne $p2) {
156         ($dev1, $ino1) = stat($p1);
157         ($dev2, $ino2) = stat($p2);
158         ($dev1 == $dev2 && $ino1 == $ino2);
159     }
160     else {
161         1;
162     }
163 }