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