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