forked from jimm/midilib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.rb
executable file
·57 lines (51 loc) · 1.4 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
#! /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:jimm@io.com)
# Copyright:: Copyright (c) 2003-2009 by Jim Menard
# License:: Distributed under the same license as Ruby.
#
require 'getoptlong'
require 'ftools'
require 'find'
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 { | name, arg |
if name == '--install-dir'
return arg
else
$stderr.puts "usage: $0 [--install-dir dir]"
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
STDERR.puts "Can't find required file `rbconfig.rb'."
STDERR.puts "The `midilib' files need to be installed manually in" +
" #{libdir}"
end
return libdir
end
INSTALL_DIR = instdir()
files = Dir.chdir('lib') { Dir['**/*.rb'] }
files.each { | f |
dir = File.dirname(f)
target_dir = File.join(INSTALL_DIR, dir)
File.makedirs(target_dir) unless File.exist?(target_dir)
File.install(File.join('lib', f), File.join(INSTALL_DIR, f), 0644, true)
}