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