-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.rb
130 lines (119 loc) · 3 KB
/
install.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
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
require 'rbconfig'
require 'find'
include Config
if CONFIG["MINOR"].to_i > 6 then $rb_18 = true else $rb_18 = false end
if $rb_18
require 'fileutils'
else
require 'ftools'
end
=begin
$version = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
$libdir = File.join(CONFIG["libdir"], "ruby", $version)
# $archdir = File.join($libdir, CONFIG["arch"])
$site_libdir = $:.find {|x| x =~ /site_ruby$/}
if !$site_libdir
$site_libdir = File.join($libdir, "site_ruby")
elsif Regexp.compile($site_libdir) !~ Regexp.quote($version)
$site_libdir = File.join($site_libdir, $version)
end
default_destdir = $site_libdir
=end
default_destdir = CONFIG["sitelibdir"]
default_bindir = CONFIG["bindir"]
def install_rb(srcdir, destdir)
libdir = "lib"
libdir = File.join(srcdir, libdir) if srcdir
path = []
dir = []
Find.find(libdir) do |f|
next unless FileTest.file?(f)
next if (f = f[libdir.length+1..-1]) == nil
next if (/CVS$/ =~ File.dirname(f))
path.push f
dir |= [File.dirname(f)]
end
for f in dir
next if f == "."
next if f == "CVS"
if $rb_18
FileUtils.makedirs(File.join(destdir, f))
else
File::makedirs(File.join(destdir, f))
end
end
for f in path
next if (/\~$/ =~ f)
next if (/^\./ =~ File.basename(f))
if $rb_18
FileUtils.install(File.join(libdir, f), File.join(destdir, f), {:mode => 0644, :verbose => true})
else
File::install(File.join(libdir, f), File.join(destdir, f), 0644, true)
end
end
end
def install_bin(srcdir, destbindir)
localbindir = "bin"
localbindir = File.join(srcdir, localbindir) if srcdir
path = []
dir = []
Find.find(localbindir) do |f|
next unless FileTest.file?(f)
next if (f = f[localbindir.length+1..-1]) == nil
next if (/CVS$/ =~ File.dirname(f))
path.push f
#dir |= [File.dirname(f)]
end
#for f in dir
# next if f == "."
# next if f == "CVS"
# File::makedirs(File.join(destbindir, f))
#end
for f in path
next if (/\~$/ =~ f)
next if (/^\./ =~ File.basename(f))
if $rb_18
FileUtils.install(File.join(localbindir, f), File.join(destbindir, f), {:mode => 0755, :verbose => true})
else
File::install(File.join(localbindir, f), File.join(destbindir, f), 0755, true)
end
end
end
def ARGV.switch
return nil if self.empty?
arg = self.shift
return nil if arg == '--'
if arg =~ /^-(.)(.*)/
return arg if $1 == '-'
raise 'unknown switch "-"' if $2.index('-')
self.unshift "-#{$2}" if $2.size > 0
"-#{$1}"
else
self.unshift arg
nil
end
end
def ARGV.req_arg
self.shift || raise('missing argument')
end
destdir = default_destdir
bindir = default_bindir
begin
while switch = ARGV.switch
case switch
when '-d', '--destdir'
destdir = ARGV.req_arg
when '-b', '--bindir'
bindir = ARGV.req_arg
else
raise "unknown switch #{switch.dump}"
end
end
rescue
STDERR.puts $!.to_s
STDERR.puts File.basename($0) +
" -d <destdir> -b <bindir>"
exit 1
end
install_rb(nil, destdir)
install_bin(nil, bindir)