Commit | Line | Data |
---|---|---|
c623bd54 | 1 | #!./perl |
a0d0e21e | 2 | BEGIN { @INC=('./lib', '../lib') } |
75f92628 | 3 | use Config; |
a0d0e21e | 4 | use File::Find; |
c623bd54 | 5 | |
bee1dbe2 LW |
6 | $mainperldir = "/usr/bin"; |
7 | ||
c623bd54 LW |
8 | while (@ARGV) { |
9 | $nonono = 1 if $ARGV[0] eq '-n'; | |
10 | $versiononly = 1 if $ARGV[0] eq '-v'; | |
11 | shift; | |
12 | } | |
13 | ||
45d8adaa LW |
14 | umask 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 | ||
21 | open(CONFIG, "config.sh") || die "You haven't run Configure yet!\n"; | |
22 | while (<CONFIG>) { | |
23 | if (s/^(\w+=)/\$$1/) { | |
24 | $accum =~ s/'undef'/undef/g; | |
25 | eval $accum; | |
26 | $accum = ''; | |
27 | } | |
28 | $accum .= $_; | |
29 | } | |
bee1dbe2 LW |
30 | close 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 | ||
38 | if ($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 |
51 | if ($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 | 68 | if ($d_dosuid) { |
fe14fcc3 LW |
69 | &cmd("cp suidperl $installbin/sperl$ver"); |
70 | &chmod(04711, "$installbin/sperl$ver"); | |
c623bd54 LW |
71 | } |
72 | ||
73 | exit 0 if $versiononly; | |
74 | ||
fe14fcc3 | 75 | # Make links to ordinary names if installbin directory isn't current directory. |
c623bd54 | 76 | |
ecfc5424 | 77 | if (! &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 | 83 | if (! &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 | |
93 | for (@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 |
102 | if ($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 | 129 | if (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 | } | |
138 | else { | |
139 | warn "Can't cd to lib to install lib files: $!\n"; | |
140 | } | |
141 | ||
75f92628 | 142 | # Install header files and libraries |
3edbfbe5 | 143 | makedir("$installarchlib/CORE"); |
75f92628 | 144 | foreach $file (<*.h libperl*.*>) { |
3edbfbe5 | 145 | cp_if_diff($file,"$installarchlib/CORE/$file"); |
75f92628 AD |
146 | if ($file =~ /\.a$/ && $Config{'osname'} eq 'next') { |
147 | #on NeXTs we have to rerun ranlib after copying libraries | |
148 | &cmd("$Config{'ranlib'} $installarchlib/CORE/$file"); | |
149 | } | |
3edbfbe5 TB |
150 | } |
151 | ||
a0d0e21e LW |
152 | # Offer to install perl in a "standard" location |
153 | ||
a0d0e21e LW |
154 | $mainperl_is_instperl = 0; |
155 | ||
ecfc5424 | 156 | if (-w $mainperldir && ! &samepath($mainperldir, $installbin) && !$nonono) { |
a0d0e21e LW |
157 | # First make sure $mainperldir/perl is not already the same as |
158 | # the perl we just installed | |
159 | if (-x "$mainperldir/perl") { | |
a0d0e21e LW |
160 | # Try to be clever about mainperl being a symbolic link |
161 | # to binexp/perl if binexp and installbin are different. | |
162 | $mainperl_is_instperl = | |
ecfc5424 | 163 | &samepath("$mainperldir/perl", "$installbin/perl") || |
a0d0e21e LW |
164 | (($binexp ne $installbin) && |
165 | (-l "$mainperldir/perl") && | |
ecfc5424 | 166 | ((readlink "$mainperldir/perl") eq "$binexp/perl")); |
a0d0e21e LW |
167 | } |
168 | if ((! $mainperl_is_instperl) && | |
169 | (&yn("Many scripts expect perl to be installed as " . | |
170 | "$mainperldir/perl.\n" . | |
171 | "Do you wish to have $mainperldir/perl be the same as\n" . | |
172 | "$binexp/perl? [y] "))) | |
173 | { | |
174 | unlink("$mainperldir/perl"); | |
175 | eval 'link("$installbin/perl", "$mainperldir/perl")' || | |
176 | eval 'symlink("$binexp/perl", "$mainperldir/perl")' || | |
177 | &cmd("cp $installbin/perl $mainperldir"); | |
178 | $mainperl_is_instperl = 1; | |
179 | } | |
180 | } | |
181 | ||
182 | # Check to make sure there aren't other perls around in installer's | |
183 | # path. This is probably UNIX-specific. Check all absolute directories | |
184 | # in the path except for where public executables are supposed to live. | |
185 | # Also skip $mainperl if the user opted to have it be a link to the | |
186 | # installed perl. | |
187 | ||
188 | @path = split(/:/, $ENV{"PATH"}); | |
189 | @otherperls = (); | |
190 | for (@path) { | |
191 | next unless m,^/,; | |
192 | next if ($_ eq $binexp); | |
193 | # Use &samepath here because some systems have other dirs linked | |
194 | # to $mainperldir (like SunOS) | |
195 | next if ($mainperl_is_instperl && &samepath($_, $mainperldir)); | |
196 | push(@otherperls, "$_/perl") if (-x "$_/perl" && ! -d "$_/perl"); | |
197 | } | |
198 | if (@otherperls) { | |
199 | print STDERR "\nWarning: perl appears in your path in the following " . | |
200 | "locations beyond where\nwe just installed it:\n"; | |
201 | for (@otherperls) { | |
202 | print STDERR " ", $_, "\n"; | |
203 | } | |
204 | print STDERR "\n"; | |
205 | } | |
206 | ||
c623bd54 LW |
207 | print STDERR " Installation complete\n"; |
208 | ||
209 | exit 0; | |
210 | ||
211 | ############################################################################### | |
212 | ||
a0d0e21e LW |
213 | sub yn { |
214 | local($prompt) = @_; | |
215 | local($answer); | |
216 | local($default) = $prompt =~ m/\[([yn])\]\s*$/i; | |
217 | print STDERR $prompt; | |
218 | chop($answer = <STDIN>); | |
219 | $answer = $default if $answer =~ m/^\s*$/; | |
220 | ($answer =~ m/^[yY]/); | |
221 | } | |
222 | ||
c623bd54 LW |
223 | sub unlink { |
224 | local(@names) = @_; | |
225 | ||
226 | foreach $name (@names) { | |
227 | next unless -e $name; | |
228 | print STDERR " unlink $name\n"; | |
229 | unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono; | |
230 | } | |
231 | } | |
232 | ||
233 | sub cmd { | |
234 | local($cmd) = @_; | |
235 | print STDERR " $cmd\n"; | |
236 | unless ($nonono) { | |
237 | system $cmd; | |
238 | warn "Command failed!!!\n" if $?; | |
239 | } | |
240 | } | |
241 | ||
242 | sub link { | |
243 | local($from,$to) = @_; | |
244 | ||
245 | print STDERR " ln $from $to\n"; | |
246 | link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono; | |
247 | } | |
248 | ||
249 | sub chmod { | |
250 | local($mode,$name) = @_; | |
251 | ||
252 | printf STDERR " chmod %o %s\n", $mode, $name; | |
514dae0d | 253 | chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name) |
c623bd54 LW |
254 | unless $nonono; |
255 | } | |
256 | ||
257 | sub makedir { | |
258 | local($dir) = @_; | |
259 | unless (-d $dir) { | |
260 | local($shortdir) = $dir; | |
261 | ||
262 | $shortdir =~ s#(.*)/.*#$1#; | |
263 | &makedir($shortdir); | |
264 | ||
265 | print STDERR " mkdir $dir\n"; | |
266 | mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono; | |
267 | } | |
268 | } | |
a0d0e21e LW |
269 | |
270 | sub samepath { | |
271 | local($p1, $p2) = @_; | |
272 | local($dev1, $ino1, $dev2, $ino2); | |
273 | ||
75f92628 | 274 | if ($p1 ne $p2) { |
a0d0e21e LW |
275 | ($dev1, $ino1) = stat($p1); |
276 | ($dev2, $ino2) = stat($p2); | |
277 | ($dev1 == $dev2 && $ino1 == $ino2); | |
278 | } | |
279 | else { | |
280 | 1; | |
281 | } | |
282 | } | |
283 | ||
284 | sub installlib { | |
285 | my $dir = $File::Find::dir; | |
286 | $dir =~ s#^\.(?![^/])/?##; | |
287 | ||
288 | my $name = $_; | |
289 | $name = "$dir/$name" if $dir ne ''; | |
290 | ||
291 | my $installlib = $installprivlib; | |
292 | if ((substr($dir, 0, 4) eq 'auto') || ($name eq 'Config.pm')) { | |
293 | $installlib = $installarchlib; | |
294 | return unless $do_installarchlib; | |
295 | } else { | |
296 | return unless $do_installprivlib; | |
297 | } | |
298 | ||
a0d0e21e | 299 | if (-f $_) { |
3edbfbe5 TB |
300 | if (/\.al$/ || /\.ix$/) { |
301 | $installlib = $installprivlib; | |
302 | #We're installing *.al and *.ix files into $installprivlib, | |
303 | #but we have to delete old *.al and *.ix files from the 5.000 | |
304 | #distribution: | |
75f92628 | 305 | #This might not work because $archname might have changed. |
3edbfbe5 TB |
306 | &unlink("$installarchlib/$name"); |
307 | } | |
a0d0e21e LW |
308 | system "cmp", "-s", $_, "$installlib/$name"; |
309 | if ($?) { | |
310 | &unlink("$installlib/$name"); | |
3edbfbe5 | 311 | &makedir("$installlib/$dir"); |
a0d0e21e | 312 | &cmd("cp $_ $installlib/$dir"); |
75f92628 AD |
313 | if (/\.a$/ && $Config{'osname'} eq 'next') { |
314 | #on NeXTs we have to rerun ranlib after copying libraries | |
315 | &cmd("$Config{'ranlib'} $installlib/$dir/$_"); | |
316 | } | |
317 | # HP-UX (at least) needs to maintain execute permissions | |
318 | # on dynamically-loaded libraries. | |
319 | &chmod(0644, "$installlib/$name") | |
320 | unless (/\.$so$/ || /\.$dlext$/); | |
a0d0e21e LW |
321 | } |
322 | } elsif (-d $_) { | |
323 | &makedir("$installlib/$name"); | |
324 | } | |
325 | } | |
3edbfbe5 TB |
326 | |
327 | sub cp_if_diff { | |
328 | my($from,$to)=@_; | |
329 | -f $from || die "$0: $from not found"; | |
330 | system "cmp", "-s", $from, $to; | |
331 | if ($?) { | |
332 | cmd("cp $from $to"); | |
333 | } | |
334 | } |