Permalink
Browse files

New compilation and cleaning tasks for submodules

  • Loading branch information...
1 parent d907bb9 commit 45bf4b4364e7f6bc44e7763a9e514c05453276a1 @RyanScottLewis committed Dec 20, 2012
Showing with 55 additions and 19 deletions.
  1. +55 −19 lib/rake/lua_mruby_tasks.rb
View
74 lib/rake/lua_mruby_tasks.rb
@@ -6,32 +6,47 @@ class Rake::LuaMRubyTasks < Rake::TaskLib
def initialize
- desc "Compile lua-mruby"
- # task(:compile, &:compile)
- task(:compile) { compile }
+ namespace :compile do
+ desc "Compile Lua"
+ task(:lua) { compile_lua }
+ desc "Compile MRuby"
+ task(:mruby) { compile_mruby }
+ desc "Compile Lua-MRuby"
+ task(:lua_mruby) { compile_lua_mruby }
+ end
+ desc "Compile the current build"
+ task :compile => ['compile:lua', 'compile:mruby', 'compile:lua_mruby']
+ namespace :clean do
+ desc "Clean Lua"
+ task(:lua) { clean_lua }
+ desc "Clean MRuby"
+ task(:mruby) { clean_mruby }
+ desc "Clean Lua-MRuby"
+ task(:lua_mruby) { clean_lua_mruby }
+ end
desc "Clean up the current build"
- # task(:clean, &:clean)
- task(:clean) { clean }
+ task :clean => ['clean:lua', 'clean:mruby', 'clean:lua_mruby']
task :default => [:clean, :compile]
end
define_method(:root) { (Pathname.new(__FILE__) / '..' / '..' / '..').expand_path }
+ define_method(:lib) { root / 'lib' }
define_method(:compiler) { '/usr/bin/gcc' }
- define_method(:mruby) { Pathname.new('/Users/ryguy/Code/C/Source/mruby') }
- define_method(:lua) { Pathname.new('/usr/local/Cellar/lua/5.1.4') }
+ define_method(:mruby) { lib / 'mruby' }
+ define_method(:lua) { lib / 'lua' }
define_method(:mruby_include) { mruby / 'include' }
define_method(:mruby_src) { mruby / 'src' }
define_method(:lua_include) { lua / 'include' }
- define_method(:package) { root / 'pkg' }
+ define_method(:package) { root / 'pkg' }
define_method(:output) { "-o #{package / 'mruby.so'}" }
-
+
def includes
[mruby_include, mruby_src, lua_include].collect { |path| "-I#{path}" }.join(' ')
end
-
+
def libraries
[
root / 'lib' / 'lua-mruby.c',
@@ -40,22 +55,43 @@ def libraries
mruby / 'lib' / 'libmruby.a'
].join(' ')
end
-
+
def flags
'-llua -O3 -g -Wall -Werror-implicit-function-declaration -shared -O'
end
-
+
def command
[compiler, includes, flags, output, libraries].join(' ')
end
-
- def compile
- package.mkdir
- system(command)
+
+ def run(command)
+ puts '-=-=-=-=-=-=-=-', '', command, '', '-=-=-=-=-=-=-=-'
+ system command
end
-
- def clean
- package.rmtree rescue nil
+
+ def compile_lua
+ run "cd #{lua} && make posix" # TODO: Not 100% sure this is needed...
+ end
+
+ def compile_mruby
+ run "cd #{mruby} && make"
+ end
+
+ def compile_lua_mruby
+ package.mkpath
+ run "cd #{root} && #{command}"
+ end
+
+ def clean_lua
+ run "cd #{lua} && make clean"
+ end
+
+ def clean_mruby
+ run "cd #{mruby} && make clean"
+ end
+
+ def clean_lua_mruby
+ run "cd #{root} && rm -rf #{package / 'mruby.so*'}"
end
end

0 comments on commit 45bf4b4

Please sign in to comment.