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