summaryrefslogtreecommitdiff
path: root/instruby.rb
blob: 84aa430d4796a77a92df3f1b39e3005cbe4cb4ac (plain)
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
#!./miniruby

load "./rbconfig.rb"
include Config

File.umask(0)

while arg = ARGV.shift
  case arg
  when /^--/			# ignore
  when /^-/
    $dryrun = /n/ =~ arg
  when /=/			# ignore
  else
    destdir ||= arg
    break
  end
end
destdir ||= ''

$:.unshift CONFIG["srcdir"]+"/lib"
require 'ftools'
require 'shellwords'

class Installer < File; end
class << Installer
  if $dryrun
    def makedirs(*dirs)
      String === dirs.last or dirs.pop
      for dir in dirs
	File.directory?(dir) or print "mkdir -p #{dir}\n"
      end
    end
    def install(file, dir, mode = nil, verbose = false)
      to = catname(file, dir)
      unless FileTest.exist? to and cmp file, to
	print "install#{' -m %#o'%mode if mode} #{file} #{dir}\n"
      end
    end
    def makelink(orig, link, verbose = false)
      unless File.symlink?(link) and File.readlink(link) == orig
	print "ln -sf #{orig} #{link}\n"
      end
    end
  else
    require "ftools"
    def makelink(orig, link, verbose = false)
      if exist? link
	delete link
      end
      symlink orig, link
      print "link #{orig} -> #{link}\n"
    end
  end
end

exeext = CONFIG["EXEEXT"]

ruby_install_name = CONFIG["ruby_install_name"]
rubyw_install_name = CONFIG["rubyw_install_name"]

version = CONFIG["ruby_version"]
bindir = destdir+CONFIG["bindir"]
libdir = destdir+CONFIG["libdir"]
rubylibdir = destdir+CONFIG["rubylibdir"]
archlibdir = destdir+CONFIG["archdir"]
sitelibdir = destdir+CONFIG["sitelibdir"]
sitearchlibdir = destdir+CONFIG["sitearchdir"]
mandir = destdir+CONFIG["mandir"] + "/man1"
configure_args = Shellwords.shellwords(CONFIG["configure_args"])
enable_shared = CONFIG["ENABLE_SHARED"] == 'yes'
dll = CONFIG["LIBRUBY_SO"]
lib = CONFIG["LIBRUBY"]
arc = CONFIG["LIBRUBY_A"]

Installer.makedirs bindir, libdir, rubylibdir, archlibdir, sitelibdir, sitearchlibdir, mandir, true

Installer.install ruby_install_name+exeext, bindir+"/"+ruby_install_name+exeext, 0755, true
if rubyw_install_name and !rubyw_install_name.empty?
  Installer.install rubyw_install_name+exeext, bindir, 0755, true
end
Installer.install dll, bindir, 0755, true if enable_shared and dll != lib
Installer.install lib, libdir, 0555, true unless lib == arc
Installer.install arc, archlibdir, 0644, true
Installer.install "config.h", archlibdir, 0644, true
Installer.install "rbconfig.rb", archlibdir, 0644, true
if CONFIG["ARCHFILE"]
  for file in CONFIG["ARCHFILE"].split
    Installer.install file, archlibdir, 0644, true
  end
end

if dll == lib and dll != arc
  for link in CONFIG["LIBRUBY_ALIASES"].split
    Installer.makelink(dll, File.join(libdir, link), true)
  end
end

Dir.chdir CONFIG["srcdir"]

Installer.install "sample/irb.rb", "#{bindir}/irb", 0755, true

Dir.glob("lib/**/*{.rb,help-message}") do |f|
  dir = File.dirname(f).sub!(/\Alib/, rubylibdir) || rubylibdir
  Installer.makedirs dir, true unless File.directory? dir
  Installer.install f, dir, 0644, true
end

for f in Dir["*.h"]
  Installer.install f, archlibdir, 0644, true
end
if RUBY_PLATFORM =~ /mswin32|mingw|bccwin32/
  Installer.makedirs archlibdir + "/win32", true
  Installer.install "win32/win32.h", archlibdir + "/win32", 0644, true
end

Installer.makedirs mandir, true
Installer.install "ruby.1", mandir+"/"+ruby_install_name+".1", 0644, true

# vi:set sw=2: