Commit | Line | Data |
c623bd54 |
1 | #!./perl |
a0d0e21e |
2 | BEGIN { @INC=('./lib', '../lib') } |
a0d0e21e |
3 | use File::Find; |
c623bd54 |
4 | |
bee1dbe2 |
5 | $mainperldir = "/usr/bin"; |
6 | |
c623bd54 |
7 | while (@ARGV) { |
8 | $nonono = 1 if $ARGV[0] eq '-n'; |
9 | $versiononly = 1 if $ARGV[0] eq '-v'; |
10 | shift; |
11 | } |
12 | |
45d8adaa |
13 | umask 022; |
14 | |
a0d0e21e |
15 | @scripts = ('cppstdin', 'c2ph', 'pstruct', 'x2p/s2p', 'x2p/find2perl'); |
16 | @manpages = (<pod/*.man>, 'x2p/a2p.man', 'x2p/s2p.man'); |
c623bd54 |
17 | |
18 | # Read in the config file. |
19 | |
20 | open(CONFIG, "config.sh") || die "You haven't run Configure yet!\n"; |
21 | while (<CONFIG>) { |
22 | if (s/^(\w+=)/\$$1/) { |
23 | $accum =~ s/'undef'/undef/g; |
24 | eval $accum; |
25 | $accum = ''; |
26 | } |
27 | $accum .= $_; |
28 | } |
bee1dbe2 |
29 | close CONFIG; |
30 | |
ecfc5424 |
31 | $ver = sprintf("%5.3f", $] + 0); |
bee1dbe2 |
32 | $release = substr($ver,0,3); |
33 | $patchlevel = substr($ver,3,2); |
c623bd54 |
34 | |
35 | # Do some quick sanity checks. |
36 | |
37 | if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; } |
38 | |
fe14fcc3 |
39 | $installbin || die "No installbin directory in config.sh\n"; |
40 | -d $installbin || die "$installbin is not a directory\n"; |
41 | -w $installbin || die "$installbin is not writable by you\n" |
3edbfbe5 |
42 | unless $installbin =~ m#^/afs/# || $nonono; |
c623bd54 |
43 | |
fe14fcc3 |
44 | -x 'perl' || die "perl isn't executable!\n"; |
fe14fcc3 |
45 | -x 'suidperl' || die "suidperl isn't executable!\n" if $d_dosuid; |
c623bd54 |
46 | |
fe14fcc3 |
47 | -x 't/TEST' || warn "WARNING: You've never run 'make test'!!!", |
48 | " (Installing anyway.)\n"; |
c623bd54 |
49 | |
ecfc5424 |
50 | if ($d_shrplib) { |
51 | if (!<libperl*.$so*>) { |
52 | warn "WARNING: Can't find libperl*.$so* to install into $shrpdir.", |
53 | " (Installing other things anyway.)\n"; |
54 | } else { |
55 | &makedir($shrpdir); |
56 | -w $shrpdir || die "$shrpdir is not writable by you\n"; |
57 | &cmd("cp libperl*.$so* $shrpdir"); |
58 | } |
59 | } |
60 | |
c623bd54 |
61 | # First we install the version-numbered executables. |
62 | |
fe14fcc3 |
63 | &unlink("$installbin/perl$ver"); |
64 | &cmd("cp perl $installbin/perl$ver"); |
c623bd54 |
65 | |
fe14fcc3 |
66 | &unlink("$installbin/sperl$ver"); |
c623bd54 |
67 | if ($d_dosuid) { |
fe14fcc3 |
68 | &cmd("cp suidperl $installbin/sperl$ver"); |
69 | &chmod(04711, "$installbin/sperl$ver"); |
c623bd54 |
70 | } |
71 | |
72 | exit 0 if $versiononly; |
73 | |
fe14fcc3 |
74 | # Make links to ordinary names if installbin directory isn't current directory. |
c623bd54 |
75 | |
ecfc5424 |
76 | if (! &samepath($installbin, '.')) { |
85e6fe83 |
77 | &unlink("$installbin/perl", "$installbin/suidperl"); |
fe14fcc3 |
78 | &link("$installbin/perl$ver", "$installbin/perl"); |
fe14fcc3 |
79 | &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid; |
c623bd54 |
80 | } |
81 | |
ecfc5424 |
82 | if (! &samepath($installbin, 'x2p')) { |
352d5a3a |
83 | &unlink("$installbin/a2p"); |
84 | &cmd("cp x2p/a2p $installbin/a2p"); |
bee1dbe2 |
85 | &chmod(0755, "$installbin/a2p"); |
352d5a3a |
86 | } |
87 | |
c623bd54 |
88 | # Install scripts. |
89 | |
a0d0e21e |
90 | &makedir($installscript); |
c623bd54 |
91 | |
92 | for (@scripts) { |
a0d0e21e |
93 | if (-f $_) { # cppstdin might not exist on this system. |
94 | &cmd("cp $_ $installscript"); |
95 | s#.*/##; &chmod(0755, "$installscript/$_"); |
96 | } |
c623bd54 |
97 | } |
98 | |
c623bd54 |
99 | # Install man pages. |
100 | |
a0d0e21e |
101 | if ($installmansrc ne '') { |
102 | &makedir($installmansrc); |
fe14fcc3 |
103 | |
ecfc5424 |
104 | if (! &samepath($installmansrc, '.')) { |
fe14fcc3 |
105 | for (@manpages) { |
106 | ($new = $_) =~ s/man$/$manext/; |
352d5a3a |
107 | $new =~ s#.*/##; |
a0d0e21e |
108 | print STDERR " Installing $installmansrc/$new\n"; |
fe14fcc3 |
109 | next if $nonono; |
bee1dbe2 |
110 | open(MI,$_) || warn "Can't open $_: $!\n"; |
a0d0e21e |
111 | open(MO,">$installmansrc/$new") || warn "Can't install $installmansrc/$new: $!\n"; |
fe14fcc3 |
112 | print MO ".ds RP Release $release Patchlevel $patchlevel\n"; |
113 | while (<MI>) { |
114 | print MO; |
115 | } |
116 | close MI; |
117 | close MO; |
118 | } |
c623bd54 |
119 | } |
120 | } |
121 | |
45d8adaa |
122 | # Install library files. |
123 | |
a0d0e21e |
124 | $do_installarchlib = $do_installprivlib = 0; |
125 | |
45d8adaa |
126 | &makedir($installprivlib); |
a0d0e21e |
127 | &makedir($installarchlib); |
45d8adaa |
128 | if (chdir "lib") { |
ecfc5424 |
129 | $do_installarchlib = ! &samepath($installarchlib, '.'); |
130 | $do_installprivlib = ! &samepath($installprivlib, '.'); |
45d8adaa |
131 | |
a0d0e21e |
132 | if ($do_installarchlib || $do_installprivlib) { |
133 | find(\&installlib, '.'); |
45d8adaa |
134 | } |
135 | chdir ".." || die "Can't cd back to source directory: $!\n"; |
136 | } |
137 | else { |
138 | warn "Can't cd to lib to install lib files: $!\n"; |
139 | } |
140 | |
1aef975c |
141 | # Install header files and libraries. |
3edbfbe5 |
142 | makedir("$installarchlib/CORE"); |
75f92628 |
143 | foreach $file (<*.h libperl*.*>) { |
3edbfbe5 |
144 | cp_if_diff($file,"$installarchlib/CORE/$file"); |
1aef975c |
145 | if ($file =~ /\.a$/ && $osname eq 'next') { |
75f92628 |
146 | #on NeXTs we have to rerun ranlib after copying libraries |
1aef975c |
147 | &cmd("$ranlib $installarchlib/CORE/$file"); |
75f92628 |
148 | } |
3edbfbe5 |
149 | } |
1aef975c |
150 | # AIX needs perl.exp installed as well. |
151 | cp_if_diff("perl.exp" ,"$installarchlib/CORE/perl.exp") if ($osname eq 'aix'); |
152 | |
3edbfbe5 |
153 | |
a0d0e21e |
154 | # Offer to install perl in a "standard" location |
155 | |
a0d0e21e |
156 | $mainperl_is_instperl = 0; |
157 | |
ecfc5424 |
158 | if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) { |
a0d0e21e |
159 | # First make sure $mainperldir/perl is not already the same as |
160 | # the perl we just installed |
161 | if (-x "$mainperldir/perl") { |
a0d0e21e |
162 | # Try to be clever about mainperl being a symbolic link |
163 | # to binexp/perl if binexp and installbin are different. |
164 | $mainperl_is_instperl = |
ecfc5424 |
165 | &samepath("$mainperldir/perl", "$installbin/perl") || |
a0d0e21e |
166 | (($binexp ne $installbin) && |
167 | (-l "$mainperldir/perl") && |
ecfc5424 |
168 | ((readlink "$mainperldir/perl") eq "$binexp/perl")); |
a0d0e21e |
169 | } |
170 | if ((! $mainperl_is_instperl) && |
171 | (&yn("Many scripts expect perl to be installed as " . |
172 | "$mainperldir/perl.\n" . |
173 | "Do you wish to have $mainperldir/perl be the same as\n" . |
174 | "$binexp/perl? [y] "))) |
175 | { |
176 | unlink("$mainperldir/perl"); |
177 | eval 'link("$installbin/perl", "$mainperldir/perl")' || |
178 | eval 'symlink("$binexp/perl", "$mainperldir/perl")' || |
179 | &cmd("cp $installbin/perl $mainperldir"); |
180 | $mainperl_is_instperl = 1; |
181 | } |
182 | } |
183 | |
184 | # Check to make sure there aren't other perls around in installer's |
185 | # path. This is probably UNIX-specific. Check all absolute directories |
186 | # in the path except for where public executables are supposed to live. |
187 | # Also skip $mainperl if the user opted to have it be a link to the |
188 | # installed perl. |
189 | |
190 | @path = split(/:/, $ENV{"PATH"}); |
191 | @otherperls = (); |
192 | for (@path) { |
193 | next unless m,^/,; |
194 | next if ($_ eq $binexp); |
195 | # Use &samepath here because some systems have other dirs linked |
196 | # to $mainperldir (like SunOS) |
197 | next if ($mainperl_is_instperl && &samepath($_, $mainperldir)); |
198 | push(@otherperls, "$_/perl") if (-x "$_/perl" && ! -d "$_/perl"); |
199 | } |
200 | if (@otherperls) { |
201 | print STDERR "\nWarning: perl appears in your path in the following " . |
202 | "locations beyond where\nwe just installed it:\n"; |
203 | for (@otherperls) { |
204 | print STDERR " ", $_, "\n"; |
205 | } |
206 | print STDERR "\n"; |
207 | } |
208 | |
c623bd54 |
209 | print STDERR " Installation complete\n"; |
210 | |
211 | exit 0; |
212 | |
213 | ############################################################################### |
214 | |
a0d0e21e |
215 | sub yn { |
216 | local($prompt) = @_; |
217 | local($answer); |
218 | local($default) = $prompt =~ m/\[([yn])\]\s*$/i; |
219 | print STDERR $prompt; |
220 | chop($answer = <STDIN>); |
221 | $answer = $default if $answer =~ m/^\s*$/; |
222 | ($answer =~ m/^[yY]/); |
223 | } |
224 | |
c623bd54 |
225 | sub unlink { |
226 | local(@names) = @_; |
227 | |
228 | foreach $name (@names) { |
229 | next unless -e $name; |
230 | print STDERR " unlink $name\n"; |
231 | unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono; |
232 | } |
233 | } |
234 | |
235 | sub cmd { |
236 | local($cmd) = @_; |
237 | print STDERR " $cmd\n"; |
238 | unless ($nonono) { |
239 | system $cmd; |
240 | warn "Command failed!!!\n" if $?; |
241 | } |
242 | } |
243 | |
244 | sub link { |
245 | local($from,$to) = @_; |
246 | |
247 | print STDERR " ln $from $to\n"; |
248 | link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono; |
249 | } |
250 | |
251 | sub chmod { |
252 | local($mode,$name) = @_; |
253 | |
254 | printf STDERR " chmod %o %s\n", $mode, $name; |
514dae0d |
255 | chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name) |
c623bd54 |
256 | unless $nonono; |
257 | } |
258 | |
259 | sub makedir { |
260 | local($dir) = @_; |
261 | unless (-d $dir) { |
262 | local($shortdir) = $dir; |
263 | |
264 | $shortdir =~ s#(.*)/.*#$1#; |
265 | &makedir($shortdir); |
266 | |
267 | print STDERR " mkdir $dir\n"; |
268 | mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono; |
269 | } |
270 | } |
a0d0e21e |
271 | |
272 | sub samepath { |
273 | local($p1, $p2) = @_; |
274 | local($dev1, $ino1, $dev2, $ino2); |
275 | |
75f92628 |
276 | if ($p1 ne $p2) { |
a0d0e21e |
277 | ($dev1, $ino1) = stat($p1); |
278 | ($dev2, $ino2) = stat($p2); |
279 | ($dev1 == $dev2 && $ino1 == $ino2); |
280 | } |
281 | else { |
282 | 1; |
283 | } |
284 | } |
285 | |
286 | sub installlib { |
287 | my $dir = $File::Find::dir; |
288 | $dir =~ s#^\.(?![^/])/?##; |
289 | |
290 | my $name = $_; |
291 | $name = "$dir/$name" if $dir ne ''; |
292 | |
293 | my $installlib = $installprivlib; |
294 | if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) { |
295 | $installlib = $installarchlib; |
296 | return unless $do_installarchlib; |
297 | } else { |
298 | return unless $do_installprivlib; |
299 | } |
300 | |
a0d0e21e |
301 | if (-f $_) { |
3edbfbe5 |
302 | if (/\.al$/ || /\.ix$/) { |
303 | $installlib = $installprivlib; |
304 | #We're installing *.al and *.ix files into $installprivlib, |
305 | #but we have to delete old *.al and *.ix files from the 5.000 |
306 | #distribution: |
75f92628 |
307 | #This might not work because $archname might have changed. |
3edbfbe5 |
308 | &unlink("$installarchlib/$name"); |
309 | } |
a0d0e21e |
310 | system "cmp", "-s", $_, "$installlib/$name"; |
311 | if ($?) { |
312 | &unlink("$installlib/$name"); |
3edbfbe5 |
313 | &makedir("$installlib/$dir"); |
a0d0e21e |
314 | &cmd("cp $_ $installlib/$dir"); |
1aef975c |
315 | if (/\.a$/ && $osname eq 'next') { |
75f92628 |
316 | #on NeXTs we have to rerun ranlib after copying libraries |
1aef975c |
317 | &cmd("$ranlib $installlib/$dir/$_"); |
75f92628 |
318 | } |
319 | # HP-UX (at least) needs to maintain execute permissions |
320 | # on dynamically-loaded libraries. |
321 | &chmod(0644, "$installlib/$name") |
322 | unless (/\.$so$/ || /\.$dlext$/); |
a0d0e21e |
323 | } |
324 | } elsif (-d $_) { |
325 | &makedir("$installlib/$name"); |
326 | } |
327 | } |
3edbfbe5 |
328 | |
329 | sub cp_if_diff { |
330 | my($from,$to)=@_; |
331 | -f $from || die "$0: $from not found"; |
332 | system "cmp", "-s", $from, $to; |
333 | if ($?) { |
334 | cmd("cp $from $to"); |
335 | } |
336 | } |