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/) { |
14 |
$DEFINE = " -DCORO_LOOSE"; |
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-/ ? "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") { |
29 |
$iface = "u"; |
30 |
} else { |
31 |
$iface = "s"; |
32 |
} |
33 |
|
34 |
print <<EOF; |
35 |
|
36 |
Version 0.12 introduced C context sharing. This makes it possible to share |
37 |
the C stack and context between many coroutines, resulting in memory |
38 |
savings and slight speed gains, at the cost of potential (but mostly |
39 |
theoretical) segfaults. On my Linux/x86 machine this decreased the size |
40 |
of a new coroutine from 9k to 5k, but the savings are much more apparent |
41 |
on machines without mmap or good memory management. This algorithm relies |
42 |
on the non-fact that the same machine stack pointer indicates the same |
43 |
function call nesting level, which usually works good enough but might |
44 |
fail... |
45 |
|
46 |
The default (enabled) has been in-use on productions servers for some time |
47 |
now, without any problem reports so far. |
48 |
|
49 |
EOF |
50 |
|
51 |
if (prompt ("Do you want to enable C context sharing (y/n)", "y") !~ /^\s*n/i) { |
52 |
print "\nExperimental context sharing enabled.\n\n"; |
53 |
$DEFINE .= " -DCORO_LAZY_STACK"; |
54 |
} |
55 |
|
56 |
if ($iface) { |
57 |
print <<EOF; |
58 |
|
59 |
Coro can use various ways to implement coroutines at the C level: |
60 |
|
61 |
u The unix ucontext functions are newer and not implemented in older |
62 |
unices (or broken libc's like glibc-2.2.2 and below). They allow very |
63 |
fast coroutine creation and fast switching, and, most importantly, are |
64 |
very stable. |
65 |
|
66 |
s If the ucontext functions are not working or you don't want |
67 |
to use them for other reasons you can try a workaround using |
68 |
setjmp/longjmp/sigaltstack (also standard unix functions). Coroutine |
69 |
creation is rather slow, but switching is very fast as well (often much |
70 |
faster than with the ucontext functions). Unfortunately, glibc-2.1 and |
71 |
below don't even feature a working sigaltstack. |
72 |
|
73 |
l Older GNU/Linux systems (glibc-2.1 and below) need this hack. Since it is |
74 |
very linux-specific it is also quite fast for newer versions; when it |
75 |
works, that is (currently x86 only)... |
76 |
|
77 |
i IRIX. For some reason, SGI really does not like to follow the unix |
78 |
standard (does that surprise you?), so this workaround might be needed |
79 |
(it's fast), although s and u should also work now. |
80 |
|
81 |
EOF |
82 |
|
83 |
retry: |
84 |
|
85 |
my $r = prompt "Use which implementation,\n" . |
86 |
"<s>etjmp/longjump, <u>context, <i>rix or <l>inux?", |
87 |
$iface; |
88 |
$iface = lc $1 if $r =~ /(\S)/; |
89 |
|
90 |
if ($iface eq "u") { |
91 |
$DEFINE .= " -DCORO_UCONTEXT"; |
92 |
print "\nUsing ucontext implementation\n\n"; |
93 |
conftest("TEST_makecontext"); |
94 |
} elsif ($iface eq "s") { |
95 |
$DEFINE .= " -DCORO_SJLJ"; |
96 |
print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n"; |
97 |
conftest("TEST_sigaltstack"); |
98 |
} elsif ($iface eq "l") { |
99 |
$DEFINE .= " -DCORO_LINUX"; |
100 |
print "\nUsing linux-specific implementation\n\n"; |
101 |
} elsif ($iface eq "i") { |
102 |
$DEFINE .= " -DCORO_IRIX"; |
103 |
print "\nUsing irix-specific implementation\n\n"; |
104 |
} else { |
105 |
print "\nUnknown implementation \"$iface\"\n"; |
106 |
goto retry; |
107 |
} |
108 |
} else { |
109 |
print "\nUsing microsoft compatible coroutines\n\n"; |
110 |
} |
111 |
|
112 |
WriteMakefile( |
113 |
NAME => "Coro::State", |
114 |
VERSION_FROM => "State.pm", |
115 |
DEFINE => $DEFINE, |
116 |
DIR => [], |
117 |
); |
118 |
|
119 |
sub conftest { |
120 |
my $type = shift; |
121 |
|
122 |
print "\nTrying to detect stack growth direction (for $type)\n"; |
123 |
print "You might see some warnings, this should not concern you.\n\n"; |
124 |
system "$Config{cc} $Config{ccflags} -D$type libcoro/conftest.c"; |
125 |
|
126 |
my $res = qx<./a.out>; |
127 |
$res =~ s/\s+$//; |
128 |
my ($sp, $ss) = split /,/, $res; |
129 |
|
130 |
print "\n\n*****************************************************************************\n"; |
131 |
print "If the testsuite fails PLEASE provide the following information\n"; |
132 |
print "to Marc Lehmann <pcg\@goof.com>: operating system name, version,\n"; |
133 |
print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d# |
134 |
print "*****************************************************************************\n\n"; |
135 |
|
136 |
unlink "a.out"; |
137 |
unlink "conftestval"; |
138 |
} |
139 |
|
140 |
print <<EOF if $^O =~ /linux/; |
141 |
|
142 |
***************************************************************************** |
143 |
* * |
144 |
* HEY!! You are using Linux! That's not at all bad, but if you get seg- * |
145 |
* faults with Coro almost all the time please refer to README.linux-glibc * |
146 |
* * |
147 |
***************************************************************************** |
148 |
|
149 |
EOF |
150 |
|