5 chdir '..' if !-d 'lib' and -d '..\lib';
7 $ENV{PERL5LIB} = 'lib';
15 use subs qw(unlink link chmod);
17 # override the ones in the rest of the script
19 File::Path::mkpath(@_) unless $nonono;
22 $mainperldir = "/usr/bin";
23 $exe_ext = $Config{exe_ext};
26 $nonono = 1 if $ARGV[0] eq '-n';
27 $versiononly = 1 if $ARGV[0] eq '-v';
33 @scripts = qw( utils/c2ph utils/h2ph utils/h2xs
34 utils/perlbug utils/perldoc utils/pl2pm utils/splain
36 pod/pod2man pod/pod2html pod/pod2latex pod/pod2text);
38 @pods = (<pod/*.pod>);
40 %archpms = (Config => 1, FileHandle => 1, overload => 1);
43 push(@scripts,'djgpp/fixpmain');
44 $archpms{config} = $archpms{filehand} = 1;
48 if ("$File::Find::dir/$_" =~ m{^ext/[^/]+/(.*)\.pm$}) {
49 (my $pm = $1) =~ s{^lib/}{};
55 $release = substr($ver,0,3); # Not used presently.
56 $patchlevel = substr($ver,3,2);
57 die "Patchlevel of perl ($patchlevel)",
58 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
59 if $patchlevel != $Config{'PATCHLEVEL'};
61 # Fetch some frequently-used items from %Config
62 $installbin = $Config{installbin};
63 $installscript = $Config{installscript};
64 $installprivlib = $Config{installprivlib};
65 $installarchlib = $Config{installarchlib};
66 $installsitelib = $Config{installsitelib};
67 $installsitearch = $Config{installsitearch};
68 $installman1dir = $Config{installman1dir};
69 $man1ext = $Config{man1ext};
70 $libperl = $Config{libperl};
71 # Shared library and dynamic loading suffixes.
73 $dlext = $Config{dlext};
75 $d_dosuid = $Config{d_dosuid};
76 $binexp = $Config{binexp};
78 # Do some quick sanity checks.
80 if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
82 $installbin || die "No installbin directory in config.sh\n";
83 -d $installbin || mkpath($installbin, 1, 0777);
84 -d $installbin || $nonono || die "$installbin is not a directory\n";
85 -w $installbin || $nonono || die "$installbin is not writable by you\n"
86 unless $installbin =~ m#^/afs/# || $nonono;
88 -x 'perl' . $exe_ext || die "perl isn't executable!\n";
89 -x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid;
91 -x 't/TEST' || $^O eq 'MSWin32'
92 || warn "WARNING: You've never run 'make test'!!!",
93 " (Installing anyway.)\n";
95 if ($^O eq 'MSWin32') {
97 $perldll = 'perl.' . $dlext;
98 $perldll = 'perlcore.' . $dlext if $Config{'ccflags'} =~ /PERL_OBJECT/i;
100 -f $perldll || die "No perl DLL built\n";
104 safe_unlink("$installbin/$perldll");
105 copy("$perldll", "$installbin/$perldll");
106 chmod(0755, "$installbin/$perldll");
109 # First we install the version-numbered executables.
112 safe_unlink("$installbin/perl$ver$exe_ext");
113 copy("perl$exe_ext", "$installbin/perl$ver$exe_ext");
114 chmod(0755, "$installbin/perl$ver$exe_ext");
116 safe_unlink("$installbin/perl.exe");
117 copy("perl.exe", "$installbin/perl.exe");
120 safe_unlink("$installbin/sperl$ver$exe_ext");
122 copy("suidperl$exe_ext", "$installbin/sperl$ver$exe_ext");
123 chmod(04711, "$installbin/sperl$ver$exe_ext");
126 # Install library files.
128 $do_installarchlib = $do_installprivlib = 0;
130 mkpath($installprivlib, 1, 0777);
131 mkpath($installarchlib, 1, 0777);
132 mkpath($installsitelib, 1, 0777) if ($installsitelib);
133 mkpath($installsitearch, 1, 0777) if ($installsitearch);
136 $do_installarchlib = ! samepath($installarchlib, '.');
137 $do_installprivlib = ! samepath($installprivlib, '.');
138 $do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$]/);
140 if ($do_installarchlib || $do_installprivlib) {
141 find(\&installlib, '.');
143 chdir ".." || die "Can't cd back to source directory: $!\n";
146 warn "Can't cd to lib to install lib files: $!\n";
149 # Install header files and libraries.
150 mkpath("$installarchlib/CORE", 1, 0777);
151 @corefiles = <*.h libperl*.*>;
152 # AIX needs perl.exp installed as well.
153 push(@corefiles,'perl.exp') if $^O eq 'aix';
154 # If they have built sperl.o...
155 push(@corefiles,'sperl.o') if -f 'sperl.o';
156 foreach $file (@corefiles) {
157 # HP-UX (at least) needs to maintain execute permissions
158 # on dynamically-loadable libraries. So we do it for all.
159 copy_if_diff($file,"$installarchlib/CORE/$file")
160 and chmod($file =~ /\.(so|\Q$dlext\E)$/ ? 0555 : 0444,
161 "$installarchlib/CORE/$file");
164 # Install main perl executables
165 # Make links to ordinary names if installbin directory isn't current directory.
167 if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos')) {
168 safe_unlink("$installbin/perl$exe_ext", "$installbin/suidperl$exe_ext");
169 link("$installbin/perl$ver$exe_ext", "$installbin/perl$exe_ext");
170 link("$installbin/sperl$ver$exe_ext", "$installbin/suidperl$exe_ext")
174 # Offer to install perl in a "standard" location
176 $mainperl_is_instperl = 0;
178 if (!$versiononly && !$nonono && $^O ne 'MSWin32' && -t STDIN && -t STDERR
179 && -w $mainperldir && ! samepath($mainperldir, $installbin)) {
180 local($usrbinperl) = "$mainperldir/perl$exe_ext";
181 local($instperl) = "$installbin/perl$exe_ext";
182 local($expinstperl) = "$binexp/perl$exe_ext";
184 # First make sure $usrbinperl is not already the same as the perl we
186 if (-x $usrbinperl) {
187 # Try to be clever about mainperl being a symbolic link
188 # to binexp/perl if binexp and installbin are different.
189 $mainperl_is_instperl =
190 samepath($usrbinperl, $instperl) ||
191 samepath($usrbinperl, $expinstperl) ||
192 (($binexp ne $installbin) &&
194 ((readlink $usrbinperl) eq $expinstperl));
196 if ((! $mainperl_is_instperl) &&
197 (yn("Many scripts expect perl to be installed as $usrbinperl.\n" .
198 "Do you wish to have $usrbinperl be the same as\n" .
199 "$expinstperl? [y] ")))
202 eval { CORE::link $instperl, $usrbinperl } ||
203 eval { symlink $expinstperl, $usrbinperl } ||
204 copy($instperl, $usrbinperl);
205 $mainperl_is_instperl = 1;
209 # Make links to ordinary names if installbin directory isn't current directory.
211 if (!$versiononly && ! samepath($installbin, 'x2p')) {
212 safe_unlink("$installbin/a2p$exe_ext");
213 copy("x2p/a2p$exe_ext", "$installbin/a2p$exe_ext");
214 chmod(0755, "$installbin/a2p$exe_ext");
217 # cppstdin is just a script, but it is architecture-dependent, so
218 # it can't safely be shared. Place it in $installbin.
219 # Note that Configure doesn't build cppstin if it isn't needed, so
220 # we skip this if cppstdin doesn't exist.
221 if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) {
222 safe_unlink("$installbin/cppstdin");
223 copy("cppstdin", "$installbin/cppstdin");
224 chmod(0755, "$installbin/cppstdin");
229 mkpath($installscript, 1, 0777);
231 if (! $versiononly) {
233 (my $base = $_) =~ s#.*/##;
234 copy($_, "$installscript/$base");
235 chmod(0755, "$installscript/$base");
239 # pstruct should be a link to c2ph
241 if (! $versiononly) {
242 safe_unlink("$installscript/pstruct");
244 copy("$installscript/c2ph","$installscript/pstruct");
246 link("$installscript/c2ph","$installscript/pstruct");
250 # Install pod pages. Where? I guess in $installprivlib/pod.
252 if (! $versiononly || !($installprivlib =~ m/\Q$]/)) {
253 mkpath("${installprivlib}/pod", 1, 0777);
255 # If Perl 5.003's perldiag.pod is there, rename it.
256 if (open POD, "${installprivlib}/pod/perldiag.pod") {
259 # Some of Perl 5.003's diagnostic messages ended with periods.
261 my ($from, $to) = ("${installprivlib}/pod/perldiag.pod",
262 "${installprivlib}/pod/perldiag-5.003.pod");
263 print STDERR " rename $from $to";
265 or warn "Couldn't rename $from to $to: $!\n"
270 foreach $file (@pods) {
271 # $file is a name like pod/perl.pod
272 copy_if_diff($file, "${installprivlib}/${file}");
275 # Link perldiag.pod into archlib
276 my ($from, $to) = ("${installprivlib}/pod/perldiag.pod",
277 "${installarchlib}/pod/perldiag.pod");
278 if (compare($from, $to) || $nonono) {
279 mkpath("${installarchlib}/pod", 1, 0777);
281 link($from, $to) if ($^O ne 'dos');
285 # Check to make sure there aren't other perls around in installer's
286 # path. This is probably UNIX-specific. Check all absolute directories
287 # in the path except for where public executables are supposed to live.
288 # Also skip $mainperl if the user opted to have it be a link to the
293 $dirsep = ($^O eq 'os2' || $^O eq 'MSWin32') ? ';' : ':' ;
294 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
295 @path = split(/$dirsep/, $path);
299 # Use &samepath here because some systems have other dirs linked
300 # to $mainperldir (like SunOS)
301 next if samepath($_, $binexp);
302 next if ($mainperl_is_instperl && samepath($_, $mainperldir));
303 push(@otherperls, "$_/perl$exe_ext")
304 if (-x "$_/perl$exe_ext" && ! -d "$_/perl$exe_ext");
307 print STDERR "\nWarning: perl appears in your path in the following " .
308 "locations beyond where\nwe just installed it:\n";
310 print STDERR " ", $_, "\n";
317 print STDERR " Installation complete\n";
321 ###############################################################################
326 local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
327 print STDERR $prompt;
328 chop($answer = <STDIN>);
329 $answer = $default if $answer =~ m/^\s*$/;
330 ($answer =~ m/^[yY]/);
337 foreach $name (@names) {
338 next unless -e $name;
339 chmod 0777, $name if ($^O eq 'os2' || $^O eq 'MSWin32');
340 print STDERR " unlink $name\n";
341 ( CORE::unlink($name) and ++$cnt
342 or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
350 foreach $name (@names) {
351 next unless -e $name;
352 chmod 0777, $name if ($^O eq 'os2' || $^O eq 'MSWin32');
353 print STDERR " unlink $name\n";
354 next if CORE::unlink($name);
355 warn "Couldn't unlink $name: $!\n";
357 print STDERR " mv $name $name.old\n";
358 safe_rename($name, "$name.old")
359 or warn "Couldn't rename $name: $!\n";
365 local($from,$to) = @_;
366 if (-f $to and not unlink($to)) {
368 for ($i = 1; $i < 50; $i++) {
369 last if rename($to, "$to.$i");
371 warn("Cannot rename to `$to.$i': $!"), return 0
372 if $i >= 50; # Give up!
374 link($from,$to) || return 0;
382 print STDERR " ln $from $to\n";
384 CORE::link($from, $to)
386 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
387 ? die "AFS" # okay inside eval {}
388 : warn "Couldn't link $from to $to: $!\n"
392 File::Copy::copy($from, $to)
394 : warn "Couldn't copy $from to $to: $!\n"
401 local($mode,$name) = @_;
403 return if ($^O eq 'dos');
404 printf STDERR " chmod %o %s\n", $mode, $name;
405 CORE::chmod($mode,$name)
406 || warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name)
413 print STDERR " cp $from $to\n";
414 File::Copy::copy($from, $to)
415 || warn "Couldn't copy $from to $to: $!\n"
420 local($p1, $p2) = @_;
422 return (lc($p1) eq lc($p2)) if ($^O eq 'MSWin32');
425 local($dev1, $ino1, $dev2, $ino2);
426 ($dev1, $ino1) = stat($p1);
427 ($dev2, $ino2) = stat($p2);
428 ($dev1 == $dev2 && $ino1 == $ino2);
436 my $dir = $File::Find::dir;
437 $dir =~ s#^\.(?![^/])/?##;
438 local($depth) = $dir ? "lib/$dir" : "lib";
442 if ($name eq 'CVS' && -d $name) {
443 $File::Find::prune = 1;
447 # ignore patch backups and the .exists files.
448 return if $name =~ m{\.orig$|~$|^\.exists};
450 $name = "$dir/$name" if $dir ne '';
452 my $installlib = $installprivlib;
453 if ($dir =~ /^auto/ ||
454 ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) ||
455 ($name =~ /^(.*)\.(?:h|lib)$/i && $^O eq 'MSWin32')
457 $installlib = $installarchlib;
458 return unless $do_installarchlib;
460 return unless $do_installprivlib;
464 if (/\.(?:al|ix)$/ && !($dir =~ m[^auto/(.*)$] && $archpms{$1})) {
465 $installlib = $installprivlib;
466 #We're installing *.al and *.ix files into $installprivlib,
467 #but we have to delete old *.al and *.ix files from the 5.000
469 #This might not work because $archname might have changed.
470 unlink("$installarchlib/$name");
472 if (compare($_, "$installlib/$name") || $nonono) {
473 unlink("$installlib/$name");
474 mkpath("$installlib/$dir", 1, 0777);
475 # HP-UX (at least) needs to maintain execute permissions
476 # on dynamically-loaded libraries.
477 copy_if_diff($_, "$installlib/$name")
478 and chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444,
479 "$installlib/$name");
482 mkpath("$installlib/$name", 1, 0777);
486 # Copy $from to $to, only if $from is different than $to.
487 # Also preserve modification times for .a libraries.
488 # On some systems, if you do
490 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
491 # and then try to link against the installed libperl.a, you might
492 # get an error message to the effect that the symbol table is older
494 # Return true if copying occurred.
498 -f $from || die "$0: $from not found";
499 if (compare($from, $to) || $nonono) {
500 safe_unlink($to); # In case we don't have write permissions.
502 $from = $depth . "/" . $from if $depth;
505 # Restore timestamps if it's a .a library or for OS/2.
506 if (!$nonono && ($^O eq 'os2' || $to =~ /\.a$/)) {
507 my ($atime, $mtime) = (stat $from)[8,9];
508 utime $atime, $mtime, $to;