2 BEGIN { @INC=('./lib', '../lib') }
4 use File::Path qw(mkpath);
7 $mainperldir = "/usr/bin";
10 $nonono = 1 if $ARGV[0] eq '-n';
11 $versiononly = 1 if $ARGV[0] eq '-v';
17 @scripts = qw(cppstdin
18 utils/c2ph utils/h2ph utils/h2xs utils/pstruct
19 utils/perlbug utils/perldoc
21 pod/pod2man pod/pod2html pod/pod2latex pod/pod2text);
23 # pod documentation now handled by separate installman script.
24 # These two are archaic leftovers.
25 @manpages = qw(x2p/a2p.man x2p/s2p.man);
27 @pods = (<pod/*.pod>);
30 $release = substr($ver,0,3); # Not used presently.
31 $patchlevel = substr($ver,3,2);
32 die "Patchlevel of perl ($patchlevel)",
33 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
34 if $patchlevel != $Config{'PATCHLEVEL'};
36 # Fetch some frequently-used items from %Config
37 $installbin = $Config{installbin};
38 $installscript = $Config{installscript};
39 $installprivlib = $Config{installprivlib};
40 $installarchlib = $Config{installarchlib};
41 $installsitelib = $Config{installsitelib};
42 $installsitearch = $Config{installsitearch};
43 $installman1dir = $Config{installman1dir};
44 $man1ext = $Config{man1ext};
45 # Did we build libperl as a shared library?
46 $d_shrplib = $Config{d_shrplib};
47 $shrpdir = $Config{shrpdir};
48 # Shared library and dynamic loading suffixes.
50 $dlext = $Config{dlext};
52 $d_dosuid = $Config{d_dosuid};
53 $binexp = $Config{binexp};
54 $osname = $Config{osname};
56 # Do some quick sanity checks.
58 if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
60 $installbin || die "No installbin directory in config.sh\n";
61 -d $installbin || mkpath($installbin, 1, 0777);
62 -d $installbin || die "$installbin is not a directory\n";
63 -w $installbin || die "$installbin is not writable by you\n"
64 unless $installbin =~ m#^/afs/# || $nonono;
66 -x 'perl' || die "perl isn't executable!\n";
67 -x 'suidperl' || die "suidperl isn't executable!\n" if $d_dosuid;
69 -x 't/TEST' || warn "WARNING: You've never run 'make test'!!!",
70 " (Installing anyway.)\n";
73 if (!<libperl*.$so*>) {
74 warn "WARNING: Can't find libperl*.$so* to install into $shrpdir.",
75 " (Installing other things anyway.)\n";
77 mkpath($shrpdir, 1, 0777);
78 -w $shrpdir || die "$shrpdir is not writable by you\n";
79 &cmd("cp libperl*.$so* $shrpdir");
83 # First we install the version-numbered executables.
85 &safe_unlink("$installbin/perl$ver");
86 &cmd("cp perl $installbin/perl$ver");
88 &safe_unlink("$installbin/sperl$ver");
90 &cmd("cp suidperl $installbin/sperl$ver");
91 &chmod(04711, "$installbin/sperl$ver");
94 exit 0 if $versiononly;
96 # Make links to ordinary names if installbin directory isn't current directory.
98 if (! &samepath($installbin, '.')) {
99 &safe_unlink("$installbin/perl", "$installbin/suidperl");
100 &link("$installbin/perl$ver", "$installbin/perl");
101 &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
104 if (! &samepath($installbin, 'x2p')) {
105 &safe_unlink("$installbin/a2p");
106 &cmd("cp x2p/a2p $installbin/a2p");
107 &chmod(0755, "$installbin/a2p");
112 mkpath($installscript, 1, 0777);
115 if (-f $_) { # cppstdin might not exist on this system.
116 &cmd("cp $_ $installscript");
117 s#.*/##; &chmod(0755, "$installscript/$_");
121 # Install pod pages. Where? I guess in $installprivlib/pod.
122 mkpath("${installprivlib}/pod", 1, 0777);
123 foreach $file (@pods) {
124 # $file is a name like pod/perl.pod
125 cp_if_diff($file, "${installprivlib}/${file}");
128 # Install old man pages.
130 if ($installman1dir ne '') {
131 mkpath($installman1dir, 1, 0777);
133 if (! &samepath($installman1dir, '.')) {
135 ($new = $_) =~ s/man$/$man1ext/;
137 print STDERR " Installing $installman1dir/$new\n";
139 open(MI,$_) || warn "Can't open $_: $!\n";
140 open(MO,">$installman1dir/$new") ||
141 warn "Can't install $installman1dir/$new: $!\n";
142 print MO ".ds RP Release $release Patchlevel $patchlevel\n";
152 # Install library files.
154 $do_installarchlib = $do_installprivlib = 0;
156 mkpath($installprivlib, 1, 0777);
157 mkpath($installarchlib, 1, 0777);
158 mkpath($installsitelib, 1, 0777) if ($installsitelib);
159 mkpath($installsitearch, 1, 0777) if ($installsitearch);
162 $do_installarchlib = ! &samepath($installarchlib, '.');
163 $do_installprivlib = ! &samepath($installprivlib, '.');
165 if ($do_installarchlib || $do_installprivlib) {
166 find(\&installlib, '.');
168 chdir ".." || die "Can't cd back to source directory: $!\n";
171 warn "Can't cd to lib to install lib files: $!\n";
174 # Install header files and libraries.
175 mkpath("$installarchlib/CORE", 1, 0777);
176 foreach $file (<*.h libperl*.*>) {
177 cp_if_diff($file,"$installarchlib/CORE/$file");
179 # AIX needs perl.exp installed as well.
180 cp_if_diff("perl.exp" ,"$installarchlib/CORE/perl.exp") if ($osname eq 'aix');
182 # If they have built sperl.o...
183 cp_if_diff("sperl.o" ,"$installarchlib/CORE/sperl.o") if (-f 'sperl.o');
186 # Offer to install perl in a "standard" location
188 $mainperl_is_instperl = 0;
190 if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) {
191 # First make sure $mainperldir/perl is not already the same as
192 # the perl we just installed
193 if (-x "$mainperldir/perl") {
194 # Try to be clever about mainperl being a symbolic link
195 # to binexp/perl if binexp and installbin are different.
196 $mainperl_is_instperl =
197 &samepath("$mainperldir/perl", "$installbin/perl") ||
198 (($binexp ne $installbin) &&
199 (-l "$mainperldir/perl") &&
200 ((readlink "$mainperldir/perl") eq "$binexp/perl"));
202 if ((! $mainperl_is_instperl) &&
203 (&yn("Many scripts expect perl to be installed as " .
204 "$mainperldir/perl.\n" .
205 "Do you wish to have $mainperldir/perl be the same as\n" .
206 "$binexp/perl? [y] ")))
208 unlink("$mainperldir/perl");
209 eval 'link("$installbin/perl", "$mainperldir/perl")' ||
210 eval 'symlink("$binexp/perl", "$mainperldir/perl")' ||
211 &cmd("cp $installbin/perl $mainperldir");
212 $mainperl_is_instperl = 1;
216 # Check to make sure there aren't other perls around in installer's
217 # path. This is probably UNIX-specific. Check all absolute directories
218 # in the path except for where public executables are supposed to live.
219 # Also skip $mainperl if the user opted to have it be a link to the
222 @path = split(/:/, $ENV{"PATH"});
226 next if ($_ eq $binexp);
227 # Use &samepath here because some systems have other dirs linked
228 # to $mainperldir (like SunOS)
229 next if ($mainperl_is_instperl && &samepath($_, $mainperldir));
230 push(@otherperls, "$_/perl") if (-x "$_/perl" && ! -d "$_/perl");
233 print STDERR "\nWarning: perl appears in your path in the following " .
234 "locations beyond where\nwe just installed it:\n";
236 print STDERR " ", $_, "\n";
241 print STDERR " Installation complete\n";
245 ###############################################################################
250 local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
251 print STDERR $prompt;
252 chop($answer = <STDIN>);
253 $answer = $default if $answer =~ m/^\s*$/;
254 ($answer =~ m/^[yY]/);
260 foreach $name (@names) {
261 next unless -e $name;
262 print STDERR " unlink $name\n";
263 unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
270 foreach $name (@names) {
271 next unless -e $name;
272 print STDERR " unlink $name\n";
274 next if unlink($name);
275 warn "Couldn't unlink $name: $!\n";
277 print STDERR " mv $name $name.old\n";
278 &rename($name, "$name.old") || warn "Couldn't rename $name: $!\n";
285 print STDERR " $cmd\n";
288 warn "Command failed!!!\n" if $?;
293 local($from,$to) = @_;
294 unless (unlink($to)) {
296 for ($i = 1; $i < 50; $i++) {
297 last if rename($to, "$to.$i");
299 return 0 if $i >= 50; # Give up!
301 link($from,$to) || return 0;
306 local($from,$to) = @_;
308 print STDERR " ln $from $to\n";
309 link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
313 local($mode,$name) = @_;
315 printf STDERR " chmod %o %s\n", $mode, $name;
316 chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
321 local($p1, $p2) = @_;
322 local($dev1, $ino1, $dev2, $ino2);
325 ($dev1, $ino1) = stat($p1);
326 ($dev2, $ino2) = stat($p2);
327 ($dev1 == $dev2 && $ino1 == $ino2);
335 my $dir = $File::Find::dir;
336 $dir =~ s#^\.(?![^/])/?##;
340 # ignore patch backups and the .exists files.
341 return if $name =~ m{\.orig$|~$|^\.exists};
343 $name = "$dir/$name" if $dir ne '';
345 my $installlib = $installprivlib;
346 if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) {
347 $installlib = $installarchlib;
348 return unless $do_installarchlib;
350 return unless $do_installprivlib;
354 if (/\.al$/ || /\.ix$/) {
355 $installlib = $installprivlib;
356 #We're installing *.al and *.ix files into $installprivlib,
357 #but we have to delete old *.al and *.ix files from the 5.000
359 #This might not work because $archname might have changed.
360 &unlink("$installarchlib/$name");
362 system "cmp", "-s", $_, "$installlib/$name";
364 &unlink("$installlib/$name");
365 mkpath("$installlib/$dir", 1, 0777);
366 cp_if_diff($_, "$installlib/$name");
367 # HP-UX (at least) needs to maintain execute permissions
368 # on dynamically-loaded libraries.
369 if ($name =~ /\.(so|$dlext)$/o) {
370 &chmod(0555, "$installlib/$name");
373 &chmod(0444, "$installlib/$name");
377 mkpath("$installlib/$name", 1, 0777);
381 # Copy $from to $to, only if $from is different than $to.
382 # Also preserve modification times for .a libraries.
383 # On some systems, if you do
385 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
386 # and then try to link against the installed libperl.a, you might
387 # get an error message to the effect that the symbol table is older
391 -f $from || die "$0: $from not found";
392 system "cmp", "-s", $from, $to;
395 unlink($to); # In case we don't have write permissions.
397 # Restore timestamps if it's a .a library.
399 ($atime, $mtime) = (stat $from)[8,9];
400 utime $atime, $mtime, $to;