This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 4.0 patch 12: patch #11, continued
[perl5.git] / installperl
CommitLineData
c623bd54
LW
1#!./perl
2
3while (@ARGV) {
4 $nonono = 1 if $ARGV[0] eq '-n';
5 $versiononly = 1 if $ARGV[0] eq '-v';
6 shift;
7}
8
352d5a3a
LW
9@scripts = ('h2ph', 'x2p/s2p', 'x2p/find2perl');
10@manpages = ('perl.man', 'h2ph.man', 'x2p/a2p.man', 'x2p/s2p.man');
c623bd54 11
fe14fcc3
LW
12$version = sprintf("%5.3f", $]);
13$release = substr($version,0,3);
14$patchlevel = substr($version,3,2);
15
c623bd54
LW
16# Read in the config file.
17
18open(CONFIG, "config.sh") || die "You haven't run Configure yet!\n";
19while (<CONFIG>) {
20 if (s/^(\w+=)/\$$1/) {
21 $accum =~ s/'undef'/undef/g;
22 eval $accum;
23 $accum = '';
24 }
25 $accum .= $_;
26}
27
28# Do some quick sanity checks.
29
30if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
31
fe14fcc3
LW
32 $installbin || die "No installbin directory in config.sh\n";
33-d $installbin || die "$installbin is not a directory\n";
34-w $installbin || die "$installbin is not writable by you\n"
35 unless $installbin =~ m#^/afs/#;
c623bd54 36
fe14fcc3
LW
37-x 'perl' || die "perl isn't executable!\n";
38-x 'taintperl' || die "taintperl isn't executable!\n";
39-x 'suidperl' || die "suidperl isn't executable!\n" if $d_dosuid;
c623bd54 40
fe14fcc3
LW
41-x 't/TEST' || warn "WARNING: You've never run 'make test'!!!",
42 " (Installing anyway.)\n";
c623bd54
LW
43
44# First we install the version-numbered executables.
45
46$ver = sprintf("%5.3f", $]);
47
fe14fcc3
LW
48&unlink("$installbin/perl$ver");
49&cmd("cp perl $installbin/perl$ver");
c623bd54 50
fe14fcc3
LW
51&unlink("$installbin/tperl$ver");
52&cmd("cp taintperl $installbin/tperl$ver");
53&chmod(0755, "$installbin/tperl$ver"); # force non-suid for security
c623bd54 54
fe14fcc3 55&unlink("$installbin/sperl$ver");
c623bd54 56if ($d_dosuid) {
fe14fcc3
LW
57 &cmd("cp suidperl $installbin/sperl$ver");
58 &chmod(04711, "$installbin/sperl$ver");
c623bd54
LW
59}
60
61exit 0 if $versiononly;
62
fe14fcc3 63# Make links to ordinary names if installbin directory isn't current directory.
c623bd54 64
fe14fcc3 65($bdev,$bino) = stat($installbin);
c623bd54
LW
66($ddev,$dino) = stat('.');
67
68if ($bdev != $ddev || $bino != $dino) {
fe14fcc3
LW
69 &unlink("$installbin/perl", "$installbin/taintperl", "$installbin/suidperl");
70 &link("$installbin/perl$ver", "$installbin/perl");
71 &link("$installbin/tperl$ver", "$installbin/taintperl");
72 &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
c623bd54
LW
73}
74
352d5a3a
LW
75($bdev,$bino) = stat($installbin);
76($ddev,$dino) = stat('x2p');
77
78if ($bdev != $ddev || $bino != $dino) {
79 &unlink("$installbin/a2p");
80 &cmd("cp x2p/a2p $installbin/a2p");
81}
82
c623bd54
LW
83# Make some enemies in the name of standardization. :-)
84
85($udev,$uino) = stat("/usr/bin");
86
fe14fcc3 87if (-w _ && ($udev != $ddev || $uino != $dino) && !$nonono) {
c623bd54 88 unlink "/usr/bin/perl";
fe14fcc3
LW
89 eval 'symlink("$installbin/perl", "/usr/bin/perl")' ||
90 eval 'link("$installbin/perl", "/usr/bin/perl")' ||
91 &cmd("cp $installbin/perl /usr/bin");
c623bd54
LW
92}
93
94# Install scripts.
95
352d5a3a 96&makedir($installscr);
c623bd54
LW
97
98for (@scripts) {
352d5a3a
LW
99 &cmd("cp $_ $installscr");
100 s#.*/##; &chmod(0755, "$installscr/$_");
c623bd54
LW
101}
102
103# Install library files.
104
fe14fcc3 105&makedir($installprivlib);
c623bd54 106
fe14fcc3 107($pdev,$pino) = stat($installprivlib);
c623bd54
LW
108
109if ($pdev != $ddev || $pino != $dino) {
fe14fcc3 110 &cmd("cd lib && cp *.pl $installprivlib");
c623bd54
LW
111}
112
113# Install man pages.
114
fe14fcc3
LW
115if ($mansrc ne '') {
116 &makedir($mansrc);
117
118 ($mdev,$mino) = stat($mansrc);
119 if ($mdev != $ddev || $mino != $dino) {
120 for (@manpages) {
121 ($new = $_) =~ s/man$/$manext/;
352d5a3a 122 $new =~ s#.*/##;
fe14fcc3
LW
123 print STDERR " Installing $mansrc/$new\n";
124 next if $nonono;
125 open(MI,$_);
126 open(MO,">$mansrc/$new");
127 print MO ".ds RP Release $release Patchlevel $patchlevel\n";
128 while (<MI>) {
129 print MO;
130 }
131 close MI;
132 close MO;
133 }
c623bd54
LW
134 }
135}
136
137print STDERR " Installation complete\n";
138
139exit 0;
140
141###############################################################################
142
143sub unlink {
144 local(@names) = @_;
145
146 foreach $name (@names) {
147 next unless -e $name;
148 print STDERR " unlink $name\n";
149 unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
150 }
151}
152
153sub cmd {
154 local($cmd) = @_;
155 print STDERR " $cmd\n";
156 unless ($nonono) {
157 system $cmd;
158 warn "Command failed!!!\n" if $?;
159 }
160}
161
162sub link {
163 local($from,$to) = @_;
164
165 print STDERR " ln $from $to\n";
166 link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
167}
168
169sub chmod {
170 local($mode,$name) = @_;
171
172 printf STDERR " chmod %o %s\n", $mode, $name;
173 chmod($mode,$name) || warn "Couldn't chmod $mode $name: $!\n"
174 unless $nonono;
175}
176
177sub makedir {
178 local($dir) = @_;
179 unless (-d $dir) {
180 local($shortdir) = $dir;
181
182 $shortdir =~ s#(.*)/.*#$1#;
183 &makedir($shortdir);
184
185 print STDERR " mkdir $dir\n";
186 mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono;
187 }
188}