Commit | Line | Data |
56c1b3bd |
1 | #!/usr/bin/perl |
2 | # |
3 | # In general we trust %Config, but for nanosleep() this trust |
3d0346a5 |
4 | # may be misplaced (it may be linkable but not really functional). |
56c1b3bd |
5 | # Use $ENV{FORCE_NANOSLEEP_SCAN} to force rescanning whether there |
6 | # really is hope. |
7 | |
3f2ee006 |
8 | require 5.002; |
9 | |
10 | use Config; |
dcf686c9 |
11 | use ExtUtils::MakeMaker; |
98b50af3 |
12 | use strict; |
3f2ee006 |
13 | |
14 | my $VERBOSE = $ENV{VERBOSE}; |
98b50af3 |
15 | my $DEFINE; |
046e3f33 |
16 | my $LIBS = []; |
56c1b3bd |
17 | my $XSOPT = ''; |
ced84e60 |
18 | my $SYSCALL_H; |
98b50af3 |
19 | |
046e3f33 |
20 | use vars qw($self); # Used in 'sourcing' the hints. |
21 | |
4ed0e2d4 |
22 | my $ld_exeext = ($^O eq 'cygwin' || |
23 | $^O eq 'os2' && $Config{ldflags} =~ /-Zexe\b/) ? '.exe' : ''; |
622913ab |
24 | |
12724655 |
25 | unless($ENV{PERL_CORE}) { |
26 | $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV; |
98b50af3 |
27 | } |
28 | |
29 | # Perls 5.002 and 5.003 did not have File::Spec, fake what we need. |
3f2ee006 |
30 | |
31 | sub my_dirsep { |
32 | $^O eq 'VMS' ? '.' : |
33 | $^O =~ /mswin32|netware|djgpp/i ? '\\' : |
34 | $^O eq 'MacOS' ? ':' |
35 | : '/'; |
36 | } |
37 | |
38 | sub my_catdir { |
39 | shift; |
40 | my $catdir = join(my_dirsep, @_); |
98b50af3 |
41 | $^O eq 'VMS' ? "[$catdir]" : $catdir; |
42 | } |
43 | |
44 | sub my_catfile { |
45 | shift; |
46 | return join(my_dirsep, @_) unless $^O eq 'VMS'; |
47 | my $file = pop; |
48 | return my_catdir (undef, @_) . $file; |
3f2ee006 |
49 | } |
50 | |
51 | sub my_updir { |
52 | shift; |
53 | $^O eq 'VMS' ? "-" : ".."; |
54 | } |
55 | |
56 | BEGIN { |
57 | eval { require File::Spec }; |
58 | if ($@) { |
25ca0970 |
59 | *File::Spec::catdir = \&my_catdir; |
60 | *File::Spec::updir = \&my_updir; |
98b50af3 |
61 | *File::Spec::catfile = \&my_catfile; |
3f2ee006 |
62 | } |
63 | } |
64 | |
98b50af3 |
65 | # Avoid 'used only once' warnings. |
66 | my $nop1 = *File::Spec::catdir; |
67 | my $nop2 = *File::Spec::updir; |
68 | my $nop3 = *File::Spec::catfile; |
69 | |
3f2ee006 |
70 | # if you have 5.004_03 (and some slightly older versions?), xsubpp |
71 | # tries to generate line numbers in the C code generated from the .xs. |
72 | # unfortunately, it is a little buggy around #ifdef'd code. |
5d899d7e |
73 | # my choice is leave it in and have people with old perls complain |
3f2ee006 |
74 | # about the "Usage" bug, or leave it out and be unable to compile myself |
5d899d7e |
75 | # without changing it, and then I'd always forget to change it before a |
3f2ee006 |
76 | # release. Sorry, Edward :) |
77 | |
3f2ee006 |
78 | sub try_compile_and_link { |
79 | my ($c, %args) = @_; |
80 | |
81 | my ($ok) = 0; |
2359510d |
82 | my ($tmp) = "tmp$$"; |
3f2ee006 |
83 | local(*TMPC); |
84 | |
85 | my $obj_ext = $Config{obj_ext} || ".o"; |
86 | unlink("$tmp.c", "$tmp$obj_ext"); |
87 | |
88 | if (open(TMPC, ">$tmp.c")) { |
89 | print TMPC $c; |
90 | close(TMPC); |
91 | |
98b50af3 |
92 | my $cccmd = $args{cccmd}; |
3f2ee006 |
93 | |
94 | my $errornull; |
95 | |
96 | my $COREincdir; |
98b50af3 |
97 | |
3f2ee006 |
98 | if ($ENV{PERL_CORE}) { |
99 | my $updir = File::Spec->updir; |
100 | $COREincdir = File::Spec->catdir(($updir) x 3); |
101 | } else { |
102 | $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE'); |
103 | } |
98b50af3 |
104 | |
3f2ee006 |
105 | my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir"; |
98b50af3 |
106 | |
3f2ee006 |
107 | if ($^O eq 'VMS') { |
108 | if ($ENV{PERL_CORE}) { |
3d036c2b |
109 | # Fragile if the extensions change hierarchy within |
6a20eacc |
110 | # the Perl core but this should do for now. |
111 | $cccmd = "$Config{'cc'} /include=([---]) $tmp.c"; |
3f2ee006 |
112 | } else { |
113 | my $perl_core = $Config{'installarchlib'}; |
114 | $perl_core =~ s/\]$/.CORE]/; |
98b50af3 |
115 | $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c"; |
3f2ee006 |
116 | } |
117 | } |
118 | |
119 | if ($args{silent} || !$VERBOSE) { |
120 | $errornull = "2>/dev/null" unless defined $errornull; |
121 | } else { |
122 | $errornull = ''; |
123 | } |
124 | |
98b50af3 |
125 | $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull" |
3f2ee006 |
126 | unless defined $cccmd; |
98b50af3 |
127 | |
c1363767 |
128 | if ($^O eq 'VMS') { |
3f2ee006 |
129 | open( CMDFILE, ">$tmp.com" ); |
130 | print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n"; |
131 | print CMDFILE "\$ $cccmd\n"; |
98b50af3 |
132 | print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate |
3f2ee006 |
133 | close CMDFILE; |
134 | system("\@ $tmp.com"); |
135 | $ok = $?==0; |
5d899d7e |
136 | for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") { |
98b50af3 |
137 | 1 while unlink $_; |
3f2ee006 |
138 | } |
139 | } |
140 | else |
141 | { |
622913ab |
142 | my $tmp_exe = "$tmp$ld_exeext"; |
3f2ee006 |
143 | printf "cccmd = $cccmd\n" if $VERBOSE; |
622913ab |
144 | my $res = system($cccmd); |
ced84e60 |
145 | $ok = defined($res) && $res == 0 && -s $tmp_exe && -x _; |
26e22fd9 |
146 | |
147 | if ( $ok && exists $args{run} && $args{run}) { |
06252d99 |
148 | my $tmp_exe = |
149 | File::Spec->catfile(File::Spec->curdir, $tmp_exe); |
150 | printf "Running $tmp_exe..." if $VERBOSE; |
151 | if (system($tmp_exe) == 0) { |
56c1b3bd |
152 | $ok = 1; |
26e22fd9 |
153 | } else { |
56c1b3bd |
154 | $ok = 0; |
ced84e60 |
155 | my $errno = $? >> 8; |
156 | local $! = $errno; |
157 | printf <<EOF; |
158 | |
159 | *** The test run of '$tmp_exe' failed: status $? |
160 | *** (the status means: errno = $errno or '$!') |
161 | *** DO NOT PANIC: this just means that *some* functionality will be missing. |
162 | EOF |
26e22fd9 |
163 | } |
164 | } |
622913ab |
165 | unlink("$tmp.c", $tmp_exe); |
3f2ee006 |
166 | } |
167 | } |
5d899d7e |
168 | |
26e22fd9 |
169 | return $ok; |
3f2ee006 |
170 | } |
171 | |
172 | sub has_gettimeofday { |
173 | # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already) |
56c1b3bd |
174 | return 0 if $Config{d_gettimeod}; |
98b50af3 |
175 | return 1 if try_compile_and_link(<<EOM); |
5d899d7e |
176 | #include "EXTERN.h" |
177 | #include "perl.h" |
178 | #include "XSUB.h" |
179 | #ifdef I_SYS_TYPES |
3f2ee006 |
180 | # include <sys/types.h> |
181 | #endif |
182 | |
183 | #ifdef I_SYS_TIME |
184 | # include <sys/time.h> |
185 | #endif |
186 | |
187 | #ifdef I_SYS_SELECT |
188 | # include <sys/select.h> /* struct timeval might be hidden in here */ |
189 | #endif |
190 | static int foo() |
191 | { |
192 | struct timeval tv; |
193 | gettimeofday(&tv, 0); |
194 | } |
195 | int main _((int argc, char** argv, char** env)) |
196 | { |
197 | foo(); |
198 | } |
199 | EOM |
200 | return 0; |
201 | } |
202 | |
203 | sub has_x { |
98b50af3 |
204 | my ($x, %args) = @_; |
3f2ee006 |
205 | |
206 | return 1 if |
207 | try_compile_and_link(<<EOM, %args); |
208 | #include "EXTERN.h" |
209 | #include "perl.h" |
210 | #include "XSUB.h" |
211 | |
212 | #ifdef I_UNISTD |
213 | # include <unistd.h> |
214 | #endif |
215 | |
216 | #ifdef I_SYS_TYPES |
217 | # include <sys/types.h> |
218 | #endif |
219 | |
220 | #ifdef I_SYS_TIME |
221 | # include <sys/time.h> |
222 | #endif |
223 | |
224 | int main _((int argc, char** argv, char** env)) |
225 | { |
226 | $x; |
227 | } |
228 | EOM |
229 | return 0; |
230 | } |
231 | |
26e22fd9 |
232 | sub has_nanosleep { |
3d0346a5 |
233 | print "testing... "; |
26e22fd9 |
234 | return 1 if |
235 | try_compile_and_link(<<EOM, run => 1); |
236 | #include <time.h> |
237 | #include <sys/time.h> |
238 | #include <stdio.h> |
239 | #include <stdlib.h> |
240 | #include <errno.h> |
241 | |
242 | /* int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); */ |
243 | |
244 | int main() { |
245 | struct timespec ts1, ts2; |
56c1b3bd |
246 | int ret; |
26e22fd9 |
247 | ts1.tv_sec = 0; |
248 | ts1.tv_nsec = 750000000; |
249 | ts2.tv_sec = 0; |
250 | ts2.tv_nsec = 0; |
56c1b3bd |
251 | errno = 0; |
ced84e60 |
252 | ret = nanosleep(&ts1, &ts2); /* E.g. in AIX nanosleep() fails and sets errno to ENOSYS. */ |
56c1b3bd |
253 | ret == 0 ? exit(0) : exit(errno ? errno : -1); |
26e22fd9 |
254 | } |
255 | EOM |
256 | } |
257 | |
4ed0e2d4 |
258 | sub has_include { |
259 | my ($inc) = @_; |
260 | return 1 if |
261 | try_compile_and_link(<<EOM); |
262 | #include "EXTERN.h" |
263 | #include "perl.h" |
264 | #include "XSUB.h" |
265 | |
266 | #include <$inc> |
267 | int main _((int argc, char** argv, char** env)) |
268 | { |
269 | return 0; |
270 | } |
271 | EOM |
272 | return 0; |
273 | } |
274 | |
170c5524 |
275 | sub has_clock_xxx_syscall { |
ced84e60 |
276 | my $x = shift; |
277 | return 0 unless defined $SYSCALL_H; |
278 | return 1 if |
279 | try_compile_and_link(<<EOM, run => 1); |
280 | #include "EXTERN.h" |
281 | #include "perl.h" |
282 | #include "XSUB.h" |
283 | #include <$SYSCALL_H> |
284 | int main _((int argc, char** argv, char** env)) |
285 | { |
286 | struct timespec ts; |
287 | /* Many Linuxes get ENOSYS even though the syscall exists. */ |
288 | /* All implementations are supposed to support CLOCK_REALTIME. */ |
289 | int ret = syscall(SYS_clock_$x, CLOCK_REALTIME, &ts); |
290 | ret == 0 ? exit(0) : exit(errno ? errno : -1); |
291 | } |
292 | EOM |
293 | } |
294 | |
170c5524 |
295 | sub has_clock_xxx { |
296 | my $xxx = shift; |
ced84e60 |
297 | return 1 if |
298 | try_compile_and_link(<<EOM, run => 1); |
299 | #include "EXTERN.h" |
300 | #include "perl.h" |
301 | #include "XSUB.h" |
302 | int main _((int argc, char** argv, char** env)) |
303 | { |
304 | struct timespec ts; |
170c5524 |
305 | int ret = clock_$xxx(CLOCK_REALTIME, &ts); /* Many Linuxes get ENOSYS. */ |
ced84e60 |
306 | /* All implementations are supposed to support CLOCK_REALTIME. */ |
307 | ret == 0 ? exit(0) : exit(errno ? errno : -1); |
308 | } |
309 | EOM |
310 | } |
311 | |
170c5524 |
312 | sub has_clock { |
313 | return 1 if |
314 | try_compile_and_link(<<EOM, run => 1); |
315 | #include "EXTERN.h" |
316 | #include "perl.h" |
317 | #include "XSUB.h" |
318 | int main _((int argc, char** argv, char** env)) |
319 | { |
320 | clock_t tictoc; |
321 | clock_t ret = clock(); |
322 | ret == (clock_t)-1 ? exit(errno ? errno : -1) : exit(0); |
323 | } |
324 | EOM |
325 | } |
326 | |
327 | sub has_clock_nanosleep { |
328 | return 1 if |
329 | try_compile_and_link(<<EOM, run => 1); |
330 | #include "EXTERN.h" |
331 | #include "perl.h" |
332 | #include "XSUB.h" |
333 | int main _((int argc, char** argv, char** env)) |
334 | { |
335 | int ret; |
336 | struct timerspec ts1; |
337 | struct timerspec ts2; |
338 | ts1.tv_sec = 0; |
339 | ts1.tv_nsec = 750000000;; |
340 | ret = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts1, &ts2); |
341 | ret == 0 ? exit(0) : exit(errno ? errno : -1); |
342 | } |
343 | EOM |
344 | } |
345 | |
046e3f33 |
346 | sub init { |
347 | my $hints = File::Spec->catfile("hints", "$^O.pl"); |
348 | if (-f $hints) { |
349 | print "Using hints $hints...\n"; |
350 | local $self; |
351 | do $hints; |
352 | if (exists $self->{LIBS}) { |
353 | $LIBS = $self->{LIBS}; |
354 | print "Extra libraries: @$LIBS...\n"; |
3f2ee006 |
355 | } |
356 | } |
046e3f33 |
357 | |
358 | $DEFINE = ''; |
3f2ee006 |
359 | |
ced84e60 |
360 | if ($Config{d_syscall}) { |
a5929ff3 |
361 | print "Have syscall()... looking for syscall.h... "; |
ced84e60 |
362 | if (has_include('syscall.h')) { |
363 | $SYSCALL_H = 'syscall.h'; |
364 | } elsif (has_include('sys/syscall.h')) { |
365 | $SYSCALL_H = 'sys/syscall.h'; |
366 | } |
a5929ff3 |
367 | } else { |
368 | print "No syscall()...\n"; |
ced84e60 |
369 | } |
370 | |
a5929ff3 |
371 | if ($Config{d_syscall}) { |
372 | if (defined $SYSCALL_H) { |
373 | print "found <$SYSCALL_H>.\n"; |
374 | } else { |
375 | print "NOT found.\n"; |
376 | } |
ced84e60 |
377 | } |
378 | |
98b50af3 |
379 | print "Looking for gettimeofday()... "; |
3f2ee006 |
380 | my $has_gettimeofday; |
5d899d7e |
381 | if (exists $Config{d_gettimeod}) { |
382 | $has_gettimeofday++ if $Config{d_gettimeod}; |
3f2ee006 |
383 | } elsif (has_gettimeofday()) { |
384 | $DEFINE .= ' -DHAS_GETTIMEOFDAY'; |
385 | $has_gettimeofday++; |
386 | } |
387 | |
388 | if ($has_gettimeofday) { |
98b50af3 |
389 | print "found.\n"; |
3f2ee006 |
390 | } else { |
391 | die <<EOD |
392 | Your operating system does not seem to have the gettimeofday() function. |
393 | (or, at least, I cannot find it) |
394 | |
395 | There is no way Time::HiRes is going to work. |
396 | |
397 | I am awfully sorry but I cannot go further. |
398 | |
399 | Aborting configuration. |
400 | |
401 | EOD |
402 | } |
403 | |
98b50af3 |
404 | print "Looking for setitimer()... "; |
3f2ee006 |
405 | my $has_setitimer; |
5d899d7e |
406 | if (exists $Config{d_setitimer}) { |
407 | $has_setitimer++ if $Config{d_setitimer}; |
3f2ee006 |
408 | } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) { |
409 | $has_setitimer++; |
410 | $DEFINE .= ' -DHAS_SETITIMER'; |
411 | } |
412 | |
413 | if ($has_setitimer) { |
98b50af3 |
414 | print "found.\n"; |
3f2ee006 |
415 | } else { |
98b50af3 |
416 | print "NOT found.\n"; |
3f2ee006 |
417 | } |
418 | |
98b50af3 |
419 | print "Looking for getitimer()... "; |
3f2ee006 |
420 | my $has_getitimer; |
5d899d7e |
421 | if (exists $Config{'d_getitimer'}) { |
422 | $has_getitimer++ if $Config{'d_getitimer'}; |
3f2ee006 |
423 | } elsif (has_x("getitimer(ITIMER_REAL, 0)")) { |
424 | $has_getitimer++; |
425 | $DEFINE .= ' -DHAS_GETITIMER'; |
426 | } |
427 | |
428 | if ($has_getitimer) { |
98b50af3 |
429 | print "found.\n"; |
3f2ee006 |
430 | } else { |
98b50af3 |
431 | print "NOT found.\n"; |
3f2ee006 |
432 | } |
433 | |
434 | if ($has_setitimer && $has_getitimer) { |
4ed0e2d4 |
435 | print "You have interval timers (both setitimer and getitimer).\n"; |
3f2ee006 |
436 | } else { |
98b50af3 |
437 | print "You do not have interval timers.\n"; |
3f2ee006 |
438 | } |
439 | |
98b50af3 |
440 | print "Looking for ualarm()... "; |
441 | my $has_ualarm; |
5d899d7e |
442 | if (exists $Config{d_ualarm}) { |
443 | $has_ualarm++ if $Config{d_ualarm}; |
3f2ee006 |
444 | } elsif (has_x ("ualarm (0, 0)")) { |
445 | $has_ualarm++; |
446 | $DEFINE .= ' -DHAS_UALARM'; |
447 | } |
448 | |
449 | if ($has_ualarm) { |
98b50af3 |
450 | print "found.\n"; |
3f2ee006 |
451 | } else { |
98b50af3 |
452 | print "NOT found.\n"; |
453 | if ($has_setitimer) { |
454 | print "But you have setitimer().\n"; |
455 | print "We can make a Time::HiRes::ualarm().\n"; |
3f2ee006 |
456 | } |
457 | } |
458 | |
98b50af3 |
459 | print "Looking for usleep()... "; |
3f2ee006 |
460 | my $has_usleep; |
5d899d7e |
461 | if (exists $Config{d_usleep}) { |
462 | $has_usleep++ if $Config{d_usleep}; |
3f2ee006 |
463 | } elsif (has_x ("usleep (0)")) { |
464 | $has_usleep++; |
465 | $DEFINE .= ' -DHAS_USLEEP'; |
466 | } |
467 | |
468 | if ($has_usleep) { |
98b50af3 |
469 | print "found.\n"; |
3f2ee006 |
470 | } else { |
98b50af3 |
471 | print "NOT found.\n"; |
472 | print "Let's see if you have select()... "; |
56c1b3bd |
473 | if ($Config{'d_select'}) { |
98b50af3 |
474 | print "found.\n"; |
475 | print "We can make a Time::HiRes::usleep().\n"; |
3f2ee006 |
476 | } else { |
98b50af3 |
477 | print "NOT found.\n"; |
478 | print "You won't have a Time::HiRes::usleep().\n"; |
3f2ee006 |
479 | } |
480 | } |
481 | |
98b50af3 |
482 | print "Looking for nanosleep()... "; |
3f2ee006 |
483 | my $has_nanosleep; |
3d0346a5 |
484 | if ($ENV{FORCE_NANOSLEEP_SCAN}) { |
485 | print "forced scan... "; |
486 | if (has_nanosleep()) { |
487 | $has_nanosleep++; |
488 | $DEFINE .= ' -DTIME_HIRES_NANOSLEEP'; |
489 | } |
490 | } |
491 | elsif (exists $Config{d_nanosleep}) { |
492 | print "believing \$Config{d_nanosleep}... "; |
c1363767 |
493 | if ($Config{d_nanosleep}) { |
494 | $has_nanosleep++; |
495 | $DEFINE .= ' -DTIME_HIRES_NANOSLEEP'; |
496 | } |
3d0346a5 |
497 | } elsif ($^O =~ /^(mpeix)$/) { |
498 | # MPE/iX falsely finds nanosleep from its libc equivalent. |
499 | print "skipping because in $^O... "; |
500 | } else { |
501 | if (has_nanosleep()) { |
502 | $has_nanosleep++; |
503 | $DEFINE .= ' -DTIME_HIRES_NANOSLEEP'; |
504 | } |
3f2ee006 |
505 | } |
506 | |
507 | if ($has_nanosleep) { |
98b50af3 |
508 | print "found.\n"; |
4ed0e2d4 |
509 | print "You can mix subsecond sleeps with signals, if you want to.\n"; |
510 | print "(It's still not portable, though.)\n"; |
3f2ee006 |
511 | } else { |
98b50af3 |
512 | print "NOT found.\n"; |
622913ab |
513 | my $nt = ($^O eq 'os2' ? '' : 'not'); |
514 | print "You can$nt mix subsecond sleeps with signals.\n"; |
4ed0e2d4 |
515 | print "(It would not be portable anyway.)\n"; |
516 | } |
517 | |
ced84e60 |
518 | print "Looking for clock_gettime()... "; |
519 | my $has_clock_gettime; |
520 | if (exists $Config{d_clock_gettime}) { |
521 | $has_clock_gettime++ if $Config{d_clock_gettime}; # Unlikely... |
170c5524 |
522 | } elsif (has_clock_xxx('gettime')) { |
ced84e60 |
523 | $has_clock_gettime++; |
524 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETTIME'; |
170c5524 |
525 | } elsif (defined $SYSCALL_H && has_clock_xxx_syscall('gettime')) { |
ced84e60 |
526 | $has_clock_gettime++; |
527 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETTIME -DTIME_HIRES_CLOCK_GETTIME_SYSCALL'; |
528 | } |
529 | |
530 | if ($has_clock_gettime) { |
531 | if ($DEFINE =~ /-DTIME_HIRES_CLOCK_GETTIME_SYSCALL/) { |
532 | print "found (via syscall).\n"; |
533 | } else { |
534 | print "found.\n"; |
535 | } |
536 | } else { |
537 | print "NOT found.\n"; |
538 | } |
539 | |
540 | print "Looking for clock_getres()... "; |
541 | my $has_clock_getres; |
542 | if (exists $Config{d_clock_getres}) { |
543 | $has_clock_getres++ if $Config{d_clock_getres}; # Unlikely... |
170c5524 |
544 | } elsif (has_clock_xxx('getres')) { |
ced84e60 |
545 | $has_clock_getres++; |
546 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETRES'; |
170c5524 |
547 | } elsif (defined $SYSCALL_H && has_clock_xxx_syscall('getres')) { |
ced84e60 |
548 | $has_clock_getres++; |
549 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETRES -DTIME_HIRES_CLOCK_GETRES_SYSCALL'; |
550 | } |
551 | |
552 | if ($has_clock_getres) { |
553 | if ($DEFINE =~ /-DTIME_HIRES_CLOCK_GETRES_SYSCALL/) { |
554 | print "found (via syscall).\n"; |
555 | } else { |
556 | print "found.\n"; |
557 | } |
558 | } else { |
559 | print "NOT found.\n"; |
560 | } |
561 | |
170c5524 |
562 | print "Looking for clock_nanosleep()... "; |
563 | my $has_clock_nanosleep; |
564 | if (exists $Config{d_clock_nanosleep}) { |
565 | $has_clock_nanosleep++ if $Config{d_clock_nanosleep}; # Unlikely... |
566 | } elsif (has_clock_nanosleep()) { |
567 | $has_clock_nanosleep++; |
568 | $DEFINE .= ' -DTIME_HIRES_CLOCK_NANOSLEEP'; |
569 | } |
570 | |
571 | if ($has_clock_nanosleep) { |
572 | print "found.\n"; |
573 | } else { |
574 | print "NOT found.\n"; |
575 | } |
576 | |
577 | print "Looking for clock()... "; |
578 | my $has_clock; |
579 | if (exists $Config{d_clock}) { |
580 | $has_clock++ if $Config{d_clock}; # Unlikely... |
581 | } elsif (has_clock()) { |
582 | $has_clock++; |
583 | $DEFINE .= ' -DTIME_HIRES_CLOCK'; |
584 | } |
585 | |
586 | if ($has_clock) { |
587 | print "found.\n"; |
588 | } else { |
589 | print "NOT found.\n"; |
590 | } |
591 | |
4ed0e2d4 |
592 | my $has_w32api_windows_h; |
170c5524 |
593 | |
4ed0e2d4 |
594 | if ($^O eq 'cygwin') { |
595 | print "Looking for <w32api/windows.h>... "; |
596 | if (has_include('w32api/windows.h')) { |
597 | $has_w32api_windows_h++; |
598 | $DEFINE .= ' -DHAS_W32API_WINDOWS_H'; |
599 | } |
600 | if ($has_w32api_windows_h) { |
601 | print "found.\n"; |
602 | } else { |
603 | print "NOT found.\n"; |
604 | } |
3f2ee006 |
605 | } |
606 | |
607 | if ($DEFINE) { |
608 | $DEFINE =~ s/^\s+//; |
609 | if (open(XDEFINE, ">xdefine")) { |
610 | print XDEFINE $DEFINE, "\n"; |
611 | close(XDEFINE); |
612 | } |
613 | } |
614 | } |
615 | |
616 | sub doMakefile { |
98b50af3 |
617 | my @makefileopts = (); |
3f2ee006 |
618 | |
619 | if ($] >= 5.005) { |
620 | push (@makefileopts, |
621 | 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>', |
622 | 'ABSTRACT_FROM' => 'HiRes.pm', |
623 | ); |
624 | $DEFINE .= " -DATLEASTFIVEOHOHFIVE"; |
625 | } |
626 | |
627 | push (@makefileopts, |
628 | 'NAME' => 'Time::HiRes', |
629 | 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION |
5d899d7e |
630 | 'LIBS' => $LIBS, # e.g., '-lm' |
631 | 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING' |
3f2ee006 |
632 | 'XSOPT' => $XSOPT, |
ced84e60 |
633 | # Do not even think about 'INC' => '-I/usr/ucbinclude', |
634 | # Solaris will avenge. |
5d899d7e |
635 | 'INC' => '', # e.g., '-I/usr/include/other' |
9649b81b |
636 | 'INSTALLDIRS' => ($] >= 5.008 ? 'perl' : 'site'), |
3f2ee006 |
637 | 'dist' => { |
638 | 'CI' => 'ci -l', |
5d899d7e |
639 | 'COMPRESS' => 'gzip -9f', |
3f2ee006 |
640 | 'SUFFIX' => 'gz', |
641 | }, |
642 | clean => { FILES => "xdefine" }, |
1caec985 |
643 | realclean => { FILES=> 'const-c.inc const-xs.inc' }, |
3f2ee006 |
644 | ); |
645 | |
9ac5eb64 |
646 | if ($ENV{PERL_CORE}) { |
647 | push @makefileopts, MAN3PODS => {}; |
648 | } |
649 | |
3f2ee006 |
650 | WriteMakefile(@makefileopts); |
651 | } |
652 | |
98b50af3 |
653 | sub doConstants { |
654 | if (eval {require ExtUtils::Constant; 1}) { |
ced84e60 |
655 | my @names = (qw(CLOCK_HIGHRES CLOCK_MONOTONIC |
656 | CLOCK_PROCESS_CPUTIME_ID |
657 | CLOCK_REALTIME |
170c5524 |
658 | CLOCK_SOFTTIME |
ced84e60 |
659 | CLOCK_THREAD_CPUTIME_ID |
660 | CLOCK_TIMEOFDAY |
170c5524 |
661 | CLOCKS_PER_SEC |
ced84e60 |
662 | ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF |
170c5524 |
663 | ITIMER_REALPROF |
664 | TIMER_ABSTIME)); |
98b50af3 |
665 | foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer |
170c5524 |
666 | d_nanosleep d_clock_gettime d_clock_getres |
667 | d_clock d_clock_nanosleep)) { |
98b50af3 |
668 | my $macro = $_; |
170c5524 |
669 | if ($macro =~ /^(d_nanosleep|d_clock_gettime|d_clock_getres|d_clock|d_clock_nanosleep)$/) { |
82cbdcc3 |
670 | $macro =~ s/^d_(.+)/TIME_HIRES_\U$1/; |
672f6857 |
671 | } else { |
82cbdcc3 |
672 | $macro =~ s/^d_(.+)/HAS_\U$1/; |
672f6857 |
673 | } |
98b50af3 |
674 | push @names, {name => $_, macro => $macro, value => 1, |
675 | default => ["IV", "0"]}; |
676 | } |
677 | ExtUtils::Constant::WriteConstants( |
678 | NAME => 'Time::HiRes', |
679 | NAMES => \@names, |
680 | ); |
681 | } else { |
1fbb4de4 |
682 | my $file; |
683 | foreach $file ('const-c.inc', 'const-xs.inc') { |
98b50af3 |
684 | my $fallback = File::Spec->catfile('fallback', $file); |
685 | local $/; |
686 | open IN, "<$fallback" or die "Can't open $fallback: $!"; |
687 | open OUT, ">$file" or die "Can't open $file: $!"; |
688 | print OUT <IN> or die $!; |
689 | close OUT or die "Can't close $file: $!"; |
690 | close IN or die "Can't close $fallback: $!"; |
691 | } |
692 | } |
693 | } |
3f2ee006 |
694 | |
98b50af3 |
695 | sub main { |
696 | print "Configuring Time::HiRes...\n"; |
1fbb4de4 |
697 | if ($] == 5.007002) { |
698 | die "Cannot Configure Time::HiRes for Perl $], aborting.\n"; |
699 | } |
3f2ee006 |
700 | |
701 | if ($^O =~ /Win32/i) { |
702 | $DEFINE = '-DSELECT_IS_BROKEN'; |
046e3f33 |
703 | $LIBS = []; |
a5929ff3 |
704 | print "System is $^O, skipping full configure...\n"; |
3f2ee006 |
705 | } else { |
046e3f33 |
706 | init(); |
3f2ee006 |
707 | } |
3f2ee006 |
708 | doMakefile; |
98b50af3 |
709 | doConstants; |
3f2ee006 |
710 | my $make = $Config{'make'} || "make"; |
1fbb4de4 |
711 | unless (exists $ENV{PERL_CORE} && $ENV{PERL_CORE}) { |
3f2ee006 |
712 | print <<EOM; |
3f2ee006 |
713 | Now you may issue '$make'. Do not forget also '$make test'. |
dfffa540 |
714 | EOM |
1fbb4de4 |
715 | if ((exists $ENV{LC_ALL} && $ENV{LC_ALL} =~ /utf-?8/i) || |
716 | (exists $ENV{LC_CTYPE} && $ENV{LC_CTYPE} =~ /utf-?8/i) || |
717 | (exists $ENV{LANG} && $ENV{LANG} =~ /utf-?8/i)) { |
dfffa540 |
718 | print <<EOM; |
ced84e60 |
719 | NOTE: if you get an error like this (the Makefile line number may vary): |
d7358e6a |
720 | Makefile:91: *** missing separator |
1caec985 |
721 | then set the environment variable LC_ALL to "C" and retry |
722 | from scratch (re-run perl "Makefile.PL"). |
3f2ee006 |
723 | EOM |
dfffa540 |
724 | } |
3f2ee006 |
725 | } |
726 | } |
727 | |
728 | &main; |
dcf686c9 |
729 | |
3f2ee006 |
730 | # EOF |