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 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 :)
72 (grep(defined $_ && -d $_ && -w _,
73 ((defined $ENV{'TMPDIR'} ? $ENV{'TMPDIR'} : undef),
74 qw(/var/tmp /usr/tmp /tmp c:/temp))))[0];
75 $TMPDIR || die "Cannot find writable temporary directory.\n";
78 sub try_compile_and_link {
82 my ($tmp) = (($^O eq 'VMS') ? "sys\$scratch:tmp$$" : TMPDIR() . '/' . "tmp$$");
85 my $obj_ext = $Config{obj_ext} || ".o";
86 unlink("$tmp.c", "$tmp$obj_ext");
88 if (open(TMPC, ">$tmp.c")) {
92 my $cccmd = $args{cccmd};
98 if ($ENV{PERL_CORE}) {
99 my $updir = File::Spec->updir;
100 $COREincdir = File::Spec->catdir(($updir) x 3);
102 $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE');
105 my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir";
108 if ($ENV{PERL_CORE}) {
109 # Fragile if the extensions change hierachy within
110 # the Perl core but this should do for now.
111 $cccmd = "$Config{'cc'} /include=([---]) $tmp.c";
113 my $perl_core = $Config{'installarchlib'};
114 $perl_core =~ s/\]$/.CORE]/;
115 $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
119 if ($args{silent} || !$VERBOSE) {
120 $errornull = "2>/dev/null" unless defined $errornull;
125 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
126 unless defined $cccmd;
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
134 system("\@ $tmp.com");
136 for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
142 printf "cccmd = $cccmd\n" if $VERBOSE;
144 $ok = -s $tmp && -x _;
145 unlink("$tmp.c", $tmp);
152 sub has_gettimeofday {
153 # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
154 return 0 if $Config{'d_gettimeod'} eq 'define';
155 return 1 if try_compile_and_link(<<EOM);
160 # include <sys/types.h>
164 # include <sys/time.h>
168 # include <sys/select.h> /* struct timeval might be hidden in here */
173 gettimeofday(&tv, 0);
175 int main _((int argc, char** argv, char** env))
187 try_compile_and_link(<<EOM, %args);
197 # include <sys/types.h>
201 # include <sys/time.h>
204 int main _((int argc, char** argv, char** env))
217 # this might break the link, try it if it can't find some things you
218 # honestly think should be in there...
219 # $LIBS = ['-lucb -lbsd'];
221 # ... but ucb is poison for Solaris, and probably Linux. honest.
222 $LIBS = [] if $Config{'osname'} eq 'solaris';
223 $LIBS = [] if $Config{'osname'} eq 'linux';
224 $LIBS = ['-lm'] if $Config{'osname'} =~ /sco/i;
225 $LIBS = ['-lc'] if $Config{'osname'} =~ /dynixptx/i;
228 push @$LIBS, '-lrt' unless $Config{'osname'} =~ /^(?:irix|linux)$/;
229 push @$LIBS, '-lposix4';
236 print "Checking for libraries...\n";
239 print "Checking for $lib... ";
241 if ($Config{libs} =~ /\b$lib\b/ || has_x("time(0)")) {
242 push @goodlibs, $lib;
245 print "NOT found.\n";
248 $LIBS = [ @goodlibs ];
250 "You have extra libraries: @$LIBS.\n" :
251 "You have no applicable extra libraries.\n";
253 print "Looking for gettimeofday()... ";
254 my $has_gettimeofday;
255 if ($Config{'d_gettimeod'}) {
257 } elsif (has_gettimeofday()) {
258 $DEFINE .= ' -DHAS_GETTIMEOFDAY';
262 if ($has_gettimeofday) {
266 Your operating system does not seem to have the gettimeofday() function.
267 (or, at least, I cannot find it)
269 There is no way Time::HiRes is going to work.
271 I am awfully sorry but I cannot go further.
273 Aborting configuration.
278 print "Looking for setitimer()... ";
280 if ($Config{d_setitimer}) {
282 } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
284 $DEFINE .= ' -DHAS_SETITIMER';
287 if ($has_setitimer) {
290 print "NOT found.\n";
293 print "Looking for getitimer()... ";
295 if ($Config{d_getitimer}) {
297 } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
299 $DEFINE .= ' -DHAS_GETITIMER';
302 if ($has_getitimer) {
305 print "NOT found.\n";
308 if ($has_setitimer && $has_getitimer) {
309 print "You have interval timers (both setitimer and setitimer).\n";
311 print "You do not have interval timers.\n";
314 print "Looking for ualarm()... ";
316 if ($Config{d_ualarm}) {
318 } elsif (has_x ("ualarm (0, 0)")) {
320 $DEFINE .= ' -DHAS_UALARM';
326 print "NOT found.\n";
327 if ($has_setitimer) {
328 print "But you have setitimer().\n";
329 print "We can make a Time::HiRes::ualarm().\n";
333 print "Looking for usleep()... ";
335 if ($Config{d_usleep}) {
337 } elsif (has_x ("usleep (0)")) {
339 $DEFINE .= ' -DHAS_USLEEP';
345 print "NOT found.\n";
346 print "Let's see if you have select()... ";
347 if ($Config{'d_select'} eq 'define') {
349 print "We can make a Time::HiRes::usleep().\n";
351 print "NOT found.\n";
352 print "You won't have a Time::HiRes::usleep().\n";
356 print "Looking for nanosleep()... ";
358 if ($Config{d_nanosleep}) {
360 } elsif (has_x ("nanosleep (NULL, NULL)")) {
362 $DEFINE .= ' -DHAS_NANOSLEEP';
365 if ($has_nanosleep) {
367 print "You can mix subsecond sleeps with signals.\n";
369 print "NOT found.\n";
370 print "You cannot mix subsecond sleeps with signals.\n";
375 if (open(XDEFINE, ">xdefine")) {
376 print XDEFINE $DEFINE, "\n";
383 my @makefileopts = ();
387 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>',
388 'ABSTRACT_FROM' => 'HiRes.pm',
390 $DEFINE .= " -DATLEASTFIVEOHOHFIVE";
394 'NAME' => 'Time::HiRes',
395 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
396 'LIBS' => $LIBS, # e.g., '-lm'
397 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
399 # do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge.
400 'INC' => '', # e.g., '-I/usr/include/other'
401 'INSTALLDIRS' => 'perl',
404 'COMPRESS' => 'gzip -9f',
407 clean => { FILES => "xdefine" },
408 realclean => {FILES=> 'const-c.inc const-xs.inc'},
411 if ($ENV{PERL_CORE}) {
412 push @makefileopts, MAN3PODS => {};
415 WriteMakefile(@makefileopts);
419 if (eval {require ExtUtils::Constant; 1}) {
420 my @names = (qw(ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF
422 foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
425 $macro =~ s/d_(.*)/HAS_\U$1/;
426 push @names, {name => $_, macro => $macro, value => 1,
427 default => ["IV", "0"]};
429 ExtUtils::Constant::WriteConstants(
430 NAME => 'Time::HiRes',
434 foreach my $file ('const-c.inc', 'const-xs.inc') {
435 my $fallback = File::Spec->catfile('fallback', $file);
437 open IN, "<$fallback" or die "Can't open $fallback: $!";
438 open OUT, ">$file" or die "Can't open $file: $!";
439 print OUT <IN> or die $!;
440 close OUT or die "Can't close $file: $!";
441 close IN or die "Can't close $fallback: $!";
447 print "Configuring Time::HiRes...\n";
449 if ($^O =~ /Win32/i) {
450 $DEFINE = '-DSELECT_IS_BROKEN';
457 my $make = $Config{'make'} || "make";
458 unless ($ENV{PERL_CORE}) {
460 Now you may issue '$make'. Do not forget also '$make test'.