| 1 | #!/usr/bin/perl
|
|---|
| 2 | #
|
|---|
| 3 | # In general we trust %Config, but for nanosleep() this trust
|
|---|
| 4 | # may be misplaced (it may be linkable but not really functional).
|
|---|
| 5 | # Use $ENV{FORCE_NANOSLEEP_SCAN} to force rescanning whether there
|
|---|
| 6 | # really is hope.
|
|---|
| 7 |
|
|---|
| 8 | require 5.002;
|
|---|
| 9 |
|
|---|
| 10 | use Config;
|
|---|
| 11 | use ExtUtils::MakeMaker;
|
|---|
| 12 | use strict;
|
|---|
| 13 |
|
|---|
| 14 | my $VERBOSE = $ENV{VERBOSE};
|
|---|
| 15 | my $DEFINE;
|
|---|
| 16 | my $LIBS = [];
|
|---|
| 17 | my $XSOPT = '';
|
|---|
| 18 | my $SYSCALL_H;
|
|---|
| 19 |
|
|---|
| 20 | use vars qw($self); # Used in 'sourcing' the hints.
|
|---|
| 21 |
|
|---|
| 22 | my $ld_exeext = ($^O eq 'cygwin' ||
|
|---|
| 23 | $^O eq 'os2') ? '.exe' : '';
|
|---|
| 24 |
|
|---|
| 25 | unless($ENV{PERL_CORE}) {
|
|---|
| 26 | $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | # Perls 5.002 and 5.003 did not have File::Spec, fake what we need.
|
|---|
| 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, @_);
|
|---|
| 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;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | sub my_updir {
|
|---|
| 52 | shift;
|
|---|
| 53 | $^O eq 'VMS' ? "-" : "..";
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | BEGIN {
|
|---|
| 57 | eval { require File::Spec };
|
|---|
| 58 | if ($@) {
|
|---|
| 59 | *File::Spec::catdir = \&my_catdir;
|
|---|
| 60 | *File::Spec::updir = \&my_updir;
|
|---|
| 61 | *File::Spec::catfile = \&my_catfile;
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 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 |
|
|---|
| 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.
|
|---|
| 73 | # my choice is leave it in and have people with old perls complain
|
|---|
| 74 | # about the "Usage" bug, or leave it out and be unable to compile myself
|
|---|
| 75 | # without changing it, and then I'd always forget to change it before a
|
|---|
| 76 | # release. Sorry, Edward :)
|
|---|
| 77 |
|
|---|
| 78 | sub try_compile_and_link {
|
|---|
| 79 | my ($c, %args) = @_;
|
|---|
| 80 |
|
|---|
| 81 | my ($ok) = 0;
|
|---|
| 82 | my ($tmp) = "tmp$$";
|
|---|
| 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 |
|
|---|
| 92 | my $cccmd = $args{cccmd};
|
|---|
| 93 |
|
|---|
| 94 | my $errornull;
|
|---|
| 95 |
|
|---|
| 96 | my $COREincdir;
|
|---|
| 97 |
|
|---|
| 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 | }
|
|---|
| 104 |
|
|---|
| 105 | my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir";
|
|---|
| 106 |
|
|---|
| 107 | if ($^O eq 'VMS') {
|
|---|
| 108 | if ($ENV{PERL_CORE}) {
|
|---|
| 109 | # Fragile if the extensions change hierarchy within
|
|---|
| 110 | # the Perl core but this should do for now.
|
|---|
| 111 | $cccmd = "$Config{'cc'} /include=([---]) $tmp.c";
|
|---|
| 112 | } else {
|
|---|
| 113 | my $perl_core = $Config{'installarchlib'};
|
|---|
| 114 | $perl_core =~ s/\]$/.CORE]/;
|
|---|
| 115 | $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | if ($args{silent} || !$VERBOSE) {
|
|---|
| 120 | $errornull = "2>/dev/null" unless defined $errornull;
|
|---|
| 121 | } else {
|
|---|
| 122 | $errornull = '';
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
|
|---|
| 126 | unless defined $cccmd;
|
|---|
| 127 |
|
|---|
| 128 | if ($^O eq 'VMS') {
|
|---|
| 129 | open( CMDFILE, ">$tmp.com" );
|
|---|
| 130 | print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
|
|---|
| 131 | print CMDFILE "\$ $cccmd\n";
|
|---|
| 132 | print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
|
|---|
| 133 | close CMDFILE;
|
|---|
| 134 | system("\@ $tmp.com");
|
|---|
| 135 | $ok = $?==0;
|
|---|
| 136 | for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
|
|---|
| 137 | 1 while unlink $_;
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
| 140 | else
|
|---|
| 141 | {
|
|---|
| 142 | my $tmp_exe = "$tmp$ld_exeext";
|
|---|
| 143 | printf "cccmd = $cccmd\n" if $VERBOSE;
|
|---|
| 144 | my $res = system($cccmd);
|
|---|
| 145 | $ok = defined($res) && $res == 0 && -s $tmp_exe && -x _;
|
|---|
| 146 |
|
|---|
| 147 | if ( $ok && exists $args{run} && $args{run}) {
|
|---|
| 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) {
|
|---|
| 152 | $ok = 1;
|
|---|
| 153 | } else {
|
|---|
| 154 | $ok = 0;
|
|---|
| 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
|
|---|
| 163 | }
|
|---|
| 164 | }
|
|---|
| 165 | unlink("$tmp.c", $tmp_exe);
|
|---|
| 166 | }
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | return $ok;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | sub has_gettimeofday {
|
|---|
| 173 | # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
|
|---|
| 174 | return 0 if $Config{d_gettimeod};
|
|---|
| 175 | return 1 if try_compile_and_link(<<EOM);
|
|---|
| 176 | #include "EXTERN.h"
|
|---|
| 177 | #include "perl.h"
|
|---|
| 178 | #include "XSUB.h"
|
|---|
| 179 | #ifdef I_SYS_TYPES
|
|---|
| 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 {
|
|---|
| 204 | my ($x, %args) = @_;
|
|---|
| 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 |
|
|---|
| 232 | sub has_nanosleep {
|
|---|
| 233 | print "testing... ";
|
|---|
| 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;
|
|---|
| 246 | int ret;
|
|---|
| 247 | ts1.tv_sec = 0;
|
|---|
| 248 | ts1.tv_nsec = 750000000;
|
|---|
| 249 | ts2.tv_sec = 0;
|
|---|
| 250 | ts2.tv_nsec = 0;
|
|---|
| 251 | errno = 0;
|
|---|
| 252 | ret = nanosleep(&ts1, &ts2); /* E.g. in AIX nanosleep() fails and sets errno to ENOSYS. */
|
|---|
| 253 | ret == 0 ? exit(0) : exit(errno ? errno : -1);
|
|---|
| 254 | }
|
|---|
| 255 | EOM
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 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 |
|
|---|
| 275 | sub has_clock_xxx_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_xxx {
|
|---|
| 296 | my $xxx = 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_$xxx(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 |
|
|---|
| 312 | sub has_clock {
|
|---|
| 313 | return 1 if
|
|---|
| 314 | try_compile_and_link(<<EOM, run => 1);
|
|---|
| 315 | #include "EXTERN.h"
|
|---|
| 316 | #include "perl.h"
|
|---|
| 317 | #include "XSUB.h"
|
|---|
| 318 | int main _((int argc, char** argv, char** env))
|
|---|
| 319 | {
|
|---|
| 320 | clock_t tictoc;
|
|---|
| 321 | clock_t ret = clock();
|
|---|
| 322 | ret == (clock_t)-1 ? exit(errno ? errno : -1) : exit(0);
|
|---|
| 323 | }
|
|---|
| 324 | EOM
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | sub has_clock_nanosleep {
|
|---|
| 328 | return 1 if
|
|---|
| 329 | try_compile_and_link(<<EOM, run => 1);
|
|---|
| 330 | #include "EXTERN.h"
|
|---|
| 331 | #include "perl.h"
|
|---|
| 332 | #include "XSUB.h"
|
|---|
| 333 | int main _((int argc, char** argv, char** env))
|
|---|
| 334 | {
|
|---|
| 335 | int ret;
|
|---|
| 336 | struct timerspec ts1;
|
|---|
| 337 | struct timerspec ts2;
|
|---|
| 338 | ts1.tv_sec = 0;
|
|---|
| 339 | ts1.tv_nsec = 750000000;;
|
|---|
| 340 | ret = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts1, &ts2);
|
|---|
| 341 | ret == 0 ? exit(0) : exit(errno ? errno : -1);
|
|---|
| 342 | }
|
|---|
| 343 | EOM
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | sub init {
|
|---|
| 347 | my $hints = File::Spec->catfile("hints", "$^O.pl");
|
|---|
| 348 | if (-f $hints) {
|
|---|
| 349 | print "Using hints $hints...\n";
|
|---|
| 350 | local $self;
|
|---|
| 351 | do $hints;
|
|---|
| 352 | if (exists $self->{LIBS}) {
|
|---|
| 353 | $LIBS = $self->{LIBS};
|
|---|
| 354 | print "Extra libraries: @$LIBS...\n";
|
|---|
| 355 | }
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | $DEFINE = '';
|
|---|
| 359 |
|
|---|
| 360 | if ($Config{d_syscall}) {
|
|---|
| 361 | print "Have syscall()... looking for syscall.h... ";
|
|---|
| 362 | if (has_include('syscall.h')) {
|
|---|
| 363 | $SYSCALL_H = 'syscall.h';
|
|---|
| 364 | } elsif (has_include('sys/syscall.h')) {
|
|---|
| 365 | $SYSCALL_H = 'sys/syscall.h';
|
|---|
| 366 | }
|
|---|
| 367 | } else {
|
|---|
| 368 | print "No syscall()...\n";
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | if ($Config{d_syscall}) {
|
|---|
| 372 | if (defined $SYSCALL_H) {
|
|---|
| 373 | print "found <$SYSCALL_H>.\n";
|
|---|
| 374 | } else {
|
|---|
| 375 | print "NOT found.\n";
|
|---|
| 376 | }
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | print "Looking for gettimeofday()... ";
|
|---|
| 380 | my $has_gettimeofday;
|
|---|
| 381 | if (exists $Config{d_gettimeod}) {
|
|---|
| 382 | $has_gettimeofday++ if $Config{d_gettimeod};
|
|---|
| 383 | } elsif (has_gettimeofday()) {
|
|---|
| 384 | $DEFINE .= ' -DHAS_GETTIMEOFDAY';
|
|---|
| 385 | $has_gettimeofday++;
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | if ($has_gettimeofday) {
|
|---|
| 389 | print "found.\n";
|
|---|
| 390 | } else {
|
|---|
| 391 | die <<EOD
|
|---|
| 392 | Your operating system does not seem to have the gettimeofday() function.
|
|---|
| 393 | (or, at least, I cannot find it)
|
|---|
| 394 |
|
|---|
| 395 | There is no way Time::HiRes is going to work.
|
|---|
| 396 |
|
|---|
| 397 | I am awfully sorry but I cannot go further.
|
|---|
| 398 |
|
|---|
| 399 | Aborting configuration.
|
|---|
| 400 |
|
|---|
| 401 | EOD
|
|---|
| 402 | }
|
|---|
| 403 |
|
|---|
| 404 | print "Looking for setitimer()... ";
|
|---|
| 405 | my $has_setitimer;
|
|---|
| 406 | if (exists $Config{d_setitimer}) {
|
|---|
| 407 | $has_setitimer++ if $Config{d_setitimer};
|
|---|
| 408 | } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
|
|---|
| 409 | $has_setitimer++;
|
|---|
| 410 | $DEFINE .= ' -DHAS_SETITIMER';
|
|---|
| 411 | }
|
|---|
| 412 |
|
|---|
| 413 | if ($has_setitimer) {
|
|---|
| 414 | print "found.\n";
|
|---|
| 415 | } else {
|
|---|
| 416 | print "NOT found.\n";
|
|---|
| 417 | }
|
|---|
| 418 |
|
|---|
| 419 | print "Looking for getitimer()... ";
|
|---|
| 420 | my $has_getitimer;
|
|---|
| 421 | if (exists $Config{'d_getitimer'}) {
|
|---|
| 422 | $has_getitimer++ if $Config{'d_getitimer'};
|
|---|
| 423 | } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
|
|---|
| 424 | $has_getitimer++;
|
|---|
| 425 | $DEFINE .= ' -DHAS_GETITIMER';
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | if ($has_getitimer) {
|
|---|
| 429 | print "found.\n";
|
|---|
| 430 | } else {
|
|---|
| 431 | print "NOT found.\n";
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | if ($has_setitimer && $has_getitimer) {
|
|---|
| 435 | print "You have interval timers (both setitimer and getitimer).\n";
|
|---|
| 436 | } else {
|
|---|
| 437 | print "You do not have interval timers.\n";
|
|---|
| 438 | }
|
|---|
| 439 |
|
|---|
| 440 | print "Looking for ualarm()... ";
|
|---|
| 441 | my $has_ualarm;
|
|---|
| 442 | if (exists $Config{d_ualarm}) {
|
|---|
| 443 | $has_ualarm++ if $Config{d_ualarm};
|
|---|
| 444 | } elsif (has_x ("ualarm (0, 0)")) {
|
|---|
| 445 | $has_ualarm++;
|
|---|
| 446 | $DEFINE .= ' -DHAS_UALARM';
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | if ($has_ualarm) {
|
|---|
| 450 | print "found.\n";
|
|---|
| 451 | } else {
|
|---|
| 452 | print "NOT found.\n";
|
|---|
| 453 | if ($has_setitimer) {
|
|---|
| 454 | print "But you have setitimer().\n";
|
|---|
| 455 | print "We can make a Time::HiRes::ualarm().\n";
|
|---|
| 456 | }
|
|---|
| 457 | }
|
|---|
| 458 |
|
|---|
| 459 | print "Looking for usleep()... ";
|
|---|
| 460 | my $has_usleep;
|
|---|
| 461 | if (exists $Config{d_usleep}) {
|
|---|
| 462 | $has_usleep++ if $Config{d_usleep};
|
|---|
| 463 | } elsif (has_x ("usleep (0)")) {
|
|---|
| 464 | $has_usleep++;
|
|---|
| 465 | $DEFINE .= ' -DHAS_USLEEP';
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | if ($has_usleep) {
|
|---|
| 469 | print "found.\n";
|
|---|
| 470 | } else {
|
|---|
| 471 | print "NOT found.\n";
|
|---|
| 472 | print "Let's see if you have select()... ";
|
|---|
| 473 | if ($Config{'d_select'}) {
|
|---|
| 474 | print "found.\n";
|
|---|
| 475 | print "We can make a Time::HiRes::usleep().\n";
|
|---|
| 476 | } else {
|
|---|
| 477 | print "NOT found.\n";
|
|---|
| 478 | print "You won't have a Time::HiRes::usleep().\n";
|
|---|
| 479 | }
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | print "Looking for nanosleep()... ";
|
|---|
| 483 | my $has_nanosleep;
|
|---|
| 484 | if ($ENV{FORCE_NANOSLEEP_SCAN}) {
|
|---|
| 485 | print "forced scan... ";
|
|---|
| 486 | if (has_nanosleep()) {
|
|---|
| 487 | $has_nanosleep++;
|
|---|
| 488 | $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
|
|---|
| 489 | }
|
|---|
| 490 | }
|
|---|
| 491 | elsif (exists $Config{d_nanosleep}) {
|
|---|
| 492 | print "believing \$Config{d_nanosleep}... ";
|
|---|
| 493 | if ($Config{d_nanosleep}) {
|
|---|
| 494 | $has_nanosleep++;
|
|---|
| 495 | $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
|
|---|
| 496 | }
|
|---|
| 497 | } elsif ($^O =~ /^(mpeix)$/) {
|
|---|
| 498 | # MPE/iX falsely finds nanosleep from its libc equivalent.
|
|---|
| 499 | print "skipping because in $^O... ";
|
|---|
| 500 | } else {
|
|---|
| 501 | if (has_nanosleep()) {
|
|---|
| 502 | $has_nanosleep++;
|
|---|
| 503 | $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
|
|---|
| 504 | }
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | if ($has_nanosleep) {
|
|---|
| 508 | print "found.\n";
|
|---|
| 509 | print "You can mix subsecond sleeps with signals, if you want to.\n";
|
|---|
| 510 | print "(It's still not portable, though.)\n";
|
|---|
| 511 | } else {
|
|---|
| 512 | print "NOT found.\n";
|
|---|
| 513 | my $nt = ($^O eq 'os2' ? '' : 'not');
|
|---|
| 514 | print "You can$nt mix subsecond sleeps with signals.\n";
|
|---|
| 515 | print "(It would not be portable anyway.)\n";
|
|---|
| 516 | }
|
|---|
| 517 |
|
|---|
| 518 | print "Looking for clock_gettime()... ";
|
|---|
| 519 | my $has_clock_gettime;
|
|---|
| 520 | if (exists $Config{d_clock_gettime}) {
|
|---|
| 521 | $has_clock_gettime++ if $Config{d_clock_gettime}; # Unlikely...
|
|---|
| 522 | } elsif (has_clock_xxx('gettime')) {
|
|---|
| 523 | $has_clock_gettime++;
|
|---|
| 524 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETTIME';
|
|---|
| 525 | } elsif (defined $SYSCALL_H && has_clock_xxx_syscall('gettime')) {
|
|---|
| 526 | $has_clock_gettime++;
|
|---|
| 527 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETTIME -DTIME_HIRES_CLOCK_GETTIME_SYSCALL';
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | if ($has_clock_gettime) {
|
|---|
| 531 | if ($DEFINE =~ /-DTIME_HIRES_CLOCK_GETTIME_SYSCALL/) {
|
|---|
| 532 | print "found (via syscall).\n";
|
|---|
| 533 | } else {
|
|---|
| 534 | print "found.\n";
|
|---|
| 535 | }
|
|---|
| 536 | } else {
|
|---|
| 537 | print "NOT found.\n";
|
|---|
| 538 | }
|
|---|
| 539 |
|
|---|
| 540 | print "Looking for clock_getres()... ";
|
|---|
| 541 | my $has_clock_getres;
|
|---|
| 542 | if (exists $Config{d_clock_getres}) {
|
|---|
| 543 | $has_clock_getres++ if $Config{d_clock_getres}; # Unlikely...
|
|---|
| 544 | } elsif (has_clock_xxx('getres')) {
|
|---|
| 545 | $has_clock_getres++;
|
|---|
| 546 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETRES';
|
|---|
| 547 | } elsif (defined $SYSCALL_H && has_clock_xxx_syscall('getres')) {
|
|---|
| 548 | $has_clock_getres++;
|
|---|
| 549 | $DEFINE .= ' -DTIME_HIRES_CLOCK_GETRES -DTIME_HIRES_CLOCK_GETRES_SYSCALL';
|
|---|
| 550 | }
|
|---|
| 551 |
|
|---|
| 552 | if ($has_clock_getres) {
|
|---|
| 553 | if ($DEFINE =~ /-DTIME_HIRES_CLOCK_GETRES_SYSCALL/) {
|
|---|
| 554 | print "found (via syscall).\n";
|
|---|
| 555 | } else {
|
|---|
| 556 | print "found.\n";
|
|---|
| 557 | }
|
|---|
| 558 | } else {
|
|---|
| 559 | print "NOT found.\n";
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | print "Looking for clock_nanosleep()... ";
|
|---|
| 563 | my $has_clock_nanosleep;
|
|---|
| 564 | if (exists $Config{d_clock_nanosleep}) {
|
|---|
| 565 | $has_clock_nanosleep++ if $Config{d_clock_nanosleep}; # Unlikely...
|
|---|
| 566 | } elsif (has_clock_nanosleep()) {
|
|---|
| 567 | $has_clock_nanosleep++;
|
|---|
| 568 | $DEFINE .= ' -DTIME_HIRES_CLOCK_NANOSLEEP';
|
|---|
| 569 | }
|
|---|
| 570 |
|
|---|
| 571 | if ($has_clock_nanosleep) {
|
|---|
| 572 | print "found.\n";
|
|---|
| 573 | } else {
|
|---|
| 574 | print "NOT found.\n";
|
|---|
| 575 | }
|
|---|
| 576 |
|
|---|
| 577 | print "Looking for clock()... ";
|
|---|
| 578 | my $has_clock;
|
|---|
| 579 | if (exists $Config{d_clock}) {
|
|---|
| 580 | $has_clock++ if $Config{d_clock}; # Unlikely...
|
|---|
| 581 | } elsif (has_clock()) {
|
|---|
| 582 | $has_clock++;
|
|---|
| 583 | $DEFINE .= ' -DTIME_HIRES_CLOCK';
|
|---|
| 584 | }
|
|---|
| 585 |
|
|---|
| 586 | if ($has_clock) {
|
|---|
| 587 | print "found.\n";
|
|---|
| 588 | } else {
|
|---|
| 589 | print "NOT found.\n";
|
|---|
| 590 | }
|
|---|
| 591 |
|
|---|
| 592 | my $has_w32api_windows_h;
|
|---|
| 593 |
|
|---|
| 594 | if ($^O eq 'cygwin') {
|
|---|
| 595 | print "Looking for <w32api/windows.h>... ";
|
|---|
| 596 | if (has_include('w32api/windows.h')) {
|
|---|
| 597 | $has_w32api_windows_h++;
|
|---|
| 598 | $DEFINE .= ' -DHAS_W32API_WINDOWS_H';
|
|---|
| 599 | }
|
|---|
| 600 | if ($has_w32api_windows_h) {
|
|---|
| 601 | print "found.\n";
|
|---|
| 602 | } else {
|
|---|
| 603 | print "NOT found.\n";
|
|---|
| 604 | }
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | if ($DEFINE) {
|
|---|
| 608 | $DEFINE =~ s/^\s+//;
|
|---|
| 609 | if (open(XDEFINE, ">xdefine")) {
|
|---|
| 610 | print XDEFINE $DEFINE, "\n";
|
|---|
| 611 | close(XDEFINE);
|
|---|
| 612 | }
|
|---|
| 613 | }
|
|---|
| 614 | }
|
|---|
| 615 |
|
|---|
| 616 | sub doMakefile {
|
|---|
| 617 | my @makefileopts = ();
|
|---|
| 618 |
|
|---|
| 619 | if ($] >= 5.005) {
|
|---|
| 620 | push (@makefileopts,
|
|---|
| 621 | 'AUTHOR' => 'Jarkko Hietaniemi <[email protected]>',
|
|---|
| 622 | 'ABSTRACT_FROM' => 'HiRes.pm',
|
|---|
| 623 | );
|
|---|
| 624 | $DEFINE .= " -DATLEASTFIVEOHOHFIVE";
|
|---|
| 625 | }
|
|---|
| 626 |
|
|---|
| 627 | push (@makefileopts,
|
|---|
| 628 | 'NAME' => 'Time::HiRes',
|
|---|
| 629 | 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
|
|---|
| 630 | 'LIBS' => $LIBS, # e.g., '-lm'
|
|---|
| 631 | 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
|
|---|
| 632 | 'XSOPT' => $XSOPT,
|
|---|
| 633 | # Do not even think about 'INC' => '-I/usr/ucbinclude',
|
|---|
| 634 | # Solaris will avenge.
|
|---|
| 635 | 'INC' => '', # e.g., '-I/usr/include/other'
|
|---|
| 636 | 'INSTALLDIRS' => ($] >= 5.008 ? 'perl' : 'site'),
|
|---|
| 637 | 'dist' => {
|
|---|
| 638 | 'CI' => 'ci -l',
|
|---|
| 639 | 'COMPRESS' => 'gzip -9f',
|
|---|
| 640 | 'SUFFIX' => 'gz',
|
|---|
| 641 | },
|
|---|
| 642 | clean => { FILES => "xdefine" },
|
|---|
| 643 | realclean => { FILES=> 'const-c.inc const-xs.inc' },
|
|---|
| 644 | );
|
|---|
| 645 |
|
|---|
| 646 | if ($ENV{PERL_CORE}) {
|
|---|
| 647 | push @makefileopts, MAN3PODS => {};
|
|---|
| 648 | }
|
|---|
| 649 |
|
|---|
| 650 | WriteMakefile(@makefileopts);
|
|---|
| 651 | }
|
|---|
| 652 |
|
|---|
| 653 | sub doConstants {
|
|---|
| 654 | if (eval {require ExtUtils::Constant; 1}) {
|
|---|
| 655 | my @names = (qw(CLOCK_HIGHRES CLOCK_MONOTONIC
|
|---|
| 656 | CLOCK_PROCESS_CPUTIME_ID
|
|---|
| 657 | CLOCK_REALTIME
|
|---|
| 658 | CLOCK_SOFTTIME
|
|---|
| 659 | CLOCK_THREAD_CPUTIME_ID
|
|---|
| 660 | CLOCK_TIMEOFDAY
|
|---|
| 661 | CLOCKS_PER_SEC
|
|---|
| 662 | ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF
|
|---|
| 663 | ITIMER_REALPROF
|
|---|
| 664 | TIMER_ABSTIME));
|
|---|
| 665 | foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
|
|---|
| 666 | d_nanosleep d_clock_gettime d_clock_getres
|
|---|
| 667 | d_clock d_clock_nanosleep)) {
|
|---|
| 668 | my $macro = $_;
|
|---|
| 669 | if ($macro =~ /^(d_nanosleep|d_clock_gettime|d_clock_getres|d_clock|d_clock_nanosleep)$/) {
|
|---|
| 670 | $macro =~ s/^d_(.+)/TIME_HIRES_\U$1/;
|
|---|
| 671 | } else {
|
|---|
| 672 | $macro =~ s/^d_(.+)/HAS_\U$1/;
|
|---|
| 673 | }
|
|---|
| 674 | push @names, {name => $_, macro => $macro, value => 1,
|
|---|
| 675 | default => ["IV", "0"]};
|
|---|
| 676 | }
|
|---|
| 677 | ExtUtils::Constant::WriteConstants(
|
|---|
| 678 | NAME => 'Time::HiRes',
|
|---|
| 679 | NAMES => \@names,
|
|---|
| 680 | );
|
|---|
| 681 | } else {
|
|---|
| 682 | my $file;
|
|---|
| 683 | foreach $file ('const-c.inc', 'const-xs.inc') {
|
|---|
| 684 | my $fallback = File::Spec->catfile('fallback', $file);
|
|---|
| 685 | local $/;
|
|---|
| 686 | open IN, "<$fallback" or die "Can't open $fallback: $!";
|
|---|
| 687 | open OUT, ">$file" or die "Can't open $file: $!";
|
|---|
| 688 | print OUT <IN> or die $!;
|
|---|
| 689 | close OUT or die "Can't close $file: $!";
|
|---|
| 690 | close IN or die "Can't close $fallback: $!";
|
|---|
| 691 | }
|
|---|
| 692 | }
|
|---|
| 693 | }
|
|---|
| 694 |
|
|---|
| 695 | sub main {
|
|---|
| 696 | print "Configuring Time::HiRes...\n";
|
|---|
| 697 | if ($] == 5.007002) {
|
|---|
| 698 | die "Cannot Configure Time::HiRes for Perl $], aborting.\n";
|
|---|
| 699 | }
|
|---|
| 700 |
|
|---|
| 701 | if ($^O =~ /Win32/i) {
|
|---|
| 702 | $DEFINE = '-DSELECT_IS_BROKEN';
|
|---|
| 703 | $LIBS = [];
|
|---|
| 704 | print "System is $^O, skipping full configure...\n";
|
|---|
| 705 | } else {
|
|---|
| 706 | init();
|
|---|
| 707 | }
|
|---|
| 708 | doMakefile;
|
|---|
| 709 | doConstants;
|
|---|
| 710 | my $make = $Config{'make'} || "make";
|
|---|
| 711 | unless (exists $ENV{PERL_CORE} && $ENV{PERL_CORE}) {
|
|---|
| 712 | print <<EOM;
|
|---|
| 713 | Now you may issue '$make'. Do not forget also '$make test'.
|
|---|
| 714 | EOM
|
|---|
| 715 | if ((exists $ENV{LC_ALL} && $ENV{LC_ALL} =~ /utf-?8/i) ||
|
|---|
| 716 | (exists $ENV{LC_CTYPE} && $ENV{LC_CTYPE} =~ /utf-?8/i) ||
|
|---|
| 717 | (exists $ENV{LANG} && $ENV{LANG} =~ /utf-?8/i)) {
|
|---|
| 718 | print <<EOM;
|
|---|
| 719 | NOTE: if you get an error like this (the Makefile line number may vary):
|
|---|
| 720 | Makefile:91: *** missing separator
|
|---|
| 721 | then set the environment variable LC_ALL to "C" and retry
|
|---|
| 722 | from scratch (re-run perl "Makefile.PL").
|
|---|
| 723 | EOM
|
|---|
| 724 | }
|
|---|
| 725 | }
|
|---|
| 726 | }
|
|---|
| 727 |
|
|---|
| 728 | &main;
|
|---|
| 729 |
|
|---|
| 730 | # EOF
|
|---|