forked from djberg96/sys-proctable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
185 lines (165 loc) · 5.67 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
require 'rake'
require 'rake/clean'
require 'rake/testtask'
require 'rbconfig'
include RbConfig
CLEAN.include(
'**/*.core', # Core dump files
'**/*.gem', # Gem files
'**/*.rbc', # Rubinius
'.rbx', '**/*/.rbx', # Rubinius
'**/*.o', # C object file
'**/*.log', # Ruby extension build log
'**/Makefile', # C Makefile
'**/conftest.dSYM', # OS X build directory
"**/*.#{CONFIG['DLEXT']}" # C shared object
)
desc 'Build the sys-proctable library for C versions of sys-proctable'
task :build => [:clean] do
if RUBY_PLATFORM == 'java'
if ENV['JRUBY_OPTS']
ENV['JRUBY_OPTS'] += ' -Xcext.enabled=true'
else
ENV['JRUBY_OPTS'] = '-Xcext.enabled=true'
end
end
case CONFIG['host_os']
when /bsd/i
dir = 'ext/bsd'
ext = '.so'
when /darwin/i
dir = 'ext/darwin'
ext = '.bundle'
when /hpux/i
dir = 'ext/hpux'
ext = '.sl'
end
unless CONFIG['host_os'] =~ /win32|mswin|dos|cygwin|mingw|windows|linux|sunos|solaris/i
Dir.chdir(dir) do
ruby 'extconf.rb'
sh 'make'
cp 'proctable' + ext, 'sys'
end
end
end
desc 'Install the sys-proctable library'
task :install => [:build] do
file = nil
dir = File.join(CONFIG['sitelibdir'], 'sys')
Dir.mkdir(dir) unless File.exists?(dir)
case CONFIG['host_os']
when /mswin|win32|msdos|cygwin|mingw|windows/i
file = 'lib/windows/sys/proctable.rb'
when /linux/i
file = 'lib/linux/sys/proctable.rb'
when /sunos|solaris/i
file = 'lib/sunos/sys/proctable.rb'
when /bsd/i
Dir.chdir('ext/bsd'){ sh 'make install' }
when /darwin/i
Dir.chdir('ext/darwin'){ sh 'make install' }
when /hpux/i
Dir.chdir('ext/hpux'){ sh 'make install' }
end
cp(file, dir, :verbose => true) if file
end
desc 'Uninstall the sys-proctable library'
task :uninstall do
case CONFIG['host_os']
when /win32|mswin|dos|cygwin|mingw|windows|linux|sunos|solaris/i
dir = File.join(CONFIG['sitelibdir'], 'sys')
file = File.join(dir, 'proctable.rb')
else
dir = File.join(CONFIG['sitearchdir'], 'sys')
file = File.join(dir, 'proctable.' + CONFIG['DLEXT'])
end
rm(file)
end
desc 'Run the benchmark suite'
task :bench => [:build] do
sh "ruby -Ilib benchmarks/bench_ps.rb"
end
desc 'Run the example program'
task :example => [:build] do
sh 'ruby -Ilib -Iext examples/example_ps.rb'
end
desc 'Run the test suite'
Rake::TestTask.new do |t|
task :test => :build
t.libs << 'test' << '.'
case CONFIG['host_os']
when /mswin|msdos|cygwin|mingw|windows/i
t.test_files = FileList['test/test_sys_proctable_windows.rb']
t.libs << 'lib/windows'
when /linux/i
t.test_files = FileList['test/test_sys_proctable_linux.rb']
t.libs << 'lib/linux'
when /sunos|solaris/i
t.test_files = FileList['test/test_sys_proctable_sunos.rb']
t.libs << 'lib/sunos'
when /darwin/i
t.libs << 'ext/darwin'
t.test_files = FileList['test/test_sys_proctable_darwin.rb']
when /bsd/i
t.libs << 'ext/bsd'
t.test_files = FileList['test/test_sys_proctable_bsd.rb']
when /hpux/i
t.libs << 'ext/hpux'
t.test_files = FileList['test/test_sys_proctable_hpux.rb']
end
end
namespace :gem do
desc 'Create a gem'
task :create => [:clean] do
spec = eval(IO.read('sys-proctable.gemspec'))
# I've had to manually futz with the spec here in some cases
# in order to get the universal platform settings I want because
# of some bugginess in Rubygems' platform.rb.
#
case CONFIG['host_os']
when /bsd/i
spec.platform = Gem::Platform.new(['universal', 'freebsd'])
spec.platform.version = nil
spec.files << 'ext/bsd/sys/proctable.c'
spec.extra_rdoc_files << 'ext/bsd/sys/proctable.c'
spec.test_files << 'test/test_sys_proctable_bsd.rb'
spec.extensions = ['ext/bsd/extconf.rb']
when /darwin/i
spec.platform = Gem::Platform.new(['universal', 'darwin'])
spec.files << 'ext/darwin/sys/proctable.c'
spec.extra_rdoc_files << 'ext/darwin/sys/proctable.c'
spec.test_files << 'test/test_sys_proctable_darwin.rb'
spec.extensions = ['ext/darwin/extconf.rb']
when /hpux/i
spec.platform = Gem::Platform.new(['universal', 'hpux'])
spec.files << 'ext/hpux/sys/proctable.c'
spec.extra_rdoc_files << 'ext/hpux/sys/proctable.c'
spec.test_files << 'test/test_sys_proctable_hpux.rb'
spec.extensions = ['ext/hpux/extconf.rb']
when /linux/i
spec.platform = Gem::Platform.new(['universal', 'linux'])
spec.require_paths = ['lib', 'lib/linux']
spec.files += ['lib/linux/sys/proctable.rb']
spec.test_files << 'test/test_sys_proctable_linux.rb'
when /sunos|solaris/i
spec.platform = Gem::Platform.new(['universal', 'solaris'])
spec.require_paths = ['lib', 'lib/sunos']
spec.files += ['lib/sunos/sys/proctable.rb']
spec.test_files << 'test/test_sys_proctable_sunos.rb'
when /mswin|win32|dos|cygwin|mingw|windows/i
spec.platform = Gem::Platform.new(['universal', 'mingw32'])
spec.require_paths = ['lib', 'lib/windows']
spec.files += ['lib/windows/sys/proctable.rb']
spec.test_files << 'test/test_sys_proctable_windows.rb'
end
# https://github.com/rubygems/rubygems/issues/147
spec.original_platform = spec.platform
Gem::Builder.new(spec).build
end
desc 'Install the sys-proctable library as a gem'
task :install => [:create] do
gem_name = Dir['*.gem'].first
sh "gem install #{gem_name}"
end
end
task :default => :test