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