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