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 $libperl = $Config{libperl};
47 # Shared library and dynamic loading suffixes.
49 $dlext = $Config{dlext};
51 $d_dosuid = $Config{d_dosuid};
52 $binexp = $Config{binexp};
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 || mkpath($installbin, 1, 0777);
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' . $exe_ext || die "perl isn't executable!\n";
65 -x 'suidperl' . $exe_ext|| 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";
70 # First we install the version-numbered executables.
72 &safe_unlink("$installbin/perl$ver$exe_ext");
73 &cmd("cp perl$exe_ext $installbin/perl$ver$exe_ext");
75 &safe_unlink("$installbin/sperl$ver$exe_ext");
77 &cmd("cp suidperl$exe_ext $installbin/sperl$ver$exe_ext");
78 &chmod(04711, "$installbin/sperl$ver$exe_ext");
81 exit 0 if $versiononly;
83 # Make links to ordinary names if installbin directory isn't current directory.
85 if (! &samepath($installbin, '.')) {
86 &safe_unlink("$installbin/perl$exe_ext", "$installbin/suidperl$exe_ext");
87 &link("$installbin/perl$ver$exe_ext", "$installbin/perl$exe_ext");
88 &link("$installbin/sperl$ver$exe_ext", "$installbin/suidperl$exe_ext")
92 if (! &samepath($installbin, 'x2p')) {
93 &safe_unlink("$installbin/a2p$exe_ext");
94 &cmd("cp x2p/a2p$exe_ext $installbin/a2p$exe_ext");
95 &chmod(0755, "$installbin/a2p$exe_ext");
98 # cppstdin is just a script, but it is architecture-dependent, so
99 # it can't safely be shared. Place it in $installbin.
100 # Note that Configure doesn't build cppstin if it isn't needed, so
101 # we skip this if cppstdin doesn't exist.
102 if ((-f cppstdin) && (! &samepath($installbin, '.'))) {
103 &safe_unlink("$installbin/cppstdin");
104 &cmd("cp cppstdin $installbin/cppstdin");
105 &chmod(0755, "$installbin/cppstdin");
110 mkpath($installscript, 1, 0777);
113 &cmd("cp $_ $installscript");
114 s#.*/##; &chmod(0755, "$installscript/$_");
117 # Install pod pages. Where? I guess in $installprivlib/pod.
118 mkpath("${installprivlib}/pod", 1, 0777);
119 foreach $file (@pods) {
120 # $file is a name like pod/perl.pod
121 cp_if_diff($file, "${installprivlib}/${file}");
124 # Install old man pages.
126 if ($installman1dir ne '') {
127 mkpath($installman1dir, 1, 0777);
129 if (! &samepath($installman1dir, '.')) {
131 ($new = $_) =~ s/man$/$man1ext/;
133 print STDERR " Installing $installman1dir/$new\n";
135 open(MI,$_) || warn "Can't open $_: $!\n";
136 open(MO,">$installman1dir/$new") ||
137 warn "Can't install $installman1dir/$new: $!\n";
138 print MO ".ds RP Release $release Patchlevel $patchlevel\n";
148 # Install library files.
150 $do_installarchlib = $do_installprivlib = 0;
152 mkpath($installprivlib, 1, 0777);
153 mkpath($installarchlib, 1, 0777);
154 mkpath($installsitelib, 1, 0777) if ($installsitelib);
155 mkpath($installsitearch, 1, 0777) if ($installsitearch);
158 $do_installarchlib = ! &samepath($installarchlib, '.');
159 $do_installprivlib = ! &samepath($installprivlib, '.');
161 if ($do_installarchlib || $do_installprivlib) {
162 find(\&installlib, '.');
164 chdir ".." || die "Can't cd back to source directory: $!\n";
167 warn "Can't cd to lib to install lib files: $!\n";
170 # Install header files and libraries.
171 mkpath("$installarchlib/CORE", 1, 0777);
172 @corefiles = <*.h libperl*.*>;
173 # AIX needs perl.exp installed as well.
174 push(@corefiles,'perl.exp') if $^O eq 'aix';
175 # If they have built sperl.o...
176 push(@corefiles,'sperl.o') if -f 'sperl.o';
177 foreach $file (@corefiles) {
178 cp_if_diff($file,"$installarchlib/CORE/$file");
179 &chmod($file =~ /^libperl/ ? 0555 : 0444,"$installarchlib/CORE/$file");
182 # Offer to install perl in a "standard" location
184 $mainperl_is_instperl = 0;
186 if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) {
187 # First make sure $mainperldir/perl is not already the same as
188 # the perl we just installed
189 if (-x "$mainperldir/perl$exe_ext") {
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 =
193 &samepath("$mainperldir/perl$exe_ext", "$installbin/perl$exe_ext") ||
194 (($binexp ne $installbin) &&
195 (-l "$mainperldir/perl$exe_ext") &&
196 ((readlink "$mainperldir/perl$exe_ext") eq "$binexp/perl$exe_ext"));
198 if ((! $mainperl_is_instperl) &&
199 (&yn("Many scripts expect perl to be installed as " .
200 "$mainperldir/perl.\n" .
201 "Do you wish to have $mainperldir/perl be the same as\n" .
202 "$binexp/perl? [y] ")))
204 unlink("$mainperldir/perl$exe_ext");
205 CORE::link("$installbin/perl$exe_ext", "$mainperldir/perl$exe_ext") ||
206 symlink("$binexp/perl$exe_ext", "$mainperldir/perl$exe_ext") ||
207 cmd("cp $installbin/perl$exe_ext $mainperldir$exe_ext");
208 $mainperl_is_instperl = 1;
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
218 $dirsep = ($^O eq 'os2') ? ';' : ':' ;
219 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
220 @path = split(/$dirsep/, $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$exe_ext")
229 if (-x "$_/perl$exe_ext" && ! -d "$_/perl$exe_ext");
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]/);
260 foreach $name (@names) {
261 next unless -e $name;
262 chmod 0777, $name if $^O eq 'os2';
263 print STDERR " unlink $name\n";
264 ( CORE::unlink($name) and ++$cnt
265 or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
273 foreach $name (@names) {
274 next unless -e $name;
276 chmod 0777, $name if $^O eq 'os2';
277 print STDERR " unlink $name\n";
278 next if CORE::unlink($name);
279 warn "Couldn't unlink $name: $!\n";
281 print STDERR " mv $name $name.old\n";
282 &rename($name, "$name.old") || warn "Couldn't rename $name: $!\n";
289 print STDERR " $cmd\n";
292 warn "Command failed!!!\n" if $?;
297 local($from,$to) = @_;
298 if (-f $to and not unlink($to)) {
300 for ($i = 1; $i < 50; $i++) {
301 last if CORE::rename($to, "$to.$i");
303 warn("Cannot rename to `$to.$i': $!"), return 0
304 if $i >= 50; # Give up!
306 link($from,$to) || return 0;
314 print STDERR " ln $from $to\n";
316 CORE::link($from,$to) ? $success++ : warn "Couldn't link $from to $to: $!\n" unless $nonono;
319 system( $cp, $from, $to )==0 ? $success++ :
320 warn "Couldn't copy $from to $to: $!\n" unless $nonono;
326 local($mode,$name) = @_;
328 printf STDERR " chmod %o %s\n", $mode, $name;
329 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
334 local($p1, $p2) = @_;
335 local($dev1, $ino1, $dev2, $ino2);
338 ($dev1, $ino1) = stat($p1);
339 ($dev2, $ino2) = stat($p2);
340 ($dev1 == $dev2 && $ino1 == $ino2);
348 my $dir = $File::Find::dir;
349 $dir =~ s#^\.(?![^/])/?##;
353 # ignore patch backups and the .exists files.
354 return if $name =~ m{\.orig$|~$|^\.exists};
356 $name = "$dir/$name" if $dir ne '';
358 my $installlib = $installprivlib;
359 if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) {
360 $installlib = $installarchlib;
361 return unless $do_installarchlib;
363 return unless $do_installprivlib;
367 if (/\.al$/ || /\.ix$/) {
368 $installlib = $installprivlib;
369 #We're installing *.al and *.ix files into $installprivlib,
370 #but we have to delete old *.al and *.ix files from the 5.000
372 #This might not work because $archname might have changed.
373 &unlink("$installarchlib/$name");
375 system "cmp", "-s", $_, "$installlib/$name";
377 &unlink("$installlib/$name");
378 mkpath("$installlib/$dir", 1, 0777);
379 cp_if_diff($_, "$installlib/$name");
380 # HP-UX (at least) needs to maintain execute permissions
381 # on dynamically-loaded libraries.
382 if ($name =~ /\.(so|$dlext)$/o) {
383 &chmod(0555, "$installlib/$name");
386 &chmod(0444, "$installlib/$name");
390 mkpath("$installlib/$name", 1, 0777);
394 # Copy $from to $to, only if $from is different than $to.
395 # Also preserve modification times for .a libraries.
396 # On some systems, if you do
398 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
399 # and then try to link against the installed libperl.a, you might
400 # get an error message to the effect that the symbol table is older
404 -f $from || die "$0: $from not found";
405 system "cmp", "-s", $from, $to;
408 unlink($to); # In case we don't have write permissions.
410 # Restore timestamps if it's a .a library.
412 ($atime, $mtime) = (stat $from)[8,9];
413 utime $atime, $mtime, $to;