2 BEGIN { @INC=('./lib', '../lib') }
6 use subs qw(unlink rename link chmod);
8 # override the ones in the rest of the script
11 File::Path::mkpath(@_) unless $nonono;
14 $mainperldir = "/usr/bin";
15 $exe_ext = $Config{exe_ext};
18 $nonono = 1 if $ARGV[0] eq '-n';
19 $versiononly = 1 if $ARGV[0] eq '-v';
25 @scripts = qw( utils/c2ph utils/h2ph utils/h2xs
26 utils/perlbug utils/perldoc utils/pl2pm
28 pod/pod2man pod/pod2html pod/pod2latex pod/pod2text);
30 @pods = (<pod/*.pod>);
33 $release = substr($ver,0,3); # Not used presently.
34 $patchlevel = substr($ver,3,2);
35 die "Patchlevel of perl ($patchlevel)",
36 "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
37 if $patchlevel != $Config{'PATCHLEVEL'};
39 # Fetch some frequently-used items from %Config
40 $installbin = $Config{installbin};
41 $installscript = $Config{installscript};
42 $installprivlib = $Config{installprivlib};
43 $installarchlib = $Config{installarchlib};
44 $installsitelib = $Config{installsitelib};
45 $installsitearch = $Config{installsitearch};
46 $installman1dir = $Config{installman1dir};
47 $man1ext = $Config{man1ext};
48 $libperl = $Config{libperl};
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 || $nonono || die "$installbin is not a directory\n";
63 -w $installbin || $nonono || 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";
72 # First we install the version-numbered executables.
74 &safe_unlink("$installbin/perl$ver$exe_ext");
75 &cmd("cp perl$exe_ext $installbin/perl$ver$exe_ext");
77 &safe_unlink("$installbin/sperl$ver$exe_ext");
79 &cmd("cp suidperl$exe_ext $installbin/sperl$ver$exe_ext");
80 &chmod(04711, "$installbin/sperl$ver$exe_ext");
83 exit 0 if $versiononly;
85 # Make links to ordinary names if installbin directory isn't current directory.
87 if (! &samepath($installbin, '.')) {
88 &safe_unlink("$installbin/perl$exe_ext", "$installbin/suidperl$exe_ext");
89 &link("$installbin/perl$ver$exe_ext", "$installbin/perl$exe_ext");
90 &link("$installbin/sperl$ver$exe_ext", "$installbin/suidperl$exe_ext")
94 if (! &samepath($installbin, 'x2p')) {
95 &safe_unlink("$installbin/a2p$exe_ext");
96 &cmd("cp x2p/a2p$exe_ext $installbin/a2p$exe_ext");
97 &chmod(0755, "$installbin/a2p$exe_ext");
100 # cppstdin is just a script, but it is architecture-dependent, so
101 # it can't safely be shared. Place it in $installbin.
102 # Note that Configure doesn't build cppstin if it isn't needed, so
103 # we skip this if cppstdin doesn't exist.
104 if ((-f cppstdin) && (! &samepath($installbin, '.'))) {
105 &safe_unlink("$installbin/cppstdin");
106 &cmd("cp cppstdin $installbin/cppstdin");
107 &chmod(0755, "$installbin/cppstdin");
112 mkpath($installscript, 1, 0777);
115 &cmd("cp $_ $installscript");
116 s#.*/##; &chmod(0755, "$installscript/$_");
119 # pstruct should be a link to c2ph
121 &safe_unlink("$installscript/pstruct");
122 &link("$installscript/c2ph","$installscript/pstruct");
124 # Install pod pages. Where? I guess in $installprivlib/pod.
125 mkpath("${installprivlib}/pod", 1, 0777);
126 foreach $file (@pods) {
127 # $file is a name like pod/perl.pod
128 cp_if_diff($file, "${installprivlib}/${file}");
131 # Install library files.
133 $do_installarchlib = $do_installprivlib = 0;
135 mkpath($installprivlib, 1, 0777);
136 mkpath($installarchlib, 1, 0777);
137 mkpath($installsitelib, 1, 0777) if ($installsitelib);
138 mkpath($installsitearch, 1, 0777) if ($installsitearch);
141 $do_installarchlib = ! &samepath($installarchlib, '.');
142 $do_installprivlib = ! &samepath($installprivlib, '.');
144 if ($do_installarchlib || $do_installprivlib) {
145 find(\&installlib, '.');
147 chdir ".." || die "Can't cd back to source directory: $!\n";
150 warn "Can't cd to lib to install lib files: $!\n";
153 # Install header files and libraries.
154 mkpath("$installarchlib/CORE", 1, 0777);
155 @corefiles = <*.h libperl*.*>;
156 # AIX needs perl.exp installed as well.
157 push(@corefiles,'perl.exp') if $^O eq 'aix';
158 # If they have built sperl.o...
159 push(@corefiles,'sperl.o') if -f 'sperl.o';
160 foreach $file (@corefiles) {
161 cp_if_diff($file,"$installarchlib/CORE/$file");
162 &chmod($file =~ /^libperl/ ? 0555 : 0444,"$installarchlib/CORE/$file");
165 # Offer to install perl in a "standard" location
167 $mainperl_is_instperl = 0;
169 if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) {
170 # First make sure $mainperldir/perl is not already the same as
171 # the perl we just installed
172 if (-x "$mainperldir/perl$exe_ext") {
173 # Try to be clever about mainperl being a symbolic link
174 # to binexp/perl if binexp and installbin are different.
175 $mainperl_is_instperl =
176 &samepath("$mainperldir/perl$exe_ext", "$installbin/perl$exe_ext") ||
177 (($binexp ne $installbin) &&
178 (-l "$mainperldir/perl$exe_ext") &&
179 ((readlink "$mainperldir/perl$exe_ext") eq "$binexp/perl$exe_ext"));
181 if ((! $mainperl_is_instperl) &&
182 (&yn("Many scripts expect perl to be installed as " .
183 "$mainperldir/perl.\n" .
184 "Do you wish to have $mainperldir/perl be the same as\n" .
185 "$binexp/perl? [y] ")))
187 unlink("$mainperldir/perl$exe_ext");
188 CORE::link("$installbin/perl$exe_ext", "$mainperldir/perl$exe_ext") ||
189 symlink("$binexp/perl$exe_ext", "$mainperldir/perl$exe_ext") ||
190 cmd("cp $installbin/perl$exe_ext $mainperldir$exe_ext");
191 $mainperl_is_instperl = 1;
195 # Check to make sure there aren't other perls around in installer's
196 # path. This is probably UNIX-specific. Check all absolute directories
197 # in the path except for where public executables are supposed to live.
198 # Also skip $mainperl if the user opted to have it be a link to the
201 $dirsep = ($^O eq 'os2') ? ';' : ':' ;
202 ($path = $ENV{"PATH"}) =~ s:\\:/:g ;
203 @path = split(/$dirsep/, $path);
207 next if ($_ eq $binexp);
208 # Use &samepath here because some systems have other dirs linked
209 # to $mainperldir (like SunOS)
210 next if ($mainperl_is_instperl && &samepath($_, $mainperldir));
211 push(@otherperls, "$_/perl$exe_ext")
212 if (-x "$_/perl$exe_ext" && ! -d "$_/perl$exe_ext");
215 print STDERR "\nWarning: perl appears in your path in the following " .
216 "locations beyond where\nwe just installed it:\n";
218 print STDERR " ", $_, "\n";
223 print STDERR " Installation complete\n";
227 ###############################################################################
232 local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
233 print STDERR $prompt;
234 chop($answer = <STDIN>);
235 $answer = $default if $answer =~ m/^\s*$/;
236 ($answer =~ m/^[yY]/);
243 foreach $name (@names) {
244 next unless -e $name;
245 chmod 0777, $name if $^O eq 'os2';
246 print STDERR " unlink $name\n";
247 ( CORE::unlink($name) and ++$cnt
248 or warn "Couldn't unlink $name: $!\n" ) unless $nonono;
256 foreach $name (@names) {
257 next unless -e $name;
259 chmod 0777, $name if $^O eq 'os2';
260 print STDERR " unlink $name\n";
261 next if CORE::unlink($name);
262 warn "Couldn't unlink $name: $!\n";
264 print STDERR " mv $name $name.old\n";
265 &rename($name, "$name.old") || warn "Couldn't rename $name: $!\n";
272 print STDERR " $cmd\n";
275 warn "Command failed!!!\n" if $?;
280 local($from,$to) = @_;
281 if (-f $to and not unlink($to)) {
283 for ($i = 1; $i < 50; $i++) {
284 last if CORE::rename($to, "$to.$i");
286 warn("Cannot rename to `$to.$i': $!"), return 0
287 if $i >= 50; # Give up!
289 link($from,$to) || return 0;
297 print STDERR " ln $from $to\n";
299 CORE::link($from,$to) ? $success++ : warn "Couldn't link $from to $to: $!\n" unless $nonono;
302 system( $cp, $from, $to )==0 ? $success++ :
303 warn "Couldn't copy $from to $to: $!\n" unless $nonono;
309 local($mode,$name) = @_;
311 printf STDERR " chmod %o %s\n", $mode, $name;
312 CORE::chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
317 local($p1, $p2) = @_;
318 local($dev1, $ino1, $dev2, $ino2);
321 ($dev1, $ino1) = stat($p1);
322 ($dev2, $ino2) = stat($p2);
323 ($dev1 == $dev2 && $ino1 == $ino2);
331 my $dir = $File::Find::dir;
332 $dir =~ s#^\.(?![^/])/?##;
333 local($depth) = $dir ? "lib/$dir" : "lib";
337 # ignore patch backups and the .exists files.
338 return if $name =~ m{\.orig$|~$|^\.exists};
340 $name = "$dir/$name" if $dir ne '';
342 my $installlib = $installprivlib;
343 if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) {
344 $installlib = $installarchlib;
345 return unless $do_installarchlib;
347 return unless $do_installprivlib;
351 if (/\.al$/ || /\.ix$/) {
352 $installlib = $installprivlib;
353 #We're installing *.al and *.ix files into $installprivlib,
354 #but we have to delete old *.al and *.ix files from the 5.000
356 #This might not work because $archname might have changed.
357 &unlink("$installarchlib/$name");
359 system "cmp", "-s", $_, "$installlib/$name";
361 &unlink("$installlib/$name");
362 mkpath("$installlib/$dir", 1, 0777);
363 cp_if_diff($_, "$installlib/$name");
364 # HP-UX (at least) needs to maintain execute permissions
365 # on dynamically-loaded libraries.
366 if ($name =~ /\.(so|$dlext)$/o) {
367 &chmod(0555, "$installlib/$name");
370 &chmod(0444, "$installlib/$name");
374 mkpath("$installlib/$name", 1, 0777);
378 # Copy $from to $to, only if $from is different than $to.
379 # Also preserve modification times for .a libraries.
380 # On some systems, if you do
382 # cp libperl.a /usr/local/lib/perl5/archlib/CORE/libperl.a
383 # and then try to link against the installed libperl.a, you might
384 # get an error message to the effect that the symbol table is older
388 -f $from || die "$0: $from not found";
389 system "cmp", "-s", $from, $to;
392 unlink($to); # In case we don't have write permissions.
394 $from = $depth . "/" . $from if $depth;
397 # Restore timestamps if it's a .a library.
398 if ($to =~ /\.a$/ or $^O eq 'os2') { # For binary install
399 ($atime, $mtime) = (stat $from)[8,9];
400 utime $atime, $mtime, $to;