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