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