2 BEGIN { @INC=('./lib', '../lib') }
4 use File::Path qw(mkpath);
6 use subs qw(unlink rename link chmod);
8 $mainperldir = "/usr/bin";
9 $exe_ext = $Config{exe_ext};
12 $nonono = 1 if $ARGV[0] eq '-n';
13 $versiononly = 1 if $ARGV[0] eq '-v';
19 @scripts = qw( utils/c2ph utils/h2ph utils/h2xs utils/pstruct
20 utils/perlbug utils/perldoc
22 pod/pod2man pod/pod2html pod/pod2latex pod/pod2text);
24 # pod documentation now handled by separate installman script.
25 # These two are archaic leftovers.
26 @manpages = qw(x2p/a2p.man x2p/s2p.man);
28 @pods = (<pod/*.pod>);
31 $release = substr($ver,0,3); # Not used presently.
32 $patchlevel = substr($ver,3,2);
33 die "Patchlevel of perl ($patchlevel)",
34 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
35 if $patchlevel != $Config{'PATCHLEVEL'};
37 # Fetch some frequently-used items from %Config
38 $installbin = $Config{installbin};
39 $installscript = $Config{installscript};
40 $installprivlib = $Config{installprivlib};
41 $installarchlib = $Config{installarchlib};
42 $installsitelib = $Config{installsitelib};
43 $installsitearch = $Config{installsitearch};
44 $installman1dir = $Config{installman1dir};
45 $man1ext = $Config{man1ext};
46 # Did we build libperl as a shared library?
47 $d_shrplib = $Config{d_shrplib};
48 $shrpdir = $Config{shrpdir};
49 # Shared library and dynamic loading suffixes.
51 $dlext = $Config{dlext};
53 $d_dosuid = $Config{d_dosuid};
54 $binexp = $Config{binexp};
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' . $exe_ext || die "perl isn't executable!\n";
67 -x 'suidperl' . $exe_ext|| 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 || $nonono || 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$exe_ext");
86 &cmd("cp perl$exe_ext $installbin/perl$ver$exe_ext");
88 &safe_unlink("$installbin/sperl$ver$exe_ext");
90 &cmd("cp suidperl$exe_ext $installbin/sperl$ver$exe_ext");
91 &chmod(04711, "$installbin/sperl$ver$exe_ext");
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$exe_ext", "$installbin/suidperl$exe_ext");
100 &link("$installbin/perl$ver$exe_ext", "$installbin/perl$exe_ext");
101 &link("$installbin/sperl$ver$exe_ext", "$installbin/suidperl$exe_ext")
105 if (! &samepath($installbin, 'x2p')) {
106 &safe_unlink("$installbin/a2p$exe_ext");
107 &cmd("cp x2p/a2p$exe_ext $installbin/a2p$exe_ext");
108 &chmod(0755, "$installbin/a2p$exe_ext");
111 # cppstdin is just a script, but it is architecture-dependent, so
112 # it can't safely be shared. Place it in $installbin.
113 # Note that Configure doesn't build cppstin if it isn't needed, so
114 # we skip this if cppstdin doesn't exist.
115 if ((-f cppstdin) && (! &samepath($installbin, '.'))) {
116 &safe_unlink("$installbin/cppstdin");
117 &cmd("cp cppstdin $installbin/cppstdin");
118 &chmod(0755, "$installbin/cppstdin");
123 mkpath($installscript, 1, 0777);
126 &cmd("cp $_ $installscript");
127 s#.*/##; &chmod(0755, "$installscript/$_");
130 # Install pod pages. Where? I guess in $installprivlib/pod.
131 mkpath("${installprivlib}/pod", 1, 0777);
132 foreach $file (@pods) {
133 # $file is a name like pod/perl.pod
134 cp_if_diff($file, "${installprivlib}/${file}");
137 # Install old man pages.
139 if ($installman1dir ne '') {
140 mkpath($installman1dir, 1, 0777);
142 if (! &samepath($installman1dir, '.')) {
144 ($new = $_) =~ s/man$/$man1ext/;
146 print STDERR " Installing $installman1dir/$new\n";
148 open(MI,$_) || warn "Can't open $_: $!\n";
149 open(MO,">$installman1dir/$new") ||
150 warn "Can't install $installman1dir/$new: $!\n";
151 print MO ".ds RP Release $release Patchlevel $patchlevel\n";
161 # Install library files.
163 $do_installarchlib = $do_installprivlib = 0;
165 mkpath($installprivlib, 1, 0777);
166 mkpath($installarchlib, 1, 0777);
167 mkpath($installsitelib, 1, 0777) if ($installsitelib);
168 mkpath($installsitearch, 1, 0777) if ($installsitearch);
171 $do_installarchlib = ! &samepath($installarchlib, '.');
172 $do_installprivlib = ! &samepath($installprivlib, '.');
174 if ($do_installarchlib || $do_installprivlib) {
175 find(\&installlib, '.');
177 chdir ".." || die "Can't cd back to source directory: $!\n";
180 warn "Can't cd to lib to install lib files: $!\n";
183 # Install header files and libraries.
184 mkpath("$installarchlib/CORE", 1, 0777);
185 @corefiles = <*.h libperl*.*>;
186 # AIX needs perl.exp installed as well.
187 push(@corefiles,'perl.exp') if $^O eq 'aix';
188 # If they have built sperl.o...
189 push(@corefiles,'sperl.o') if -f 'sperl.o';
190 foreach $file (@corefiles) {
191 cp_if_diff($file,"$installarchlib/CORE/$file");
192 &chmod($file =~ /^libperl/ ? 0555 : 0444,"$installarchlib/CORE/$file");
195 # Offer to install perl in a "standard" location
197 $mainperl_is_instperl = 0;
199 if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) {
200 # First make sure $mainperldir/perl is not already the same as
201 # the perl we just installed
202 if (-x "$mainperldir/perl$exe_ext") {
203 # Try to be clever about mainperl being a symbolic link
204 # to binexp/perl if binexp and installbin are different.
205 $mainperl_is_instperl =
206 &samepath("$mainperldir/perl$exe_ext", "$installbin/perl$exe_ext") ||
207 (($binexp ne $installbin) &&
208 (-l "$mainperldir/perl$exe_ext") &&
209 ((readlink "$mainperldir/perl$exe_ext") eq "$binexp/perl$exe_ext"));
211 if ((! $mainperl_is_instperl) &&
212 (&yn("Many scripts expect perl to be installed as " .
213 "$mainperldir/perl.\n" .
214 "Do you wish to have $mainperldir/perl be the same as\n" .
215 "$binexp/perl? [y] ")))
217 unlink("$mainperldir/perl$exe_ext");
218 eval 'link("$installbin/perl$exe_ext", "$mainperldir/perl$exe_ext")' ||
219 eval 'symlink("$binexp/perl$exe_ext", "$mainperldir/perl$exe_ext")' ||
220 &cmd("cp $installbin/perl$exe_ext $mainperldir$exe_ext");
221 $mainperl_is_instperl = 1;
225 # Check to make sure there aren't other perls around in installer's
226 # path. This is probably UNIX-specific. Check all absolute directories
227 # in the path except for where public executables are supposed to live.
228 # Also skip $mainperl if the user opted to have it be a link to the
231 $dirsep = ($^O eq 'os2') ? ';' : ':' ;
232 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
233 @path = split(/$dirsep/, $path);
237 next if ($_ eq $binexp);
238 # Use &samepath here because some systems have other dirs linked
239 # to $mainperldir (like SunOS)
240 next if ($mainperl_is_instperl && &samepath($_, $mainperldir));
241 push(@otherperls, "$_/perl$exe_ext")
242 if (-x "$_/perl$exe_ext" && ! -d "$_/perl$exe_ext");
245 print STDERR "\nWarning: perl appears in your path in the following " .
246 "locations beyond where\nwe just installed it:\n";
248 print STDERR " ", $_, "\n";
253 print STDERR " Installation complete\n";
257 ###############################################################################
262 local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
263 print STDERR $prompt;
264 chop($answer = <STDIN>);
265 $answer = $default if $answer =~ m/^\s*$/;
266 ($answer =~ m/^[yY]/);
273 foreach $name (@names) {
274 next unless -e $name;
275 chmod 0777, $name if $^O eq 'os2';
276 print STDERR " unlink $name\n";
277 ( CORE::unlink($name) and ++$cnt
278 or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
286 foreach $name (@names) {
287 next unless -e $name;
289 chmod 0777, $name if $^O eq 'os2';
290 print STDERR " unlink $name\n";
291 next if CORE::unlink($name);
292 warn "Couldn't unlink $name: $!\n";
294 print STDERR " mv $name $name.old\n";
295 &rename($name, "$name.old") || warn "Couldn't rename $name: $!\n";
302 print STDERR " $cmd\n";
305 warn "Command failed!!!\n" if $?;
310 local($from,$to) = @_;
311 if (-f $to and not unlink($to)) {
313 for ($i = 1; $i < 50; $i++) {
314 last if CORE::rename($to, "$to.$i");
316 warn("Cannot rename to `$to.$i': $!"), return 0
317 if $i >= 50; # Give up!
319 link($from,$to) || return 0;
324 local($from,$to) = @_;
326 print STDERR " ln $from $to\n";
328 CORE::link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
331 system( $cp, $from, $to )
332 && warn "Couldn't copy $from to $to: $!\n" unless $nonono;
337 local($mode,$name) = @_;
339 printf STDERR " chmod %o %s\n", $mode, $name;
340 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
345 local($p1, $p2) = @_;
346 local($dev1, $ino1, $dev2, $ino2);
349 ($dev1, $ino1) = stat($p1);
350 ($dev2, $ino2) = stat($p2);
351 ($dev1 == $dev2 && $ino1 == $ino2);
359 my $dir = $File::Find::dir;
360 $dir =~ s#^\.(?![^/])/?##;
364 # ignore patch backups and the .exists files.
365 return if $name =~ m{\.orig$|~$|^\.exists};
367 $name = "$dir/$name" if $dir ne '';
369 my $installlib = $installprivlib;
370 if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) {
371 $installlib = $installarchlib;
372 return unless $do_installarchlib;
374 return unless $do_installprivlib;
378 if (/\.al$/ || /\.ix$/) {
379 $installlib = $installprivlib;
380 #We're installing *.al and *.ix files into $installprivlib,
381 #but we have to delete old *.al and *.ix files from the 5.000
383 #This might not work because $archname might have changed.
384 &unlink("$installarchlib/$name");
386 system "cmp", "-s", $_, "$installlib/$name";
388 &unlink("$installlib/$name");
389 mkpath("$installlib/$dir", 1, 0777);
390 cp_if_diff($_, "$installlib/$name");
391 # HP-UX (at least) needs to maintain execute permissions
392 # on dynamically-loaded libraries.
393 if ($name =~ /\.(so|$dlext)$/o) {
394 &chmod(0555, "$installlib/$name");
397 &chmod(0444, "$installlib/$name");
401 mkpath("$installlib/$name", 1, 0777);
405 # Copy $from to $to, only if $from is different than $to.
406 # Also preserve modification times for .a libraries.
407 # On some systems, if you do
409 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
410 # and then try to link against the installed libperl.a, you might
411 # get an error message to the effect that the symbol table is older
415 -f $from || die "$0: $from not found";
416 system "cmp", "-s", $from, $to;
419 unlink($to); # In case we don't have write permissions.
421 # Restore timestamps if it's a .a library.
423 ($atime, $mtime) = (stat $from)[8,9];
424 utime $atime, $mtime, $to;