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 | |
ced84e60 |
275 | sub has_clock_x_syscall { |
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 | |
295 | sub has_clock_x { |
296 | my $x = shift; |
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; |
305 | int ret = clock_$x(CLOCK_REALTIME, &ts); /* Many Linuxes get ENOSYS. */ |
306 | /* All implementations are supposed to support CLOCK_REALTIME. */ |
307 | ret == 0 ? exit(0) : exit(errno ? errno : -1); |
308 | } |
309 | EOM |
310 | } |
311 | |
046e3f33 |
312 | sub init { |
313 | my $hints = File::Spec->catfile("hints", "$^O.pl"); |
314 | if (-f $hints) { |
315 | print "Using hints $hints...\n"; |
316 | local $self; |
317 | do $hints; |
318 | if (exists $self->{LIBS}) { |
319 | $LIBS = $self->{LIBS}; |
320 | print "Extra libraries: @$LIBS...\n"; |
3f2ee006 |
321 | } |
322 | } |
046e3f33 |
323 | |
324 | $DEFINE = ''; |
3f2ee006 |
325 | |
ced84e60 |
326 | if ($Config{d_syscall}) { |
327 | print "Have syscall(), looking for syscall.h... "; |
328 | if (has_include('syscall.h')) { |
329 | $SYSCALL_H = 'syscall.h'; |
330 | } elsif (has_include('sys/syscall.h')) { |
331 | $SYSCALL_H = 'sys/syscall.h'; |
332 | } |
333 | } |
334 | |
335 | if (defined $SYSCALL_H) { |
336 | print "found <$SYSCALL_H>.\n"; |
337 | } else { |
338 | print "NOT found.\n"; |
339 | } |
340 | |
98b50af3 |
341 | print "Looking for gettimeofday()... "; |
3f2ee006 |
342 | my $has_gettimeofday; |
5d899d7e |
343 | if (exists $Config{d_gettimeod}) { |
344 | $has_gettimeofday++ if $Config{d_gettimeod}; |
3f2ee006 |
345 | } elsif (has_gettimeofday()) { |
346 | $DEFINE .= ' -DHAS_GETTIMEOFDAY'; |
347 | $has_gettimeofday++; |
348 | } |
349 | |
350 | if ($has_gettimeofday) { |
98b50af3 |
351 | print "found.\n"; |
3f2ee006 |
352 | } else { |
353 | die <<EOD |
354 | Your operating system does not seem to have the gettimeofday() function. |
355 | (or, at least, I cannot find it) |
356 | |
357 | There is no way Time::HiRes is going to work. |
358 | |
359 | I am awfully sorry but I cannot go further. |
360 | |
361 | Aborting configuration. |
362 | |
363 | EOD |
364 | } |
365 | |
98b50af3 |
366 | print "Looking for setitimer()... "; |
3f2ee006 |
367 | my $has_setitimer; |
5d899d7e |
368 | if (exists $Config{d_setitimer}) { |
369 | $has_setitimer++ if $Config{d_setitimer}; |
3f2ee006 |
370 | } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) { |
371 | $has_setitimer++; |
372 | $DEFINE .= ' -DHAS_SETITIMER'; |
373 | } |
374 | |
375 | if ($has_setitimer) { |
98b50af3 |
376 | print "found.\n"; |
3f2ee006 |
377 | } else { |
98b50af3 |
378 | print "NOT found.\n"; |
3f2ee006 |
379 | } |
380 | |
98b50af3 |
381 | print "Looking for getitimer()... "; |
3f2ee006 |
382 | my $has_getitimer; |
5d899d7e |
383 | if (exists $Config{'d_getitimer'}) { |
384 | $has_getitimer++ if $Config{'d_getitimer'}; |
3f2ee006 |
385 | } elsif (has_x("getitimer(ITIMER_REAL, 0)")) { |
386 | $has_getitimer++; |
387 | $DEFINE .= ' -DHAS_GETITIMER'; |
388 | } |
389 | |
390 | if ($has_getitimer) { |
98b50af3 |
391 | print "found.\n"; |
3f2ee006 |
392 | } else { |
98b50af3 |
393 | print "NOT found.\n"; |
3f2ee006 |
394 | } |
395 | |
396 | if ($has_setitimer && $has_getitimer) { |
4ed0e2d4 |
397 | print "You have interval timers (both setitimer and getitimer).\n"; |
3f2ee006 |
398 | } else { |
98b50af3 |
399 | print "You do not have interval timers.\n"; |
3f2ee006 |
400 | } |
401 | |
98b50af3 |
402 | print "Looking for ualarm()... "; |
403 | my $has_ualarm; |
5d899d7e |
404 | if (exists $Config{d_ualarm}) { |
405 | $has_ualarm++ if $Config{d_ualarm}; |
3f2ee006 |
406 | } elsif (has_x ("ualarm (0, 0)")) { |
407 | $has_ualarm++; |
408 | $DEFINE .= ' -DHAS_UALARM'; |
409 | } |
410 | |
411 | if ($has_ualarm) { |
98b50af3 |
412 | print "found.\n"; |
3f2ee006 |
413 | } else { |
98b50af3 |
414 | print "NOT found.\n"; |
415 | if ($has_setitimer) { |
416 | print "But you have setitimer().\n"; |
417 | print "We can make a Time::HiRes::ualarm().\n"; |
3f2ee006 |
418 | } |
419 | } |
420 | |
98b50af3 |
421 | print "Looking for usleep()... "; |
3f2ee006 |
422 | my $has_usleep; |
5d899d7e |
423 | if (exists $Config{d_usleep}) { |
424 | $has_usleep++ if $Config{d_usleep}; |
3f2ee006 |
425 | } elsif (has_x ("usleep (0)")) { |
426 | $has_usleep++; |
427 | $DEFINE .= ' -DHAS_USLEEP'; |
428 | } |
429 | |
430 | if ($has_usleep) { |
98b50af3 |
431 | print "found.\n"; |
3f2ee006 |
432 | } else { |
98b50af3 |
433 | print "NOT found.\n"; |
434 | print "Let's see if you have select()... "; |
56c1b3bd |
435 | if ($Config{'d_select'}) { |
98b50af3 |
436 | print "found.\n"; |
437 | print "We can make a Time::HiRes::usleep().\n"; |
3f2ee006 |
438 | } else { |
98b50af3 |
439 | print "NOT found.\n"; |
440 | print "You won't have a Time::HiRes::usleep().\n"; |
3f2ee006 |
441 | } |
442 | } |
443 | |
98b50af3 |
444 | print "Looking for nanosleep()... "; |
3f2ee006 |
445 | my $has_nanosleep; |
3d0346a5 |
446 | if ($ENV{FORCE_NANOSLEEP_SCAN}) { |
447 | print "forced scan... "; |
448 | if (has_nanosleep()) { |
449 | $has_nanosleep++; |
450 | $DEFINE .= ' -DTIME_HIRES_NANOSLEEP'; |
451 | } |
452 | } |
453 | elsif (exists $Config{d_nanosleep}) { |
454 | print "believing \$Config{d_nanosleep}... "; |
c1363767 |
455 | if ($Config{d_nanosleep}) { |
456 | $has_nanosleep++; |
457 | $DEFINE .= ' -DTIME_HIRES_NANOSLEEP'; |
458 | } |
3d0346a5 |
459 | } elsif ($^O =~ /^(mpeix)$/) { |
460 | # MPE/iX falsely finds nanosleep from its libc equivalent. |
461 | print "skipping because in $^O... "; |
462 | } else { |
463 | if (has_nanosleep()) { |
464 | $has_nanosleep++; |
465 | $DEFINE .= ' -DTIME_HIRES_NANOSLEEP'; |
466 | } |
3f2ee006 |
467 | } |
468 | |
469 | if ($has_nanosleep) { |
98b50af3 |
470 | print "found.\n"; |
4ed0e2d4 |
471 | print "You can mix subsecond sleeps with signals, if you want to.\n"; |
472 | print "(It's still not portable, though.)\n"; |
3f2ee006 |
473 | } else { |
98b50af3 |
474 | print "NOT found.\n"; |
622913ab |
475 | my $nt = ($^O eq 'os2' ? '' : 'not'); |
476 | print "You can$nt mix subsecond sleeps with signals.\n"; |
4ed0e2d4 |
477 | print "(It would not be portable anyway.)\n"; |
478 | } |
479 | |
ced84e60 |
480 | print "Looking for clock_gettime()... "; |
481 | my $has_clock_gettime; |
482 | if (exists $Config{d_clock_gettime}) { |
483 | $has_clock_gettime++ if $Config{d_clock_gettime}; # Unlikely... |
484 | } elsif (has_clock_x('gettime')) { |
485 | $has_clock_gettime++; |
486 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETTIME'; |
487 | } elsif (defined $SYSCALL_H && has_clock_x_syscall('gettime')) { |
488 | $has_clock_gettime++; |
489 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETTIME -DTIME_HIRES_CLOCK_GETTIME_SYSCALL'; |
490 | } |
491 | |
492 | if ($has_clock_gettime) { |
493 | if ($DEFINE =~ /-DTIME_HIRES_CLOCK_GETTIME_SYSCALL/) { |
494 | print "found (via syscall).\n"; |
495 | } else { |
496 | print "found.\n"; |
497 | } |
498 | } else { |
499 | print "NOT found.\n"; |
500 | } |
501 | |
502 | print "Looking for clock_getres()... "; |
503 | my $has_clock_getres; |
504 | if (exists $Config{d_clock_getres}) { |
505 | $has_clock_getres++ if $Config{d_clock_getres}; # Unlikely... |
506 | } elsif (has_clock_x('getres')) { |
507 | $has_clock_getres++; |
508 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETRES'; |
509 | } elsif (defined $SYSCALL_H && has_clock_x_syscall('getres')) { |
510 | $has_clock_getres++; |
511 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETRES -DTIME_HIRES_CLOCK_GETRES_SYSCALL'; |
512 | } |
513 | |
514 | if ($has_clock_getres) { |
515 | if ($DEFINE =~ /-DTIME_HIRES_CLOCK_GETRES_SYSCALL/) { |
516 | print "found (via syscall).\n"; |
517 | } else { |
518 | print "found.\n"; |
519 | } |
520 | } else { |
521 | print "NOT found.\n"; |
522 | } |
523 | |
4ed0e2d4 |
524 | my $has_w32api_windows_h; |
525 | if ($^O eq 'cygwin') { |
526 | print "Looking for <w32api/windows.h>... "; |
527 | if (has_include('w32api/windows.h')) { |
528 | $has_w32api_windows_h++; |
529 | $DEFINE .= ' -DHAS_W32API_WINDOWS_H'; |
530 | } |
531 | if ($has_w32api_windows_h) { |
532 | print "found.\n"; |
533 | } else { |
534 | print "NOT found.\n"; |
535 | } |
3f2ee006 |
536 | } |
537 | |
538 | if ($DEFINE) { |
539 | $DEFINE =~ s/^\s+//; |
540 | if (open(XDEFINE, ">xdefine")) { |
541 | print XDEFINE $DEFINE, "\n"; |
542 | close(XDEFINE); |
543 | } |
544 | } |
545 | } |
546 | |
547 | sub doMakefile { |
98b50af3 |
548 | my @makefileopts = (); |
3f2ee006 |
549 | |
550 | if ($] >= 5.005) { |
551 | push (@makefileopts, |
552 | 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>', |
553 | 'ABSTRACT_FROM' => 'HiRes.pm', |
554 | ); |
555 | $DEFINE .= " -DATLEASTFIVEOHOHFIVE"; |
556 | } |
557 | |
558 | push (@makefileopts, |
559 | 'NAME' => 'Time::HiRes', |
560 | 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION |
5d899d7e |
561 | 'LIBS' => $LIBS, # e.g., '-lm' |
562 | 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING' |
3f2ee006 |
563 | 'XSOPT' => $XSOPT, |
ced84e60 |
564 | # Do not even think about 'INC' => '-I/usr/ucbinclude', |
565 | # Solaris will avenge. |
5d899d7e |
566 | 'INC' => '', # e.g., '-I/usr/include/other' |
9649b81b |
567 | 'INSTALLDIRS' => ($] >= 5.008 ? 'perl' : 'site'), |
3f2ee006 |
568 | 'dist' => { |
569 | 'CI' => 'ci -l', |
5d899d7e |
570 | 'COMPRESS' => 'gzip -9f', |
3f2ee006 |
571 | 'SUFFIX' => 'gz', |
572 | }, |
573 | clean => { FILES => "xdefine" }, |
1caec985 |
574 | realclean => { FILES=> 'const-c.inc const-xs.inc' }, |
3f2ee006 |
575 | ); |
576 | |
9ac5eb64 |
577 | if ($ENV{PERL_CORE}) { |
578 | push @makefileopts, MAN3PODS => {}; |
579 | } |
580 | |
3f2ee006 |
581 | WriteMakefile(@makefileopts); |
582 | } |
583 | |
98b50af3 |
584 | sub doConstants { |
585 | if (eval {require ExtUtils::Constant; 1}) { |
ced84e60 |
586 | my @names = (qw(CLOCK_HIGHRES CLOCK_MONOTONIC |
587 | CLOCK_PROCESS_CPUTIME_ID |
588 | CLOCK_REALTIME |
589 | CLOCK_THREAD_CPUTIME_ID |
590 | CLOCK_TIMEOFDAY |
591 | ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF |
98b50af3 |
592 | ITIMER_REALPROF)); |
593 | foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer |
ced84e60 |
594 | d_nanosleep d_clock_gettime d_clock_getres)) { |
98b50af3 |
595 | my $macro = $_; |
ced84e60 |
596 | if ($macro =~ /^(d_nanosleep|d_clock_gettime|d_clock_getres)$/) { |
82cbdcc3 |
597 | $macro =~ s/^d_(.+)/TIME_HIRES_\U$1/; |
672f6857 |
598 | } else { |
82cbdcc3 |
599 | $macro =~ s/^d_(.+)/HAS_\U$1/; |
672f6857 |
600 | } |
98b50af3 |
601 | push @names, {name => $_, macro => $macro, value => 1, |
602 | default => ["IV", "0"]}; |
603 | } |
604 | ExtUtils::Constant::WriteConstants( |
605 | NAME => 'Time::HiRes', |
606 | NAMES => \@names, |
607 | ); |
608 | } else { |
1fbb4de4 |
609 | my $file; |
610 | foreach $file ('const-c.inc', 'const-xs.inc') { |
98b50af3 |
611 | my $fallback = File::Spec->catfile('fallback', $file); |
612 | local $/; |
613 | open IN, "<$fallback" or die "Can't open $fallback: $!"; |
614 | open OUT, ">$file" or die "Can't open $file: $!"; |
615 | print OUT <IN> or die $!; |
616 | close OUT or die "Can't close $file: $!"; |
617 | close IN or die "Can't close $fallback: $!"; |
618 | } |
619 | } |
620 | } |
3f2ee006 |
621 | |
98b50af3 |
622 | sub main { |
623 | print "Configuring Time::HiRes...\n"; |
1fbb4de4 |
624 | if ($] == 5.007002) { |
625 | die "Cannot Configure Time::HiRes for Perl $], aborting.\n"; |
626 | } |
3f2ee006 |
627 | |
628 | if ($^O =~ /Win32/i) { |
629 | $DEFINE = '-DSELECT_IS_BROKEN'; |
046e3f33 |
630 | $LIBS = []; |
3f2ee006 |
631 | } else { |
046e3f33 |
632 | init(); |
3f2ee006 |
633 | } |
3f2ee006 |
634 | doMakefile; |
98b50af3 |
635 | doConstants; |
3f2ee006 |
636 | my $make = $Config{'make'} || "make"; |
1fbb4de4 |
637 | unless (exists $ENV{PERL_CORE} && $ENV{PERL_CORE}) { |
3f2ee006 |
638 | print <<EOM; |
3f2ee006 |
639 | Now you may issue '$make'. Do not forget also '$make test'. |
dfffa540 |
640 | EOM |
1fbb4de4 |
641 | if ((exists $ENV{LC_ALL} && $ENV{LC_ALL} =~ /utf-?8/i) || |
642 | (exists $ENV{LC_CTYPE} && $ENV{LC_CTYPE} =~ /utf-?8/i) || |
643 | (exists $ENV{LANG} && $ENV{LANG} =~ /utf-?8/i)) { |
dfffa540 |
644 | print <<EOM; |
ced84e60 |
645 | NOTE: if you get an error like this (the Makefile line number may vary): |
d7358e6a |
646 | Makefile:91: *** missing separator |
1caec985 |
647 | then set the environment variable LC_ALL to "C" and retry |
648 | from scratch (re-run perl "Makefile.PL"). |
3f2ee006 |
649 | EOM |
dfffa540 |
650 | } |
3f2ee006 |
651 | } |
652 | } |
653 | |
654 | &main; |
dcf686c9 |
655 | |
3f2ee006 |
656 | # EOF |