forked from jimm/midilib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.rb
executable file
·56 lines (50 loc) · 1.42 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
#! /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 '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 do |name, arg|
if name == '--install-dir'
return arg
else
$stderr.puts "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
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 do |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)
end