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