2 BEGIN { @INC=('./lib', '../lib') }
7 use subs qw(unlink rename link chmod);
9 # override the ones in the rest of the script
12 File::Path::mkpath(@_) unless $nonono;
15 $mainperldir = "/usr/bin";
16 $exe_ext = $Config{exe_ext};
19 $nonono = 1 if $ARGV[0] eq '-n';
20 $versiononly = 1 if $ARGV[0] eq '-v';
26 @scripts = qw( utils/c2ph utils/h2ph utils/h2xs
27 utils/perlbug utils/perldoc utils/pl2pm utils/splain
29 pod/pod2man pod/pod2html pod/pod2latex pod/pod2text);
31 @pods = (<pod/*.pod>);
34 $release = substr($ver,0,3); # Not used presently.
35 $patchlevel = substr($ver,3,2);
36 die "Patchlevel of perl ($patchlevel)",
37 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
38 if $patchlevel != $Config{'PATCHLEVEL'};
40 # Fetch some frequently-used items from %Config
41 $installbin = $Config{installbin};
42 $installscript = $Config{installscript};
43 $installprivlib = $Config{installprivlib};
44 $installarchlib = $Config{installarchlib};
45 $installsitelib = $Config{installsitelib};
46 $installsitearch = $Config{installsitearch};
47 $installman1dir = $Config{installman1dir};
48 $man1ext = $Config{man1ext};
49 $libperl = $Config{libperl};
50 # Shared library and dynamic loading suffixes.
52 $dlext = $Config{dlext};
54 $d_dosuid = $Config{d_dosuid};
55 $binexp = $Config{binexp};
57 # Do some quick sanity checks.
59 if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
61 $installbin || die "No installbin directory in config.sh\n";
62 -d $installbin || mkpath($installbin, 1, 0777);
63 -d $installbin || $nonono || die "$installbin is not a directory\n";
64 -w $installbin || $nonono || die "$installbin is not writable by you\n"
65 unless $installbin =~ m#^/afs/# || $nonono;
67 -x 'perl' . $exe_ext || die "perl isn't executable!\n";
68 -x 'suidperl' . $exe_ext|| die "suidperl isn't executable!\n" if $d_dosuid;
70 -x 't/TEST' || warn "WARNING: You've never run 'make test'!!!",
71 " (Installing anyway.)\n";
73 # First we install the version-numbered executables.
75 &safe_unlink("$installbin/perl$ver$exe_ext");
76 &cmd("cp perl$exe_ext $installbin/perl$ver$exe_ext");
77 &chmod(0755, "$installbin/perl$ver$exe_ext");
79 &safe_unlink("$installbin/sperl$ver$exe_ext");
81 &cmd("cp suidperl$exe_ext $installbin/sperl$ver$exe_ext");
82 &chmod(04711, "$installbin/sperl$ver$exe_ext");
85 exit 0 if $versiononly;
87 # Make links to ordinary names if installbin directory isn't current directory.
89 if (! &samepath($installbin, '.')) {
90 &safe_unlink("$installbin/perl$exe_ext", "$installbin/suidperl$exe_ext");
91 &link("$installbin/perl$ver$exe_ext", "$installbin/perl$exe_ext");
92 &link("$installbin/sperl$ver$exe_ext", "$installbin/suidperl$exe_ext")
96 if (! &samepath($installbin, 'x2p')) {
97 &safe_unlink("$installbin/a2p$exe_ext");
98 &cmd("cp x2p/a2p$exe_ext $installbin/a2p$exe_ext");
99 &chmod(0755, "$installbin/a2p$exe_ext");
102 # cppstdin is just a script, but it is architecture-dependent, so
103 # it can't safely be shared. Place it in $installbin.
104 # Note that Configure doesn't build cppstin if it isn't needed, so
105 # we skip this if cppstdin doesn't exist.
106 if ((-f cppstdin) && (! &samepath($installbin, '.'))) {
107 &safe_unlink("$installbin/cppstdin");
108 &cmd("cp cppstdin $installbin/cppstdin");
109 &chmod(0755, "$installbin/cppstdin");
114 mkpath($installscript, 1, 0777);
117 &cmd("cp $_ $installscript");
118 s#.*/##; &chmod(0755, "$installscript/$_");
121 # pstruct should be a link to c2ph
123 &safe_unlink("$installscript/pstruct");
124 &link("$installscript/c2ph","$installscript/pstruct");
126 # Install pod pages. Where? I guess in $installprivlib/pod.
127 mkpath("${installprivlib}/pod", 1, 0777);
128 foreach $file (@pods) {
129 # $file is a name like pod/perl.pod
130 cp_if_diff($file, "${installprivlib}/${file}");
133 # Install library files.
135 $do_installarchlib = $do_installprivlib = 0;
137 mkpath($installprivlib, 1, 0777);
138 mkpath($installarchlib, 1, 0777);
139 mkpath($installsitelib, 1, 0777) if ($installsitelib);
140 mkpath($installsitearch, 1, 0777) if ($installsitearch);
143 $do_installarchlib = ! &samepath($installarchlib, '.');
144 $do_installprivlib = ! &samepath($installprivlib, '.');
146 if ($do_installarchlib || $do_installprivlib) {
147 find(\&installlib, '.');
149 chdir ".." || die "Can't cd back to source directory: $!\n";
152 warn "Can't cd to lib to install lib files: $!\n";
155 # Install header files and libraries.
156 mkpath("$installarchlib/CORE", 1, 0777);
157 @corefiles = <*.h libperl*.*>;
158 # AIX needs perl.exp installed as well.
159 push(@corefiles,'perl.exp') if $^O eq 'aix';
160 # If they have built sperl.o...
161 push(@corefiles,'sperl.o') if -f 'sperl.o';
162 foreach $file (@corefiles) {
163 cp_if_diff($file,"$installarchlib/CORE/$file");
164 &chmod($file =~ /^libperl/ ? 0555 : 0444,"$installarchlib/CORE/$file");
167 # Offer to install perl in a "standard" location
169 $mainperl_is_instperl = 0;
171 if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) {
172 local($usrbinperl) = "$mainperldir/perl$exe_ext";
173 local($instperl) = "$installbin/perl$exe_ext";
174 local($expinstperl) = "$binexp/perl$exe_ext";
176 # First make sure $usrbinperl is not already the same as the perl we
178 if (-x $usrbinperl) {
179 # Try to be clever about mainperl being a symbolic link
180 # to binexp/perl if binexp and installbin are different.
181 $mainperl_is_instperl =
182 &samepath($usrbinperl, $instperl) ||
183 (($binexp ne $installbin) &&
185 ((readlink $usrbinperl) eq $expinstperl));
187 if ((! $mainperl_is_instperl) &&
188 (&yn("Many scripts expect perl to be installed as $usrbinperl.\n" .
189 "Do you wish to have $usrbinperl be the same as\n" .
190 "$expinstperl? [y] ")))
193 eval { CORE::link $instperl, $usrbinperl } ||
194 eval { symlink $expinstperl, $usrbinperl } ||
195 cmd("cp $instperl $usrbinperl");
196 $mainperl_is_instperl = 1;
200 # Check to make sure there aren't other perls around in installer's
201 # path. This is probably UNIX-specific. Check all absolute directories
202 # in the path except for where public executables are supposed to live.
203 # Also skip $mainperl if the user opted to have it be a link to the
206 $dirsep = ($^O eq 'os2') ? ';' : ':' ;
207 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
208 @path = split(/$dirsep/, $path);
212 next if ($_ eq $binexp);
213 # Use &samepath here because some systems have other dirs linked
214 # to $mainperldir (like SunOS)
215 next if ($mainperl_is_instperl && &samepath($_, $mainperldir));
216 push(@otherperls, "$_/perl$exe_ext")
217 if (-x "$_/perl$exe_ext" && ! -d "$_/perl$exe_ext");
220 print STDERR "\nWarning: perl appears in your path in the following " .
221 "locations beyond where\nwe just installed it:\n";
223 print STDERR " ", $_, "\n";
228 print STDERR " Installation complete\n";
232 ###############################################################################
237 local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
238 print STDERR $prompt;
239 chop($answer = <STDIN>);
240 $answer = $default if $answer =~ m/^\s*$/;
241 ($answer =~ m/^[yY]/);
248 foreach $name (@names) {
249 next unless -e $name;
250 chmod 0777, $name if $^O eq 'os2';
251 print STDERR " unlink $name\n";
252 ( CORE::unlink($name) and ++$cnt
253 or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
261 foreach $name (@names) {
262 next unless -e $name;
264 chmod 0777, $name if $^O eq 'os2';
265 print STDERR " unlink $name\n";
266 next if CORE::unlink($name);
267 warn "Couldn't unlink $name: $!\n";
269 print STDERR " mv $name $name.old\n";
270 &rename($name, "$name.old") || warn "Couldn't rename $name: $!\n";
277 print STDERR " $cmd\n";
280 warn "Command failed!!!\n" if $?;
285 local($from,$to) = @_;
286 if (-f $to and not unlink($to)) {
288 for ($i = 1; $i < 50; $i++) {
289 last if CORE::rename($to, "$to.$i");
291 warn("Cannot rename to `$to.$i': $!"), return 0
292 if $i >= 50; # Give up!
294 link($from,$to) || return 0;
302 print STDERR " ln $from $to\n";
304 CORE::link($from,$to) ? $success++ : warn "Couldn't link $from to $to: $!\n" unless $nonono;
307 system( $cp, $from, $to )==0 ? $success++ :
308 warn "Couldn't copy $from to $to: $!\n" unless $nonono;
314 local($mode,$name) = @_;
316 printf STDERR " chmod %o %s\n", $mode, $name;
317 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
322 local($p1, $p2) = @_;
323 local($dev1, $ino1, $dev2, $ino2);
326 ($dev1, $ino1) = stat($p1);
327 ($dev2, $ino2) = stat($p2);
328 ($dev1 == $dev2 && $ino1 == $ino2);
336 my $dir = $File::Find::dir;
337 $dir =~ s#^\.(?![^/])/?##;
338 local($depth) = $dir ? "lib/$dir" : "lib";
342 # ignore patch backups and the .exists files.
343 return if $name =~ m{\.orig$|~$|^\.exists};
345 $name = "$dir/$name" if $dir ne '';
347 my $installlib = $installprivlib;
348 if ($dir =~ /^auto/ || $name =~ /^(Config|FileHandle|Safe)\.pm$/) {
349 $installlib = $installarchlib;
350 return unless $do_installarchlib;
352 return unless $do_installprivlib;
356 if (/\.al$/ || /\.ix$/) {
357 $installlib = $installprivlib;
358 #We're installing *.al and *.ix files into $installprivlib,
359 #but we have to delete old *.al and *.ix files from the 5.000
361 #This might not work because $archname might have changed.
362 &unlink("$installarchlib/$name");
364 if (compare($_, "$installlib/$name") || $nonono) {
365 &unlink("$installlib/$name");
366 mkpath("$installlib/$dir", 1, 0777);
367 cp_if_diff($_, "$installlib/$name");
368 # HP-UX (at least) needs to maintain execute permissions
369 # on dynamically-loaded libraries.
370 if ($name =~ /\.(so|$dlext)$/o) {
371 &chmod(0555, "$installlib/$name");
374 &chmod(0444, "$installlib/$name");
378 mkpath("$installlib/$name", 1, 0777);
382 # Copy $from to $to, only if $from is different than $to.
383 # Also preserve modification times for .a libraries.
384 # On some systems, if you do
386 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
387 # and then try to link against the installed libperl.a, you might
388 # get an error message to the effect that the symbol table is older
392 -f $from || die "$0: $from not found";
393 if (compare($from, $to) || $nonono) {
395 unlink($to); # In case we don't have write permissions.
397 $from = $depth . "/" . $from if $depth;
400 # Restore timestamps if it's a .a library.
401 if ($to =~ /\.a$/ or $^O eq 'os2') { # For binary install
402 ($atime, $mtime) = (stat $from)[8,9];
403 utime $atime, $mtime, $to;