This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.0 alpha 9
[perl5.git] / installperl
CommitLineData
c623bd54
LW
1#!./perl
2
bee1dbe2
LW
3$mainperldir = "/usr/bin";
4
c623bd54
LW
5while (@ARGV) {
6 $nonono = 1 if $ARGV[0] eq '-n';
7 $versiononly = 1 if $ARGV[0] eq '-v';
8 shift;
9}
10
45d8adaa
LW
11umask 022;
12
13@scripts = ('cppstdin', 'h2ph', 'c2ph', 'pstruct', 'x2p/s2p', 'x2p/find2perl');
352d5a3a 14@manpages = ('perl.man', 'h2ph.man', 'x2p/a2p.man', 'x2p/s2p.man');
c623bd54
LW
15
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}
bee1dbe2
LW
27close CONFIG;
28
29open(PERL_C, "perl.c");
30while (<PERL_C>) {
31 last if /Revision:/;
32}
33close PERL_C;
34s/.*Revision: //;
35$major = $_ + 0;
36
37$ver = sprintf("%5.3f", $major + $PATCHLEVEL / 1000);
38$release = substr($ver,0,3);
39$patchlevel = substr($ver,3,2);
c623bd54
LW
40
41# Do some quick sanity checks.
42
43if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
44
fe14fcc3
LW
45 $installbin || die "No installbin directory in config.sh\n";
46-d $installbin || die "$installbin is not a directory\n";
47-w $installbin || die "$installbin is not writable by you\n"
48 unless $installbin =~ m#^/afs/#;
c623bd54 49
fe14fcc3 50-x 'perl' || die "perl isn't executable!\n";
fe14fcc3 51-x 'suidperl' || die "suidperl isn't executable!\n" if $d_dosuid;
c623bd54 52
fe14fcc3
LW
53-x 't/TEST' || warn "WARNING: You've never run 'make test'!!!",
54 " (Installing anyway.)\n";
c623bd54
LW
55
56# First we install the version-numbered executables.
57
fe14fcc3
LW
58&unlink("$installbin/perl$ver");
59&cmd("cp perl $installbin/perl$ver");
c623bd54 60
fe14fcc3 61&unlink("$installbin/sperl$ver");
c623bd54 62if ($d_dosuid) {
fe14fcc3
LW
63 &cmd("cp suidperl $installbin/sperl$ver");
64 &chmod(04711, "$installbin/sperl$ver");
c623bd54
LW
65}
66
67exit 0 if $versiononly;
68
fe14fcc3 69# Make links to ordinary names if installbin directory isn't current directory.
c623bd54 70
fe14fcc3 71($bdev,$bino) = stat($installbin);
c623bd54
LW
72($ddev,$dino) = stat('.');
73
74if ($bdev != $ddev || $bino != $dino) {
85e6fe83 75 &unlink("$installbin/perl", "$installbin/suidperl");
fe14fcc3 76 &link("$installbin/perl$ver", "$installbin/perl");
fe14fcc3 77 &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
c623bd54
LW
78}
79
352d5a3a
LW
80($bdev,$bino) = stat($installbin);
81($ddev,$dino) = stat('x2p');
82
83if ($bdev != $ddev || $bino != $dino) {
84 &unlink("$installbin/a2p");
85 &cmd("cp x2p/a2p $installbin/a2p");
bee1dbe2 86 &chmod(0755, "$installbin/a2p");
352d5a3a
LW
87}
88
c623bd54
LW
89# Make some enemies in the name of standardization. :-)
90
bee1dbe2 91($udev,$uino) = stat($mainperldir);
c623bd54 92
bee1dbe2
LW
93if (-w _ && ($udev != $bdev || $uino != $bino) && !$nonono) {
94 &unlink("$mainperldir/perl");
95 eval 'link("$installbin/perl", "$mainperldir/perl")' ||
96 eval 'symlink("$installbin/perl", "$mainperldir/perl")' ||
97 &cmd("cp $installbin/perl $mainperldir");
c623bd54
LW
98}
99
100# Install scripts.
101
352d5a3a 102&makedir($installscr);
c623bd54
LW
103
104for (@scripts) {
352d5a3a
LW
105 &cmd("cp $_ $installscr");
106 s#.*/##; &chmod(0755, "$installscr/$_");
c623bd54
LW
107}
108
c623bd54
LW
109# Install man pages.
110
fe14fcc3
LW
111if ($mansrc ne '') {
112 &makedir($mansrc);
113
114 ($mdev,$mino) = stat($mansrc);
115 if ($mdev != $ddev || $mino != $dino) {
116 for (@manpages) {
117 ($new = $_) =~ s/man$/$manext/;
352d5a3a 118 $new =~ s#.*/##;
fe14fcc3
LW
119 print STDERR " Installing $mansrc/$new\n";
120 next if $nonono;
bee1dbe2
LW
121 open(MI,$_) || warn "Can't open $_: $!\n";
122 open(MO,">$mansrc/$new") || warn "Can't install $mansrc/$new: $!\n";
fe14fcc3
LW
123 print MO ".ds RP Release $release Patchlevel $patchlevel\n";
124 while (<MI>) {
125 print MO;
126 }
127 close MI;
128 close MO;
129 }
c623bd54
LW
130 }
131}
132
45d8adaa
LW
133# Install library files.
134
135&makedir($installprivlib);
136if (chdir "lib") {
137
138 ($pdev,$pino) = stat($installprivlib);
139 ($ldev,$lino) = stat('.');
140
141 if ($pdev != $ldev || $pino != $lino) {
85e6fe83
LW
142 # Optimize for quick access. First the auto directory.
143 system "tar cf - auto | (cd $installprivlib; tar xvf -)";
144 # Next the Perl modules.
145 foreach $file (<*.pm>) {
146 system "cmp", "-s", $file, "$privlib/$file";
147 if ($?) {
148 &unlink("$installprivlib/$file");
149 &cmd("cp $file $installprivlib");
150 &chmod(0644, "$installprivlib/$file");
151 }
152 }
153 # Finally the old library files.
45d8adaa 154 foreach $file (<*.pl>) {
988174c1
LW
155 system "cmp", "-s", $file, "$privlib/$file";
156 if ($?) {
157 &unlink("$installprivlib/$file");
158 &cmd("cp $file $installprivlib");
faf8582f 159 &chmod(0644, "$installprivlib/$file");
988174c1 160 }
45d8adaa
LW
161 }
162 }
163 chdir ".." || die "Can't cd back to source directory: $!\n";
164}
165else {
166 warn "Can't cd to lib to install lib files: $!\n";
167}
168
c623bd54
LW
169print STDERR " Installation complete\n";
170
171exit 0;
172
173###############################################################################
174
175sub unlink {
176 local(@names) = @_;
177
178 foreach $name (@names) {
179 next unless -e $name;
180 print STDERR " unlink $name\n";
181 unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
182 }
183}
184
185sub cmd {
186 local($cmd) = @_;
187 print STDERR " $cmd\n";
188 unless ($nonono) {
189 system $cmd;
190 warn "Command failed!!!\n" if $?;
191 }
192}
193
194sub link {
195 local($from,$to) = @_;
196
197 print STDERR " ln $from $to\n";
198 link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
199}
200
201sub chmod {
202 local($mode,$name) = @_;
203
204 printf STDERR " chmod %o %s\n", $mode, $name;
514dae0d 205 chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
c623bd54
LW
206 unless $nonono;
207}
208
209sub makedir {
210 local($dir) = @_;
211 unless (-d $dir) {
212 local($shortdir) = $dir;
213
214 $shortdir =~ s#(.*)/.*#$1#;
215 &makedir($shortdir);
216
217 print STDERR " mkdir $dir\n";
218 mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono;
219 }
220}