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