From e56c70c34d0c9e8012a96566ea06f8f90a434d25 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 24 Jun 2013 16:27:14 +0200 Subject: update for version 2.3.2, local installation fixed, workaround for plugin loading --- README.md | 10 +++++--- ext/openbabel/extconf.rb | 66 +++++++++++++++++++++++++++++++----------------- lib/openbabel.rb | 2 ++ lib/openbabel/version.rb | 4 +-- openbabel.gemspec | 5 ++-- 5 files changed, 56 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index c248ee2..b1b131e 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,19 @@ GEM for [OpenBabel](http://openbabel.sf.net), a chemical library by Geoff Hutchison and others. -openbabel gem has been tested with ruby 1.9. It only compiles on POSIX systems and requires the following to be installed already: +openbabel gem has been tested with ruby 1.9 and 2.0. It compiles only on POSIX systems and requires the following programs and libraries (details at http://openbabel.org/docs/2.3.0/Installation/install.html#compiling-open-babel): - * openbabel library - * cmake + * cmake 2.4.8 or later * curl * tar, sed, make (those should be present anyway) + * libxml2 (optional) + * zlib (optional) + * Eigen 2.0.3 or later (optional) ## Install gem install openbabel -It downloads the sources, compiles OpenBabel (if not installed) and the ruby bindings and installs them. +It downloads the sources, compiles and installs OpenBabel (if not installed system wide) and ruby bindings. If OpenBabel is not yet installed installation may last very long - please be patient. Check out [http://cs.maunz.de](http://cs.maunz.de) for more information. diff --git a/ext/openbabel/extconf.rb b/ext/openbabel/extconf.rb index ae9c3f2..e44ec5d 100644 --- a/ext/openbabel/extconf.rb +++ b/ext/openbabel/extconf.rb @@ -1,48 +1,68 @@ require 'fileutils' -require 'tmpdir' require 'mkmf' +require 'rbconfig' $:.unshift File.expand_path('../../../lib', __FILE__) require 'openbabel/version' ob_num_ver = OpenBabel::VERSION ob_ver = "openbabel-"+ob_num_ver -RUBY=File.join(RbConfig::CONFIG['bindir'], - RbConfig::CONFIG['ruby_install_name']) +RUBY=File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) -main_dir = File.expand_path(File.join(File.dirname(__FILE__),"..","..","src")) -lib_dir = File.expand_path(File.join(File.dirname(__FILE__),"..","..","src")) -Dir.mkdir main_dir -ob_main_dir = File.join(main_dir,ob_ver) -ob_bindings_dir = File.join(ob_main_dir,"scripts","ruby") +main_dir = File.expand_path(File.join(File.dirname(__FILE__),"..","..")) +src_dir = File.join main_dir, ob_ver +build_dir = File.join main_dir, "build" +install_dir = main_dir +install_lib_dir = File.join install_dir, "lib" +lib_dir = File.join main_dir, "lib", "openbabel" +ruby_src_dir = File.join src_dir, "scripts", "ruby" + +begin + nr_processors = `grep processor /proc/cpuinfo | wc -l` # speed up compilation, Linux only +rescue + nr_processors = 1 +end begin Dir.chdir main_dir do - FileUtils.rm_rf ob_main_dir + FileUtils.rm_rf src_dir puts "Downloading OpenBabel sources" system "curl -L -d use_mirror=netcologne 'http://downloads.sourceforge.net/project/openbabel/openbabel/#{ob_num_ver}/openbabel-#{ob_num_ver}.tar.gz' | tar xz" + system "sed -i -e 's/-Wl,-flat_namespace//;s/-flat_namespace//' #{File.join ruby_src_dir, "extconf.rb"}" # remove unrecognized compiler option + system "sed -i -e 's/Init_OpenBabel/Init_openbabel/g' #{File.join ruby_src_dir,"*cpp"}" # fix swig bindings end - Dir.chdir ob_main_dir do + FileUtils.mkdir_p build_dir + FileUtils.mkdir_p install_dir + Dir.chdir build_dir do puts "Configuring OpenBabel" - system "cmake #{ob_main_dir} -DCMAKE_INSTALL_PREFIX=#{lib_dir}" - openbabel_libs = have_library('openbabel') - unless openbabel_libs + cmake = "cmake #{src_dir} -DCMAKE_INSTALL_PREFIX=#{install_dir} -DBUILD_GUI=OFF -DENABLE_TESTS=OFF -DRUBY_BINDINGS=ON" + # set rpath for local installations + # http://www.cmake.org/Wiki/CMake_RPATH_handling + # http://vtk.1045678.n5.nabble.com/How-to-force-cmake-not-to-remove-install-rpath-td5721193.html + cmake += " -DCMAKE_INSTALL_RPATH:STRING=\"#{install_lib_dir}\"" unless have_library('openbabel') + system cmake + end + unless have_library('openbabel') + # local installation in gem directory + Dir.chdir build_dir do puts "OpenBabel not installed. Compiling sources." - system "make" + system "make -j#{nr_processors}" system "make install" + ENV["PKG_CONFIG_PATH"] = File.dirname(File.expand_path(Dir["#{install_dir}/**/openbabel*pc"].first)) end end - Dir.chdir ob_bindings_dir do - puts "Compiling and instaling OpenBabel Ruby bindings." - system "sed -i -e 's/Init_OpenBabel/Init_openbabel/g' *cpp" + # compile ruby bindings + puts "Compiling and installing OpenBabel Ruby bindings." + Dir.chdir ruby_src_dir do + # fix rpath + system "sed -i 's|with_ldflags.*$|with_ldflags(\"#\$LDFLAGS -dynamic -Wl,-rpath,#{install_lib_dir}\") do|' #{File.join(ruby_src_dir,'extconf.rb')}" unless have_library('openbabel') # get include and lib from pkg-config ob_include=`pkg-config openbabel-2.0 --cflags-only-I`.sub(/\s+/,'').sub(/-I/,'') ob_lib=`pkg-config openbabel-2.0 --libs-only-L`.sub(/\s+/,'').sub(/-L/,'') system "#{RUBY} extconf.rb --with-openbabel-include=#{ob_include} --with-openbabel-lib=#{ob_lib}" - system "sed -i -e 's/-Wl,-flat_namespace//;s/-flat_namespace//' Makefile" - system "make" + system "make -j#{nr_processors}" end - FileUtils.cp(ob_bindings_dir+"/openbabel.#{RbConfig::CONFIG["DLEXT"]}", "./") + FileUtils.cp(ruby_src_dir+"/openbabel.#{RbConfig::CONFIG["DLEXT"]}", "./") File.open('Makefile', 'w') do |makefile| makefile.write <<"EOF" .PHONY: openbabel.#{RbConfig::CONFIG["DLEXT"]} @@ -51,10 +71,10 @@ openbabel.#{RbConfig::CONFIG["DLEXT"]}: .PHONY: install install: - mkdir -p ../../lib/openbabel - mv openbabel.#{RbConfig::CONFIG["DLEXT"]} ../../lib/openbabel + mkdir -p #{lib_dir} + mv openbabel.#{RbConfig::CONFIG["DLEXT"]} #{lib_dir} EOF end ensure - FileUtils.remove_entry_secure main_dir + FileUtils.remove_entry_secure src_dir, build_dir end diff --git a/lib/openbabel.rb b/lib/openbabel.rb index 6f6e60a..97ac94f 100644 --- a/lib/openbabel.rb +++ b/lib/openbabel.rb @@ -1,2 +1,4 @@ require 'openbabel/openbabel' require 'openbabel/version' +# http://sourceforge.net/mailarchive/message.php?msg_id=31065700 +OpenBabel::OBConversion.new # required to load plugins diff --git a/lib/openbabel/version.rb b/lib/openbabel/version.rb index cfc1bd8..3a367cb 100644 --- a/lib/openbabel/version.rb +++ b/lib/openbabel/version.rb @@ -1,4 +1,4 @@ module OpenBabel - VERSION = '2.3.1' - GEMVERSION = VERSION + '.9' + VERSION = '2.3.2' + GEMVERSION = VERSION + '.0' end diff --git a/openbabel.gemspec b/openbabel.gemspec index ca6d11b..4c8b6d6 100644 --- a/openbabel.gemspec +++ b/openbabel.gemspec @@ -8,11 +8,12 @@ Gem::Specification.new do |s| s.authors = ["Andreas Maunz, Christoph Helma, Katsuhiko Nishimra"] s.date = %q{2012-04-03} s.description = %q{OpenBabel as a GEM} - s.email = %q{andreas@maunz.de} - s.homepage = %q{http://cs.maunz.de} + s.email = ["andreas@maunz.de","helma@in-silico.ch"] + s.homepage = %q{http://github.com/opentox/openbabel-gem} s.require_paths = ["lib"] s.rubygems_version = %q{1.6.2} s.summary = %q{OpenBabel!} + s.license = "GPL-3" s.test_files = ["test/test_openbabel.rb"] s.files = %w{Rakefile lib/openbabel.rb lib/openbabel/version.rb} -- cgit v1.2.3