Commit | Line | Data |
---|---|---|
5b7ea690 | 1 | |
dcf686c9 JH |
2 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence |
3 | # the contents of the Makefile that is written. | |
4 | # | |
5 | ||
5b7ea690 JH |
6 | require 5.002; |
7 | ||
8 | use Config; | |
dcf686c9 | 9 | use ExtUtils::MakeMaker; |
4ea4a029 | 10 | use strict; |
5b7ea690 JH |
11 | |
12 | my $VERBOSE = $ENV{VERBOSE}; | |
4ea4a029 JH |
13 | my $DEFINE; |
14 | my $LIBS; | |
15 | my $XSOPT; | |
16 | ||
18729d3e JH |
17 | my $ld_exeext = ($^O eq 'os2' and $Config{ldflags} =~ /-Zexe\b/) ? '.exe' : ''; |
18 | ||
18015851 JH |
19 | unless($ENV{PERL_CORE}) { |
20 | $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV; | |
1e7c5a0f JH |
21 | } |
22 | ||
4ea4a029 | 23 | # Perls 5.002 and 5.003 did not have File::Spec, fake what we need. |
5b7ea690 JH |
24 | |
25 | sub my_dirsep { | |
26 | $^O eq 'VMS' ? '.' : | |
27 | $^O =~ /mswin32|netware|djgpp/i ? '\\' : | |
28 | $^O eq 'MacOS' ? ':' | |
29 | : '/'; | |
30 | } | |
31 | ||
32 | sub my_catdir { | |
33 | shift; | |
34 | my $catdir = join(my_dirsep, @_); | |
4ea4a029 | 35 | $^O eq 'VMS' ? "[$catdir]" : $catdir; |
5b7ea690 JH |
36 | } |
37 | ||
87917fc5 JH |
38 | sub my_catfile { |
39 | shift; | |
40 | return join(my_dirsep, @_) unless $^O eq 'VMS'; | |
41 | my $file = pop; | |
42 | return my_catdir (undef, @_) . $file; | |
43 | } | |
44 | ||
5b7ea690 JH |
45 | sub my_updir { |
46 | shift; | |
47 | $^O eq 'VMS' ? "-" : ".."; | |
48 | } | |
49 | ||
50 | BEGIN { | |
51 | eval { require File::Spec }; | |
52 | if ($@) { | |
7a285505 JH |
53 | *File::Spec::catdir = \&my_catdir; |
54 | *File::Spec::updir = \&my_updir; | |
87917fc5 | 55 | *File::Spec::catfile = \&my_catfile; |
5b7ea690 JH |
56 | } |
57 | } | |
58 | ||
4ea4a029 JH |
59 | # Avoid 'used only once' warnings. |
60 | my $nop1 = *File::Spec::catdir; | |
61 | my $nop2 = *File::Spec::updir; | |
87917fc5 | 62 | my $nop3 = *File::Spec::catfile; |
4ea4a029 | 63 | |
5b7ea690 JH |
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 :) | |
71 | ||
72 | sub TMPDIR { | |
73 | my $TMPDIR = | |
74 | (grep(defined $_ && -d $_ && -w _, | |
75 | ((defined $ENV{'TMPDIR'} ? $ENV{'TMPDIR'} : undef), | |
ecde6dd6 | 76 | qw(/var/tmp /usr/tmp /tmp c:/temp))))[0]; |
5b7ea690 JH |
77 | $TMPDIR || die "Cannot find writable temporary directory.\n"; |
78 | } | |
79 | ||
80 | sub try_compile_and_link { | |
81 | my ($c, %args) = @_; | |
82 | ||
83 | my ($ok) = 0; | |
4ea4a029 | 84 | my ($tmp) = (($^O eq 'VMS') ? "sys\$scratch:tmp$$" : TMPDIR() . '/' . "tmp$$"); |
5b7ea690 JH |
85 | local(*TMPC); |
86 | ||
87 | my $obj_ext = $Config{obj_ext} || ".o"; | |
88 | unlink("$tmp.c", "$tmp$obj_ext"); | |
89 | ||
90 | if (open(TMPC, ">$tmp.c")) { | |
91 | print TMPC $c; | |
92 | close(TMPC); | |
93 | ||
4ea4a029 | 94 | my $cccmd = $args{cccmd}; |
5b7ea690 JH |
95 | |
96 | my $errornull; | |
97 | ||
98 | my $COREincdir; | |
1e7c5a0f | 99 | |
5b7ea690 JH |
100 | if ($ENV{PERL_CORE}) { |
101 | my $updir = File::Spec->updir; | |
102 | $COREincdir = File::Spec->catdir(($updir) x 3); | |
103 | } else { | |
104 | $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE'); | |
105 | } | |
1e7c5a0f | 106 | |
5b7ea690 | 107 | my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir"; |
1e7c5a0f | 108 | |
5b7ea690 JH |
109 | if ($^O eq 'VMS') { |
110 | if ($ENV{PERL_CORE}) { | |
4f4e7967 JH |
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"; | |
5b7ea690 JH |
114 | } else { |
115 | my $perl_core = $Config{'installarchlib'}; | |
116 | $perl_core =~ s/\]$/.CORE]/; | |
4ea4a029 | 117 | $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c"; |
5b7ea690 JH |
118 | } |
119 | } | |
120 | ||
121 | if ($args{silent} || !$VERBOSE) { | |
122 | $errornull = "2>/dev/null" unless defined $errornull; | |
123 | } else { | |
124 | $errornull = ''; | |
125 | } | |
126 | ||
1e7c5a0f | 127 | $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull" |
5b7ea690 | 128 | unless defined $cccmd; |
1e7c5a0f | 129 | |
5b7ea690 JH |
130 | if ($^O eq 'VMS') { |
131 | open( CMDFILE, ">$tmp.com" ); | |
132 | print CMDFILE "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n"; | |
133 | print CMDFILE "\$ $cccmd\n"; | |
4ea4a029 | 134 | print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate |
5b7ea690 JH |
135 | close CMDFILE; |
136 | system("\@ $tmp.com"); | |
137 | $ok = $?==0; | |
138 | for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") { | |
4ea4a029 | 139 | 1 while unlink $_; |
5b7ea690 JH |
140 | } |
141 | } | |
142 | else | |
143 | { | |
18729d3e | 144 | my $tmp_exe = "$tmp$ld_exeext"; |
5b7ea690 | 145 | printf "cccmd = $cccmd\n" if $VERBOSE; |
18729d3e JH |
146 | my $res = system($cccmd); |
147 | $ok = defined($res) && $res==0 && -s $tmp_exe && -x _; | |
148 | unlink("$tmp.c", $tmp_exe); | |
5b7ea690 JH |
149 | } |
150 | } | |
151 | ||
152 | $ok; | |
153 | } | |
154 | ||
155 | sub has_gettimeofday { | |
156 | # confusing but true (if condition true ==> -DHAS_GETTIMEOFDAY already) | |
157 | return 0 if $Config{'d_gettimeod'} eq 'define'; | |
4ea4a029 | 158 | return 1 if try_compile_and_link(<<EOM); |
5b7ea690 JH |
159 | #include "EXTERN.h" |
160 | #include "perl.h" | |
161 | #include "XSUB.h" | |
162 | #ifdef I_SYS_TYPES | |
163 | # include <sys/types.h> | |
164 | #endif | |
165 | ||
166 | #ifdef I_SYS_TIME | |
167 | # include <sys/time.h> | |
168 | #endif | |
169 | ||
170 | #ifdef I_SYS_SELECT | |
171 | # include <sys/select.h> /* struct timeval might be hidden in here */ | |
172 | #endif | |
173 | static int foo() | |
174 | { | |
175 | struct timeval tv; | |
176 | gettimeofday(&tv, 0); | |
177 | } | |
178 | int main _((int argc, char** argv, char** env)) | |
179 | { | |
180 | foo(); | |
181 | } | |
182 | EOM | |
183 | return 0; | |
184 | } | |
185 | ||
186 | sub has_x { | |
4ea4a029 | 187 | my ($x, %args) = @_; |
5b7ea690 JH |
188 | |
189 | return 1 if | |
190 | try_compile_and_link(<<EOM, %args); | |
191 | #include "EXTERN.h" | |
192 | #include "perl.h" | |
193 | #include "XSUB.h" | |
194 | ||
195 | #ifdef I_UNISTD | |
196 | # include <unistd.h> | |
197 | #endif | |
198 | ||
199 | #ifdef I_SYS_TYPES | |
200 | # include <sys/types.h> | |
201 | #endif | |
202 | ||
203 | #ifdef I_SYS_TIME | |
204 | # include <sys/time.h> | |
205 | #endif | |
206 | ||
207 | int main _((int argc, char** argv, char** env)) | |
208 | { | |
209 | $x; | |
210 | } | |
211 | EOM | |
212 | return 0; | |
213 | } | |
214 | ||
215 | sub unixinit { | |
216 | $DEFINE = ''; | |
217 | ||
218 | $LIBS = []; | |
219 | ||
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']; | |
223 | ||
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; | |
229 | ||
230 | # For nanosleep | |
0710cc63 JH |
231 | push @$LIBS, '-lrt' unless $Config{'osname'} =~ /^(?:irix|linux)$/; |
232 | push @$LIBS, '-lposix4'; | |
5b7ea690 JH |
233 | |
234 | my @goodlibs; | |
235 | ||
4ea4a029 JH |
236 | select(STDOUT); |
237 | $| = 1; | |
5b7ea690 JH |
238 | |
239 | print "Checking for libraries...\n"; | |
240 | my $lib; | |
241 | for $lib (@$LIBS) { | |
1e7c5a0f | 242 | print "Checking for $lib... "; |
5b7ea690 JH |
243 | $LIBS = [ $lib ]; |
244 | if ($Config{libs} =~ /\b$lib\b/ || has_x("time(0)")) { | |
245 | push @goodlibs, $lib; | |
1e7c5a0f JH |
246 | print "found.\n"; |
247 | } else { | |
248 | print "NOT found.\n"; | |
5b7ea690 JH |
249 | } |
250 | } | |
1e7c5a0f | 251 | $LIBS = [ @goodlibs ]; |
5b7ea690 JH |
252 | print @$LIBS ? |
253 | "You have extra libraries: @$LIBS.\n" : | |
254 | "You have no applicable extra libraries.\n"; | |
5b7ea690 | 255 | |
4ea4a029 | 256 | print "Looking for gettimeofday()... "; |
5b7ea690 JH |
257 | my $has_gettimeofday; |
258 | if ($Config{'d_gettimeod'}) { | |
259 | $has_gettimeofday++; | |
260 | } elsif (has_gettimeofday()) { | |
261 | $DEFINE .= ' -DHAS_GETTIMEOFDAY'; | |
262 | $has_gettimeofday++; | |
263 | } | |
264 | ||
265 | if ($has_gettimeofday) { | |
4ea4a029 | 266 | print "found.\n"; |
5b7ea690 JH |
267 | } else { |
268 | die <<EOD | |
269 | Your operating system does not seem to have the gettimeofday() function. | |
270 | (or, at least, I cannot find it) | |
271 | ||
272 | There is no way Time::HiRes is going to work. | |
273 | ||
274 | I am awfully sorry but I cannot go further. | |
275 | ||
276 | Aborting configuration. | |
277 | ||
278 | EOD | |
279 | } | |
280 | ||
4ea4a029 | 281 | print "Looking for setitimer()... "; |
5b7ea690 JH |
282 | my $has_setitimer; |
283 | if ($Config{d_setitimer}) { | |
284 | $has_setitimer++; | |
285 | } elsif (has_x("setitimer(ITIMER_REAL, 0, 0)")) { | |
286 | $has_setitimer++; | |
287 | $DEFINE .= ' -DHAS_SETITIMER'; | |
288 | } | |
289 | ||
290 | if ($has_setitimer) { | |
4ea4a029 | 291 | print "found.\n"; |
5b7ea690 | 292 | } else { |
4ea4a029 | 293 | print "NOT found.\n"; |
5b7ea690 JH |
294 | } |
295 | ||
4ea4a029 | 296 | print "Looking for getitimer()... "; |
5b7ea690 JH |
297 | my $has_getitimer; |
298 | if ($Config{d_getitimer}) { | |
299 | $has_getitimer++; | |
300 | } elsif (has_x("getitimer(ITIMER_REAL, 0)")) { | |
301 | $has_getitimer++; | |
302 | $DEFINE .= ' -DHAS_GETITIMER'; | |
303 | } | |
304 | ||
305 | if ($has_getitimer) { | |
4ea4a029 | 306 | print "found.\n"; |
5b7ea690 | 307 | } else { |
4ea4a029 | 308 | print "NOT found.\n"; |
5b7ea690 JH |
309 | } |
310 | ||
311 | if ($has_setitimer && $has_getitimer) { | |
4ea4a029 | 312 | print "You have interval timers (both setitimer and setitimer).\n"; |
5b7ea690 | 313 | } else { |
4ea4a029 | 314 | print "You do not have interval timers.\n"; |
5b7ea690 JH |
315 | } |
316 | ||
4ea4a029 JH |
317 | print "Looking for ualarm()... "; |
318 | my $has_ualarm; | |
5b7ea690 JH |
319 | if ($Config{d_ualarm}) { |
320 | $has_ualarm++; | |
321 | } elsif (has_x ("ualarm (0, 0)")) { | |
322 | $has_ualarm++; | |
323 | $DEFINE .= ' -DHAS_UALARM'; | |
324 | } | |
325 | ||
326 | if ($has_ualarm) { | |
4ea4a029 | 327 | print "found.\n"; |
5b7ea690 | 328 | } else { |
4ea4a029 JH |
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"; | |
5b7ea690 JH |
333 | } |
334 | } | |
335 | ||
4ea4a029 | 336 | print "Looking for usleep()... "; |
5b7ea690 JH |
337 | my $has_usleep; |
338 | if ($Config{d_usleep}) { | |
339 | $has_usleep++; | |
340 | } elsif (has_x ("usleep (0)")) { | |
341 | $has_usleep++; | |
342 | $DEFINE .= ' -DHAS_USLEEP'; | |
343 | } | |
344 | ||
345 | if ($has_usleep) { | |
4ea4a029 | 346 | print "found.\n"; |
5b7ea690 | 347 | } else { |
4ea4a029 JH |
348 | print "NOT found.\n"; |
349 | print "Let's see if you have select()... "; | |
5b7ea690 | 350 | if ($Config{'d_select'} eq 'define') { |
4ea4a029 JH |
351 | print "found.\n"; |
352 | print "We can make a Time::HiRes::usleep().\n"; | |
5b7ea690 | 353 | } else { |
4ea4a029 JH |
354 | print "NOT found.\n"; |
355 | print "You won't have a Time::HiRes::usleep().\n"; | |
5b7ea690 JH |
356 | } |
357 | } | |
358 | ||
4ea4a029 | 359 | print "Looking for nanosleep()... "; |
5b7ea690 JH |
360 | my $has_nanosleep; |
361 | if ($Config{d_nanosleep}) { | |
362 | $has_nanosleep++; | |
363 | } elsif (has_x ("nanosleep (NULL, NULL)")) { | |
364 | $has_nanosleep++; | |
365 | $DEFINE .= ' -DHAS_NANOSLEEP'; | |
366 | } | |
367 | ||
368 | if ($has_nanosleep) { | |
4ea4a029 JH |
369 | print "found.\n"; |
370 | print "You can mix subsecond sleeps with signals.\n"; | |
5b7ea690 | 371 | } else { |
4ea4a029 | 372 | print "NOT found.\n"; |
18729d3e JH |
373 | my $nt = ($^O eq 'os2' ? '' : 'not'); |
374 | print "You can$nt mix subsecond sleeps with signals.\n"; | |
5b7ea690 JH |
375 | } |
376 | ||
377 | if ($DEFINE) { | |
378 | $DEFINE =~ s/^\s+//; | |
379 | if (open(XDEFINE, ">xdefine")) { | |
380 | print XDEFINE $DEFINE, "\n"; | |
381 | close(XDEFINE); | |
382 | } | |
383 | } | |
384 | } | |
385 | ||
386 | sub doMakefile { | |
4ea4a029 | 387 | my @makefileopts = (); |
5b7ea690 JH |
388 | |
389 | if ($] >= 5.005) { | |
390 | push (@makefileopts, | |
391 | 'AUTHOR' => 'Jarkko Hietaniemi <jhi@iki.fi>', | |
392 | 'ABSTRACT_FROM' => 'HiRes.pm', | |
393 | ); | |
394 | $DEFINE .= " -DATLEASTFIVEOHOHFIVE"; | |
395 | } | |
396 | ||
397 | push (@makefileopts, | |
398 | 'NAME' => 'Time::HiRes', | |
399 | 'VERSION_FROM' => 'HiRes.pm', # finds $VERSION | |
400 | 'LIBS' => $LIBS, # e.g., '-lm' | |
401 | 'DEFINE' => $DEFINE, # e.g., '-DHAS_SOMETHING' | |
402 | 'XSOPT' => $XSOPT, | |
403 | # do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge. | |
404 | 'INC' => '', # e.g., '-I/usr/include/other' | |
405 | 'INSTALLDIRS' => 'perl', | |
406 | 'dist' => { | |
407 | 'CI' => 'ci -l', | |
408 | 'COMPRESS' => 'gzip -9f', | |
409 | 'SUFFIX' => 'gz', | |
410 | }, | |
411 | clean => { FILES => "xdefine" }, | |
87917fc5 | 412 | realclean => {FILES=> 'const-c.inc const-xs.inc'}, |
5b7ea690 JH |
413 | ); |
414 | ||
c0401c5d JH |
415 | if ($ENV{PERL_CORE}) { |
416 | push @makefileopts, MAN3PODS => {}; | |
417 | } | |
418 | ||
5b7ea690 JH |
419 | WriteMakefile(@makefileopts); |
420 | } | |
421 | ||
87917fc5 JH |
422 | sub doConstants { |
423 | if (eval {require ExtUtils::Constant; 1}) { | |
424 | my @names = (qw(ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF | |
425 | ITIMER_REALPROF)); | |
426 | foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer | |
427 | d_nanosleep)) { | |
428 | my $macro = $_; | |
429 | $macro =~ s/d_(.*)/HAS_\U$1/; | |
430 | push @names, {name => $_, macro => $macro, value => 1, | |
431 | default => ["IV", "0"]}; | |
432 | } | |
433 | ExtUtils::Constant::WriteConstants( | |
434 | NAME => 'Time::HiRes', | |
435 | NAMES => \@names, | |
436 | ); | |
437 | } else { | |
438 | foreach my $file ('const-c.inc', 'const-xs.inc') { | |
439 | my $fallback = File::Spec->catfile('fallback', $file); | |
440 | local $/; | |
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: $!"; | |
446 | } | |
447 | } | |
448 | } | |
449 | ||
5b7ea690 | 450 | sub main { |
4ea4a029 | 451 | print "Configuring Time::HiRes...\n"; |
5b7ea690 JH |
452 | |
453 | if ($^O =~ /Win32/i) { | |
454 | $DEFINE = '-DSELECT_IS_BROKEN'; | |
455 | $LIBS = ['']; | |
456 | } else { | |
457 | unixinit(); | |
458 | } | |
5b7ea690 | 459 | doMakefile; |
87917fc5 | 460 | doConstants; |
5b7ea690 JH |
461 | my $make = $Config{'make'} || "make"; |
462 | unless ($ENV{PERL_CORE}) { | |
463 | print <<EOM; | |
5b7ea690 | 464 | Now you may issue '$make'. Do not forget also '$make test'. |
5b7ea690 JH |
465 | EOM |
466 | } | |
467 | } | |
468 | ||
469 | &main; | |
dcf686c9 | 470 | |
5b7ea690 | 471 | # EOF |