2013-03-02 21:08:54 +00:00
# -*- mode: ruby; coding: utf-8 -*-
2008-08-19 15:01:28 +00:00
require 'rubygems'
2013-05-04 11:52:46 +00:00
require " rubygems/ext "
require " rubygems/installer "
2008-08-19 15:01:28 +00:00
require 'hoe'
2011-04-07 05:25:08 +00:00
require 'rake/extensiontask'
2013-05-04 11:52:46 +00:00
require 'fileutils'
require './lib/opencv/psyched_yaml'
2014-01-18 10:06:04 +00:00
require 'yard'
require 'yard/rake/yardoc_task'
require './yard_extension'
2013-05-04 11:52:46 +00:00
SO_FILE = 'opencv.so'
2008-08-19 15:01:28 +00:00
2011-04-07 05:25:08 +00:00
Hoe . plugin :gemspec
2013-01-19 23:12:44 +00:00
hoespec = Hoe . spec 'ruby-opencv' do | s |
s . summary = 'OpenCV wrapper for Ruby'
2013-03-02 17:59:54 +00:00
s . description = 'ruby-opencv is a wrapper of OpenCV for Ruby. It helps you to write computer vision programs (e.g. detecting faces from pictures) with Ruby.'
2016-07-16 16:33:52 +00:00
s . licenses = [ 'BSD-3-Clause' ]
2013-01-19 23:12:44 +00:00
s . developer ( 'lsxi' , 'masakazu.yonekura@gmail.com' )
s . developer ( 'ser1zw' , 'azariahsawtikes@gmail.com' )
s . developer ( 'pcting' , 'pcting@gmail.com' )
2013-01-27 03:39:17 +00:00
s . readme_file = 'README.md'
2013-01-19 23:12:44 +00:00
s . history_file = 'History.txt'
2013-05-01 22:37:23 +00:00
2013-05-04 11:52:46 +00:00
s . spec_extras = { :extensions = > [ 'ext/opencv/extconf.rb' ] }
2013-05-01 22:37:23 +00:00
2013-01-19 23:12:44 +00:00
s . test_globs = [ 'test/test_*.rb' ]
s . urls = [ 'https://github.com/ruby-opencv/ruby-opencv/' ]
2014-01-18 18:10:19 +00:00
s . extra_dev_deps << [ 'rake-compiler' , '~> 0' ] << [ 'hoe-gemspec' , '~> 0' ]
2011-04-07 05:25:08 +00:00
Rake :: ExtensionTask . new ( 'opencv' , spec ) do | ext |
2013-05-04 11:52:46 +00:00
ext . lib_dir = 'lib'
2011-04-07 05:25:08 +00:00
end
2008-08-19 15:01:28 +00:00
end
2011-04-07 05:25:08 +00:00
hoespec . spec . files . delete ( '.gemtest' )
Rake :: Task [ :test ] . prerequisites << :compile
2013-05-04 11:52:46 +00:00
desc 'Create a pre-compiled gem'
task 'gem:precompile' = > [ 'gem' ] do
tmp_dir = Dir . mktmpdir ( 'tmp' , '.' )
gemfile = Dir . glob ( " pkg/*.gem " ) [ 0 ]
target_dir = File . join ( tmp_dir , File . basename ( gemfile , '.gem' ) )
installer = Gem :: Installer . new ( gemfile )
installer . unpack ( target_dir )
gemspec = installer . spec
extension = gemspec . extensions [ 0 ]
gemspec . extensions . clear
2013-05-04 17:23:19 +00:00
config = ENV [ 'CONFIG' ] ? YAML . load_file ( ENV [ 'CONFIG' ] ) : { }
rubies = config [ 'rubies' ] || [ Gem . ruby ]
args = config [ 'extopts' ] || [ ]
gemspec . platform = config [ 'platform' ] || Gem :: Platform :: CURRENT
2013-05-04 11:52:46 +00:00
multi = rubies . size > 1
rubies . each { | ruby |
lib_dir = 'lib'
if multi
major , minor , _ = ` #{ ruby } -e "print RUBY_VERSION" ` . chomp . split ( '.' )
lib_dir = File . join ( lib_dir , [ major , minor ] . join ( '.' ) )
end
2013-05-04 14:56:38 +00:00
2013-05-04 17:23:19 +00:00
make_cmd = ( ` #{ ruby } -e "print RUBY_PLATFORM" ` =~ / mswin / ) ? 'nmake' : 'make'
2013-05-04 11:52:46 +00:00
Dir . chdir ( target_dir ) {
cmd = [ ruby , extension , * args ] . join ( ' ' )
2013-05-04 17:23:19 +00:00
results = [ ]
2013-05-04 11:52:46 +00:00
Gem :: Ext :: ExtConfBuilder . run ( cmd , results )
Gem :: Ext :: ExtConfBuilder . make ( '' , results )
FileUtils . mkdir_p lib_dir
FileUtils . mv SO_FILE , lib_dir
sh " #{ make_cmd } clean "
}
gemspec . files << File . join ( lib_dir , SO_FILE )
}
Dir . chdir ( target_dir ) {
gemfile = Gem :: Package . build ( gemspec )
FileUtils . mv gemfile , File . dirname ( __FILE__ )
}
FileUtils . rm_rf tmp_dir
end
2014-01-18 10:06:04 +00:00
# yard
YARD :: Rake :: YardocTask . new do | t |
t . files = [ 'lib/**/*.rb' , 'ext/**/*.cpp' ]
end
2013-01-19 23:12:44 +00:00
# vim: syntax=ruby
2014-01-18 10:06:04 +00:00