ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Makefile.PL
Revision: 1.73
Committed: Thu Dec 4 17:29:40 2008 UTC (15 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-5_151, rel-6_13, rel-5_161, rel-5_12, rel-5_15, rel-5_14, rel-5_16, rel-5_132, rel-5_131
Changes since 1.72: +6 -6 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 use 5.005;
2
3 use strict;
4 use ExtUtils::MakeMaker;
5 use Config;
6
7 $|=1;
8
9 my $DEFINE;
10 my @LIBS = [];
11
12 my $threads = $Config{usethreads};
13
14 print <<EOF;
15
16 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
17
18 Coro has a number of configuration options. Due to its maturity, the
19 defaults that Coro chooses are usually fine, so you can decide to skip
20 these questions. Only if something went wrong you should select 'n'
21 here and manually configure Coro, and, of course, report this to the
22 maintainer :)
23
24 EOF
25
26 if (prompt ("Skip further questions and use defaults (y/n)?", "y") =~ /[yY]/) {
27 $ENV{PERL_MM_USE_DEFAULT} = 1;
28 }
29
30
31 $DEFINE .= " -DHAVE_MMAP" if $Config{d_mmap} eq "define" && $Config{d_munmap} eq "define";
32
33 my $iface;
34
35 # default to assembly on x86 and x86_64 sometimes
36 my $iface_asm = $Config{archname} =~ /^(i[3456]86|amd64|x86_64)-/ ? "a" : undef;
37
38 if (exists $ENV{CORO_INTERFACE}) {
39 $iface = $ENV{CORO_INTERFACE};
40
41 } elsif ($^O =~ /win32/i or $^O =~ /cygwin/ or $^O =~ /mswin/) {
42 # nothing works, really, without deep hacks
43 $iface = 'w';
44
45 } elsif ($^O =~ /irix/) {
46 # sigaltstack works like sigstack, i.e. expects stack pointer, not stack base
47 # but wikipeida lists it as 100% posix compliant. geeeee.
48 $iface = "i";
49
50 } elsif ($^O =~ /linux/) {
51 # everything "just works", as expected
52 $iface = $iface_asm || "s";
53
54 } elsif ($^O =~ /freebsd/) {
55 # FreeBSD 4.x has ucontext.h but no makecontext et al. (see BUGS section of
56 # man context).
57 #
58 # FreeBSD 6.2 has marginally working ucontext, setjmp and asm, but
59 # some 5.8.8's barf when threaded due to broken threading.
60
61 $iface = $iface_asm || "s";
62
63 } elsif ($^O =~ /netbsd/) {
64 # netbsd is totally broken (pthreads are incomaptible with ucontext or
65 # other stack switching mechanisms) therefore, default to pthread -
66 # hey, it might actually work, with some hacks
67 $iface = "p";
68
69 } elsif ($^O =~ /(openbsd|mirbsd)/) {
70 # openbsd:
71 # asm seems to work, setjmp might, ucontext is missing, threads lets not talk about
72 # try setjmp/longjmp on 4.4, but pthread on earlier
73 # mirbsd:
74 # seems to be bug-to-bug compatible openbsd fork,
75 # with the name change being the biggest difference.
76 $iface = $iface_asm || ($Config{osvers} >= 4.4 ? "s" : "p");
77
78 } elsif ($^O =~ /solaris/) {
79 # setjmp, ucontext seem to work, as well as asm
80 $iface = $iface_asm || "s";
81
82 } elsif ($^O =~ /darwin/) {
83 # assembler doesn't support .type
84 # ucontext is of course totally broken (it just crashes)
85 # surprisingly, pthreads seem to work
86 $iface = "s";
87
88 } elsif ($^O =~ /dragonfly/) {
89 # ucontext is totally broken on dragonfly bsd:
90 # Fatal error 'siglongjmp()ing between thread contexts is undefined by POSIX 1003.1
91 $iface = "s";
92
93 } elsif (-e "/usr/include/ucontext.h") { # shame on this heuristic
94 $iface = "u";
95
96 } else {
97 $iface = "s";
98 }
99
100 print <<EOF;
101
102 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
103
104 Coro can use a number of methods to implement coroutines at the C
105 level. The default chosen is based on your current confguration and is
106 correct in most cases, but you still can chose between these alternatives:
107
108 u The unix 'ucontext.h' functions are relatively new and not implemented
109 or well-tested in older unices. They allow very fast coroutine creation
110 and reasonably fast switching. They are, however, usually slower than
111 the other alternatives due to an extra syscall done by swapcontext. And
112 while nominally most portable (it's the only POSIX-standardised
113 interface for coroutines), ucontext functions are, as usual, broken on
114 most/all BSDs.
115
116 s If the ucontext functions are not working or you don't want
117 to use them for other reasons you can try a workaround using
118 setjmp/longjmp/sigaltstack (also standard unix functions). Coroutine
119 creation is rather slow, but switching is very fast (often much faster
120 than with the ucontext functions). Unfortunately, glibc-2.1 and
121 below don't even feature a working sigaltstack. You cannot use this
122 implementation if some other code uses SIGUSR2 or you plan to create
123 coroutines from an alternative signal stack, as both are being used for
124 coroutine creation.
125
126 a Handcoded assembly. This is the fastest and most compatible method,
127 with the least side effects, if it works, that is. It has been tested
128 on GNU/Linux x86 and x86_64 systems and should work on all x86/x86_64
129 systems using the SVR ELF ABI (it is also reported to be working on
130 Strawberry Perl for Windows using MinGW). This is the recommended
131 method on supported platforms. When it doesn't work, use another
132 method, such as (s)etjmp/longjmp.
133
134 l GNU/Linux. Very old GNU/Linux systems (glibc-2.1 and below) need
135 this hack. Since it is very linux-specific it is also quite fast and
136 recommended even for newer versions; when it works, that is (currently
137 x86 and a few others only. If it compiles, it's usually ok). Newer
138 glibc versions (>= 2.5) stop working with this implementation however.
139
140 i IRIX. For some reason, SGI really does not like to follow POSIX (does
141 that surprise you?), so this workaround might be needed (it's fast),
142 although [s] and [u] should also work now.
143
144 w Microsoft Windows. Try this on Microsoft Windows when using Cygwin or
145 the MSVC compilers (e.g. ActiveState Perl, but see "a" for Strawberry
146 Perl), although, as there is no standard on how to do this under
147 windows, different environments might work differently. Doh.
148
149 p Use pthread API. Try to avoid this option, it was only created to
150 make a point about the programming language shootout. It is unlikely
151 to work with perls that have windows process emulation enabled ("perl
152 threads"). It is also likely the slowest method of implementing
153 coroutines. It might work fine as a last resort, however, as the
154 pthread API is slightly better tested than ucontext functions for
155 example. Of course, not on BSDs, who usually have very broken pthread
156 implementations.
157
158 Coro tries hard to come up with a suitable default for most systems,
159 so pressing return at the prompt usually does the right thing. If you
160 experience problems (e.g. make test fails) then you should experiment with
161 this setting.
162
163 EOF
164
165 retry:
166
167 my $r = prompt "Use which implementation,\n" .
168 "<s>et/longjump, <u>context, <a>ssembly, <i>rix, <l>inux or <w>indows?",
169 $iface;
170 $iface = lc $1 if $r =~ /(\S)/;
171
172 if ($iface eq "u") {
173 $DEFINE .= " -DCORO_UCONTEXT";
174 print "\nUsing ucontext implementation\n\n";
175 conftest ("TEST_makecontext");
176 } elsif ($iface eq "s") {
177 $DEFINE .= " -DCORO_SJLJ";
178 print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n";
179 conftest ("TEST_sigaltstack");
180 } elsif ($iface eq "l") {
181 $DEFINE .= " -DCORO_LINUX";
182 print "\nUsing linux-specific implementation\n\n";
183 } elsif ($iface eq "i") {
184 $DEFINE .= " -DCORO_IRIX";
185 print "\nUsing irix-specific implementation\n\n";
186 } elsif ($iface eq "w") {
187 $DEFINE .= " -DCORO_LOSER";
188 print "\nUsing windows-specific implementation\n\n";
189 } elsif ($iface eq "a") {
190 $DEFINE .= " -DCORO_ASM";
191 print "\nUsing handcoded assembly implementation\n\n";
192 } elsif ($iface eq "p") {
193 $DEFINE .= " -DCORO_PTHREAD";
194 @LIBS = ["-lpthread"];
195 print "\nUsing pthread implementation\n\n";
196 } else {
197 print "\nUnknown implementation \"$iface\"\n";
198 goto retry;
199 }
200
201 print <<EOF;
202
203 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
204
205 Per-context stack size factor: Depending on your settings, Coro tries to
206 share the C stacks is creates as much as possible, but sometimes it needs
207 to allocate a new one. This setting controls the maximum size that gets
208 allocated, and should not be set too high, as memory and address space
209 still is wasted even if it's not fully used. The value entered will be
210 multiplied by sizeof(long), which is usually 4 on 32-bit systems, and 8 on
211 64-bit systems.
212
213 A setting of 16384 (the default) therefore corresponds to a 64k..128k
214 stack, which usually is ample space (you might even want to try 8192 or
215 lower if your program creates many coroutines).
216
217 On systems supporting mmap and dynamic memory management, the actual
218 memory usually gets allocated on demand, but with many large stacks you
219 can still run out of address space on your typical 32 bit platform (not to
220 forget the pagetables).
221
222 Some perls (mostly threaded ones and perl compiled under linux 2.6) and
223 some programs (inefficient regexes can use a lot of stack space) may
224 need much, much more: If Coro segfaults with weird backtraces (e.g. in a
225 function prologue) or in t/10_bugs.t, you might want to increase this to
226 65536 or more.
227
228 The default should be fine, and can be changed at runtime with
229 Coro::State::cctx_stacksize.
230
231 EOF
232
233 my $stacksize = $^O eq "linux" && $] < 5.008008 ? 128 * 1024 : 16384;
234
235 $stacksize = prompt ("C stack size factor?", $stacksize);
236 $DEFINE .= " -DCORO_STACKSIZE=$stacksize";
237
238 print "using a stacksize of $stacksize * sizeof(long)\n";
239
240 print <<EOF;
241
242 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
243
244 Coro can optionally put a guard area before each stack segment: When the
245 stack is too small and the access is not too far outside the stack (i.e.
246 within the guard area), then the program will safely segfault instead of
247 running into other data. The cost is some additional overhead with is
248 usually negligible, and extra use of address space.
249
250 The guard area size currently needs to be specified in pages (typical
251 pagesizes are 4k and 8k). The guard area is only enabled on a few
252 hardcoded architectures and is ignored on others. The actual preprocessor
253 expression disables this feature if:
254
255 !__i386 && !__x86_64 && !__powerpc && !__m68k \
256 && !__alpha && !__mips && !__sparc64
257
258 The default, as usual, should be just fine.
259
260 EOF
261
262 my $stackguard = prompt ("Number of guard pages (0 disables)?", "4");
263 $DEFINE .= " -DCORO_STACKGUARD=$stackguard";
264
265 print <<EOF;
266
267 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
268
269 Coro can tell valgrind about its stacks and so reduce spurious warnings
270 where valgrind would otherwise complain about possible stack switches.
271
272 Enabling this does not incur noticable runtime or memory overhead, but it
273 requires that you have the <valgrind/valgrind.h> header file available.
274
275 Valgrind support is completely optional, so disabling it is the safe
276 choice.
277
278 EOF
279
280 my $valgrind = prompt ("Enable valgrind support (y/n)?",
281 -r "/usr/include/valgrind/valgrind.h" ? "y" : "n");
282 $DEFINE .= " -DCORO_USE_VALGRIND=1" if $valgrind =~ /[yY]/;
283
284
285 print <<EOF;
286
287 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
288
289 Coro can use (or even trick) some perl functions into doing what it needs
290 instead of relying on (some) of its own functions. This might increase
291 chances that it compiles and works, but it could just as well result in
292 memory leaks, crashes or silent data corruption. It certainly does result
293 in slightly slower speed and higher memory consumption, though, so YOU
294 SHOULD ENABLE THIS OPTION ONLY AS A LAST RESORT.
295
296 EOF
297
298 my $use_internals = prompt ("Prefer perl functions over coro functions (y/n)?", "n");
299 $DEFINE .= " -DCORO_PREFER_PERL_FUNCTIONS=1" if $use_internals =~ /[yY]/;
300
301 print <<EOF;
302
303 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
304
305 Coro has experimental support for cloning states. This can be used
306 to implement a scheme-like call/cc. However, this doesn't add to the
307 expressiveness in general, and is likely perl-version specific. As such,
308 it is disabled by default. Enable it when you want to play around with
309 it, but note that it isn't supported, and unlikely ever will be. It
310 exists mainly to prove that it could be done - if only it were useful for
311 something.
312
313 EOF
314
315 my $masturbate = $ENV{CORO_CLONE} || "n";
316 $masturbate = prompt ("Implement Coro::State->clone method (y/n)?", $masturbate);
317 $DEFINE .= " -DCORO_CLONE=1" if $masturbate =~ /[yY]/;
318
319 print <<EOF;
320
321 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
322
323 EOF
324
325 WriteMakefile(
326 NAME => "Coro::State",
327 VERSION_FROM => "State.pm",
328 DEFINE => $DEFINE,
329 LIBS => @LIBS,
330 DIR => [],
331 depend => {
332 "State.c" => "state.h clone.c libcoro/coro.h libcoro/coro.c",
333 },
334 );
335
336 sub conftest {
337 my $type = shift;
338
339 print "\nTrying to detect stack growth direction (for $type)\n";
340 print "You might see some warnings, this should not concern you.\n\n";
341 system "$Config{cc} $Config{ccflags} -D$type libcoro/conftest.c";
342
343 my $res = qx<./a.out>;
344 $res =~ s/\s+$//;
345 my ($sp, $ss) = split /,/, $res;
346
347 print "\n\n*****************************************************************************\n";
348 print "If the testsuite fails PLEASE provide the following information\n";
349 print "to Marc Lehmann <schmorp\@schmorp.de>: operating system name, version,\n";
350 print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d#
351 print "*****************************************************************************\n\n";
352
353 unlink "a.out";
354 unlink "conftestval";
355 }
356