perl 5.0 alpha 9
[p5sagit/p5-mst-13.2.git] / installperl
1 #!./perl
2
3 $mainperldir = "/usr/bin";
4
5 while (@ARGV) {
6     $nonono = 1 if $ARGV[0] eq '-n';
7     $versiononly = 1 if $ARGV[0] eq '-v';
8     shift;
9 }
10
11 umask 022;
12
13 @scripts = ('cppstdin', 'h2ph', 'c2ph', 'pstruct', 'x2p/s2p', 'x2p/find2perl');
14 @manpages = ('perl.man', 'h2ph.man', 'x2p/a2p.man', 'x2p/s2p.man');
15
16 # Read in the config file.
17
18 open(CONFIG, "config.sh") || die "You haven't run Configure yet!\n";
19 while (<CONFIG>) {
20     if (s/^(\w+=)/\$$1/) {
21         $accum =~ s/'undef'/undef/g;
22         eval $accum;
23         $accum = '';
24     }
25     $accum .= $_;
26 }
27 close CONFIG;
28
29 open(PERL_C, "perl.c");
30 while (<PERL_C>) {
31     last if /Revision:/;
32 }
33 close PERL_C;
34 s/.*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);
40
41 # Do some quick sanity checks.
42
43 if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
44
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/#;
49
50 -x 'perl'               || die "perl isn't executable!\n";
51 -x 'suidperl'           || die "suidperl isn't executable!\n" if $d_dosuid;
52
53 -x 't/TEST'             || warn "WARNING: You've never run 'make test'!!!",
54         "  (Installing anyway.)\n";
55
56 # First we install the version-numbered executables.
57
58 &unlink("$installbin/perl$ver");
59 &cmd("cp perl $installbin/perl$ver");
60
61 &unlink("$installbin/sperl$ver");
62 if ($d_dosuid) {
63     &cmd("cp suidperl $installbin/sperl$ver");
64     &chmod(04711, "$installbin/sperl$ver");
65 }
66
67 exit 0 if $versiononly;
68
69 # Make links to ordinary names if installbin directory isn't current directory.
70
71 ($bdev,$bino) = stat($installbin);
72 ($ddev,$dino) = stat('.');
73
74 if ($bdev != $ddev || $bino != $dino) {
75     &unlink("$installbin/perl", "$installbin/suidperl");
76     &link("$installbin/perl$ver", "$installbin/perl");
77     &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
78 }
79
80 ($bdev,$bino) = stat($installbin);
81 ($ddev,$dino) = stat('x2p');
82
83 if ($bdev != $ddev || $bino != $dino) {
84     &unlink("$installbin/a2p");
85     &cmd("cp x2p/a2p $installbin/a2p");
86     &chmod(0755, "$installbin/a2p");
87 }
88
89 # Make some enemies in the name of standardization.   :-)
90
91 ($udev,$uino) = stat($mainperldir);
92
93 if (-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");
98 }
99
100 # Install scripts.
101
102 &makedir($installscr);
103
104 for (@scripts) {
105     &cmd("cp $_ $installscr");
106     s#.*/##; &chmod(0755, "$installscr/$_");
107 }
108
109 # Install man pages.
110
111 if ($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/;
118             $new =~ s#.*/##;
119             print STDERR "  Installing $mansrc/$new\n";
120             next if $nonono;
121             open(MI,$_) || warn "Can't open $_: $!\n";
122             open(MO,">$mansrc/$new") || warn "Can't install $mansrc/$new: $!\n";
123             print MO ".ds RP Release $release Patchlevel $patchlevel\n";
124             while (<MI>) {
125                 print MO;
126             }
127             close MI;
128             close MO;
129         }
130     }
131 }
132
133 # Install library files.
134
135 &makedir($installprivlib);
136 if (chdir "lib") {
137
138     ($pdev,$pino) = stat($installprivlib);
139     ($ldev,$lino) = stat('.');
140
141     if ($pdev != $ldev || $pino != $lino) {
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.
154         foreach $file (<*.pl>) {
155             system "cmp", "-s", $file, "$privlib/$file";
156             if ($?) {
157                 &unlink("$installprivlib/$file");
158                 &cmd("cp $file $installprivlib");
159                 &chmod(0644, "$installprivlib/$file");
160             }
161         }
162     }
163     chdir ".." || die "Can't cd back to source directory: $!\n";
164 }
165 else {
166     warn "Can't cd to lib to install lib files: $!\n";
167 }
168
169 print STDERR "  Installation complete\n";
170
171 exit 0;
172
173 ###############################################################################
174
175 sub 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
185 sub cmd {
186     local($cmd) = @_;
187     print STDERR "  $cmd\n";
188     unless ($nonono) {
189         system $cmd;
190         warn "Command failed!!!\n" if $?;
191     }
192 }
193
194 sub 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
201 sub chmod {
202     local($mode,$name) = @_;
203
204     printf STDERR "  chmod %o %s\n", $mode, $name;
205     chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
206         unless $nonono;
207 }
208
209 sub 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 }