PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/vendor/ruby/2.2.0/gems/eventmachine-1.2.3/ext/extconf.rb

https://bitbucket.org/saranyutcr/client_cinestaan_cms
Ruby | 270 lines | 180 code | 43 blank | 47 comment | 39 complexity | cfad416f8b4d01701a7abc67a5d5cfd4 MD5 | raw file
Possible License(s): MIT, CC-BY-SA-3.0, BSD-3-Clause, 0BSD, Apache-2.0, JSON
  1. require 'fileutils'
  2. require 'mkmf'
  3. # Eager check devs tools
  4. have_devel? if respond_to?(:have_devel?)
  5. def check_libs libs = [], fatal = false
  6. libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
  7. end
  8. def check_heads heads = [], fatal = false
  9. heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
  10. end
  11. def add_define(name)
  12. $defs.push("-D#{name}")
  13. end
  14. ##
  15. # OpenSSL:
  16. # override append_library, so it actually appends (instead of prepending)
  17. # this fixes issues with linking ssl, since libcrypto depends on symbols in libssl
  18. def append_library(libs, lib)
  19. libs + " " + format(LIBARG, lib)
  20. end
  21. SSL_HEADS = %w(openssl/ssl.h openssl/err.h)
  22. SSL_LIBS = case RUBY_PLATFORM
  23. when /mswin|mingw|bccwin/ ; %w(ssleay32 libeay32)
  24. else ; %w(crypto ssl)
  25. end
  26. def dir_config_wrapper(pretty_name, name, idefault=nil, ldefault=nil)
  27. inc, lib = dir_config(name, idefault, ldefault)
  28. if inc && lib
  29. # TODO: Remove when 2.0.0 is the minimum supported version
  30. # Ruby versions not incorporating the mkmf fix at
  31. # https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39717
  32. # do not properly search for lib directories, and must be corrected
  33. unless lib && lib[-3, 3] == 'lib'
  34. @libdir_basename = 'lib'
  35. inc, lib = dir_config(name, idefault, ldefault)
  36. end
  37. unless idefault && ldefault
  38. abort "-----\nCannot find #{pretty_name} include path #{inc}\n-----" unless inc && inc.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
  39. abort "-----\nCannot find #{pretty_name} library path #{lib}\n-----" unless lib && lib.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
  40. warn "-----\nUsing #{pretty_name} in path #{File.dirname inc}\n-----"
  41. end
  42. true
  43. end
  44. end
  45. def dir_config_search(pretty_name, name, paths, &b)
  46. paths.each do |p|
  47. if dir_config_wrapper('OpenSSL', 'ssl', p + '/include', p + '/lib') && yield
  48. warn "-----\nFound #{pretty_name} in path #{p}\n-----"
  49. return true
  50. end
  51. end
  52. false
  53. end
  54. def pkg_config_wrapper(pretty_name, name)
  55. cflags, ldflags, libs = pkg_config(name)
  56. unless [cflags, ldflags, libs].any?(&:nil?) || [cflags, ldflags, libs].any?(&:empty?)
  57. warn "-----\nUsing #{pretty_name} from pkg-config #{cflags} && #{ldflags} && #{libs}\n-----"
  58. true
  59. end
  60. end
  61. if ENV['CROSS_COMPILING']
  62. openssl_version = ENV.fetch("OPENSSL_VERSION", "1.0.2e")
  63. openssl_dir = File.expand_path("~/.rake-compiler/builds/openssl-#{openssl_version}/")
  64. if File.exist?(openssl_dir)
  65. FileUtils.mkdir_p Dir.pwd+"/openssl/"
  66. FileUtils.cp Dir[openssl_dir+"/include/openssl/*.h"], Dir.pwd+"/openssl/", :verbose => true
  67. FileUtils.cp Dir[openssl_dir+"/lib*.a"], Dir.pwd, :verbose => true
  68. $INCFLAGS << " -I#{Dir.pwd}" # for the openssl headers
  69. add_define "WITH_SSL"
  70. else
  71. STDERR.puts
  72. STDERR.puts "**************************************************************************************"
  73. STDERR.puts "**** Cross-compiled OpenSSL not found"
  74. STDERR.puts "**** Run: hg clone http://bitbucket.org/ged/ruby-pg && cd ruby-pg && rake openssl_libs"
  75. STDERR.puts "**************************************************************************************"
  76. STDERR.puts
  77. end
  78. elsif dir_config_wrapper('OpenSSL', 'ssl')
  79. # If the user has provided a --with-ssl-dir argument, we must respect it or fail.
  80. add_define 'WITH_SSL' if check_libs(SSL_LIBS) && check_heads(SSL_HEADS)
  81. elsif pkg_config_wrapper('OpenSSL', 'openssl')
  82. # If we can detect OpenSSL by pkg-config, use it as the next-best option
  83. add_define 'WITH_SSL' if check_libs(SSL_LIBS) && check_heads(SSL_HEADS)
  84. elsif check_libs(SSL_LIBS) && check_heads(SSL_HEADS)
  85. # If we don't even need any options to find a usable OpenSSL, go with it
  86. add_define 'WITH_SSL'
  87. elsif dir_config_search('OpenSSL', 'ssl', ['/usr/local', '/opt/local', '/usr/local/opt/openssl']) do
  88. check_libs(SSL_LIBS) && check_heads(SSL_HEADS)
  89. end
  90. # Finally, look for OpenSSL in alternate locations including MacPorts and HomeBrew
  91. add_define 'WITH_SSL'
  92. end
  93. add_define 'BUILD_FOR_RUBY'
  94. # Ruby features:
  95. have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
  96. have_func('rb_thread_blocking_region')
  97. have_func('rb_thread_call_without_gvl', 'ruby/thread.h')
  98. have_func('rb_thread_fd_select')
  99. have_type('rb_fdset_t', 'ruby/intern.h')
  100. have_func('rb_wait_for_single_fd')
  101. have_func('rb_enable_interrupt')
  102. have_func('rb_time_new')
  103. # System features:
  104. add_define('HAVE_INOTIFY') if inotify = have_func('inotify_init', 'sys/inotify.h')
  105. add_define('HAVE_OLD_INOTIFY') if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
  106. have_func('writev', 'sys/uio.h')
  107. have_func('pipe2', 'unistd.h')
  108. have_func('accept4', 'sys/socket.h')
  109. have_const('SOCK_CLOEXEC', 'sys/socket.h')
  110. # Minor platform details between *nix and Windows:
  111. if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
  112. GNU_CHAIN = ENV['CROSS_COMPILING'] || $1 == 'mingw'
  113. OS_WIN32 = true
  114. add_define "OS_WIN32"
  115. else
  116. GNU_CHAIN = true
  117. OS_UNIX = true
  118. add_define 'OS_UNIX'
  119. add_define "HAVE_KQUEUE" if have_header("sys/event.h") && have_header("sys/queue.h")
  120. end
  121. # Adjust number of file descriptors (FD) on Windows
  122. if RbConfig::CONFIG["host_os"] =~ /mingw/
  123. found = RbConfig::CONFIG.values_at("CFLAGS", "CPPFLAGS").
  124. any? { |v| v.include?("FD_SETSIZE") }
  125. add_define "FD_SETSIZE=32767" unless found
  126. end
  127. # Main platform invariances:
  128. case RUBY_PLATFORM
  129. when /mswin32/, /mingw32/, /bccwin32/
  130. check_heads(%w[windows.h winsock.h], true)
  131. check_libs(%w[kernel32 rpcrt4 gdi32], true)
  132. if GNU_CHAIN
  133. CONFIG['LDSHAREDXX'] = "$(CXX) -shared -static-libgcc -static-libstdc++"
  134. else
  135. $defs.push "-EHs"
  136. $defs.push "-GR"
  137. end
  138. # Newer versions of Ruby already define _WIN32_WINNT, which is needed
  139. # to get access to newer POSIX networking functions (e.g. getaddrinfo)
  140. add_define '_WIN32_WINNT=0x0501' unless have_func('getaddrinfo')
  141. when /solaris/
  142. add_define 'OS_SOLARIS8'
  143. check_libs(%w[nsl socket], true)
  144. # If Ruby was compiled for 32-bits, then select() can only handle 1024 fds
  145. # There is an alternate function, select_large_fdset, that supports more.
  146. have_func('select_large_fdset', 'sys/select.h')
  147. if CONFIG['CC'] == 'cc' && (
  148. `cc -flags 2>&1` =~ /Sun/ || # detect SUNWspro compiler
  149. `cc -V 2>&1` =~ /Sun/ # detect Solaris Studio compiler
  150. )
  151. # SUN CHAIN
  152. add_define 'CC_SUNWspro'
  153. $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
  154. $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
  155. CONFIG['CCDLFLAGS'] = "-KPIC"
  156. CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
  157. CONFIG['LDSHAREDXX'] = "$(CXX) -G -KPIC -lCstd"
  158. else
  159. # GNU CHAIN
  160. # on Unix we need a g++ link, not gcc.
  161. CONFIG['LDSHARED'] = "$(CXX) -shared"
  162. end
  163. when /openbsd/
  164. # OpenBSD branch contributed by Guillaume Sellier.
  165. # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
  166. CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
  167. CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
  168. when /darwin/
  169. add_define 'OS_DARWIN'
  170. # on Unix we need a g++ link, not gcc.
  171. # Ff line contributed by Daniel Harple.
  172. CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
  173. when /linux/
  174. add_define 'HAVE_EPOLL' if have_func('epoll_create', 'sys/epoll.h')
  175. # on Unix we need a g++ link, not gcc.
  176. CONFIG['LDSHARED'] = "$(CXX) -shared"
  177. when /aix/
  178. CONFIG['LDSHARED'] = "$(CXX) -Wl,-bstatic -Wl,-bdynamic -Wl,-G -Wl,-brtl"
  179. when /cygwin/
  180. # For rubies built with Cygwin, CXX may be set to CC, which is just
  181. # a wrapper for gcc.
  182. # This will compile, but it will not link to the C++ std library.
  183. # Explicitly set CXX to use g++.
  184. CONFIG['CXX'] = "g++"
  185. # on Unix we need a g++ link, not gcc.
  186. CONFIG['LDSHARED'] = "$(CXX) -shared"
  187. else
  188. # on Unix we need a g++ link, not gcc.
  189. CONFIG['LDSHARED'] = "$(CXX) -shared"
  190. end
  191. # Platform-specific time functions
  192. if have_func('clock_gettime')
  193. # clock_gettime is POSIX, but the monotonic clocks are not
  194. have_const('CLOCK_MONOTONIC_RAW', 'time.h') # Linux
  195. have_const('CLOCK_MONOTONIC', 'time.h') # Linux, Solaris, BSDs
  196. else
  197. have_func('gethrtime') # Older Solaris and HP-UX
  198. end
  199. # Hack so that try_link will test with a C++ compiler instead of a C compiler
  200. TRY_LINK.sub!('$(CC)', '$(CXX)')
  201. # This is our wishlist. We use whichever flags work on the host.
  202. # In the future, add -Werror to make sure all warnings are resolved.
  203. # deprecated-declarations are used in OS X OpenSSL
  204. # ignored-qualifiers are used by the Bindings (would-be void *)
  205. # unused-result because GCC 4.6 no longer silences (void) ignore_this(function)
  206. # address because on Windows, rb_fd_select checks if &fds is non-NULL, which it cannot be
  207. %w(
  208. -Wall
  209. -Wextra
  210. -Wno-deprecated-declarations
  211. -Wno-ignored-qualifiers
  212. -Wno-unused-result
  213. -Wno-address
  214. ).select do |flag|
  215. try_link('int main() {return 0;}', flag)
  216. end.each do |flag|
  217. CONFIG['CXXFLAGS'] << ' ' << flag
  218. end
  219. puts "CXXFLAGS=#{CONFIG['CXXFLAGS']}"
  220. # Solaris C++ compiler doesn't have make_pair()
  221. add_define 'HAVE_MAKE_PAIR' if try_link(<<SRC, '-lstdc++')
  222. #include <utility>
  223. using namespace std;
  224. int main(){ pair<const int,int> tuple = make_pair(1,2); }
  225. SRC
  226. TRY_LINK.sub!('$(CXX)', '$(CC)')
  227. create_makefile "rubyeventmachine"