Initial Revision
[ohcount] / Rakefile
1 require 'rake'
2 require 'rake/clean'
3 require 'rake/gempackagetask'
4 require 'rake/rdoctask'
5 require 'rake/testtask'
6 require 'rbconfig'
7 include Config
8
9 NAME = 'ohcount'
10 VERS = '1.0.0'
11
12 EXT_DIR  = "ext/ohcount_native"
13 EXT_DL   = "#{EXT_DIR}/ohcount_native.#{CONFIG['DLEXT']}"
14 ARCH_DIR = "lib/#{::Config::CONFIG['arch']}"
15 ARCH_DL  = "#{ARCH_DIR}/ohcount_native.#{CONFIG['DLEXT']}"
16
17 CLEAN.include FileList["#{EXT_DIR}/*.{so,bundle,#{CONFIG['DLEXT']}}"],
18                                                   FileList["#{EXT_DIR}/*.o"],
19                                                   FileList["#{EXT_DIR}/Makefile"]
20
21 RDOC_OPTS = ['--quiet', '--title', 'Ohcount Reference', '--main', 'README', '--inline-source']
22
23 PKG_FILES = %w(README Rakefile lib/ohcount.rb) +
24         Dir.glob("ext/ohcount_native/*.{h,c,rb}") +
25         Dir.glob("ext/ohcount_native/glots/*.rb") +
26         Dir.glob("lib/ohcount/*.rb") +
27         Dir.glob("bin/*")
28
29 SPEC =
30         Gem::Specification.new do |s|
31                 s.name = NAME
32                 s.version = VERS
33                 s.platform = Gem::Platform::RUBY
34                 s.has_rdoc = true
35                 s.rdoc_options += RDOC_OPTS
36                 s.summary = "The Ohloh source code line counter"
37                 s.description = s.summary
38                 s.author = "Ohloh Corporation"
39                 s.email = "info@ohloh.net"
40                 s.homepage = "http://www.ohloh.net"
41                 s.files = PKG_FILES
42                 s.require_paths = ["lib", ARCH_DIR]
43                 s.extensions << 'ext/ohcount_native/extconf.rb'
44                 s.bindir = 'bin'
45                 s.executables = ['ohcount']
46         end
47
48 Rake::GemPackageTask.new(SPEC) do |p|
49         p.need_tar = true
50         p.gem_spec = SPEC
51 end
52
53 task :install => :package do
54         `sudo gem install pkg/#{NAME}-#{VERS}`
55 end
56
57 file ARCH_DL => EXT_DL do
58         mkdir_p ARCH_DIR
59         cp EXT_DL, ARCH_DIR
60 end
61
62 file EXT_DL => FileList["#{EXT_DIR}/Makefile", "#{EXT_DIR}/*.{c,h,rb}"] do
63         cd EXT_DIR do
64                 sh 'make'
65         end
66 end
67
68 file "#{EXT_DIR}/Makefile" => "#{EXT_DIR}/extconf.rb" do
69         cd EXT_DIR do
70                 if ENV['DEBUG']
71                         ruby 'extconf.rb', 'debug'
72                 else
73                         ruby 'extconf.rb'
74                 end
75         end
76 end
77
78 file "#{EXT_DIR}/polyglots.c" => FileList["#{EXT_DIR}/*.rb", "#{EXT_DIR}/glots/*.rb"] do
79         cd EXT_DIR do
80                 ruby 'generator.rb'
81         end
82 end
83
84 Rake::RDocTask.new do |rdoc|
85         rdoc.rdoc_dir = 'doc'
86         rdoc.options += RDOC_OPTS
87         rdoc.rdoc_files.add ['README' ,'COPYING', 'lib/**/*.rb', 'ext/**/*.rb']
88 end
89
90 Rake::TestTask.new :ohcount_unit_tests => ARCH_DL do |t|
91         puts File.dirname(__FILE__) + '/test/unit/*_test.rb'
92         t.test_files = FileList[File.dirname(__FILE__) + '/test/unit/*_test.rb']
93         t.verbose = true
94 end
95
96 task :default => :ohcount_unit_tests