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