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