forked from cosmo0920/win32-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
105 lines (90 loc) · 2.53 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
require 'rake'
require 'rake/clean'
require 'rake/testtask'
require 'rbconfig'
include Config
make = CONFIG['host_os'] =~ /mingw|cygwin/i ? 'make' : 'nmake'
desc 'Build the ruby.exe.manifest if it does not already exist'
task :build_manifest do
version = CONFIG['host_os'].split('_')[1]
if version && version.to_i >= 80
unless File.exist?(File.join(CONFIG['bindir'], 'ruby.exe.manifest'))
Dir.chdir(CONFIG['bindir']) do
sh "mt -inputresource:ruby.exe;2 -out:ruby.exe.manifest"
end
end
end
end
desc 'Install the win32-api library (non-gem)'
task :install => [:build] do
Dir.chdir('ext'){
sh "#{make} install"
}
end
desc 'Clean any build files for Win32::API'
task :clean do
Dir.chdir('ext') do
if File.exists?('api.so') || File.exists?('win32/api.so') ||
File.exists?('api.obj') || File.exists?('Makefile')
then
sh "#{make} distclean"
rm 'win32/api.so' if File.exists?('win32/api.so')
rm 'api.so' if File.exists?('api.so')
end
end
# Cleanup any files generated by the build_binary_gem task
rm_rf('lib') if File.exists?('lib')
Dir["*.gem"].each{ |f| File.delete(f) }
end
desc "Build Win32::API (but don't install it)"
task :build => [:clean, :build_manifest] do
Dir.chdir('ext') do
ruby "extconf.rb"
sh make
cp "api.so", "win32" # For the test suite
end
end
namespace 'gem' do
desc 'Build a standard gem'
task :create => [:clean] do
spec = eval(IO.read('win32-api.gemspec'))
Gem::Builder.new(spec).build
end
desc 'Build a binary gem'
task :binary => [:build] do
mkdir_p 'lib/win32'
cp 'ext/api.so', 'lib/win32'
spec = eval(IO.read('win32-api.gemspec'))
spec.platform = Gem::Platform::CURRENT
spec.extensions = nil
spec.files = spec.files.reject{ |f| f.include?('ext') }
Gem::Builder.new(spec).build
end
desc 'Install the gem'
task :install => [:create] do
file = Dir["*.gem"].first
sh "gem install #{file}"
end
end
namespace 'test' do
Rake::TestTask.new(:all) do |test|
task :all => [:build]
test.libs << 'ext'
test.warning = true
test.verbose = true
end
Rake::TestTask.new(:callback) do |test|
task :callback => [:build]
test.test_files = FileList['test/test_win32_api_callback.rb']
test.libs << 'ext'
test.warning = true
test.verbose = true
end
Rake::TestTask.new(:function) do |test|
task :function => [:build]
test.test_files = FileList['test/test_win32_api_function.rb']
test.libs << 'ext'
test.warning = true
test.verbose = true
end
end