3 # Initialisation code and subroutines shared between installperl and installman
4 # Probably installhtml needs to join the club.
7 use vars qw($Is_VMS $Is_W32 $Is_OS2 $Is_Cygwin $Is_Darwin $Is_NetWare
9 use subs qw(unlink link chmod);
13 if ($Config{userelocatableinc}) {
14 # This might be a considered a hack. Need to get information about the
15 # configuration from Config.pm *before* Config.pm expands any .../
18 # So we set $^X to pretend that we're the already installed perl, so
19 # Config.pm does its ... expansion off that location.
21 my $location = $Config{initialinstalllocation};
22 die <<'OS' unless defined $location;
23 $Config{initialinstalllocation} is not defined - can't install a relocatable
26 $^X = "$location/perl";
27 # And then remove all trace of ever having loaded Config.pm, so that
28 # it will reload with the revised $^X
30 delete $INC{"Config.pm"};
31 delete $INC{"Config_heavy.pl"};
32 delete $INC{"Config_git.pl"};
33 # You never saw us. We weren't here.
40 if ($Config{d_umask}) {
41 umask(022); # umasks like 077 aren't that useful for installations
44 $Is_VMS = $^O eq 'VMS';
45 $Is_W32 = $^O eq 'MSWin32';
46 $Is_OS2 = $^O eq 'os2';
47 $Is_Cygwin = $^O eq 'cygwin';
48 $Is_Darwin = $^O eq 'darwin';
49 $Is_NetWare = $Config{osname} eq 'NetWare';
55 return scalar(@names) if $Is_VMS;
57 foreach my $name (@names) {
59 chmod 0777, $name if ($Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare);
60 print " unlink $name\n" if $opts{verbose};
61 ( CORE::unlink($name) and ++$cnt
62 or warn "Couldn't unlink $name: $!\n" ) unless $opts{notify};
72 $xfrom =~ s/^\Q$opts{destdir}\E// if $opts{destdir};
74 $xto =~ s/^\Q$opts{destdir}\E// if $opts{destdir};
75 print $opts{verbose} ? " ln $xfrom $xto\n" : " $xto\n"
78 CORE::link($from, $to)
80 : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
81 ? die "AFS" # okay inside eval {}
82 : die "Couldn't link $from to $to: $!\n"
84 $packlist->{$xto} = { from => $xfrom, type => 'link' };
87 warn "Replacing link() with File::Copy::copy(): $@";
88 print $opts{verbose} ? " cp $from $xto\n" : " $xto\n"
90 print " creating new version of $xto\n"
91 if $Is_VMS and -e $to and !$opts{silent};
92 unless ($opts{notify} or File::Copy::copy($from, $to) and ++$success) {
93 # Might have been that F::C::c can't overwrite the target
94 warn "Couldn't copy $from to $to: $!\n"
95 unless -f $to and (chmod(0666, $to), unlink $to)
96 and File::Copy::copy($from, $to) and ++$success;
98 $packlist->{$xto} = { type => 'file' };
104 my($mode,$name) = @_;
106 return if ($^O eq 'dos');
107 printf " chmod %o %s\n", $mode, $name if $opts{verbose};
108 CORE::chmod($mode,$name)
109 || warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name)
110 unless $opts{notify};
117 return (lc($p1) eq lc($p2)) if ($Is_W32 || $Is_NetWare);
120 my($dev1, $ino1, $dev2, $ino2);
121 ($dev1, $ino1) = stat($p1);
122 ($dev2, $ino2) = stat($p2);
123 ($dev1 == $dev2 && $ino1 == $ino2);
132 if (-f $to and not unlink($to)) {
134 for ($i = 1; $i < 50; $i++) {
135 last if rename($to, "$to.$i");
137 warn("Cannot rename to '$to.$i': $!"), return 0
138 if $i >= 50; # Give up!
140 link($from,$to) || return 0;