Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extconf.rb, so gem can be built. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions ext/memcached/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,54 @@
abort 'Please install SASL to continue. The package is called libsasl2-dev on Ubuntu and cyrus-sasl on Gentoo.'
end

HERE = File.expand_path(File.dirname(__FILE__))
LIBMEMCACHED_DIR = Dir.glob(File.join(HERE, '..', '..', 'vendor','libmemcached-1.0.18')).first
HERE = __dir__
LIBMEMCACHED_DIR = Dir.glob(File.join(HERE, '..', '..', 'vendor', 'libmemcached-1.0.18')).first

SOLARIS_32 = RbConfig::CONFIG['target'] == "i386-pc-solaris2.10"
SOLARIS_32 = RbConfig::CONFIG['target'] == 'i386-pc-solaris2.10'
BSD = RbConfig::CONFIG['host_os'].downcase =~ /bsd/

$CFLAGS = "#{RbConfig::CONFIG['CFLAGS']} #{$CFLAGS}".gsub("$(cflags)", "").gsub("-fno-common", "").gsub("-Wdeclaration-after-statement", "")
$CFLAGS << " -Os"
$CFLAGS << " -std=gnu99" if SOLARIS_32
$CFLAGS << " -I/usr/local/include" if BSD
$EXTRA_CONF = " --disable-64bit" if SOLARIS_32
$LDFLAGS = "#{RbConfig::CONFIG['LDFLAGS']} #{$LDFLAGS} -L#{RbConfig::CONFIG['libdir']}".gsub("$(ldflags)", "").gsub("-fno-common", "")
$CFLAGS = "#{RbConfig::CONFIG['CFLAGS']} #{$CFLAGS}".gsub('$(cflags)', '').gsub('-fno-common', '').gsub(
'-Wdeclaration-after-statement', ''
)
$CFLAGS << ' -Os'
$CFLAGS << ' -std=gnu99' if SOLARIS_32
$CFLAGS << ' -I/usr/local/include' if BSD
$EXTRA_CONF = ' --disable-64bit' if SOLARIS_32
$LDFLAGS = "#{RbConfig::CONFIG['LDFLAGS']} #{$LDFLAGS} -L#{RbConfig::CONFIG['libdir']}".gsub('$(ldflags)', '').gsub(
'-fno-common', ''
)
$CXXFLAGS = "#{RbConfig::CONFIG['CXXFLAGS']} -fPIC"
$CC = "CC=#{RbConfig::MAKEFILE_CONFIG["CC"].inspect}"
$CC = "CC=#{RbConfig::MAKEFILE_CONFIG['CC'].inspect}"

# JRuby's default configure options can't build libmemcached properly
LIBM_CFLAGS = defined?(JRUBY_VERSION) ? "-fPIC -g -O2" : $CFLAGS
LIBM_LDFLAGS = defined?(JRUBY_VERSION) ? "-fPIC -lsasl2 -lm" : $LDFLAGS
LIBM_CFLAGS = defined?(JRUBY_VERSION) ? '-fPIC -g -O2' : $CFLAGS
LIBM_LDFLAGS = defined?(JRUBY_VERSION) ? '-fPIC -lsasl2 -lm' : $LDFLAGS

GMAKE_CMD = RbConfig::CONFIG['host_os'].downcase =~ /bsd|solaris/ ? "gmake" : "make"
GMAKE_CMD = RbConfig::CONFIG['host_os'].downcase =~ /bsd|solaris/ ? 'gmake' : 'make'

if ENV['DEBUG']
puts "Setting debug flags."
$CFLAGS << " -O0 -ggdb -DHAVE_DEBUG"
$EXTRA_CONF = ""
puts 'Setting debug flags.'
$CFLAGS << ' -O0 -ggdb -DHAVE_DEBUG'
$EXTRA_CONF = ''
end

def compile_libmemcached
return if ENV["EXTERNAL_LIB"]
return if ENV['EXTERNAL_LIB']

Dir.chdir(LIBMEMCACHED_DIR) do
Dir.mkdir("build") if !Dir.exists?("build")
build_folder = File.join(LIBMEMCACHED_DIR, "build")
Dir.mkdir('build') unless Dir.exist?('build')
build_folder = File.join(LIBMEMCACHED_DIR, 'build')

ts_now=(Time.now - 1800).strftime("%Y%m%d%H%M.%S")
ts_now = (Time.now - 1800).strftime('%Y%m%d%H%M.%S')
run("find . | xargs touch -t #{ts_now}", "Touching all files so autoconf doesn't run.")
run("env CFLAGS='-fPIC #{LIBM_CFLAGS}' LDFLAGS='-fPIC #{LIBM_LDFLAGS}' ./configure --prefix=#{build_folder} --libdir=#{build_folder}/lib --with-pic --without-memcached --disable-shared --disable-util\
s --disable-dependency-tracking #{$CC} #{$EXTRA_CONF} 2>&1", "Configuring libmemcached.")
s --disable-dependency-tracking #{$CC} #{$EXTRA_CONF} 2>&1", 'Configuring libmemcached.')
run("#{GMAKE_CMD} clean 2>&1")
run("#{GMAKE_CMD} CXXFLAGS='#{$CXXFLAGS}' 2>&1")
run("#{GMAKE_CMD} install 2>&1")

pcfile = File.join(LIBMEMCACHED_DIR, "build", "lib", "pkgconfig", "libmemcached.pc")
$LDFLAGS << " -lsasl2 " + `pkg-config --libs --static #{pcfile}`.strip
pcfile = File.join(LIBMEMCACHED_DIR, 'build', 'lib', 'pkgconfig', 'libmemcached.pc')
$LDFLAGS << ' -lsasl2 ' + `pkg-config --libs --static #{pcfile}`.strip
end
$DEFLIBPATH.unshift("#{LIBMEMCACHED_DIR}/build")
dir_config('memcached', "#{LIBMEMCACHED_DIR}/build/include", "#{LIBMEMCACHED_DIR}/build/lib")
Expand All @@ -62,10 +66,8 @@ def run(cmd, reason = nil)

compile_libmemcached

$libs = append_library($libs, "stdc++")
$libs = append_library($libs, 'stdc++')

unless have_library 'memcached' and have_header 'libmemcached/memcached.h'
abort "ERROR: Failed to build libmemcached"
end
abort 'ERROR: Failed to build libmemcached' unless have_library 'memcached' and have_header 'libmemcached/memcached.h'

create_makefile 'memcached'