PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/eventmachine/ext/extconf.rb

https://bitbucket.org/sledzias/sr
Ruby | 176 lines | 118 code | 34 blank | 24 comment | 25 complexity | 7e8db861ddec9d443a40d31c4984ff02 MD5 | raw file
Possible License(s): LGPL-2.1
  1. require 'fileutils'
  2. require 'mkmf'
  3. def check_libs libs = [], fatal = false
  4. libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
  5. end
  6. def check_heads heads = [], fatal = false
  7. heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
  8. end
  9. def add_define(name)
  10. $defs.push("-D#{name}")
  11. end
  12. ##
  13. # OpenSSL:
  14. # override append_library, so it actually appends (instead of prepending)
  15. # this fixes issues with linking ssl, since libcrypto depends on symbols in libssl
  16. def append_library(libs, lib)
  17. libs + " " + format(LIBARG, lib)
  18. end
  19. def manual_ssl_config
  20. ssl_libs_heads_args = {
  21. :unix => [%w[ssl crypto], %w[openssl/ssl.h openssl/err.h]],
  22. :mswin => [%w[ssleay32 eay32], %w[openssl/ssl.h openssl/err.h]],
  23. }
  24. dc_flags = ['ssl']
  25. dc_flags += ["#{ENV['OPENSSL']}/include", ENV['OPENSSL']] if /linux/ =~ RUBY_PLATFORM and ENV['OPENSSL']
  26. libs, heads = case RUBY_PLATFORM
  27. when /mswin/ ; ssl_libs_heads_args[:mswin]
  28. else ssl_libs_heads_args[:unix]
  29. end
  30. dir_config(*dc_flags)
  31. check_libs(libs) and check_heads(heads)
  32. end
  33. if ENV['CROSS_COMPILING']
  34. openssl_version = ENV.fetch("OPENSSL_VERSION", "1.0.0j")
  35. openssl_dir = File.expand_path("~/.rake-compiler/builds/openssl-#{openssl_version}/")
  36. if File.exists?(openssl_dir)
  37. FileUtils.mkdir_p Dir.pwd+"/openssl/"
  38. FileUtils.cp Dir[openssl_dir+"/include/openssl/*.h"], Dir.pwd+"/openssl/", :verbose => true
  39. FileUtils.cp Dir[openssl_dir+"/lib*.a"], Dir.pwd, :verbose => true
  40. $INCFLAGS << " -I#{Dir.pwd}" # for the openssl headers
  41. else
  42. STDERR.puts
  43. STDERR.puts "**************************************************************************************"
  44. STDERR.puts "**** Cross-compiled OpenSSL not found"
  45. STDERR.puts "**** Run: hg clone http://bitbucket.org/ged/ruby-pg && cd ruby-pg && rake openssl_libs"
  46. STDERR.puts "**************************************************************************************"
  47. STDERR.puts
  48. end
  49. end
  50. # Try to use pkg_config first, fixes #73
  51. if (!ENV['CROSS_COMPILING'] and pkg_config('openssl')) || manual_ssl_config
  52. add_define "WITH_SSL"
  53. else
  54. add_define "WITHOUT_SSL"
  55. end
  56. add_define 'BUILD_FOR_RUBY'
  57. add_define 'HAVE_RBTRAP' if have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
  58. add_define "HAVE_TBR" if have_func('rb_thread_blocking_region')# and have_macro('RUBY_UBF_IO', 'ruby.h')
  59. add_define "HAVE_INOTIFY" if inotify = have_func('inotify_init', 'sys/inotify.h')
  60. add_define "HAVE_OLD_INOTIFY" if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
  61. add_define 'HAVE_WRITEV' if have_func('writev', 'sys/uio.h')
  62. have_func('rb_thread_check_ints')
  63. have_func('rb_time_new')
  64. # Minor platform details between *nix and Windows:
  65. if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
  66. GNU_CHAIN = ENV['CROSS_COMPILING'] || $1 == 'mingw'
  67. OS_WIN32 = true
  68. add_define "OS_WIN32"
  69. else
  70. GNU_CHAIN = true
  71. OS_UNIX = true
  72. add_define 'OS_UNIX'
  73. add_define "HAVE_KQUEUE" if have_header("sys/event.h") and have_header("sys/queue.h")
  74. end
  75. # Adjust number of file descriptors (FD) on Windows
  76. if RbConfig::CONFIG["host_os"] =~ /mingw/
  77. found = RbConfig::CONFIG.values_at("CFLAGS", "CPPFLAGS").
  78. any? { |v| v.include?("FD_SETSIZE") }
  79. add_define "FD_SETSIZE=32767" unless found
  80. end
  81. # Main platform invariances:
  82. case RUBY_PLATFORM
  83. when /mswin32/, /mingw32/, /bccwin32/
  84. check_heads(%w[windows.h winsock.h], true)
  85. check_libs(%w[kernel32 rpcrt4 gdi32], true)
  86. if GNU_CHAIN
  87. CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
  88. else
  89. $defs.push "-EHs"
  90. $defs.push "-GR"
  91. end
  92. when /solaris/
  93. add_define 'OS_SOLARIS8'
  94. check_libs(%w[nsl socket], true)
  95. if CONFIG['CC'] == 'cc' and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
  96. # SUN CHAIN
  97. add_define 'CC_SUNWspro'
  98. $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
  99. $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
  100. CONFIG['CCDLFLAGS'] = "-KPIC"
  101. CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
  102. else
  103. # GNU CHAIN
  104. # on Unix we need a g++ link, not gcc.
  105. CONFIG['LDSHARED'] = "$(CXX) -shared"
  106. end
  107. when /openbsd/
  108. # OpenBSD branch contributed by Guillaume Sellier.
  109. # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
  110. CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
  111. CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
  112. when /darwin/
  113. # on Unix we need a g++ link, not gcc.
  114. # Ff line contributed by Daniel Harple.
  115. CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
  116. when /linux/
  117. add_define 'HAVE_EPOLL' if have_func('epoll_create', 'sys/epoll.h')
  118. # on Unix we need a g++ link, not gcc.
  119. CONFIG['LDSHARED'] = "$(CXX) -shared"
  120. when /aix/
  121. CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"
  122. when /cygwin/
  123. # For rubies built with Cygwin, CXX may be set to CC, which is just
  124. # a wrapper for gcc.
  125. # This will compile, but it will not link to the C++ std library.
  126. # Explicitly set CXX to use g++.
  127. CONFIG['CXX'] = "g++"
  128. # on Unix we need a g++ link, not gcc.
  129. CONFIG['LDSHARED'] = "$(CXX) -shared"
  130. else
  131. # on Unix we need a g++ link, not gcc.
  132. CONFIG['LDSHARED'] = "$(CXX) -shared"
  133. end
  134. # solaris c++ compiler doesn't have make_pair()
  135. TRY_LINK.sub!('$(CC)', '$(CXX)')
  136. add_define 'HAVE_MAKE_PAIR' if try_link(<<SRC, '-lstdc++')
  137. #include <utility>
  138. using namespace std;
  139. int main(){ pair<int,int> tuple = make_pair(1,2); }
  140. SRC
  141. TRY_LINK.sub!('$(CXX)', '$(CC)')
  142. create_makefile "rubyeventmachine"