ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Makefile.PL
Revision: 1.49
Committed: Wed May 2 05:53:26 2007 UTC (17 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-3_63
Changes since 1.48: +21 -6 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 use ExtUtils::MakeMaker;
2
3 use 5.005;
4
5 use Config;
6
7 $|=1;
8
9 $DEFINE = "";
10
11 print <<EOF;
12
13 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
14
15 Coro has a number of configuration options. Due to its maturity, the
16 defaults that Coro chooses are usually fine, so you can decide to skip
17 these questions. Only if something went wrong you should select 'n'
18 here and manually configure Coro, and, of course, report this to the
19 maintainer :)
20
21 EOF
22
23 if (prompt ("Skip further questions and use defaults (y/n)?", "y") =~ /[yY]/) {
24 $ENV{PERL_MM_USE_DEFAULT} = 1;
25 }
26
27
28 $DEFINE .= " -DHAVE_MMAP" if $Config{d_mmap} eq "define" && $Config{d_munmap} eq "define";
29
30 if (exists $ENV{CORO_INTERFACE}) {
31 $iface = $ENV{CORO_INTERFACE};
32 } elsif ($^O =~ /win32/i or $^O =~ /cygwin/ or $^O =~ /mswin/) {
33 $iface = 'w';
34 } elsif ($^O =~ /irix/) {
35 $iface = "i";
36 } elsif ($^O =~ /linux/) {
37 ## default to setjmp/longjmp on non-x86...
38 #$iface = $Config{archname} =~ /^(i[3456]86|amd64|x86_64)-/ ? "l" : "s";
39
40 # default to setjmp/longjmp everywhere as newer libc change everything around
41 $iface = "s";
42 } elsif ($^O =~ /(free|net|open)bsd/) {
43 # FreeBSD 4.x has ucontext.h but no makecontext et al. (see BUGS section of
44 # man context). Assume the same problem for all other BSDs.
45 $iface = "s";
46 } elsif ($^O =~ /solaris/) {
47 $iface = "s";
48 } elsif ($^O =~ /darwin/) {
49 $iface = "s";
50 } elsif (-e "/usr/include/ucontext.h") { # shame on this heuristic
51 $iface = "u";
52 } else {
53 $iface = "s";
54 }
55
56 print <<EOF;
57
58 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
59
60 Coro can use a number of methods to implement coroutines at the C
61 level. The default chosen is based on your current confguration and is
62 correct in most cases, but you still can chose between these alternatives:
63
64 u The unix 'ucontext.h' functions are relatively new and not implemented
65 or well-tested in older unices. They allow very fast coroutine creation
66 and reasonably fast switching, and, most importantly, are very stable.
67 It is, however, usually slower than the other alternatives due to an
68 extra syscall done by swapcontext.
69
70 s If the ucontext functions are not working or you don't want
71 to use them for other reasons you can try a workaround using
72 setjmp/longjmp/sigaltstack (also standard unix functions). Coroutine
73 creation is rather slow, but switching is very fast (often much faster
74 than with the ucontext functions). Unfortunately, glibc-2.1 and
75 below don't even feature a working sigaltstack. You cannot use this
76 implementation if some other code uses SIGUSR2 or you plan to
77 create coroutines from an alternative signal stack, as both are being
78 used for coroutine creation.
79
80 a Handcoded assembly. This is the fastest method with the least side
81 effects, if it works, that is. It has been tested on GNU/Linux x86 and
82 x86_64 systems and should work on all x86/x86_64 systems using the SVR
83 ELF ABI.
84
85 l GNU/Linux. Very old GNU/Linux systems (glibc-2.1 and below) need
86 this hack. Since it is very linux-specific it is also quite fast and
87 recommended even for newer versions; when it works, that is (currently
88 x86 and a few others only. If it compiles, it's usually ok). Newer
89 glibc versions (>= 2.5) stop working with this implementation again.
90
91 i IRIX. For some reason, SGI really does not like to follow the single
92 unix specification (does that surprise you?), so this workaround might
93 be needed (it's fast), although [s] and [u] should also work now.
94
95 w Microsoft Windows. Try this on Microsoft Windows, although, as there is
96 no standard on how to do this under windows, this might work only on
97 cygwin or specific versions of msvc. Your problem, your fix, our patch.
98
99 For most systems, the default chosen should be OK. If you experience
100 problems then you should experiment with this setting and/or turn off
101 optimizations (make OPTIMIZE=-O0).
102
103 EOF
104
105 retry:
106
107 my $r = prompt "Use which implementation,\n" .
108 "<s>et/longjump, <u>context, <a>ssembly, <i>rix, <l>inux or <w>indows?",
109 $iface;
110 $iface = lc $1 if $r =~ /(\S)/;
111
112 if ($iface eq "u") {
113 $DEFINE .= " -DCORO_UCONTEXT";
114 print "\nUsing ucontext implementation\n\n";
115 conftest("TEST_makecontext");
116 } elsif ($iface eq "s") {
117 $DEFINE .= " -DCORO_SJLJ";
118 print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n";
119 conftest("TEST_sigaltstack");
120 } elsif ($iface eq "l") {
121 $DEFINE .= " -DCORO_LINUX";
122 print "\nUsing linux-specific implementation\n\n";
123 } elsif ($iface eq "i") {
124 $DEFINE .= " -DCORO_IRIX";
125 print "\nUsing irix-specific implementation\n\n";
126 } elsif ($iface eq "w") {
127 $DEFINE .= " -DCORO_LOSER";
128 print "\nUsing windows-specific implementation\n\n";
129 } elsif ($iface eq "a") {
130 $DEFINE .= " -DCORO_ASM";
131 print "\nUsing handcoded assembly implementation\n\n";
132 } else {
133 print "\nUnknown implementation \"$iface\"\n";
134 goto retry;
135 }
136
137 print <<EOF;
138
139 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
140
141 Per-context stack size factor: Depending on your settings, Coro tries to
142 share the C stack as much as possible, but sometimes it needs to allocate
143 a new one. This setting controls the maximum size that gets allocated,
144 and should not be set too high, as memory and address space still is
145 wasted even if it's not fully used. The value entered will be multiplied
146 by sizeof(long), which is usually 4 on 32-bit systems, and 8 on 64-bit
147 systems.
148
149 A setting of 16384 (the default) therefore corresponds to a 64k..128k
150 stack, which usually is ample space (you might even want to try 8192 or
151 lower if your program creates many coroutines).
152
153 On systems supporting mmap and dynamic memory management, the actual
154 memory usually gets allocated on demand, but with many large stacks you
155 can still run out of address space on your typical 32 bit platform.
156
157 Some perls (mostly threaded ones and perl compiled under linux 2.6) and
158 some programs (inefficient regexes can use a lot of stack space) may
159 need much, much more: If Coro segfaults with weird backtraces (e.g. in a
160 function prologue) or in t/10_bugs.t, you might want to increase this to
161 65536 or more.
162
163 The default should be fine, and can be changed at runtime with
164 Coro::State::cctx_stacksize.
165
166 EOF
167
168 my $stacksize = prompt ("C stack size factor?", "16384");
169 $DEFINE .= " -DCORO_STACKSIZE=$stacksize";
170
171 print "using a stacksize of $stacksize * sizeof(long)\n";
172
173 print <<EOF;
174
175 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
176
177 Coro can optionally put a guard area before each stack segment. When the
178 stack is too small and the access is not too far outside the stack (i.e.
179 within the guard area), then the program will safely segfault instead of
180 running into other data. The cost is some additional overhead with is
181 usually negligible, and extra use of address space.
182
183 The guard area size currently needs to be specified in pages (typical
184 pagesizes are 4k and 8k). The guard area is only enabled on a few
185 hardcoded architectures and is ignored on others. The actual preprocessor
186 expression disables this feature if:
187
188 !__i386 && !__x86_64 && !__powerpc && !__m68k \
189 && !__alpha && !__mips && !__sparc64
190
191 The default, as usual, should be just fine.
192
193 EOF
194
195 my $stackguard = prompt ("Number of guard pages (0 disables)?", "4");
196 $DEFINE .= " -DCORO_STACKGUARD=$stackguard";
197
198 print <<EOF;
199
200 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
201
202 Coro can tell valgrind about its stacks and so reduce spurious warnings
203 where valgrind would otherwise complain about possible stack switches.
204
205 Enabling this does not incur visible runtime or memory overhead, but it
206 requires that you have the <valgrind/valgrind.h> header file available.
207
208 Valgrind support is completely optional, so the default of disabling it is
209 the safe choice.
210
211 EOF
212
213 my $valgrind = prompt ("Enable valgrind support (y/n)?",
214 -r "/usr/include/valgrind/valgrind.h" ? "y" : "n");
215 $DEFINE .= " -DCORO_USE_VALGRIND=1" if $valgrind =~ /[yY]/;
216
217
218 print <<EOF;
219
220 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
221
222 Coro can use (or even trick) some perl functions into doing what it needs
223 instead of relying on (some) of its own functions. This might increase
224 chances that it compiles and works, but it could just as well result in
225 memory leaks, crashes or silent data corruption. It certainly does result
226 in slightly slower speed and higher memory consumption, though, so you
227 should enable it only as a last resort.
228
229 EOF
230
231 my $use_internals = prompt ("Prefer perl functions over coro functions (y/n)?", "n");
232 $DEFINE .= " -DCORO_PREFER_PERL_FUNCTIONS=1" if $use_internals =~ /[yY]/;
233
234 print <<EOF;
235
236 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
237
238 EOF
239
240 WriteMakefile(
241 NAME => "Coro::State",
242 VERSION_FROM => "State.pm",
243 DEFINE => $DEFINE,
244 DIR => [],
245 );
246
247 sub conftest {
248 my $type = shift;
249
250 print "\nTrying to detect stack growth direction (for $type)\n";
251 print "You might see some warnings, this should not concern you.\n\n";
252 system "$Config{cc} $Config{ccflags} -D$type libcoro/conftest.c";
253
254 my $res = qx<./a.out>;
255 $res =~ s/\s+$//;
256 my ($sp, $ss) = split /,/, $res;
257
258 print "\n\n*****************************************************************************\n";
259 print "If the testsuite fails PLEASE provide the following information\n";
260 print "to Marc Lehmann <schmorp\@schmorp.de>: operating system name, version,\n";
261 print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d#
262 print "*****************************************************************************\n\n";
263
264 unlink "a.out";
265 unlink "conftestval";
266 }
267
268 print <<EOF if $^O =~ /linux/;
269
270 *****************************************************************************
271 * *
272 * HEY!! You are using Linux! That's not at all bad, but if you get seg- *
273 * faults with Coro almost all the time please refer to README.linux-glibc *
274 * *
275 *****************************************************************************
276
277 EOF
278