forked from jimm/midilib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.rb
executable file
·76 lines (68 loc) · 1.7 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
#! /usr/bin/env ruby
#
# usage: install.rb [(--install-dir | -i) install_directory]
#
# This script installs midilib into the Ruby site-local library directory.
#
# Author:: Jim Menard (mailto:[email protected])
# Copyright:: Copyright (c) 2003-2013 by Jim Menard
# License:: Distributed under the same license as Ruby.
#
require 'getoptlong'
require 'find'
begin
require 'ftools'
def mkdirs(dir)
File.makedirs(dir)
end
def install(*args)
File.install(*args)
end
rescue LoadError
require 'fileutils'
def mkdirs(dir)
FileUtils.mkdir_p(dir)
end
def install(*args)
args[2] = { mode: args[2], verbose: args[3] }
args.pop
FileUtils.install(*args)
end
end
SOURCE_DIR = 'lib'
LIB_DIR = 'midilib'
IO_DIR = File.join(LIB_DIR, 'io')
def instdir
g = GetoptLong.new(['--install-dir', '-i', GetoptLong::REQUIRED_ARGUMENT])
g.each do |name, arg|
if name == '--install-dir'
return arg
else
warn 'usage: $0 [--install-dir dir]'
end
end
begin
require 'rbconfig'
libdir = Config::CONFIG['sitedir'] + '/' +
Config::CONFIG['MAJOR'] + '.' +
Config::CONFIG['MINOR']
rescue ScriptError
$LOAD_PATH.each do |l|
if l =~ /site_ruby/ && l =~ /\d$/ && l !~ /#{PLATFORM}/
libdir = l
break
end
end
warn "Can't find required file `rbconfig.rb'."
warn "The `midilib' files need to be installed manually in #{libdir}"
end
libdir
end
INSTALL_DIR = instdir
files = Dir.chdir('lib') { Dir['**/*.rb'] }
files.each do |f|
dir = File.dirname(f)
target_dir = File.join(INSTALL_DIR, dir)
mkdirs(target_dir) unless File.exist?(target_dir)
install(File.join('lib', f), File.join(INSTALL_DIR, f), 0o644, true)
end