2 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
3 # the contents of the Makefile that is written.
9 use ExtUtils::MakeMaker;
12 my $VERBOSE = $ENV{VERBOSE};
17 use vars qw($self); # Used in 'sourcing' the hints.
19 my $ld_exeext = ($^O eq 'os2' and $Config{ldflags} =~ /-Zexe\b/) ? '.exe' : '';
21 unless($ENV{PERL_CORE}) {
22 $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV;
25 # Perls 5.002 and 5.003 did not have File::Spec, fake what we need.
29 $^O =~ /mswin32|netware|djgpp/i ? '\\' :
36 my $catdir = join(my_dirsep, @_);
37 $^O eq 'VMS' ? "[$catdir]" : $catdir;
42 return join(my_dirsep, @_) unless $^O eq 'VMS';
44 return my_catdir (undef, @_) . $file;
49 $^O eq 'VMS' ? "-" : "..";
53 eval { require File::Spec };
55 *File::Spec::catdir = \&my_catdir;
56 *File::Spec::updir = \&my_updir;
57 *File::Spec::catfile = \&my_catfile;
61 # Avoid 'used only once' warnings.
62 my $nop1 = *File::Spec::catdir;
63 my $nop2 = *File::Spec::updir;
64 my $nop3 = *File::Spec::catfile;
66 # if you have 5.004_03 (and some slightly older versions?), xsubpp
67 # tries to generate line numbers in the C code generated from the .xs.
68 # unfortunately, it is a little buggy around #ifdef'd code.
69 # my choice is leave it in and have people with old perls complain
70 # about the "Usage" bug, or leave it out and be unable to compile myself
71 # without changing it, and then I'd always forget to change it before a
72 # release. Sorry, Edward :)
74 sub try_compile_and_link {
81 my $obj_ext = $Config{obj_ext} || ".o";
82 unlink("$tmp.c", "$tmp$obj_ext");
84 if (open(TMPC, ">$tmp.c")) {
88 my $cccmd = $args{cccmd};
94 if ($ENV{PERL_CORE}) {
95 my $updir = File::Spec->updir;
96 $COREincdir = File::Spec->catdir(($updir) x 3);
98 $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE');
101 my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir";
104 if ($ENV{PERL_CORE}) {
105 # Fragile if the extensions change hierachy within
106 # the Perl core but this should do for now.
107 $cccmd = "$Config{'cc'} /include=([---]) $tmp.c";
109 my $perl_core = $Config{'installarchlib'};
110 $perl_core =~ s/\]$/.CORE]/;
111 $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
115 if ($args{silent} || !$VERBOSE) {
116 $errornull = "2>/dev/null" unless defined $errornull;
121 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
122 unless defined $cccmd;
125 open( CMDFILE, ">$tmp.com" );
126 print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
127 print CMDFILE "\$ $cccmd\n";
128 print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
130 system("\@ $tmp.com");
132 for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
138 my $tmp_exe = "$tmp$ld_exeext";
139 printf "cccmd = $cccmd\n" if $VERBOSE;
140 my $res = system($cccmd);
141 $ok = defined($res) && $res==0 && -s $tmp_exe && -x _;
142 unlink("$tmp.c", $tmp_exe);
149 sub has_gettimeofday {
150 # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
151 return 0 if $Config{d_gettimeod} eq 'define';
152 return 1 if try_compile_and_link(<<EOM);
157 # include <sys/types.h>
161 # include <sys/time.h>
165 # include <sys/select.h> /* struct timeval might be hidden in here */
170 gettimeofday(&tv, 0);
172 int main _((int argc, char** argv, char** env))
184 try_compile_and_link(<<EOM, %args);
194 # include <sys/types.h>
198 # include <sys/time.h>
201 int main _((int argc, char** argv, char** env))
210 my $hints = File::Spec->catfile("hints", "$^O.pl");
212 print "Using hints $hints...\n";
215 if (exists $self->{LIBS}) {
216 $LIBS = $self->{LIBS};
217 print "Extra libraries: @$LIBS...\n";
223 print "Looking for gettimeofday()... ";
224 my $has_gettimeofday;
225 if (exists $Config{d_gettimeod}) {
226 $has_gettimeofday++ if $Config{d_gettimeod};
227 } elsif (has_gettimeofday()) {
228 $DEFINE .= ' -DHAS_GETTIMEOFDAY';
232 if ($has_gettimeofday) {
236 Your operating system does not seem to have the gettimeofday() function.
237 (or, at least, I cannot find it)
239 There is no way Time::HiRes is going to work.
241 I am awfully sorry but I cannot go further.
243 Aborting configuration.
248 print "Looking for setitimer()... ";
250 if (exists $Config{d_setitimer}) {
251 $has_setitimer++ if $Config{d_setitimer};
252 } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
254 $DEFINE .= ' -DHAS_SETITIMER';
257 if ($has_setitimer) {
260 print "NOT found.\n";
263 print "Looking for getitimer()... ";
265 if (exists $Config{'d_getitimer'}) {
266 $has_getitimer++ if $Config{'d_getitimer'};
267 } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
269 $DEFINE .= ' -DHAS_GETITIMER';
272 if ($has_getitimer) {
275 print "NOT found.\n";
278 if ($has_setitimer && $has_getitimer) {
279 print "You have interval timers (both setitimer and setitimer).\n";
281 print "You do not have interval timers.\n";
284 print "Looking for ualarm()... ";
286 if (exists $Config{d_ualarm}) {
287 $has_ualarm++ if $Config{d_ualarm};
288 } elsif (has_x ("ualarm (0, 0)")) {
290 $DEFINE .= ' -DHAS_UALARM';
296 print "NOT found.\n";
297 if ($has_setitimer) {
298 print "But you have setitimer().\n";
299 print "We can make a Time::HiRes::ualarm().\n";
303 print "Looking for usleep()... ";
305 if (exists $Config{d_usleep}) {
306 $has_usleep++ if $Config{d_usleep};
307 } elsif (has_x ("usleep (0)")) {
309 $DEFINE .= ' -DHAS_USLEEP';
315 print "NOT found.\n";
316 print "Let's see if you have select()... ";
317 if ($Config{'d_select'} eq 'define') {
319 print "We can make a Time::HiRes::usleep().\n";
321 print "NOT found.\n";
322 print "You won't have a Time::HiRes::usleep().\n";
326 print "Looking for nanosleep()... ";
328 if (exists $Config{d_nanosleep}) {
329 if ($Config{d_nanosleep}) {
331 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
333 } elsif ($^O ne 'mpeix' && # MPE/iX falsely finds nanosleep.
334 has_x ("nanosleep (NULL, NULL)")) {
336 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
339 if ($has_nanosleep) {
341 print "You can mix subsecond sleeps with signals.\n";
343 print "NOT found.\n";
344 my $nt = ($^O eq 'os2' ? '' : 'not');
345 print "You can$nt mix subsecond sleeps with signals.\n";
350 if (open(XDEFINE, ">xdefine")) {
351 print XDEFINE $DEFINE, "\n";
358 my @makefileopts = ();
362 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>',
363 'ABSTRACT_FROM' => 'HiRes.pm',
365 $DEFINE .= " -DATLEASTFIVEOHOHFIVE";
369 'NAME' => 'Time::HiRes',
370 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
371 'LIBS' => $LIBS, # e.g., '-lm'
372 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
374 # do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge.
375 'INC' => '', # e.g., '-I/usr/include/other'
376 'INSTALLDIRS' => 'perl',
379 'COMPRESS' => 'gzip -9f',
382 clean => { FILES => "xdefine" },
383 realclean => { FILES=> 'const-c.inc const-xs.inc' },
386 if ($ENV{PERL_CORE}) {
387 push @makefileopts, MAN3PODS => {};
390 WriteMakefile(@makefileopts);
394 if (eval {require ExtUtils::Constant; 1}) {
395 my @names = (qw(ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF
397 foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
400 if ($macro eq 'd_nanosleep') {
401 $macro =~ s/d_(.*)/TIME_HIRES_\U$1/;
403 $macro =~ s/d_(.*)/HAS_\U$1/;
405 push @names, {name => $_, macro => $macro, value => 1,
406 default => ["IV", "0"]};
408 ExtUtils::Constant::WriteConstants(
409 NAME => 'Time::HiRes',
413 foreach my $file ('const-c.inc', 'const-xs.inc') {
414 my $fallback = File::Spec->catfile('fallback', $file);
416 open IN, "<$fallback" or die "Can't open $fallback: $!";
417 open OUT, ">$file" or die "Can't open $file: $!";
418 print OUT <IN> or die $!;
419 close OUT or die "Can't close $file: $!";
420 close IN or die "Can't close $fallback: $!";
426 print "Configuring Time::HiRes...\n";
428 if ($^O =~ /Win32/i) {
429 $DEFINE = '-DSELECT_IS_BROKEN';
436 my $make = $Config{'make'} || "make";
437 unless ($ENV{PERL_CORE}) {
439 Now you may issue '$make'. Do not forget also '$make test'.
442 if ($ENV{LC_ALL} =~ /utf-?8/i ||
443 $ENV{LC_CTYPE} =~ /utf-?8/i ||
444 $ENV{LANG} =~ /utf-?8/i) {
446 NOTE: if you get an error like this (the line number may vary):
447 Makefile:91: *** missing separator
448 then set the environment variable LC_ALL to "C" and retry
449 from scratch (re-run perl "Makefile.PL").