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