espace / eventmachine forked from riham/eventmachine

A fast network I/O and event-management framework for Ruby, Java, and C++ programmers.

This URL has Read+Write access

eventmachine / ext / extconf.rb
100644 204 lines (173 sloc) 5.642 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# $Id$
#
#----------------------------------------------------------------------------
#
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
# Gmail: blackhedd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of either: 1) the GNU General Public License
# as published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version; or 2) Ruby's License.
#
# See the file COPYING for complete licensing information.
#
#---------------------------------------------------------------------------
#
# extconf.rb for Ruby/EventMachine
# We have to munge LDSHARED because this code needs a C++ link.
#
 
require 'mkmf'
 
flags = []
 
case RUBY_PLATFORM.split('-',2)[1]
when 'mswin32', 'mingw32', 'bccwin32'
  unless have_header('windows.h') and
      have_header('winsock.h') and
      have_library('kernel32') and
      have_library('rpcrt4') and
      have_library('gdi32')
    exit
  end
 
  flags << "-D OS_WIN32"
  flags << '-D BUILD_FOR_RUBY'
  flags << "-EHs"
  flags << "-GR"
 
  dir_config('ssl')
  if have_library('ssleay32') and
have_library('libeay32') and
have_header('openssl/ssl.h') and
have_header('openssl/err.h')
    flags << '-D WITH_SSL'
  else
    flags << '-D WITHOUT_SSL'
  end
 
when /solaris/
  unless have_library('pthread') and
have_library('nsl') and
have_library('socket')
exit
  end
 
  flags << '-D OS_UNIX'
  flags << '-D OS_SOLARIS8'
  flags << '-D BUILD_FOR_RUBY'
 
  dir_config('ssl')
  if have_library('ssl') and
have_library('crypto') and
have_header('openssl/ssl.h') and
have_header('openssl/err.h')
    flags << '-D WITH_SSL'
  else
    flags << '-D WITHOUT_SSL'
  end
 
  # on Unix we need a g++ link, not gcc.
  CONFIG['LDSHARED'] = "$(CXX) -shared"
 
  # Patch by Tim Pease, fixes SUNWspro compile problems.
  if CONFIG['CC'] == 'cc'
    $CFLAGS = CONFIG['CFLAGS'] = "-g -O2 -fPIC"
    CONFIG['CCDLFLAGS'] = "-fPIC"
  end
 
when /openbsd/
  # OpenBSD branch contributed by Guillaume Sellier.
  flags << '-DOS_UNIX'
  flags << '-DBUILD_FOR_RUBY'
   
  dir_config('ssl') # here I don't know why we have to check -lcrypto before -lssl otherwise -lssl is not found
  if have_library('crypto') and
     have_library('ssl') and
     have_header('openssl/ssl.h') and
     have_header('openssl/err.h')
    flags << '-DWITH_SSL'
  else
    flags << '-DWITHOUT_SSL'
  end
  # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
  CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
 
 
when /darwin/
  flags << '-DOS_UNIX'
  flags << '-DBUILD_FOR_RUBY'
 
  if have_header("sys/event.h") and have_header("sys/queue.h")
    flags << "-DHAVE_KQUEUE"
  end
 
  dir_config('ssl')
  if have_library('ssl') and
have_library('crypto') and
have_library('C') and
have_header('openssl/ssl.h') and
have_header('openssl/err.h')
    flags << '-DWITH_SSL'
  else
    flags << '-DWITHOUT_SSL'
  end
  # on Unix we need a g++ link, not gcc.
  # Ff line contributed by Daniel Harple.
  CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
 
when /linux/
  unless have_library('pthread')
exit
  end
 
  flags << '-DOS_UNIX'
  flags << '-DBUILD_FOR_RUBY'
 
  # Original epoll test is inadequate because 2.4 kernels have the header
  # but not the code.
  #flags << '-DHAVE_EPOLL' if have_header('sys/epoll.h')
  if have_header('sys/epoll.h')
File.open("hasEpollTest.c", "w") {|f|
f.puts "#include <sys/epoll.h>"
f.puts "int main() { epoll_create(1024); return 0;}"
}
(e = system( "gcc hasEpollTest.c -o hasEpollTest " )) and (e = $?.to_i)
`rm -f hasEpollTest.c hasEpollTest`
flags << '-DHAVE_EPOLL' if e == 0
  end
 
  if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h')
flags << "-DHAVE_TBR"
  end
 
  dir_config('ssl', "#{ENV['OPENSSL']}/include", ENV['OPENSSL'])
  # Check for libcrypto twice, before and after ssl. That's because on some platforms
  # and openssl versions, libssl will emit unresolved externals from crypto. It
  # would be cleaner to simply check crypto first, but that doesn't always work in
  # Ruby. The order we check them doesn't seem to control the order in which they're
  # emitted into the link command. This is pretty weird, I have to admit.
  if have_library('crypto') and
have_library('ssl') and
have_library('crypto') and
have_header('openssl/ssl.h') and
have_header('openssl/err.h')
    flags << '-DWITH_SSL'
  else
    flags << '-DWITHOUT_SSL'
  end
  # on Unix we need a g++ link, not gcc.
  CONFIG['LDSHARED'] = "$(CXX) -shared"
 
  # Modify the mkmf constant LINK_SO so the generated shared object is stripped.
  # You might think modifying CONFIG['LINK_SO'] would be a better way to do this,
  # but it doesn't work because mkmf doesn't look at CONFIG['LINK_SO'] again after
  # it initializes.
  linkso = Object.send :remove_const, "LINK_SO"
  LINK_SO = linkso + "; strip $@"
 
else
  unless have_library('pthread')
exit
  end
 
  flags << '-DOS_UNIX'
  flags << '-DBUILD_FOR_RUBY'
 
  if have_header("sys/event.h") and have_header("sys/queue.h")
    flags << "-DHAVE_KQUEUE"
  end
 
  dir_config('ssl')
  if have_library('ssl') and
have_library('crypto') and
have_header('openssl/ssl.h') and
have_header('openssl/err.h')
    flags << '-DWITH_SSL'
  else
    flags << '-DWITHOUT_SSL'
  end
  # on Unix we need a g++ link, not gcc.
  CONFIG['LDSHARED'] = "$(CXX) -shared"
 
end
 
if $CPPFLAGS
  $CPPFLAGS += ' ' + flags.join(' ')
else
  $CFLAGS += ' ' + flags.join(' ')
end
 
 
create_makefile "rubyeventmachine"