Commit | Line | Data |
3f2ee006 |
1 | |
dcf686c9 |
2 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence |
3 | # the contents of the Makefile that is written. |
4 | # |
5 | |
3f2ee006 |
6 | require 5.002; |
7 | |
8 | use Config; |
dcf686c9 |
9 | use ExtUtils::MakeMaker; |
98b50af3 |
10 | use strict; |
3f2ee006 |
11 | |
12 | my $VERBOSE = $ENV{VERBOSE}; |
98b50af3 |
13 | my $DEFINE; |
14 | my $LIBS; |
15 | my $XSOPT; |
16 | |
622913ab |
17 | my $ld_exeext = ($^O eq 'os2' and $Config{ldflags} =~ /-Zexe\b/) ? '.exe' : ''; |
18 | |
12724655 |
19 | unless($ENV{PERL_CORE}) { |
20 | $ENV{PERL_CORE} = 1 if grep { $_ eq 'PERL_CORE=1' } @ARGV; |
98b50af3 |
21 | } |
22 | |
23 | # Perls 5.002 and 5.003 did not have File::Spec, fake what we need. |
3f2ee006 |
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, @_); |
98b50af3 |
35 | $^O eq 'VMS' ? "[$catdir]" : $catdir; |
36 | } |
37 | |
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; |
3f2ee006 |
43 | } |
44 | |
45 | sub my_updir { |
46 | shift; |
47 | $^O eq 'VMS' ? "-" : ".."; |
48 | } |
49 | |
50 | BEGIN { |
51 | eval { require File::Spec }; |
52 | if ($@) { |
25ca0970 |
53 | *File::Spec::catdir = \&my_catdir; |
54 | *File::Spec::updir = \&my_updir; |
98b50af3 |
55 | *File::Spec::catfile = \&my_catfile; |
3f2ee006 |
56 | } |
57 | } |
58 | |
98b50af3 |
59 | # Avoid 'used only once' warnings. |
60 | my $nop1 = *File::Spec::catdir; |
61 | my $nop2 = *File::Spec::updir; |
62 | my $nop3 = *File::Spec::catfile; |
63 | |
3f2ee006 |
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), |
a0c8e3cf |
76 | qw(/var/tmp /usr/tmp /tmp c:/temp))))[0]; |
3f2ee006 |
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; |
98b50af3 |
84 | my ($tmp) = (($^O eq 'VMS') ? "sys\$scratch:tmp$$" : TMPDIR() . '/' . "tmp$$"); |
3f2ee006 |
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 | |
98b50af3 |
94 | my $cccmd = $args{cccmd}; |
3f2ee006 |
95 | |
96 | my $errornull; |
97 | |
98 | my $COREincdir; |
98b50af3 |
99 | |
3f2ee006 |
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 | } |
98b50af3 |
106 | |
3f2ee006 |
107 | my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir"; |
98b50af3 |
108 | |
3f2ee006 |
109 | if ($^O eq 'VMS') { |
110 | if ($ENV{PERL_CORE}) { |
6a20eacc |
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"; |
3f2ee006 |
114 | } else { |
115 | my $perl_core = $Config{'installarchlib'}; |
116 | $perl_core =~ s/\]$/.CORE]/; |
98b50af3 |
117 | $cccmd = "$Config{'cc'} /include=(perl_root:[000000],$perl_core) $tmp.c"; |
3f2ee006 |
118 | } |
119 | } |
120 | |
121 | if ($args{silent} || !$VERBOSE) { |
122 | $errornull = "2>/dev/null" unless defined $errornull; |
123 | } else { |
124 | $errornull = ''; |
125 | } |
126 | |
98b50af3 |
127 | $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c @$LIBS $errornull" |
3f2ee006 |
128 | unless defined $cccmd; |
98b50af3 |
129 | |
3f2ee006 |
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"; |
98b50af3 |
134 | print CMDFILE "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate |
3f2ee006 |
135 | close CMDFILE; |
136 | system("\@ $tmp.com"); |
137 | $ok = $?==0; |
138 | for ("$tmp.c", "$tmp$obj_ext", "$tmp.com", "$tmp$Config{exe_ext}") { |
98b50af3 |
139 | 1 while unlink $_; |
3f2ee006 |
140 | } |
141 | } |
142 | else |
143 | { |
622913ab |
144 | my $tmp_exe = "$tmp$ld_exeext"; |
3f2ee006 |
145 | printf "cccmd = $cccmd\n" if $VERBOSE; |
622913ab |
146 | my $res = system($cccmd); |
147 | $ok = defined($res) && $res==0 && -s $tmp_exe && -x _; |
148 | unlink("$tmp.c", $tmp_exe); |
3f2ee006 |
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'; |
98b50af3 |
158 | return 1 if try_compile_and_link(<<EOM); |
3f2ee006 |
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 { |
98b50af3 |
187 | my ($x, %args) = @_; |
3f2ee006 |
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 |
1a08a6ab |
231 | push @$LIBS, '-lrt' unless $Config{'osname'} =~ /^(?:irix|linux)$/; |
232 | push @$LIBS, '-lposix4'; |
3f2ee006 |
233 | |
234 | my @goodlibs; |
235 | |
98b50af3 |
236 | select(STDOUT); |
237 | $| = 1; |
3f2ee006 |
238 | |
239 | print "Checking for libraries...\n"; |
240 | my $lib; |
241 | for $lib (@$LIBS) { |
98b50af3 |
242 | print "Checking for $lib... "; |
3f2ee006 |
243 | $LIBS = [ $lib ]; |
244 | if ($Config{libs} =~ /\b$lib\b/ || has_x("time(0)")) { |
245 | push @goodlibs, $lib; |
98b50af3 |
246 | print "found.\n"; |
247 | } else { |
248 | print "NOT found.\n"; |
3f2ee006 |
249 | } |
250 | } |
98b50af3 |
251 | $LIBS = [ @goodlibs ]; |
3f2ee006 |
252 | print @$LIBS ? |
253 | "You have extra libraries: @$LIBS.\n" : |
254 | "You have no applicable extra libraries.\n"; |
3f2ee006 |
255 | |
98b50af3 |
256 | print "Looking for gettimeofday()... "; |
3f2ee006 |
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) { |
98b50af3 |
266 | print "found.\n"; |
3f2ee006 |
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 | |
98b50af3 |
281 | print "Looking for setitimer()... "; |
3f2ee006 |
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) { |
98b50af3 |
291 | print "found.\n"; |
3f2ee006 |
292 | } else { |
98b50af3 |
293 | print "NOT found.\n"; |
3f2ee006 |
294 | } |
295 | |
98b50af3 |
296 | print "Looking for getitimer()... "; |
3f2ee006 |
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) { |
98b50af3 |
306 | print "found.\n"; |
3f2ee006 |
307 | } else { |
98b50af3 |
308 | print "NOT found.\n"; |
3f2ee006 |
309 | } |
310 | |
311 | if ($has_setitimer && $has_getitimer) { |
98b50af3 |
312 | print "You have interval timers (both setitimer and setitimer).\n"; |
3f2ee006 |
313 | } else { |
98b50af3 |
314 | print "You do not have interval timers.\n"; |
3f2ee006 |
315 | } |
316 | |
98b50af3 |
317 | print "Looking for ualarm()... "; |
318 | my $has_ualarm; |
3f2ee006 |
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) { |
98b50af3 |
327 | print "found.\n"; |
3f2ee006 |
328 | } else { |
98b50af3 |
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"; |
3f2ee006 |
333 | } |
334 | } |
335 | |
98b50af3 |
336 | print "Looking for usleep()... "; |
3f2ee006 |
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) { |
98b50af3 |
346 | print "found.\n"; |
3f2ee006 |
347 | } else { |
98b50af3 |
348 | print "NOT found.\n"; |
349 | print "Let's see if you have select()... "; |
3f2ee006 |
350 | if ($Config{'d_select'} eq 'define') { |
98b50af3 |
351 | print "found.\n"; |
352 | print "We can make a Time::HiRes::usleep().\n"; |
3f2ee006 |
353 | } else { |
98b50af3 |
354 | print "NOT found.\n"; |
355 | print "You won't have a Time::HiRes::usleep().\n"; |
3f2ee006 |
356 | } |
357 | } |
358 | |
98b50af3 |
359 | print "Looking for nanosleep()... "; |
3f2ee006 |
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) { |
98b50af3 |
369 | print "found.\n"; |
370 | print "You can mix subsecond sleeps with signals.\n"; |
3f2ee006 |
371 | } else { |
98b50af3 |
372 | print "NOT found.\n"; |
622913ab |
373 | my $nt = ($^O eq 'os2' ? '' : 'not'); |
374 | print "You can$nt mix subsecond sleeps with signals.\n"; |
3f2ee006 |
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 { |
98b50af3 |
387 | my @makefileopts = (); |
3f2ee006 |
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" }, |
98b50af3 |
412 | realclean => {FILES=> 'const-c.inc const-xs.inc'}, |
3f2ee006 |
413 | ); |
414 | |
9ac5eb64 |
415 | if ($ENV{PERL_CORE}) { |
416 | push @makefileopts, MAN3PODS => {}; |
417 | } |
418 | |
3f2ee006 |
419 | WriteMakefile(@makefileopts); |
420 | } |
421 | |
98b50af3 |
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 | } |
3f2ee006 |
449 | |
98b50af3 |
450 | sub main { |
451 | print "Configuring Time::HiRes...\n"; |
3f2ee006 |
452 | |
453 | if ($^O =~ /Win32/i) { |
454 | $DEFINE = '-DSELECT_IS_BROKEN'; |
455 | $LIBS = ['']; |
456 | } else { |
457 | unixinit(); |
458 | } |
3f2ee006 |
459 | doMakefile; |
98b50af3 |
460 | doConstants; |
3f2ee006 |
461 | my $make = $Config{'make'} || "make"; |
462 | unless ($ENV{PERL_CORE}) { |
463 | print <<EOM; |
3f2ee006 |
464 | Now you may issue '$make'. Do not forget also '$make test'. |
3f2ee006 |
465 | EOM |
466 | } |
467 | } |
468 | |
469 | &main; |
dcf686c9 |
470 | |
3f2ee006 |
471 | # EOF |