-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.rb
51 lines (43 loc) · 1.19 KB
/
setup.rb
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
require 'rbconfig'
require 'fileutils'
class Setup
attr_accessor :site_dir, :site_lib_dir, :site_arch_dir
def initialize
@site_dir = RbConfig::CONFIG["sitedir"]
@site_lib_dir = RbConfig::CONFIG["sitelibdir"]
@site_arch_dir = RbConfig::CONFIG["sitearchdir"]
end
def compile
Dir.chdir 'ext' do
if File.exist?("Makefile")
system("make clean")
end
system("#{Gem.ruby} extconf.rb")
system("make")
end
end
def copy_files
ext_path =
File.absolute_path "ext/rbkit_server.#{RbConfig::MAKEFILE_CONFIG['DLEXT']}"
cleanup
FileUtils.cp_r "lib/.", site_lib_dir, verbose: true
FileUtils.cp_r ext_path, site_arch_dir, verbose: true
end
def cleanup
puts "Removing existing installation"
FileUtils.rm_r site_lib_dir + "/rbkit", force: true
FileUtils.rm_r site_lib_dir + "/rbkit.rb", force: true
FileUtils.rm_r site_arch_dir + "/rbkit_server.#{RbConfig::MAKEFILE_CONFIG['DLEXT']}", force: true
end
end
if __FILE__ == $0
cmd_arg = ARGV[0] ? ARGV[0].strip : 'setup'
setup_script = Setup.new
case cmd_arg
when 'remove'
setup_script.cleanup
else
setup_script.compile
setup_script.copy_files
end
end