This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Okay, here's your official unofficial closure leak patch
[perl5.git] / installperl
CommitLineData
c623bd54 1#!./perl
a0d0e21e 2BEGIN { @INC=('./lib', '../lib') }
a0d0e21e 3use File::Find;
c623bd54 4
bee1dbe2
LW
5$mainperldir = "/usr/bin";
6
c623bd54
LW
7while (@ARGV) {
8 $nonono = 1 if $ARGV[0] eq '-n';
9 $versiononly = 1 if $ARGV[0] eq '-v';
10 shift;
11}
12
45d8adaa
LW
13umask 022;
14
40000a8c 15@scripts = ('cppstdin', 'c2ph', 'h2xs', 'pstruct', 'x2p/s2p', 'x2p/find2perl');
a0d0e21e 16@manpages = (<pod/*.man>, 'x2p/a2p.man', 'x2p/s2p.man');
c623bd54
LW
17
18# Read in the config file.
19
20open(CONFIG, "config.sh") || die "You haven't run Configure yet!\n";
21while (<CONFIG>) {
22 if (s/^(\w+=)/\$$1/) {
23 $accum =~ s/'undef'/undef/g;
24 eval $accum;
25 $accum = '';
26 }
27 $accum .= $_;
28}
bee1dbe2
LW
29close CONFIG;
30
748a9306 31$ver = $];
bee1dbe2
LW
32$release = substr($ver,0,3);
33$patchlevel = substr($ver,3,2);
748a9306
LW
34die "Patchlevel of perl ($patchlevel)",
35 "and patchlevel of config.sh ($PATCHLEVEL) don't match\n"
36 if $patchlevel != $PATCHLEVEL;
c623bd54
LW
37
38# Do some quick sanity checks.
39
40if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
41
fe14fcc3
LW
42 $installbin || die "No installbin directory in config.sh\n";
43-d $installbin || die "$installbin is not a directory\n";
44-w $installbin || die "$installbin is not writable by you\n"
3edbfbe5 45 unless $installbin =~ m#^/afs/# || $nonono;
c623bd54 46
fe14fcc3 47-x 'perl' || die "perl isn't executable!\n";
fe14fcc3 48-x 'suidperl' || die "suidperl isn't executable!\n" if $d_dosuid;
c623bd54 49
fe14fcc3
LW
50-x 't/TEST' || warn "WARNING: You've never run 'make test'!!!",
51 " (Installing anyway.)\n";
c623bd54 52
ecfc5424
AD
53if ($d_shrplib) {
54 if (!<libperl*.$so*>) {
55 warn "WARNING: Can't find libperl*.$so* to install into $shrpdir.",
56 " (Installing other things anyway.)\n";
57 } else {
58 &makedir($shrpdir);
59 -w $shrpdir || die "$shrpdir is not writable by you\n";
60 &cmd("cp libperl*.$so* $shrpdir");
61 }
62}
63
c623bd54
LW
64# First we install the version-numbered executables.
65
fe14fcc3
LW
66&unlink("$installbin/perl$ver");
67&cmd("cp perl $installbin/perl$ver");
c623bd54 68
fe14fcc3 69&unlink("$installbin/sperl$ver");
c623bd54 70if ($d_dosuid) {
fe14fcc3
LW
71 &cmd("cp suidperl $installbin/sperl$ver");
72 &chmod(04711, "$installbin/sperl$ver");
c623bd54
LW
73}
74
75exit 0 if $versiononly;
76
fe14fcc3 77# Make links to ordinary names if installbin directory isn't current directory.
c623bd54 78
ecfc5424 79if (! &samepath($installbin, '.')) {
85e6fe83 80 &unlink("$installbin/perl", "$installbin/suidperl");
fe14fcc3 81 &link("$installbin/perl$ver", "$installbin/perl");
fe14fcc3 82 &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
c623bd54
LW
83}
84
ecfc5424 85if (! &samepath($installbin, 'x2p')) {
352d5a3a
LW
86 &unlink("$installbin/a2p");
87 &cmd("cp x2p/a2p $installbin/a2p");
bee1dbe2 88 &chmod(0755, "$installbin/a2p");
352d5a3a
LW
89}
90
c623bd54
LW
91# Install scripts.
92
a0d0e21e 93&makedir($installscript);
c623bd54
LW
94
95for (@scripts) {
a0d0e21e
LW
96 if (-f $_) { # cppstdin might not exist on this system.
97 &cmd("cp $_ $installscript");
98 s#.*/##; &chmod(0755, "$installscript/$_");
99 }
c623bd54
LW
100}
101
c623bd54
LW
102# Install man pages.
103
a0d0e21e
LW
104if ($installmansrc ne '') {
105 &makedir($installmansrc);
fe14fcc3 106
ecfc5424 107 if (! &samepath($installmansrc, '.')) {
fe14fcc3
LW
108 for (@manpages) {
109 ($new = $_) =~ s/man$/$manext/;
352d5a3a 110 $new =~ s#.*/##;
a0d0e21e 111 print STDERR " Installing $installmansrc/$new\n";
fe14fcc3 112 next if $nonono;
bee1dbe2 113 open(MI,$_) || warn "Can't open $_: $!\n";
a0d0e21e 114 open(MO,">$installmansrc/$new") || warn "Can't install $installmansrc/$new: $!\n";
fe14fcc3
LW
115 print MO ".ds RP Release $release Patchlevel $patchlevel\n";
116 while (<MI>) {
117 print MO;
118 }
119 close MI;
120 close MO;
121 }
c623bd54
LW
122 }
123}
124
45d8adaa
LW
125# Install library files.
126
a0d0e21e
LW
127$do_installarchlib = $do_installprivlib = 0;
128
45d8adaa 129&makedir($installprivlib);
a0d0e21e 130&makedir($installarchlib);
45d8adaa 131if (chdir "lib") {
ecfc5424
AD
132 $do_installarchlib = ! &samepath($installarchlib, '.');
133 $do_installprivlib = ! &samepath($installprivlib, '.');
45d8adaa 134
a0d0e21e
LW
135 if ($do_installarchlib || $do_installprivlib) {
136 find(\&installlib, '.');
45d8adaa
LW
137 }
138 chdir ".." || die "Can't cd back to source directory: $!\n";
139}
140else {
141 warn "Can't cd to lib to install lib files: $!\n";
142}
143
1aef975c 144# Install header files and libraries.
3edbfbe5 145makedir("$installarchlib/CORE");
75f92628 146foreach $file (<*.h libperl*.*>) {
3edbfbe5 147 cp_if_diff($file,"$installarchlib/CORE/$file");
1aef975c 148 if ($file =~ /\.a$/ && $osname eq 'next') {
75f92628 149 #on NeXTs we have to rerun ranlib after copying libraries
1aef975c 150 &cmd("$ranlib $installarchlib/CORE/$file");
75f92628 151 }
3edbfbe5 152}
1aef975c
AD
153# AIX needs perl.exp installed as well.
154cp_if_diff("perl.exp" ,"$installarchlib/CORE/perl.exp") if ($osname eq 'aix');
155
fed7345c
AD
156# If they have built sperl.o...
157cp_if_diff("sperl.o" ,"$installarchlib/CORE/sperl.o") if (-f 'sperl.o');
158
3edbfbe5 159
a0d0e21e
LW
160# Offer to install perl in a "standard" location
161
a0d0e21e
LW
162$mainperl_is_instperl = 0;
163
ecfc5424 164if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) {
a0d0e21e
LW
165 # First make sure $mainperldir/perl is not already the same as
166 # the perl we just installed
167 if (-x "$mainperldir/perl") {
a0d0e21e
LW
168 # Try to be clever about mainperl being a symbolic link
169 # to binexp/perl if binexp and installbin are different.
170 $mainperl_is_instperl =
ecfc5424 171 &samepath("$mainperldir/perl", "$installbin/perl") ||
a0d0e21e
LW
172 (($binexp ne $installbin) &&
173 (-l "$mainperldir/perl") &&
ecfc5424 174 ((readlink "$mainperldir/perl") eq "$binexp/perl"));
a0d0e21e
LW
175 }
176 if ((! $mainperl_is_instperl) &&
177 (&yn("Many scripts expect perl to be installed as " .
178 "$mainperldir/perl.\n" .
179 "Do you wish to have $mainperldir/perl be the same as\n" .
180 "$binexp/perl? [y] ")))
181 {
182 unlink("$mainperldir/perl");
183 eval 'link("$installbin/perl", "$mainperldir/perl")' ||
184 eval 'symlink("$binexp/perl", "$mainperldir/perl")' ||
185 &cmd("cp $installbin/perl $mainperldir");
186 $mainperl_is_instperl = 1;
187 }
188}
189
190# Check to make sure there aren't other perls around in installer's
191# path. This is probably UNIX-specific. Check all absolute directories
192# in the path except for where public executables are supposed to live.
193# Also skip $mainperl if the user opted to have it be a link to the
194# installed perl.
195
196@path = split(/:/, $ENV{"PATH"});
197@otherperls = ();
198for (@path) {
199 next unless m,^/,;
200 next if ($_ eq $binexp);
201 # Use &samepath here because some systems have other dirs linked
202 # to $mainperldir (like SunOS)
203 next if ($mainperl_is_instperl && &samepath($_, $mainperldir));
204 push(@otherperls, "$_/perl") if (-x "$_/perl" && ! -d "$_/perl");
205}
206if (@otherperls) {
207 print STDERR "\nWarning: perl appears in your path in the following " .
208 "locations beyond where\nwe just installed it:\n";
209 for (@otherperls) {
210 print STDERR " ", $_, "\n";
211 }
212 print STDERR "\n";
213}
214
c623bd54
LW
215print STDERR " Installation complete\n";
216
217exit 0;
218
219###############################################################################
220
a0d0e21e
LW
221sub yn {
222 local($prompt) = @_;
223 local($answer);
224 local($default) = $prompt =~ m/\[([yn])\]\s*$/i;
225 print STDERR $prompt;
226 chop($answer = <STDIN>);
227 $answer = $default if $answer =~ m/^\s*$/;
228 ($answer =~ m/^[yY]/);
229}
230
c623bd54
LW
231sub unlink {
232 local(@names) = @_;
233
234 foreach $name (@names) {
235 next unless -e $name;
236 print STDERR " unlink $name\n";
237 unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
238 }
239}
240
241sub cmd {
242 local($cmd) = @_;
243 print STDERR " $cmd\n";
244 unless ($nonono) {
245 system $cmd;
246 warn "Command failed!!!\n" if $?;
247 }
248}
249
250sub link {
251 local($from,$to) = @_;
252
253 print STDERR " ln $from $to\n";
254 link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
255}
256
257sub chmod {
258 local($mode,$name) = @_;
259
260 printf STDERR " chmod %o %s\n", $mode, $name;
514dae0d 261 chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
c623bd54
LW
262 unless $nonono;
263}
264
265sub makedir {
266 local($dir) = @_;
267 unless (-d $dir) {
268 local($shortdir) = $dir;
269
270 $shortdir =~ s#(.*)/.*#$1#;
271 &makedir($shortdir);
272
273 print STDERR " mkdir $dir\n";
274 mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono;
275 }
276}
a0d0e21e
LW
277
278sub samepath {
279 local($p1, $p2) = @_;
280 local($dev1, $ino1, $dev2, $ino2);
281
75f92628 282 if ($p1 ne $p2) {
a0d0e21e
LW
283 ($dev1, $ino1) = stat($p1);
284 ($dev2, $ino2) = stat($p2);
285 ($dev1 == $dev2 && $ino1 == $ino2);
286 }
287 else {
288 1;
289 }
290}
291
292sub installlib {
293 my $dir = $File::Find::dir;
294 $dir =~ s#^\.(?![^/])/?##;
295
296 my $name = $_;
297 $name = "$dir/$name" if $dir ne '';
298
299 my $installlib = $installprivlib;
300 if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) {
301 $installlib = $installarchlib;
302 return unless $do_installarchlib;
303 } else {
304 return unless $do_installprivlib;
305 }
306
a0d0e21e 307 if (-f $_) {
3edbfbe5
TB
308 if (/\.al$/ || /\.ix$/) {
309 $installlib = $installprivlib;
310 #We're installing *.al and *.ix files into $installprivlib,
311 #but we have to delete old *.al and *.ix files from the 5.000
312 #distribution:
75f92628 313 #This might not work because $archname might have changed.
3edbfbe5
TB
314 &unlink("$installarchlib/$name");
315 }
a0d0e21e
LW
316 system "cmp", "-s", $_, "$installlib/$name";
317 if ($?) {
318 &unlink("$installlib/$name");
3edbfbe5 319 &makedir("$installlib/$dir");
a0d0e21e 320 &cmd("cp $_ $installlib/$dir");
1aef975c 321 if (/\.a$/ && $osname eq 'next') {
75f92628 322 #on NeXTs we have to rerun ranlib after copying libraries
1aef975c 323 &cmd("$ranlib $installlib/$dir/$_");
75f92628
AD
324 }
325 # HP-UX (at least) needs to maintain execute permissions
326 # on dynamically-loaded libraries.
748a9306
LW
327 if ($name =~ /\.(so|$dlext)$/o) {
328 &chmod(0555, "$installlib/$name");
329 }
330 else {
331 &chmod(0444, "$installlib/$name");
332 }
a0d0e21e
LW
333 }
334 } elsif (-d $_) {
335 &makedir("$installlib/$name");
336 }
337}
3edbfbe5
TB
338
339sub cp_if_diff {
340 my($from,$to)=@_;
341 -f $from || die "$0: $from not found";
342 system "cmp", "-s", $from, $to;
343 if ($?) {
344 cmd("cp $from $to");
345 }
346}