Configure updates for intsize and ssizetype
[p5sagit/p5-mst-13.2.git] / installperl
CommitLineData
c623bd54 1#!./perl
a0d0e21e 2BEGIN { @INC=('./lib', '../lib') }
a0d0e21e 3use File::Find;
5f05dabc 4use File::Compare;
0ecb046b 5use File::Path ();
4633a7c4 6use Config;
39add537 7use subs qw(unlink rename link chmod);
c623bd54 8
0ecb046b 9# override the ones in the rest of the script
10sub mkpath
11{
12 File::Path::mkpath(@_) unless $nonono;
13}
14
bee1dbe2 15$mainperldir = "/usr/bin";
39add537 16$exe_ext = $Config{exe_ext};
bee1dbe2 17
c623bd54 18while (@ARGV) {
19 $nonono = 1 if $ARGV[0] eq '-n';
20 $versiononly = 1 if $ARGV[0] eq '-v';
21 shift;
22}
23
45d8adaa 24umask 022;
25
1fef88e7 26@scripts = qw( utils/c2ph utils/h2ph utils/h2xs
5f05dabc 27 utils/perlbug utils/perldoc utils/pl2pm utils/splain
dd6decf0 28 x2p/s2p x2p/find2perl
29 pod/pod2man pod/pod2html pod/pod2latex pod/pod2text);
16d20bd9 30
16d20bd9 31@pods = (<pod/*.pod>);
c623bd54 32
1dd15ed4 33%archpms = (Config => 1, FileHandle => 1, overload => 1);
34find(sub {
35 if ("$File::Find::dir/$_" =~ m{^ext/[^/]+/(.*)\.pm$}) {
36 (my $pm = $1) =~ s{^lib/}{};
37 $archpms{$pm} = 1;
38 }
39 }, 'ext');
40
748a9306 41$ver = $];
4633a7c4 42$release = substr($ver,0,3); # Not used presently.
bee1dbe2 43$patchlevel = substr($ver,3,2);
748a9306 44die "Patchlevel of perl ($patchlevel)",
4633a7c4 45 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
46 if $patchlevel != $Config{'PATCHLEVEL'};
47
48# Fetch some frequently-used items from %Config
49$installbin = $Config{installbin};
50$installscript = $Config{installscript};
51$installprivlib = $Config{installprivlib};
52$installarchlib = $Config{installarchlib};
53$installsitelib = $Config{installsitelib};
54$installsitearch = $Config{installsitearch};
55$installman1dir = $Config{installman1dir};
56$man1ext = $Config{man1ext};
15792f64 57$libperl = $Config{libperl};
4633a7c4 58# Shared library and dynamic loading suffixes.
59$so = $Config{so};
60$dlext = $Config{dlext};
61
62$d_dosuid = $Config{d_dosuid};
63$binexp = $Config{binexp};
c623bd54 64
65# Do some quick sanity checks.
66
67if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
68
fe14fcc3 69 $installbin || die "No installbin directory in config.sh\n";
fcbdbaa8 70-d $installbin || mkpath($installbin, 1, 0777);
0ecb046b 71-d $installbin || $nonono || die "$installbin is not a directory\n";
72-w $installbin || $nonono || die "$installbin is not writable by you\n"
3edbfbe5 73 unless $installbin =~ m#^/afs/# || $nonono;
c623bd54 74
39add537 75-x 'perl' . $exe_ext || die "perl isn't executable!\n";
76-x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid;
c623bd54 77
fe14fcc3 78-x 't/TEST' || warn "WARNING: You've never run 'make test'!!!",
79 " (Installing anyway.)\n";
c623bd54 80
81# First we install the version-numbered executables.
82
39add537 83&safe_unlink("$installbin/perl$ver$exe_ext");
84&cmd("cp perl$exe_ext $installbin/perl$ver$exe_ext");
36477c24 85&chmod(0755, "$installbin/perl$ver$exe_ext");
c623bd54 86
39add537 87&safe_unlink("$installbin/sperl$ver$exe_ext");
c623bd54 88if ($d_dosuid) {
39add537 89 &cmd("cp suidperl$exe_ext $installbin/sperl$ver$exe_ext");
90 &chmod(04711, "$installbin/sperl$ver$exe_ext");
c623bd54 91}
92
93exit 0 if $versiononly;
94
fe14fcc3 95# Make links to ordinary names if installbin directory isn't current directory.
c623bd54 96
ecfc5424 97if (! &samepath($installbin, '.')) {
39add537 98 &safe_unlink("$installbin/perl$exe_ext", "$installbin/suidperl$exe_ext");
99 &link("$installbin/perl$ver$exe_ext", "$installbin/perl$exe_ext");
100 &link("$installbin/sperl$ver$exe_ext", "$installbin/suidperl$exe_ext")
101 if $d_dosuid;
c623bd54 102}
103
ecfc5424 104if (! &samepath($installbin, 'x2p')) {
39add537 105 &safe_unlink("$installbin/a2p$exe_ext");
106 &cmd("cp x2p/a2p$exe_ext $installbin/a2p$exe_ext");
107 &chmod(0755, "$installbin/a2p$exe_ext");
352d5a3a 108}
109
340f689c 110# cppstdin is just a script, but it is architecture-dependent, so
111# it can't safely be shared. Place it in $installbin.
112# Note that Configure doesn't build cppstin if it isn't needed, so
113# we skip this if cppstdin doesn't exist.
114if ((-f cppstdin) && (! &samepath($installbin, '.'))) {
115 &safe_unlink("$installbin/cppstdin");
116 &cmd("cp cppstdin $installbin/cppstdin");
117 &chmod(0755, "$installbin/cppstdin");
118}
119
c623bd54 120# Install scripts.
121
fcbdbaa8 122mkpath($installscript, 1, 0777);
c623bd54 123
124for (@scripts) {
340f689c 125 &cmd("cp $_ $installscript");
126 s#.*/##; &chmod(0755, "$installscript/$_");
c623bd54 127}
128
1fef88e7 129# pstruct should be a link to c2ph
130
131&safe_unlink("$installscript/pstruct");
132&link("$installscript/c2ph","$installscript/pstruct");
133
16d20bd9 134# Install pod pages. Where? I guess in $installprivlib/pod.
fcbdbaa8 135mkpath("${installprivlib}/pod", 1, 0777);
16d20bd9 136foreach $file (@pods) {
137 # $file is a name like pod/perl.pod
138 cp_if_diff($file, "${installprivlib}/${file}");
139}
140
45d8adaa 141# Install library files.
142
a0d0e21e 143$do_installarchlib = $do_installprivlib = 0;
144
fcbdbaa8 145mkpath($installprivlib, 1, 0777);
146mkpath($installarchlib, 1, 0777);
147mkpath($installsitelib, 1, 0777) if ($installsitelib);
148mkpath($installsitearch, 1, 0777) if ($installsitearch);
4633a7c4 149
45d8adaa 150if (chdir "lib") {
ecfc5424 151 $do_installarchlib = ! &samepath($installarchlib, '.');
152 $do_installprivlib = ! &samepath($installprivlib, '.');
45d8adaa 153
a0d0e21e 154 if ($do_installarchlib || $do_installprivlib) {
155 find(\&installlib, '.');
45d8adaa 156 }
157 chdir ".." || die "Can't cd back to source directory: $!\n";
158}
159else {
160 warn "Can't cd to lib to install lib files: $!\n";
161}
162
1aef975c 163# Install header files and libraries.
fcbdbaa8 164mkpath("$installarchlib/CORE", 1, 0777);
340f689c 165@corefiles = <*.h libperl*.*>;
1aef975c 166# AIX needs perl.exp installed as well.
340f689c 167push(@corefiles,'perl.exp') if $^O eq 'aix';
fed7345c 168# If they have built sperl.o...
340f689c 169push(@corefiles,'sperl.o') if -f 'sperl.o';
170foreach $file (@corefiles) {
aa3cf465 171 # HP-UX (at least) needs to maintain execute permissions
172 # on dynamically-loaded libraries.
173 cp_if_diff($file,"$installarchlib/CORE/$file")
174 and &chmod($file =~ /^\.(so|$dlext)$/ ? 0555 : 0444,
175 "$installarchlib/CORE/$file");
340f689c 176}
3edbfbe5 177
a0d0e21e 178# Offer to install perl in a "standard" location
179
a0d0e21e 180$mainperl_is_instperl = 0;
181
ecfc5424 182if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) {
55497cff 183 local($usrbinperl) = "$mainperldir/perl$exe_ext";
184 local($instperl) = "$installbin/perl$exe_ext";
185 local($expinstperl) = "$binexp/perl$exe_ext";
186
187 # First make sure $usrbinperl is not already the same as the perl we
188 # just installed.
189 if (-x $usrbinperl) {
a0d0e21e 190 # Try to be clever about mainperl being a symbolic link
191 # to binexp/perl if binexp and installbin are different.
192 $mainperl_is_instperl =
55497cff 193 &samepath($usrbinperl, $instperl) ||
4927f9a3 194 &samepath($usrbinperl, $expinstperl) ||
a0d0e21e 195 (($binexp ne $installbin) &&
55497cff 196 (-l $usrbinperl) &&
197 ((readlink $usrbinperl) eq $expinstperl));
a0d0e21e 198 }
199 if ((! $mainperl_is_instperl) &&
55497cff 200 (&yn("Many scripts expect perl to be installed as $usrbinperl.\n" .
201 "Do you wish to have $usrbinperl be the same as\n" .
202 "$expinstperl? [y] ")))
a0d0e21e 203 {
55497cff 204 unlink($usrbinperl);
205 eval { CORE::link $instperl, $usrbinperl } ||
206 eval { symlink $expinstperl, $usrbinperl } ||
207 cmd("cp $instperl $usrbinperl");
a0d0e21e 208 $mainperl_is_instperl = 1;
209 }
210}
211
212# Check to make sure there aren't other perls around in installer's
213# path. This is probably UNIX-specific. Check all absolute directories
214# in the path except for where public executables are supposed to live.
215# Also skip $mainperl if the user opted to have it be a link to the
216# installed perl.
217
39add537 218$dirsep = ($^O eq 'os2') ? ';' : ':' ;
219($path = $ENV{"PATH"}) =~ s:\\:/:g ;
220@path = split(/$dirsep/, $path);
a0d0e21e 221@otherperls = ();
222for (@path) {
223 next unless m,^/,;
224 next if ($_ eq $binexp);
225 # Use &samepath here because some systems have other dirs linked
226 # to $mainperldir (like SunOS)
227 next if ($mainperl_is_instperl && &samepath($_, $mainperldir));
39add537 228 push(@otherperls, "$_/perl$exe_ext")
229 if (-x "$_/perl$exe_ext" && ! -d "$_/perl$exe_ext");
a0d0e21e 230}
231if (@otherperls) {
232 print STDERR "\nWarning: perl appears in your path in the following " .
233 "locations beyond where\nwe just installed it:\n";
234 for (@otherperls) {
235 print STDERR " ", $_, "\n";
236 }
237 print STDERR "\n";
238}
239
c623bd54 240print STDERR " Installation complete\n";
241
242exit 0;
243
244###############################################################################
245
a0d0e21e 246sub yn {
247 local($prompt) = @_;
248 local($answer);
249 local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
250 print STDERR $prompt;
251 chop($answer = <STDIN>);
252 $answer = $default if $answer =~ m/^\s*$/;
253 ($answer =~ m/^[yY]/);
254}
255
c623bd54 256sub unlink {
257 local(@names) = @_;
39add537 258 my($cnt) = 0;
c623bd54 259
260 foreach $name (@names) {
261 next unless -e $name;
39add537 262 chmod 0777, $name if $^O eq 'os2';
c623bd54 263 print STDERR " unlink $name\n";
39add537 264 ( CORE::unlink($name) and ++$cnt
265 or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
c623bd54 266 }
39add537 267 return $cnt;
c623bd54 268}
269
e50aee73 270sub safe_unlink {
271 local(@names) = @_;
272
273 foreach $name (@names) {
274 next unless -e $name;
e50aee73 275 next if $nonono;
39add537 276 chmod 0777, $name if $^O eq 'os2';
277 print STDERR " unlink $name\n";
278 next if CORE::unlink($name);
e50aee73 279 warn "Couldn't unlink $name: $!\n";
280 if ($! =~ /busy/i) {
281 print STDERR " mv $name $name.old\n";
282 &rename($name, "$name.old") || warn "Couldn't rename $name: $!\n";
283 }
284 }
285}
286
c623bd54 287sub cmd {
288 local($cmd) = @_;
289 print STDERR " $cmd\n";
290 unless ($nonono) {
291 system $cmd;
292 warn "Command failed!!!\n" if $?;
293 }
294}
295
e50aee73 296sub rename {
297 local($from,$to) = @_;
39add537 298 if (-f $to and not unlink($to)) {
e50aee73 299 my($i);
300 for ($i = 1; $i < 50; $i++) {
39add537 301 last if CORE::rename($to, "$to.$i");
e50aee73 302 }
39add537 303 warn("Cannot rename to `$to.$i': $!"), return 0
304 if $i >= 50; # Give up!
e50aee73 305 }
306 link($from,$to) || return 0;
307 unlink($from);
308}
309
c623bd54 310sub link {
15792f64 311 my($from,$to) = @_;
312 my($success) = 0;
c623bd54 313
314 print STDERR " ln $from $to\n";
39add537 315 eval {
15792f64 316 CORE::link($from,$to) ? $success++ : warn "Couldn't link $from to $to: $!\n" unless $nonono;
39add537 317 };
318 if ($@) {
15792f64 319 system( $cp, $from, $to )==0 ? $success++ :
320 warn "Couldn't copy $from to $to: $!\n" unless $nonono;
39add537 321 }
15792f64 322 $success;
c623bd54 323}
324
325sub chmod {
326 local($mode,$name) = @_;
327
328 printf STDERR " chmod %o %s\n", $mode, $name;
39add537 329 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
c623bd54 330 unless $nonono;
331}
332
a0d0e21e 333sub samepath {
334 local($p1, $p2) = @_;
335 local($dev1, $ino1, $dev2, $ino2);
336
75f92628 337 if ($p1 ne $p2) {
a0d0e21e 338 ($dev1, $ino1) = stat($p1);
339 ($dev2, $ino2) = stat($p2);
340 ($dev1 == $dev2 && $ino1 == $ino2);
341 }
342 else {
343 1;
344 }
345}
346
347sub installlib {
348 my $dir = $File::Find::dir;
349 $dir =~ s#^\.(?![^/])/?##;
0ecb046b 350 local($depth) = $dir ? "lib/$dir" : "lib";
a0d0e21e 351
352 my $name = $_;
e50aee73 353
354 # ignore patch backups and the .exists files.
355 return if $name =~ m{\.orig$|~$|^\.exists};
356
a0d0e21e 357 $name = "$dir/$name" if $dir ne '';
358
359 my $installlib = $installprivlib;
1dd15ed4 360 if ($dir =~ /^auto/ ||
361 ($name =~ /^(.*)\.(?:pm|pod)$/ && $archpms{$1})) {
a0d0e21e 362 $installlib = $installarchlib;
363 return unless $do_installarchlib;
364 } else {
365 return unless $do_installprivlib;
366 }
367
a0d0e21e 368 if (-f $_) {
3edbfbe5 369 if (/\.al$/ || /\.ix$/) {
370 $installlib = $installprivlib;
371 #We're installing *.al and *.ix files into $installprivlib,
372 #but we have to delete old *.al and *.ix files from the 5.000
373 #distribution:
75f92628 374 #This might not work because $archname might have changed.
3edbfbe5 375 &unlink("$installarchlib/$name");
376 }
5f05dabc 377 if (compare($_, "$installlib/$name") || $nonono) {
a0d0e21e 378 &unlink("$installlib/$name");
fcbdbaa8 379 mkpath("$installlib/$dir", 1, 0777);
75f92628 380 # HP-UX (at least) needs to maintain execute permissions
381 # on dynamically-loaded libraries.
aa3cf465 382 cp_if_diff($_, "$installlib/$name")
383 and &chmod($name =~ /\.(so|$dlext)$/o ? 0555 : 0444,
384 "$installlib/$name");
a0d0e21e 385 }
386 } elsif (-d $_) {
fcbdbaa8 387 mkpath("$installlib/$name", 1, 0777);
a0d0e21e 388 }
389}
3edbfbe5 390
16d20bd9 391# Copy $from to $to, only if $from is different than $to.
392# Also preserve modification times for .a libraries.
393# On some systems, if you do
394# ranlib libperl.a
395# cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
396# and then try to link against the installed libperl.a, you might
397# get an error message to the effect that the symbol table is older
398# than the library.
aa3cf465 399# Return true if copying occurred.
3edbfbe5 400sub cp_if_diff {
401 my($from,$to)=@_;
402 -f $from || die "$0: $from not found";
5f05dabc 403 if (compare($from, $to) || $nonono) {
16d20bd9 404 my ($atime, $mtime);
5d94fbed 405 unlink($to); # In case we don't have write permissions.
0ecb046b 406 if ($nonono) {
407 $from = $depth . "/" . $from if $depth;
408 }
3edbfbe5 409 cmd("cp $from $to");
16d20bd9 410 # Restore timestamps if it's a .a library.
a2a3efe7 411 if ($to =~ /\.a$/ or $^O eq 'os2') { # For binary install
16d20bd9 412 ($atime, $mtime) = (stat $from)[8,9];
413 utime $atime, $mtime, $to;
414 }
aa3cf465 415 1;
3edbfbe5 416 }
417}