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