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