Forgot to bump Time-HiRes $VERSION in change #29180
[p5sagit/p5-mst-13.2.git] / ext / Time / HiRes / Makefile.PL
CommitLineData
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 8require 5.002;
9
10use Config;
dcf686c9 11use ExtUtils::MakeMaker;
98b50af3 12use strict;
3f2ee006 13
14my $VERBOSE = $ENV{VERBOSE};
98b50af3 15my $DEFINE;
046e3f33 16my $LIBS = [];
56c1b3bd 17my $XSOPT = '';
ced84e60 18my $SYSCALL_H;
98b50af3 19
046e3f33 20use vars qw($self); # Used in 'sourcing' the hints.
21
4ed0e2d4 22my $ld_exeext = ($^O eq 'cygwin' ||
23 $^O eq 'os2' && $Config{ldflags} =~ /-Zexe\b/) ? '.exe' : '';
622913ab 24
12724655 25unless($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
31sub my_dirsep {
32 $^O eq 'VMS' ? '.' :
33 $^O =~ /mswin32|netware|djgpp/i ? '\\' :
34 $^O eq 'MacOS' ? ':'
35 : '/';
36}
37
38sub my_catdir {
39 shift;
40 my $catdir = join(my_dirsep, @_);
98b50af3 41 $^O eq 'VMS' ? "[$catdir]" : $catdir;
42}
43
44sub 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
51sub my_updir {
52 shift;
53 $^O eq 'VMS' ? "-" : "..";
54}
55
56BEGIN {
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.
66my $nop1 = *File::Spec::catdir;
67my $nop2 = *File::Spec::updir;
68my $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 78sub 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.
162EOF
26e22fd9 163 }
164 }
622913ab 165 unlink("$tmp.c", $tmp_exe);
3f2ee006 166 }
167 }
5d899d7e 168
26e22fd9 169 return $ok;
3f2ee006 170}
171
75d5269b 172my $TIME_HEADERS = <<EOH;
5d899d7e 173#include "EXTERN.h"
174#include "perl.h"
175#include "XSUB.h"
176#ifdef I_SYS_TYPES
3f2ee006 177# include <sys/types.h>
178#endif
3f2ee006 179#ifdef I_SYS_TIME
180# include <sys/time.h>
181#endif
3f2ee006 182#ifdef I_SYS_SELECT
183# include <sys/select.h> /* struct timeval might be hidden in here */
184#endif
75d5269b 185EOH
186
187sub has_gettimeofday {
188 # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
189 return 0 if $Config{d_gettimeod};
190 return 1 if try_compile_and_link(<<EOM);
191$TIME_HEADERS
3f2ee006 192static int foo()
193{
194 struct timeval tv;
195 gettimeofday(&tv, 0);
196}
197int main _((int argc, char** argv, char** env))
198{
199 foo();
200}
201EOM
202 return 0;
203}
204
205sub has_x {
98b50af3 206 my ($x, %args) = @_;
3f2ee006 207
208 return 1 if
209 try_compile_and_link(<<EOM, %args);
210#include "EXTERN.h"
211#include "perl.h"
212#include "XSUB.h"
213
214#ifdef I_UNISTD
215# include <unistd.h>
216#endif
217
218#ifdef I_SYS_TYPES
219# include <sys/types.h>
220#endif
221
222#ifdef I_SYS_TIME
223# include <sys/time.h>
224#endif
225
226int main _((int argc, char** argv, char** env))
227{
228 $x;
229}
230EOM
231 return 0;
232}
233
26e22fd9 234sub has_nanosleep {
3d0346a5 235 print "testing... ";
26e22fd9 236 return 1 if
237 try_compile_and_link(<<EOM, run => 1);
238#include <time.h>
239#include <sys/time.h>
240#include <stdio.h>
241#include <stdlib.h>
242#include <errno.h>
243
244/* int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); */
245
246int main() {
247 struct timespec ts1, ts2;
56c1b3bd 248 int ret;
26e22fd9 249 ts1.tv_sec = 0;
250 ts1.tv_nsec = 750000000;
251 ts2.tv_sec = 0;
252 ts2.tv_nsec = 0;
56c1b3bd 253 errno = 0;
ced84e60 254 ret = nanosleep(&ts1, &ts2); /* E.g. in AIX nanosleep() fails and sets errno to ENOSYS. */
56c1b3bd 255 ret == 0 ? exit(0) : exit(errno ? errno : -1);
26e22fd9 256}
257EOM
258}
259
4ed0e2d4 260sub has_include {
261 my ($inc) = @_;
262 return 1 if
263 try_compile_and_link(<<EOM);
264#include "EXTERN.h"
265#include "perl.h"
266#include "XSUB.h"
267
268#include <$inc>
269int main _((int argc, char** argv, char** env))
270{
271 return 0;
272}
273EOM
274 return 0;
275}
276
170c5524 277sub has_clock_xxx_syscall {
ced84e60 278 my $x = shift;
279 return 0 unless defined $SYSCALL_H;
280 return 1 if
281 try_compile_and_link(<<EOM, run => 1);
282#include "EXTERN.h"
283#include "perl.h"
284#include "XSUB.h"
285#include <$SYSCALL_H>
286int main _((int argc, char** argv, char** env))
287{
288 struct timespec ts;
289 /* Many Linuxes get ENOSYS even though the syscall exists. */
290 /* All implementations are supposed to support CLOCK_REALTIME. */
291 int ret = syscall(SYS_clock_$x, CLOCK_REALTIME, &ts);
292 ret == 0 ? exit(0) : exit(errno ? errno : -1);
293}
294EOM
295}
296
170c5524 297sub has_clock_xxx {
298 my $xxx = shift;
ced84e60 299 return 1 if
300 try_compile_and_link(<<EOM, run => 1);
301#include "EXTERN.h"
302#include "perl.h"
303#include "XSUB.h"
304int main _((int argc, char** argv, char** env))
305{
306 struct timespec ts;
170c5524 307 int ret = clock_$xxx(CLOCK_REALTIME, &ts); /* Many Linuxes get ENOSYS. */
ced84e60 308 /* All implementations are supposed to support CLOCK_REALTIME. */
309 ret == 0 ? exit(0) : exit(errno ? errno : -1);
310}
311EOM
312}
313
170c5524 314sub has_clock {
315 return 1 if
316 try_compile_and_link(<<EOM, run => 1);
317#include "EXTERN.h"
318#include "perl.h"
319#include "XSUB.h"
320int main _((int argc, char** argv, char** env))
321{
322 clock_t tictoc;
323 clock_t ret = clock();
324 ret == (clock_t)-1 ? exit(errno ? errno : -1) : exit(0);
325}
326EOM
327}
328
329sub has_clock_nanosleep {
330 return 1 if
331 try_compile_and_link(<<EOM, run => 1);
332#include "EXTERN.h"
333#include "perl.h"
334#include "XSUB.h"
335int main _((int argc, char** argv, char** env))
336{
337 int ret;
338 struct timerspec ts1;
339 struct timerspec ts2;
340 ts1.tv_sec = 0;
341 ts1.tv_nsec = 750000000;;
342 ret = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts1, &ts2);
343 ret == 0 ? exit(0) : exit(errno ? errno : -1);
344}
345EOM
346}
347
046e3f33 348sub init {
349 my $hints = File::Spec->catfile("hints", "$^O.pl");
350 if (-f $hints) {
351 print "Using hints $hints...\n";
352 local $self;
353 do $hints;
354 if (exists $self->{LIBS}) {
355 $LIBS = $self->{LIBS};
356 print "Extra libraries: @$LIBS...\n";
3f2ee006 357 }
358 }
046e3f33 359
360 $DEFINE = '';
3f2ee006 361
ced84e60 362 if ($Config{d_syscall}) {
a5929ff3 363 print "Have syscall()... looking for syscall.h... ";
ced84e60 364 if (has_include('syscall.h')) {
365 $SYSCALL_H = 'syscall.h';
366 } elsif (has_include('sys/syscall.h')) {
367 $SYSCALL_H = 'sys/syscall.h';
368 }
a5929ff3 369 } else {
370 print "No syscall()...\n";
ced84e60 371 }
372
a5929ff3 373 if ($Config{d_syscall}) {
374 if (defined $SYSCALL_H) {
375 print "found <$SYSCALL_H>.\n";
376 } else {
377 print "NOT found.\n";
378 }
ced84e60 379 }
380
98b50af3 381 print "Looking for gettimeofday()... ";
3f2ee006 382 my $has_gettimeofday;
5d899d7e 383 if (exists $Config{d_gettimeod}) {
384 $has_gettimeofday++ if $Config{d_gettimeod};
3f2ee006 385 } elsif (has_gettimeofday()) {
386 $DEFINE .= ' -DHAS_GETTIMEOFDAY';
387 $has_gettimeofday++;
388 }
389
390 if ($has_gettimeofday) {
98b50af3 391 print "found.\n";
3f2ee006 392 } else {
393 die <<EOD
394Your operating system does not seem to have the gettimeofday() function.
395(or, at least, I cannot find it)
396
397There is no way Time::HiRes is going to work.
398
399I am awfully sorry but I cannot go further.
400
401Aborting configuration.
402
403EOD
404 }
405
98b50af3 406 print "Looking for setitimer()... ";
3f2ee006 407 my $has_setitimer;
5d899d7e 408 if (exists $Config{d_setitimer}) {
409 $has_setitimer++ if $Config{d_setitimer};
3f2ee006 410 } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
411 $has_setitimer++;
412 $DEFINE .= ' -DHAS_SETITIMER';
413 }
414
415 if ($has_setitimer) {
98b50af3 416 print "found.\n";
3f2ee006 417 } else {
98b50af3 418 print "NOT found.\n";
3f2ee006 419 }
420
98b50af3 421 print "Looking for getitimer()... ";
3f2ee006 422 my $has_getitimer;
5d899d7e 423 if (exists $Config{'d_getitimer'}) {
424 $has_getitimer++ if $Config{'d_getitimer'};
3f2ee006 425 } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
426 $has_getitimer++;
427 $DEFINE .= ' -DHAS_GETITIMER';
428 }
429
430 if ($has_getitimer) {
98b50af3 431 print "found.\n";
3f2ee006 432 } else {
98b50af3 433 print "NOT found.\n";
3f2ee006 434 }
435
436 if ($has_setitimer && $has_getitimer) {
4ed0e2d4 437 print "You have interval timers (both setitimer and getitimer).\n";
3f2ee006 438 } else {
98b50af3 439 print "You do not have interval timers.\n";
3f2ee006 440 }
441
98b50af3 442 print "Looking for ualarm()... ";
443 my $has_ualarm;
5d899d7e 444 if (exists $Config{d_ualarm}) {
445 $has_ualarm++ if $Config{d_ualarm};
3f2ee006 446 } elsif (has_x ("ualarm (0, 0)")) {
447 $has_ualarm++;
448 $DEFINE .= ' -DHAS_UALARM';
449 }
450
451 if ($has_ualarm) {
98b50af3 452 print "found.\n";
3f2ee006 453 } else {
98b50af3 454 print "NOT found.\n";
455 if ($has_setitimer) {
456 print "But you have setitimer().\n";
457 print "We can make a Time::HiRes::ualarm().\n";
3f2ee006 458 }
459 }
460
98b50af3 461 print "Looking for usleep()... ";
3f2ee006 462 my $has_usleep;
5d899d7e 463 if (exists $Config{d_usleep}) {
464 $has_usleep++ if $Config{d_usleep};
3f2ee006 465 } elsif (has_x ("usleep (0)")) {
466 $has_usleep++;
467 $DEFINE .= ' -DHAS_USLEEP';
468 }
469
470 if ($has_usleep) {
98b50af3 471 print "found.\n";
3f2ee006 472 } else {
98b50af3 473 print "NOT found.\n";
474 print "Let's see if you have select()... ";
56c1b3bd 475 if ($Config{'d_select'}) {
98b50af3 476 print "found.\n";
477 print "We can make a Time::HiRes::usleep().\n";
3f2ee006 478 } else {
98b50af3 479 print "NOT found.\n";
480 print "You won't have a Time::HiRes::usleep().\n";
3f2ee006 481 }
482 }
483
98b50af3 484 print "Looking for nanosleep()... ";
3f2ee006 485 my $has_nanosleep;
3d0346a5 486 if ($ENV{FORCE_NANOSLEEP_SCAN}) {
487 print "forced scan... ";
488 if (has_nanosleep()) {
489 $has_nanosleep++;
490 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
491 }
492 }
493 elsif (exists $Config{d_nanosleep}) {
494 print "believing \$Config{d_nanosleep}... ";
c1363767 495 if ($Config{d_nanosleep}) {
496 $has_nanosleep++;
497 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
498 }
3d0346a5 499 } elsif ($^O =~ /^(mpeix)$/) {
500 # MPE/iX falsely finds nanosleep from its libc equivalent.
501 print "skipping because in $^O... ";
502 } else {
503 if (has_nanosleep()) {
504 $has_nanosleep++;
505 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
506 }
3f2ee006 507 }
508
509 if ($has_nanosleep) {
98b50af3 510 print "found.\n";
4ed0e2d4 511 print "You can mix subsecond sleeps with signals, if you want to.\n";
512 print "(It's still not portable, though.)\n";
3f2ee006 513 } else {
98b50af3 514 print "NOT found.\n";
622913ab 515 my $nt = ($^O eq 'os2' ? '' : 'not');
516 print "You can$nt mix subsecond sleeps with signals.\n";
4ed0e2d4 517 print "(It would not be portable anyway.)\n";
518 }
519
ced84e60 520 print "Looking for clock_gettime()... ";
521 my $has_clock_gettime;
522 if (exists $Config{d_clock_gettime}) {
523 $has_clock_gettime++ if $Config{d_clock_gettime}; # Unlikely...
170c5524 524 } elsif (has_clock_xxx('gettime')) {
ced84e60 525 $has_clock_gettime++;
526 $DEFINE .= ' -DTIME_HIRES_CLOCK_GETTIME';
170c5524 527 } elsif (defined $SYSCALL_H && has_clock_xxx_syscall('gettime')) {
ced84e60 528 $has_clock_gettime++;
529 $DEFINE .= ' -DTIME_HIRES_CLOCK_GETTIME -DTIME_HIRES_CLOCK_GETTIME_SYSCALL';
530 }
531
532 if ($has_clock_gettime) {
533 if ($DEFINE =~ /-DTIME_HIRES_CLOCK_GETTIME_SYSCALL/) {
534 print "found (via syscall).\n";
535 } else {
536 print "found.\n";
537 }
538 } else {
539 print "NOT found.\n";
540 }
541
542 print "Looking for clock_getres()... ";
543 my $has_clock_getres;
544 if (exists $Config{d_clock_getres}) {
545 $has_clock_getres++ if $Config{d_clock_getres}; # Unlikely...
170c5524 546 } elsif (has_clock_xxx('getres')) {
ced84e60 547 $has_clock_getres++;
548 $DEFINE .= ' -DTIME_HIRES_CLOCK_GETRES';
170c5524 549 } elsif (defined $SYSCALL_H && has_clock_xxx_syscall('getres')) {
ced84e60 550 $has_clock_getres++;
551 $DEFINE .= ' -DTIME_HIRES_CLOCK_GETRES -DTIME_HIRES_CLOCK_GETRES_SYSCALL';
552 }
553
554 if ($has_clock_getres) {
555 if ($DEFINE =~ /-DTIME_HIRES_CLOCK_GETRES_SYSCALL/) {
556 print "found (via syscall).\n";
557 } else {
558 print "found.\n";
559 }
560 } else {
561 print "NOT found.\n";
562 }
563
170c5524 564 print "Looking for clock_nanosleep()... ";
565 my $has_clock_nanosleep;
566 if (exists $Config{d_clock_nanosleep}) {
567 $has_clock_nanosleep++ if $Config{d_clock_nanosleep}; # Unlikely...
568 } elsif (has_clock_nanosleep()) {
569 $has_clock_nanosleep++;
570 $DEFINE .= ' -DTIME_HIRES_CLOCK_NANOSLEEP';
571 }
572
573 if ($has_clock_nanosleep) {
574 print "found.\n";
575 } else {
576 print "NOT found.\n";
577 }
578
579 print "Looking for clock()... ";
580 my $has_clock;
581 if (exists $Config{d_clock}) {
582 $has_clock++ if $Config{d_clock}; # Unlikely...
583 } elsif (has_clock()) {
584 $has_clock++;
585 $DEFINE .= ' -DTIME_HIRES_CLOCK';
586 }
587
588 if ($has_clock) {
589 print "found.\n";
590 } else {
591 print "NOT found.\n";
592 }
593
75d5269b 594 print "Trying struct stat st_atimespec.tv_nsec...";
595 my $has_stat_st_xtimespec;
596 if (try_compile_and_link(<<EOM)) {
597$TIME_HEADERS
598#include <sys/stat.h>
599int main() {
600 struct stat st;
601 st.st_atimespec.tv_nsec = 0;
602}
603EOM
604 $has_stat_st_xtimespec++;
605 $DEFINE .= ' -DTIME_HIRES_STAT=1';
606 }
607
608 if ($has_stat_st_xtimespec) {
609 print "found.\n";
610 } else {
611 print "NOT found.\n";
612 }
613
614 print "Trying struct stat st_atimensec...";
615 my $has_stat_st_xtimensec;
616 if (try_compile_and_link(<<EOM)) {
617$TIME_HEADERS
618#include <sys/stat.h>
619int main() {
620 struct stat st;
621 st.st_atimensec = 0;
622}
623EOM
624 $has_stat_st_xtimensec++;
625 $DEFINE .= ' -DTIME_HIRES_STAT=2';
626 }
627
628 if ($has_stat_st_xtimensec) {
629 print "found.\n";
630 } else {
631 print "NOT found.\n";
632 }
633
634 print "Trying struct stat st_atime_n...";
635 my $has_stat_st_xtime_n;
636 if (try_compile_and_link(<<EOM)) {
637$TIME_HEADERS
638#include <sys/stat.h>
639int main() {
640 struct stat st;
641 st.st_atime_n = 0;
642}
643EOM
644 $has_stat_st_xtime_n++;
645 $DEFINE .= ' -DTIME_HIRES_STAT=3';
646 }
647
648 if ($has_stat_st_xtime_n) {
649 print "found.\n";
650 } else {
651 print "NOT found.\n";
652 }
653
654 print "Trying struct stat st_atim.tv_nsec...";
655 my $has_stat_st_xtim;
656 if (try_compile_and_link(<<EOM)) {
657$TIME_HEADERS
658#include <sys/stat.h>
659int main() {
660 struct stat st;
661 st.st_atim.tv_nsec = 0;
662}
663EOM
664 $has_stat_st_xtim++;
665 $DEFINE .= ' -DTIME_HIRES_STAT=4';
666 }
667
668 if ($has_stat_st_xtim) {
669 print "found.\n";
670 } else {
671 print "NOT found.\n";
672 }
673
674 print "Trying struct stat st_uatime...";
675 my $has_stat_st_uxtime;
676 if (try_compile_and_link(<<EOM)) {
677$TIME_HEADERS
678#include <sys/stat.h>
679int main() {
680 struct stat st;
681 st.st_uatime = 0;
682}
683EOM
684 $has_stat_st_uxtime++;
685 $DEFINE .= ' -DTIME_HIRES_STAT=5';
686 }
687
688 if ($has_stat_st_uxtime) {
689 print "found.\n";
690 } else {
691 print "NOT found.\n";
692 }
693
694 if ($DEFINE =~ /-DTIME_HIRES_STAT=\d+/) {
695 print "You seem to have stat subsecond timestamps.\n";
696 print "(Your struct stat has them, but the filesystems must help.)\n";
697 } else {
698 print "You do not seem to have stat subsecond timestamps.\n";
699 }
700
4ed0e2d4 701 my $has_w32api_windows_h;
170c5524 702
4ed0e2d4 703 if ($^O eq 'cygwin') {
704 print "Looking for <w32api/windows.h>... ";
705 if (has_include('w32api/windows.h')) {
706 $has_w32api_windows_h++;
707 $DEFINE .= ' -DHAS_W32API_WINDOWS_H';
708 }
709 if ($has_w32api_windows_h) {
710 print "found.\n";
711 } else {
712 print "NOT found.\n";
713 }
3f2ee006 714 }
715
716 if ($DEFINE) {
717 $DEFINE =~ s/^\s+//;
718 if (open(XDEFINE, ">xdefine")) {
719 print XDEFINE $DEFINE, "\n";
720 close(XDEFINE);
721 }
722 }
723}
724
725sub doMakefile {
98b50af3 726 my @makefileopts = ();
3f2ee006 727
728 if ($] >= 5.005) {
729 push (@makefileopts,
730 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>',
731 'ABSTRACT_FROM' => 'HiRes.pm',
732 );
733 $DEFINE .= " -DATLEASTFIVEOHOHFIVE";
734 }
735
736 push (@makefileopts,
737 'NAME' => 'Time::HiRes',
738 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
5d899d7e 739 'LIBS' => $LIBS, # e.g., '-lm'
740 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
3f2ee006 741 'XSOPT' => $XSOPT,
ced84e60 742 # Do not even think about 'INC' => '-I/usr/ucbinclude',
743 # Solaris will avenge.
5d899d7e 744 'INC' => '', # e.g., '-I/usr/include/other'
9649b81b 745 'INSTALLDIRS' => ($] >= 5.008 ? 'perl' : 'site'),
3f2ee006 746 'dist' => {
747 'CI' => 'ci -l',
5d899d7e 748 'COMPRESS' => 'gzip -9f',
3f2ee006 749 'SUFFIX' => 'gz',
750 },
751 clean => { FILES => "xdefine" },
1caec985 752 realclean => { FILES=> 'const-c.inc const-xs.inc' },
3f2ee006 753 );
754
9ac5eb64 755 if ($ENV{PERL_CORE}) {
756 push @makefileopts, MAN3PODS => {};
757 }
758
3f2ee006 759 WriteMakefile(@makefileopts);
760}
761
98b50af3 762sub doConstants {
763 if (eval {require ExtUtils::Constant; 1}) {
75d5269b 764 my @names = qw(CLOCK_HIGHRES CLOCK_MONOTONIC
765 CLOCK_PROCESS_CPUTIME_ID
766 CLOCK_REALTIME
767 CLOCK_SOFTTIME
768 CLOCK_THREAD_CPUTIME_ID
769 CLOCK_TIMEOFDAY
770 CLOCKS_PER_SEC
771 ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF
772 ITIMER_REALPROF
773 TIMER_ABSTIME);
98b50af3 774 foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
170c5524 775 d_nanosleep d_clock_gettime d_clock_getres
75d5269b 776 d_clock d_clock_nanosleep d_hires_stat)) {
98b50af3 777 my $macro = $_;
170c5524 778 if ($macro =~ /^(d_nanosleep|d_clock_gettime|d_clock_getres|d_clock|d_clock_nanosleep)$/) {
82cbdcc3 779 $macro =~ s/^d_(.+)/TIME_HIRES_\U$1/;
75d5269b 780 } elsif ($macro =~ /^(d_hires_stat)$/) {
781 my $d_hires_stat = 0;
782 $d_hires_stat = $1 if ($DEFINE =~ /-DTIME_HIRES_STAT=(\d+)/);
783 push @names, {name => $_, macro => "TIME_HIRES_STAT", value => $d_hires_stat,
784 default => ["IV", "0"]};
785 next;
672f6857 786 } else {
82cbdcc3 787 $macro =~ s/^d_(.+)/HAS_\U$1/;
672f6857 788 }
98b50af3 789 push @names, {name => $_, macro => $macro, value => 1,
790 default => ["IV", "0"]};
791 }
792 ExtUtils::Constant::WriteConstants(
793 NAME => 'Time::HiRes',
794 NAMES => \@names,
795 );
796 } else {
1fbb4de4 797 my $file;
798 foreach $file ('const-c.inc', 'const-xs.inc') {
98b50af3 799 my $fallback = File::Spec->catfile('fallback', $file);
800 local $/;
801 open IN, "<$fallback" or die "Can't open $fallback: $!";
802 open OUT, ">$file" or die "Can't open $file: $!";
803 print OUT <IN> or die $!;
804 close OUT or die "Can't close $file: $!";
805 close IN or die "Can't close $fallback: $!";
806 }
807 }
808}
3f2ee006 809
98b50af3 810sub main {
811 print "Configuring Time::HiRes...\n";
1fbb4de4 812 if ($] == 5.007002) {
813 die "Cannot Configure Time::HiRes for Perl $], aborting.\n";
814 }
3f2ee006 815
816 if ($^O =~ /Win32/i) {
817 $DEFINE = '-DSELECT_IS_BROKEN';
046e3f33 818 $LIBS = [];
a5929ff3 819 print "System is $^O, skipping full configure...\n";
3f2ee006 820 } else {
046e3f33 821 init();
3f2ee006 822 }
3f2ee006 823 doMakefile;
98b50af3 824 doConstants;
3f2ee006 825 my $make = $Config{'make'} || "make";
1fbb4de4 826 unless (exists $ENV{PERL_CORE} && $ENV{PERL_CORE}) {
3f2ee006 827 print <<EOM;
3f2ee006 828Now you may issue '$make'. Do not forget also '$make test'.
dfffa540 829EOM
1fbb4de4 830 if ((exists $ENV{LC_ALL} && $ENV{LC_ALL} =~ /utf-?8/i) ||
831 (exists $ENV{LC_CTYPE} && $ENV{LC_CTYPE} =~ /utf-?8/i) ||
832 (exists $ENV{LANG} && $ENV{LANG} =~ /utf-?8/i)) {
dfffa540 833 print <<EOM;
ced84e60 834NOTE: if you get an error like this (the Makefile line number may vary):
d7358e6a 835Makefile:91: *** missing separator
1caec985 836then set the environment variable LC_ALL to "C" and retry
837from scratch (re-run perl "Makefile.PL").
3f2ee006 838EOM
dfffa540 839 }
3f2ee006 840 }
841}
842
843&main;
dcf686c9 844
3f2ee006 845# EOF