5 chdir '..' if !-d 'lib' and -d '..\lib';
7 $ENV{PERL5LIB} = 'lib';
11 use vars qw($Is_VMS $Is_W32 $Is_OS2 $nonono $versiononly $depth);
14 $Is_VMS = $^O eq 'VMS';
15 $Is_W32 = $^O eq 'MSWin32';
16 $Is_OS2 = $^O eq 'os2';
17 if ($Is_VMS) { eval 'use VMS::Filespec;' }
20 my $scr_ext = ($Is_VMS ? '.Com' : $Is_W32 ? '.bat' : '');
26 use ExtUtils::Packlist;
28 use subs qw(unlink link chmod);
29 use vars qw($packlist);
31 # override the ones in the rest of the script
33 File::Path::mkpath(@_) unless $nonono;
36 my $mainperldir = "/usr/bin";
37 my $exe_ext = $Config{exe_ext};
39 # Allow ``make install PERLNAME=something_besides_perl'':
40 my $perl = defined($ENV{PERLNAME}) ? $ENV{PERLNAME} : 'perl';
43 $nonono = 1 if $ARGV[0] eq '-n';
44 $versiononly = 1 if $ARGV[0] eq '-v';
48 umask 022 unless $Is_VMS;
50 my @scripts = qw(utils/c2ph utils/h2ph utils/h2xs utils/perlbug utils/perldoc
51 utils/pl2pm utils/splain utils/perlcc
53 pod/pod2man pod/pod2html pod/pod2latex pod/pod2text);
55 if ($scr_ext) { @scripts = map { "$_$scr_ext" } @scripts; }
57 my @pods = (<pod/*.pod>);
59 # Specify here any .pm files that are actually architecture-dependent.
60 # (Those included with XS extensions under ext/ are automatically
62 # Now that the default privlib has the full perl version number included,
63 # we no longer have to play the trick of sticking version-specific .pm
64 # files under the archlib directory.
70 push(@scripts,'djgpp/fixpmain');
71 $archpms{config} = $archpms{filehand} = 1;
74 if ((-e "testcompile") && (defined($ENV{'COMPILE'})))
76 push(@scripts, map("$_.exe", @scripts));
80 if ("$File::Find::dir/$_" =~ m{^ext/[^/]+/(.*)\.pm$}) {
81 (my $pm = $1) =~ s{^lib/}{};
87 my $release = substr($ver,0,3); # Not used presently.
88 my $patchlevel = substr($ver,3,2);
89 die "Patchlevel of perl ($patchlevel)",
90 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
91 if $patchlevel != $Config{'PATCHLEVEL'};
93 # Fetch some frequently-used items from %Config
94 my $installbin = $Config{installbin};
95 my $installscript = $Config{installscript};
96 my $installprivlib = $Config{installprivlib};
97 my $installarchlib = $Config{installarchlib};
98 my $installsitelib = $Config{installsitelib};
99 my $installsitearch = $Config{installsitearch};
100 my $installman1dir = $Config{installman1dir};
101 my $man1ext = $Config{man1ext};
102 my $libperl = $Config{libperl};
103 # Shared library and dynamic loading suffixes.
104 my $so = $Config{so};
105 my $dlext = $Config{dlext};
107 my $d_dosuid = $Config{d_dosuid};
108 my $binexp = $Config{binexp};
110 if ($Is_VMS) { # Hang in there until File::Spec hits the big time
111 foreach ( \$installbin, \$installscript, \$installprivlib,
112 \$installarchlib, \$installsitelib, \$installsitearch,
114 $$_ = unixify($$_); $$_ =~ s:/$::;
118 # Do some quick sanity checks.
120 if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
122 $installbin || die "No installbin directory in config.sh\n";
123 -d $installbin || mkpath($installbin, 1, 0777);
124 -d $installbin || $nonono || die "$installbin is not a directory\n";
125 -w $installbin || $nonono || die "$installbin is not writable by you\n"
126 unless $installbin =~ m#^/afs/# || $nonono;
128 -x 'perl' . $exe_ext || die "perl isn't executable!\n";
129 -x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid;
131 -x 't/TEST' || $Is_W32
132 || warn "WARNING: You've never run 'make test'!!!",
133 " (Installing anyway.)\n";
137 my $perldll = 'perl.' . $dlext;
138 $perldll = 'perlcore.' . $dlext if $Config{'ccflags'} =~ /PERL_OBJECT/i;
140 -f $perldll || die "No perl DLL built\n";
144 safe_unlink("$installbin/$perldll");
145 copy("$perldll", "$installbin/$perldll");
146 chmod(0755, "$installbin/$perldll");
149 # This will be used to store the packlist
150 my $packlist = ExtUtils::Packlist->new("$installarchlib/.packlist");
152 # First we install the version-numbered executables.
155 safe_unlink("$installbin/$perl$exe_ext");
156 copy("perl$exe_ext", "$installbin/$perl$exe_ext");
157 chmod(0755, "$installbin/$perl$exe_ext");
158 safe_unlink("$installbin/${perl}shr$exe_ext");
159 copy("perlshr$exe_ext", "$installbin/${perl}shr$exe_ext");
160 chmod(0755, "$installbin/${perl}shr$exe_ext");
162 elsif ($^O eq 'mpeix') {
163 # MPE lacks hard links and requires that executables with special
164 # capabilities reside in the MPE namespace.
165 safe_unlink("$installbin/perl$ver$exe_ext", $Config{perlpath});
166 # Install the primary executable into the MPE namespace as perlpath.
167 copy("perl$exe_ext", $Config{perlpath});
168 chmod(0755, $Config{perlpath});
169 # Create a backup copy with the version number.
170 link($Config{perlpath}, "$installbin/perl$ver$exe_ext");
172 elsif ($^O ne 'dos') {
173 safe_unlink("$installbin/$perl$ver$exe_ext");
174 copy("perl$exe_ext", "$installbin/$perl$ver$exe_ext");
175 chmod(0755, "$installbin/$perl$ver$exe_ext");
178 safe_unlink("$installbin/$perl.exe");
179 copy("perl.exe", "$installbin/$perl.exe");
182 safe_unlink("$installbin/s$perl$ver$exe_ext");
184 copy("suidperl$exe_ext", "$installbin/s$perl$ver$exe_ext");
185 chmod(04711, "$installbin/s$perl$ver$exe_ext");
188 # Install library files.
190 my ($do_installarchlib, $do_installprivlib) = (0, 0);
192 mkpath($installprivlib, 1, 0777);
193 mkpath($installarchlib, 1, 0777);
194 mkpath($installsitelib, 1, 0777) if ($installsitelib);
195 mkpath($installsitearch, 1, 0777) if ($installsitearch);
198 $do_installarchlib = ! samepath($installarchlib, '.');
199 $do_installprivlib = ! samepath($installprivlib, '.');
200 $do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$]/);
202 if ($do_installarchlib || $do_installprivlib) {
203 find(\&installlib, '.');
205 chdir ".." || die "Can't cd back to source directory: $!\n";
208 warn "Can't cd to lib to install lib files: $!\n";
211 # Install header files and libraries.
212 mkpath("$installarchlib/CORE", 1, 0777);
214 if ($Is_VMS) { # We did core file selection during build
215 my $coredir = "lib/$Config{'arch'}/$]";
217 @corefiles = <$coredir/*.*>;
220 @corefiles = <*.h libperl*.*>;
221 # AIX needs perl.exp installed as well.
222 push(@corefiles,'perl.exp') if $^O eq 'aix';
223 if ($^O eq 'mpeix') {
224 # MPE needs mpeixish.h installed as well.
225 mkpath("$installarchlib/CORE/mpeix", 1, 0777);
226 push(@corefiles,'mpeix/mpeixish.h');
228 # If they have built sperl.o...
229 push(@corefiles,'sperl.o') if -f 'sperl.o';
231 foreach my $file (@corefiles) {
232 # HP-UX (at least) needs to maintain execute permissions
233 # on dynamically-loadable libraries. So we do it for all.
234 copy_if_diff($file,"$installarchlib/CORE/$file")
235 and chmod($file =~ /\.(so|\Q$dlext\E)$/ ? 0555 : 0444,
236 "$installarchlib/CORE/$file");
239 # Install main perl executables
240 # Make links to ordinary names if installbin directory isn't current directory.
242 if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS) {
243 safe_unlink("$installbin/$perl$exe_ext", "$installbin/suid$perl$exe_ext");
244 if ($^O eq 'mpeix') {
245 # MPE doesn't support hard links, so use a symlink.
246 # We don't want another cloned copy.
247 symlink($Config{perlpath}, "$installbin/perl$exe_ext");
249 link("$installbin/$perl$ver$exe_ext", "$installbin/$perl$exe_ext");
251 link("$installbin/s$perl$ver$exe_ext", "$installbin/suid$perl$exe_ext")
255 # Offer to install perl in a "standard" location
257 my $mainperl_is_instperl = 0;
259 if ($Config{installusrbinperl} eq 'define' &&
260 !$versiononly && !$nonono && !$Is_W32 && !$Is_VMS && -t STDIN && -t STDERR
261 && -w $mainperldir && ! samepath($mainperldir, $installbin)) {
262 my($usrbinperl) = "$mainperldir/$perl$exe_ext";
263 my($instperl) = "$installbin/$perl$exe_ext";
264 my($expinstperl) = "$binexp/$perl$exe_ext";
266 # First make sure $usrbinperl is not already the same as the perl we
268 if (-x $usrbinperl) {
269 # Try to be clever about mainperl being a symbolic link
270 # to binexp/perl if binexp and installbin are different.
271 $mainperl_is_instperl =
272 samepath($usrbinperl, $instperl) ||
273 samepath($usrbinperl, $expinstperl) ||
274 (($binexp ne $installbin) &&
276 ((readlink $usrbinperl) eq $expinstperl));
278 if ((! $mainperl_is_instperl) &&
279 (yn("Many scripts expect perl to be installed as $usrbinperl.\n" .
280 "Do you wish to have $usrbinperl be the same as\n" .
281 "$expinstperl? [y] ")))
284 ( $Config{'d_link'} eq 'define' &&
285 eval { CORE::link $instperl, $usrbinperl } ) ||
286 eval { symlink $expinstperl, $usrbinperl } ||
287 copy($instperl, $usrbinperl);
289 $mainperl_is_instperl = 1;
293 # Make links to ordinary names if installbin directory isn't current directory.
295 if (!$versiononly && ! samepath($installbin, 'x2p')) {
296 safe_unlink("$installbin/a2p$exe_ext");
297 copy("x2p/a2p$exe_ext", "$installbin/a2p$exe_ext");
298 chmod(0755, "$installbin/a2p$exe_ext");
301 # cppstdin is just a script, but it is architecture-dependent, so
302 # it can't safely be shared. Place it in $installbin.
303 # Note that Configure doesn't build cppstin if it isn't needed, so
304 # we skip this if cppstdin doesn't exist.
305 if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) {
306 safe_unlink("$installbin/cppstdin");
307 copy("cppstdin", "$installbin/cppstdin");
308 chmod(0755, "$installbin/cppstdin");
313 mkpath($installscript, 1, 0777);
315 if (! $versiononly) {
317 (my $base = $_) =~ s#.*/##;
318 copy($_, "$installscript/$base");
319 chmod(0755, "$installscript/$base");
323 # pstruct should be a link to c2ph
325 if (! $versiononly) {
326 safe_unlink("$installscript/pstruct$scr_ext");
327 if ($^O eq 'dos' or $Is_VMS) {
328 copy("$installscript/c2ph$scr_ext", "$installscript/pstruct$scr_ext");
330 link("$installscript/c2ph$scr_ext", "$installscript/pstruct$scr_ext");
334 # Install pod pages. Where? I guess in $installprivlib/pod.
336 unless ( $versiononly && !($installprivlib =~ m/\Q$]/)) {
337 mkpath("${installprivlib}/pod", 1, 0777);
339 # If Perl 5.003's perldiag.pod is there, rename it.
340 if (open POD, "${installprivlib}/pod/perldiag.pod") {
343 # Some of Perl 5.003's diagnostic messages ended with periods.
345 my ($from, $to) = ("${installprivlib}/pod/perldiag.pod",
346 "${installprivlib}/pod/perldiag-5.003.pod");
347 print STDERR " rename $from $to";
349 or warn "Couldn't rename $from to $to: $!\n"
354 foreach my $file (@pods) {
355 # $file is a name like pod/perl.pod
356 copy_if_diff($file, "${installprivlib}/${file}");
361 # Check to make sure there aren't other perls around in installer's
362 # path. This is probably UNIX-specific. Check all absolute directories
363 # in the path except for where public executables are supposed to live.
364 # Also skip $mainperl if the user opted to have it be a link to the
369 my $dirsep = ($Is_OS2 || $Is_W32) ? ';' : ':' ;
370 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
371 @path = split(/$dirsep/, $path);
374 while (exists $ENV{'DCL$PATH' . $i}) {
375 my $dir = unixpath($ENV{'DCL$PATH' . $i}); $dir =~ s-/$--;
382 # Use &samepath here because some systems have other dirs linked
383 # to $mainperldir (like SunOS)
384 next if samepath($_, $binexp);
385 next if ($mainperl_is_instperl && samepath($_, $mainperldir));
386 push(@otherperls, "$_/$perl$exe_ext")
387 if (-x "$_/$perl$exe_ext" && ! -d "$_/$perl$exe_ext");
390 print STDERR "\nWarning: $perl appears in your path in the following " .
391 "locations beyond where\nwe just installed it:\n";
393 print STDERR " ", $_, "\n";
400 $packlist->write() unless $nonono;
401 print STDERR " Installation complete\n";
405 ###############################################################################
410 my($default) = $prompt =~ m/\[([yn])\]\s*$/i;
411 print STDERR $prompt;
412 chop($answer = <STDIN>);
413 $answer = $default if $answer =~ m/^\s*$/;
414 ($answer =~ m/^[yY]/);
421 return scalar(@names) if $Is_VMS;
423 foreach my $name (@names) {
424 next unless -e $name;
425 chmod 0777, $name if ($Is_OS2 || $Is_W32);
426 print STDERR " unlink $name\n";
427 ( CORE::unlink($name) and ++$cnt
428 or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
434 return if $nonono or $Is_VMS;
436 foreach my $name (@names) {
437 next unless -e $name;
438 chmod 0777, $name if ($Is_OS2 || $Is_W32);
439 print STDERR " unlink $name\n";
440 next if CORE::unlink($name);
441 warn "Couldn't unlink $name: $!\n";
443 print STDERR " mv $name $name.old\n";
444 safe_rename($name, "$name.old")
445 or warn "Couldn't rename $name: $!\n";
452 if (-f $to and not unlink($to)) {
454 for ($i = 1; $i < 50; $i++) {
455 last if rename($to, "$to.$i");
457 warn("Cannot rename to `$to.$i': $!"), return 0
458 if $i >= 50; # Give up!
460 link($from,$to) || return 0;
468 print STDERR " ln $from $to\n";
470 CORE::link($from, $to)
472 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
473 ? die "AFS" # okay inside eval {}
474 : warn "Couldn't link $from to $to: $!\n"
476 $packlist->{$to} = { from => $from, type => 'link' };
479 print STDERR " creating new version of $to\n" if $Is_VMS and -e $to;
480 File::Copy::copy($from, $to)
482 : warn "Couldn't copy $from to $to: $!\n"
484 $packlist->{$to} = { type => 'file' };
490 my($mode,$name) = @_;
492 return if ($^O eq 'dos');
493 printf STDERR " chmod %o %s\n", $mode, $name;
494 CORE::chmod($mode,$name)
495 || warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name)
502 print STDERR " cp $from $to\n";
503 print STDERR " creating new version of $to\n" if $Is_VMS and -e $to;
504 File::Copy::copy($from, $to)
505 || warn "Couldn't copy $from to $to: $!\n"
507 $packlist->{$to} = { type => 'file' };
513 return (lc($p1) eq lc($p2)) if $Is_W32;
516 my($dev1, $ino1, $dev2, $ino2);
517 ($dev1, $ino1) = stat($p1);
518 ($dev2, $ino2) = stat($p2);
519 ($dev1 == $dev2 && $ino1 == $ino2);
527 my $dir = $File::Find::dir;
528 $dir =~ s#^\.(?![^/])/?##;
529 local($depth) = $dir ? "lib/$dir" : "lib";
533 if ($name eq 'CVS' && -d $name) {
534 $File::Find::prune = 1;
538 # ignore patch backups and the .exists files.
539 return if $name =~ m{\.orig$|~$|^\.exists};
541 $name = "$dir/$name" if $dir ne '';
543 my $installlib = $installprivlib;
544 if ($dir =~ /^auto/ ||
545 ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) ||
546 ($name =~ /^(.*)\.(?:h|lib)$/i && $Is_W32)
548 $installlib = $installarchlib;
549 return unless $do_installarchlib;
551 return unless $do_installprivlib;
555 if (/\.(?:al|ix)$/ && !($dir =~ m[^auto/(.*)$] && $archpms{$1})) {
556 $installlib = $installprivlib;
557 #We're installing *.al and *.ix files into $installprivlib,
558 #but we have to delete old *.al and *.ix files from the 5.000
560 #This might not work because $archname might have changed.
561 unlink("$installarchlib/$name");
563 $packlist->{"$installlib/$name"} = { type => 'file' };
564 if (compare($_, "$installlib/$name") || $nonono) {
565 unlink("$installlib/$name");
566 mkpath("$installlib/$dir", 1, 0777);
567 # HP-UX (at least) needs to maintain execute permissions
568 # on dynamically-loaded libraries.
569 copy_if_diff($_, "$installlib/$name")
570 and chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444,
571 "$installlib/$name");
576 # Copy $from to $to, only if $from is different than $to.
577 # Also preserve modification times for .a libraries.
578 # On some systems, if you do
580 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
581 # and then try to link against the installed libperl.a, you might
582 # get an error message to the effect that the symbol table is older
584 # Return true if copying occurred.
588 return 1 if (($^O eq 'VMS') && (-d $from));
589 -f $from || die "$0: $from not found";
590 $packlist->{$to} = { type => 'file' };
591 if (compare($from, $to) || $nonono) {
592 safe_unlink($to); # In case we don't have write permissions.
594 $from = $depth . "/" . $from if $depth;
597 # Restore timestamps if it's a .a library or for OS/2.
598 if (!$nonono && ($Is_OS2 || $to =~ /\.a$/)) {
599 my ($atime, $mtime) = (stat $from)[8,9];
600 utime $atime, $mtime, $to;