xref: /openbsd-src/gnu/usr.bin/perl/installperl (revision e2a1b4748ac00cfe1e64a346f850b3c670166aef)
1#!./perl
2
3BEGIN {
4    require 5.004;
5    chdir '..' if !-d 'lib' and -d '../lib';
6    @INC = 'lib';
7    $ENV{PERL5LIB} = 'lib';
8}
9
10use strict;
11my ($Is_VMS, $Is_W32, $Is_OS2, $Is_Cygwin, $Is_Darwin,
12    $nonono, $dostrip, $versiononly, $silent, $verbose, $force,
13    $otherperls, $archname, $Is_NetWare, $nwinstall, $nopods);
14use vars qw /$depth/;
15
16BEGIN {
17    $Is_VMS = $^O eq 'VMS';
18    $Is_W32 = $^O eq 'MSWin32';
19    $Is_OS2 = $^O eq 'os2';
20    $Is_Cygwin = $^O eq 'cygwin';
21    $Is_Darwin = $^O eq 'darwin';
22    if ($Is_VMS) { eval 'use VMS::Filespec;' }
23}
24
25my $scr_ext = ($Is_VMS ? '.Com' : $Is_W32 ? '.bat' : '');
26
27use File::Find;
28use File::Compare;
29use File::Copy ();
30use File::Path ();
31use ExtUtils::Packlist;
32use Config;
33use subs qw(unlink link chmod);
34
35if ($Config{d_umask}) {
36    umask(022); # umasks like 077 aren't that useful for installations
37}
38
39$Is_NetWare = $Config{osname} eq 'NetWare';
40if ($Is_NetWare) {
41    $Is_W32 = 0;
42    $scr_ext = '.pl';
43}
44
45# override the ones in the rest of the script
46sub mkpath {
47    File::Path::mkpath(@_) unless $nonono;
48}
49
50my $mainperldir = "/usr/bin";
51my $exe_ext = $Config{exe_ext};
52
53# Allow ``make install PERLNAME=something_besides_perl'':
54my $perl = defined($ENV{PERLNAME}) ? $ENV{PERLNAME} : 'perl';
55
56# This is the base used for versioned names, like "perl5.6.0".
57# It's separate because a common use of $PERLNAME is to install
58# perl as "perl5", if that's used as base for versioned files you
59# get "perl55.6.0".
60my $perl_verbase = defined($ENV{PERLNAME_VERBASE})
61		    ? $ENV{PERLNAME_VERBASE}
62		    : $perl;
63my $dbg = '';
64my $ndbg = '';
65if ( $Is_VMS ) {
66    if ( defined $Config{usevmsdebug} ) {
67        if ( $Config{usevmsdebug} eq 'define' ) {
68            $dbg = 'dbg';
69            $ndbg = 'ndbg';
70        }
71    }
72}
73
74$otherperls = 1;
75my $destdir = '';
76while (@ARGV) {
77    $nonono = 1 if $ARGV[0] eq '-n';
78    $dostrip = 1 if $ARGV[0] eq '-s';
79    $versiononly = 1 if $ARGV[0] eq '-v';
80    $versiononly = 0 if $ARGV[0] eq '+v';
81    $silent = 1 if $ARGV[0] eq '-S';
82    $otherperls = 0 if $ARGV[0] eq '-o';
83    $force = 1 if $ARGV[0] eq '-f';
84    $verbose = 1 if $ARGV[0] eq '-V' || $ARGV [0] eq '-n';
85    $archname = 1 if $ARGV[0] eq '-A';
86    $nwinstall = 1 if $ARGV[0] eq '-netware';
87    $nopods = 1 if $ARGV[0] eq '-p';
88    $destdir = $1 if $ARGV[0] =~ /^-?-destdir=(.*)$/;
89    if ($ARGV[0] eq '-?' or $ARGV[0] =~ /^-?-h/) {
90	print <<"EOT";
91Usage $0: [switches]
92  -n	    Don't actually run any commands; just print them.
93  -s        Run strip on installed binaries.
94  -v        Only install perl as a binary with the version number in the name.
95            (Override whatever config.sh says)
96  +v        Install perl as "perl" and as a binary with the version number in
97            the name.  (Override whatever config.sh says)
98  -S        Silent mode.
99  -f        Force installation (don't check if same version is there)
100  -o        Skip checking for other copies of perl in your PATH.
101  -V        Verbose mode.
102  -A        Also install perl with the architecture's name in the perl binary's
103            name.
104  -p        Don't install the pod files. [This will break use diagnostics;]
105  -netware  Install correctly on a Netware server.
106EOT
107	exit;
108    }
109    shift;
110}
111
112$versiononly = 1 if $Config{versiononly} && !defined $versiononly;
113my (@scripts, @tolink);
114open SCRIPTS, "utils.lst" or die "Can't open utils.lst: $!";
115while (<SCRIPTS>) {
116    next if /^#/;
117    s/\s*#\s*pod\s*=.*//; # install script regardless of pod location
118    next if /a2p/; # a2p is binary, to be installed separately
119    chomp;
120    if (/(\S*)\s*#\s*link\s*=\s*(\S*)/) {
121	push @scripts, $1;
122	push @tolink, [$1, $2];
123    } else {
124	push @scripts, $_;
125    }
126}
127close SCRIPTS;
128
129if ($scr_ext) { @scripts = map { "$_$scr_ext" } @scripts; }
130
131my @pods = $nopods ? () : (<pod/*.pod>);
132
133# Specify here any .pm files that are actually architecture-dependent.
134# (Those included with XS extensions under ext/ are automatically
135# added later.)
136# Now that the default privlib has the full perl version number included,
137# we no longer have to play the trick of sticking version-specific .pm
138# files under the archlib directory.
139my %archpms = (
140    Config => 1,
141    lib => 1,
142    Cwd => 1,
143);
144
145if ($^O eq 'dos') {
146    push(@scripts,'djgpp/fixpmain');
147    $archpms{config} = $archpms{filehand} = 1;
148}
149
150if ((-e "testcompile") && (defined($ENV{'COMPILE'}))) {
151    push(@scripts, map("$_.exe", @scripts));
152}
153
154find(sub {
155    if ("$File::Find::dir/$_" =~ m{^ext\b(.*)/([^/]+)\.pm$}) {
156	my($path, $modname) = ($1,$2);
157
158	# strip trailing component first
159	$path =~ s{/[^/]*$}{};
160
161	# strip optional "/lib";
162	$path =~ s{/lib\b}{};
163
164	# strip any leading /
165	$path =~ s{^/}{};
166
167	# reconstitute canonical module name
168	$modname = "$path/$modname" if length $path;
169
170	# remember it
171	$archpms{$modname} = 1;
172    }
173}, 'ext');
174
175# print "[$_]\n" for sort keys %archpms;
176
177my $ver = $Config{version};
178my $release = substr($],0,3);   # Not used currently.
179my $patchlevel = substr($],3,2);
180die "Patchlevel of perl ($patchlevel)",
181    "and patchlevel of config.sh ($Config{'PERL_VERSION'}) don't match\n"
182	if $patchlevel != $Config{'PERL_VERSION'};
183
184# Fetch some frequently-used items from %Config
185my $installbin = "$destdir$Config{installbin}";
186my $installscript = "$destdir$Config{installscript}";
187my $installprivlib = "$destdir$Config{installprivlib}";
188my $installarchlib = "$destdir$Config{installarchlib}";
189my $installsitelib = "$destdir$Config{installsitelib}";
190my $installsitearch = "$destdir$Config{installsitearch}";
191my $installman1dir = "$destdir$Config{installman1dir}";
192my $man1ext = $Config{man1ext};
193my $libperl = $Config{libperl};
194# Shared library and dynamic loading suffixes.
195my $so = $Config{so};
196my $dlext = $Config{dlext};
197my $dlsrc = $Config{dlsrc};
198if ($^O eq 'os390') {
199    my $pwd;
200    chomp($pwd=`pwd`);
201    my $archlibexp = $Config{archlibexp};
202    my $usedl = $Config{usedl};
203    if ($usedl eq 'define') {
204	`./$^X -pibak -e 's{$pwd\/libperl.x}{$archlibexp/CORE/libperl.x}' lib/Config.pm`;
205    }
206}
207
208if ($nwinstall) {
209    # This is required only if we are installing on a NetWare server
210    $installscript = $Config{installnwscripts};
211    $installprivlib = $Config{installnwlib};
212    $installarchlib = $Config{installnwlib};
213    $installsitelib = $Config{installnwlib};
214}
215
216my $d_dosuid = $Config{d_dosuid};
217my $binexp = $Config{binexp};
218
219if ($Is_VMS) {  # Hang in there until File::Spec hits the big time
220    foreach ( \$installbin,     \$installscript,  \$installprivlib,
221	      \$installarchlib, \$installsitelib, \$installsitearch,
222	      \$installman1dir ) {
223	$$_ = unixify($$_);  $$_ =~ s:/$::;
224    }
225}
226
227# Do some quick sanity checks.
228
229if (!$nonono && $d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
230
231   $installbin		|| die "No installbin directory in config.sh\n";
232-d $installbin		|| mkpath($installbin, $verbose, 0777);
233-d $installbin		|| $nonono || die "$installbin is not a directory\n";
234-w $installbin		|| $nonono || die "$installbin is not writable by you\n"
235	unless $installbin =~ m#^/afs/# || $nonono;
236
237if (!$Is_NetWare) {
238if (!$Is_VMS) {
239-x 'perl' . $exe_ext	|| die "perl isn't executable!\n";
240}
241else {
242-x $ndbg . 'perl' . $exe_ext	|| die "${ndbg}perl$exe_ext isn't executable!\n";
243    if ($dbg) {
244        -x $dbg . 'perl' . $exe_ext	|| die "${dbg}perl$exe_ext isn't executable!\n";
245    }
246}
247-x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid;
248
249#-f 't/rantests'		|| $Is_W32
250#			|| warn "WARNING: You've never run 'make test' or",
251#				" some tests failed! (Installing anyway.)\n";
252} #if (!$Is_NetWare)
253
254if (($Is_W32 and ! $Is_NetWare) or $Is_Cygwin) {
255    my $perldll;
256
257    if ($Is_Cygwin) {
258	$perldll = $libperl;
259	my $v_e_r_s = $ver; $v_e_r_s =~ tr/./_/;
260	$perldll =~ s/(\..*)?$/$v_e_r_s.$dlext/;
261	$perldll =~ s/^lib/cyg/;
262	if ($Config{useshrplib} eq 'true') {
263	    # install ld2 and perlld as well
264	    foreach ('ld2', 'perlld') {
265		safe_unlink("$installbin/$_");
266		copy("$_", "$installbin/$_");
267		chmod(0755, "$installbin/$_");
268	    };
269	    open (LD2, ">$installbin/ld2");
270	    print LD2 <<SHELL;
271#!/bin/sh
272#
273# ld wrapper, passes all args to perlld;
274#
275for trythis in $installbin/perl
276do
277  if [ -x \$trythis ]
278  then
279    \$trythis $installbin/perlld "\$\@"
280    exit \$?
281  fi
282done
283# hard luck!
284echo I see no perl executable around there
285echo perl is required to build dynamic libraries
286echo look if the path to perl in /bin/ld2 is correct
287exit 1
288SHELL
289	    close LD2;
290	    chmod(0755, "$installbin/ld2");
291	};
292    } else {
293	$perldll = 'perl58.' . $dlext;
294    }
295
296    if ($dlsrc ne "dl_none.xs") {
297	-f $perldll || die "No perl DLL built\n";
298    }
299
300    # Install the DLL
301    safe_unlink("$installbin/$perldll");
302    copy("$perldll", "$installbin/$perldll");
303    chmod(0755, "$installbin/$perldll");
304} # if (($Is_W32 and ! $Is_NetWare) or $Is_Cygwin)
305
306# This will be used to store the packlist
307my $packlist = ExtUtils::Packlist->new("$installarchlib/.packlist");
308
309# Get the install command and flags from the environment
310my @installcmd = $ENV{"INSTALL"} || "install";
311push(@installcmd, $ENV{"INSTALL_COPY"} || "-c");
312
313# First we install the version-numbered executables.
314
315if ($Is_VMS) {
316    safe_unlink("$installbin/perl_setup.com");
317    copy("perl_setup.com", "$installbin/perl_setup.com");
318    chmod(0755, "$installbin/perl_setup.com");
319    safe_unlink("$installbin/$dbg$perl$exe_ext");
320    copy("$dbg$perl$exe_ext", "$installbin/$dbg$perl$exe_ext");
321    chmod(0755, "$installbin/$dbg$perl$exe_ext");
322    safe_unlink("$installbin/$dbg${perl}shr$exe_ext");
323    copy("$dbg${perl}shr$exe_ext", "$installbin/$dbg${perl}shr$exe_ext");
324    chmod(0755, "$installbin/$dbg${perl}shr$exe_ext");
325    if ($ndbg) {
326        safe_unlink("$installbin/$ndbg$perl$exe_ext");
327        copy("$ndbg$perl$exe_ext", "$installbin/$ndbg$perl$exe_ext");
328        chmod(0755, "$installbin/$ndbg$perl$exe_ext");
329	safe_unlink("$installbin/${dbg}a2p$exe_ext");
330	copy("x2p/${dbg}a2p$exe_ext", "$installbin/${dbg}a2p$exe_ext");
331	chmod(0755, "$installbin/${dbg}a2p$exe_ext");
332    }
333}
334elsif ($^O eq 'mpeix') {
335    # MPE lacks hard links and requires that executables with special
336    # capabilities reside in the MPE namespace.
337    safe_unlink("$installbin/perl$ver$exe_ext", $Config{perlpath});
338    # Install the primary executable into the MPE namespace as perlpath.
339    copy("perl$exe_ext", $Config{perlpath});
340    chmod(0755, $Config{perlpath});
341    # Create a backup copy with the version number.
342    link($Config{perlpath}, "$installbin/perl$ver$exe_ext");
343}
344elsif ($^O ne 'dos') {
345    if (!$Is_NetWare) {
346	install("perl$exe_ext", "$installbin/$perl_verbase$ver$exe_ext",
347	    "0755", $dostrip);
348    }
349    else {
350	# If installing onto a NetWare server
351	if ($nwinstall) {
352	    # Copy perl.nlm, echo.nlm, type.nlm, a2p.nlm & cgi2perl.nlm
353	    mkpath($Config{installnwsystem}, 1, 0777);
354	    copy("netware\\".$ENV{'MAKE_TYPE'}."\\perl.nlm", $Config{installnwsystem});
355	    copy("netware\\testnlm\\echo\\echo.nlm", $Config{installnwsystem});
356	    copy("netware\\testnlm\\type\\type.nlm", $Config{installnwsystem});
357	    copy("x2p\\a2p.nlm", $Config{installnwsystem});
358	    chmod(0755, "$Config{installnwsystem}\\perl.nlm");
359	    mkpath($Config{installnwlcgi}, 1, 0777);
360	    copy("lib\\auto\\cgi2perl\\cgi2perl.nlm", $Config{installnwlcgi});
361	}
362    } #if (!$Is_NetWare)
363}
364else {
365    safe_unlink("$installbin/$perl.exe");
366    copy("perl.exe", "$installbin/$perl.exe");
367}
368
369safe_unlink("$installbin/s$perl_verbase$ver$exe_ext");
370if ($d_dosuid) {
371    install("perl$exe_ext", "$installbin/s$perl_verbase$ver$exe_ext",
372	"04711", $dostrip);
373}
374
375# Install library files.
376
377my ($do_installarchlib, $do_installprivlib) = (0, 0);
378
379mkpath($installprivlib, $verbose, 0777);
380mkpath($installarchlib, $verbose, 0777);
381mkpath($installsitelib, $verbose, 0777) if ($installsitelib);
382mkpath($installsitearch, $verbose, 0777) if ($installsitearch);
383
384if (chdir "lib") {
385    $do_installarchlib = ! samepath($installarchlib, '.');
386    $do_installprivlib = ! samepath($installprivlib, '.');
387    $do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$ver/);
388
389    if ($do_installarchlib || $do_installprivlib) {
390	find(\&installlib, '.');
391    }
392    chdir ".." || die "Can't cd back to source directory: $!\n";
393}
394else {
395    warn "Can't cd to lib to install lib files: $!\n";
396}
397
398# Install header files and libraries.
399mkpath("$installarchlib/CORE", $verbose, 0777);
400my @corefiles;
401if ($Is_VMS) {  # We did core file selection during build
402    my $coredir = "lib/$Config{archname}/$ver/CORE";
403    $coredir =~ tr/./_/;
404    map { s|^$coredir/||i; } @corefiles = <$coredir/*.*>;
405}
406else {
407    # [als] hard-coded 'libperl' name... not good!
408    #@corefiles = <*.h *.inc libperl*.*>;
409    @corefiles = <*.h *.inc>;
410    push(@corefiles,<libperl*.*>) unless defined($ENV{"NOLIBINSTALL"});
411
412    # AIX needs perl.exp installed as well.
413    push(@corefiles,'perl.exp') if $^O eq 'aix';
414    if ($^O eq 'mpeix') {
415	# MPE needs mpeixish.h installed as well.
416	mkpath("$installarchlib/CORE/mpeix", $verbose, 0777);
417	push(@corefiles,'mpeix/mpeixish.h');
418    }
419    # If they have built sperl.o...
420    push(@corefiles,'sperl.o') if -f 'sperl.o';
421}
422foreach my $file (@corefiles) {
423    # HP-UX (at least) needs to maintain execute permissions
424    # on dynamically-loadable libraries. So we do it for all.
425    if (copy_if_diff($file,"$installarchlib/CORE/$file")) {
426	if ($file =~ /\.(\Q$so\E|\Q$dlext\E)$/) {
427	    strip("-S", "$installarchlib/CORE/$file") if $^O =~ /^(rhapsody|darwin)$/;
428	    chmod(0555, "$installarchlib/CORE/$file");
429	} else {
430	    chmod(0444, "$installarchlib/CORE/$file");
431	}
432    }
433}
434
435# Switch in the 5.005-threads versions of he threadsafe queue and semaphore
436# modules if so needed.
437if ($Config{use5005threads}) {
438    for my $m (qw(Queue Semaphore)) {
439	install("ext/Thread/$m.pmx", "$installprivlib/Thread/$m.pm", "0444");
440    }
441}
442
443# Install main perl executables
444# Make links to ordinary names if installbin directory isn't current directory.
445
446if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS && ! $Is_NetWare) {
447    safe_unlink("$installbin/$perl$exe_ext", "$installbin/suid$perl$exe_ext");
448    if ($^O eq 'mpeix') {
449	# MPE doesn't support hard links, so use a symlink.
450	# We don't want another cloned copy.
451	symlink($Config{perlpath}, "$installbin/perl$exe_ext");
452    } elsif ($^O eq 'vos') {
453	# VOS doesn't support hard links, so use a symlink.
454	symlink("$installbin/$perl_verbase$ver$exe_ext",
455		"$installbin/$perl$exe_ext");
456    } else {
457	link("$installbin/$perl_verbase$ver$exe_ext",
458		"$installbin/$perl$exe_ext");
459    }
460    link("$installbin/s$perl_verbase$ver$exe_ext",
461	    "$installbin/suid$perl$exe_ext")
462      if $d_dosuid;
463}
464
465# For development purposes it can be very useful to have multiple perls
466# build for different "architectures" (eg threading or not) simultaneously.
467if ($archname && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS) {
468    my $archperl = "$perl_verbase$ver-$Config{archname}$exe_ext";
469    safe_unlink("$installbin/$archperl");
470    if ($^O eq 'mpeix') {
471	# MPE doesn't support hard links, so use a symlink.
472	# We don't want another cloned copy.
473	symlink($Config{perlpath}, "$installbin/$archperl");
474    } elsif ($^O eq 'vos') {
475	# VOS doesn't support hard links, so use a symlink.
476	symlink("$installbin/$perl_verbase$ver$exe_ext",
477		"$installbin/$archperl");
478    } else {
479	link("$installbin/$perl_verbase$ver$exe_ext", "$installbin/$archperl");
480    }
481}
482
483# Offer to install perl in a "standard" location
484
485my $mainperl_is_instperl = 0;
486
487if ($Config{installusrbinperl} && $Config{installusrbinperl} eq 'define' &&
488    !$versiononly && !$nonono && !$Is_W32 && !$Is_NetWare && !$Is_VMS && -t STDIN && -t STDERR
489	&& -w $mainperldir && ! samepath($mainperldir, $installbin)) {
490    my($usrbinperl)	= "$mainperldir/$perl$exe_ext";
491    my($instperl)	= "$installbin/$perl$exe_ext";
492    my($expinstperl)	= "$binexp/$perl$exe_ext";
493
494    # First make sure $usrbinperl is not already the same as the perl we
495    # just installed.
496    if (-x $usrbinperl) {
497	# Try to be clever about mainperl being a symbolic link
498	# to binexp/perl if binexp and installbin are different.
499	$mainperl_is_instperl =
500	    samepath($usrbinperl, $instperl) ||
501	    samepath($usrbinperl, $expinstperl) ||
502	     (($binexp ne $installbin) &&
503	      (-l $usrbinperl) &&
504	      ((readlink $usrbinperl) eq $expinstperl));
505    }
506    if (! $mainperl_is_instperl) {
507	unlink($usrbinperl);
508	( $Config{'d_link'} eq 'define' &&
509	  eval { CORE::link $instperl, $usrbinperl } )	||
510	eval { symlink $expinstperl, $usrbinperl }	||
511	copy($instperl, $usrbinperl);
512
513	$mainperl_is_instperl = 1;
514    }
515}
516
517# Make links to ordinary names if installbin directory isn't current directory.
518if (!$Is_NetWare && $dbg eq '') {
519    if (! samepath($installbin, 'x2p')) {
520	my $base = 'a2p';
521	$base .= $ver if $versiononly;
522	safe_unlink("$installbin/$base$exe_ext");
523	copy("x2p/a2p$exe_ext", "$installbin/$base$exe_ext");
524	strip("$installbin/$base$exe_ext");
525	chmod(0755, "$installbin/$base$exe_ext");
526    }
527}
528
529# cppstdin is just a script, but it is architecture-dependent, so
530# it can't safely be shared.  Place it in $installbin.
531# Note that Configure doesn't build cppstin if it isn't needed, so
532# we skip this if cppstdin doesn't exist.
533if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) {
534    safe_unlink("$installbin/cppstdin");
535    copy("cppstdin", "$installbin/cppstdin");
536    chmod(0755, "$installbin/cppstdin");
537}
538
539sub script_alias {
540    my ($installscript, $orig, $alias, $scr_ext) = @_;
541
542    safe_unlink("$installscript/$alias$scr_ext");
543    if ($^O eq 'dos' or $Is_VMS or $^O eq 'transit') {
544	copy("$installscript/$orig$scr_ext",
545	     "$installscript/$alias$scr_ext");
546    } elsif ($^O eq 'vos') {
547	symlink("$installscript/$orig$scr_ext",
548		"$installscript/$alias$scr_ext");
549    } else {
550	link("$installscript/$orig$scr_ext",
551	     "$installscript/$alias$scr_ext");
552    }
553}
554
555# Install scripts.
556mkpath($installscript, $verbose, 0777);
557if ($versiononly) {
558    for (@scripts) {
559	(my $base = $_) =~ s#.*/##;
560	$base .= $ver;
561	copy($_,    "$installscript/$base");
562	chmod(0755, "$installscript/$base");
563    }
564
565    for (@tolink) {
566	my ($from, $to) = map { "$_$ver" } @$_;
567	(my $frbase = $from) =~ s#.*/##;
568	(my $tobase = $to) =~ s#.*/##;
569	script_alias($installscript, $frbase, $tobase, $scr_ext);
570    }
571} else {
572    for (@scripts) {
573	(my $base = $_) =~ s#.*/##;
574	copy($_, "$installscript/$base");
575	chmod(0755, "$installscript/$base");
576    }
577
578    for (@tolink) {
579	my ($from, $to) = @$_;
580	(my $frbase = $from) =~ s#.*/##;
581	(my $tobase = $to) =~ s#.*/##;
582	script_alias($installscript, $frbase, $tobase, $scr_ext);
583    }
584}
585
586# Install pod pages.  Where? I guess in $installprivlib/pod
587# ($installprivlib/pods for cygwin).
588
589my $pod = ($Is_Cygwin || $Is_Darwin) ? 'pods' : 'pod';
590if ( !$versiononly || ($installprivlib =~ m/\Q$ver/)) {
591    mkpath("${installprivlib}/$pod", $verbose, 0777);
592
593    # If Perl 5.003's perldiag.pod is there, rename it.
594    if (open POD, "${installprivlib}/$pod/perldiag.pod") {
595	read POD, $_, 4000;
596	close POD;
597	# Some of Perl 5.003's diagnostic messages ended with periods.
598	if (/^=.*\.$/m) {
599	    my ($from, $to) = ("${installprivlib}/$pod/perldiag.pod",
600			       "${installprivlib}/$pod/perldiag-5.003.pod");
601	    print "  rename $from $to";
602	    rename($from, $to)
603		or warn "Couldn't rename $from to $to: $!\n"
604		unless $nonono;
605	}
606    }
607
608    for (@pods) {
609	# $_ is a name like  pod/perl.pod
610	(my $base = $_) =~ s#.*/##;
611	copy_if_diff($_, "${installprivlib}/$pod/${base}");
612    }
613
614}
615
616# Check to make sure there aren't other perls around in installer's
617# path.  This is probably UNIX-specific.  Check all absolute directories
618# in the path except for where public executables are supposed to live.
619# Also skip $mainperl if the user opted to have it be a link to the
620# installed perl.
621
622if (!$versiononly && $otherperls) {
623    my ($path, @path);
624    my $dirsep = ($Is_OS2 || $Is_W32 || $Is_NetWare) ? ';' : ':' ;
625    ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
626    @path = split(/$dirsep/, $path);
627    if ($Is_VMS) {
628	my $i = 0;
629	while (exists $ENV{'DCL$PATH' . $i}) {
630	    my $dir = unixpath($ENV{'DCL$PATH' . $i});  $dir =~ s-/$--;
631	    push(@path,$dir);
632	}
633    }
634    my @otherperls;
635    my %otherperls;
636    for (@path) {
637	next unless m,^/,;
638	# Use &samepath here because some systems have other dirs linked
639	# to $mainperldir (like SunOS)
640	next if samepath($_, $binexp);
641	next if ($mainperl_is_instperl && samepath($_, $mainperldir));
642	my $otherperl = "$_/$perl$exe_ext";
643	next if $otherperls{$otherperl}++;
644	push(@otherperls, $otherperl)
645	    if (-x $otherperl && ! -d $otherperl);
646    }
647    if (@otherperls) {
648	warn "\nWarning: $perl appears in your path in the following " .
649	    "locations beyond where\nwe just installed it:\n";
650	for (@otherperls) {
651	    warn "    ", $_, "\n";
652	}
653	warn "\n";
654    }
655
656}
657
658$packlist->write() unless $nonono;
659print "  Installation complete\n" if $verbose;
660
661exit 0;
662
663###############################################################################
664
665sub yn {
666    my($prompt) = @_;
667    my($answer);
668    my($default) = $prompt =~ m/\[([yn])\]\s*$/i;
669    print STDERR $prompt;
670    chop($answer = <STDIN>);
671    $answer = $default if $answer =~ m/^\s*$/;
672    ($answer =~ m/^[yY]/);
673}
674
675sub unlink {
676    my(@names) = @_;
677    my($cnt) = 0;
678
679    return scalar(@names) if $Is_VMS;
680
681    foreach my $name (@names) {
682	next unless -e $name;
683	chmod 0777, $name if ($Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare);
684	print "  unlink $name\n" if $verbose;
685	( CORE::unlink($name) and ++$cnt
686	  or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
687    }
688    return $cnt;
689}
690
691sub safe_unlink {
692    return if $nonono or $Is_VMS;
693    my @names = @_;
694    foreach my $name (@names) {
695	next unless -e $name;
696	chmod 0777, $name if ($Is_OS2 || $Is_W32 || $Is_NetWare);
697	print "  unlink $name\n" if $verbose;
698	next if CORE::unlink($name);
699	warn "Couldn't unlink $name: $!\n";
700	if ($! =~ /busy/i) {
701	    print "  mv $name $name.old\n" if $verbose;
702	    safe_rename($name, "$name.old")
703		or warn "Couldn't rename $name: $!\n";
704	}
705    }
706}
707
708sub safe_rename {
709    my($from,$to) = @_;
710    if (-f $to and not unlink($to)) {
711	my($i);
712	for ($i = 1; $i < 50; $i++) {
713	    last if rename($to, "$to.$i");
714	}
715	warn("Cannot rename to `$to.$i': $!"), return 0
716	   if $i >= 50;	# Give up!
717    }
718    link($from,$to) || return 0;
719    unlink($from);
720}
721
722sub link {
723    my($from,$to) = @_;
724    my($success) = 0;
725
726    my $xfrom = $from;
727    $xfrom =~ s/^\Q$destdir\E// if $destdir;
728    my $xto = $to;
729    $xto =~ s/^\Q$destdir\E// if $destdir;
730    print $verbose ? "  ln $xfrom $xto\n" : "  $xto\n" unless $silent;
731    eval {
732	CORE::link($from, $to)
733	    ? $success++
734	    : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
735	      ? die "AFS"  # okay inside eval {}
736	      : die "Couldn't link $from to $to: $!\n"
737	  unless $nonono;
738	$packlist->{$xto} = { from => $xfrom, type => 'link' };
739    };
740    if ($@) {
741	warn $@;
742	print $verbose ? "  cp $from $xto\n" : "  $xto\n" unless $silent;
743	print "  creating new version of $xto\n"
744		 if $Is_VMS and -e $to and !$silent;
745	File::Copy::copy($from, $to)
746	    ? $success++
747	    : warn "Couldn't copy $from to $to: $!\n"
748	  unless $nonono;
749	$packlist->{$xto} = { type => 'file' };
750    }
751    $success;
752}
753
754sub chmod {
755    my($mode,$name) = @_;
756
757    return if ($^O eq 'dos');
758    printf "  chmod %o %s\n", $mode, $name if $verbose;
759    CORE::chmod($mode,$name)
760	|| warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name)
761      unless $nonono;
762}
763
764sub copy {
765    my($from,$to) = @_;
766
767    my $xto = $to;
768    $xto =~ s/^\Q$destdir\E// if $destdir;
769    print $verbose ? "  cp $from $xto\n" : "  $xto\n" unless $silent;
770    print "  creating new version of $xto\n" if $Is_VMS and -e $to and !$silent;
771    File::Copy::copy($from, $to)
772	|| warn "Couldn't copy $from to $to: $!\n"
773      unless $nonono;
774    $packlist->{$xto} = { type => 'file' };
775}
776
777sub install {
778    my($from,$to,$mode,$strip) = @_;
779
780    my $xto = $to;
781    my $cmd = join(' ', @installcmd);
782    $cmd .= " -m $mode" if $mode;
783    $cmd .= " -s" if $strip;
784    $cmd .= " $from $to";
785    $xto =~ s/^\Q$destdir\E// if $destdir;
786    print $verbose ? "  install $from $xto\n" : "  $xto\n" unless $silent;
787    unless ($nonono) {
788	system($cmd);
789	warn "Couldn't $cmd\n" if $?;
790    }
791    $packlist->{$xto} = { type => 'file' };
792}
793
794sub samepath {
795    my($p1, $p2) = @_;
796
797    return (lc($p1) eq lc($p2)) if ($Is_W32 || $Is_NetWare);
798
799    if ($p1 ne $p2) {
800	my($dev1, $ino1, $dev2, $ino2);
801	($dev1, $ino1) = stat($p1);
802	($dev2, $ino2) = stat($p2);
803	($dev1 == $dev2 && $ino1 == $ino2);
804    }
805    else {
806	1;
807    }
808}
809
810sub installlib {
811    my $dir = $File::Find::dir;
812    $dir =~ s#^\.(?![^/])/?##;
813    local($depth) = $dir ? "lib/$dir" : "lib";
814
815    my $name = $_;
816
817    # Ignore version control directories.
818    if (($name eq 'CVS' or $name eq 'RCS' or $name eq '.svn') and -d $name) {
819	$File::Find::prune = 1;
820	return;
821    }
822
823    # ignore patch backups, RCS files, emacs backup & temp files and the
824    # .exists files, .PL files, and test files.
825    return if $name =~ m{\.orig$|\.rej$|~$|^#.+#$|,v$|^\.exists|\.PL$|\.plc$|\.t$|^test\.pl$} ||
826	      $dir  =~ m{/t(?:/|$)};
827    # ignore the cpan script in lib/CPAN/bin (installed later with other utils)
828    return if $name eq 'cpan';
829    # ignore the Makefiles
830    return if $name =~ /^makefile$/i;
831    # ignore the test extensions
832    return if $dir =~ m{ext/XS/(?:APItest|Typemap)/};
833
834    $name = "$dir/$name" if $dir ne '';
835
836    my $installlib = $installprivlib;
837    if ($dir =~ /^auto/ ||
838	  ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) ||
839	  ($name =~ /^(.*)\.(?:h|lib)$/i && ($Is_W32 || $Is_NetWare))
840       ) {
841	$installlib = $installarchlib;
842	return unless $do_installarchlib;
843    } else {
844	return unless $do_installprivlib;
845    }
846
847    if (-f $_) {
848	if (/\.(?:al|ix)$/ && !($dir =~ m[^auto/(.*)$] && $archpms{$1})) {
849	    $installlib = $installprivlib;
850	    #We're installing *.al and *.ix files into $installprivlib,
851	    #but we have to delete old *.al and *.ix files from the 5.000
852	    #distribution:
853	    #This might not work because $archname might have changed.
854	    unlink("$installarchlib/$name");
855	}
856	my $xname = "$installlib/$name";
857	$xname =~ s/^\Q$destdir\E// if $destdir;
858	$packlist->{$xname} = { type => 'file' };
859	if ($force || compare($_, "$installlib/$name") || $nonono) {
860	    unlink("$installlib/$name");
861	    mkpath("$installlib/$dir", $verbose, 0777);
862	    # HP-UX (at least) needs to maintain execute permissions
863	    # on dynamically-loaded libraries.
864	    if ($Is_NetWare && !$nwinstall) {
865		# Don't copy .nlp,.nlm files, doesn't make sense on Windows and also
866		# if copied will give problems when building new extensions.
867		# Has to be copied if we are installing on a NetWare server and hence
868		# the check !$nwinstall
869		if (!(/\.(?:nlp|nlm|bs)$/)) {
870		    copy_if_diff($_, "$installlib/$name")
871			and chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444,
872				  "$installlib/$name");
873		}
874	   } else {
875		if (copy_if_diff($_, "$installlib/$name")) {
876		    if ($name =~ /\.(so|$dlext)$/o) {
877			strip("-S", "$installlib/$name") if $^O =~ /^(rhapsody|darwin)$/;
878			chmod(0555, "$installlib/$name");
879		    } else {
880			strip("-S", "$installlib/$name")
881			    if ($name =~ /\.a$/o and $^O =~ /^(rhapsody|darwin)$/);
882			chmod(0444, "$installlib/$name");
883		    }
884		}
885	    } #if ($Is_NetWare)
886	}
887    }
888}
889
890# Copy $from to $to, only if $from is different than $to.
891# Also preserve modification times for .a libraries.
892# On some systems, if you do
893#   ranlib libperl.a
894#   cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
895# and then try to link against the installed libperl.a, you might
896# get an error message to the effect that the symbol table is older
897# than the library.
898# Return true if copying occurred.
899
900sub copy_if_diff {
901    my($from,$to)=@_;
902    return 1 if (($^O eq 'VMS') && (-d $from));
903    my $xto = $to;
904    $xto =~ s/^\Q$destdir\E// if $destdir;
905    my $perlpodbadsymlink;
906    if ($from =~ m!^pod/perl[\w-]+\.pod$! &&
907	-l $from &&
908	! -e $from) {
909	# Some Linux implementations have problems traversing over
910	# multiple symlinks (when going over NFS?) and fail to read
911	# the symlink target.  Combine this with the fact that some
912	# of the pod files (the perl$OS.pod) are symlinks (to ../README.$OS),
913	# and you end up with those pods not getting installed.
914	$perlpodbadsymlink = 1;
915    }
916    -f $from || $perlpodbadsymlink || warn "$0: $from not found";
917    $packlist->{$xto} = { type => 'file' };
918    if ($force || compare($from, $to) || $nonono) {
919	safe_unlink($to);   # In case we don't have write permissions.
920	if ($nonono) {
921	    $from = $depth . "/" . $from if $depth;
922	}
923	if ($perlpodbadsymlink && $from =~ m!^pod/perl(.+)\.pod$!) {
924	    $from = "README.$1";
925	}
926	copy($from, $to);
927	# Restore timestamps if it's a .a library or for OS/2.
928	if (!$nonono && ($Is_OS2 || $to =~ /\.a$/)) {
929	    my ($atime, $mtime) = (stat $from)[8,9];
930	    utime $atime, $mtime, $to;
931	}
932	1;
933    }
934}
935
936sub strip
937{
938    my(@args) = @_;
939
940    return unless $dostrip;
941
942    my @opts;
943    while (@args && $args[0] =~ /^(-\w+)$/) {
944	push @opts, shift @args;
945    }
946
947    foreach my $file (@args) {
948	if (-f $file) {
949	    if ($verbose) {
950		print "  strip " . join(' ', @opts);
951		print " " if (@opts);
952		print "$file\n";
953	    }
954	    system("strip", @opts, $file);
955	} else {
956	    print "# file '$file' skipped\n" if $verbose;
957	}
958    }
959}
960