Commit | Line | Data |
16d20bd9 |
1 | #!./perl |
2 | BEGIN { @INC = ('lib') } |
3 | use Config; |
4 | use Getopt::Long; |
5 | use File::Find; |
356fc125 |
6 | use File::Path qw(mkpath); |
16d20bd9 |
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 help)) |
30 | || die $usage; |
4633a7c4 |
31 | die $usage if $opt_help; |
16d20bd9 |
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 = defined($opt_notify) ? $opt_notify : 0; |
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. |
e50aee73 |
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 |
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}"; |
16d20bd9 |
93 | &cmd("$pod2man $mod > $manpage"); |
cb1a09d0 |
94 | if (-z $manpage) { |
95 | print STDERR "unlink $manpage\n"; |
96 | unless ($notify) { |
97 | unlink($manpage) || warn "cannot unlink $manpage: $!"; |
98 | } |
99 | } |
16d20bd9 |
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) { |
b29d8d13 |
125 | if ($Config{d_fork}) { |
126 | fork ? wait : exec $cmd; # Allow user to ^C out of command. |
127 | } |
128 | else { |
129 | system $cmd; |
130 | } |
cb1a09d0 |
131 | warn "Command failed!!\n" if $?; |
16d20bd9 |
132 | } |
cb1a09d0 |
133 | return $? != 0; |
16d20bd9 |
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 | |
16d20bd9 |
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 | } |