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;
132 if ($^O eq 'mpeix') {
133 $cccmd = 'MPEAUTOCONF=1 '.$cccmd;
134 } elsif ($^O eq 'VMS') {
135 open( CMDFILE, ">$tmp.com" );
136 print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
137 print CMDFILE "\$ $cccmd\n";
138 print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
140 system("\@ $tmp.com");
142 for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
148 my $tmp_exe = "$tmp$ld_exeext";
149 printf "cccmd = $cccmd\n" if $VERBOSE;
150 my $res = system($cccmd);
151 $ok = defined($res) && $res==0 && -s $tmp_exe && -x _;
152 unlink("$tmp.c", $tmp_exe);
159 sub has_gettimeofday {
160 # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
161 return 0 if $Config{'d_gettimeod'} eq 'define';
162 return 1 if try_compile_and_link(<<EOM);
167 # include <sys/types.h>
171 # include <sys/time.h>
175 # include <sys/select.h> /* struct timeval might be hidden in here */
180 gettimeofday(&tv, 0);
182 int main _((int argc, char** argv, char** env))
194 try_compile_and_link(<<EOM, %args);
204 # include <sys/types.h>
208 # include <sys/time.h>
211 int main _((int argc, char** argv, char** env))
220 my $hints = File::Spec->catfile("hints", "$^O.pl");
222 print "Using hints $hints...\n";
225 if (exists $self->{LIBS}) {
226 $LIBS = $self->{LIBS};
227 print "Extra libraries: @$LIBS...\n";
233 print "Looking for gettimeofday()... ";
234 my $has_gettimeofday;
235 if ($Config{'d_gettimeod'}) {
237 } elsif (has_gettimeofday()) {
238 $DEFINE .= ' -DHAS_GETTIMEOFDAY';
242 if ($has_gettimeofday) {
246 Your operating system does not seem to have the gettimeofday() function.
247 (or, at least, I cannot find it)
249 There is no way Time::HiRes is going to work.
251 I am awfully sorry but I cannot go further.
253 Aborting configuration.
258 print "Looking for setitimer()... ";
260 if ($Config{d_setitimer}) {
262 } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
264 $DEFINE .= ' -DHAS_SETITIMER';
267 if ($has_setitimer) {
270 print "NOT found.\n";
273 print "Looking for getitimer()... ";
275 if ($Config{d_getitimer}) {
277 } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
279 $DEFINE .= ' -DHAS_GETITIMER';
282 if ($has_getitimer) {
285 print "NOT found.\n";
288 if ($has_setitimer && $has_getitimer) {
289 print "You have interval timers (both setitimer and setitimer).\n";
291 print "You do not have interval timers.\n";
294 print "Looking for ualarm()... ";
296 if ($Config{d_ualarm}) {
298 } elsif (has_x ("ualarm (0, 0)")) {
300 $DEFINE .= ' -DHAS_UALARM';
306 print "NOT found.\n";
307 if ($has_setitimer) {
308 print "But you have setitimer().\n";
309 print "We can make a Time::HiRes::ualarm().\n";
313 print "Looking for usleep()... ";
315 if ($Config{d_usleep}) {
317 } elsif (has_x ("usleep (0)")) {
319 $DEFINE .= ' -DHAS_USLEEP';
325 print "NOT found.\n";
326 print "Let's see if you have select()... ";
327 if ($Config{'d_select'} eq 'define') {
329 print "We can make a Time::HiRes::usleep().\n";
331 print "NOT found.\n";
332 print "You won't have a Time::HiRes::usleep().\n";
336 print "Looking for nanosleep()... ";
338 if ($Config{d_nanosleep}) {
340 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
341 } elsif (has_x ("nanosleep (NULL, NULL)")) {
343 $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
346 if ($has_nanosleep) {
348 print "You can mix subsecond sleeps with signals.\n";
350 print "NOT found.\n";
351 my $nt = ($^O eq 'os2' ? '' : 'not');
352 print "You can$nt mix subsecond sleeps with signals.\n";
357 if (open(XDEFINE, ">xdefine")) {
358 print XDEFINE $DEFINE, "\n";
365 my @makefileopts = ();
369 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>',
370 'ABSTRACT_FROM' => 'HiRes.pm',
372 $DEFINE .= " -DATLEASTFIVEOHOHFIVE";
376 'NAME' => 'Time::HiRes',
377 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
378 'LIBS' => $LIBS, # e.g., '-lm'
379 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
381 # do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge.
382 'INC' => '', # e.g., '-I/usr/include/other'
383 'INSTALLDIRS' => 'perl',
386 'COMPRESS' => 'gzip -9f',
389 clean => { FILES => "xdefine" },
390 realclean => {FILES=> 'const-c.inc const-xs.inc'},
393 if ($ENV{PERL_CORE}) {
394 push @makefileopts, MAN3PODS => {};
397 WriteMakefile(@makefileopts);
401 if (eval {require ExtUtils::Constant; 1}) {
402 my @names = (qw(ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF
404 foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
407 $macro =~ s/d_(.*)/HAS_\U$1/;
408 push @names, {name => $_, macro => $macro, value => 1,
409 default => ["IV", "0"]};
411 ExtUtils::Constant::WriteConstants(
412 NAME => 'Time::HiRes',
416 foreach my $file ('const-c.inc', 'const-xs.inc') {
417 my $fallback = File::Spec->catfile('fallback', $file);
419 open IN, "<$fallback" or die "Can't open $fallback: $!";
420 open OUT, ">$file" or die "Can't open $file: $!";
421 print OUT <IN> or die $!;
422 close OUT or die "Can't close $file: $!";
423 close IN or die "Can't close $fallback: $!";
429 print "Configuring Time::HiRes...\n";
431 if ($^O =~ /Win32/i) {
432 $DEFINE = '-DSELECT_IS_BROKEN';
439 my $make = $Config{'make'} || "make";
440 unless ($ENV{PERL_CORE}) {
442 Now you may issue '$make'. Do not forget also '$make test'.