Skip to content

Commit

Permalink
steal platform-specific C++ config from eventmachine
Browse files Browse the repository at this point in the history
It's in platform.rb.
  • Loading branch information
William Morgan committed Dec 13, 2011
1 parent a697176 commit 9062fab
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -10,7 +10,7 @@ spec = Gem::Specification.new do |s|
s.authors = ["William Morgan"] s.authors = ["William Morgan"]
s.summary = "a Ruby binding to LevelDB" s.summary = "a Ruby binding to LevelDB"
s.homepage = "http://github.com/wmorgan/leveldb-ruby" s.homepage = "http://github.com/wmorgan/leveldb-ruby"
s.files = %w(README ext/leveldb/extconf.rb lib/leveldb.rb ext/leveldb/leveldb.cc leveldb/Makefile leveldb/build_detect_platform) s.files = %w(README ext/leveldb/extconf.rb ext/leveldb/platform.rb lib/leveldb.rb ext/leveldb/leveldb.cc leveldb/Makefile leveldb/build_detect_platform)
Find.find("leveldb") { |x| s.files << x if x =~ /\.(cc|h)$/} Find.find("leveldb") { |x| s.files << x if x =~ /\.(cc|h)$/}
s.extensions = %w(ext/leveldb/extconf.rb) s.extensions = %w(ext/leveldb/extconf.rb)
s.executables = [] s.executables = []
Expand Down
8 changes: 2 additions & 6 deletions ext/leveldb/extconf.rb
@@ -1,18 +1,14 @@
require 'mkmf' require 'mkmf'
require 'fileutils' require 'fileutils'
require "./platform.rb"


Dir.chdir "../../leveldb" Dir.chdir "../../leveldb"
system "make libleveldb.a" or abort system "make libleveldb.a" or abort
Dir.chdir "../ext/leveldb" Dir.chdir "../ext/leveldb"


CONFIG['LDSHARED'] = "$(CXX) -shared" set_platform_specific_variables!


$CFLAGS << " -I../../leveldb/include" $CFLAGS << " -I../../leveldb/include"
$LIBS << " -L../../leveldb -lleveldb" $LIBS << " -L../../leveldb -lleveldb"
if RUBY_PLATFORM =~ /darwin/
$CFLAGS.sub! "-arch i386", ""
$LDFLAGS.sub! "-arch i386", ""
$LIBS << " -lruby" # whyyyyy
end


create_makefile "leveldb/leveldb" create_makefile "leveldb/leveldb"
83 changes: 83 additions & 0 deletions ext/leveldb/platform.rb
@@ -0,0 +1,83 @@
## here lies some platform-specific C++ compile and link environment
## variable hacking.
##
## this code is entirely stolen from eventmachine's extconf.rb. many
## thanks to @tmm1 for the pointer.

def check_libs libs=[], fatal=false
libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
end

def check_heads heads=[], fatal=false
heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
end

def add_define name; $defs.push "-D#{name}" end

def set_platform_specific_variables!
puts "setting build environment for #{RUBY_PLATFORM}..."
case RUBY_PLATFORM
when /mswin32/, /mingw32/, /bccwin32/
check_heads(%w[windows.h winsock.h], true)
check_libs(%w[kernel32 rpcrt4 gdi32], true)

if GNU_CHAIN
CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
else
$defs.push "-EHs"
$defs.push "-GR"
end

when /solaris/
add_define 'OS_SOLARIS8'
check_libs(%w[nsl socket], true)

if CONFIG['CC'] == 'cc' and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
# SUN CHAIN
add_define 'CC_SUNWspro'
$preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
$CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
CONFIG['CCDLFLAGS'] = "-KPIC"
CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
else
# GNU CHAIN
# on Unix we need a g++ link, not gcc.
CONFIG['LDSHARED'] = "$(CXX) -shared"
end

when /openbsd/
# OpenBSD branch contributed by Guillaume Sellier.

# 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++ -fPIC"
CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"

when /darwin/
# 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/
add_define 'HAVE_EPOLL' if have_func('epoll_create', 'sys/epoll.h')

# on Unix we need a g++ link, not gcc.
CONFIG['LDSHARED'] = "$(CXX) -shared"

when /aix/
CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"

when /cygwin/
# For rubies built with Cygwin, CXX may be set to CC, which is just
# a wrapper for gcc.
# This will compile, but it will not link to the C++ std library.
# Explicitly set CXX to use g++.
CONFIG['CXX'] = "g++"
# on Unix we need a g++ link, not gcc.
CONFIG['LDSHARED'] = "$(CXX) -shared"

else
# on Unix we need a g++ link, not gcc.
CONFIG['LDSHARED'] = "$(CXX) -shared"
end
end

0 comments on commit 9062fab

Please sign in to comment.