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;
11 # Perls 5.002 and 5.003 did not have File::Spec, fake what we need.
13 my $VERBOSE = $ENV{VERBOSE};
17 $^O =~ /mswin32|netware|djgpp/i ? '\\' :
24 my $catdir = join(my_dirsep, @_);
25 $^O eq 'VMS' ? "[$dirsep]" : $dirsep;
30 $^O eq 'VMS' ? "-" : "..";
34 eval { require File::Spec };
36 *File::Spec::catdir = \&my_catdir;
37 *File::Spec::updir = \&my_updir;
41 # if you have 5.004_03 (and some slightly older versions?), xsubpp
42 # tries to generate line numbers in the C code generated from the .xs.
43 # unfortunately, it is a little buggy around #ifdef'd code.
44 # my choice is leave it in and have people with old perls complain
45 # about the "Usage" bug, or leave it out and be unable to compile myself
46 # without changing it, and then I'd always forget to change it before a
47 # release. Sorry, Edward :)
51 (grep(defined $_ && -d $_ && -w _,
52 ((defined $ENV{'TMPDIR'} ? $ENV{'TMPDIR'} : undef),
53 qw(/var/tmp /usr/tmp /tmp))))[0]
54 unless defined $TMPDIR;
55 $TMPDIR || die "Cannot find writable temporary directory.\n";
58 sub try_compile_and_link {
62 my ($tmp) = (($^O eq 'VMS') ? "sys\$scratch:tmp$$" : TMPDIR . '/' . "tmp$$");
65 my $obj_ext = $Config{obj_ext} || ".o";
66 unlink("$tmp.c", "$tmp$obj_ext");
68 if (open(TMPC, ">$tmp.c")) {
72 $cccmd = $args{cccmd};
77 if ($ENV{PERL_CORE}) {
78 my $updir = File::Spec->updir;
79 $COREincdir = File::Spec->catdir(($updir) x 3);
81 $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE');
83 my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir";
85 if ($ENV{PERL_CORE}) {
86 # Fragile if the extensions change hierachy within
87 # the Perl core but this should do for now.
88 $cccmd = "$Config{'cc'} /include=([---]) $tmp.c";
90 my $perl_core = $Config{'installarchlib'};
91 $perl_core =~ s/\]$/.CORE]/;
92 $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
96 if ($args{silent} || !$VERBOSE) {
97 $errornull = "2>/dev/null" unless defined $errornull;
102 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
103 unless defined $cccmd;
105 open( CMDFILE, ">$tmp.com" );
106 print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
107 print CMDFILE "\$ $cccmd\n";
108 print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
110 system("\@ $tmp.com");
112 for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
118 printf "cccmd = $cccmd\n" if $VERBOSE;
120 $ok = -s $tmp && -x _;
121 unlink("$tmp.c", $tmp);
128 sub has_gettimeofday {
129 # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
130 return 0 if $Config{'d_gettimeod'} eq 'define';
131 return 1 if try_compile_and_link(<<EOM);
136 # include <sys/types.h>
140 # include <sys/time.h>
144 # include <sys/select.h> /* struct timeval might be hidden in here */
149 gettimeofday(&tv, 0);
151 int main _((int argc, char** argv, char** env))
163 try_compile_and_link(<<EOM, %args);
173 # include <sys/types.h>
177 # include <sys/time.h>
180 int main _((int argc, char** argv, char** env))
193 # this might break the link, try it if it can't find some things you
194 # honestly think should be in there...
195 # $LIBS = ['-lucb -lbsd'];
197 # ... but ucb is poison for Solaris, and probably Linux. honest.
198 $LIBS = [] if $Config{'osname'} eq 'solaris';
199 $LIBS = [] if $Config{'osname'} eq 'linux';
200 $LIBS = ['-lm'] if $Config{'osname'} =~ /sco/i;
201 $LIBS = ['-lc'] if $Config{'osname'} =~ /dynixptx/i;
204 push @$LIBS, '-lrt' unless $Config{'osname'} =~ /irix/;
205 push @$LIBS, '-lposix4' ;
209 select(STDOUT); $| = 1;
211 print "Checking for libraries...\n";
214 print "Checking for $lib...\n";
216 if ($Config{libs} =~ /\b$lib\b/ || has_x("time(0)")) {
217 push @goodlibs, $lib;
222 "You have extra libraries: @$LIBS.\n" :
223 "You have no applicable extra libraries.\n";
226 print "Looking for gettimeofday()...\n";
227 my $has_gettimeofday;
228 if ($Config{'d_gettimeod'}) {
230 } elsif (has_gettimeofday()) {
231 $DEFINE .= ' -DHAS_GETTIMEOFDAY';
235 if ($has_gettimeofday) {
236 print "You have gettimeofday().\n\n";
239 Your operating system does not seem to have the gettimeofday() function.
240 (or, at least, I cannot find it)
242 There is no way Time::HiRes is going to work.
244 I am awfully sorry but I cannot go further.
246 Aborting configuration.
251 print "Looking for setitimer()...\n";
253 if ($Config{d_setitimer}) {
255 } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
257 $DEFINE .= ' -DHAS_SETITIMER';
260 if ($has_setitimer) {
261 print "You have setitimer().\n\n";
263 print "No setitimer().\n\n";
266 print "Looking for getitimer()...\n";
268 if ($Config{d_getitimer}) {
270 } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
272 $DEFINE .= ' -DHAS_GETITIMER';
275 if ($has_getitimer) {
276 print "You have getitimer().\n\n";
278 print "No getitimer().\n\n";
281 if ($has_setitimer && $has_getitimer) {
282 print "You have interval timers (both setitimer and setitimer).\n\n";
284 print "You do not have interval timers.\n\n";
287 print "Looking for ualarm()...\n";
289 if ($Config{d_ualarm}) {
291 } elsif (has_x ("ualarm (0, 0)")) {
293 $DEFINE .= ' -DHAS_UALARM';
297 print "You have ualarm().\n\n";
299 print "Whoops! No ualarm()!\n";
301 print "You have setitimer(); we can make a Time::HiRes::ualarm()\n\n";
303 print "We'll manage.\n\n";
307 print "Looking for usleep()...\n";
309 if ($Config{d_usleep}) {
311 } elsif (has_x ("usleep (0)")) {
313 $DEFINE .= ' -DHAS_USLEEP';
317 print "You have usleep().\n\n";
319 print "Whoops! No usleep()! Let's see if you have select().\n";
320 if ($Config{'d_select'} eq 'define') {
321 print "You have select(); we can make a Time::HiRes::usleep()\n\n";
323 print "No select(); you won't have a Time::HiRes::usleep()\n\n";
327 print "Looking for nanosleep()...\n";
329 if ($Config{d_nanosleep}) {
331 } elsif (has_x ("nanosleep (NULL, NULL)")) {
333 $DEFINE .= ' -DHAS_NANOSLEEP';
336 if ($has_nanosleep) {
337 print "You have nanosleep(). You can mix subsecond sleeps with signals.\n\n";
339 print "Whoops! No nanosleep()! You cannot mix subsecond sleeps with signals.\n";
344 if (open(XDEFINE, ">xdefine")) {
345 print XDEFINE $DEFINE, "\n";
356 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>',
357 'ABSTRACT_FROM' => 'HiRes.pm',
359 $DEFINE .= " -DATLEASTFIVEOHOHFIVE";
363 'NAME' => 'Time::HiRes',
364 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
365 'LIBS' => $LIBS, # e.g., '-lm'
366 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
368 # do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge.
369 'INC' => '', # e.g., '-I/usr/include/other'
370 'INSTALLDIRS' => 'perl',
373 'COMPRESS' => 'gzip -9f',
376 clean => { FILES => "xdefine" },
379 WriteMakefile(@makefileopts);
385 Configuring Time::HiRes...
389 if ($^O =~ /Win32/i) {
390 $DEFINE = '-DSELECT_IS_BROKEN';
397 my $make = $Config{'make'} || "make";
398 unless ($ENV{PERL_CORE}) {
403 Now you may issue '$make'. Do not forget also '$make test'.