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