summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-05-14 13:24:06 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-05-14 13:24:06 -0700
commit6fa5b34dad219934944524af35904c8bd25f3a42 (patch)
tree75dd7617c9d484546ab0141bd96d69f64fea1b7c
parent42f473d07ae41cacc4e4b02a4a340142085843d0 (diff)
downloadlibyajl2-gem-6fa5b34dad219934944524af35904c8bd25f3a42.tar.gz
refator to remove cmake
mkmf.rb sucks as well, so roll our own
-rw-r--r--Rakefile48
-rw-r--r--ext/libyajl2/Makefile12
-rw-r--r--ext/libyajl2/extconf.rb212
-rw-r--r--libyajl2.gemspec1
4 files changed, 217 insertions, 56 deletions
diff --git a/Rakefile b/Rakefile
index 11c2d71..c979c8a 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,6 +5,7 @@ require 'rake'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
+require 'rake/extensiontask'
GEM_NAME = "libyajl2"
@@ -18,27 +19,32 @@ end
# build tasks
#
-desc "repackage and install #{GEM_NAME}-#{Libyajl2::VERSION}.gem"
-task :install => :repackage do
- sh %{gem install pkg/#{GEM_NAME}-#{Libyajl2::VERSION}.gem --no-rdoc --no-ri}
-end
-
-desc "uninstall #{GEM_NAME}-#{Libyajl2::VERSION}.gem"
-task :uninstall do
- sh %{gem uninstall #{GEM_NAME} -x -v #{Libyajl2::VERSION} }
-end
-
-desc "compile native gem"
-task :compile do
- cd "ext/libyajl2"
- ruby "extconf.rb"
-end
-
-desc "clean the git repo"
-task :clean do
- sh "git clean -fdx"
- cd "ext/libyajl2/vendor/yajl"
- sh "git clean -fdx"
+#desc "repackage and install #{GEM_NAME}-#{Libyajl2::VERSION}.gem"
+#task :install => :repackage do
+# sh %{gem install pkg/#{GEM_NAME}-#{Libyajl2::VERSION}.gem --no-rdoc --no-ri}
+#end
+#
+#desc "uninstall #{GEM_NAME}-#{Libyajl2::VERSION}.gem"
+#task :uninstall do
+# sh %{gem uninstall #{GEM_NAME} -x -v #{Libyajl2::VERSION} }
+#end
+#
+#desc "compile native gem"
+#task :compile do
+# cd "ext/libyajl2"
+# ruby "extconf.rb"
+#end
+#
+#desc "clean the git repo"
+#task :clean do
+# sh "git clean -fdx"
+# cd "ext/libyajl2/vendor/yajl"
+# sh "git clean -fdx"
+#end
+
+Rake::ExtensionTask.new('libyajl', gemspec) do |ext|
+ ext.lib_dir = 'lib/libyajl2/vendored-libyajl2'
+ ext.ext_dir = 'ext/libyajl2'
end
# FIXME: need a rake task to update the git submodule and need to do that before shipping
diff --git a/ext/libyajl2/Makefile b/ext/libyajl2/Makefile
index 215b8c1..e8aef79 100644
--- a/ext/libyajl2/Makefile
+++ b/ext/libyajl2/Makefile
@@ -1,7 +1,9 @@
-# We do all the work in extconf.rb, so we just have a dummy makefile here to
-# make rubygems happy.
-
+TARGET = libyajl
+DLLIB = $(TARGET).bundle
all:
-
+ cd /Users/lamont/git/libyajl2-gem/ext/libyajl2/vendor/yajl/src && make
+ cp /Users/lamont/git/libyajl2-gem/ext/libyajl2/vendor/yajl/src/$(DLLIB) .
install:
-
+ cp $(DLLIB) /Users/lamont/git/libyajl2-gem/lib/libyajl2/vendored-libyajl2
+clean:
+ cd /Users/lamont/git/libyajl2-gem/ext/libyajl2/vendor/yajl/src && make clean
diff --git a/ext/libyajl2/extconf.rb b/ext/libyajl2/extconf.rb
index 9f65a60..1eb9229 100644
--- a/ext/libyajl2/extconf.rb
+++ b/ext/libyajl2/extconf.rb
@@ -1,5 +1,6 @@
exit(0) if ENV["USE_SYSTEM_LIBYAJL2"]
+require 'rbconfig'
require 'pp'
module Libyajl2Build
@@ -17,31 +18,31 @@ module Libyajl2Build
LIBYAJL2_VENDOR_DIR
end
- def self.configure
- File.join(LIBYAJL2_VENDOR_DIR, "configure")
- end
-
def self.prefix
PREFIX
end
- def self.configure_cmd
- # NB: this is not a gnu configure command
- %W[
- sh
- #{configure}
- -p
- #{prefix}
- ]
+ def self.setup_env
end
- def self.setup_env
- if windows?
- ENV['PATH'] ||= 'C:\Ruby\DevKit\bin;C:\Ruby\DevKit\mingw\bin;' + ENV['PATH']
- ENV['RI_DEVKIT'] ||= 'C:\Ruby\DevKit'
- ENV['CC'] ||= 'gcc'
- ENV['CPP'] ||= 'cpp'
- ENV['CXX'] ||= 'g++'
+ # for mkmf.rb compat
+ CONFIG = RbConfig::MAKEFILE_CONFIG
+
+ def self.mkintpath(path)
+ case CONFIG['build_os']
+ when 'mingw32'
+ path = path.dup
+ path.tr!('\\', '/')
+ path.sub!(/\A([A-Za-z]):(?=\/)/, '/\1')
+ path
+ when 'cygwin'
+ if CONFIG['target_os'] != 'cygwin'
+ IO.popen(["cygpath", "-u", path], &:read).chomp
+ else
+ path
+ end
+ else
+ path
end
end
@@ -50,20 +51,171 @@ module Libyajl2Build
super(*args)
end
- def self.run_build_commands
- setup_env
- puts `pwd`
- puts `env`
- puts configure_cmd
- system(*configure_cmd) &&
- system("make", "-j", "5", "install")
+ # since we're not using cmake we have to mangle up yajl_version.h ourselves
+ def self.generate_yajl_version
+ yajl_major = yajl_minor = yajl_micro = nil
+ File.open("#{libyajl2_vendor_dir}/CMakeLists.txt").each do |line|
+ if m = line.match(/YAJL_MAJOR (\d+)/)
+ yajl_major = m[1]
+ end
+ if m = line.match(/YAJL_MINOR (\d+)/)
+ yajl_minor = m[1]
+ end
+ if m = line.match(/YAJL_MICRO (\d+)/)
+ yajl_micro = m[1]
+ end
+ end
+ File.open("#{libyajl2_vendor_dir}/src/api/yajl_version.h", "w+") do |out|
+ File.open("#{libyajl2_vendor_dir}/src/api/yajl_version.h.cmake").each do |line|
+ line.gsub!(/\$\{YAJL_MAJOR\}/, yajl_major)
+ line.gsub!(/\$\{YAJL_MINOR\}/, yajl_minor)
+ line.gsub!(/\$\{YAJL_MICRO\}/, yajl_micro)
+ out.write(line)
+ end
+ end
end
- def self.run
- Dir.chdir(libyajl2_vendor_dir) do
- run_build_commands or raise BuildError, "Failed to build libyajl2 library."
+ def self.yajl_makefile
+ File.open("Makefile", "w+") do |f|
+ f.write <<EOF
+SHELL = /bin/sh
+
+# V=0 quiet, V=1 verbose. other values don't work.
+V = 0
+Q1 = $(V:1=)
+Q = $(Q1:0=@)
+ECHO1 = $(V:1=@:)
+ECHO = $(ECHO1:0=@echo)
+
+#### Start of system configuration section. ####
+
+srcdir = .
+prefix = #{mkintpath(CONFIG['prefix'])}
+rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
+exec_prefix = $(prefix)
+sitearchdir = $(sitelibdir)/$(sitearch)
+sitelibdir = $(sitedir)/$(ruby_version)
+sitedir = $(rubylibprefix)/site_ruby
+libdir = $(exec_prefix)/lib
+
+CC = #{CONFIG['CC']}
+empty =
+COUTFLAG = #{CONFIG['COUTFLAG']}$(empty)
+
+cflags = #{CONFIG['cflags']}
+optflags = #{CONFIG['optflags']}
+debugflags = #{CONFIG['debugflags']}
+warnflags = #{CONFIG['warnflags']}
+CCDLFLAGS = #{CONFIG['CCDLFLAGS']}
+CFLAGS = $(CCDLFLAGS) -I#{libyajl2_vendor_dir}/src/api -I. #{CONFIG['CFLAGS']} $(ARCH_FLAG)
+INCFLAGS = -I. -I$(srcdir)
+DEFS = #{CONFIG['DEFS']}
+CPPFLAGS = #{CONFIG['CPPFLAGS']} $(cppflags)
+ldflags = #{CONFIG['LDFLAGS']}
+#dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress
+dldflags = #{CONFIG['DLDFLAGS']} #{CONFIG['EXTDLDFLAGS']}
+ARCH_FLAG = #{CONFIG['ARCH_FLAG']}
+DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
+LDSHARED = #{CONFIG['LDSHARED']}
+
+RUBY_INSTALL_NAME = #{CONFIG['RUBY_INSTALL_NAME']}
+RUBY_SO_NAME = #{CONFIG['RUBY_SO_NAME']}
+RUBYW_INSTALL_NAME = #{CONFIG['RUBYW_INSTALL_NAME']}
+RUBY_VERSION_NAME = #{CONFIG['RUBY_VERSION_NAME']}
+RUBYW_BASE_NAME = #{CONFIG['RUBYW_BASE_NAME']}
+RUBY_BASE_NAME = #{CONFIG['RUBY_BASE_NAME']}
+
+arch = #{CONFIG['arch']}
+sitearch = #{CONFIG['sitearch']}
+ruby_version = #{RbConfig::CONFIG['ruby_version']}
+ruby = #{File.join(RbConfig::CONFIG["bindir"], CONFIG["ruby_install_name"])}
+RUBY = $(ruby)
+
+RM = $(RUBY) -run -e rm -- -f
+MAKEDIRS = $(RUBY) -run -e mkdir -- -p
+INSTALL = $(RUBY) -run -e install -- -vp
+INSTALL_PROG = $(INSTALL) -m 0755
+TOUCH = exit >
+
+#### End of system configuration section. ####
+
+libpath = . $(libdir)
+LIBPATH = -L. -L$(libdir)
+
+CLEANFILES = mkmf.log
+
+target_prefix =
+LIBS = #{CONFIG['LIBS']} #{CONFIG['DLDLIBS']}
+ORIG_SRCS = yajl.c yajl_alloc.c yajl_buf.c yajl_encode.c yajl_gen.c yajl_lex.c yajl_parser.c yajl_tree.c yajl_version.c
+SRCS = $(ORIG_SRCS)
+OBJS = yajl.o yajl_alloc.o yajl_buf.o yajl_encode.o yajl_gen.o yajl_lex.o yajl_parser.o yajl_tree.o yajl_version.o
+HDRS = yajl_alloc.h yajl_buf.h yajl_bytestack.h yajl_encode.h yajl_lex.h yajl_parser.h
+TARGET = libyajl
+DLLIB = $(TARGET).#{CONFIG['DLEXT']}
+
+TIMESTAMP_DIR = .
+RUBYARCHDIR = $(sitearchdir)$(target_prefix)
+
+CLEANLIBS = $(TARGET).bundle
+CLEANOBJS = *.o *.bak
+
+all: $(DLLIB)
+
+clean:
+\t-$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
+
+install: install-so install-rb
+
+install-so: $(DLLIB) $(TIMESTAMP_DIR)/.RUBYARCHDIR.time
+\t$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
+
+install-rb:
+\t$(ECHO) installing default libyajl libraries
+$(TIMESTAMP_DIR)/.RUBYARCHDIR.time:
+\t$(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
+\t$(Q) $(TOUCH) $@
+
+.SUFFIXES: .c .o
+
+.c.o:
+\t$(ECHO) compiling $(<)
+\t$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
+
+$(DLLIB): $(OBJS) Makefile
+\t$(ECHO) linking shared-object $(DLLIB)
+\t-$(Q)$(RM) $(@)
+\t$(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LIBS)
+\t$(Q) $(POSTLINK)
+
+$(OBJS): $(HDRS)
+EOF
+ end
+ end
+
+ def self.makemakefiles
+ setup_env
+ generate_yajl_version
+ Dir.chdir("#{libyajl2_vendor_dir}/src") do
+ # hack to make includes work
+ system("rm -f api/yajl")
+ system("ln -s . api/yajl")
+ yajl_makefile
+ end
+ File.open("Makefile", "w+") do |f|
+ f.write <<EOF
+TARGET = libyajl
+DLLIB = $(TARGET).#{CONFIG['DLEXT']}
+all:
+\tcd #{libyajl2_vendor_dir}/src && make
+\tcp #{libyajl2_vendor_dir}/src/$(DLLIB) .
+install:
+\tcp $(DLLIB) #{prefix}
+clean:
+\tcd #{libyajl2_vendor_dir}/src && make clean
+EOF
end
end
end
-Libyajl2Build.run
+Libyajl2Build.makemakefiles
+
diff --git a/libyajl2.gemspec b/libyajl2.gemspec
index a6e1288..df65f25 100644
--- a/libyajl2.gemspec
+++ b/libyajl2.gemspec
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
# required for 'rake spec'
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
+ spec.add_development_dependency "rake-compiler"
spec.add_development_dependency "rspec", "~> 2.14"
spec.add_development_dependency "ffi", "~> 1.9"
end