Top Level Namespace

Defined Under Namespace

Modules: Rlibmemcached Classes: Integer, Memcached

Constant Summary collapse

HERE =
File.expand_path(File.dirname(__FILE__))
BUNDLE =
Dir.glob("libmemcached-*.tar.gz").first
BUNDLE_PATH =
BUNDLE.sub(".tar.gz", "")
SOLARIS_32 =
RbConfig::CONFIG['target'] == "i386-pc-solaris2.10"

Instance Method Summary collapse

Instance Method Details

#check_libmemcachedObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'ext/extconf.rb', line 23

def check_libmemcached
  return if ENV["EXTERNAL_LIB"]

  $includes = " -I#{HERE}/include"
  $defines = " -DLIBMEMCACHED_WITH_SASL_SUPPORT"
  $libraries = " -L#{HERE}/lib"
  $CFLAGS = "#{$includes} #{$libraries} #{$CFLAGS}"
  $LDFLAGS = "#{$libraries} #{$LDFLAGS}"
  $LIBPATH = ["#{HERE}/lib"]
  $DEFLIBPATH = [] unless SOLARIS_32

  Dir.chdir(HERE) do
    if File.exist?("lib")
      puts "Libmemcached already built; run 'rake clean' first if you need to rebuild."
    else
      tar = SOLARIS_32 ? 'gtar' : 'tar'
      patch = SOLARIS_32 ? 'gpatch' : 'patch'

      # have_sasl check may fail on OSX, skip it
      # unless RUBY_PLATFORM =~ /darwin/ or have_library('sasl2')
      #   raise "SASL2 not found. You need the libsasl2-dev library, which should be provided through your system's package manager."
      # end

      puts "Building libmemcached."
      puts(cmd = "#{tar} xzf #{BUNDLE} 2>&1")
      raise "'#{cmd}' failed" unless system(cmd)

      puts "Patching libmemcached source."
      puts(cmd = "#{patch} -p1 -Z < libmemcached.patch")
      raise "'#{cmd}' failed" unless system(cmd)

      puts "Patching libmemcached with SASL support."
      puts(cmd = "#{patch} -p1 -Z < sasl.patch")
      raise "'#{cmd}' failed" unless system(cmd)

      puts "Touching aclocal.m4  in libmemcached."
      puts(cmd = "touch -r #{BUNDLE_PATH}/m4/visibility.m4 #{BUNDLE_PATH}/configure.ac #{BUNDLE_PATH}/m4/pandora_have_sasl.m4")
      raise "'#{cmd}' failed" unless system(cmd)

      Dir.chdir(BUNDLE_PATH) do
        puts(cmd = "env CFLAGS='-fPIC #{$CFLAGS}' LDFLAGS='-fPIC #{$LDFLAGS}' ./configure --prefix=#{HERE} --without-memcached --disable-shared --disable-utils --disable-dependency-tracking #{$EXTRA_CONF} 2>&1")
        raise "'#{cmd}' failed" unless system(cmd)

        puts(cmd = "make CXXFLAGS='#{$CXXFLAGS}' || true 2>&1")
        raise "'#{cmd}' failed" unless system(cmd)

        puts(cmd = "make install || true 2>&1")
        raise "'#{cmd}' failed" unless system(cmd)
      end

      system("rm -rf #{BUNDLE_PATH}") unless ENV['DEBUG'] or ENV['DEV']
    end
  end

  # Absolutely prevent the linker from picking up any other libmemcached
  Dir.chdir("#{HERE}/lib") do
    system("cp -f libmemcached.a libmemcached_gem.a")
    system("cp -f libmemcached.la libmemcached_gem.la")
  end
  $LIBS << " -lmemcached_gem -lsasl2"
end