1 |
use 5.006; |
2 |
|
3 |
use strict qw(vars subs); |
4 |
use Config; |
5 |
use ExtUtils::MakeMaker; |
6 |
|
7 |
unless (-e "libev/ev_epoll.c") { |
8 |
print <<EOF; |
9 |
|
10 |
*** |
11 |
*** ERROR: libev is missing or damaged. If you used a CVS check-out of EV, |
12 |
*** you also have to check-out the "libev" module from the same CVS |
13 |
*** repository into the EV dir (i.e. EV/libev from outside). |
14 |
*** |
15 |
|
16 |
EOF |
17 |
exit 1; |
18 |
} |
19 |
|
20 |
print <<EOF; |
21 |
|
22 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
23 |
|
24 |
|
25 |
Welcome to EV configuration. If you are in a hurry, just press return here |
26 |
and hope for the best. The defaults should usually do. |
27 |
|
28 |
EOF |
29 |
|
30 |
if (prompt ("Skip further questions and use defaults (y/n)?", "y") =~ /[yY]/) { |
31 |
$ENV{PERL_MM_USE_DEFAULT} = 1; |
32 |
} |
33 |
|
34 |
print <<EOF; |
35 |
|
36 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
37 |
|
38 |
|
39 |
POSIX optionally offers support for a monotonic clock source. EV |
40 |
can take advantage of this clock source to detect time jumps |
41 |
reliably. Unfortunately, some systems are bound to be broken, so you can |
42 |
disable this here: you can completely disable the detection and use of |
43 |
the monotonic clock by answering 'n' here. Support for this clock type |
44 |
will otherwise be autodetected at both compile- and runtime. (this setting |
45 |
currently affects the use of nanosleep over select as well). |
46 |
|
47 |
EOF |
48 |
|
49 |
my $DEFINE .= " -DEV_USE_MONOTONIC=" . (0 + (prompt ("Enable optional support for CLOCK_MONOTONIC (y/n)?", "y") =~ /[yY]/)); |
50 |
|
51 |
print <<EOF; |
52 |
|
53 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
54 |
|
55 |
|
56 |
POSIX optionally offers support for a (potentially) high-resolution |
57 |
realtime clock interface. In a good implementation, using it is faster |
58 |
than the normal method of using gettimeofday. Unfortunately, this option |
59 |
is also bound to be broken on some systems, so you can disable use and |
60 |
probing of this feature altogether here. Otherwise support for this clock |
61 |
type will be autodetected at compiletime. |
62 |
|
63 |
EOF |
64 |
|
65 |
$DEFINE .= " -DEV_USE_REALTIME=" . (0 + (prompt ("Prefer clock_gettime (CLOCK_REALTIME) over gettimeofday (y/n)?", "y") =~ /[yY]/)); |
66 |
|
67 |
print <<EOF; |
68 |
|
69 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
70 |
|
71 |
|
72 |
EV can use various backends with various portability issue. The select |
73 |
backend is the most portable and makes for a good fallback, but it can be |
74 |
limited to a low number of file descriptors and/or might not compile. If |
75 |
you have problems with compiling ev_select.c, you might try to play around |
76 |
with disabling it here, or forcing it to use the fd_set provided by your |
77 |
OS, via the next question. I highly recommend keeping it in. |
78 |
|
79 |
EOF |
80 |
|
81 |
if (prompt ("Enable select backend (y/n)?", "y") =~ /[yY]/) { |
82 |
$DEFINE .= " -DEV_USE_SELECT=1"; |
83 |
|
84 |
print <<EOF; |
85 |
|
86 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
87 |
|
88 |
|
89 |
The select backend can operate in two modes. One uses the system-provided |
90 |
fd_set and is usually limited to 1024 file descriptors (64 on windows), |
91 |
the other requires your header files to define NFDBITS and declare a |
92 |
suitable fd_mask type. If you run into problems compiling ev_select.c, you |
93 |
can try forcing the use of the system fd_set here. |
94 |
|
95 |
EOF |
96 |
|
97 |
if (prompt ("Force use of system fd_set for select backend (y/n)?", "n") =~ /[yY]/) { |
98 |
$DEFINE .= " -DEV_SELECT_USE_FD_SET"; |
99 |
} |
100 |
} else { |
101 |
$DEFINE .= " -DEV_USE_SELECT=0"; |
102 |
} |
103 |
|
104 |
print <<EOF; |
105 |
|
106 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
107 |
|
108 |
|
109 |
The second very portable backend is poll(2). It does not exist on windows |
110 |
and various versions of Mac OS X (and on the other versions it simply |
111 |
doesn't work), but works basically everywhere else. It is recommended to use |
112 |
the default here unless you run into compile problems in ev_poll.c. |
113 |
|
114 |
EOF |
115 |
|
116 |
$DEFINE .= " -DEV_USE_POLL=" . (0 + (prompt ("Enable poll backend (y/n)?", (-e "/usr/include/poll.h") ? "y" : "n") =~ /[yY]/)); |
117 |
|
118 |
print <<EOF; |
119 |
|
120 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
121 |
|
122 |
|
123 |
Select and poll make it hard to write efficient servers, especially if the |
124 |
number of active connections is much lower than the watched ones. GNU/Linux |
125 |
systems have a more scalable method called "epoll", which EV can use. For |
126 |
this to work, both your kernel and glibc have to support epoll, but if you |
127 |
can compile it, the detection will be done at runtime, and EV will safely |
128 |
fall back to using select when epoll isn't available. If unsure, accept |
129 |
the default. |
130 |
|
131 |
EOF |
132 |
|
133 |
my $can_epoll = -e "/usr/include/sys/epoll.h"; |
134 |
$can_epoll = $ENV{EV_EPOLL} if exists $ENV{EV_EPOLL}; |
135 |
$DEFINE .= " -DEV_USE_EPOLL=" . (0 + (prompt ("Enable epoll backend (y/n)?", $can_epoll ? "y" : "n") =~ /[yY]/)); |
136 |
|
137 |
print <<EOF; |
138 |
|
139 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
140 |
|
141 |
|
142 |
Similarly to the epoll backend above, EV can take advantage of kqueue on |
143 |
many BSD systems. Support for kqueue will be detected at runtime, with a |
144 |
safe fallback to other methods when it cannot be used. |
145 |
|
146 |
Note that kqueue is broken on most operating systems, so by default it |
147 |
won't be used on many platforms, but you can still create your own event |
148 |
loop with kqueue backend. |
149 |
|
150 |
Here is what we know: |
151 |
|
152 |
NetBSD: partially working in at least 3.1. Yeah! :) |
153 |
FreeBSD: broken on at least 6.2-STABLE, |
154 |
sockets *likely* work, ptys definitely don't. |
155 |
OpenBSD: reports indicate that it likely doesn't work |
156 |
(similar problems as on FreeBSD). |
157 |
OS X: completely, utterly broken on at least < 10.5. |
158 |
|
159 |
EOF |
160 |
|
161 |
my $can_kqueue = -e "/usr/include/sys/event.h"; |
162 |
$can_kqueue = $ENV{EV_KQUEUE} if exists $ENV{EV_KQUEUE}; |
163 |
$DEFINE .= " -DEV_USE_KQUEUE=" . (0 + (prompt ("Enable kqueue backend (y/n)?", $can_kqueue ? "y" : "n") =~ /[yY]/)); |
164 |
|
165 |
print <<EOF; |
166 |
|
167 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
168 |
|
169 |
|
170 |
Similarly to the kqueue backend above, EV can take advantage of the |
171 |
solaris 10 event port interface. Support for event ports will be detected |
172 |
at runtime, with a safe fallback to other methods when it cannot be used. |
173 |
|
174 |
EOF |
175 |
|
176 |
$DEFINE .= " -DEV_USE_PORT=" . (0 + (prompt ("Enable event port backend (y/n)?", (-e "/usr/include/sys/port.h") ? "y" : "n") =~ /[yY]/)); |
177 |
|
178 |
print <<EOF; |
179 |
|
180 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
181 |
|
182 |
|
183 |
EV needs the functions pthread_atfork and clock_gettime. On most systems |
184 |
you need some special libraries for this (such as -lrt and -lpthread). You |
185 |
can specify additional libraries to provide these calls (and any other |
186 |
required by EV) now, or accept the default. |
187 |
|
188 |
EOF |
189 |
|
190 |
my $solaris_libs = $^O =~ /solaris/i ? "-lsocket -lnsl" : ""; |
191 |
my $librt = $^O =~ /linux/i ? "-lpthread" : "-lpthread -lrt"; |
192 |
my $LIBS = prompt "Extra libraries for pthread_atfork and clock_gettime?", "$librt $solaris_libs"; |
193 |
|
194 |
|
195 |
print <<EOF; |
196 |
|
197 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
198 |
|
199 |
|
200 |
A backend of a different kind is the Linux inotify(7) interface, which can |
201 |
be used to speed up (and reduce resource consumption) of stat watchers. If |
202 |
you have it, it is usually a good idea to enable it. |
203 |
|
204 |
EOF |
205 |
|
206 |
my $can_inotify = -e "/usr/include/sys/inotify.h"; |
207 |
$can_inotify = $ENV{EV_INOTIFY} if exists $ENV{EV_INOTIFY}; |
208 |
$DEFINE .= " -DEV_USE_INOTIFY=" . (0 + (prompt ("Enable inotify support (y/n)?", $can_inotify ? "y" : "n") =~ /[yY]/)); |
209 |
|
210 |
print <<EOF; |
211 |
|
212 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
213 |
|
214 |
|
215 |
Another useful bit of functionality is the Linux eventfd, which is useful |
216 |
for faster signal handling (don't care) and intra-thread communications |
217 |
(more relevant). Kernel support for this will be probed at runtime, but |
218 |
your libc must contain the necessary wrapper. Glibc 2.7 and later should |
219 |
have this wrapper. |
220 |
|
221 |
EOF |
222 |
|
223 |
my $can_eventfd = -e "/usr/include/sys/eventfd.h"; |
224 |
$can_eventfd = $ENV{EV_EVENTFD} if exists $ENV{EV_EVENTFD}; |
225 |
$DEFINE .= " -DEV_USE_EVENTFD=" . (0 + (prompt ("Enable linux eventfd support (y/n)?", $can_eventfd ? "y" : "n") =~ /[yY]/)); |
226 |
|
227 |
print <<EOF; |
228 |
|
229 |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** |
230 |
|
231 |
|
232 |
EOF |
233 |
|
234 |
my @anyevent = eval { require AnyEvent; $AnyEvent::VERSION < 2.6 } ? (AnyEvent => 2.6) : (); |
235 |
|
236 |
WriteMakefile( |
237 |
dist => { |
238 |
PREOP => 'pod2text EV.pm | tee README >$(DISTVNAME)/README; chmod -R u=rwX,go=rX . ;', |
239 |
COMPRESS => 'gzip -9v', |
240 |
SUFFIX => '.gz', |
241 |
}, |
242 |
depend => { |
243 |
"EV.c" => "EV/EVAPI.h " |
244 |
. "libev/ev.c libev/ev.h libev/ev_epoll.c libev/ev_select.c libev/ev_kqueue.c libev/ev_poll.c " |
245 |
. "libev/ev_vars.h libev/ev_wrap.h", |
246 |
}, |
247 |
INC => "-Ilibev", |
248 |
DEFINE => "$DEFINE", |
249 |
NAME => "EV", |
250 |
LIBS => [$LIBS], |
251 |
PREREQ_PM => { |
252 |
@anyevent, |
253 |
}, |
254 |
VERSION_FROM => "EV.pm", |
255 |
PM => { |
256 |
'EV.pm' => '$(INST_LIBDIR)/EV.pm', |
257 |
'EV/EVAPI.h' => '$(INST_LIBDIR)/EV/EVAPI.h', |
258 |
'EV/MakeMaker.pm' => '$(INST_LIBDIR)/EV/MakeMaker.pm', |
259 |
'libev/ev.h' => '$(INST_LIBDIR)/EV/ev.h', |
260 |
'libev/ev.pod' => '$(INST_LIBDIR)/EV/libev.pod', |
261 |
}, |
262 |
MAN3PODS => { |
263 |
'EV.pm' => '$(INST_MAN3DIR)/EV.$(MAN3EXT)', |
264 |
'EV/MakeMaker.pm' => '$(INST_MAN3DIR)/EV::MakeMaker.$(MAN3EXT)', |
265 |
'libev/ev.pod' => '$(INST_MAN3DIR)/EV::libev.$(MAN3EXT)', |
266 |
}, |
267 |
); |
268 |
|
269 |
|