Commit | Line | Data |
---|---|---|
16d20bd9 AD |
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; | |
4633a7c4 | 30 | die $usage if $opt_help; |
16d20bd9 AD |
31 | |
32 | # These are written funny to avoid -w typo warnings. | |
33 | $man1dir = defined($opt_man1dir) ? $opt_man1dir : $Config{'installman1dir'}; | |
34 | $man1ext = defined($opt_man1ext) ? $opt_man1ext : $Config{'man1ext'}; | |
35 | $man3dir = defined($opt_man3dir) ? $opt_man3dir : $Config{'installman3dir'}; | |
36 | $man3ext = defined($opt_man3ext) ? $opt_man3ext : $Config{'man3ext'}; | |
37 | ||
38 | $notify = defined($opt_notify) ? $opt_notify : 0; | |
39 | ||
40 | #Sanity checks | |
41 | ||
42 | -x "./perl" || warn "./perl not found! Have you run make?\n"; | |
43 | -d $Config{'installprivlib'} | |
44 | || warn "Perl library directory $Config{'installprivlib'} not found. | |
45 | Have you run make install?. (Installing anyway.)\n"; | |
46 | -x 't/TEST' || warn "WARNING: You've never run 'make test'!!!", | |
47 | " (Installing anyway.)\n"; | |
48 | ||
49 | # Install the main pod pages. | |
50 | runpod2man('pod', $man1dir, $man1ext); | |
51 | ||
52 | # Install the pods for library modules. | |
53 | runpod2man('lib', $man3dir, $man3ext); | |
54 | ||
55 | sub runpod2man { | |
56 | my($poddir, $mandir, $manext) = @_; | |
57 | my($builddir) = Cwd::getcwd(); | |
58 | ||
59 | if ($mandir eq ' ' or $mandir eq '') { | |
60 | print STDERR "Skipping installation of $poddir man pages.\n"; | |
61 | return; | |
62 | } | |
63 | ||
64 | chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n"; | |
65 | ||
66 | # We insist on using the current version of pod2man in case there | |
67 | # are enhancements or changes from previous installed versions. | |
e50aee73 AD |
68 | # The error message doesn't include the '..' because the user |
69 | # won't be aware that we've chdir to $poddir. | |
70 | -x "../pod/pod2man" || die "Executable pod/pod2man not found.\n"; | |
71 | ||
72 | # We want to be sure to use the current perl. We can't rely on | |
73 | # the installed perl because it might not be actually installed | |
74 | # yet. (The user may have set the $install* Configure variables | |
75 | # to point to some temporary home, from which the executable gets | |
76 | # installed by occult means.) | |
cb1a09d0 | 77 | $pod2man = "../perl -I ../lib ../pod/pod2man --section=$manext --official"; |
16d20bd9 AD |
78 | |
79 | &makedir($mandir); | |
80 | # Make a list of all the .pm and .pod files in the directory. We will | |
81 | # always run pod2man from the lib directory and feed it the full pathname | |
82 | # of the pod. This might be useful for pod2man someday. | |
83 | @modpods = (); | |
84 | find(\&lsmodpods, '.'); | |
85 | foreach $mod (@modpods) { | |
86 | $manpage = $mod; | |
87 | # Convert name from File/Basename.pm to File::Basename.3 format, | |
88 | # if necessary. | |
89 | $manpage =~ s#\.p(m|od)$##; | |
90 | $manpage =~ s#/#::#g; | |
91 | $manpage = "${mandir}/${manpage}.${manext}"; | |
16d20bd9 | 92 | &cmd("$pod2man $mod > $manpage"); |
cb1a09d0 AD |
93 | if (-z $manpage) { |
94 | print STDERR "unlink $manpage\n"; | |
95 | unless ($notify) { | |
96 | unlink($manpage) || warn "cannot unlink $manpage: $!"; | |
97 | } | |
98 | } | |
16d20bd9 AD |
99 | } |
100 | chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n"; | |
101 | } | |
102 | ||
103 | sub lsmodpods { | |
104 | my $dir = $File::Find::dir; | |
105 | my $name = $File::Find::name; | |
106 | if (-f $_) { | |
107 | $name =~ s#^\./##; | |
108 | push(@modpods, $name) if ($name =~ /\.p(m|od)$/); | |
109 | } | |
110 | } | |
111 | ||
112 | print STDERR " Installation complete\n"; | |
113 | ||
114 | exit 0; | |
115 | ||
116 | ||
117 | ############################################################################### | |
118 | # Utility subroutines from installperl | |
119 | ||
120 | sub cmd { | |
121 | local($cmd) = @_; | |
122 | print STDERR " $cmd\n"; | |
123 | unless ($notify) { | |
cb1a09d0 AD |
124 | fork ? wait : exec $cmd; |
125 | warn "Command failed!!\n" if $?; | |
16d20bd9 | 126 | } |
cb1a09d0 | 127 | return $? != 0; |
16d20bd9 AD |
128 | } |
129 | ||
130 | sub link { | |
131 | local($from,$to) = @_; | |
132 | ||
133 | print STDERR " ln $from $to\n"; | |
134 | link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $notify; | |
135 | } | |
136 | ||
137 | sub chmod { | |
138 | local($mode,$name) = @_; | |
139 | ||
140 | printf STDERR " chmod %o %s\n", $mode, $name; | |
141 | chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name) | |
142 | unless $notify; | |
143 | } | |
144 | ||
145 | sub makedir { | |
146 | local($dir) = @_; | |
147 | unless (-d $dir) { | |
148 | local($shortdir) = $dir; | |
149 | ||
150 | $shortdir =~ s#(.*)/.*#$1#; | |
151 | &makedir($shortdir); | |
152 | ||
153 | print STDERR " mkdir $dir\n"; | |
154 | mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $notify; | |
155 | } | |
156 | } | |
157 | ||
158 | sub samepath { | |
159 | local($p1, $p2) = @_; | |
160 | local($dev1, $ino1, $dev2, $ino2); | |
161 | ||
162 | if ($p1 ne $p2) { | |
163 | ($dev1, $ino1) = stat($p1); | |
164 | ($dev2, $ino2) = stat($p2); | |
165 | ($dev1 == $dev2 && $ino1 == $ino2); | |
166 | } | |
167 | else { | |
168 | 1; | |
169 | } | |
170 | } |