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