5 chdir '..' if !-d 'lib' and -d '..\lib';
7 $ENV{PERL5LIB} = 'lib';
8 $Is_VMS = $^O eq 'VMS';
9 $Is_W32 = $^O eq 'MSWin32';
10 $Is_OS2 = $^O eq 'os2';
11 if ($Is_VMS) { eval 'use VMS::Filespec;' }
14 $scr_ext = ($Is_VMS ? '.Com' : $Is_W32 ? '.bat' : '');
20 use ExtUtils::Packlist;
22 use subs qw(unlink link chmod);
23 use vars qw($packlist);
25 # override the ones in the rest of the script
27 File::Path::mkpath(@_) unless $nonono;
30 $mainperldir = "/usr/bin";
31 $exe_ext = $Config{exe_ext};
33 # Allow ``make install PERLNAME=something_besides_perl'':
34 $perl = defined($ENV{PERLNAME}) ? $ENV{PERLNAME} : 'perl';
37 $nonono = 1 if $ARGV[0] eq '-n';
38 $versiononly = 1 if $ARGV[0] eq '-v';
42 umask 022 unless $Is_VMS;
44 @scripts = qw( utils/c2ph utils/h2ph utils/h2xs utils/perlbug utils/perldoc
45 utils/pl2pm utils/splain utils/perlcc
47 pod/pod2man pod/pod2html pod/pod2latex pod/pod2text);
49 if ($scr_ext) { @scripts = map { "$_$scr_ext" } @scripts; }
51 @pods = (<pod/*.pod>);
53 # Specify here any .pm files that are actually architecture-dependent.
54 # (Those included with XS extensions under ext/ are automatically
56 # Now that the default privlib has the full perl version number included,
57 # we no longer have to play the trick of sticking version-specific .pm
58 # files under the archlib directory.
64 push(@scripts,'djgpp/fixpmain');
65 $archpms{config} = $archpms{filehand} = 1;
68 if ((-e "testcompile") && (defined($ENV{'COMPILE'})))
70 push(@scripts, map("$_.exe", @scripts));
74 if ("$File::Find::dir/$_" =~ m{^ext/[^/]+/(.*)\.pm$}) {
75 (my $pm = $1) =~ s{^lib/}{};
81 $release = substr($ver,0,3); # Not used presently.
82 $patchlevel = substr($ver,3,2);
83 die "Patchlevel of perl ($patchlevel)",
84 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
85 if $patchlevel != $Config{'PATCHLEVEL'};
87 # Fetch some frequently-used items from %Config
88 $installbin = $Config{installbin};
89 $installscript = $Config{installscript};
90 $installprivlib = $Config{installprivlib};
91 $installarchlib = $Config{installarchlib};
92 $installsitelib = $Config{installsitelib};
93 $installsitearch = $Config{installsitearch};
94 $installman1dir = $Config{installman1dir};
95 $man1ext = $Config{man1ext};
96 $libperl = $Config{libperl};
97 # Shared library and dynamic loading suffixes.
99 $dlext = $Config{dlext};
101 $d_dosuid = $Config{d_dosuid};
102 $binexp = $Config{binexp};
104 if ($Is_VMS) { # Hang in there until File::Spec hits the big time
105 foreach ( \$installbin, \$installscript, \$installprivlib,
106 \$installarchlib, \$installsitelib, \$installsitearch,
108 $$_ = unixify($$_); $$_ =~ s:/$::;
112 # Do some quick sanity checks.
114 if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
116 $installbin || die "No installbin directory in config.sh\n";
117 -d $installbin || mkpath($installbin, 1, 0777);
118 -d $installbin || $nonono || die "$installbin is not a directory\n";
119 -w $installbin || $nonono || die "$installbin is not writable by you\n"
120 unless $installbin =~ m#^/afs/# || $nonono;
122 -x 'perl' . $exe_ext || die "perl isn't executable!\n";
123 -x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid;
125 -x 't/TEST' || $Is_W32
126 || warn "WARNING: You've never run 'make test'!!!",
127 " (Installing anyway.)\n";
131 $perldll = 'perl.' . $dlext;
132 $perldll = 'perlcore.' . $dlext if $Config{'ccflags'} =~ /PERL_OBJECT/i;
134 -f $perldll || die "No perl DLL built\n";
138 safe_unlink("$installbin/$perldll");
139 copy("$perldll", "$installbin/$perldll");
140 chmod(0755, "$installbin/$perldll");
143 # This will be used to store the packlist
144 $packlist = ExtUtils::Packlist->new("$installarchlib/.packlist");
146 # First we install the version-numbered executables.
149 safe_unlink("$installbin/$perl$exe_ext");
150 copy("perl$exe_ext", "$installbin/$perl$exe_ext");
151 chmod(0755, "$installbin/$perl$exe_ext");
152 safe_unlink("$installbin/${perl}shr$exe_ext");
153 copy("perlshr$exe_ext", "$installbin/${perl}shr$exe_ext");
154 chmod(0755, "$installbin/${perl}shr$exe_ext");
156 elsif ($^O ne 'dos') {
157 safe_unlink("$installbin/$perl$ver$exe_ext");
158 copy("perl$exe_ext", "$installbin/$perl$ver$exe_ext");
159 chmod(0755, "$installbin/$perl$ver$exe_ext");
161 safe_unlink("$installbin/$perl.exe");
162 copy("perl.exe", "$installbin/$perl.exe");
165 safe_unlink("$installbin/s$perl$ver$exe_ext");
167 copy("suidperl$exe_ext", "$installbin/s$perl$ver$exe_ext");
168 chmod(04711, "$installbin/s$perl$ver$exe_ext");
171 # Install library files.
173 $do_installarchlib = $do_installprivlib = 0;
175 mkpath($installprivlib, 1, 0777);
176 mkpath($installarchlib, 1, 0777);
177 mkpath($installsitelib, 1, 0777) if ($installsitelib);
178 mkpath($installsitearch, 1, 0777) if ($installsitearch);
181 $do_installarchlib = ! samepath($installarchlib, '.');
182 $do_installprivlib = ! samepath($installprivlib, '.');
183 $do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$]/);
185 if ($do_installarchlib || $do_installprivlib) {
186 find(\&installlib, '.');
188 chdir ".." || die "Can't cd back to source directory: $!\n";
191 warn "Can't cd to lib to install lib files: $!\n";
194 # Install header files and libraries.
195 mkpath("$installarchlib/CORE", 1, 0777);
196 if ($Is_VMS) { # We did core file selection during build
197 my $coredir = "lib/$Config{'arch'}/$]";
199 @corefiles = <$coredir/*.*>;
202 @corefiles = <*.h libperl*.*>;
203 # AIX needs perl.exp installed as well.
204 push(@corefiles,'perl.exp') if $^O eq 'aix';
205 # If they have built sperl.o...
206 push(@corefiles,'sperl.o') if -f 'sperl.o';
208 foreach $file (@corefiles) {
209 # HP-UX (at least) needs to maintain execute permissions
210 # on dynamically-loadable libraries. So we do it for all.
211 copy_if_diff($file,"$installarchlib/CORE/$file")
212 and chmod($file =~ /\.(so|\Q$dlext\E)$/ ? 0555 : 0444,
213 "$installarchlib/CORE/$file");
216 # Install main perl executables
217 # Make links to ordinary names if installbin directory isn't current directory.
219 if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS) {
220 safe_unlink("$installbin/$perl$exe_ext", "$installbin/suid$perl$exe_ext");
221 link("$installbin/$perl$ver$exe_ext", "$installbin/$perl$exe_ext");
222 link("$installbin/s$perl$ver$exe_ext", "$installbin/suid$perl$exe_ext")
226 # Offer to install perl in a "standard" location
228 $mainperl_is_instperl = 0;
230 if (!$versiononly && !$nonono && !$Is_W32 && !$Is_VMS && -t STDIN && -t STDERR
231 && -w $mainperldir && ! samepath($mainperldir, $installbin)) {
232 local($usrbinperl) = "$mainperldir/$perl$exe_ext";
233 local($instperl) = "$installbin/$perl$exe_ext";
234 local($expinstperl) = "$binexp/$perl$exe_ext";
236 # First make sure $usrbinperl is not already the same as the perl we
238 if (-x $usrbinperl) {
239 # Try to be clever about mainperl being a symbolic link
240 # to binexp/perl if binexp and installbin are different.
241 $mainperl_is_instperl =
242 samepath($usrbinperl, $instperl) ||
243 samepath($usrbinperl, $expinstperl) ||
244 (($binexp ne $installbin) &&
246 ((readlink $usrbinperl) eq $expinstperl));
248 if ((! $mainperl_is_instperl) &&
249 (yn("Many scripts expect perl to be installed as $usrbinperl.\n" .
250 "Do you wish to have $usrbinperl be the same as\n" .
251 "$expinstperl? [y] ")))
254 eval { CORE::link $instperl, $usrbinperl } ||
255 eval { symlink $expinstperl, $usrbinperl } ||
256 copy($instperl, $usrbinperl);
257 $mainperl_is_instperl = 1;
261 # Make links to ordinary names if installbin directory isn't current directory.
263 if (!$versiononly && ! samepath($installbin, 'x2p')) {
264 safe_unlink("$installbin/a2p$exe_ext");
265 copy("x2p/a2p$exe_ext", "$installbin/a2p$exe_ext");
266 chmod(0755, "$installbin/a2p$exe_ext");
269 # cppstdin is just a script, but it is architecture-dependent, so
270 # it can't safely be shared. Place it in $installbin.
271 # Note that Configure doesn't build cppstin if it isn't needed, so
272 # we skip this if cppstdin doesn't exist.
273 if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) {
274 safe_unlink("$installbin/cppstdin");
275 copy("cppstdin", "$installbin/cppstdin");
276 chmod(0755, "$installbin/cppstdin");
281 mkpath($installscript, 1, 0777);
283 if (! $versiononly) {
285 (my $base = $_) =~ s#.*/##;
286 copy($_, "$installscript/$base");
287 chmod(0755, "$installscript/$base");
291 # pstruct should be a link to c2ph
293 if (! $versiononly) {
294 safe_unlink("$installscript/pstruct$scr_ext");
295 if ($^O eq 'dos' or $Is_VMS) {
296 copy("$installscript/c2ph$scr_ext", "$installscript/pstruct$scr_ext");
298 link("$installscript/c2ph$scr_ext", "$installscript/pstruct$scr_ext");
302 # Install pod pages. Where? I guess in $installprivlib/pod.
304 if (! $versiononly || !($installprivlib =~ m/\Q$]/)) {
305 mkpath("${installprivlib}/pod", 1, 0777);
307 # If Perl 5.003's perldiag.pod is there, rename it.
308 if (open POD, "${installprivlib}/pod/perldiag.pod") {
311 # Some of Perl 5.003's diagnostic messages ended with periods.
313 my ($from, $to) = ("${installprivlib}/pod/perldiag.pod",
314 "${installprivlib}/pod/perldiag-5.003.pod");
315 print STDERR " rename $from $to";
317 or warn "Couldn't rename $from to $to: $!\n"
322 foreach $file (@pods) {
323 # $file is a name like pod/perl.pod
324 copy_if_diff($file, "${installprivlib}/${file}");
329 # Check to make sure there aren't other perls around in installer's
330 # path. This is probably UNIX-specific. Check all absolute directories
331 # in the path except for where public executables are supposed to live.
332 # Also skip $mainperl if the user opted to have it be a link to the
337 $dirsep = ($Is_OS2 || $Is_W32) ? ';' : ':' ;
338 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
339 @path = split(/$dirsep/, $path);
342 while (exists $ENV{'DCL$PATH' . $i}) {
343 $dir = unixpath($ENV{'DCL$PATH' . $i}); $dir =~ s-/$--;
350 # Use &samepath here because some systems have other dirs linked
351 # to $mainperldir (like SunOS)
352 next if samepath($_, $binexp);
353 next if ($mainperl_is_instperl && samepath($_, $mainperldir));
354 push(@otherperls, "$_/$perl$exe_ext")
355 if (-x "$_/$perl$exe_ext" && ! -d "$_/$perl$exe_ext");
358 print STDERR "\nWarning: $perl appears in your path in the following " .
359 "locations beyond where\nwe just installed it:\n";
361 print STDERR " ", $_, "\n";
368 $packlist->write() unless $nonono;
369 print STDERR " Installation complete\n";
373 ###############################################################################
378 local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
379 print STDERR $prompt;
380 chop($answer = <STDIN>);
381 $answer = $default if $answer =~ m/^\s*$/;
382 ($answer =~ m/^[yY]/);
389 return scalar(@names) if $Is_VMS;
391 foreach $name (@names) {
392 next unless -e $name;
393 chmod 0777, $name if ($Is_OS2 || $Is_W32);
394 print STDERR " unlink $name\n";
395 ( CORE::unlink($name) and ++$cnt
396 or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
402 return if $nonono or $Is_VMS;
404 foreach $name (@names) {
405 next unless -e $name;
406 chmod 0777, $name if ($Is_OS2 || $Is_W32);
407 print STDERR " unlink $name\n";
408 next if CORE::unlink($name);
409 warn "Couldn't unlink $name: $!\n";
411 print STDERR " mv $name $name.old\n";
412 safe_rename($name, "$name.old")
413 or warn "Couldn't rename $name: $!\n";
419 local($from,$to) = @_;
420 if (-f $to and not unlink($to)) {
422 for ($i = 1; $i < 50; $i++) {
423 last if rename($to, "$to.$i");
425 warn("Cannot rename to `$to.$i': $!"), return 0
426 if $i >= 50; # Give up!
428 link($from,$to) || return 0;
436 print STDERR " ln $from $to\n";
438 CORE::link($from, $to)
440 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
441 ? die "AFS" # okay inside eval {}
442 : warn "Couldn't link $from to $to: $!\n"
444 $packlist->{$to} = { from => $from, type => 'link' };
447 print STDERR " creating new version of $to\n" if $Is_VMS and -e $to;
448 File::Copy::copy($from, $to)
450 : warn "Couldn't copy $from to $to: $!\n"
452 $packlist->{$to} = { type => 'file' };
458 local($mode,$name) = @_;
460 return if ($^O eq 'dos');
461 printf STDERR " chmod %o %s\n", $mode, $name;
462 CORE::chmod($mode,$name)
463 || warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name)
470 print STDERR " cp $from $to\n";
471 print STDERR " creating new version of $to\n" if $Is_VMS and -e $to;
472 File::Copy::copy($from, $to)
473 || warn "Couldn't copy $from to $to: $!\n"
475 $packlist->{$to} = { type => 'file' };
479 local($p1, $p2) = @_;
481 return (lc($p1) eq lc($p2)) if $Is_W32;
484 local($dev1, $ino1, $dev2, $ino2);
485 ($dev1, $ino1) = stat($p1);
486 ($dev2, $ino2) = stat($p2);
487 ($dev1 == $dev2 && $ino1 == $ino2);
495 my $dir = $File::Find::dir;
496 $dir =~ s#^\.(?![^/])/?##;
497 local($depth) = $dir ? "lib/$dir" : "lib";
501 if ($name eq 'CVS' && -d $name) {
502 $File::Find::prune = 1;
506 # ignore patch backups and the .exists files.
507 return if $name =~ m{\.orig$|~$|^\.exists};
509 $name = "$dir/$name" if $dir ne '';
511 my $installlib = $installprivlib;
512 if ($dir =~ /^auto/ ||
513 ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) ||
514 ($name =~ /^(.*)\.(?:h|lib)$/i && $Is_W32)
516 $installlib = $installarchlib;
517 return unless $do_installarchlib;
519 return unless $do_installprivlib;
523 if (/\.(?:al|ix)$/ && !($dir =~ m[^auto/(.*)$] && $archpms{$1})) {
524 $installlib = $installprivlib;
525 #We're installing *.al and *.ix files into $installprivlib,
526 #but we have to delete old *.al and *.ix files from the 5.000
528 #This might not work because $archname might have changed.
529 unlink("$installarchlib/$name");
531 $packlist->{"$installlib/$name"} = { type => 'file' };
532 if (compare($_, "$installlib/$name") || $nonono) {
533 unlink("$installlib/$name");
534 mkpath("$installlib/$dir", 1, 0777);
535 # HP-UX (at least) needs to maintain execute permissions
536 # on dynamically-loaded libraries.
537 copy_if_diff($_, "$installlib/$name")
538 and chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444,
539 "$installlib/$name");
542 mkpath("$installlib/$name", 1, 0777);
546 # Copy $from to $to, only if $from is different than $to.
547 # Also preserve modification times for .a libraries.
548 # On some systems, if you do
550 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
551 # and then try to link against the installed libperl.a, you might
552 # get an error message to the effect that the symbol table is older
554 # Return true if copying occurred.
558 return 1 if (($^O eq 'VMS') && (-d $from));
559 -f $from || die "$0: $from not found";
560 $packlist->{$to} = { type => 'file' };
561 if (compare($from, $to) || $nonono) {
562 safe_unlink($to); # In case we don't have write permissions.
564 $from = $depth . "/" . $from if $depth;
567 # Restore timestamps if it's a .a library or for OS/2.
568 if (!$nonono && ($Is_OS2 || $to =~ /\.a$/)) {
569 my ($atime, $mtime) = (stat $from)[8,9];
570 utime $atime, $mtime, $to;