From 73b68b1ce611020ade54c4da0ea0c7a37d9a34a9 Mon Sep 17 00:00:00 2001 From: Ivan Kuznetsov Date: Thu, 16 Aug 2012 17:02:28 +0300 Subject: [PATCH 1/3] Converted linalg to new gem spec --- .gitignore | 46 ++++++ Gemfile | 5 + Rakefile | 11 ++ ext/lapack/extconf.rb | 7 +- ext/lapack/rb_lapack.h | 2 +- ext/linalg/dcomplex.h | 2 +- ext/linalg/extconf.rb | 5 +- ext/linalg/xdata.h | 2 +- ext/linalg/xmatrix.h.tmpl | 2 +- install.rb | 300 -------------------------------------- lib/linalg.rb | 25 ++-- lib/linalg/version.rb | 3 + linalg.gemspec | 20 +++ 13 files changed, 101 insertions(+), 329 deletions(-) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Rakefile delete mode 100644 install.rb create mode 100644 lib/linalg/version.rb create mode 100644 linalg.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7046960 --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ +# ignore native extensions build output +mkmf.log +Makefile +*.o +*.so + +# ignore editor temp files +*.swp + +# ignore built gem +*.gem + +# ignore generated docs +doc/ + +# ignore bundler output +Gemfile.lock + +# ignore files generated from templates +ext/lapack/rb_lapack_c.c +ext/lapack/rb_lapack_d.c +ext/lapack/rb_lapack_s.c +ext/lapack/rb_lapack_x.c +ext/lapack/rb_lapack_z.c +ext/linalg/cdata.c +ext/linalg/chardata.c +ext/linalg/cmatrix.c +ext/linalg/cmatrix.h +ext/linalg/cmatrixc.c +ext/linalg/dmatrix.c +ext/linalg/dmatrix.h +ext/linalg/dmatrixr.c +ext/linalg/idata.c +ext/linalg/ldata.c +ext/linalg/scomplex.c +ext/linalg/scomplex.h +ext/linalg/sdata.c +ext/linalg/smatrix.c +ext/linalg/smatrix.h +ext/linalg/smatrixr.c +ext/linalg/zdata.c +ext/linalg/zmatrix.c +ext/linalg/zmatrix.h +ext/linalg/zmatrixc.c + + diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..6eff9df --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source "http://rubygems.org" + +# Will automatically pull in this gem and all its +# dependencies specified in the gemspec +gem "linalg", :path => File.expand_path("..", __FILE__) diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..8484642 --- /dev/null +++ b/Rakefile @@ -0,0 +1,11 @@ +require "bundler" +Bundler.setup + +gemspec = eval(File.read("linalg.gemspec")) + +task :build => "#{gemspec.full_name}.gem" + +file "#{gemspec.full_name}.gem" => gemspec.files + ["linalg.gemspec"] do + system "gem build linalg.gemspec" + system "gem install linalg-#{Linalg::VERSION}.gem" +end diff --git a/ext/lapack/extconf.rb b/ext/lapack/extconf.rb index feeeb9b..c6df0ba 100644 --- a/ext/lapack/extconf.rb +++ b/ext/lapack/extconf.rb @@ -117,7 +117,7 @@ def self.read cppdefs = { "extern" => "", - # these are in g2c.h + # these are in f2c.h "C_f" => "void", "Z_f" => "void", } @@ -271,8 +271,7 @@ def write_c end def config - unless have_header("g2c.h") and - have_library("g2c") and + unless have_header("f2c.h") and have_library("blas") and have_library("lapack") puts "A full LAPACK installation was not found." @@ -286,8 +285,6 @@ def config "rb_lapack_z.c", "rb_lapack_x.c", ] - - $CFLAGS += ' -I.. -include g2c_typedefs.h' end def create diff --git a/ext/lapack/rb_lapack.h b/ext/lapack/rb_lapack.h index a045fd4..66968e7 100644 --- a/ext/lapack/rb_lapack.h +++ b/ext/lapack/rb_lapack.h @@ -7,7 +7,7 @@ #include "ruby.h" -#include +#include #include "include/BLAS.h" #include "include/LAPACK.h" diff --git a/ext/linalg/dcomplex.h b/ext/linalg/dcomplex.h index c3a0073..35344b5 100644 --- a/ext/linalg/dcomplex.h +++ b/ext/linalg/dcomplex.h @@ -11,7 +11,7 @@ #include #include -#include +#include #include "ruby.h" diff --git a/ext/linalg/extconf.rb b/ext/linalg/extconf.rb index 993ab35..13ad843 100644 --- a/ext/linalg/extconf.rb +++ b/ext/linalg/extconf.rb @@ -13,8 +13,7 @@ # #################################################### -unless have_header("g2c.h") and - have_library("g2c") and +unless have_header("f2c.h") and have_library("blas") and have_library("lapack") puts "A full LAPACK installation was not found." @@ -32,8 +31,6 @@ # why doesn't $INCFLAGS work $CFLAGS += " -I../lapack/include" -$CFLAGS += ' -I.. -include g2c_typedefs.h' - #################################################### # # Instantiator diff --git a/ext/linalg/xdata.h b/ext/linalg/xdata.h index 6bc4725..ad60268 100644 --- a/ext/linalg/xdata.h +++ b/ext/linalg/xdata.h @@ -10,7 +10,7 @@ #include "ruby.h" -#include +#include #include "linalg.h" #include "dcomplex.h" diff --git a/ext/linalg/xmatrix.h.tmpl b/ext/linalg/xmatrix.h.tmpl index 29a642c..18d67b5 100644 --- a/ext/linalg/xmatrix.h.tmpl +++ b/ext/linalg/xmatrix.h.tmpl @@ -12,7 +12,7 @@ #include #include -#include +#include #include "BLAS.h" #include "LAPACK.h" diff --git a/install.rb b/install.rb deleted file mode 100644 index ea7c984..0000000 --- a/install.rb +++ /dev/null @@ -1,300 +0,0 @@ - -require 'rbconfig' -require 'fileutils' -require 'rdoc/rdoc' -require 'mkmf' - -LINALG_VERSION = "1.0.1" - -DLEXT = Config::CONFIG["DLEXT"] - -# developer use only -module LinalgPackager - include FileUtils - - module Ext - def self.each - [ - "ext/lapack", - "ext/linalg", - ].each { |dir| - Dir.chdir(dir) { |path| - yield path - } - } - end - end - - def _archive(pkgdir, type) - filename = "#{pkgdir}.#{type}" - case type - when :tgz - system("tar zvcf #{filename} #{pkgdir}") - when :zip - system("zip -r #{filename} #{pkgdir}") - else - raise "unknown archive type" - end - system("md5sum #{filename} > #{filename}.md5") - end - - def _release(pkgdir, ziptype) - Dir.chdir("..") { - rm_rf pkgdir - cp_r "linalg", pkgdir - rm_rf(Dir.glob("#{pkgdir}/**/CVS") + - Dir.glob("#{pkgdir}/**/.svn") + - ["#{pkgdir}/.git"]) - _archive(pkgdir, ziptype) - rm_rf pkgdir - } - end - - def _release_bin(pkgdir, ziptype) - distclean - config - make - doc - mv "ext/lapack/lapack.#{DLEXT}", "." - mv "ext/linalg/linalg.#{DLEXT}", "." - distclean(false) - mv "lapack.#{DLEXT}", "ext/lapack" - mv "linalg.#{DLEXT}", "ext/linalg" - _release(pkgdir, ziptype) - rm "ext/lapack/lapack.#{DLEXT}" - rm "ext/linalg/linalg.#{DLEXT}" - distclean - end - - def release_src - distclean - _release("linalg-#{LINALG_VERSION}", :tgz) - end - - def release_bin - pkgdir = "linalg-#{LINALG_VERSION}-#{CONFIG["arch"]}-ruby#{CONFIG["MAJOR"]}#{CONFIG["MINOR"]}" - if pkgdir =~ /mingw32|mswin32/ - pkgdir.sub!(/mingw32/, "mswin32") - _release_bin(pkgdir, :zip) - else - _release_bin(pkgdir, :tgz) - end - end - - def publish - doc - Dir.chdir("doc") { - args = %w(scp -r . quix@rubyforge.org:/var/www/gforge-projects/linalg) - puts args.join(" ") - raise unless system(*args) - } - end -end - -module Main - include LinalgPackager - include FileUtils - - extend self - - def doc - rdoc_files = [ - 'lib/linalg.rb', - 'lib/lapack.rb', - 'lib/linalg/exception.rb', - 'lib/linalg/iterators.rb', - 'lib/linalg/dmatrix/main.rb', - ] + Dir['lib/linalg/dmatrix/*.rb'].reject { |f| - f =~ %r!/alias.rb$! or f =~ %r!/main.rb$! - } + [ - 'ext/linalg/dmatrix.c', - 'lib/linalg/dmatrix/alias.rb', - 'README', - ] - - rm_rf "doc" - RDoc::RDoc.new.document( - rdoc_files + - ["--main", "README", - "--title", "Linalg: Ruby Linear Algebra Library"]) - end - - def distclean(rmdoc = true) - Ext.each { |path| - puts "distclean #{path}" - if File.exists? "Makefile" - system("#{$make} distclean") - end - } - rm_rf "doc" if rmdoc - rm_f Dir.glob("*.gem") - rm_f Dir.glob("*~") - rm_f Dir.glob("**/*~") - rm_rf Dir.glob("ext/**/conftest.dSYM") - rm_f Dir.glob("ext/**/g2c.h") - rm_f Dir.glob("ext/**/libg2c.a") - rm_f Dir.glob("**/mkmf.log") - end - - def make - Ext.each { |path| - puts "make #{path}" - unless system("#{$make}") - raise "compilation failed" - end - } - end - - def config - Ext.each { |path| - puts "config #{path}" - unless system("#{$ruby} extconf.rb") - raise "configuration failed" - end - } - end - - alias_method :configure, :config - alias_method :extconf, :config - - def clean - Ext.each { |path| - puts "clean #{path}" - system("#{$make} clean") - } - end - - def test - Dir.chdir("test") { - puts "testing" - system("#{$ruby} -w all.rb") - } - end - - def install - sitelibdir = Config::CONFIG["sitelibdir"] - sitearchdir = Config::CONFIG["sitearchdir"] - - spec = [ - ["ext/linalg/linalg.#{DLEXT}", sitearchdir + "/linalg.#{DLEXT}", 0755], - ["ext/lapack/lapack.#{DLEXT}", sitearchdir + "/lapack.#{DLEXT}", 0755], - ["lib/linalg.rb", sitelibdir + "/linalg.rb", 0644], - ] + Dir.glob("lib/linalg/*.rb").map { |f| - [f, sitelibdir + "/linalg/" + File.basename(f), 0644] - } + Dir.glob("lib/linalg/dmatrix/*.rb").map { |f| - [f, sitelibdir + "/linalg/dmatrix/" + File.basename(f), 0644] - } - - File.open("InstalledFiles", "w") { |log| - class << log - def puts(*args) - super(*args) - STDOUT.puts(*args) - end - end - spec.each { |f| - mkdir_p File.dirname(f[1]), :mode => 0755 - FileUtils.install f[0], f[1], :mode => f[2] - log.puts "install #{f[0]} --> #{f[1]}" - } - } - - puts - puts "Installation was successful." - puts "Installed files are recorded in InstalledFiles." - puts "Documentation is in doc/." - end - - def uninstall - sitelibdir = Config::CONFIG["sitelibdir"] - sitearchdir = Config::CONFIG["sitearchdir"] - [ - sitearchdir + "/lapack.#{DLEXT}", - sitearchdir + "/linalg.#{DLEXT}", - sitelibdir + "/linalg.rb", - sitelibdir + "/linalg/", - "InstalledFiles", - ].each { |f| - rm_rf(f) - puts "remove #{f}" - } - end - - def setup - make - doc - end - - def auto - unless FileTest.exist?("ext/lapack/lapack.#{DLEXT}") and - FileTest.exist?("ext/linalg/linalg.#{DLEXT}") - config - make - doc - end - install - end - - action = ARGV.shift || "auto" - - send(action, *ARGV) -end - -module LinalgGem - include FileUtils - - def makegembin - cp "ext/lapack/lapack.#{DLEXT}", "lib" - cp "ext/linalg/linalg.#{DLEXT}", "lib" - mv "doc", "doc-save" - distclean - mv "doc-save", "doc" - _makegem - rm_f Dir.glob("lib/*.#{DLEXT}") - end - - def makegem - distclean - _makegem - end - - def _makegem - require 'rubygems' - - spec = Gem::Specification.new { |s| - s.name = 'linalg' - s.version = LINALG_VERSION - - s.summary = < Date: Thu, 16 Aug 2012 17:30:37 +0300 Subject: [PATCH 2/3] Fixed inclusion of C extensions --- lib/linalg.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/linalg.rb b/lib/linalg.rb index 27374b7..1af40fd 100644 --- a/lib/linalg.rb +++ b/lib/linalg.rb @@ -1,5 +1,5 @@ -require "linalg/linalg" -require "linalg/lapack" +require "linalg#{Config::CONFIG['DLEXT']}" +require "lapack#{Config::CONFIG['DLEXT']}" require "linalg/dcomplex" require "linalg/dmatrix" require "linalg/exception" From b72835200dfdb3dfd114d3f3282ef68bdf065c0f Mon Sep 17 00:00:00 2001 From: Ivan Kuznetsov Date: Thu, 23 Aug 2012 13:32:12 +0300 Subject: [PATCH 3/3] Replaced deprecated Config with RbConfig --- lib/linalg.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/linalg.rb b/lib/linalg.rb index 1af40fd..a1e9c10 100644 --- a/lib/linalg.rb +++ b/lib/linalg.rb @@ -1,5 +1,5 @@ -require "linalg#{Config::CONFIG['DLEXT']}" -require "lapack#{Config::CONFIG['DLEXT']}" +require "linalg.#{RbConfig::CONFIG['DLEXT']}" +require "lapack.#{RbConfig::CONFIG['DLEXT']}" require "linalg/dcomplex" require "linalg/dmatrix" require "linalg/exception"