ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Makefile.PL
Revision: 1.32
Committed: Thu Mar 3 17:20:31 2005 UTC (19 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.31: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 use ExtUtils::MakeMaker;
2    
3 root 1.7 use 5.005;
4 root 1.1
5 root 1.2 use Config;
6    
7 root 1.6 $|=1;
8    
9 root 1.2 $DEFINE = "";
10    
11     $DEFINE .= " -DHAVE_MMAP" if $Config{d_mmap} eq "define" && $Config{d_munmap} eq "define";
12    
13 root 1.18 if ($^O =~ /win32/i or $^O =~ /cygwin/) {
14 root 1.3 $DEFINE = " -DCORO_LOOSE";
15 root 1.14 } elsif ($^O =~ /irix/) {
16     $iface = "i";
17 root 1.4 } elsif ($^O =~ /linux/) {
18 root 1.23 # default to setjmp/longjmp on non-x86...
19 root 1.31 $iface = $Config{archname} =~ /^(i[3456]86|amd64)-/ ? "l" : "s";
20 root 1.24 } 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 root 1.8 } elsif ($^O =~ /solaris/) {
25     $iface = "s";
26 root 1.25 } elsif ($^O =~ /darwin/) {
27     $iface = "s";
28 root 1.2 } elsif (-e "/usr/include/ucontext.h") {
29 root 1.3 $iface = "u";
30 root 1.2 } else {
31 root 1.3 $iface = "s";
32 root 1.2 }
33    
34 root 1.6 print <<EOF;
35    
36 root 1.21 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 root 1.6
46 root 1.21 The default (enabled) has been in-use on productions servers for some time
47     now, without any problem reports so far.
48 root 1.6
49     EOF
50    
51 root 1.27 if (prompt ("Do you want to enable C context sharing (y/n)", "y") !~ /^\s*n/i) {
52 root 1.6 print "\nExperimental context sharing enabled.\n\n";
53     $DEFINE .= " -DCORO_LAZY_STACK";
54     }
55    
56 root 1.3 if ($iface) {
57     print <<EOF;
58 root 1.2
59 root 1.20 Coro can use various ways to implement coroutines at the C level:
60 root 1.3
61 root 1.4 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 root 1.14 very linux-specific it is also quite fast for newer versions; when it
75 root 1.23 works, that is (currently x86 only)...
76 root 1.14
77     i IRIX. For some reason, SGI really does not like to follow the unix
78 root 1.20 standard (does that surprise you?), so this workaround might be needed
79     (it's fast), although s and u should also work now.
80 root 1.2
81 root 1.28 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 root 1.2 EOF
86 root 1.3
87     retry:
88 root 1.14
89 root 1.27 my $r = prompt "Use which implementation,\n" .
90     "<s>etjmp/longjump, <u>context, <i>rix or <l>inux?",
91     $iface;
92 root 1.3 $iface = lc $1 if $r =~ /(\S)/;
93    
94     if ($iface eq "u") {
95     $DEFINE .= " -DCORO_UCONTEXT";
96     print "\nUsing ucontext implementation\n\n";
97 root 1.15 conftest("TEST_makecontext");
98 root 1.3 } elsif ($iface eq "s") {
99     $DEFINE .= " -DCORO_SJLJ";
100     print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n";
101 root 1.15 conftest("TEST_sigaltstack");
102 root 1.4 } elsif ($iface eq "l") {
103     $DEFINE .= " -DCORO_LINUX";
104     print "\nUsing linux-specific implementation\n\n";
105 root 1.14 } elsif ($iface eq "i") {
106     $DEFINE .= " -DCORO_IRIX";
107     print "\nUsing irix-specific implementation\n\n";
108 root 1.3 } else {
109     print "\nUnknown implementation \"$iface\"\n";
110     goto retry;
111     }
112     } else {
113 root 1.16 print "\nUsing microsoft compatible coroutines\n\n";
114 root 1.3 }
115 root 1.2
116 root 1.1 WriteMakefile(
117 root 1.2 NAME => "Coro::State",
118     VERSION_FROM => "State.pm",
119     DEFINE => $DEFINE,
120     DIR => [],
121 root 1.1 );
122 root 1.2
123 root 1.15 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 root 1.32 print "to Marc Lehmann <schmorp\@schmorp.de>: operating system name, version,\n";
137 root 1.15 print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d#
138     print "*****************************************************************************\n\n";
139    
140     unlink "a.out";
141 root 1.17 unlink "conftestval";
142 root 1.15 }
143 root 1.2
144 root 1.26 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 root 1.1