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 my $ld_exeext = ($^O eq 'os2' and $Config{ldflags} =~ /-Zexe\b/) ? '.exe' : '';
19 unless($ENV{PERL_CORE}) {
20 $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV;
23 # Perls 5.002 and 5.003 did not have File::Spec, fake what we need.
27 $^O =~ /mswin32|netware|djgpp/i ? '\\' :
34 my $catdir = join(my_dirsep, @_);
35 $^O eq 'VMS' ? "[$catdir]" : $catdir;
40 return join(my_dirsep, @_) unless $^O eq 'VMS';
42 return my_catdir (undef, @_) . $file;
47 $^O eq 'VMS' ? "-" : "..";
51 eval { require File::Spec };
53 *File::Spec::catdir = \&my_catdir;
54 *File::Spec::updir = \&my_updir;
55 *File::Spec::catfile = \&my_catfile;
59 # Avoid 'used only once' warnings.
60 my $nop1 = *File::Spec::catdir;
61 my $nop2 = *File::Spec::updir;
62 my $nop3 = *File::Spec::catfile;
64 # if you have 5.004_03 (and some slightly older versions?), xsubpp
65 # tries to generate line numbers in the C code generated from the .xs.
66 # unfortunately, it is a little buggy around #ifdef'd code.
67 # my choice is leave it in and have people with old perls complain
68 # about the "Usage" bug, or leave it out and be unable to compile myself
69 # without changing it, and then I'd always forget to change it before a
70 # release. Sorry, Edward :)
74 (grep(defined $_ && -d $_ && -w _,
75 ((defined $ENV{'TMPDIR'} ? $ENV{'TMPDIR'} : undef),
76 qw(/var/tmp /usr/tmp /tmp c:/temp))))[0];
77 $TMPDIR || die "Cannot find writable temporary directory.\n";
80 sub try_compile_and_link {
84 my ($tmp) = (($^O eq 'VMS') ? "sys\$scratch:tmp$$" : TMPDIR() . '/' . "tmp$$");
87 my $obj_ext = $Config{obj_ext} || ".o";
88 unlink("$tmp.c", "$tmp$obj_ext");
90 if (open(TMPC, ">$tmp.c")) {
94 my $cccmd = $args{cccmd};
100 if ($ENV{PERL_CORE}) {
101 my $updir = File::Spec->updir;
102 $COREincdir = File::Spec->catdir(($updir) x 3);
104 $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE');
107 my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir";
110 if ($ENV{PERL_CORE}) {
111 # Fragile if the extensions change hierachy within
112 # the Perl core but this should do for now.
113 $cccmd = "$Config{'cc'} /include=([---]) $tmp.c";
115 my $perl_core = $Config{'installarchlib'};
116 $perl_core =~ s/\]$/.CORE]/;
117 $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
121 if ($args{silent} || !$VERBOSE) {
122 $errornull = "2>/dev/null" unless defined $errornull;
127 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
128 unless defined $cccmd;
131 open( CMDFILE, ">$tmp.com" );
132 print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
133 print CMDFILE "\$ $cccmd\n";
134 print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
136 system("\@ $tmp.com");
138 for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
144 my $tmp_exe = "$tmp$ld_exeext";
145 printf "cccmd = $cccmd\n" if $VERBOSE;
146 my $res = system($cccmd);
147 $ok = defined($res) && $res==0 && -s $tmp_exe && -x _;
148 unlink("$tmp.c", $tmp_exe);
155 sub has_gettimeofday {
156 # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
157 return 0 if $Config{'d_gettimeod'} eq 'define';
158 return 1 if try_compile_and_link(<<EOM);
163 # include <sys/types.h>
167 # include <sys/time.h>
171 # include <sys/select.h> /* struct timeval might be hidden in here */
176 gettimeofday(&tv, 0);
178 int main _((int argc, char** argv, char** env))
190 try_compile_and_link(<<EOM, %args);
200 # include <sys/types.h>
204 # include <sys/time.h>
207 int main _((int argc, char** argv, char** env))
220 # this might break the link, try it if it can't find some things you
221 # honestly think should be in there...
222 # $LIBS = ['-lucb -lbsd'];
224 # ... but ucb is poison for Solaris, and probably Linux. honest.
225 $LIBS = [] if $Config{'osname'} eq 'solaris';
226 $LIBS = [] if $Config{'osname'} eq 'linux';
227 $LIBS = ['-lm'] if $Config{'osname'} =~ /sco/i;
228 $LIBS = ['-lc'] if $Config{'osname'} =~ /dynixptx/i;
231 push @$LIBS, '-lrt' unless $Config{'osname'} =~ /^(?:irix|linux)$/;
232 push @$LIBS, '-lposix4';
239 print "Checking for libraries...\n";
242 print "Checking for $lib... ";
244 if ($Config{libs} =~ /\b$lib\b/ || has_x("time(0)")) {
245 push @goodlibs, $lib;
248 print "NOT found.\n";
251 $LIBS = [ @goodlibs ];
253 "You have extra libraries: @$LIBS.\n" :
254 "You have no applicable extra libraries.\n";
256 print "Looking for gettimeofday()... ";
257 my $has_gettimeofday;
258 if ($Config{'d_gettimeod'}) {
260 } elsif (has_gettimeofday()) {
261 $DEFINE .= ' -DHAS_GETTIMEOFDAY';
265 if ($has_gettimeofday) {
269 Your operating system does not seem to have the gettimeofday() function.
270 (or, at least, I cannot find it)
272 There is no way Time::HiRes is going to work.
274 I am awfully sorry but I cannot go further.
276 Aborting configuration.
281 print "Looking for setitimer()... ";
283 if ($Config{d_setitimer}) {
285 } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
287 $DEFINE .= ' -DHAS_SETITIMER';
290 if ($has_setitimer) {
293 print "NOT found.\n";
296 print "Looking for getitimer()... ";
298 if ($Config{d_getitimer}) {
300 } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
302 $DEFINE .= ' -DHAS_GETITIMER';
305 if ($has_getitimer) {
308 print "NOT found.\n";
311 if ($has_setitimer && $has_getitimer) {
312 print "You have interval timers (both setitimer and setitimer).\n";
314 print "You do not have interval timers.\n";
317 print "Looking for ualarm()... ";
319 if ($Config{d_ualarm}) {
321 } elsif (has_x ("ualarm (0, 0)")) {
323 $DEFINE .= ' -DHAS_UALARM';
329 print "NOT found.\n";
330 if ($has_setitimer) {
331 print "But you have setitimer().\n";
332 print "We can make a Time::HiRes::ualarm().\n";
336 print "Looking for usleep()... ";
338 if ($Config{d_usleep}) {
340 } elsif (has_x ("usleep (0)")) {
342 $DEFINE .= ' -DHAS_USLEEP';
348 print "NOT found.\n";
349 print "Let's see if you have select()... ";
350 if ($Config{'d_select'} eq 'define') {
352 print "We can make a Time::HiRes::usleep().\n";
354 print "NOT found.\n";
355 print "You won't have a Time::HiRes::usleep().\n";
359 print "Looking for nanosleep()... ";
361 if ($Config{d_nanosleep}) {
363 } elsif (has_x ("nanosleep (NULL, NULL)")) {
365 $DEFINE .= ' -DHAS_NANOSLEEP';
368 if ($has_nanosleep) {
370 print "You can mix subsecond sleeps with signals.\n";
372 print "NOT found.\n";
373 my $nt = ($^O eq 'os2' ? '' : 'not');
374 print "You can$nt mix subsecond sleeps with signals.\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 $macro =~ s/d_(.*)/HAS_\U$1/;
430 push @names, {name => $_, macro => $macro, value => 1,
431 default => ["IV", "0"]};
433 ExtUtils::Constant::WriteConstants(
434 NAME => 'Time::HiRes',
438 foreach my $file ('const-c.inc', 'const-xs.inc') {
439 my $fallback = File::Spec->catfile('fallback', $file);
441 open IN, "<$fallback" or die "Can't open $fallback: $!";
442 open OUT, ">$file" or die "Can't open $file: $!";
443 print OUT <IN> or die $!;
444 close OUT or die "Can't close $file: $!";
445 close IN or die "Can't close $fallback: $!";
451 print "Configuring Time::HiRes...\n";
453 if ($^O =~ /Win32/i) {
454 $DEFINE = '-DSELECT_IS_BROKEN';
461 my $make = $Config{'make'} || "make";
462 unless ($ENV{PERL_CORE}) {
464 Now you may issue '$make'. Do not forget also '$make test'.