forked from ruby/rake
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.rb
90 lines (71 loc) · 2.11 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
require 'rbconfig'
require 'find'
require 'fileutils'
include RbConfig
$ruby = CONFIG['ruby_install_name']
##
# Install a binary file. We patch in on the way through to
# insert a #! line. If this is a Unix install, we name
# the command (for example) 'rake' and let the shebang line
# handle running it. Under windows, we add a '.rb' extension
# and let file associations to their stuff
#
def installBIN(from, opfile)
tmp_dir = nil
for t in [".", "/tmp", "c:/temp", $bindir]
stat = File.stat(t) rescue next
if stat.directory? and stat.writable?
tmp_dir = t
break
end
end
fail "Cannot find a temporary directory" unless tmp_dir
tmp_file = File.join(tmp_dir, "_tmp")
File.open(from) do |ip|
File.open(tmp_file, "w") do |op|
ruby = File.join($realbindir, $ruby)
op.puts "#!#{ruby} -w"
op.write ip.read
end
end
opfile += ".rb" if CONFIG["target_os"] =~ /mswin/i
FileUtils.install(tmp_file, File.join($bindir, opfile),
{:mode => 0755, :verbose => true})
File.unlink(tmp_file)
end
$sitedir = CONFIG["sitelibdir"]
unless $sitedir
version = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
$libdir = File.join(CONFIG["libdir"], "ruby", version)
$sitedir = $:.find {|x| x =~ /site_ruby/}
if !$sitedir
$sitedir = File.join($libdir, "site_ruby")
elsif $sitedir !~ Regexp.quote(version)
$sitedir = File.join($sitedir, version)
end
end
$bindir = CONFIG["bindir"]
$realbindir = $bindir
bindir = CONFIG["bindir"]
if (destdir = ENV['DESTDIR'])
$bindir = destdir + $bindir
$sitedir = destdir + $sitedir
FileUtils.mkdir_p($bindir)
FileUtils.mkdir_p($sitedir)
end
rake_dest = File.join($sitedir, "rake")
FileUtils.mkdir_p(rake_dest, {:verbose => true})
File.chmod(0755, rake_dest)
# The library files
files = Dir.chdir('lib') { Dir['**/*.rb'].sort }
for fn in files
fn_dir = File.dirname(fn)
target_dir = File.join($sitedir, fn_dir)
if ! File.exist?(target_dir)
FileUtils.mkdir_p(target_dir)
end
FileUtils.install(File.join('lib', fn), File.join($sitedir, fn),
{:mode => 0644, :verbose => true})
end
# and the executable
installBIN("bin/rake", "rake")