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