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 = ('cppstdin', 'c2ph', 'h2ph', 'h2xs', 'pstruct',
17 'x2p/s2p', 'x2p/find2perl',
19 'pod/pod2man', 'pod/pod2html', 'pod/pod2latex' );
21 # pod documentation now handled by separate installman script.
22 # These two are archaic leftovers.
23 @manpages = ('x2p/a2p.man', 'x2p/s2p.man');
25 @pods = (<pod/*.pod>);
28 $release = substr($ver,0,3); # Not used presently.
29 $patchlevel = substr($ver,3,2);
30 die "Patchlevel of perl ($patchlevel)",
31 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
32 if $patchlevel != $Config{'PATCHLEVEL'};
34 # Fetch some frequently-used items from %Config
35 $installbin = $Config{installbin};
36 $installscript = $Config{installscript};
37 $installprivlib = $Config{installprivlib};
38 $installarchlib = $Config{installarchlib};
39 $installsitelib = $Config{installsitelib};
40 $installsitearch = $Config{installsitearch};
41 $installman1dir = $Config{installman1dir};
42 $man1ext = $Config{man1ext};
43 # Did we build libperl as a shared library?
44 $d_shrplib = $Config{d_shrplib};
45 $shrpdir = $Config{shrpdir};
46 # Shared library and dynamic loading suffixes.
48 $dlext = $Config{dlext};
50 $d_dosuid = $Config{d_dosuid};
51 $binexp = $Config{binexp};
52 $osname = $Config{osname};
54 # Do some quick sanity checks.
56 if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
58 $installbin || die "No installbin directory in config.sh\n";
59 -d $installbin || makedir($installbin);
60 -d $installbin || die "$installbin is not a directory\n";
61 -w $installbin || die "$installbin is not writable by you\n"
62 unless $installbin =~ m#^/afs/# || $nonono;
64 -x 'perl' || die "perl isn't executable!\n";
65 -x 'suidperl' || die "suidperl isn't executable!\n" if $d_dosuid;
67 -x 't/TEST' || warn "WARNING: You've never run 'make test'!!!",
68 " (Installing anyway.)\n";
71 if (!<libperl*.$so*>) {
72 warn "WARNING: Can't find libperl*.$so* to install into $shrpdir.",
73 " (Installing other things anyway.)\n";
76 -w $shrpdir || die "$shrpdir is not writable by you\n";
77 &cmd("cp libperl*.$so* $shrpdir");
81 # First we install the version-numbered executables.
83 &safe_unlink("$installbin/perl$ver");
84 &cmd("cp perl $installbin/perl$ver");
86 &safe_unlink("$installbin/sperl$ver");
88 &cmd("cp suidperl $installbin/sperl$ver");
89 &chmod(04711, "$installbin/sperl$ver");
92 exit 0 if $versiononly;
94 # Make links to ordinary names if installbin directory isn't current directory.
96 if (! &samepath($installbin, '.')) {
97 &safe_unlink("$installbin/perl", "$installbin/suidperl");
98 &link("$installbin/perl$ver", "$installbin/perl");
99 &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
102 if (! &samepath($installbin, 'x2p')) {
103 &safe_unlink("$installbin/a2p");
104 &cmd("cp x2p/a2p $installbin/a2p");
105 &chmod(0755, "$installbin/a2p");
110 &makedir($installscript);
113 if (-f $_) { # cppstdin might not exist on this system.
114 &cmd("cp $_ $installscript");
115 s#.*/##; &chmod(0755, "$installscript/$_");
119 # Install pod pages. Where? I guess in $installprivlib/pod.
120 &makedir("${installprivlib}/pod");
121 foreach $file (@pods) {
122 # $file is a name like pod/perl.pod
123 cp_if_diff($file, "${installprivlib}/${file}");
126 # Install old man pages.
128 if ($installman1dir ne '') {
129 &makedir($installman1dir);
131 if (! &samepath($installman1dir, '.')) {
133 ($new = $_) =~ s/man$/$man1ext/;
135 print STDERR " Installing $installman1dir/$new\n";
137 open(MI,$_) || warn "Can't open $_: $!\n";
138 open(MO,">$installman1dir/$new") ||
139 warn "Can't install $installman1dir/$new: $!\n";
140 print MO ".ds RP Release $release Patchlevel $patchlevel\n";
150 # Install library files.
152 $do_installarchlib = $do_installprivlib = 0;
154 &makedir($installprivlib);
155 &makedir($installarchlib);
156 &makedir($installsitelib) if ($installsitelib);
157 &makedir($installsitearch) if ($installsitearch);
160 $do_installarchlib = ! &samepath($installarchlib, '.');
161 $do_installprivlib = ! &samepath($installprivlib, '.');
163 if ($do_installarchlib || $do_installprivlib) {
164 find(\&installlib, '.');
166 chdir ".." || die "Can't cd back to source directory: $!\n";
169 warn "Can't cd to lib to install lib files: $!\n";
172 # Install header files and libraries.
173 makedir("$installarchlib/CORE");
174 foreach $file (<*.h libperl*.*>) {
175 cp_if_diff($file,"$installarchlib/CORE/$file");
177 # AIX needs perl.exp installed as well.
178 cp_if_diff("perl.exp" ,"$installarchlib/CORE/perl.exp") if ($osname eq 'aix');
180 # If they have built sperl.o...
181 cp_if_diff("sperl.o" ,"$installarchlib/CORE/sperl.o") if (-f 'sperl.o');
184 # Offer to install perl in a "standard" location
186 $mainperl_is_instperl = 0;
188 if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) {
189 # First make sure $mainperldir/perl is not already the same as
190 # the perl we just installed
191 if (-x "$mainperldir/perl") {
192 # Try to be clever about mainperl being a symbolic link
193 # to binexp/perl if binexp and installbin are different.
194 $mainperl_is_instperl =
195 &samepath("$mainperldir/perl", "$installbin/perl") ||
196 (($binexp ne $installbin) &&
197 (-l "$mainperldir/perl") &&
198 ((readlink "$mainperldir/perl") eq "$binexp/perl"));
200 if ((! $mainperl_is_instperl) &&
201 (&yn("Many scripts expect perl to be installed as " .
202 "$mainperldir/perl.\n" .
203 "Do you wish to have $mainperldir/perl be the same as\n" .
204 "$binexp/perl? [y] ")))
206 unlink("$mainperldir/perl");
207 eval 'link("$installbin/perl", "$mainperldir/perl")' ||
208 eval 'symlink("$binexp/perl", "$mainperldir/perl")' ||
209 &cmd("cp $installbin/perl $mainperldir");
210 $mainperl_is_instperl = 1;
214 # Check to make sure there aren't other perls around in installer's
215 # path. This is probably UNIX-specific. Check all absolute directories
216 # in the path except for where public executables are supposed to live.
217 # Also skip $mainperl if the user opted to have it be a link to the
220 @path = split(/:/, $ENV{"PATH"});
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));
228 push(@otherperls, "$_/perl") if (-x "$_/perl" && ! -d "$_/perl");
231 print STDERR "\nWarning: perl appears in your path in the following " .
232 "locations beyond where\nwe just installed it:\n";
234 print STDERR " ", $_, "\n";
239 print STDERR " Installation complete\n";
243 ###############################################################################
248 local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
249 print STDERR $prompt;
250 chop($answer = <STDIN>);
251 $answer = $default if $answer =~ m/^\s*$/;
252 ($answer =~ m/^[yY]/);
258 foreach $name (@names) {
259 next unless -e $name;
260 print STDERR " unlink $name\n";
261 unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
268 foreach $name (@names) {
269 next unless -e $name;
270 print STDERR " unlink $name\n";
272 next if unlink($name);
273 warn "Couldn't unlink $name: $!\n";
275 print STDERR " mv $name $name.old\n";
276 &rename($name, "$name.old") || warn "Couldn't rename $name: $!\n";
283 print STDERR " $cmd\n";
286 warn "Command failed!!!\n" if $?;
291 local($from,$to) = @_;
292 unless (unlink($to)) {
294 for ($i = 1; $i < 50; $i++) {
295 last if rename($to, "$to.$i");
297 return 0 if $i >= 50; # Give up!
299 link($from,$to) || return 0;
304 local($from,$to) = @_;
306 print STDERR " ln $from $to\n";
307 link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
311 local($mode,$name) = @_;
313 printf STDERR " chmod %o %s\n", $mode, $name;
314 chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
321 local($shortdir) = $dir;
323 $shortdir =~ s#(.*)/.*#$1#;
326 print STDERR " mkdir $dir\n";
327 mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono;
332 local($p1, $p2) = @_;
333 local($dev1, $ino1, $dev2, $ino2);
336 ($dev1, $ino1) = stat($p1);
337 ($dev2, $ino2) = stat($p2);
338 ($dev1 == $dev2 && $ino1 == $ino2);
346 my $dir = $File::Find::dir;
347 $dir =~ s#^\.(?![^/])/?##;
351 # ignore patch backups and the .exists files.
352 return if $name =~ m{\.orig$|~$|^\.exists};
354 $name = "$dir/$name" if $dir ne '';
356 my $installlib = $installprivlib;
357 if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) {
358 $installlib = $installarchlib;
359 return unless $do_installarchlib;
361 return unless $do_installprivlib;
365 if (/\.al$/ || /\.ix$/) {
366 $installlib = $installprivlib;
367 #We're installing *.al and *.ix files into $installprivlib,
368 #but we have to delete old *.al and *.ix files from the 5.000
370 #This might not work because $archname might have changed.
371 &unlink("$installarchlib/$name");
373 system "cmp", "-s", $_, "$installlib/$name";
375 &unlink("$installlib/$name");
376 &makedir("$installlib/$dir");
377 cp_if_diff("$_", "$installlib/$dir/$_");
378 # HP-UX (at least) needs to maintain execute permissions
379 # on dynamically-loaded libraries.
380 if ($name =~ /\.(so|$dlext)$/o) {
381 &chmod(0555, "$installlib/$name");
384 &chmod(0444, "$installlib/$name");
388 &makedir("$installlib/$name");
392 # Copy $from to $to, only if $from is different than $to.
393 # Also preserve modification times for .a libraries.
394 # On some systems, if you do
396 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
397 # and then try to link against the installed libperl.a, you might
398 # get an error message to the effect that the symbol table is older
402 -f $from || die "$0: $from not found";
403 system "cmp", "-s", $from, $to;
406 unlink($to); # In case we don't have write permissions.
408 # Restore timestamps if it's a .a library.
410 ($atime, $mtime) = (stat $from)[8,9];
411 utime $atime, $mtime, $to;