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>);
54 Config => 1, FileHandle => 1, overload => 1,
58 push(@scripts,'djgpp/fixpmain');
59 $archpms{config} = $archpms{filehand} = 1;
62 if ((-e "testcompile") && (defined($ENV{'COMPILE'})))
64 push(@scripts, map("$_.exe", @scripts));
68 if ("$File::Find::dir/$_" =~ m{^ext/[^/]+/(.*)\.pm$}) {
69 (my $pm = $1) =~ s{^lib/}{};
75 $release = substr($ver,0,3); # Not used presently.
76 $patchlevel = substr($ver,3,2);
77 die "Patchlevel of perl ($patchlevel)",
78 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
79 if $patchlevel != $Config{'PATCHLEVEL'};
81 # Fetch some frequently-used items from %Config
82 $installbin = $Config{installbin};
83 $installscript = $Config{installscript};
84 $installprivlib = $Config{installprivlib};
85 $installarchlib = $Config{installarchlib};
86 $installsitelib = $Config{installsitelib};
87 $installsitearch = $Config{installsitearch};
88 $installman1dir = $Config{installman1dir};
89 $man1ext = $Config{man1ext};
90 $libperl = $Config{libperl};
91 # Shared library and dynamic loading suffixes.
93 $dlext = $Config{dlext};
95 $d_dosuid = $Config{d_dosuid};
96 $binexp = $Config{binexp};
98 if ($Is_VMS) { # Hang in there until File::Spec hits the big time
99 foreach ( \$installbin, \$installscript, \$installprivlib,
100 \$installarchlib, \$installsitelib, \$installsitearch,
102 $$_ = unixify($$_); $$_ =~ s:/$::;
106 # Do some quick sanity checks.
108 if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
110 $installbin || die "No installbin directory in config.sh\n";
111 -d $installbin || mkpath($installbin, 1, 0777);
112 -d $installbin || $nonono || die "$installbin is not a directory\n";
113 -w $installbin || $nonono || die "$installbin is not writable by you\n"
114 unless $installbin =~ m#^/afs/# || $nonono;
116 -x 'perl' . $exe_ext || die "perl isn't executable!\n";
117 -x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid;
119 -x 't/TEST' || $Is_W32
120 || warn "WARNING: You've never run 'make test'!!!",
121 " (Installing anyway.)\n";
125 $perldll = 'perl.' . $dlext;
126 $perldll = 'perlcore.' . $dlext if $Config{'ccflags'} =~ /PERL_OBJECT/i;
128 -f $perldll || die "No perl DLL built\n";
132 safe_unlink("$installbin/$perldll");
133 copy("$perldll", "$installbin/$perldll");
134 chmod(0755, "$installbin/$perldll");
137 # This will be used to store the packlist
138 $packlist = ExtUtils::Packlist->new("$installarchlib/.packlist");
140 # First we install the version-numbered executables.
143 safe_unlink("$installbin/$perl$exe_ext");
144 copy("perl$exe_ext", "$installbin/$perl$exe_ext");
145 chmod(0755, "$installbin/$perl$exe_ext");
146 safe_unlink("$installbin/${perl}shr$exe_ext");
147 copy("perlshr$exe_ext", "$installbin/${perl}shr$exe_ext");
148 chmod(0755, "$installbin/${perl}shr$exe_ext");
150 elsif ($^O ne 'dos') {
151 safe_unlink("$installbin/$perl$ver$exe_ext");
152 copy("perl$exe_ext", "$installbin/$perl$ver$exe_ext");
153 chmod(0755, "$installbin/$perl$ver$exe_ext");
155 safe_unlink("$installbin/$perl.exe");
156 copy("perl.exe", "$installbin/$perl.exe");
159 safe_unlink("$installbin/s$perl$ver$exe_ext");
161 copy("suidperl$exe_ext", "$installbin/s$perl$ver$exe_ext");
162 chmod(04711, "$installbin/s$perl$ver$exe_ext");
165 # Install library files.
167 $do_installarchlib = $do_installprivlib = 0;
169 mkpath($installprivlib, 1, 0777);
170 mkpath($installarchlib, 1, 0777);
171 mkpath($installsitelib, 1, 0777) if ($installsitelib);
172 mkpath($installsitearch, 1, 0777) if ($installsitearch);
175 $do_installarchlib = ! samepath($installarchlib, '.');
176 $do_installprivlib = ! samepath($installprivlib, '.');
177 $do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$]/);
179 if ($do_installarchlib || $do_installprivlib) {
180 find(\&installlib, '.');
182 chdir ".." || die "Can't cd back to source directory: $!\n";
185 warn "Can't cd to lib to install lib files: $!\n";
188 # Install header files and libraries.
189 mkpath("$installarchlib/CORE", 1, 0777);
190 if ($Is_VMS) { # We did core file selection during build
191 my $coredir = "lib/$Config{'arch'}/$]";
193 @corefiles = <$coredir/*.*>;
196 @corefiles = <*.h libperl*.*>;
197 # AIX needs perl.exp installed as well.
198 push(@corefiles,'perl.exp') if $^O eq 'aix';
199 # If they have built sperl.o...
200 push(@corefiles,'sperl.o') if -f 'sperl.o';
202 foreach $file (@corefiles) {
203 # HP-UX (at least) needs to maintain execute permissions
204 # on dynamically-loadable libraries. So we do it for all.
205 copy_if_diff($file,"$installarchlib/CORE/$file")
206 and chmod($file =~ /\.(so|\Q$dlext\E)$/ ? 0555 : 0444,
207 "$installarchlib/CORE/$file");
210 # Install main perl executables
211 # Make links to ordinary names if installbin directory isn't current directory.
213 if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS) {
214 safe_unlink("$installbin/$perl$exe_ext", "$installbin/suid$perl$exe_ext");
215 link("$installbin/$perl$ver$exe_ext", "$installbin/$perl$exe_ext");
216 link("$installbin/s$perl$ver$exe_ext", "$installbin/suid$perl$exe_ext")
220 # Offer to install perl in a "standard" location
222 $mainperl_is_instperl = 0;
224 if (!$versiononly && !$nonono && !$Is_W32 && !$Is_VMS && -t STDIN && -t STDERR
225 && -w $mainperldir && ! samepath($mainperldir, $installbin)) {
226 local($usrbinperl) = "$mainperldir/$perl$exe_ext";
227 local($instperl) = "$installbin/$perl$exe_ext";
228 local($expinstperl) = "$binexp/$perl$exe_ext";
230 # First make sure $usrbinperl is not already the same as the perl we
232 if (-x $usrbinperl) {
233 # Try to be clever about mainperl being a symbolic link
234 # to binexp/perl if binexp and installbin are different.
235 $mainperl_is_instperl =
236 samepath($usrbinperl, $instperl) ||
237 samepath($usrbinperl, $expinstperl) ||
238 (($binexp ne $installbin) &&
240 ((readlink $usrbinperl) eq $expinstperl));
242 if ((! $mainperl_is_instperl) &&
243 (yn("Many scripts expect perl to be installed as $usrbinperl.\n" .
244 "Do you wish to have $usrbinperl be the same as\n" .
245 "$expinstperl? [y] ")))
248 eval { CORE::link $instperl, $usrbinperl } ||
249 eval { symlink $expinstperl, $usrbinperl } ||
250 copy($instperl, $usrbinperl);
251 $mainperl_is_instperl = 1;
255 # Make links to ordinary names if installbin directory isn't current directory.
257 if (!$versiononly && ! samepath($installbin, 'x2p')) {
258 safe_unlink("$installbin/a2p$exe_ext");
259 copy("x2p/a2p$exe_ext", "$installbin/a2p$exe_ext");
260 chmod(0755, "$installbin/a2p$exe_ext");
263 # cppstdin is just a script, but it is architecture-dependent, so
264 # it can't safely be shared. Place it in $installbin.
265 # Note that Configure doesn't build cppstin if it isn't needed, so
266 # we skip this if cppstdin doesn't exist.
267 if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) {
268 safe_unlink("$installbin/cppstdin");
269 copy("cppstdin", "$installbin/cppstdin");
270 chmod(0755, "$installbin/cppstdin");
275 mkpath($installscript, 1, 0777);
277 if (! $versiononly) {
279 (my $base = $_) =~ s#.*/##;
280 copy($_, "$installscript/$base");
281 chmod(0755, "$installscript/$base");
285 # pstruct should be a link to c2ph
287 if (! $versiononly) {
288 safe_unlink("$installscript/pstruct$scr_ext");
289 if ($^O eq 'dos' or $Is_VMS) {
290 copy("$installscript/c2ph$scr_ext", "$installscript/pstruct$scr_ext");
292 link("$installscript/c2ph$scr_ext", "$installscript/pstruct$scr_ext");
296 # Install pod pages. Where? I guess in $installprivlib/pod.
298 if (! $versiononly || !($installprivlib =~ m/\Q$]/)) {
299 mkpath("${installprivlib}/pod", 1, 0777);
301 # If Perl 5.003's perldiag.pod is there, rename it.
302 if (open POD, "${installprivlib}/pod/perldiag.pod") {
305 # Some of Perl 5.003's diagnostic messages ended with periods.
307 my ($from, $to) = ("${installprivlib}/pod/perldiag.pod",
308 "${installprivlib}/pod/perldiag-5.003.pod");
309 print STDERR " rename $from $to";
311 or warn "Couldn't rename $from to $to: $!\n"
316 foreach $file (@pods) {
317 # $file is a name like pod/perl.pod
318 copy_if_diff($file, "${installprivlib}/${file}");
321 # Link perldiag.pod into archlib
322 my ($from, $to) = ("${installprivlib}/pod/perldiag.pod",
323 "${installarchlib}/pod/perldiag.pod");
324 $packlist->{$to} = { from => $from, type => 'link' };
325 if (compare($from, $to) || $nonono) {
326 mkpath("${installarchlib}/pod", 1, 0777);
328 link($from, $to) if ($^O ne 'dos');
332 # Check to make sure there aren't other perls around in installer's
333 # path. This is probably UNIX-specific. Check all absolute directories
334 # in the path except for where public executables are supposed to live.
335 # Also skip $mainperl if the user opted to have it be a link to the
340 $dirsep = ($Is_OS2 || $Is_W32) ? ';' : ':' ;
341 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
342 @path = split(/$dirsep/, $path);
345 while (exists $ENV{'DCL$PATH' . $i}) {
346 $dir = unixpath($ENV{'DCL$PATH' . $i}); $dir =~ s-/$--;
353 # Use &samepath here because some systems have other dirs linked
354 # to $mainperldir (like SunOS)
355 next if samepath($_, $binexp);
356 next if ($mainperl_is_instperl && samepath($_, $mainperldir));
357 push(@otherperls, "$_/$perl$exe_ext")
358 if (-x "$_/$perl$exe_ext" && ! -d "$_/$perl$exe_ext");
361 print STDERR "\nWarning: $perl appears in your path in the following " .
362 "locations beyond where\nwe just installed it:\n";
364 print STDERR " ", $_, "\n";
371 $packlist->write() unless $nono;
372 print STDERR " Installation complete\n";
376 ###############################################################################
381 local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
382 print STDERR $prompt;
383 chop($answer = <STDIN>);
384 $answer = $default if $answer =~ m/^\s*$/;
385 ($answer =~ m/^[yY]/);
392 return scalar(@names) if $Is_VMS;
394 foreach $name (@names) {
395 next unless -e $name;
396 chmod 0777, $name if ($Is_OS2 || $Is_W32);
397 print STDERR " unlink $name\n";
398 ( CORE::unlink($name) and ++$cnt
399 or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
405 return if $nonono or $Is_VMS;
407 foreach $name (@names) {
408 next unless -e $name;
409 chmod 0777, $name if ($Is_OS2 || $Is_W32);
410 print STDERR " unlink $name\n";
411 next if CORE::unlink($name);
412 warn "Couldn't unlink $name: $!\n";
414 print STDERR " mv $name $name.old\n";
415 safe_rename($name, "$name.old")
416 or warn "Couldn't rename $name: $!\n";
422 local($from,$to) = @_;
423 if (-f $to and not unlink($to)) {
425 for ($i = 1; $i < 50; $i++) {
426 last if rename($to, "$to.$i");
428 warn("Cannot rename to `$to.$i': $!"), return 0
429 if $i >= 50; # Give up!
431 link($from,$to) || return 0;
439 print STDERR " ln $from $to\n";
441 CORE::link($from, $to)
443 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
444 ? die "AFS" # okay inside eval {}
445 : warn "Couldn't link $from to $to: $!\n"
447 $packlist->{$to} = { from => $from, type => 'link' };
450 print STDERR " creating new version of $to\n" if $Is_VMS and -e $to;
451 File::Copy::copy($from, $to)
453 : warn "Couldn't copy $from to $to: $!\n"
455 $packlist->{$to} = { type => 'file' };
461 local($mode,$name) = @_;
463 return if ($^O eq 'dos');
464 printf STDERR " chmod %o %s\n", $mode, $name;
465 CORE::chmod($mode,$name)
466 || warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name)
473 print STDERR " cp $from $to\n";
474 print STDERR " creating new version of $to\n" if $Is_VMS and -e $to;
475 File::Copy::copy($from, $to)
476 || warn "Couldn't copy $from to $to: $!\n"
478 $packlist->{$to} = { type => 'file' };
482 local($p1, $p2) = @_;
484 return (lc($p1) eq lc($p2)) if $Is_W32;
487 local($dev1, $ino1, $dev2, $ino2);
488 ($dev1, $ino1) = stat($p1);
489 ($dev2, $ino2) = stat($p2);
490 ($dev1 == $dev2 && $ino1 == $ino2);
498 my $dir = $File::Find::dir;
499 $dir =~ s#^\.(?![^/])/?##;
500 local($depth) = $dir ? "lib/$dir" : "lib";
504 if ($name eq 'CVS' && -d $name) {
505 $File::Find::prune = 1;
509 # ignore patch backups and the .exists files.
510 return if $name =~ m{\.orig$|~$|^\.exists};
512 $name = "$dir/$name" if $dir ne '';
514 my $installlib = $installprivlib;
515 if ($dir =~ /^auto/ ||
516 ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) ||
517 ($name =~ /^(.*)\.(?:h|lib)$/i && $Is_W32)
519 $installlib = $installarchlib;
520 return unless $do_installarchlib;
522 return unless $do_installprivlib;
526 if (/\.(?:al|ix)$/ && !($dir =~ m[^auto/(.*)$] && $archpms{$1})) {
527 $installlib = $installprivlib;
528 #We're installing *.al and *.ix files into $installprivlib,
529 #but we have to delete old *.al and *.ix files from the 5.000
531 #This might not work because $archname might have changed.
532 unlink("$installarchlib/$name");
534 $packlist->{"$installlib/$name"} = { type => 'file' };
535 if (compare($_, "$installlib/$name") || $nonono) {
536 unlink("$installlib/$name");
537 mkpath("$installlib/$dir", 1, 0777);
538 # HP-UX (at least) needs to maintain execute permissions
539 # on dynamically-loaded libraries.
540 copy_if_diff($_, "$installlib/$name")
541 and chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444,
542 "$installlib/$name");
545 mkpath("$installlib/$name", 1, 0777);
549 # Copy $from to $to, only if $from is different than $to.
550 # Also preserve modification times for .a libraries.
551 # On some systems, if you do
553 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
554 # and then try to link against the installed libperl.a, you might
555 # get an error message to the effect that the symbol table is older
557 # Return true if copying occurred.
561 -f $from || die "$0: $from not found";
562 $packlist->{$to} = { type => 'file' };
563 if (compare($from, $to) || $nonono) {
564 safe_unlink($to); # In case we don't have write permissions.
566 $from = $depth . "/" . $from if $depth;
569 # Restore timestamps if it's a .a library or for OS/2.
570 if (!$nonono && ($Is_OS2 || $to =~ /\.a$/)) {
571 my ($atime, $mtime) = (stat $from)[8,9];
572 utime $atime, $mtime, $to;