2 BEGIN { @INC=('./lib', '../lib') }
6 $mainperldir = "/usr/bin";
9 $nonono = 1 if $ARGV[0] eq '-n';
10 $versiononly = 1 if $ARGV[0] eq '-v';
16 @scripts = qw(cppstdin
17 utils/c2ph utils/h2ph utils/h2xs utils/pstruct
18 utils/perlbug utils/perldoc
20 pod/pod2man pod/pod2html pod/pod2latex pod/pod2text);
22 # pod documentation now handled by separate installman script.
23 # These two are archaic leftovers.
24 @manpages = qw(x2p/a2p.man x2p/s2p.man);
26 @pods = (<pod/*.pod>);
29 $release = substr($ver,0,3); # Not used presently.
30 $patchlevel = substr($ver,3,2);
31 die "Patchlevel of perl ($patchlevel)",
32 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
33 if $patchlevel != $Config{'PATCHLEVEL'};
35 # Fetch some frequently-used items from %Config
36 $installbin = $Config{installbin};
37 $installscript = $Config{installscript};
38 $installprivlib = $Config{installprivlib};
39 $installarchlib = $Config{installarchlib};
40 $installsitelib = $Config{installsitelib};
41 $installsitearch = $Config{installsitearch};
42 $installman1dir = $Config{installman1dir};
43 $man1ext = $Config{man1ext};
44 # Did we build libperl as a shared library?
45 $d_shrplib = $Config{d_shrplib};
46 $shrpdir = $Config{shrpdir};
47 # Shared library and dynamic loading suffixes.
49 $dlext = $Config{dlext};
51 $d_dosuid = $Config{d_dosuid};
52 $binexp = $Config{binexp};
53 $osname = $Config{osname};
55 # Do some quick sanity checks.
57 if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
59 $installbin || die "No installbin directory in config.sh\n";
60 -d $installbin || makedir($installbin);
61 -d $installbin || die "$installbin is not a directory\n";
62 -w $installbin || die "$installbin is not writable by you\n"
63 unless $installbin =~ m#^/afs/# || $nonono;
65 -x 'perl' || die "perl isn't executable!\n";
66 -x 'suidperl' || die "suidperl isn't executable!\n" if $d_dosuid;
68 -x 't/TEST' || warn "WARNING: You've never run 'make test'!!!",
69 " (Installing anyway.)\n";
72 if (!<libperl*.$so*>) {
73 warn "WARNING: Can't find libperl*.$so* to install into $shrpdir.",
74 " (Installing other things anyway.)\n";
77 -w $shrpdir || die "$shrpdir is not writable by you\n";
78 &cmd("cp libperl*.$so* $shrpdir");
82 # First we install the version-numbered executables.
84 &safe_unlink("$installbin/perl$ver");
85 &cmd("cp perl $installbin/perl$ver");
87 &safe_unlink("$installbin/sperl$ver");
89 &cmd("cp suidperl $installbin/sperl$ver");
90 &chmod(04711, "$installbin/sperl$ver");
93 exit 0 if $versiononly;
95 # Make links to ordinary names if installbin directory isn't current directory.
97 if (! &samepath($installbin, '.')) {
98 &safe_unlink("$installbin/perl", "$installbin/suidperl");
99 &link("$installbin/perl$ver", "$installbin/perl");
100 &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
103 if (! &samepath($installbin, 'x2p')) {
104 &safe_unlink("$installbin/a2p");
105 &cmd("cp x2p/a2p $installbin/a2p");
106 &chmod(0755, "$installbin/a2p");
111 &makedir($installscript);
114 if (-f $_) { # cppstdin might not exist on this system.
115 &cmd("cp $_ $installscript");
116 s#.*/##; &chmod(0755, "$installscript/$_");
120 # Install pod pages. Where? I guess in $installprivlib/pod.
121 &makedir("${installprivlib}/pod");
122 foreach $file (@pods) {
123 # $file is a name like pod/perl.pod
124 cp_if_diff($file, "${installprivlib}/${file}");
127 # Install old man pages.
129 if ($installman1dir ne '') {
130 &makedir($installman1dir);
132 if (! &samepath($installman1dir, '.')) {
134 ($new = $_) =~ s/man$/$man1ext/;
136 print STDERR " Installing $installman1dir/$new\n";
138 open(MI,$_) || warn "Can't open $_: $!\n";
139 open(MO,">$installman1dir/$new") ||
140 warn "Can't install $installman1dir/$new: $!\n";
141 print MO ".ds RP Release $release Patchlevel $patchlevel\n";
151 # Install library files.
153 $do_installarchlib = $do_installprivlib = 0;
155 &makedir($installprivlib);
156 &makedir($installarchlib);
157 &makedir($installsitelib) if ($installsitelib);
158 &makedir($installsitearch) if ($installsitearch);
161 $do_installarchlib = ! &samepath($installarchlib, '.');
162 $do_installprivlib = ! &samepath($installprivlib, '.');
164 if ($do_installarchlib || $do_installprivlib) {
165 find(\&installlib, '.');
167 chdir ".." || die "Can't cd back to source directory: $!\n";
170 warn "Can't cd to lib to install lib files: $!\n";
173 # Install header files and libraries.
174 makedir("$installarchlib/CORE");
175 foreach $file (<*.h libperl*.*>) {
176 cp_if_diff($file,"$installarchlib/CORE/$file");
178 # AIX needs perl.exp installed as well.
179 cp_if_diff("perl.exp" ,"$installarchlib/CORE/perl.exp") if ($osname eq 'aix');
181 # If they have built sperl.o...
182 cp_if_diff("sperl.o" ,"$installarchlib/CORE/sperl.o") if (-f 'sperl.o');
185 # Offer to install perl in a "standard" location
187 $mainperl_is_instperl = 0;
189 if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) {
190 # First make sure $mainperldir/perl is not already the same as
191 # the perl we just installed
192 if (-x "$mainperldir/perl") {
193 # Try to be clever about mainperl being a symbolic link
194 # to binexp/perl if binexp and installbin are different.
195 $mainperl_is_instperl =
196 &samepath("$mainperldir/perl", "$installbin/perl") ||
197 (($binexp ne $installbin) &&
198 (-l "$mainperldir/perl") &&
199 ((readlink "$mainperldir/perl") eq "$binexp/perl"));
201 if ((! $mainperl_is_instperl) &&
202 (&yn("Many scripts expect perl to be installed as " .
203 "$mainperldir/perl.\n" .
204 "Do you wish to have $mainperldir/perl be the same as\n" .
205 "$binexp/perl? [y] ")))
207 unlink("$mainperldir/perl");
208 eval 'link("$installbin/perl", "$mainperldir/perl")' ||
209 eval 'symlink("$binexp/perl", "$mainperldir/perl")' ||
210 &cmd("cp $installbin/perl $mainperldir");
211 $mainperl_is_instperl = 1;
215 # Check to make sure there aren't other perls around in installer's
216 # path. This is probably UNIX-specific. Check all absolute directories
217 # in the path except for where public executables are supposed to live.
218 # Also skip $mainperl if the user opted to have it be a link to the
221 @path = split(/:/, $ENV{"PATH"});
225 next if ($_ eq $binexp);
226 # Use &samepath here because some systems have other dirs linked
227 # to $mainperldir (like SunOS)
228 next if ($mainperl_is_instperl && &samepath($_, $mainperldir));
229 push(@otherperls, "$_/perl") if (-x "$_/perl" && ! -d "$_/perl");
232 print STDERR "\nWarning: perl appears in your path in the following " .
233 "locations beyond where\nwe just installed it:\n";
235 print STDERR " ", $_, "\n";
240 print STDERR " Installation complete\n";
244 ###############################################################################
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]/);
259 foreach $name (@names) {
260 next unless -e $name;
261 print STDERR " unlink $name\n";
262 unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
269 foreach $name (@names) {
270 next unless -e $name;
271 print STDERR " unlink $name\n";
273 next if unlink($name);
274 warn "Couldn't unlink $name: $!\n";
276 print STDERR " mv $name $name.old\n";
277 &rename($name, "$name.old") || warn "Couldn't rename $name: $!\n";
284 print STDERR " $cmd\n";
287 warn "Command failed!!!\n" if $?;
292 local($from,$to) = @_;
293 unless (unlink($to)) {
295 for ($i = 1; $i < 50; $i++) {
296 last if rename($to, "$to.$i");
298 return 0 if $i >= 50; # Give up!
300 link($from,$to) || return 0;
305 local($from,$to) = @_;
307 print STDERR " ln $from $to\n";
308 link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
312 local($mode,$name) = @_;
314 printf STDERR " chmod %o %s\n", $mode, $name;
315 chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
322 local($shortdir) = $dir;
324 $shortdir =~ s#(.*)/.*#$1#;
327 print STDERR " mkdir $dir\n";
328 mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono;
333 local($p1, $p2) = @_;
334 local($dev1, $ino1, $dev2, $ino2);
337 ($dev1, $ino1) = stat($p1);
338 ($dev2, $ino2) = stat($p2);
339 ($dev1 == $dev2 && $ino1 == $ino2);
347 my $dir = $File::Find::dir;
348 $dir =~ s#^\.(?![^/])/?##;
352 # ignore patch backups and the .exists files.
353 return if $name =~ m{\.orig$|~$|^\.exists};
355 $name = "$dir/$name" if $dir ne '';
357 my $installlib = $installprivlib;
358 if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) {
359 $installlib = $installarchlib;
360 return unless $do_installarchlib;
362 return unless $do_installprivlib;
366 if (/\.al$/ || /\.ix$/) {
367 $installlib = $installprivlib;
368 #We're installing *.al and *.ix files into $installprivlib,
369 #but we have to delete old *.al and *.ix files from the 5.000
371 #This might not work because $archname might have changed.
372 &unlink("$installarchlib/$name");
374 system "cmp", "-s", $_, "$installlib/$name";
376 &unlink("$installlib/$name");
377 &makedir("$installlib/$dir");
378 cp_if_diff($_, "$installlib/$name");
379 # HP-UX (at least) needs to maintain execute permissions
380 # on dynamically-loaded libraries.
381 if ($name =~ /\.(so|$dlext)$/o) {
382 &chmod(0555, "$installlib/$name");
385 &chmod(0444, "$installlib/$name");
389 &makedir("$installlib/$name");
393 # Copy $from to $to, only if $from is different than $to.
394 # Also preserve modification times for .a libraries.
395 # On some systems, if you do
397 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
398 # and then try to link against the installed libperl.a, you might
399 # get an error message to the effect that the symbol table is older
403 -f $from || die "$0: $from not found";
404 system "cmp", "-s", $from, $to;
407 unlink($to); # In case we don't have write permissions.
409 # Restore timestamps if it's a .a library.
411 ($atime, $mtime) = (stat $from)[8,9];
412 utime $atime, $mtime, $to;