Commit | Line | Data |
---|---|---|
c623bd54 | 1 | #!./perl |
a0d0e21e | 2 | BEGIN { @INC=('./lib', '../lib') } |
a0d0e21e | 3 | use File::Find; |
4633a7c4 | 4 | use Config; |
c623bd54 | 5 | |
bee1dbe2 LW |
6 | $mainperldir = "/usr/bin"; |
7 | ||
c623bd54 LW |
8 | while (@ARGV) { |
9 | $nonono = 1 if $ARGV[0] eq '-n'; | |
10 | $versiononly = 1 if $ARGV[0] eq '-v'; | |
11 | shift; | |
12 | } | |
13 | ||
45d8adaa LW |
14 | umask 022; |
15 | ||
4633a7c4 LW |
16 | @scripts = ('cppstdin', 'c2ph', 'h2ph', 'h2xs', 'pstruct', |
17 | 'x2p/s2p', 'x2p/find2perl', | |
18 | 'perldoc', | |
19 | 'pod/pod2man', 'pod/pod2html', 'pod/pod2latex' ); | |
16d20bd9 AD |
20 | |
21 | # pod documentation now handled by separate installman script. | |
22 | # These two are archaic leftovers. | |
23 | @manpages = ('x2p/a2p.man', 'x2p/s2p.man'); | |
24 | ||
25 | @pods = (<pod/*.pod>); | |
c623bd54 | 26 | |
748a9306 | 27 | $ver = $]; |
4633a7c4 | 28 | $release = substr($ver,0,3); # Not used presently. |
bee1dbe2 | 29 | $patchlevel = substr($ver,3,2); |
748a9306 | 30 | die "Patchlevel of perl ($patchlevel)", |
4633a7c4 LW |
31 | "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n" |
32 | if $patchlevel != $Config{'PATCHLEVEL'}; | |
33 | ||
34 | # Fetch some frequently-used items from %Config | |
35 | $installbin = $Config{installbin}; | |
36 | $installscript = $Config{installscript}; | |
37 | $installprivlib = $Config{installprivlib}; | |
38 | $installarchlib = $Config{installarchlib}; | |
39 | $installsitelib = $Config{installsitelib}; | |
40 | $installsitearch = $Config{installsitearch}; | |
41 | $installman1dir = $Config{installman1dir}; | |
42 | $man1ext = $Config{man1ext}; | |
43 | # Did we build libperl as a shared library? | |
44 | $d_shrplib = $Config{d_shrplib}; | |
45 | $shrpdir = $Config{shrpdir}; | |
46 | # Shared library and dynamic loading suffixes. | |
47 | $so = $Config{so}; | |
48 | $dlext = $Config{dlext}; | |
49 | ||
50 | $d_dosuid = $Config{d_dosuid}; | |
51 | $binexp = $Config{binexp}; | |
52 | $osname = $Config{osname}; | |
c623bd54 LW |
53 | |
54 | # Do some quick sanity checks. | |
55 | ||
56 | if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; } | |
57 | ||
fe14fcc3 | 58 | $installbin || die "No installbin directory in config.sh\n"; |
4633a7c4 | 59 | -d $installbin || makedir($installbin); |
fe14fcc3 LW |
60 | -d $installbin || die "$installbin is not a directory\n"; |
61 | -w $installbin || die "$installbin is not writable by you\n" | |
3edbfbe5 | 62 | unless $installbin =~ m#^/afs/# || $nonono; |
c623bd54 | 63 | |
fe14fcc3 | 64 | -x 'perl' || die "perl isn't executable!\n"; |
fe14fcc3 | 65 | -x 'suidperl' || die "suidperl isn't executable!\n" if $d_dosuid; |
c623bd54 | 66 | |
fe14fcc3 LW |
67 | -x 't/TEST' || warn "WARNING: You've never run 'make test'!!!", |
68 | " (Installing anyway.)\n"; | |
c623bd54 | 69 | |
ecfc5424 AD |
70 | if ($d_shrplib) { |
71 | if (!<libperl*.$so*>) { | |
72 | warn "WARNING: Can't find libperl*.$so* to install into $shrpdir.", | |
73 | " (Installing other things anyway.)\n"; | |
74 | } else { | |
75 | &makedir($shrpdir); | |
76 | -w $shrpdir || die "$shrpdir is not writable by you\n"; | |
77 | &cmd("cp libperl*.$so* $shrpdir"); | |
78 | } | |
79 | } | |
80 | ||
c623bd54 LW |
81 | # First we install the version-numbered executables. |
82 | ||
e50aee73 | 83 | &safe_unlink("$installbin/perl$ver"); |
fe14fcc3 | 84 | &cmd("cp perl $installbin/perl$ver"); |
c623bd54 | 85 | |
e50aee73 | 86 | &safe_unlink("$installbin/sperl$ver"); |
c623bd54 | 87 | if ($d_dosuid) { |
fe14fcc3 LW |
88 | &cmd("cp suidperl $installbin/sperl$ver"); |
89 | &chmod(04711, "$installbin/sperl$ver"); | |
c623bd54 LW |
90 | } |
91 | ||
92 | exit 0 if $versiononly; | |
93 | ||
fe14fcc3 | 94 | # Make links to ordinary names if installbin directory isn't current directory. |
c623bd54 | 95 | |
ecfc5424 | 96 | if (! &samepath($installbin, '.')) { |
e50aee73 | 97 | &safe_unlink("$installbin/perl", "$installbin/suidperl"); |
fe14fcc3 | 98 | &link("$installbin/perl$ver", "$installbin/perl"); |
fe14fcc3 | 99 | &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid; |
c623bd54 LW |
100 | } |
101 | ||
ecfc5424 | 102 | if (! &samepath($installbin, 'x2p')) { |
e50aee73 | 103 | &safe_unlink("$installbin/a2p"); |
352d5a3a | 104 | &cmd("cp x2p/a2p $installbin/a2p"); |
bee1dbe2 | 105 | &chmod(0755, "$installbin/a2p"); |
352d5a3a LW |
106 | } |
107 | ||
c623bd54 LW |
108 | # Install scripts. |
109 | ||
a0d0e21e | 110 | &makedir($installscript); |
c623bd54 LW |
111 | |
112 | for (@scripts) { | |
a0d0e21e LW |
113 | if (-f $_) { # cppstdin might not exist on this system. |
114 | &cmd("cp $_ $installscript"); | |
115 | s#.*/##; &chmod(0755, "$installscript/$_"); | |
116 | } | |
c623bd54 LW |
117 | } |
118 | ||
16d20bd9 AD |
119 | # Install pod pages. Where? I guess in $installprivlib/pod. |
120 | &makedir("${installprivlib}/pod"); | |
121 | foreach $file (@pods) { | |
122 | # $file is a name like pod/perl.pod | |
123 | cp_if_diff($file, "${installprivlib}/${file}"); | |
124 | } | |
125 | ||
126 | # Install old man pages. | |
c623bd54 | 127 | |
16d20bd9 AD |
128 | if ($installman1dir ne '') { |
129 | &makedir($installman1dir); | |
fe14fcc3 | 130 | |
16d20bd9 | 131 | if (! &samepath($installman1dir, '.')) { |
fe14fcc3 | 132 | for (@manpages) { |
16d20bd9 | 133 | ($new = $_) =~ s/man$/$man1ext/; |
352d5a3a | 134 | $new =~ s#.*/##; |
16d20bd9 | 135 | print STDERR " Installing $installman1dir/$new\n"; |
fe14fcc3 | 136 | next if $nonono; |
bee1dbe2 | 137 | open(MI,$_) || warn "Can't open $_: $!\n"; |
16d20bd9 AD |
138 | open(MO,">$installman1dir/$new") || |
139 | warn "Can't install $installman1dir/$new: $!\n"; | |
fe14fcc3 LW |
140 | print MO ".ds RP Release $release Patchlevel $patchlevel\n"; |
141 | while (<MI>) { | |
142 | print MO; | |
143 | } | |
144 | close MI; | |
145 | close MO; | |
146 | } | |
c623bd54 LW |
147 | } |
148 | } | |
149 | ||
45d8adaa LW |
150 | # Install library files. |
151 | ||
a0d0e21e LW |
152 | $do_installarchlib = $do_installprivlib = 0; |
153 | ||
45d8adaa | 154 | &makedir($installprivlib); |
a0d0e21e | 155 | &makedir($installarchlib); |
4633a7c4 LW |
156 | &makedir($installsitelib) if ($installsitelib); |
157 | &makedir($installsitearch) if ($installsitearch); | |
158 | ||
45d8adaa | 159 | if (chdir "lib") { |
ecfc5424 AD |
160 | $do_installarchlib = ! &samepath($installarchlib, '.'); |
161 | $do_installprivlib = ! &samepath($installprivlib, '.'); | |
45d8adaa | 162 | |
a0d0e21e LW |
163 | if ($do_installarchlib || $do_installprivlib) { |
164 | find(\&installlib, '.'); | |
45d8adaa LW |
165 | } |
166 | chdir ".." || die "Can't cd back to source directory: $!\n"; | |
167 | } | |
168 | else { | |
169 | warn "Can't cd to lib to install lib files: $!\n"; | |
170 | } | |
171 | ||
1aef975c | 172 | # Install header files and libraries. |
3edbfbe5 | 173 | makedir("$installarchlib/CORE"); |
75f92628 | 174 | foreach $file (<*.h libperl*.*>) { |
3edbfbe5 TB |
175 | cp_if_diff($file,"$installarchlib/CORE/$file"); |
176 | } | |
1aef975c AD |
177 | # AIX needs perl.exp installed as well. |
178 | cp_if_diff("perl.exp" ,"$installarchlib/CORE/perl.exp") if ($osname eq 'aix'); | |
179 | ||
fed7345c AD |
180 | # If they have built sperl.o... |
181 | cp_if_diff("sperl.o" ,"$installarchlib/CORE/sperl.o") if (-f 'sperl.o'); | |
182 | ||
3edbfbe5 | 183 | |
a0d0e21e LW |
184 | # Offer to install perl in a "standard" location |
185 | ||
a0d0e21e LW |
186 | $mainperl_is_instperl = 0; |
187 | ||
ecfc5424 | 188 | if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) { |
a0d0e21e LW |
189 | # First make sure $mainperldir/perl is not already the same as |
190 | # the perl we just installed | |
191 | if (-x "$mainperldir/perl") { | |
a0d0e21e LW |
192 | # Try to be clever about mainperl being a symbolic link |
193 | # to binexp/perl if binexp and installbin are different. | |
194 | $mainperl_is_instperl = | |
ecfc5424 | 195 | &samepath("$mainperldir/perl", "$installbin/perl") || |
a0d0e21e LW |
196 | (($binexp ne $installbin) && |
197 | (-l "$mainperldir/perl") && | |
ecfc5424 | 198 | ((readlink "$mainperldir/perl") eq "$binexp/perl")); |
a0d0e21e LW |
199 | } |
200 | if ((! $mainperl_is_instperl) && | |
201 | (&yn("Many scripts expect perl to be installed as " . | |
202 | "$mainperldir/perl.\n" . | |
203 | "Do you wish to have $mainperldir/perl be the same as\n" . | |
204 | "$binexp/perl? [y] "))) | |
205 | { | |
206 | unlink("$mainperldir/perl"); | |
207 | eval 'link("$installbin/perl", "$mainperldir/perl")' || | |
208 | eval 'symlink("$binexp/perl", "$mainperldir/perl")' || | |
209 | &cmd("cp $installbin/perl $mainperldir"); | |
210 | $mainperl_is_instperl = 1; | |
211 | } | |
212 | } | |
213 | ||
214 | # Check to make sure there aren't other perls around in installer's | |
215 | # path. This is probably UNIX-specific. Check all absolute directories | |
216 | # in the path except for where public executables are supposed to live. | |
217 | # Also skip $mainperl if the user opted to have it be a link to the | |
218 | # installed perl. | |
219 | ||
220 | @path = split(/:/, $ENV{"PATH"}); | |
221 | @otherperls = (); | |
222 | for (@path) { | |
223 | next unless m,^/,; | |
224 | next if ($_ eq $binexp); | |
225 | # Use &samepath here because some systems have other dirs linked | |
226 | # to $mainperldir (like SunOS) | |
227 | next if ($mainperl_is_instperl && &samepath($_, $mainperldir)); | |
228 | push(@otherperls, "$_/perl") if (-x "$_/perl" && ! -d "$_/perl"); | |
229 | } | |
230 | if (@otherperls) { | |
231 | print STDERR "\nWarning: perl appears in your path in the following " . | |
232 | "locations beyond where\nwe just installed it:\n"; | |
233 | for (@otherperls) { | |
234 | print STDERR " ", $_, "\n"; | |
235 | } | |
236 | print STDERR "\n"; | |
237 | } | |
238 | ||
c623bd54 LW |
239 | print STDERR " Installation complete\n"; |
240 | ||
241 | exit 0; | |
242 | ||
243 | ############################################################################### | |
244 | ||
a0d0e21e LW |
245 | sub yn { |
246 | local($prompt) = @_; | |
247 | local($answer); | |
248 | local($default) = $prompt =~ m/\[([yn])\]\s*$/i; | |
249 | print STDERR $prompt; | |
250 | chop($answer = <STDIN>); | |
251 | $answer = $default if $answer =~ m/^\s*$/; | |
252 | ($answer =~ m/^[yY]/); | |
253 | } | |
254 | ||
c623bd54 LW |
255 | sub unlink { |
256 | local(@names) = @_; | |
257 | ||
258 | foreach $name (@names) { | |
259 | next unless -e $name; | |
260 | print STDERR " unlink $name\n"; | |
261 | unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono; | |
262 | } | |
263 | } | |
264 | ||
e50aee73 AD |
265 | sub safe_unlink { |
266 | local(@names) = @_; | |
267 | ||
268 | foreach $name (@names) { | |
269 | next unless -e $name; | |
270 | print STDERR " unlink $name\n"; | |
271 | next if $nonono; | |
272 | next if unlink($name); | |
273 | warn "Couldn't unlink $name: $!\n"; | |
274 | if ($! =~ /busy/i) { | |
275 | print STDERR " mv $name $name.old\n"; | |
276 | &rename($name, "$name.old") || warn "Couldn't rename $name: $!\n"; | |
277 | } | |
278 | } | |
279 | } | |
280 | ||
c623bd54 LW |
281 | sub cmd { |
282 | local($cmd) = @_; | |
283 | print STDERR " $cmd\n"; | |
284 | unless ($nonono) { | |
285 | system $cmd; | |
286 | warn "Command failed!!!\n" if $?; | |
287 | } | |
288 | } | |
289 | ||
e50aee73 AD |
290 | sub rename { |
291 | local($from,$to) = @_; | |
292 | unless (unlink($to)) { | |
293 | my($i); | |
294 | for ($i = 1; $i < 50; $i++) { | |
295 | last if rename($to, "$to.$i"); | |
296 | } | |
297 | return 0 if $i >= 50; # Give up! | |
298 | } | |
299 | link($from,$to) || return 0; | |
300 | unlink($from); | |
301 | } | |
302 | ||
c623bd54 LW |
303 | sub link { |
304 | local($from,$to) = @_; | |
305 | ||
306 | print STDERR " ln $from $to\n"; | |
307 | link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono; | |
308 | } | |
309 | ||
310 | sub chmod { | |
311 | local($mode,$name) = @_; | |
312 | ||
313 | printf STDERR " chmod %o %s\n", $mode, $name; | |
514dae0d | 314 | chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name) |
c623bd54 LW |
315 | unless $nonono; |
316 | } | |
317 | ||
318 | sub makedir { | |
319 | local($dir) = @_; | |
320 | unless (-d $dir) { | |
321 | local($shortdir) = $dir; | |
322 | ||
323 | $shortdir =~ s#(.*)/.*#$1#; | |
324 | &makedir($shortdir); | |
325 | ||
326 | print STDERR " mkdir $dir\n"; | |
327 | mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono; | |
328 | } | |
329 | } | |
a0d0e21e LW |
330 | |
331 | sub samepath { | |
332 | local($p1, $p2) = @_; | |
333 | local($dev1, $ino1, $dev2, $ino2); | |
334 | ||
75f92628 | 335 | if ($p1 ne $p2) { |
a0d0e21e LW |
336 | ($dev1, $ino1) = stat($p1); |
337 | ($dev2, $ino2) = stat($p2); | |
338 | ($dev1 == $dev2 && $ino1 == $ino2); | |
339 | } | |
340 | else { | |
341 | 1; | |
342 | } | |
343 | } | |
344 | ||
345 | sub installlib { | |
346 | my $dir = $File::Find::dir; | |
347 | $dir =~ s#^\.(?![^/])/?##; | |
348 | ||
349 | my $name = $_; | |
e50aee73 AD |
350 | |
351 | # ignore patch backups and the .exists files. | |
352 | return if $name =~ m{\.orig$|~$|^\.exists}; | |
353 | ||
a0d0e21e LW |
354 | $name = "$dir/$name" if $dir ne ''; |
355 | ||
356 | my $installlib = $installprivlib; | |
357 | if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) { | |
358 | $installlib = $installarchlib; | |
359 | return unless $do_installarchlib; | |
360 | } else { | |
361 | return unless $do_installprivlib; | |
362 | } | |
363 | ||
a0d0e21e | 364 | if (-f $_) { |
3edbfbe5 TB |
365 | if (/\.al$/ || /\.ix$/) { |
366 | $installlib = $installprivlib; | |
367 | #We're installing *.al and *.ix files into $installprivlib, | |
368 | #but we have to delete old *.al and *.ix files from the 5.000 | |
369 | #distribution: | |
75f92628 | 370 | #This might not work because $archname might have changed. |
3edbfbe5 TB |
371 | &unlink("$installarchlib/$name"); |
372 | } | |
a0d0e21e LW |
373 | system "cmp", "-s", $_, "$installlib/$name"; |
374 | if ($?) { | |
375 | &unlink("$installlib/$name"); | |
3edbfbe5 | 376 | &makedir("$installlib/$dir"); |
16d20bd9 | 377 | cp_if_diff("$_", "$installlib/$dir/$_"); |
75f92628 AD |
378 | # HP-UX (at least) needs to maintain execute permissions |
379 | # on dynamically-loaded libraries. | |
748a9306 LW |
380 | if ($name =~ /\.(so|$dlext)$/o) { |
381 | &chmod(0555, "$installlib/$name"); | |
382 | } | |
383 | else { | |
384 | &chmod(0444, "$installlib/$name"); | |
385 | } | |
a0d0e21e LW |
386 | } |
387 | } elsif (-d $_) { | |
388 | &makedir("$installlib/$name"); | |
389 | } | |
390 | } | |
3edbfbe5 | 391 | |
16d20bd9 AD |
392 | # Copy $from to $to, only if $from is different than $to. |
393 | # Also preserve modification times for .a libraries. | |
394 | # On some systems, if you do | |
395 | # ranlib libperl.a | |
396 | # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a | |
397 | # and then try to link against the installed libperl.a, you might | |
398 | # get an error message to the effect that the symbol table is older | |
399 | # than the library. | |
3edbfbe5 TB |
400 | sub cp_if_diff { |
401 | my($from,$to)=@_; | |
402 | -f $from || die "$0: $from not found"; | |
403 | system "cmp", "-s", $from, $to; | |
404 | if ($?) { | |
16d20bd9 | 405 | my ($atime, $mtime); |
5d94fbed | 406 | unlink($to); # In case we don't have write permissions. |
3edbfbe5 | 407 | cmd("cp $from $to"); |
16d20bd9 AD |
408 | # Restore timestamps if it's a .a library. |
409 | if ($to =~ /\.a$/) { | |
410 | ($atime, $mtime) = (stat $from)[8,9]; | |
411 | utime $atime, $mtime, $to; | |
412 | } | |
3edbfbe5 TB |
413 | } |
414 | } |