read permissions for h2ph-generated files
[p5sagit/p5-mst-13.2.git] / ext / Time / HiRes / Makefile.PL
CommitLineData
3f2ee006 1
dcf686c9 2# See lib/ExtUtils/MakeMaker.pm for details of how to influence
3# the contents of the Makefile that is written.
4#
5
3f2ee006 6require 5.002;
7
8use Config;
dcf686c9 9use ExtUtils::MakeMaker;
10
3f2ee006 11# Perls 5.002 and 5.003 did not have File::Spec, fake what we need.
12
13my $VERBOSE = $ENV{VERBOSE};
14
15sub my_dirsep {
16 $^O eq 'VMS' ? '.' :
17 $^O =~ /mswin32|netware|djgpp/i ? '\\' :
18 $^O eq 'MacOS' ? ':'
19 : '/';
20}
21
22sub my_catdir {
23 shift;
24 my $catdir = join(my_dirsep, @_);
25 $^O eq 'VMS' ? "[$dirsep]" : $dirsep;
26}
27
28sub my_updir {
29 shift;
30 $^O eq 'VMS' ? "-" : "..";
31}
32
33BEGIN {
34 eval { require File::Spec };
35 if ($@) {
36 *File::Spec::catdir = \&my_catdir;
37 *File::Spec::updir = \&my_updir;
38 }
39}
40
41# if you have 5.004_03 (and some slightly older versions?), xsubpp
42# tries to generate line numbers in the C code generated from the .xs.
43# unfortunately, it is a little buggy around #ifdef'd code.
44# my choice is leave it in and have people with old perls complain
45# about the "Usage" bug, or leave it out and be unable to compile myself
46# without changing it, and then I'd always forget to change it before a
47# release. Sorry, Edward :)
48
49sub TMPDIR {
50 my $TMPDIR =
51 (grep(defined $_ && -d $_ && -w _,
52 ((defined $ENV{'TMPDIR'} ? $ENV{'TMPDIR'} : undef),
53 qw(/var/tmp /usr/tmp /tmp))))[0]
54 unless defined $TMPDIR;
55 $TMPDIR || die "Cannot find writable temporary directory.\n";
56}
57
58sub try_compile_and_link {
59 my ($c, %args) = @_;
60
61 my ($ok) = 0;
62 my ($tmp) = (($^O eq 'VMS') ? "sys\$scratch:tmp$$" : TMPDIR . '/' . "tmp$$");
63 local(*TMPC);
64
65 my $obj_ext = $Config{obj_ext} || ".o";
66 unlink("$tmp.c", "$tmp$obj_ext");
67
68 if (open(TMPC, ">$tmp.c")) {
69 print TMPC $c;
70 close(TMPC);
71
72 $cccmd = $args{cccmd};
73
74 my $errornull;
75
76 my $COREincdir;
77 if ($ENV{PERL_CORE}) {
78 my $updir = File::Spec->updir;
79 $COREincdir = File::Spec->catdir(($updir) x 3);
80 } else {
81 $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE');
82 }
83 my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir";
84 if ($^O eq 'VMS') {
85 if ($ENV{PERL_CORE}) {
1f74f634 86 $cccmd = "$Config{'cc'} /include=([---]) $tmp.c";
3f2ee006 87 } else {
88 my $perl_core = $Config{'installarchlib'};
89 $perl_core =~ s/\]$/.CORE]/;
90 $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
91 }
92 }
93
94 if ($args{silent} || !$VERBOSE) {
95 $errornull = "2>/dev/null" unless defined $errornull;
96 } else {
97 $errornull = '';
98 }
99
100 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
101 unless defined $cccmd;
102 if ($^O eq 'VMS') {
103 open( CMDFILE, ">$tmp.com" );
104 print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
105 print CMDFILE "\$ $cccmd\n";
106 print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
107 close CMDFILE;
108 system("\@ $tmp.com");
109 $ok = $?==0;
110 for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
111 1 while unlink $_;
112 }
113 }
114 else
115 {
116 printf "cccmd = $cccmd\n" if $VERBOSE;
117 system($cccmd);
118 $ok = -s $tmp && -x _;
119 unlink("$tmp.c", $tmp);
120 }
121 }
122
123 $ok;
124}
125
126sub has_gettimeofday {
127 # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
128 return 0 if $Config{'d_gettimeod'} eq 'define';
129 return 1 if try_compile_and_link(<<EOM);
130#include "EXTERN.h"
131#include "perl.h"
132#include "XSUB.h"
133#ifdef I_SYS_TYPES
134# include <sys/types.h>
135#endif
136
137#ifdef I_SYS_TIME
138# include <sys/time.h>
139#endif
140
141#ifdef I_SYS_SELECT
142# include <sys/select.h> /* struct timeval might be hidden in here */
143#endif
144static int foo()
145{
146 struct timeval tv;
147 gettimeofday(&tv, 0);
148}
149int main _((int argc, char** argv, char** env))
150{
151 foo();
152}
153EOM
154 return 0;
155}
156
157sub has_x {
158 my ($x, %args) = @_;
159
160 return 1 if
161 try_compile_and_link(<<EOM, %args);
162#include "EXTERN.h"
163#include "perl.h"
164#include "XSUB.h"
165
166#ifdef I_UNISTD
167# include <unistd.h>
168#endif
169
170#ifdef I_SYS_TYPES
171# include <sys/types.h>
172#endif
173
174#ifdef I_SYS_TIME
175# include <sys/time.h>
176#endif
177
178int main _((int argc, char** argv, char** env))
179{
180 $x;
181}
182EOM
183 return 0;
184}
185
186sub unixinit {
187 $DEFINE = '';
188
189 $LIBS = [];
190
191 # this might break the link, try it if it can't find some things you
192 # honestly think should be in there...
193 # $LIBS = ['-lucb -lbsd'];
194
195 # ... but ucb is poison for Solaris, and probably Linux. honest.
196 $LIBS = [] if $Config{'osname'} eq 'solaris';
197 $LIBS = [] if $Config{'osname'} eq 'linux';
198 $LIBS = ['-lm'] if $Config{'osname'} =~ /sco/i;
199 $LIBS = ['-lc'] if $Config{'osname'} =~ /dynixptx/i;
200
201 # For nanosleep
202 push @$LIBS, '-lrt' unless $Config{'osname'} =~ /irix/;
203 push @$LIBS, '-lposix4' ;
204
205 my @goodlibs;
206
207 select(STDOUT); $| = 1;
208
209 print "Checking for libraries...\n";
210 my $lib;
211 for $lib (@$LIBS) {
212 print "Checking for $lib...\n";
213 $LIBS = [ $lib ];
214 if ($Config{libs} =~ /\b$lib\b/ || has_x("time(0)")) {
215 push @goodlibs, $lib;
216 }
217 }
218 @$LIBS = @goodlibs;
219 print @$LIBS ?
220 "You have extra libraries: @$LIBS.\n" :
221 "You have no applicable extra libraries.\n";
222 print "\n";
223
224 print "Looking for gettimeofday()...\n";
225 my $has_gettimeofday;
226 if ($Config{'d_gettimeod'}) {
227 $has_gettimeofday++;
228 } elsif (has_gettimeofday()) {
229 $DEFINE .= ' -DHAS_GETTIMEOFDAY';
230 $has_gettimeofday++;
231 }
232
233 if ($has_gettimeofday) {
234 print "You have gettimeofday().\n\n";
235 } else {
236 die <<EOD
237Your operating system does not seem to have the gettimeofday() function.
238(or, at least, I cannot find it)
239
240There is no way Time::HiRes is going to work.
241
242I am awfully sorry but I cannot go further.
243
244Aborting configuration.
245
246EOD
247 }
248
249 print "Looking for setitimer()...\n";
250 my $has_setitimer;
251 if ($Config{d_setitimer}) {
252 $has_setitimer++;
253 } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
254 $has_setitimer++;
255 $DEFINE .= ' -DHAS_SETITIMER';
256 }
257
258 if ($has_setitimer) {
259 print "You have setitimer().\n\n";
260 } else {
261 print "No setitimer().\n\n";
262 }
263
264 print "Looking for getitimer()...\n";
265 my $has_getitimer;
266 if ($Config{d_getitimer}) {
267 $has_getitimer++;
268 } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
269 $has_getitimer++;
270 $DEFINE .= ' -DHAS_GETITIMER';
271 }
272
273 if ($has_getitimer) {
274 print "You have getitimer().\n\n";
275 } else {
276 print "No getitimer().\n\n";
277 }
278
279 if ($has_setitimer && $has_getitimer) {
280 print "You have interval timers (both setitimer and setitimer).\n\n";
281 } else {
282 print "You do not have interval timers.\n\n";
283 }
284
285 print "Looking for ualarm()...\n";
286 my $has_ualarm;
287 if ($Config{d_ualarm}) {
288 $has_ualarm++;
289 } elsif (has_x ("ualarm (0, 0)")) {
290 $has_ualarm++;
291 $DEFINE .= ' -DHAS_UALARM';
292 }
293
294 if ($has_ualarm) {
295 print "You have ualarm().\n\n";
296 } else {
297 print "Whoops! No ualarm()!\n";
298 if ($setitimer) {
299 print "You have setitimer(); we can make a Time::HiRes::ualarm()\n\n";
300 } else {
301 print "We'll manage.\n\n";
302 }
303 }
304
305 print "Looking for usleep()...\n";
306 my $has_usleep;
307 if ($Config{d_usleep}) {
308 $has_usleep++;
309 } elsif (has_x ("usleep (0)")) {
310 $has_usleep++;
311 $DEFINE .= ' -DHAS_USLEEP';
312 }
313
314 if ($has_usleep) {
315 print "You have usleep().\n\n";
316 } else {
317 print "Whoops! No usleep()! Let's see if you have select().\n";
318 if ($Config{'d_select'} eq 'define') {
319 print "You have select(); we can make a Time::HiRes::usleep()\n\n";
320 } else {
321 print "No select(); you won't have a Time::HiRes::usleep()\n\n";
322 }
323 }
324
325 print "Looking for nanosleep()...\n";
326 my $has_nanosleep;
327 if ($Config{d_nanosleep}) {
328 $has_nanosleep++;
329 } elsif (has_x ("nanosleep (NULL, NULL)")) {
330 $has_nanosleep++;
331 $DEFINE .= ' -DHAS_NANOSLEEP';
332 }
333
334 if ($has_nanosleep) {
335 print "You have nanosleep(). You can mix subsecond sleeps with signals.\n\n";
336 } else {
337 print "Whoops! No nanosleep()! You cannot mix subsecond sleeps with signals.\n";
338 }
339
340 if ($DEFINE) {
341 $DEFINE =~ s/^\s+//;
342 if (open(XDEFINE, ">xdefine")) {
343 print XDEFINE $DEFINE, "\n";
344 close(XDEFINE);
345 }
346 }
347}
348
349sub doMakefile {
350 @makefileopts = ();
351
352 if ($] >= 5.005) {
353 push (@makefileopts,
354 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>',
355 'ABSTRACT_FROM' => 'HiRes.pm',
356 );
357 $DEFINE .= " -DATLEASTFIVEOHOHFIVE";
358 }
359
360 push (@makefileopts,
361 'NAME' => 'Time::HiRes',
362 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
363 'LIBS' => $LIBS, # e.g., '-lm'
364 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
365 'XSOPT' => $XSOPT,
366 # do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge.
367 'INC' => '', # e.g., '-I/usr/include/other'
368 'INSTALLDIRS' => 'perl',
369 'dist' => {
370 'CI' => 'ci -l',
371 'COMPRESS' => 'gzip -9f',
372 'SUFFIX' => 'gz',
373 },
374 clean => { FILES => "xdefine" },
375 );
376
377 WriteMakefile(@makefileopts);
378}
379
380sub main {
381 print <<EOM;
382
383Configuring Time::HiRes...
384
385EOM
386
387 if ($^O =~ /Win32/i) {
388 $DEFINE = '-DSELECT_IS_BROKEN';
389 $LIBS = [''];
390 } else {
391 unixinit();
392 }
393 configure;
394 doMakefile;
395 my $make = $Config{'make'} || "make";
396 unless ($ENV{PERL_CORE}) {
397 print <<EOM;
398
399Done configuring.
400
401Now you may issue '$make'. Do not forget also '$make test'.
402
403EOM
404 }
405}
406
407&main;
dcf686c9 408
3f2ee006 409# EOF