forked from ruby-opencv/ruby-opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
90 lines (69 loc) · 2.49 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
84
85
86
87
88
89
90
# -*- mode: ruby; coding: utf-8 -*-
require 'rubygems'
require "rubygems/ext"
require "rubygems/installer"
require 'hoe'
require 'rake/extensiontask'
require 'fileutils'
require './lib/opencv/psyched_yaml'
SO_FILE = 'opencv.so'
Hoe.plugin :gemspec
hoespec = Hoe.spec 'ruby-opencv' do |s|
s.summary = 'OpenCV wrapper for Ruby'
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.'
s.licenses = ['The BSD License']
s.developer('lsxi', '[email protected]')
s.developer('ser1zw', '[email protected]')
s.developer('pcting', '[email protected]')
s.readme_file = 'README.md'
s.history_file = 'History.txt'
s.spec_extras = { :extensions => ['ext/opencv/extconf.rb'] }
s.test_globs = ['test/test_*.rb']
s.urls = ['https://github.com/ruby-opencv/ruby-opencv/']
s.extra_dev_deps << ['rake-compiler', '>= 0'] << ['hoe-gemspec']
Rake::ExtensionTask.new('opencv', spec) do |ext|
ext.lib_dir = 'lib'
end
end
hoespec.spec.files.delete('.gemtest')
Rake::Task[:test].prerequisites << :compile
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
config = ENV['CONFIG'] ? YAML.load_file(ENV['CONFIG']) : {}
rubies = config['rubies'] || [Gem.ruby]
args = config['extopts'] || []
gemspec.platform = config['platform'] || Gem::Platform::CURRENT
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
make_cmd = (`#{ruby} -e "print RUBY_PLATFORM"` =~ /mswin/) ? 'nmake' : 'make'
Dir.chdir(target_dir) {
cmd = [ruby, extension, *args].join(' ')
results = []
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
# vim: syntax=ruby