This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add hints for new users, and miscellaneous updates from Andy Dougherty
[perl5.git] / installman
CommitLineData
16d20bd9
AD
1#!./perl
2BEGIN { @INC = ('lib') }
3use Config;
4use Getopt::Long;
5use File::Find;
356fc125 6use File::Path qw(mkpath);
16d20bd9
AD
7require Cwd;
8
9umask 022;
10
11$ver = $];
12$release = substr($ver,0,3); # Not used presently.
13$patchlevel = substr($ver,3,2);
14die "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
c07a80fd 29GetOptions( qw( man1dir=s man1ext=s man3dir=s man3ext=s notify n help))
16d20bd9 30 || die $usage;
4633a7c4 31die $usage if $opt_help;
16d20bd9
AD
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
c07a80fd 39$notify = $opt_notify || $opt_n;
16d20bd9
AD
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.
51runpod2man('pod', $man1dir, $man1ext);
52
53# Install the pods for library modules.
54runpod2man('lib', $man3dir, $man3ext);
55
56sub 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.
e50aee73
AD
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.)
cb1a09d0 78 $pod2man = "../perl -I ../lib ../pod/pod2man --section=$manext --official";
16d20bd9 79
356fc125 80 mkpath($mandir, 1, 0777); # In File::Path
16d20bd9
AD
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}";
6d64b06f
HF
93 &cmd("$pod2man $mod > $manpage.tmp");
94 if (-s "$manpage.tmp") {
95 rename("$manpage.tmp", $manpage) && next;
96 warn "cannot rename to $manpage: $!";
97 }
98 print STDERR "unlink $manpage.tmp\n";
99 unless ($notify) {
100 unlink("$manpage.tmp") || warn "cannot unlink $manpage.tmp: $!";
101 }
16d20bd9
AD
102 }
103 chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n";
104}
105
106sub lsmodpods {
107 my $dir = $File::Find::dir;
108 my $name = $File::Find::name;
109 if (-f $_) {
110 $name =~ s#^\./##;
111 push(@modpods, $name) if ($name =~ /\.p(m|od)$/);
112 }
113}
114
115print STDERR " Installation complete\n";
116
117exit 0;
118
119
120###############################################################################
121# Utility subroutines from installperl
122
123sub cmd {
124 local($cmd) = @_;
125 print STDERR " $cmd\n";
126 unless ($notify) {
b29d8d13
PP
127 if ($Config{d_fork}) {
128 fork ? wait : exec $cmd; # Allow user to ^C out of command.
129 }
130 else {
131 system $cmd;
132 }
cb1a09d0 133 warn "Command failed!!\n" if $?;
16d20bd9 134 }
cb1a09d0 135 return $? != 0;
16d20bd9
AD
136}
137
138sub link {
139 local($from,$to) = @_;
140
141 print STDERR " ln $from $to\n";
142 link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $notify;
143}
144
145sub chmod {
146 local($mode,$name) = @_;
147
148 printf STDERR " chmod %o %s\n", $mode, $name;
149 chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
150 unless $notify;
151}
152
16d20bd9
AD
153sub samepath {
154 local($p1, $p2) = @_;
155 local($dev1, $ino1, $dev2, $ino2);
156
157 if ($p1 ne $p2) {
158 ($dev1, $ino1) = stat($p1);
159 ($dev2, $ino2) = stat($p2);
160 ($dev1 == $dev2 && $ino1 == $ino2);
161 }
162 else {
163 1;
164 }
165}