4 use ExtUtils::MakeMaker;
7 my $VERBOSE = $ENV{VERBOSE};
12 use vars qw($self); # Used in 'sourcing' the hints.
14 my $ld_exeext = ($^O eq 'cygwin' ||
15 $^O eq 'os2' && $Config{ldflags} =~ /-Zexe\b/) ? '.exe' : '';
17 unless($ENV{PERL_CORE}) {
18 $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV;
21 # Perls 5.002 and 5.003 did not have File::Spec, fake what we need.
25 $^O =~ /mswin32|netware|djgpp/i ? '\\' :
32 my $catdir = join(my_dirsep, @_);
33 $^O eq 'VMS' ? "[$catdir]" : $catdir;
38 return join(my_dirsep, @_) unless $^O eq 'VMS';
40 return my_catdir (undef, @_) . $file;
45 $^O eq 'VMS' ? "-" : "..";
49 eval { require File::Spec };
51 *File::Spec::catdir = \&my_catdir;
52 *File::Spec::updir = \&my_updir;
53 *File::Spec::catfile = \&my_catfile;
57 # Avoid 'used only once' warnings.
58 my $nop1 = *File::Spec::catdir;
59 my $nop2 = *File::Spec::updir;
60 my $nop3 = *File::Spec::catfile;
62 # if you have 5.004_03 (and some slightly older versions?), xsubpp
63 # tries to generate line numbers in the C code generated from the .xs.
64 # unfortunately, it is a little buggy around #ifdef'd code.
65 # my choice is leave it in and have people with old perls complain
66 # about the "Usage" bug, or leave it out and be unable to compile myself
67 # without changing it, and then I'd always forget to change it before a
68 # release. Sorry, Edward :)
70 sub try_compile_and_link {
77 my $obj_ext = $Config{obj_ext} || ".o";
78 unlink("$tmp.c", "$tmp$obj_ext");
80 if (open(TMPC, ">$tmp.c")) {
84 my $cccmd = $args{cccmd};
90 if ($ENV{PERL_CORE}) {
91 my $updir = File::Spec->updir;
92 $COREincdir = File::Spec->catdir(($updir) x 3);
94 $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE');
97 my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir";
100 if ($ENV{PERL_CORE}) {
101 # Fragile if the extensions change hierachy within
102 # the Perl core but this should do for now.
103 $cccmd = "$Config{'cc'} /include=([---]) $tmp.c";
105 my $perl_core = $Config{'installarchlib'};
106 $perl_core =~ s/\]$/.CORE]/;
107 $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
111 if ($args{silent} || !$VERBOSE) {
112 $errornull = "2>/dev/null" unless defined $errornull;
117 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
118 unless defined $cccmd;
121 open( CMDFILE, ">$tmp.com" );
122 print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
123 print CMDFILE "\$ $cccmd\n";
124 print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
126 system("\@ $tmp.com");
128 for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
134 my $tmp_exe = "$tmp$ld_exeext";
135 printf "cccmd = $cccmd\n" if $VERBOSE;
136 my $res = system($cccmd);
137 $ok = defined($res) && $res==0 && -s $tmp_exe && -x _;
138 unlink("$tmp.c", $tmp_exe);
145 sub has_gettimeofday {
146 # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
147 return 0 if $Config{d_gettimeod} eq 'define';
148 return 1 if try_compile_and_link(<<EOM);
153 # include <sys/types.h>
157 # include <sys/time.h>
161 # include <sys/select.h> /* struct timeval might be hidden in here */
166 gettimeofday(&tv, 0);
168 int main _((int argc, char** argv, char** env))
180 try_compile_and_link(<<EOM, %args);
190 # include <sys/types.h>
194 # include <sys/time.h>
197 int main _((int argc, char** argv, char** env))
208 try_compile_and_link(<<EOM);
214 int main _((int argc, char** argv, char** env))
223 my $hints = File::Spec->catfile("hints", "$^O.pl");
225 print "Using hints $hints...\n";
228 if (exists $self->{LIBS}) {
229 $LIBS = $self->{LIBS};
230 print "Extra libraries: @$LIBS...\n";
236 print "Looking for gettimeofday()... ";
237 my $has_gettimeofday;
238 if (exists $Config{d_gettimeod}) {
239 $has_gettimeofday++ if $Config{d_gettimeod};
240 } elsif (has_gettimeofday()) {
241 $DEFINE .= ' -DHAS_GETTIMEOFDAY';
245 if ($has_gettimeofday) {
249 Your operating system does not seem to have the gettimeofday() function.
250 (or, at least, I cannot find it)
252 There is no way Time::HiRes is going to work.
254 I am awfully sorry but I cannot go further.
256 Aborting configuration.
261 print "Looking for setitimer()... ";
263 if (exists $Config{d_setitimer}) {
264 $has_setitimer++ if $Config{d_setitimer};
265 } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
267 $DEFINE .= ' -DHAS_SETITIMER';
270 if ($has_setitimer) {
273 print "NOT found.\n";
276 print "Looking for getitimer()... ";
278 if (exists $Config{'d_getitimer'}) {
279 $has_getitimer++ if $Config{'d_getitimer'};
280 } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
282 $DEFINE .= ' -DHAS_GETITIMER';
285 if ($has_getitimer) {
288 print "NOT found.\n";
291 if ($has_setitimer && $has_getitimer) {
292 print "You have interval timers (both setitimer and getitimer).\n";
294 print "You do not have interval timers.\n";
297 print "Looking for ualarm()... ";
299 if (exists $Config{d_ualarm}) {
300 $has_ualarm++ if $Config{d_ualarm};
301 } elsif (has_x ("ualarm (0, 0)")) {
303 $DEFINE .= ' -DHAS_UALARM';
309 print "NOT found.\n";
310 if ($has_setitimer) {
311 print "But you have setitimer().\n";
312 print "We can make a Time::HiRes::ualarm().\n";
316 print "Looking for usleep()... ";
318 if (exists $Config{d_usleep}) {
319 $has_usleep++ if $Config{d_usleep};
320 } elsif (has_x ("usleep (0)")) {
322 $DEFINE .= ' -DHAS_USLEEP';
328 print "NOT found.\n";
329 print "Let's see if you have select()... ";
330 if ($Config{'d_select'} eq 'define') {
332 print "We can make a Time::HiRes::usleep().\n";
334 print "NOT found.\n";
335 print "You won't have a Time::HiRes::usleep().\n";
339 print "Looking for nanosleep()... ";
341 if (exists $Config{d_nanosleep}) {
342 if ($Config{d_nanosleep}) {
344 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
346 } elsif ($^O ne 'mpeix' && # MPE/iX falsely finds nanosleep.
347 has_x ("nanosleep (NULL, NULL)")) {
349 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
352 if ($has_nanosleep) {
354 print "You can mix subsecond sleeps with signals, if you want to.\n";
355 print "(It's still not portable, though.)\n";
357 print "NOT found.\n";
358 my $nt = ($^O eq 'os2' ? '' : 'not');
359 print "You can$nt mix subsecond sleeps with signals.\n";
360 print "(It would not be portable anyway.)\n";
363 my $has_w32api_windows_h;
364 if ($^O eq 'cygwin') {
365 print "Looking for <w32api/windows.h>... ";
366 if (has_include('w32api/windows.h')) {
367 $has_w32api_windows_h++;
368 $DEFINE .= ' -DHAS_W32API_WINDOWS_H';
370 if ($has_w32api_windows_h) {
373 print "NOT found.\n";
379 if (open(XDEFINE, ">xdefine")) {
380 print XDEFINE $DEFINE, "\n";
387 my @makefileopts = ();
391 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>',
392 'ABSTRACT_FROM' => 'HiRes.pm',
394 $DEFINE .= " -DATLEASTFIVEOHOHFIVE";
398 'NAME' => 'Time::HiRes',
399 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
400 'LIBS' => $LIBS, # e.g., '-lm'
401 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
403 # do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge.
404 'INC' => '', # e.g., '-I/usr/include/other'
405 'INSTALLDIRS' => 'perl',
408 'COMPRESS' => 'gzip -9f',
411 clean => { FILES => "xdefine" },
412 realclean => { FILES=> 'const-c.inc const-xs.inc' },
415 if ($ENV{PERL_CORE}) {
416 push @makefileopts, MAN3PODS => {};
419 WriteMakefile(@makefileopts);
423 if (eval {require ExtUtils::Constant; 1}) {
424 my @names = (qw(ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF
426 foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
429 if ($macro eq 'd_nanosleep') {
430 $macro =~ s/d_(.*)/TIME_HIRES_\U$1/;
432 $macro =~ s/d_(.*)/HAS_\U$1/;
434 push @names, {name => $_, macro => $macro, value => 1,
435 default => ["IV", "0"]};
437 ExtUtils::Constant::WriteConstants(
438 NAME => 'Time::HiRes',
443 foreach $file ('const-c.inc', 'const-xs.inc') {
444 my $fallback = File::Spec->catfile('fallback', $file);
446 open IN, "<$fallback" or die "Can't open $fallback: $!";
447 open OUT, ">$file" or die "Can't open $file: $!";
448 print OUT <IN> or die $!;
449 close OUT or die "Can't close $file: $!";
450 close IN or die "Can't close $fallback: $!";
456 print "Configuring Time::HiRes...\n";
457 if ($] == 5.007002) {
458 die "Cannot Configure Time::HiRes for Perl $], aborting.\n";
461 if ($^O =~ /Win32/i) {
462 $DEFINE = '-DSELECT_IS_BROKEN';
469 my $make = $Config{'make'} || "make";
470 unless (exists $ENV{PERL_CORE} && $ENV{PERL_CORE}) {
472 Now you may issue '$make'. Do not forget also '$make test'.
475 if ((exists $ENV{LC_ALL} && $ENV{LC_ALL} =~ /utf-?8/i) ||
476 (exists $ENV{LC_CTYPE} && $ENV{LC_CTYPE} =~ /utf-?8/i) ||
477 (exists $ENV{LANG} && $ENV{LANG} =~ /utf-?8/i)) {
479 NOTE: if you get an error like this (the line number may vary):
480 Makefile:91: *** missing separator
481 then set the environment variable LC_ALL to "C" and retry
482 from scratch (re-run perl "Makefile.PL").