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 $cccmd = "$Config{'cc'} /include=(perl_root:[000000]) $tmp.c";
88 my $perl_core = $Config{'installarchlib'};
89 $perl_core =~ s/\]$/.CORE]/;
90 $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
94 if ($args{silent} || !$VERBOSE) {
95 $errornull = "2>/dev/null" unless defined $errornull;
100 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
101 unless defined $cccmd;
103 open( CMDFILE, ">$tmp.com" );
104 print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
105 print CMDFILE "\$ $cccmd\n";
106 print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
108 system("\@ $tmp.com");
110 for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
116 printf "cccmd = $cccmd\n" if $VERBOSE;
118 $ok = -s $tmp && -x _;
119 unlink("$tmp.c", $tmp);
126 sub has_gettimeofday {
127 # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
128 return 0 if $Config{'d_gettimeod'} eq 'define';
129 return 1 if try_compile_and_link(<<EOM);
134 # include <sys/types.h>
138 # include <sys/time.h>
142 # include <sys/select.h> /* struct timeval might be hidden in here */
147 gettimeofday(&tv, 0);
149 int main _((int argc, char** argv, char** env))
161 try_compile_and_link(<<EOM, %args);
171 # include <sys/types.h>
175 # include <sys/time.h>
178 int main _((int argc, char** argv, char** env))
191 # this might break the link, try it if it can't find some things you
192 # honestly think should be in there...
193 # $LIBS = ['-lucb -lbsd'];
195 # ... but ucb is poison for Solaris, and probably Linux. honest.
196 $LIBS = [] if $Config{'osname'} eq 'solaris';
197 $LIBS = [] if $Config{'osname'} eq 'linux';
198 $LIBS = ['-lm'] if $Config{'osname'} =~ /sco/i;
199 $LIBS = ['-lc'] if $Config{'osname'} =~ /dynixptx/i;
202 push @$LIBS, '-lrt' unless $Config{'osname'} =~ /irix/;
203 push @$LIBS, '-lposix4' ;
207 select(STDOUT); $| = 1;
209 print "Checking for libraries...\n";
212 print "Checking for $lib...\n";
214 if ($Config{libs} =~ /\b$lib\b/ || has_x("time(0)")) {
215 push @goodlibs, $lib;
220 "You have extra libraries: @$LIBS.\n" :
221 "You have no applicable extra libraries.\n";
224 print "Looking for gettimeofday()...\n";
225 my $has_gettimeofday;
226 if ($Config{'d_gettimeod'}) {
228 } elsif (has_gettimeofday()) {
229 $DEFINE .= ' -DHAS_GETTIMEOFDAY';
233 if ($has_gettimeofday) {
234 print "You have gettimeofday().\n\n";
237 Your operating system does not seem to have the gettimeofday() function.
238 (or, at least, I cannot find it)
240 There is no way Time::HiRes is going to work.
242 I am awfully sorry but I cannot go further.
244 Aborting configuration.
249 print "Looking for setitimer()...\n";
251 if ($Config{d_setitimer}) {
253 } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
255 $DEFINE .= ' -DHAS_SETITIMER';
258 if ($has_setitimer) {
259 print "You have setitimer().\n\n";
261 print "No setitimer().\n\n";
264 print "Looking for getitimer()...\n";
266 if ($Config{d_getitimer}) {
268 } elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
270 $DEFINE .= ' -DHAS_GETITIMER';
273 if ($has_getitimer) {
274 print "You have getitimer().\n\n";
276 print "No getitimer().\n\n";
279 if ($has_setitimer && $has_getitimer) {
280 print "You have interval timers (both setitimer and setitimer).\n\n";
282 print "You do not have interval timers.\n\n";
285 print "Looking for ualarm()...\n";
287 if ($Config{d_ualarm}) {
289 } elsif (has_x ("ualarm (0, 0)")) {
291 $DEFINE .= ' -DHAS_UALARM';
295 print "You have ualarm().\n\n";
297 print "Whoops! No ualarm()!\n";
299 print "You have setitimer(); we can make a Time::HiRes::ualarm()\n\n";
301 print "We'll manage.\n\n";
305 print "Looking for usleep()...\n";
307 if ($Config{d_usleep}) {
309 } elsif (has_x ("usleep (0)")) {
311 $DEFINE .= ' -DHAS_USLEEP';
315 print "You have usleep().\n\n";
317 print "Whoops! No usleep()! Let's see if you have select().\n";
318 if ($Config{'d_select'} eq 'define') {
319 print "You have select(); we can make a Time::HiRes::usleep()\n\n";
321 print "No select(); you won't have a Time::HiRes::usleep()\n\n";
325 print "Looking for nanosleep()...\n";
327 if ($Config{d_nanosleep}) {
329 } elsif (has_x ("nanosleep (NULL, NULL)")) {
331 $DEFINE .= ' -DHAS_NANOSLEEP';
334 if ($has_nanosleep) {
335 print "You have nanosleep(). You can mix subsecond sleeps with signals.\n\n";
337 print "Whoops! No nanosleep()! You cannot mix subsecond sleeps with signals.\n";
342 if (open(XDEFINE, ">xdefine")) {
343 print XDEFINE $DEFINE, "\n";
354 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>',
355 'ABSTRACT_FROM' => 'HiRes.pm',
357 $DEFINE .= " -DATLEASTFIVEOHOHFIVE";
361 'NAME' => 'Time::HiRes',
362 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
363 'LIBS' => $LIBS, # e.g., '-lm'
364 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
366 # do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge.
367 'INC' => '', # e.g., '-I/usr/include/other'
368 'INSTALLDIRS' => 'perl',
371 'COMPRESS' => 'gzip -9f',
374 clean => { FILES => "xdefine" },
377 WriteMakefile(@makefileopts);
383 Configuring Time::HiRes...
387 if ($^O =~ /Win32/i) {
388 $DEFINE = '-DSELECT_IS_BROKEN';
395 my $make = $Config{'make'} || "make";
396 unless ($ENV{PERL_CORE}) {
401 Now you may issue '$make'. Do not forget also '$make test'.