3 def check_libs libs = [], fatal = false
4 libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
7 def check_heads heads = [], fatal = false
8 heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
12 $defs.push("-D#{name}")
15 add_define 'BUILD_FOR_RUBY'
16 add_define 'HAVE_RBTRAP' if have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
17 add_define "HAVE_TBR" if have_func('rb_thread_blocking_region')# and have_macro('RUBY_UBF_IO', 'ruby.h')
18 add_define "HAVE_INOTIFY" if inotify = have_func('inotify_init', 'sys/inotify.h')
19 add_define "HAVE_OLD_INOTIFY" if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
20 add_define 'HAVE_WRITEV' if have_func('writev', 'sys/uio.h')
21 have_func('rb_thread_check_ints')
22 have_func('rb_time_new')
24 # Minor platform details between *nix and Windows:
26 if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
27 GNU_CHAIN = $1 == 'mingw'
35 add_define "HAVE_KQUEUE" if have_header("sys/event.h") and have_header("sys/queue.h")
38 # Main platform invariances:
41 when /mswin32/, /mingw32/, /bccwin32/
42 check_heads(%w[windows.h winsock.h], true)
43 check_libs(%w[kernel32 rpcrt4 gdi32], true)
46 CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
53 add_define 'OS_SOLARIS8'
54 check_libs(%w[nsl socket], true)
56 # Patch by Tim Pease, fixes SUNWspro compile problems.
57 if CONFIG['CC'] == 'cc'
59 $CFLAGS = CONFIG['CFLAGS'] = "-KPIC -G"
60 CONFIG['CCDLFLAGS'] = "-KPIC"
63 # on Unix we need a g++ link, not gcc.
64 CONFIG['LDSHARED'] = "$(CXX) -shared"
68 # OpenBSD branch contributed by Guillaume Sellier.
70 # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
71 CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
72 CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
75 # on Unix we need a g++ link, not gcc.
76 # Ff line contributed by Daniel Harple.
77 CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
80 add_define 'HAVE_EPOLL' if have_func('epoll_create', 'sys/epoll.h')
82 # Original epoll test is inadequate because 2.4 kernels have the header
84 # add_define 'HAVE_EPOLL' if have_header('sys/epoll.h')
85 # if have_header('sys/epoll.h')
86 # File.open("hasEpollTest.c", "w") {|f|
87 # f.puts "#include <sys/epoll.h>"
88 # f.puts "int main() { epoll_create(1024); return 0;}"
90 # (e = system( "gcc hasEpollTest.c -o hasEpollTest " )) and (e = $?.to_i)
91 # `rm -f hasEpollTest.c hasEpollTest`
92 # add_define 'HAVE_EPOLL' if e == 0
95 # on Unix we need a g++ link, not gcc.
96 CONFIG['LDSHARED'] = "$(CXX) -shared"
99 CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"
102 # on Unix we need a g++ link, not gcc.
103 CONFIG['LDSHARED'] = "$(CXX) -shared"
108 def manual_ssl_config
109 ssl_libs_heads_args = {
110 :unix => [%w[ssl crypto], %w[openssl/ssl.h openssl/err.h]],
111 :darwin => [%w[ssl crypto C], %w[openssl/ssl.h openssl/err.h]],
113 :crypto_hack => [%w[crypto ssl crypto], %w[openssl/ssl.h openssl/err.h]],
114 :mswin => [%w[ssleay32 libeay32], %w[openssl/ssl.h openssl/err.h]],
118 dc_flags += ["#{ENV['OPENSSL']}/include", ENV['OPENSSL']] if /linux/ =~ RUBY_PLATFORM
120 libs, heads = case RUBY_PLATFORM
121 when /mswin/ ; ssl_libs_heads_args[:mswin]
122 when /mingw/ ; ssl_libs_heads_args[:unix]
123 when /darwin/ ; ssl_libs_heads_args[:darwin]
124 when /openbsd/ ; ssl_libs_heads_args[:crypto_hack]
125 when /linux/ ; ssl_libs_heads_args[:crypto_hack]
126 else ssl_libs_heads_args[:unix]
128 dir_config(*dc_flags)
129 check_libs(libs) and check_heads(heads)
132 # Try to use pkg_config first, fixes #73
133 if pkg_config('openssl') || manual_ssl_config
134 add_define "WITH_SSL"
136 add_define "WITHOUT_SSL"
139 # solaris c++ compiler doesn't have make_pair()
140 TRY_LINK.sub!('$(CC)', '$(CXX)')
141 add_define 'HAVE_MAKE_PAIR' if try_link(<<SRC, '-lstdc++')
144 int main(){ pair<int,int> tuple = make_pair(1,2); }
146 TRY_LINK.sub!('$(CXX)', '$(CC)')
148 create_makefile "rubyeventmachine"