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 :)
76 (grep(defined $_ && -d $_ && -w _,
77 ((defined $ENV{'TMPDIR'} ? $ENV{'TMPDIR'} : undef),
78 qw(/var/tmp /usr/tmp /tmp c:/temp))))[0];
79 $TMPDIR || die "Cannot find writable temporary directory.\n";
82 sub try_compile_and_link {
86 my ($tmp) = (($^O eq 'VMS') ? "sys\$scratch:tmp$$" : TMPDIR() . '/' . "tmp$$");
89 my $obj_ext = $Config{obj_ext} || ".o";
90 unlink("$tmp.c", "$tmp$obj_ext");
92 if (open(TMPC, ">$tmp.c")) {
96 my $cccmd = $args{cccmd};
102 if ($ENV{PERL_CORE}) {
103 my $updir = File::Spec->updir;
104 $COREincdir = File::Spec->catdir(($updir) x 3);
106 $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE');
109 my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir";
112 if ($ENV{PERL_CORE}) {
113 # Fragile if the extensions change hierachy within
114 # the Perl core but this should do for now.
115 $cccmd = "$Config{'cc'} /include=([---]) $tmp.c";
117 my $perl_core = $Config{'installarchlib'};
118 $perl_core =~ s/\]$/.CORE]/;
119 $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
123 if ($args{silent} || !$VERBOSE) {
124 $errornull = "2>/dev/null" unless defined $errornull;
129 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
130 unless defined $cccmd;
133 open( CMDFILE, ">$tmp.com" );
134 print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
135 print CMDFILE "\$ $cccmd\n";
136 print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
138 system("\@ $tmp.com");
140 for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
146 my $tmp_exe = "$tmp$ld_exeext";
147 printf "cccmd = $cccmd\n" if $VERBOSE;
148 my $res = system($cccmd);
149 $ok = defined($res) && $res==0 && -s $tmp_exe && -x _;
150 unlink("$tmp.c", $tmp_exe);
157 sub has_gettimeofday {
158 # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
159 return 0 if $Config{'d_gettimeod'} eq 'define';
160 return 1 if try_compile_and_link(<<EOM);
165 # include <sys/types.h>
169 # include <sys/time.h>
173 # include <sys/select.h> /* struct timeval might be hidden in here */
178 gettimeofday(&tv, 0);
180 int main _((int argc, char** argv, char** env))
192 try_compile_and_link(<<EOM, %args);
202 # include <sys/types.h>
206 # include <sys/time.h>
209 int main _((int argc, char** argv, char** env))
218 my $hints = File::Spec->catfile("hints", "$^O.pl");
220 print "Using hints $hints...\n";
223 if (exists $self->{LIBS}) {
224 $LIBS = $self->{LIBS};
225 print "Extra libraries: @$LIBS...\n";
231 print "Looking for gettimeofday()... ";
232 my $has_gettimeofday;
233 if ($Config{'d_gettimeod'}) {
235 } elsif (has_gettimeofday()) {
236 $DEFINE .= ' -DHAS_GETTIMEOFDAY';
240 if ($has_gettimeofday) {
244 Your operating system does not seem to have the gettimeofday() function.
245 (or, at least, I cannot find it)
247 There is no way Time::HiRes is going to work.
249 I am awfully sorry but I cannot go further.
251 Aborting configuration.
256 print "Looking for setitimer()... ";
258 if ($Config{d_setitimer}) {
260 } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
262 $DEFINE .= ' -DHAS_SETITIMER';
265 if ($has_setitimer) {
268 print "NOT found.\n";
271 print "Looking for getitimer()... ";
273 if ($Config{d_getitimer}) {
275 } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
277 $DEFINE .= ' -DHAS_GETITIMER';
280 if ($has_getitimer) {
283 print "NOT found.\n";
286 if ($has_setitimer && $has_getitimer) {
287 print "You have interval timers (both setitimer and setitimer).\n";
289 print "You do not have interval timers.\n";
292 print "Looking for ualarm()... ";
294 if ($Config{d_ualarm}) {
296 } elsif (has_x ("ualarm (0, 0)")) {
298 $DEFINE .= ' -DHAS_UALARM';
304 print "NOT found.\n";
305 if ($has_setitimer) {
306 print "But you have setitimer().\n";
307 print "We can make a Time::HiRes::ualarm().\n";
311 print "Looking for usleep()... ";
313 if ($Config{d_usleep}) {
315 } elsif (has_x ("usleep (0)")) {
317 $DEFINE .= ' -DHAS_USLEEP';
323 print "NOT found.\n";
324 print "Let's see if you have select()... ";
325 if ($Config{'d_select'} eq 'define') {
327 print "We can make a Time::HiRes::usleep().\n";
329 print "NOT found.\n";
330 print "You won't have a Time::HiRes::usleep().\n";
334 print "Looking for nanosleep()... ";
336 if ($Config{d_nanosleep}) {
338 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
339 } elsif (has_x ("nanosleep (NULL, NULL)")) {
341 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
344 if ($has_nanosleep) {
346 print "You can mix subsecond sleeps with signals.\n";
348 print "NOT found.\n";
349 my $nt = ($^O eq 'os2' ? '' : 'not');
350 print "You can$nt mix subsecond sleeps with signals.\n";
355 if (open(XDEFINE, ">xdefine")) {
356 print XDEFINE $DEFINE, "\n";
363 my @makefileopts = ();
367 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>',
368 'ABSTRACT_FROM' => 'HiRes.pm',
370 $DEFINE .= " -DATLEASTFIVEOHOHFIVE";
374 'NAME' => 'Time::HiRes',
375 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
376 'LIBS' => $LIBS, # e.g., '-lm'
377 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
379 # do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge.
380 'INC' => '', # e.g., '-I/usr/include/other'
381 'INSTALLDIRS' => 'perl',
384 'COMPRESS' => 'gzip -9f',
387 clean => { FILES => "xdefine" },
388 realclean => {FILES=> 'const-c.inc const-xs.inc'},
391 if ($ENV{PERL_CORE}) {
392 push @makefileopts, MAN3PODS => {};
395 WriteMakefile(@makefileopts);
399 if (eval {require ExtUtils::Constant; 1}) {
400 my @names = (qw(ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF
402 foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
405 $macro =~ s/d_(.*)/HAS_\U$1/;
406 push @names, {name => $_, macro => $macro, value => 1,
407 default => ["IV", "0"]};
409 ExtUtils::Constant::WriteConstants(
410 NAME => 'Time::HiRes',
414 foreach my $file ('const-c.inc', 'const-xs.inc') {
415 my $fallback = File::Spec->catfile('fallback', $file);
417 open IN, "<$fallback" or die "Can't open $fallback: $!";
418 open OUT, ">$file" or die "Can't open $file: $!";
419 print OUT <IN> or die $!;
420 close OUT or die "Can't close $file: $!";
421 close IN or die "Can't close $fallback: $!";
427 print "Configuring Time::HiRes...\n";
429 if ($^O =~ /Win32/i) {
430 $DEFINE = '-DSELECT_IS_BROKEN';
437 my $make = $Config{'make'} || "make";
438 unless ($ENV{PERL_CORE}) {
440 Now you may issue '$make'. Do not forget also '$make test'.