Commit | Line | Data |
---|---|---|
c623bd54 | 1 | #!./perl |
68dc0745 | 2 | |
c2cd2081 KS |
3 | use strict; |
4 | use vars qw($Is_VMS $Is_W32 $Is_OS2 $nonono $versiononly $depth); | |
5 | ||
68dc0745 | 6 | BEGIN { |
c90c0ff4 | 7 | require 5.004; |
d07c2202 | 8 | chdir '..' if !-d 'lib' and -d '..\lib'; |
68dc0745 | 9 | @INC = 'lib'; |
10 | $ENV{PERL5LIB} = 'lib'; | |
17f28c40 | 11 | $Is_VMS = $^O eq 'VMS'; |
4a71ed0c GS |
12 | $Is_W32 = $^O eq 'MSWin32'; |
13 | $Is_OS2 = $^O eq 'os2'; | |
17f28c40 | 14 | if ($Is_VMS) { eval 'use VMS::Filespec;' } |
68dc0745 | 15 | } |
16 | ||
c2cd2081 | 17 | my $scr_ext = ($Is_VMS ? '.Com' : $Is_W32 ? '.bat' : ''); |
4a71ed0c | 18 | |
a0d0e21e | 19 | use File::Find; |
5f05dabc | 20 | use File::Compare; |
68dc0745 | 21 | use File::Copy (); |
0ecb046b | 22 | use File::Path (); |
354f3b56 | 23 | use ExtUtils::Packlist; |
4633a7c4 | 24 | use Config; |
91a06757 | 25 | use subs qw(unlink link chmod); |
354f3b56 | 26 | use vars qw($packlist); |
c623bd54 | 27 | |
0ecb046b | 28 | # override the ones in the rest of the script |
68dc0745 | 29 | sub mkpath { |
30 | File::Path::mkpath(@_) unless $nonono; | |
0ecb046b SH |
31 | } |
32 | ||
c2cd2081 KS |
33 | my $mainperldir = "/usr/bin"; |
34 | my $exe_ext = $Config{exe_ext}; | |
bee1dbe2 | 35 | |
6ee623d5 | 36 | # Allow ``make install PERLNAME=something_besides_perl'': |
c2cd2081 | 37 | my $perl = defined($ENV{PERLNAME}) ? $ENV{PERLNAME} : 'perl'; |
6ee623d5 | 38 | |
c623bd54 LW |
39 | while (@ARGV) { |
40 | $nonono = 1 if $ARGV[0] eq '-n'; | |
41 | $versiononly = 1 if $ARGV[0] eq '-v'; | |
42 | shift; | |
43 | } | |
44 | ||
17f28c40 | 45 | umask 022 unless $Is_VMS; |
45d8adaa | 46 | |
c2cd2081 | 47 | my @scripts = qw(utils/c2ph utils/h2ph utils/h2xs utils/perlbug utils/perldoc |
4a71ed0c | 48 | utils/pl2pm utils/splain utils/perlcc |
6ee623d5 | 49 | x2p/s2p x2p/find2perl |
dd6decf0 | 50 | pod/pod2man pod/pod2html pod/pod2latex pod/pod2text); |
16d20bd9 | 51 | |
4a71ed0c | 52 | if ($scr_ext) { @scripts = map { "$_$scr_ext" } @scripts; } |
17f28c40 | 53 | |
c2cd2081 | 54 | my @pods = (<pod/*.pod>); |
c623bd54 | 55 | |
e8ea6127 AD |
56 | # Specify here any .pm files that are actually architecture-dependent. |
57 | # (Those included with XS extensions under ext/ are automatically | |
58 | # added later.) | |
59 | # Now that the default privlib has the full perl version number included, | |
60 | # we no longer have to play the trick of sticking version-specific .pm | |
61 | # files under the archlib directory. | |
c2cd2081 | 62 | my %archpms = ( |
e8ea6127 | 63 | Config => 1, |
38b8243a | 64 | ); |
39e571d4 LM |
65 | |
66 | if ($^O eq 'dos') { | |
67 | push(@scripts,'djgpp/fixpmain'); | |
68 | $archpms{config} = $archpms{filehand} = 1; | |
69 | } | |
70 | ||
6ee623d5 GS |
71 | if ((-e "testcompile") && (defined($ENV{'COMPILE'}))) |
72 | { | |
73 | push(@scripts, map("$_.exe", @scripts)); | |
74 | } | |
75 | ||
1dd15ed4 CS |
76 | find(sub { |
77 | if ("$File::Find::dir/$_" =~ m{^ext/[^/]+/(.*)\.pm$}) { | |
78 | (my $pm = $1) =~ s{^lib/}{}; | |
79 | $archpms{$pm} = 1; | |
80 | } | |
81 | }, 'ext'); | |
82 | ||
c2cd2081 KS |
83 | my $ver = $]; |
84 | my $release = substr($ver,0,3); # Not used presently. | |
85 | my $patchlevel = substr($ver,3,2); | |
748a9306 | 86 | die "Patchlevel of perl ($patchlevel)", |
4633a7c4 LW |
87 | "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n" |
88 | if $patchlevel != $Config{'PATCHLEVEL'}; | |
89 | ||
90 | # Fetch some frequently-used items from %Config | |
c2cd2081 KS |
91 | my $installbin = $Config{installbin}; |
92 | my $installscript = $Config{installscript}; | |
93 | my $installprivlib = $Config{installprivlib}; | |
94 | my $installarchlib = $Config{installarchlib}; | |
95 | my $installsitelib = $Config{installsitelib}; | |
96 | my $installsitearch = $Config{installsitearch}; | |
97 | my $installman1dir = $Config{installman1dir}; | |
98 | my $man1ext = $Config{man1ext}; | |
99 | my $libperl = $Config{libperl}; | |
4633a7c4 | 100 | # Shared library and dynamic loading suffixes. |
c2cd2081 KS |
101 | my $so = $Config{so}; |
102 | my $dlext = $Config{dlext}; | |
4633a7c4 | 103 | |
c2cd2081 KS |
104 | my $d_dosuid = $Config{d_dosuid}; |
105 | my $binexp = $Config{binexp}; | |
c623bd54 | 106 | |
17f28c40 CB |
107 | if ($Is_VMS) { # Hang in there until File::Spec hits the big time |
108 | foreach ( \$installbin, \$installscript, \$installprivlib, | |
109 | \$installarchlib, \$installsitelib, \$installsitearch, | |
110 | \$installman1dir ) { | |
111 | $$_ = unixify($$_); $$_ =~ s:/$::; | |
112 | } | |
113 | } | |
114 | ||
c623bd54 LW |
115 | # Do some quick sanity checks. |
116 | ||
117 | if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; } | |
118 | ||
fe14fcc3 | 119 | $installbin || die "No installbin directory in config.sh\n"; |
fcbdbaa8 | 120 | -d $installbin || mkpath($installbin, 1, 0777); |
0ecb046b SH |
121 | -d $installbin || $nonono || die "$installbin is not a directory\n"; |
122 | -w $installbin || $nonono || die "$installbin is not writable by you\n" | |
3edbfbe5 | 123 | unless $installbin =~ m#^/afs/# || $nonono; |
c623bd54 | 124 | |
39add537 | 125 | -x 'perl' . $exe_ext || die "perl isn't executable!\n"; |
126 | -x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid; | |
c623bd54 | 127 | |
4a71ed0c | 128 | -x 't/TEST' || $Is_W32 |
d07c2202 GS |
129 | || warn "WARNING: You've never run 'make test'!!!", |
130 | " (Installing anyway.)\n"; | |
c623bd54 | 131 | |
4a71ed0c | 132 | if ($Is_W32) { |
eef1cf2a | 133 | |
c2cd2081 | 134 | my $perldll = 'perl.' . $dlext; |
f7a92b15 DL |
135 | $perldll = 'perlcore.' . $dlext if $Config{'ccflags'} =~ /PERL_OBJECT/i; |
136 | ||
137 | -f $perldll || die "No perl DLL built\n"; | |
eef1cf2a GS |
138 | |
139 | # Install the DLL | |
140 | ||
f7a92b15 DL |
141 | safe_unlink("$installbin/$perldll"); |
142 | copy("$perldll", "$installbin/$perldll"); | |
143 | chmod(0755, "$installbin/$perldll"); | |
eef1cf2a GS |
144 | } |
145 | ||
354f3b56 | 146 | # This will be used to store the packlist |
c2cd2081 | 147 | my $packlist = ExtUtils::Packlist->new("$installarchlib/.packlist"); |
354f3b56 | 148 | |
c623bd54 LW |
149 | # First we install the version-numbered executables. |
150 | ||
17f28c40 | 151 | if ($Is_VMS) { |
6ee623d5 GS |
152 | safe_unlink("$installbin/$perl$exe_ext"); |
153 | copy("perl$exe_ext", "$installbin/$perl$exe_ext"); | |
154 | chmod(0755, "$installbin/$perl$exe_ext"); | |
155 | safe_unlink("$installbin/${perl}shr$exe_ext"); | |
156 | copy("perlshr$exe_ext", "$installbin/${perl}shr$exe_ext"); | |
157 | chmod(0755, "$installbin/${perl}shr$exe_ext"); | |
17f28c40 CB |
158 | } |
159 | elsif ($^O ne 'dos') { | |
6ee623d5 GS |
160 | safe_unlink("$installbin/$perl$ver$exe_ext"); |
161 | copy("perl$exe_ext", "$installbin/$perl$ver$exe_ext"); | |
162 | chmod(0755, "$installbin/$perl$ver$exe_ext"); | |
39e571d4 | 163 | } else { |
6ee623d5 GS |
164 | safe_unlink("$installbin/$perl.exe"); |
165 | copy("perl.exe", "$installbin/$perl.exe"); | |
39e571d4 | 166 | } |
c623bd54 | 167 | |
6ee623d5 | 168 | safe_unlink("$installbin/s$perl$ver$exe_ext"); |
c623bd54 | 169 | if ($d_dosuid) { |
6ee623d5 GS |
170 | copy("suidperl$exe_ext", "$installbin/s$perl$ver$exe_ext"); |
171 | chmod(04711, "$installbin/s$perl$ver$exe_ext"); | |
c623bd54 LW |
172 | } |
173 | ||
45d8adaa LW |
174 | # Install library files. |
175 | ||
c2cd2081 | 176 | my ($do_installarchlib, $do_installprivlib) = (0, 0); |
a0d0e21e | 177 | |
fcbdbaa8 | 178 | mkpath($installprivlib, 1, 0777); |
179 | mkpath($installarchlib, 1, 0777); | |
180 | mkpath($installsitelib, 1, 0777) if ($installsitelib); | |
181 | mkpath($installsitearch, 1, 0777) if ($installsitearch); | |
4633a7c4 | 182 | |
45d8adaa | 183 | if (chdir "lib") { |
68dc0745 | 184 | $do_installarchlib = ! samepath($installarchlib, '.'); |
185 | $do_installprivlib = ! samepath($installprivlib, '.'); | |
b971f6e4 | 186 | $do_installprivlib = 0 if $versiononly && !($installprivlib =~ m/\Q$]/); |
45d8adaa | 187 | |
a0d0e21e LW |
188 | if ($do_installarchlib || $do_installprivlib) { |
189 | find(\&installlib, '.'); | |
45d8adaa LW |
190 | } |
191 | chdir ".." || die "Can't cd back to source directory: $!\n"; | |
192 | } | |
193 | else { | |
194 | warn "Can't cd to lib to install lib files: $!\n"; | |
195 | } | |
196 | ||
1aef975c | 197 | # Install header files and libraries. |
fcbdbaa8 | 198 | mkpath("$installarchlib/CORE", 1, 0777); |
c2cd2081 | 199 | my @corefiles; |
17f28c40 CB |
200 | if ($Is_VMS) { # We did core file selection during build |
201 | my $coredir = "lib/$Config{'arch'}/$]"; | |
202 | $coredir =~ tr/./_/; | |
203 | @corefiles = <$coredir/*.*>; | |
204 | } | |
205 | else { | |
206 | @corefiles = <*.h libperl*.*>; | |
207 | # AIX needs perl.exp installed as well. | |
208 | push(@corefiles,'perl.exp') if $^O eq 'aix'; | |
209 | # If they have built sperl.o... | |
210 | push(@corefiles,'sperl.o') if -f 'sperl.o'; | |
211 | } | |
c2cd2081 | 212 | foreach my $file (@corefiles) { |
aa3cf465 | 213 | # HP-UX (at least) needs to maintain execute permissions |
efc5ad56 | 214 | # on dynamically-loadable libraries. So we do it for all. |
68dc0745 | 215 | copy_if_diff($file,"$installarchlib/CORE/$file") |
efc5ad56 | 216 | and chmod($file =~ /\.(so|\Q$dlext\E)$/ ? 0555 : 0444, |
aa3cf465 | 217 | "$installarchlib/CORE/$file"); |
340f689c | 218 | } |
3edbfbe5 | 219 | |
156620fa NA |
220 | # Install main perl executables |
221 | # Make links to ordinary names if installbin directory isn't current directory. | |
222 | ||
17f28c40 | 223 | if (! $versiononly && ! samepath($installbin, '.') && ($^O ne 'dos') && ! $Is_VMS) { |
6ee623d5 GS |
224 | safe_unlink("$installbin/$perl$exe_ext", "$installbin/suid$perl$exe_ext"); |
225 | link("$installbin/$perl$ver$exe_ext", "$installbin/$perl$exe_ext"); | |
226 | link("$installbin/s$perl$ver$exe_ext", "$installbin/suid$perl$exe_ext") | |
156620fa NA |
227 | if $d_dosuid; |
228 | } | |
229 | ||
a0d0e21e LW |
230 | # Offer to install perl in a "standard" location |
231 | ||
c2cd2081 | 232 | my $mainperl_is_instperl = 0; |
a0d0e21e | 233 | |
4a71ed0c | 234 | if (!$versiononly && !$nonono && !$Is_W32 && !$Is_VMS && -t STDIN && -t STDERR |
68dc0745 | 235 | && -w $mainperldir && ! samepath($mainperldir, $installbin)) { |
c2cd2081 KS |
236 | my($usrbinperl) = "$mainperldir/$perl$exe_ext"; |
237 | my($instperl) = "$installbin/$perl$exe_ext"; | |
238 | my($expinstperl) = "$binexp/$perl$exe_ext"; | |
55497cff | 239 | |
240 | # First make sure $usrbinperl is not already the same as the perl we | |
241 | # just installed. | |
242 | if (-x $usrbinperl) { | |
a0d0e21e LW |
243 | # Try to be clever about mainperl being a symbolic link |
244 | # to binexp/perl if binexp and installbin are different. | |
245 | $mainperl_is_instperl = | |
68dc0745 | 246 | samepath($usrbinperl, $instperl) || |
247 | samepath($usrbinperl, $expinstperl) || | |
a0d0e21e | 248 | (($binexp ne $installbin) && |
55497cff | 249 | (-l $usrbinperl) && |
250 | ((readlink $usrbinperl) eq $expinstperl)); | |
a0d0e21e LW |
251 | } |
252 | if ((! $mainperl_is_instperl) && | |
68dc0745 | 253 | (yn("Many scripts expect perl to be installed as $usrbinperl.\n" . |
55497cff | 254 | "Do you wish to have $usrbinperl be the same as\n" . |
255 | "$expinstperl? [y] "))) | |
a0d0e21e | 256 | { |
55497cff | 257 | unlink($usrbinperl); |
258 | eval { CORE::link $instperl, $usrbinperl } || | |
259 | eval { symlink $expinstperl, $usrbinperl } || | |
68dc0745 | 260 | copy($instperl, $usrbinperl); |
a0d0e21e LW |
261 | $mainperl_is_instperl = 1; |
262 | } | |
263 | } | |
264 | ||
b971f6e4 | 265 | # Make links to ordinary names if installbin directory isn't current directory. |
266 | ||
68dc0745 | 267 | if (!$versiononly && ! samepath($installbin, 'x2p')) { |
268 | safe_unlink("$installbin/a2p$exe_ext"); | |
269 | copy("x2p/a2p$exe_ext", "$installbin/a2p$exe_ext"); | |
270 | chmod(0755, "$installbin/a2p$exe_ext"); | |
b971f6e4 | 271 | } |
272 | ||
273 | # cppstdin is just a script, but it is architecture-dependent, so | |
274 | # it can't safely be shared. Place it in $installbin. | |
275 | # Note that Configure doesn't build cppstin if it isn't needed, so | |
276 | # we skip this if cppstdin doesn't exist. | |
68dc0745 | 277 | if (! $versiononly && (-f 'cppstdin') && (! samepath($installbin, '.'))) { |
278 | safe_unlink("$installbin/cppstdin"); | |
279 | copy("cppstdin", "$installbin/cppstdin"); | |
280 | chmod(0755, "$installbin/cppstdin"); | |
b971f6e4 | 281 | } |
282 | ||
283 | # Install scripts. | |
284 | ||
285 | mkpath($installscript, 1, 0777); | |
286 | ||
287 | if (! $versiononly) { | |
288 | for (@scripts) { | |
68dc0745 | 289 | (my $base = $_) =~ s#.*/##; |
290 | copy($_, "$installscript/$base"); | |
291 | chmod(0755, "$installscript/$base"); | |
b971f6e4 | 292 | } |
293 | } | |
294 | ||
295 | # pstruct should be a link to c2ph | |
296 | ||
297 | if (! $versiononly) { | |
4a71ed0c | 298 | safe_unlink("$installscript/pstruct$scr_ext"); |
17f28c40 | 299 | if ($^O eq 'dos' or $Is_VMS) { |
4a71ed0c | 300 | copy("$installscript/c2ph$scr_ext", "$installscript/pstruct$scr_ext"); |
39e571d4 | 301 | } else { |
4a71ed0c | 302 | link("$installscript/c2ph$scr_ext", "$installscript/pstruct$scr_ext"); |
39e571d4 | 303 | } |
b971f6e4 | 304 | } |
305 | ||
306 | # Install pod pages. Where? I guess in $installprivlib/pod. | |
307 | ||
68dc0745 | 308 | if (! $versiononly || !($installprivlib =~ m/\Q$]/)) { |
b971f6e4 | 309 | mkpath("${installprivlib}/pod", 1, 0777); |
91a06757 CS |
310 | |
311 | # If Perl 5.003's perldiag.pod is there, rename it. | |
312 | if (open POD, "${installprivlib}/pod/perldiag.pod") { | |
313 | read POD, $_, 4000; | |
314 | close POD; | |
315 | # Some of Perl 5.003's diagnostic messages ended with periods. | |
316 | if (/^=.*\.$/m) { | |
317 | my ($from, $to) = ("${installprivlib}/pod/perldiag.pod", | |
318 | "${installprivlib}/pod/perldiag-5.003.pod"); | |
319 | print STDERR " rename $from $to"; | |
320 | rename($from, $to) | |
321 | or warn "Couldn't rename $from to $to: $!\n" | |
322 | unless $nonono; | |
323 | } | |
324 | } | |
325 | ||
c2cd2081 | 326 | foreach my $file (@pods) { |
b971f6e4 | 327 | # $file is a name like pod/perl.pod |
68dc0745 | 328 | copy_if_diff($file, "${installprivlib}/${file}"); |
b971f6e4 | 329 | } |
91a06757 | 330 | |
b971f6e4 | 331 | } |
332 | ||
a0d0e21e LW |
333 | # Check to make sure there aren't other perls around in installer's |
334 | # path. This is probably UNIX-specific. Check all absolute directories | |
335 | # in the path except for where public executables are supposed to live. | |
336 | # Also skip $mainperl if the user opted to have it be a link to the | |
337 | # installed perl. | |
338 | ||
b971f6e4 | 339 | if (!$versiononly) { |
c2cd2081 KS |
340 | my ($path, @path); |
341 | my $dirsep = ($Is_OS2 || $Is_W32) ? ';' : ':' ; | |
b971f6e4 | 342 | ($path = $ENV{"PATH"}) =~ s:\\:/:g ; |
343 | @path = split(/$dirsep/, $path); | |
17f28c40 CB |
344 | if ($Is_VMS) { |
345 | my $i = 0; | |
346 | while (exists $ENV{'DCL$PATH' . $i}) { | |
c2cd2081 | 347 | my $dir = unixpath($ENV{'DCL$PATH' . $i}); $dir =~ s-/$--; |
17f28c40 CB |
348 | push(@path,$dir); |
349 | } | |
350 | } | |
c2cd2081 | 351 | my @otherperls; |
b971f6e4 | 352 | for (@path) { |
353 | next unless m,^/,; | |
354 | # Use &samepath here because some systems have other dirs linked | |
355 | # to $mainperldir (like SunOS) | |
68dc0745 | 356 | next if samepath($_, $binexp); |
357 | next if ($mainperl_is_instperl && samepath($_, $mainperldir)); | |
6ee623d5 GS |
358 | push(@otherperls, "$_/$perl$exe_ext") |
359 | if (-x "$_/$perl$exe_ext" && ! -d "$_/$perl$exe_ext"); | |
b971f6e4 | 360 | } |
361 | if (@otherperls) { | |
6ee623d5 | 362 | print STDERR "\nWarning: $perl appears in your path in the following " . |
b971f6e4 | 363 | "locations beyond where\nwe just installed it:\n"; |
364 | for (@otherperls) { | |
365 | print STDERR " ", $_, "\n"; | |
366 | } | |
367 | print STDERR "\n"; | |
a0d0e21e | 368 | } |
b971f6e4 | 369 | |
a0d0e21e LW |
370 | } |
371 | ||
3f9aafa0 | 372 | $packlist->write() unless $nonono; |
c623bd54 LW |
373 | print STDERR " Installation complete\n"; |
374 | ||
375 | exit 0; | |
376 | ||
377 | ############################################################################### | |
378 | ||
a0d0e21e | 379 | sub yn { |
c2cd2081 KS |
380 | my($prompt) = @_; |
381 | my($answer); | |
382 | my($default) = $prompt =~ m/\[([yn])\]\s*$/i; | |
a0d0e21e LW |
383 | print STDERR $prompt; |
384 | chop($answer = <STDIN>); | |
385 | $answer = $default if $answer =~ m/^\s*$/; | |
386 | ($answer =~ m/^[yY]/); | |
387 | } | |
388 | ||
c623bd54 | 389 | sub unlink { |
c2cd2081 | 390 | my(@names) = @_; |
39add537 | 391 | my($cnt) = 0; |
c623bd54 | 392 | |
17f28c40 CB |
393 | return scalar(@names) if $Is_VMS; |
394 | ||
c2cd2081 | 395 | foreach my $name (@names) { |
c623bd54 | 396 | next unless -e $name; |
4a71ed0c | 397 | chmod 0777, $name if ($Is_OS2 || $Is_W32); |
c623bd54 | 398 | print STDERR " unlink $name\n"; |
39add537 | 399 | ( CORE::unlink($name) and ++$cnt |
400 | or warn "Couldn't unlink $name: $!\n" ) unless $nonono; | |
c623bd54 | 401 | } |
39add537 | 402 | return $cnt; |
c623bd54 LW |
403 | } |
404 | ||
e50aee73 | 405 | sub safe_unlink { |
17f28c40 | 406 | return if $nonono or $Is_VMS; |
c2cd2081 KS |
407 | my @names = @_; |
408 | foreach my $name (@names) { | |
e50aee73 | 409 | next unless -e $name; |
4a71ed0c | 410 | chmod 0777, $name if ($Is_OS2 || $Is_W32); |
39add537 | 411 | print STDERR " unlink $name\n"; |
412 | next if CORE::unlink($name); | |
e50aee73 AD |
413 | warn "Couldn't unlink $name: $!\n"; |
414 | if ($! =~ /busy/i) { | |
415 | print STDERR " mv $name $name.old\n"; | |
68dc0745 | 416 | safe_rename($name, "$name.old") |
417 | or warn "Couldn't rename $name: $!\n"; | |
e50aee73 AD |
418 | } |
419 | } | |
420 | } | |
421 | ||
68dc0745 | 422 | sub safe_rename { |
c2cd2081 | 423 | my($from,$to) = @_; |
39add537 | 424 | if (-f $to and not unlink($to)) { |
e50aee73 AD |
425 | my($i); |
426 | for ($i = 1; $i < 50; $i++) { | |
91a06757 | 427 | last if rename($to, "$to.$i"); |
e50aee73 | 428 | } |
39add537 | 429 | warn("Cannot rename to `$to.$i': $!"), return 0 |
430 | if $i >= 50; # Give up! | |
e50aee73 AD |
431 | } |
432 | link($from,$to) || return 0; | |
433 | unlink($from); | |
434 | } | |
435 | ||
c623bd54 | 436 | sub link { |
15792f64 | 437 | my($from,$to) = @_; |
438 | my($success) = 0; | |
c623bd54 LW |
439 | |
440 | print STDERR " ln $from $to\n"; | |
39add537 | 441 | eval { |
68dc0745 | 442 | CORE::link($from, $to) |
443 | ? $success++ | |
7bac28a0 | 444 | : ($from =~ m#^/afs/# || $to =~ m#^/afs/#) |
445 | ? die "AFS" # okay inside eval {} | |
446 | : warn "Couldn't link $from to $to: $!\n" | |
68dc0745 | 447 | unless $nonono; |
354f3b56 | 448 | $packlist->{$to} = { from => $from, type => 'link' }; |
39add537 | 449 | }; |
450 | if ($@) { | |
17f28c40 | 451 | print STDERR " creating new version of $to\n" if $Is_VMS and -e $to; |
68dc0745 | 452 | File::Copy::copy($from, $to) |
453 | ? $success++ | |
454 | : warn "Couldn't copy $from to $to: $!\n" | |
455 | unless $nonono; | |
354f3b56 | 456 | $packlist->{$to} = { type => 'file' }; |
39add537 | 457 | } |
15792f64 | 458 | $success; |
c623bd54 LW |
459 | } |
460 | ||
461 | sub chmod { | |
c2cd2081 | 462 | my($mode,$name) = @_; |
c623bd54 | 463 | |
39e571d4 | 464 | return if ($^O eq 'dos'); |
c623bd54 | 465 | printf STDERR " chmod %o %s\n", $mode, $name; |
68dc0745 | 466 | CORE::chmod($mode,$name) |
467 | || warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name) | |
468 | unless $nonono; | |
469 | } | |
470 | ||
471 | sub copy { | |
472 | my($from,$to) = @_; | |
473 | ||
474 | print STDERR " cp $from $to\n"; | |
17f28c40 | 475 | print STDERR " creating new version of $to\n" if $Is_VMS and -e $to; |
68dc0745 | 476 | File::Copy::copy($from, $to) |
477 | || warn "Couldn't copy $from to $to: $!\n" | |
478 | unless $nonono; | |
354f3b56 | 479 | $packlist->{$to} = { type => 'file' }; |
c623bd54 LW |
480 | } |
481 | ||
a0d0e21e | 482 | sub samepath { |
c2cd2081 | 483 | my($p1, $p2) = @_; |
eef1cf2a | 484 | |
4a71ed0c | 485 | return (lc($p1) eq lc($p2)) if $Is_W32; |
a0d0e21e | 486 | |
75f92628 | 487 | if ($p1 ne $p2) { |
c2cd2081 | 488 | my($dev1, $ino1, $dev2, $ino2); |
a0d0e21e LW |
489 | ($dev1, $ino1) = stat($p1); |
490 | ($dev2, $ino2) = stat($p2); | |
491 | ($dev1 == $dev2 && $ino1 == $ino2); | |
492 | } | |
493 | else { | |
494 | 1; | |
495 | } | |
496 | } | |
497 | ||
498 | sub installlib { | |
499 | my $dir = $File::Find::dir; | |
500 | $dir =~ s#^\.(?![^/])/?##; | |
0ecb046b | 501 | local($depth) = $dir ? "lib/$dir" : "lib"; |
a0d0e21e LW |
502 | |
503 | my $name = $_; | |
efc5ad56 TB |
504 | |
505 | if ($name eq 'CVS' && -d $name) { | |
506 | $File::Find::prune = 1; | |
507 | return; | |
508 | } | |
e50aee73 AD |
509 | |
510 | # ignore patch backups and the .exists files. | |
511 | return if $name =~ m{\.orig$|~$|^\.exists}; | |
512 | ||
a0d0e21e LW |
513 | $name = "$dir/$name" if $dir ne ''; |
514 | ||
515 | my $installlib = $installprivlib; | |
1dd15ed4 | 516 | if ($dir =~ /^auto/ || |
eef1cf2a | 517 | ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1}) || |
4a71ed0c | 518 | ($name =~ /^(.*)\.(?:h|lib)$/i && $Is_W32) |
eef1cf2a | 519 | ) { |
a0d0e21e LW |
520 | $installlib = $installarchlib; |
521 | return unless $do_installarchlib; | |
522 | } else { | |
523 | return unless $do_installprivlib; | |
524 | } | |
525 | ||
a0d0e21e | 526 | if (-f $_) { |
5cc330c8 | 527 | if (/\.(?:al|ix)$/ && !($dir =~ m[^auto/(.*)$] && $archpms{$1})) { |
3edbfbe5 TB |
528 | $installlib = $installprivlib; |
529 | #We're installing *.al and *.ix files into $installprivlib, | |
530 | #but we have to delete old *.al and *.ix files from the 5.000 | |
531 | #distribution: | |
75f92628 | 532 | #This might not work because $archname might have changed. |
68dc0745 | 533 | unlink("$installarchlib/$name"); |
3edbfbe5 | 534 | } |
354f3b56 | 535 | $packlist->{"$installlib/$name"} = { type => 'file' }; |
5f05dabc | 536 | if (compare($_, "$installlib/$name") || $nonono) { |
68dc0745 | 537 | unlink("$installlib/$name"); |
fcbdbaa8 | 538 | mkpath("$installlib/$dir", 1, 0777); |
75f92628 AD |
539 | # HP-UX (at least) needs to maintain execute permissions |
540 | # on dynamically-loaded libraries. | |
68dc0745 | 541 | copy_if_diff($_, "$installlib/$name") |
542 | and chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444, | |
aa3cf465 | 543 | "$installlib/$name"); |
a0d0e21e LW |
544 | } |
545 | } elsif (-d $_) { | |
fcbdbaa8 | 546 | mkpath("$installlib/$name", 1, 0777); |
a0d0e21e LW |
547 | } |
548 | } | |
3edbfbe5 | 549 | |
16d20bd9 AD |
550 | # Copy $from to $to, only if $from is different than $to. |
551 | # Also preserve modification times for .a libraries. | |
552 | # On some systems, if you do | |
553 | # ranlib libperl.a | |
554 | # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a | |
555 | # and then try to link against the installed libperl.a, you might | |
556 | # get an error message to the effect that the symbol table is older | |
557 | # than the library. | |
aa3cf465 | 558 | # Return true if copying occurred. |
68dc0745 | 559 | |
560 | sub copy_if_diff { | |
3edbfbe5 | 561 | my($from,$to)=@_; |
8530e788 | 562 | return 1 if (($^O eq 'VMS') && (-d $from)); |
3edbfbe5 | 563 | -f $from || die "$0: $from not found"; |
354f3b56 | 564 | $packlist->{$to} = { type => 'file' }; |
5f05dabc | 565 | if (compare($from, $to) || $nonono) { |
68dc0745 | 566 | safe_unlink($to); # In case we don't have write permissions. |
0ecb046b SH |
567 | if ($nonono) { |
568 | $from = $depth . "/" . $from if $depth; | |
569 | } | |
68dc0745 | 570 | copy($from, $to); |
571 | # Restore timestamps if it's a .a library or for OS/2. | |
4a71ed0c | 572 | if (!$nonono && ($Is_OS2 || $to =~ /\.a$/)) { |
68dc0745 | 573 | my ($atime, $mtime) = (stat $from)[8,9]; |
16d20bd9 AD |
574 | utime $atime, $mtime, $to; |
575 | } | |
aa3cf465 | 576 | 1; |
3edbfbe5 TB |
577 | } |
578 | } |