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