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