-
-# See lib/ExtUtils/MakeMaker.pm for details of how to influence
-# the contents of the Makefile that is written.
-#
-
require 5.002;
use Config;
use ExtUtils::MakeMaker;
-
-# Perls 5.002 and 5.003 did not have File::Spec, fake what we need.
+use strict;
my $VERBOSE = $ENV{VERBOSE};
+my $DEFINE;
+my $LIBS = [];
+my $XSOPT;
+
+use vars qw($self); # Used in 'sourcing' the hints.
+
+my $ld_exeext = ($^O eq 'cygwin' ||
+ $^O eq 'os2' && $Config{ldflags} =~ /-Zexe\b/) ? '.exe' : '';
+
+unless($ENV{PERL_CORE}) {
+ $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV;
+}
+
+# Perls 5.002 and 5.003 did not have File::Spec, fake what we need.
sub my_dirsep {
$^O eq 'VMS' ? '.' :
sub my_catdir {
shift;
my $catdir = join(my_dirsep, @_);
- $^O eq 'VMS' ? "[$dirsep]" : $dirsep;
+ $^O eq 'VMS' ? "[$catdir]" : $catdir;
+}
+
+sub my_catfile {
+ shift;
+ return join(my_dirsep, @_) unless $^O eq 'VMS';
+ my $file = pop;
+ return my_catdir (undef, @_) . $file;
}
sub my_updir {
BEGIN {
eval { require File::Spec };
if ($@) {
- *File::Spec::catdir = \&my_catdir;
- *File::Spec::updir = \&my_updir;
+ *File::Spec::catdir = \&my_catdir;
+ *File::Spec::updir = \&my_updir;
+ *File::Spec::catfile = \&my_catfile;
}
}
+# Avoid 'used only once' warnings.
+my $nop1 = *File::Spec::catdir;
+my $nop2 = *File::Spec::updir;
+my $nop3 = *File::Spec::catfile;
+
# if you have 5.004_03 (and some slightly older versions?), xsubpp
# tries to generate line numbers in the C code generated from the .xs.
# unfortunately, it is a little buggy around #ifdef'd code.
-# my choice is leave it in and have people with old perls complain
+# my choice is leave it in and have people with old perls complain
# about the "Usage" bug, or leave it out and be unable to compile myself
-# without changing it, and then I'd always forget to change it before a
+# without changing it, and then I'd always forget to change it before a
# release. Sorry, Edward :)
-sub TMPDIR {
- my $TMPDIR =
- (grep(defined $_ && -d $_ && -w _,
- ((defined $ENV{'TMPDIR'} ? $ENV{'TMPDIR'} : undef),
- qw(/var/tmp /usr/tmp /tmp))))[0]
- unless defined $TMPDIR;
- $TMPDIR || die "Cannot find writable temporary directory.\n";
-}
-
sub try_compile_and_link {
my ($c, %args) = @_;
my ($ok) = 0;
- my ($tmp) = (($^O eq 'VMS') ? "sys\$scratch:tmp$$" : TMPDIR . '/' . "tmp$$");
+ my ($tmp) = "tmp$$";
local(*TMPC);
my $obj_ext = $Config{obj_ext} || ".o";
print TMPC $c;
close(TMPC);
- $cccmd = $args{cccmd};
+ my $cccmd = $args{cccmd};
my $errornull;
my $COREincdir;
+
if ($ENV{PERL_CORE}) {
my $updir = File::Spec->updir;
$COREincdir = File::Spec->catdir(($updir) x 3);
} else {
$COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE');
}
+
my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir";
+
if ($^O eq 'VMS') {
if ($ENV{PERL_CORE}) {
- $cccmd = "$Config{'cc'} /include=(perl_root:[000000]) $tmp.c";
+ # Fragile if the extensions change hierarchy within
+ # the Perl core but this should do for now.
+ $cccmd = "$Config{'cc'} /include=([---]) $tmp.c";
} else {
my $perl_core = $Config{'installarchlib'};
$perl_core =~ s/\]$/.CORE]/;
- $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
+ $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c";
}
}
$errornull = '';
}
- $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
+ $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull"
unless defined $cccmd;
- if ($^O eq 'VMS') {
+
+ if ($^O eq 'VMS') {
open( CMDFILE, ">$tmp.com" );
print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
print CMDFILE "\$ $cccmd\n";
- print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
+ print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
close CMDFILE;
system("\@ $tmp.com");
$ok = $?==0;
- for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
- 1 while unlink $_;
+ for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") {
+ 1 while unlink $_;
}
}
else
{
+ my $tmp_exe = "$tmp$ld_exeext";
printf "cccmd = $cccmd\n" if $VERBOSE;
- system($cccmd);
- $ok = -s $tmp && -x _;
- unlink("$tmp.c", $tmp);
+ my $res = system($cccmd);
+ $ok = defined($res) && $res==0 && -s $tmp_exe && -x _;
+
+ if ( $ok && exists $args{run} && $args{run}) {
+ my $abs_tmp_exe =
+ File::Spec->
+ catfile(File::Spec->rel2abs(File::Spec->curdir),
+ $tmp_exe);
+ printf "Running $abs_tmp_exe..." if $VERBOSE;
+ if (system($abs_tmp_exe) == 0) {
+ $ok = $? == 0;
+ } else {
+ print "system('$abs_tmp_exe') failed: $?\n";
+ }
+ }
+ unlink("$tmp.c", $tmp_exe);
}
}
-
- $ok;
+
+ return $ok;
}
sub has_gettimeofday {
# confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already)
- return 0 if $Config{'d_gettimeod'} eq 'define';
- return 1 if try_compile_and_link(<<EOM);
-#include "EXTERN.h"
-#include "perl.h"
-#include "XSUB.h"
-#ifdef I_SYS_TYPES
+ return 0 if $Config{d_gettimeod} eq 'define';
+ return 1 if try_compile_and_link(<<EOM);
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+#ifdef I_SYS_TYPES
# include <sys/types.h>
#endif
}
sub has_x {
- my ($x, %args) = @_;
+ my ($x, %args) = @_;
return 1 if
try_compile_and_link(<<EOM, %args);
return 0;
}
-sub unixinit {
- $DEFINE = '';
-
- $LIBS = [];
-
- # this might break the link, try it if it can't find some things you
- # honestly think should be in there...
- # $LIBS = ['-lucb -lbsd'];
-
- # ... but ucb is poison for Solaris, and probably Linux. honest.
- $LIBS = [] if $Config{'osname'} eq 'solaris';
- $LIBS = [] if $Config{'osname'} eq 'linux';
- $LIBS = ['-lm'] if $Config{'osname'} =~ /sco/i;
- $LIBS = ['-lc'] if $Config{'osname'} =~ /dynixptx/i;
-
- # For nanosleep
- push @$LIBS, '-lrt' unless $Config{'osname'} =~ /irix/;
- push @$LIBS, '-lposix4' ;
+sub has_nanosleep {
+ return 1 if
+ try_compile_and_link(<<EOM, run => 1);
+#include <time.h>
+#include <sys/time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+/* int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); */
+
+int main() {
+ struct timespec ts1, ts2;
+ ts1.tv_sec = 0;
+ ts1.tv_nsec = 750000000;
+ ts2.tv_sec = 0;
+ ts2.tv_nsec = 0;
+ nanosleep(&ts1, &ts2); /* E.g. in AIX nanosleep() might return ENOSYS. */
+ exit(errno);
+}
+EOM
+}
- my @goodlibs;
+sub has_include {
+ my ($inc) = @_;
+ return 1 if
+ try_compile_and_link(<<EOM);
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
- select(STDOUT); $| = 1;
+#include <$inc>
+int main _((int argc, char** argv, char** env))
+{
+ return 0;
+}
+EOM
+ return 0;
+}
- print "Checking for libraries...\n";
- my $lib;
- for $lib (@$LIBS) {
- print "Checking for $lib...\n";
- $LIBS = [ $lib ];
- if ($Config{libs} =~ /\b$lib\b/ || has_x("time(0)")) {
- push @goodlibs, $lib;
+sub init {
+ my $hints = File::Spec->catfile("hints", "$^O.pl");
+ if (-f $hints) {
+ print "Using hints $hints...\n";
+ local $self;
+ do $hints;
+ if (exists $self->{LIBS}) {
+ $LIBS = $self->{LIBS};
+ print "Extra libraries: @$LIBS...\n";
}
}
- @$LIBS = @goodlibs;
- print @$LIBS ?
- "You have extra libraries: @$LIBS.\n" :
- "You have no applicable extra libraries.\n";
- print "\n";
- print "Looking for gettimeofday()...\n";
+ $DEFINE = '';
+
+ print "Looking for gettimeofday()... ";
my $has_gettimeofday;
- if ($Config{'d_gettimeod'}) {
- $has_gettimeofday++;
+ if (exists $Config{d_gettimeod}) {
+ $has_gettimeofday++ if $Config{d_gettimeod};
} elsif (has_gettimeofday()) {
$DEFINE .= ' -DHAS_GETTIMEOFDAY';
$has_gettimeofday++;
}
if ($has_gettimeofday) {
- print "You have gettimeofday().\n\n";
+ print "found.\n";
} else {
die <<EOD
Your operating system does not seem to have the gettimeofday() function.
EOD
}
- print "Looking for setitimer()...\n";
+ print "Looking for setitimer()... ";
my $has_setitimer;
- if ($Config{d_setitimer}) {
- $has_setitimer++;
+ if (exists $Config{d_setitimer}) {
+ $has_setitimer++ if $Config{d_setitimer};
} elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) {
$has_setitimer++;
$DEFINE .= ' -DHAS_SETITIMER';
}
if ($has_setitimer) {
- print "You have setitimer().\n\n";
+ print "found.\n";
} else {
- print "No setitimer().\n\n";
+ print "NOT found.\n";
}
- print "Looking for getitimer()...\n";
+ print "Looking for getitimer()... ";
my $has_getitimer;
- if ($Config{d_getitimer}) {
- $has_getitimer++;
+ if (exists $Config{'d_getitimer'}) {
+ $has_getitimer++ if $Config{'d_getitimer'};
} elsif (has_x("getitimer(ITIMER_REAL, 0)")) {
$has_getitimer++;
$DEFINE .= ' -DHAS_GETITIMER';
}
if ($has_getitimer) {
- print "You have getitimer().\n\n";
+ print "found.\n";
} else {
- print "No getitimer().\n\n";
+ print "NOT found.\n";
}
if ($has_setitimer && $has_getitimer) {
- print "You have interval timers (both setitimer and setitimer).\n\n";
+ print "You have interval timers (both setitimer and getitimer).\n";
} else {
- print "You do not have interval timers.\n\n";
+ print "You do not have interval timers.\n";
}
- print "Looking for ualarm()...\n";
- my $has_ualarm;
- if ($Config{d_ualarm}) {
- $has_ualarm++;
+ print "Looking for ualarm()... ";
+ my $has_ualarm;
+ if (exists $Config{d_ualarm}) {
+ $has_ualarm++ if $Config{d_ualarm};
} elsif (has_x ("ualarm (0, 0)")) {
$has_ualarm++;
$DEFINE .= ' -DHAS_UALARM';
}
if ($has_ualarm) {
- print "You have ualarm().\n\n";
+ print "found.\n";
} else {
- print "Whoops! No ualarm()!\n";
- if ($setitimer) {
- print "You have setitimer(); we can make a Time::HiRes::ualarm()\n\n";
- } else {
- print "We'll manage.\n\n";
+ print "NOT found.\n";
+ if ($has_setitimer) {
+ print "But you have setitimer().\n";
+ print "We can make a Time::HiRes::ualarm().\n";
}
}
- print "Looking for usleep()...\n";
+ print "Looking for usleep()... ";
my $has_usleep;
- if ($Config{d_usleep}) {
- $has_usleep++;
+ if (exists $Config{d_usleep}) {
+ $has_usleep++ if $Config{d_usleep};
} elsif (has_x ("usleep (0)")) {
$has_usleep++;
$DEFINE .= ' -DHAS_USLEEP';
}
if ($has_usleep) {
- print "You have usleep().\n\n";
+ print "found.\n";
} else {
- print "Whoops! No usleep()! Let's see if you have select().\n";
+ print "NOT found.\n";
+ print "Let's see if you have select()... ";
if ($Config{'d_select'} eq 'define') {
- print "You have select(); we can make a Time::HiRes::usleep()\n\n";
+ print "found.\n";
+ print "We can make a Time::HiRes::usleep().\n";
} else {
- print "No select(); you won't have a Time::HiRes::usleep()\n\n";
+ print "NOT found.\n";
+ print "You won't have a Time::HiRes::usleep().\n";
}
}
- print "Looking for nanosleep()...\n";
+ print "Looking for nanosleep()... ";
my $has_nanosleep;
- if ($Config{d_nanosleep}) {
- $has_nanosleep++;
- } elsif (has_x ("nanosleep (NULL, NULL)")) {
+ if (exists $Config{d_nanosleep}) {
+ if ($Config{d_nanosleep}) {
+ $has_nanosleep++;
+ $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
+ }
+ } elsif ($^O ne 'mpeix' && # MPE/iX falsely finds nanosleep.
+ has_nanosleep()) {
$has_nanosleep++;
- $DEFINE .= ' -DHAS_NANOSLEEP';
+ $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
}
if ($has_nanosleep) {
- print "You have nanosleep(). You can mix subsecond sleeps with signals.\n\n";
+ print "found.\n";
+ print "You can mix subsecond sleeps with signals, if you want to.\n";
+ print "(It's still not portable, though.)\n";
} else {
- print "Whoops! No nanosleep()! You cannot mix subsecond sleeps with signals.\n";
+ print "NOT found.\n";
+ my $nt = ($^O eq 'os2' ? '' : 'not');
+ print "You can$nt mix subsecond sleeps with signals.\n";
+ print "(It would not be portable anyway.)\n";
+ }
+
+ my $has_w32api_windows_h;
+ if ($^O eq 'cygwin') {
+ print "Looking for <w32api/windows.h>... ";
+ if (has_include('w32api/windows.h')) {
+ $has_w32api_windows_h++;
+ $DEFINE .= ' -DHAS_W32API_WINDOWS_H';
+ }
+ if ($has_w32api_windows_h) {
+ print "found.\n";
+ } else {
+ print "NOT found.\n";
+ }
}
if ($DEFINE) {
}
sub doMakefile {
- @makefileopts = ();
+ my @makefileopts = ();
if ($] >= 5.005) {
push (@makefileopts,
push (@makefileopts,
'NAME' => 'Time::HiRes',
'VERSION_FROM' => 'HiRes.pm', # finds $VERSION
- 'LIBS' => $LIBS, # e.g., '-lm'
- 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
+ 'LIBS' => $LIBS, # e.g., '-lm'
+ 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING'
'XSOPT' => $XSOPT,
# do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge.
- 'INC' => '', # e.g., '-I/usr/include/other'
+ 'INC' => '', # e.g., '-I/usr/include/other'
'INSTALLDIRS' => 'perl',
'dist' => {
'CI' => 'ci -l',
- 'COMPRESS' => 'gzip -9f',
+ 'COMPRESS' => 'gzip -9f',
'SUFFIX' => 'gz',
},
clean => { FILES => "xdefine" },
+ realclean => { FILES=> 'const-c.inc const-xs.inc' },
);
+ if ($ENV{PERL_CORE}) {
+ push @makefileopts, MAN3PODS => {};
+ }
+
WriteMakefile(@makefileopts);
}
-sub main {
- print <<EOM;
-
-Configuring Time::HiRes...
+sub doConstants {
+ if (eval {require ExtUtils::Constant; 1}) {
+ my @names = (qw(ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF
+ ITIMER_REALPROF));
+ foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
+ d_nanosleep)) {
+ my $macro = $_;
+ if ($macro eq 'd_nanosleep') {
+ $macro =~ s/d_(.*)/TIME_HIRES_\U$1/;
+ } else {
+ $macro =~ s/d_(.*)/HAS_\U$1/;
+ }
+ push @names, {name => $_, macro => $macro, value => 1,
+ default => ["IV", "0"]};
+ }
+ ExtUtils::Constant::WriteConstants(
+ NAME => 'Time::HiRes',
+ NAMES => \@names,
+ );
+ } else {
+ my $file;
+ foreach $file ('const-c.inc', 'const-xs.inc') {
+ my $fallback = File::Spec->catfile('fallback', $file);
+ local $/;
+ open IN, "<$fallback" or die "Can't open $fallback: $!";
+ open OUT, ">$file" or die "Can't open $file: $!";
+ print OUT <IN> or die $!;
+ close OUT or die "Can't close $file: $!";
+ close IN or die "Can't close $fallback: $!";
+ }
+ }
+}
-EOM
+sub main {
+ print "Configuring Time::HiRes...\n";
+ if ($] == 5.007002) {
+ die "Cannot Configure Time::HiRes for Perl $], aborting.\n";
+ }
if ($^O =~ /Win32/i) {
$DEFINE = '-DSELECT_IS_BROKEN';
- $LIBS = [''];
+ $LIBS = [];
} else {
- unixinit();
+ init();
}
- configure;
doMakefile;
+ doConstants;
my $make = $Config{'make'} || "make";
- unless ($ENV{PERL_CORE}) {
+ unless (exists $ENV{PERL_CORE} && $ENV{PERL_CORE}) {
print <<EOM;
-
-Done configuring.
-
Now you may issue '$make'. Do not forget also '$make test'.
-
EOM
+ if ((exists $ENV{LC_ALL} && $ENV{LC_ALL} =~ /utf-?8/i) ||
+ (exists $ENV{LC_CTYPE} && $ENV{LC_CTYPE} =~ /utf-?8/i) ||
+ (exists $ENV{LANG} && $ENV{LANG} =~ /utf-?8/i)) {
+ print <<EOM;
+NOTE: if you get an error like this (the line number may vary):
+Makefile:91: *** missing separator
+then set the environment variable LC_ALL to "C" and retry
+from scratch (re-run perl "Makefile.PL").
+EOM
+ }
}
}