ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Makefile.PL
Revision: 1.33
Committed: Mon Mar 21 14:38:14 2005 UTC (19 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.32: +1 -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 $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|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") {
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 For most systems, the default chosen should be OK. If you experience
82 problems then you should experiment with this setting and/or turn off
83 optimizations (make OPTIMIZE=-O0).
84
85 EOF
86
87 retry:
88
89 my $r = prompt "Use which implementation,\n" .
90 "<s>etjmp/longjump, <u>context, <i>rix or <l>inux?",
91 $iface;
92 $iface = lc $1 if $r =~ /(\S)/;
93
94 if ($iface eq "u") {
95 $DEFINE .= " -DCORO_UCONTEXT";
96 print "\nUsing ucontext implementation\n\n";
97 conftest("TEST_makecontext");
98 } elsif ($iface eq "s") {
99 $DEFINE .= " -DCORO_SJLJ";
100 print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n";
101 conftest("TEST_sigaltstack");
102 } elsif ($iface eq "l") {
103 $DEFINE .= " -DCORO_LINUX";
104 print "\nUsing linux-specific implementation\n\n";
105 } elsif ($iface eq "i") {
106 $DEFINE .= " -DCORO_IRIX";
107 print "\nUsing irix-specific implementation\n\n";
108 } else {
109 print "\nUnknown implementation \"$iface\"\n";
110 goto retry;
111 }
112 } else {
113 print "\nUsing microsoft compatible coroutines\n\n";
114 }
115
116 WriteMakefile(
117 NAME => "Coro::State",
118 VERSION_FROM => "State.pm",
119 DEFINE => $DEFINE,
120 DIR => [],
121 );
122
123 sub conftest {
124 my $type = shift;
125
126 print "\nTrying to detect stack growth direction (for $type)\n";
127 print "You might see some warnings, this should not concern you.\n\n";
128 system "$Config{cc} $Config{ccflags} -D$type libcoro/conftest.c";
129
130 my $res = qx<./a.out>;
131 $res =~ s/\s+$//;
132 my ($sp, $ss) = split /,/, $res;
133
134 print "\n\n*****************************************************************************\n";
135 print "If the testsuite fails PLEASE provide the following information\n";
136 print "to Marc Lehmann <schmorp\@schmorp.de>: operating system name, version,\n";
137 print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d#
138 print "*****************************************************************************\n\n";
139
140 unlink "a.out";
141 unlink "conftestval";
142 }
143
144 print <<EOF if $^O =~ /linux/;
145
146 *****************************************************************************
147 * *
148 * HEY!! You are using Linux! That's not at all bad, but if you get seg- *
149 * faults with Coro almost all the time please refer to README.linux-glibc *
150 * *
151 *****************************************************************************
152
153 EOF
154